Changeset 102:e962e274e6f9

Show
Ignore:
Timestamp:
06/05/08 12:48:48 (6 months ago)
Author:
Frank Benoit <benoit@tionex.de>
branch:
default
Message:

removed tabs and spaces at line end.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • snippets/table/Snippet96.d

    r100 r102  
    1  
    21/******************************************************************************* 
    32 * Copyright (c) 2000, 2004 IBM Corporation and others. 
     
    109 *     IBM Corporation - initial API and implementation 
    1110 * Port to the D programming language: 
    12  *     yidabu at gmail dot com  ( D China http://www.d-programming-language-china.org/ )   
     11 *     yidabu at gmail dot com  ( D China http://www.d-programming-language-china.org/ ) 
    1312 *******************************************************************************/ 
    1413 
     
    1817 
    1918/* 
    20  * TableCursor example snippet: navigate a table cells with arrow keys.  
     19 * TableCursor example snippet: navigate a table cells with arrow keys. 
    2120 * Edit when user hits Return key.  Exit edit mode by hitting Escape (cancels edit) 
    2221 * or Return (applies edit to table). 
     
    5756 
    5857 
    59 void main(String[] args) 
    60 
    61     Snippet96.main(args); 
    62 
    63  
    64  
    65 public class Snippet96 { 
    66  
    67 public static void main(String[] args) { 
    68     Display display = new Display(); 
    69     Shell shell = new Shell(display); 
    70     shell.setLayout(new GridLayout()); 
    71  
    72     // create a a table with 3 columns and fill with data 
    73     final Table table = new Table(shell, DWT.BORDER | DWT.MULTI | DWT.FULL_SELECTION); 
    74     table.setLayoutData(new GridData(GridData.FILL_BOTH)); 
    75     TableColumn column1 = new TableColumn(table, DWT.NONE); 
    76     TableColumn column2 = new TableColumn(table, DWT.NONE); 
    77     TableColumn column3 = new TableColumn(table, DWT.NONE); 
    78     for (int i = 0; i < 100; i++) { 
    79         TableItem item = new TableItem(table, DWT.NONE); 
    80         item.setText(["cell " ~ to!(char[])(i) ~ " 0",  "cell " ~ to!(char[])(i) ~ " 1", "cell " ~ to!(char[])(i) ~ " 2" ]); 
    81     } 
    82     column1.pack(); 
    83     column2.pack(); 
    84     column3.pack(); 
    85  
    86     // create a TableCursor to navigate around the table 
    87     final TableCursor cursor = new TableCursor(table, DWT.NONE); 
    88     // create an editor to edit the cell when the user hits "ENTER"  
    89     // while over a cell in the table 
    90     final ControlEditor editor = new ControlEditor(cursor); 
    91     editor.grabHorizontal = true; 
    92     editor.grabVertical = true; 
    93  
    94     cursor.addSelectionListener(new class(table, editor, cursor) SelectionAdapter { 
    95         // when the TableEditor is over a cell, select the corresponding row in  
    96         // the table 
    97          
     58void main() { 
     59    Display display = new Display(); 
     60    Shell shell = new Shell(display); 
     61    shell.setLayout(new GridLayout()); 
     62 
     63    // create a a table with 3 columns and fill with data 
     64    final Table table = new Table(shell, DWT.BORDER | DWT.MULTI | DWT.FULL_SELECTION); 
     65    table.setLayoutData(new GridData(GridData.FILL_BOTH)); 
     66    TableColumn column1 = new TableColumn(table, DWT.NONE); 
     67    TableColumn column2 = new TableColumn(table, DWT.NONE); 
     68    TableColumn column3 = new TableColumn(table, DWT.NONE); 
     69    for (int i = 0; i < 100; i++) { 
     70        TableItem item = new TableItem(table, DWT.NONE); 
     71        item.setText(["cell " ~ to!(char[])(i) ~ " 0",  "cell " ~ to!(char[])(i) ~ " 1", "cell " ~ to!(char[])(i) ~ " 2" ]); 
     72    } 
     73    column1.pack(); 
     74    column2.pack(); 
     75    column3.pack(); 
     76 
     77    // create a TableCursor to navigate around the table 
     78    final TableCursor cursor = new TableCursor(table, DWT.NONE); 
     79    // create an editor to edit the cell when the user hits "ENTER" 
     80    // while over a cell in the table 
     81    final ControlEditor editor = new ControlEditor(cursor); 
     82    editor.grabHorizontal = true; 
     83    editor.grabVertical = true; 
     84 
     85    cursor.addSelectionListener(new class(table, editor, cursor) SelectionAdapter { 
     86        // when the TableEditor is over a cell, select the corresponding row in 
     87        // the table 
     88 
    9889        Table table; 
    9990        ControlEditor editor; 
     
    10596            cursor = cursor_; 
    10697        } 
    107          
    108        public void widgetSelected(SelectionEvent e) { 
    109            table.setSelection([cursor.getRow()]); 
    110        
    111         // when the user hits "ENTER" in the TableCursor, pop up a text editor so that  
    112        // they can change the text of the cell 
    113        public void widgetDefaultSelected(SelectionEvent e) { 
    114            final Text text = new Text(cursor, DWT.NONE); 
    115            TableItem row = cursor.getRow(); 
    116            int column = cursor.getColumn(); 
    117            text.setText(row.getText(column)); 
    118            text.addKeyListener(new class(text, cursor) KeyAdapter { 
     98 
     99        public void widgetSelected(SelectionEvent e) { 
     100            table.setSelection([cursor.getRow()]); 
     101       
     102        // when the user hits "ENTER" in the TableCursor, pop up a text editor so that 
     103        // they can change the text of the cell 
     104        public void widgetDefaultSelected(SelectionEvent e) { 
     105            final Text text = new Text(cursor, DWT.NONE); 
     106            TableItem row = cursor.getRow(); 
     107            int column = cursor.getColumn(); 
     108            text.setText(row.getText(column)); 
     109            text.addKeyListener(new class(text, cursor) KeyAdapter { 
    119110                Text text; 
    120111                TableCursor cursor; 
     
    123114                    text = text_; 
    124115                    cursor = cursor_; 
    125                 }                 
    126                public void keyPressed(KeyEvent e) { 
    127                     // close the text editor and copy the data over  
    128                    // when the user hits "ENTER" 
    129                    if (e.character == DWT.CR) { 
    130                        TableItem row = cursor.getRow(); 
    131                        int column = cursor.getColumn(); 
    132                        row.setText(column, text.getText()); 
    133                        text.dispose(); 
    134                    
    135                    // close the text editor when the user hits "ESC" 
    136                    if (e.character == DWT.ESC) { 
    137                        text.dispose(); 
    138                    
    139                
    140            }); 
    141            // close the text editor when the user tabs away 
    142            text.addFocusListener(new class(text) FocusAdapter { 
     116                } 
     117                public void keyPressed(KeyEvent e) { 
     118                    // close the text editor and copy the data over 
     119                    // when the user hits "ENTER" 
     120                    if (e.character == DWT.CR) { 
     121                        TableItem row = cursor.getRow(); 
     122                        int column = cursor.getColumn(); 
     123                        row.setText(column, text.getText()); 
     124                        text.dispose(); 
     125                   
     126                    // close the text editor when the user hits "ESC" 
     127                    if (e.character == DWT.ESC) { 
     128                        text.dispose(); 
     129                   
     130               
     131            }); 
     132            // close the text editor when the user tabs away 
     133            text.addFocusListener(new class(text) FocusAdapter { 
    143134                Text text; 
    144135                this(Text text_) 
    145136                { 
    146137                    text = text_; 
    147                 }                  
    148                public void focusLost(FocusEvent e) { 
    149                    text.dispose(); 
    150                
    151            }); 
    152            editor.setEditor(text); 
    153            text.setFocus(); 
    154        
    155    }); 
    156    // Hide the TableCursor when the user hits the "CTRL" or "SHIFT" key. 
    157    // This alows the user to select multiple items in the table. 
    158    cursor.addKeyListener(new class(cursor) KeyAdapter { 
     138                } 
     139                public void focusLost(FocusEvent e) { 
     140                    text.dispose(); 
     141               
     142            }); 
     143            editor.setEditor(text); 
     144            text.setFocus(); 
     145       
     146    }); 
     147    // Hide the TableCursor when the user hits the "CTRL" or "SHIFT" key. 
     148    // This alows the user to select multiple items in the table. 
     149    cursor.addKeyListener(new class(cursor) KeyAdapter { 
    159150        TableCursor cursor; 
    160151        this(TableCursor cursor_) 
    161152        { 
    162153            cursor = cursor_; 
    163         }           
    164        public void keyPressed(KeyEvent e) { 
    165            if (e.keyCode == DWT.CTRL 
    166                || e.keyCode == DWT.SHIFT 
    167                || (e.stateMask & DWT.CONTROL) != 0 
    168                || (e.stateMask & DWT.SHIFT) != 0) { 
    169                cursor.setVisible(false); 
    170            
    171        
    172    }); 
    173     // When the user double clicks in the TableCursor, pop up a text editor so that  
    174    // they can change the text of the cell 
    175    cursor.addMouseListener(new class(cursor, editor) MouseAdapter { 
     154        } 
     155        public void keyPressed(KeyEvent e) { 
     156            if (e.keyCode == DWT.CTRL 
     157                || e.keyCode == DWT.SHIFT 
     158                || (e.stateMask & DWT.CONTROL) != 0 
     159                || (e.stateMask & DWT.SHIFT) != 0) { 
     160                cursor.setVisible(false); 
     161           
     162       
     163    }); 
     164    // When the user double clicks in the TableCursor, pop up a text editor so that 
     165    // they can change the text of the cell 
     166    cursor.addMouseListener(new class(cursor, editor) MouseAdapter { 
    176167        ControlEditor editor; 
    177168        TableCursor cursor; 
     
    180171            cursor = cursor_; 
    181172            editor = editor_; 
    182         }         
    183          
    184        public void mouseDown(MouseEvent e) { 
    185            final Text text = new Text(cursor, DWT.NONE); 
    186            TableItem row = cursor.getRow(); 
    187            int column = cursor.getColumn(); 
    188            text.setText(row.getText(column)); 
    189            text.addKeyListener(new class(text, cursor) KeyAdapter { 
     173        } 
     174 
     175        public void mouseDown(MouseEvent e) { 
     176            final Text text = new Text(cursor, DWT.NONE); 
     177            TableItem row = cursor.getRow(); 
     178            int column = cursor.getColumn(); 
     179            text.setText(row.getText(column)); 
     180            text.addKeyListener(new class(text, cursor) KeyAdapter { 
    190181                Text text; 
    191182                TableCursor cursor; 
     
    194185                    text = text_; 
    195186                    cursor = cursor_; 
    196                 }                   
    197                public void keyPressed(KeyEvent e) { 
    198                     // close the text editor and copy the data over  
    199                    // when the user hits "ENTER" 
    200                    if (e.character == DWT.CR) { 
    201                        TableItem row = cursor.getRow(); 
    202                        int column = cursor.getColumn(); 
    203                        row.setText(column, text.getText()); 
    204                        text.dispose(); 
    205                    
    206                    // close the text editor when the user hits "ESC" 
    207                    if (e.character == DWT.ESC) { 
    208                        text.dispose(); 
    209                    
    210                
    211            }); 
    212            // close the text editor when the user clicks away 
    213            text.addFocusListener(new class(text) FocusAdapter { 
     187                } 
     188                public void keyPressed(KeyEvent e) { 
     189                    // close the text editor and copy the data over 
     190                    // when the user hits "ENTER" 
     191                    if (e.character == DWT.CR) { 
     192                        TableItem row = cursor.getRow(); 
     193                        int column = cursor.getColumn(); 
     194                        row.setText(column, text.getText()); 
     195                        text.dispose(); 
     196                   
     197                    // close the text editor when the user hits "ESC" 
     198                    if (e.character == DWT.ESC) { 
     199                        text.dispose(); 
     200                   
     201               
     202            }); 
     203            // close the text editor when the user clicks away 
     204            text.addFocusListener(new class(text) FocusAdapter { 
    214205                Text text; 
    215206                this(Text text_) 
    216207                { 
    217208                    text = text_; 
    218                 }                   
    219                public void focusLost(FocusEvent e) { 
    220                    text.dispose(); 
    221                
    222            }); 
    223            editor.setEditor(text); 
    224            text.setFocus(); 
    225        
    226    }); 
    227      
    228    // Show the TableCursor when the user releases the "SHIFT" or "CTRL" key. 
    229    // This signals the end of the multiple selection task. 
    230    table.addKeyListener(new class(table, cursor) KeyAdapter { 
     209                } 
     210                public void focusLost(FocusEvent e) { 
     211                    text.dispose(); 
     212               
     213            }); 
     214            editor.setEditor(text); 
     215            text.setFocus(); 
     216       
     217    }); 
     218 
     219    // Show the TableCursor when the user releases the "SHIFT" or "CTRL" key. 
     220    // This signals the end of the multiple selection task. 
     221    table.addKeyListener(new class(table, cursor) KeyAdapter { 
    231222        Table table; 
    232223        TableCursor cursor; 
     
    235226            table = table_; 
    236227            cursor = cursor_; 
    237         }         
    238        public void keyReleased(KeyEvent e) { 
    239            if (e.keyCode == DWT.CONTROL && (e.stateMask & DWT.SHIFT) != 0) 
    240                return; 
    241            if (e.keyCode == DWT.SHIFT && (e.stateMask & DWT.CONTROL) != 0) 
    242                return; 
    243            if (e.keyCode != DWT.CONTROL 
    244                && (e.stateMask & DWT.CONTROL) != 0) 
    245                return; 
    246            if (e.keyCode != DWT.SHIFT && (e.stateMask & DWT.SHIFT) != 0) 
    247                return; 
    248  
    249            TableItem[] selection = table.getSelection(); 
    250            TableItem row = (selection.length == 0) ? table.getItem(table.getTopIndex()) : selection[0]; 
    251            table.showItem(row); 
    252            cursor.setSelection(row, 0); 
    253            cursor.setVisible(true); 
    254            cursor.setFocus(); 
    255        
    256    }); 
    257  
    258    shell.open(); 
    259    while (!shell.isDisposed()) { 
    260        if (!display.readAndDispatch()) 
    261            display.sleep(); 
    262    
    263    display.dispose(); 
     228        } 
     229        public void keyReleased(KeyEvent e) { 
     230            if (e.keyCode == DWT.CONTROL && (e.stateMask & DWT.SHIFT) != 0) 
     231                return; 
     232            if (e.keyCode == DWT.SHIFT && (e.stateMask & DWT.CONTROL) != 0) 
     233                return; 
     234            if (e.keyCode != DWT.CONTROL 
     235                && (e.stateMask & DWT.CONTROL) != 0) 
     236                return; 
     237            if (e.keyCode != DWT.SHIFT && (e.stateMask & DWT.SHIFT) != 0) 
     238                return; 
     239 
     240            TableItem[] selection = table.getSelection(); 
     241            TableItem row = (selection.length == 0) ? table.getItem(table.getTopIndex()) : selection[0]; 
     242            table.showItem(row); 
     243            cursor.setSelection(row, 0); 
     244            cursor.setVisible(true); 
     245            cursor.setFocus(); 
     246       
     247    }); 
     248 
     249    shell.open(); 
     250    while (!shell.isDisposed()) { 
     251        if (!display.readAndDispatch()) 
     252            display.sleep(); 
     253   
     254    display.dispose(); 
    264255} 
    265 }