Ignore:
Timestamp:
08/17/12 11:38:43 (12 years ago)
Author:
sherbold
Message:
  • adapted to quest coding style
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/quest-ui-swt/src/main/java/de/ugoe/cs/quest/ui/swt/GenerateSequencesDialog.java

    r526 r570  
     1 
    12package de.ugoe.cs.quest.ui.swt; 
    23 
     
    2223public class GenerateSequencesDialog extends Dialog { 
    2324 
    24         private String processName; 
    25          
    26         protected Button btnNumberAll; 
    27         protected Button btnLengthAll; 
    28         protected Spinner numberSpinner; 
    29         protected Spinner iterationsSpinner; 
    30         protected Spinner minLengthSpinner; 
    31         protected Spinner maxLengthSpinner; 
    32          
    33         protected Shell shlGenerateSequences; 
    34         private Text sequencesNameText; 
    35         private final FormToolkit formToolkit = new FormToolkit(Display.getDefault()); 
    36  
    37         /** 
    38          * Create the dialog. 
    39          * @param parent 
    40          * @param style 
    41          */ 
    42         public GenerateSequencesDialog(Shell parent, int style) { 
    43                 super(parent, style); 
    44                 setText("SWT Dialog"); 
    45         } 
    46  
    47         /** 
    48          * Open the dialog. 
    49          */ 
    50         public void open() { 
    51                 createContents(); 
    52                 shlGenerateSequences.open(); 
    53                 shlGenerateSequences.layout(); 
    54                 Display display = getParent().getDisplay(); 
    55                 while (!shlGenerateSequences.isDisposed()) { 
    56                         if (!display.readAndDispatch()) { 
    57                                 display.sleep(); 
    58                         } 
    59                 } 
    60         } 
    61  
    62         /** 
    63          * Create contents of the dialog. 
    64          */ 
    65         private void createContents() { 
    66                 shlGenerateSequences = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL); 
    67                 shlGenerateSequences.setSize(201, 303); 
    68                 shlGenerateSequences.setText("Generate Sequences"); 
    69                 shlGenerateSequences.setLayout(new GridLayout(2, false)); 
    70                  
    71                 Group group = new Group(shlGenerateSequences, SWT.NONE); 
    72                 group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1)); 
    73                 group.setText("Name"); 
    74                 group.setLayout(new GridLayout(1, false)); 
    75                  
    76                 sequencesNameText = new Text(group, SWT.BORDER); 
    77                 sequencesNameText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); 
    78                  
    79                 Group grpNumber = new Group(shlGenerateSequences, SWT.NONE); 
    80                 grpNumber.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1)); 
    81                 grpNumber.setText("Number"); 
    82                 grpNumber.setLayout(new GridLayout(2, false)); 
    83                  
    84                 numberSpinner = new Spinner(grpNumber, SWT.BORDER); 
    85                 numberSpinner.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); 
    86                 numberSpinner.setMinimum(1); 
    87                 numberSpinner.setMaximum(Integer.MAX_VALUE); 
    88                  
    89                 btnNumberAll = new Button(grpNumber, SWT.CHECK); 
    90                 btnNumberAll.addSelectionListener(new SelectionAdapter() { 
    91                         @Override 
    92                         public void widgetSelected(SelectionEvent e) { 
    93                                 numberSpinner.setEnabled(!btnNumberAll.getSelection()); 
    94                                 btnLengthAll.setEnabled(!btnNumberAll.getSelection()); 
    95                                 iterationsSpinner.setEnabled(!btnNumberAll.getSelection()); 
    96                         } 
    97                 }); 
    98                 btnNumberAll.setText("All"); 
    99                  
    100                 Group grpIterations = new Group(shlGenerateSequences, SWT.NONE); 
    101                 grpIterations.setLayout(new GridLayout(1, false)); 
    102                 grpIterations.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1)); 
    103                 grpIterations.setText("Iterations"); 
    104                  
    105                 iterationsSpinner = new Spinner(grpIterations, SWT.BORDER); 
    106                 iterationsSpinner.setMinimum(1); 
    107                 iterationsSpinner.setMaximum(Integer.MAX_VALUE); 
    108                 iterationsSpinner.setSelection(100000); 
    109                 iterationsSpinner.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); 
    110                  
    111                 Group grpLength = new Group(shlGenerateSequences, SWT.NONE); 
    112                 grpLength.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1)); 
    113                 grpLength.setText("Length"); 
    114                 grpLength.setLayout(new GridLayout(4, false)); 
    115                  
    116                 btnLengthAll = new Button(grpLength, SWT.CHECK); 
    117                 btnLengthAll.addSelectionListener(new SelectionAdapter() { 
    118                         @Override 
    119                         public void widgetSelected(SelectionEvent e) { 
    120                                 minLengthSpinner.setEnabled(!btnLengthAll.getSelection()); 
    121                                 maxLengthSpinner.setEnabled(!btnLengthAll.getSelection()); 
    122                         } 
    123                 }); 
    124                 btnLengthAll.setText("All"); 
    125                 new Label(grpLength, SWT.NONE); 
    126                 new Label(grpLength, SWT.NONE); 
    127                 new Label(grpLength, SWT.NONE); 
    128                  
    129                 Label label = new Label(grpLength, SWT.NONE); 
    130                 label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1)); 
    131                 label.setText("Min."); 
    132                  
    133                 minLengthSpinner = new Spinner(grpLength, SWT.BORDER); 
    134                 minLengthSpinner.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); 
    135                 minLengthSpinner.setMinimum(1); 
    136                  
    137                 Label label_1 = new Label(grpLength, SWT.NONE); 
    138                 label_1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, true, 1, 1)); 
    139                 label_1.setText("Max."); 
    140                  
    141                 maxLengthSpinner = new Spinner(grpLength, SWT.BORDER); 
    142                 maxLengthSpinner.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); 
    143                 maxLengthSpinner.setToolTipText("0 means no limitations"); 
    144                 maxLengthSpinner.setMinimum(1); 
    145                  
    146                 Button btnGenerate = formToolkit.createButton(shlGenerateSequences, "Generate!", SWT.NONE); 
    147                 btnGenerate.addSelectionListener(new SelectionAdapter() { 
    148                         @Override 
    149                         public void widgetSelected(SelectionEvent e) { 
    150                                 if("".equals(sequencesNameText.getText())) { 
    151                                         MessageBox messageBox = new MessageBox(shlGenerateSequences, SWT.ERROR); 
    152                                         messageBox.setText("Error"); 
    153                                         messageBox.setMessage("Sequences name not defined!"); 
    154                                         messageBox.open(); 
    155                                         return; 
    156                                 } 
    157                                 String sequencesName = sequencesNameText.getText(); 
    158                                 int number = numberSpinner.getSelection(); 
    159                                 int minLength = minLengthSpinner.getSelection(); 
    160                                 int maxLength = maxLengthSpinner.getSelection(); 
    161                                 int maxIter = iterationsSpinner.getSelection(); 
    162                                 if( maxIter<=number ) { 
    163                                         maxIter = number; 
    164                                 } 
    165                                 String command = ""; 
    166                                 if( btnNumberAll.getSelection() ) { 
    167                                         if( minLength>maxLength ) { 
    168                                                 MessageBox messageBox = new MessageBox(shlGenerateSequences, SWT.ERROR); 
    169                                                 messageBox.setText("Error"); 
    170                                                 messageBox.setMessage("Min. length must be smaller than or equal to max. length!"); 
    171                                                 messageBox.open(); 
    172                                                 return; 
    173                                         } 
    174                                         command = "generateFixedLengthSequences " + processName + " " + sequencesName + " " + minLength + " " + maxLength + " true"; 
    175                                 } else { 
    176                                         command = "generateRandomSequences " + processName + " " + sequencesName + " " + number + " " + maxIter; 
    177                                         if( !btnLengthAll.getSelection() ) { 
    178                                                 if( minLength>maxLength ) { 
    179                                                         MessageBox messageBox = new MessageBox(shlGenerateSequences, SWT.ERROR); 
    180                                                         messageBox.setText("Error"); 
    181                                                         messageBox.setMessage("Min. length must be smaller than or equal to max. length!"); 
    182                                                         messageBox.open(); 
    183                                                         return; 
    184                                                 } 
    185                                                 command += " " + minLength + " " + maxLength; 
    186                                         } 
    187                                 } 
    188                                 CommandExecuter.getInstance().exec(command); 
    189                                 shlGenerateSequences.dispose(); 
    190                         } 
    191                 }); 
    192                  
    193                 Button btnAbort = formToolkit.createButton(shlGenerateSequences, "Abort", SWT.NONE); 
    194                 btnAbort.addSelectionListener(new SelectionAdapter() { 
    195                         @Override 
    196                         public void widgetSelected(SelectionEvent e) { 
    197                                 shlGenerateSequences.dispose(); 
    198                         } 
    199                 }); 
    200  
    201         } 
    202          
    203         public void setProcessName(String name) { 
    204                 this.processName = name; 
    205         } 
     25    private String processName; 
     26 
     27    protected Button btnNumberAll; 
     28    protected Button btnLengthAll; 
     29    protected Spinner numberSpinner; 
     30    protected Spinner iterationsSpinner; 
     31    protected Spinner minLengthSpinner; 
     32    protected Spinner maxLengthSpinner; 
     33 
     34    protected Shell shlGenerateSequences; 
     35    private Text sequencesNameText; 
     36    private final FormToolkit formToolkit = new FormToolkit(Display.getDefault()); 
     37 
     38    /** 
     39     * Create the dialog. 
     40     *  
     41     * @param parent 
     42     * @param style 
     43     */ 
     44    public GenerateSequencesDialog(Shell parent, int style) { 
     45        super(parent, style); 
     46        setText("SWT Dialog"); 
     47    } 
     48 
     49    /** 
     50     * Open the dialog. 
     51     */ 
     52    public void open() { 
     53        createContents(); 
     54        shlGenerateSequences.open(); 
     55        shlGenerateSequences.layout(); 
     56        Display display = getParent().getDisplay(); 
     57        while (!shlGenerateSequences.isDisposed()) { 
     58            if (!display.readAndDispatch()) { 
     59                display.sleep(); 
     60            } 
     61        } 
     62    } 
     63 
     64    /** 
     65     * Create contents of the dialog. 
     66     */ 
     67    private void createContents() { 
     68        shlGenerateSequences = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL); 
     69        shlGenerateSequences.setSize(201, 303); 
     70        shlGenerateSequences.setText("Generate Sequences"); 
     71        shlGenerateSequences.setLayout(new GridLayout(2, false)); 
     72 
     73        Group group = new Group(shlGenerateSequences, SWT.NONE); 
     74        group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1)); 
     75        group.setText("Name"); 
     76        group.setLayout(new GridLayout(1, false)); 
     77 
     78        sequencesNameText = new Text(group, SWT.BORDER); 
     79        sequencesNameText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); 
     80 
     81        Group grpNumber = new Group(shlGenerateSequences, SWT.NONE); 
     82        grpNumber.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1)); 
     83        grpNumber.setText("Number"); 
     84        grpNumber.setLayout(new GridLayout(2, false)); 
     85 
     86        numberSpinner = new Spinner(grpNumber, SWT.BORDER); 
     87        numberSpinner.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); 
     88        numberSpinner.setMinimum(1); 
     89        numberSpinner.setMaximum(Integer.MAX_VALUE); 
     90 
     91        btnNumberAll = new Button(grpNumber, SWT.CHECK); 
     92        btnNumberAll.addSelectionListener(new SelectionAdapter() { 
     93            @Override 
     94            public void widgetSelected(SelectionEvent e) { 
     95                numberSpinner.setEnabled(!btnNumberAll.getSelection()); 
     96                btnLengthAll.setEnabled(!btnNumberAll.getSelection()); 
     97                iterationsSpinner.setEnabled(!btnNumberAll.getSelection()); 
     98            } 
     99        }); 
     100        btnNumberAll.setText("All"); 
     101 
     102        Group grpIterations = new Group(shlGenerateSequences, SWT.NONE); 
     103        grpIterations.setLayout(new GridLayout(1, false)); 
     104        grpIterations.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1)); 
     105        grpIterations.setText("Iterations"); 
     106 
     107        iterationsSpinner = new Spinner(grpIterations, SWT.BORDER); 
     108        iterationsSpinner.setMinimum(1); 
     109        iterationsSpinner.setMaximum(Integer.MAX_VALUE); 
     110        iterationsSpinner.setSelection(100000); 
     111        iterationsSpinner.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); 
     112 
     113        Group grpLength = new Group(shlGenerateSequences, SWT.NONE); 
     114        grpLength.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1)); 
     115        grpLength.setText("Length"); 
     116        grpLength.setLayout(new GridLayout(4, false)); 
     117 
     118        btnLengthAll = new Button(grpLength, SWT.CHECK); 
     119        btnLengthAll.addSelectionListener(new SelectionAdapter() { 
     120            @Override 
     121            public void widgetSelected(SelectionEvent e) { 
     122                minLengthSpinner.setEnabled(!btnLengthAll.getSelection()); 
     123                maxLengthSpinner.setEnabled(!btnLengthAll.getSelection()); 
     124            } 
     125        }); 
     126        btnLengthAll.setText("All"); 
     127        new Label(grpLength, SWT.NONE); 
     128        new Label(grpLength, SWT.NONE); 
     129        new Label(grpLength, SWT.NONE); 
     130 
     131        Label label = new Label(grpLength, SWT.NONE); 
     132        label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1)); 
     133        label.setText("Min."); 
     134 
     135        minLengthSpinner = new Spinner(grpLength, SWT.BORDER); 
     136        minLengthSpinner.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); 
     137        minLengthSpinner.setMinimum(1); 
     138 
     139        Label label_1 = new Label(grpLength, SWT.NONE); 
     140        label_1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, true, 1, 1)); 
     141        label_1.setText("Max."); 
     142 
     143        maxLengthSpinner = new Spinner(grpLength, SWT.BORDER); 
     144        maxLengthSpinner.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); 
     145        maxLengthSpinner.setToolTipText("0 means no limitations"); 
     146        maxLengthSpinner.setMinimum(1); 
     147 
     148        Button btnGenerate = formToolkit.createButton(shlGenerateSequences, "Generate!", SWT.NONE); 
     149        btnGenerate.addSelectionListener(new SelectionAdapter() { 
     150            @Override 
     151            public void widgetSelected(SelectionEvent e) { 
     152                if ("".equals(sequencesNameText.getText())) { 
     153                    MessageBox messageBox = new MessageBox(shlGenerateSequences, SWT.ERROR); 
     154                    messageBox.setText("Error"); 
     155                    messageBox.setMessage("Sequences name not defined!"); 
     156                    messageBox.open(); 
     157                    return; 
     158                } 
     159                String sequencesName = sequencesNameText.getText(); 
     160                int number = numberSpinner.getSelection(); 
     161                int minLength = minLengthSpinner.getSelection(); 
     162                int maxLength = maxLengthSpinner.getSelection(); 
     163                int maxIter = iterationsSpinner.getSelection(); 
     164                if (maxIter <= number) { 
     165                    maxIter = number; 
     166                } 
     167                String command = ""; 
     168                if (btnNumberAll.getSelection()) { 
     169                    if (minLength > maxLength) { 
     170                        MessageBox messageBox = new MessageBox(shlGenerateSequences, SWT.ERROR); 
     171                        messageBox.setText("Error"); 
     172                        messageBox 
     173                            .setMessage("Min. length must be smaller than or equal to max. length!"); 
     174                        messageBox.open(); 
     175                        return; 
     176                    } 
     177                    command = 
     178                        "generateFixedLengthSequences " + processName + " " + sequencesName + " " + 
     179                            minLength + " " + maxLength + " true"; 
     180                } 
     181                else { 
     182                    command = 
     183                        "generateRandomSequences " + processName + " " + sequencesName + " " + 
     184                            number + " " + maxIter; 
     185                    if (!btnLengthAll.getSelection()) { 
     186                        if (minLength > maxLength) { 
     187                            MessageBox messageBox = new MessageBox(shlGenerateSequences, SWT.ERROR); 
     188                            messageBox.setText("Error"); 
     189                            messageBox 
     190                                .setMessage("Min. length must be smaller than or equal to max. length!"); 
     191                            messageBox.open(); 
     192                            return; 
     193                        } 
     194                        command += " " + minLength + " " + maxLength; 
     195                    } 
     196                } 
     197                CommandExecuter.getInstance().exec(command); 
     198                shlGenerateSequences.dispose(); 
     199            } 
     200        }); 
     201 
     202        Button btnAbort = formToolkit.createButton(shlGenerateSequences, "Abort", SWT.NONE); 
     203        btnAbort.addSelectionListener(new SelectionAdapter() { 
     204            @Override 
     205            public void widgetSelected(SelectionEvent e) { 
     206                shlGenerateSequences.dispose(); 
     207            } 
     208        }); 
     209 
     210    } 
     211 
     212    public void setProcessName(String name) { 
     213        this.processName = name; 
     214    } 
    206215} 
Note: See TracChangeset for help on using the changeset viewer.