[188] | 1 | package de.ugoe.cs.eventbench.swt;
|
---|
| 2 |
|
---|
| 3 | import org.eclipse.swt.widgets.Dialog;
|
---|
| 4 | import org.eclipse.swt.widgets.Display;
|
---|
[194] | 5 | import org.eclipse.swt.widgets.MessageBox;
|
---|
[188] | 6 | import org.eclipse.swt.widgets.Shell;
|
---|
| 7 | import org.eclipse.swt.widgets.List;
|
---|
| 8 | import org.eclipse.swt.SWT;
|
---|
| 9 | import org.eclipse.swt.widgets.Group;
|
---|
| 10 | import org.eclipse.swt.widgets.Label;
|
---|
| 11 | import org.eclipse.swt.widgets.Button;
|
---|
| 12 | import org.eclipse.swt.layout.GridLayout;
|
---|
| 13 | import org.eclipse.swt.layout.GridData;
|
---|
| 14 | import org.eclipse.swt.layout.FillLayout;
|
---|
| 15 |
|
---|
[194] | 16 | import de.ugoe.cs.eventbench.models.FirstOrderMarkovModel;
|
---|
| 17 | import de.ugoe.cs.eventbench.models.IStochasticProcess;
|
---|
| 18 | import org.eclipse.swt.events.SelectionAdapter;
|
---|
| 19 | import org.eclipse.swt.events.SelectionEvent;
|
---|
| 20 |
|
---|
[192] | 21 | public class ModelPropertiesDialog extends Dialog {
|
---|
[188] | 22 |
|
---|
[194] | 23 | private IStochasticProcess process;
|
---|
| 24 |
|
---|
[188] | 25 | protected Shell shlModelProperties;
|
---|
| 26 |
|
---|
| 27 | /**
|
---|
| 28 | * Create the dialog.
|
---|
| 29 | * @param parent
|
---|
| 30 | * @param style
|
---|
| 31 | */
|
---|
[192] | 32 | public ModelPropertiesDialog(Shell parent, int style) {
|
---|
[188] | 33 | super(parent, style);
|
---|
| 34 | setText("SWT Dialog");
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 | /**
|
---|
| 38 | * Open the dialog.
|
---|
| 39 | */
|
---|
[287] | 40 | public void open() {
|
---|
[188] | 41 | createContents();
|
---|
| 42 | shlModelProperties.open();
|
---|
| 43 | shlModelProperties.layout();
|
---|
| 44 | Display display = getParent().getDisplay();
|
---|
| 45 | while (!shlModelProperties.isDisposed()) {
|
---|
| 46 | if (!display.readAndDispatch()) {
|
---|
| 47 | display.sleep();
|
---|
| 48 | }
|
---|
| 49 | }
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | /**
|
---|
| 53 | * Create contents of the dialog.
|
---|
| 54 | */
|
---|
| 55 | private void createContents() {
|
---|
| 56 | shlModelProperties = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.RESIZE);
|
---|
| 57 | shlModelProperties.setSize(230, 318);
|
---|
| 58 | shlModelProperties.setText("Model Properties");
|
---|
| 59 | shlModelProperties.setLayout(new GridLayout(2, false));
|
---|
| 60 |
|
---|
| 61 | Group grpEvents = new Group(shlModelProperties, SWT.NONE);
|
---|
| 62 | FillLayout fl_grpEvents = new FillLayout(SWT.HORIZONTAL);
|
---|
| 63 | fl_grpEvents.marginHeight = 5;
|
---|
| 64 | fl_grpEvents.marginWidth = 5;
|
---|
| 65 | grpEvents.setLayout(fl_grpEvents);
|
---|
| 66 | grpEvents.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
|
---|
| 67 | grpEvents.setText("Events");
|
---|
| 68 |
|
---|
[381] | 69 | List list = new List(grpEvents, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
|
---|
[194] | 70 | for( String symbol : process.getSymbolStrings() ) {
|
---|
| 71 | list.add(symbol);
|
---|
| 72 | }
|
---|
[188] | 73 |
|
---|
| 74 | Group grpStatistics = new Group(shlModelProperties, SWT.NONE);
|
---|
| 75 | grpStatistics.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
|
---|
| 76 | grpStatistics.setText("Statistics");
|
---|
| 77 | grpStatistics.setLayout(new GridLayout(2, false));
|
---|
| 78 |
|
---|
| 79 | Label lblNumEvents = new Label(grpStatistics, SWT.NONE);
|
---|
| 80 | lblNumEvents.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));
|
---|
| 81 | lblNumEvents.setText("Num. Events");
|
---|
| 82 |
|
---|
| 83 | Label label = new Label(grpStatistics, SWT.RIGHT);
|
---|
| 84 | label.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1));
|
---|
[194] | 85 | label.setText(""+process.getNumSymbols());
|
---|
[188] | 86 |
|
---|
| 87 | Label lblNumTrieLeafs = new Label(grpStatistics, SWT.NONE);
|
---|
| 88 | lblNumTrieLeafs.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));
|
---|
[194] | 89 | lblNumTrieLeafs.setText("Size (Flattend FOM)");
|
---|
[188] | 90 |
|
---|
| 91 | Label label_1 = new Label(grpStatistics, SWT.RIGHT);
|
---|
| 92 | label_1.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1));
|
---|
[194] | 93 | label_1.setText(""+process.getNumFOMStates());
|
---|
[188] | 94 |
|
---|
| 95 | Label lblEntropy = new Label(grpStatistics, SWT.NONE);
|
---|
| 96 | lblEntropy.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));
|
---|
| 97 | lblEntropy.setText("Entropy");
|
---|
| 98 |
|
---|
[194] | 99 | final Label label_2 = new Label(grpStatistics, SWT.RIGHT);
|
---|
| 100 | label_2.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));
|
---|
[188] | 101 | label_2.setText("####");
|
---|
| 102 |
|
---|
| 103 | Button btnCalculateEntropy = new Button(shlModelProperties, SWT.NONE);
|
---|
[194] | 104 | btnCalculateEntropy.addSelectionListener(new SelectionAdapter() {
|
---|
| 105 | @Override
|
---|
| 106 | public void widgetSelected(SelectionEvent e) {
|
---|
| 107 | if( process instanceof FirstOrderMarkovModel) {
|
---|
| 108 | label_2.setText(""+((FirstOrderMarkovModel) process).calcEntropy());
|
---|
| 109 | } else {
|
---|
| 110 | MessageBox messageBox = new MessageBox(shlModelProperties, SWT.NONE);
|
---|
| 111 | messageBox.setText("Feature Not Available");
|
---|
| 112 | messageBox.setMessage("The feature is currently only available for first-order Markov models.");
|
---|
| 113 | messageBox.open();
|
---|
| 114 | }
|
---|
| 115 | }
|
---|
| 116 | });
|
---|
[188] | 117 | btnCalculateEntropy.setText("Calculate Entropy");
|
---|
| 118 |
|
---|
| 119 | Button btnClose = new Button(shlModelProperties, SWT.NONE);
|
---|
[195] | 120 | btnClose.addSelectionListener(new SelectionAdapter() {
|
---|
| 121 | @Override
|
---|
| 122 | public void widgetSelected(SelectionEvent e) {
|
---|
| 123 | shlModelProperties.dispose();
|
---|
| 124 | }
|
---|
| 125 | });
|
---|
[188] | 126 | btnClose.setText("Close");
|
---|
| 127 |
|
---|
| 128 | }
|
---|
[194] | 129 |
|
---|
| 130 | public void setStochasticProcess(IStochasticProcess process) {
|
---|
| 131 | this.process = process;
|
---|
| 132 | }
|
---|
[188] | 133 | }
|
---|