- Timestamp:
- 09/24/11 02:44:33 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/swt/TrainModelDialog.java
r188 r192 3 3 import org.eclipse.swt.widgets.Dialog; 4 4 import org.eclipse.swt.widgets.Display; 5 import org.eclipse.swt.widgets.MessageBox; 5 6 import org.eclipse.swt.widgets.Shell; 6 7 import org.eclipse.swt.widgets.Button; … … 12 13 import org.eclipse.swt.layout.GridLayout; 13 14 import org.eclipse.swt.layout.GridData; 15 import org.eclipse.swt.events.SelectionAdapter; 16 import org.eclipse.swt.events.SelectionEvent; 17 18 import de.ugoe.cs.util.console.CommandExecuter; 19 import de.ugoe.cs.util.console.Console; 14 20 15 21 public class TrainModelDialog extends Dialog { … … 17 23 protected Object result; 18 24 protected Shell shlTrainUsageModel; 19 private Text text_1; 25 26 private Button btnFirstorderMarkovModel; 27 private Button btnHighorderMarkovModel; 28 private Button btnPredictionByPartial; 29 private Button btnDeterministicFiniteAutomaton; 30 31 private Spinner minOrderSpinner; 32 private Spinner maxOrderSpinner; 33 private Text modelnameText; 34 35 private String[] sequenceNames; 36 private Text probEscapeText; 37 private Label lblEscapeProbability; 20 38 21 39 /** … … 51 69 private void createContents() { 52 70 shlTrainUsageModel = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.MIN | SWT.APPLICATION_MODAL); 53 shlTrainUsageModel.setSize(219, 279);71 shlTrainUsageModel.setSize(219, 330); 54 72 shlTrainUsageModel.setText("Train Usage Model"); 55 73 shlTrainUsageModel.setLayout(new GridLayout(2, false)); … … 60 78 grpGeneralInformation.setLayout(new GridLayout(1, false)); 61 79 62 text_1= new Text(grpGeneralInformation, SWT.BORDER);63 text_1.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));80 modelnameText = new Text(grpGeneralInformation, SWT.BORDER); 81 modelnameText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1)); 64 82 65 83 Group grpType = new Group(shlTrainUsageModel, SWT.NONE); 66 84 grpType.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 2, 1)); 67 85 grpType.setText("Type"); 68 grpType.setLayout(new GridLayout(1, false)); 69 70 Button btnFirstorderMarkovModel = new Button(grpType, SWT.RADIO); 71 btnFirstorderMarkovModel.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, false, 1, 1)); 86 grpType.setLayout(new GridLayout(2, false)); 87 88 btnFirstorderMarkovModel = new Button(grpType, SWT.RADIO); 89 btnFirstorderMarkovModel.addSelectionListener(new SelectionAdapter() { 90 @Override 91 public void widgetSelected(SelectionEvent e) { 92 minOrderSpinner.setEnabled(false); 93 maxOrderSpinner.setEnabled(false); 94 probEscapeText.setEnabled(false); 95 } 96 }); 97 btnFirstorderMarkovModel.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, false, 2, 1)); 72 98 btnFirstorderMarkovModel.setText("First-Order Markov Model"); 73 74 Button btnHighorderMarkovModel = new Button(grpType, SWT.RADIO); 75 btnHighorderMarkovModel.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, false, 1, 1)); 99 btnFirstorderMarkovModel.setSelection(true); 100 101 btnHighorderMarkovModel = new Button(grpType, SWT.RADIO); 102 btnHighorderMarkovModel.addSelectionListener(new SelectionAdapter() { 103 @Override 104 public void widgetSelected(SelectionEvent e) { 105 minOrderSpinner.setEnabled(false); 106 maxOrderSpinner.setEnabled(true); 107 probEscapeText.setEnabled(false); 108 } 109 }); 110 btnHighorderMarkovModel.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, false, 2, 1)); 76 111 btnHighorderMarkovModel.setText("High-Order Markov Model"); 77 112 78 Button btnPredictionByPartial = new Button(grpType, SWT.RADIO); 79 btnPredictionByPartial.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, false, 1, 1)); 113 btnPredictionByPartial = new Button(grpType, SWT.RADIO); 114 btnPredictionByPartial.addSelectionListener(new SelectionAdapter() { 115 @Override 116 public void widgetSelected(SelectionEvent e) { 117 minOrderSpinner.setEnabled(true); 118 maxOrderSpinner.setEnabled(true); 119 probEscapeText.setEnabled(true); 120 } 121 }); 122 btnPredictionByPartial.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, true, false, 2, 1)); 80 123 btnPredictionByPartial.setText("Prediction by Partial Match"); 81 124 82 Button btnDeterministicFiniteAutomaton = new Button(grpType, SWT.RADIO); 83 btnDeterministicFiniteAutomaton.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, false, 1, 1)); 125 lblEscapeProbability = new Label(grpType, SWT.NONE); 126 lblEscapeProbability.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, false, 1, 1)); 127 lblEscapeProbability.setText("Escape Probability:"); 128 129 probEscapeText = new Text(grpType, SWT.BORDER); 130 probEscapeText.setText("0.1"); 131 probEscapeText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); 132 probEscapeText.setEnabled(false); 133 134 btnDeterministicFiniteAutomaton = new Button(grpType, SWT.RADIO); 135 btnDeterministicFiniteAutomaton.addSelectionListener(new SelectionAdapter() { 136 @Override 137 public void widgetSelected(SelectionEvent e) { 138 minOrderSpinner.setEnabled(false); 139 maxOrderSpinner.setEnabled(false); 140 probEscapeText.setEnabled(false); 141 } 142 }); 143 btnDeterministicFiniteAutomaton.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, false, 2, 1)); 84 144 btnDeterministicFiniteAutomaton.setText("Deterministic Finite Automaton"); 85 145 … … 92 152 lblMin.setText("Min."); 93 153 94 Spinner spinner_1 = new Spinner(grpModelProperties, SWT.BORDER); 154 minOrderSpinner = new Spinner(grpModelProperties, SWT.BORDER); 155 minOrderSpinner.setEnabled(false); 95 156 96 157 Label lblMax = new Label(grpModelProperties, SWT.NONE); 97 158 lblMax.setText("Max."); 98 159 99 Spinner spinner = new Spinner(grpModelProperties, SWT.BORDER); 100 new Label(grpModelProperties, SWT.NONE); 101 new Label(grpModelProperties, SWT.NONE); 102 new Label(grpModelProperties, SWT.NONE); 103 new Label(grpModelProperties, SWT.NONE); 160 maxOrderSpinner = new Spinner(grpModelProperties, SWT.BORDER); 161 maxOrderSpinner.setEnabled(false); 162 maxOrderSpinner.setMinimum(2); 104 163 105 164 Button btnTrain = new Button(shlTrainUsageModel, SWT.NONE); 165 btnTrain.addSelectionListener(new SelectionAdapter() { 166 @Override 167 public void widgetSelected(SelectionEvent e) { 168 String command = ""; 169 String modelname = modelnameText.getText(); 170 if( modelname.equals("")) { 171 MessageBox messageBox = new MessageBox(shlTrainUsageModel, SWT.ERROR); 172 messageBox.setText("Error"); 173 messageBox.setMessage("No modelname defined!"); 174 return; 175 } 176 if( btnFirstorderMarkovModel.getSelection() ) { 177 command = "trainMarkovModel " + modelname + " " + sequenceNames[0]; 178 179 } 180 else if( btnHighorderMarkovModel.getSelection() ) { 181 int modelOrder = maxOrderSpinner.getSelection(); 182 command = "trainMarkovModel " + modelname + " " + sequenceNames[0] + " " + modelOrder; 183 } 184 else if( btnPredictionByPartial.getSelection() ) { 185 int minOrder = minOrderSpinner.getSelection(); 186 int maxOrder = maxOrderSpinner.getSelection(); 187 if( minOrder>maxOrder ) { 188 MessageBox messageBox = new MessageBox(shlTrainUsageModel, SWT.ERROR); 189 messageBox.setText("Error"); 190 messageBox.setMessage("Min. Order must be smaller than or equal to max. order!"); 191 return; 192 } 193 double probEscape = Double.parseDouble(probEscapeText.getText()); 194 if( probEscape<0.0 || probEscape>1.0) { 195 MessageBox messageBox = new MessageBox(shlTrainUsageModel, SWT.ERROR); 196 messageBox.setText("Error"); 197 messageBox.setMessage("Escape probability must be in [0,1]!"); 198 return; 199 } 200 command = "trainPPM " + modelname + " " + sequenceNames[0] + " " + probEscape + " " + maxOrder + " " + minOrder; 201 } 202 else if( btnDeterministicFiniteAutomaton.getSelection() ) { 203 command = "trainDFA " + modelname + " " + sequenceNames[0]; 204 } 205 CommandExecuter.getInstance().exec(command); 206 for( int i=1; i<sequenceNames.length; i++ ) { 207 command = "updateModel " + sequenceNames[i]; 208 CommandExecuter.getInstance().exec(command); 209 } 210 shlTrainUsageModel.dispose(); 211 } 212 }); 106 213 btnTrain.setText("Train!"); 107 214 108 215 Button btnAbort = new Button(shlTrainUsageModel, SWT.NONE); 216 btnAbort.addSelectionListener(new SelectionAdapter() { 217 @Override 218 public void widgetSelected(SelectionEvent e) { 219 shlTrainUsageModel.dispose(); 220 } 221 }); 109 222 btnAbort.setText("Abort"); 110 223 111 224 } 225 226 public void setSequenceNames(String[] sequenceNames) { 227 this.sequenceNames = sequenceNames; 228 } 112 229 }
Note: See TracChangeset
for help on using the changeset viewer.