| 1 | package de.ugoe.cs.eventbench.swt;
|
|---|
| 2 |
|
|---|
| 3 | import org.eclipse.swt.widgets.Dialog;
|
|---|
| 4 | import org.eclipse.swt.widgets.Display;
|
|---|
| 5 | import org.eclipse.swt.widgets.MessageBox;
|
|---|
| 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 |
|
|---|
| 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 |
|
|---|
| 21 | public class ModelPropertiesDialog extends Dialog {
|
|---|
| 22 |
|
|---|
| 23 | private IStochasticProcess process;
|
|---|
| 24 |
|
|---|
| 25 | protected Shell shlModelProperties;
|
|---|
| 26 |
|
|---|
| 27 | /**
|
|---|
| 28 | * Create the dialog.
|
|---|
| 29 | * @param parent
|
|---|
| 30 | * @param style
|
|---|
| 31 | */
|
|---|
| 32 | public ModelPropertiesDialog(Shell parent, int style) {
|
|---|
| 33 | super(parent, style);
|
|---|
| 34 | setText("SWT Dialog");
|
|---|
| 35 | }
|
|---|
| 36 |
|
|---|
| 37 | /**
|
|---|
| 38 | * Open the dialog.
|
|---|
| 39 | */
|
|---|
| 40 | public void open() {
|
|---|
| 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 |
|
|---|
| 69 | List list = new List(grpEvents, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
|
|---|
| 70 | for( String symbol : process.getSymbolStrings() ) {
|
|---|
| 71 | if( symbol==null ) {
|
|---|
| 72 | list.add("null");
|
|---|
| 73 | } else {
|
|---|
| 74 | list.add(symbol);
|
|---|
| 75 | }
|
|---|
| 76 | }
|
|---|
| 77 |
|
|---|
| 78 | Group grpStatistics = new Group(shlModelProperties, SWT.NONE);
|
|---|
| 79 | grpStatistics.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
|
|---|
| 80 | grpStatistics.setText("Statistics");
|
|---|
| 81 | grpStatistics.setLayout(new GridLayout(2, false));
|
|---|
| 82 |
|
|---|
| 83 | Label lblNumEvents = new Label(grpStatistics, SWT.NONE);
|
|---|
| 84 | lblNumEvents.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));
|
|---|
| 85 | lblNumEvents.setText("Num. Events");
|
|---|
| 86 |
|
|---|
| 87 | Label label = new Label(grpStatistics, SWT.RIGHT);
|
|---|
| 88 | label.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1));
|
|---|
| 89 | label.setText(""+process.getNumSymbols());
|
|---|
| 90 |
|
|---|
| 91 | Label lblNumTrieLeafs = new Label(grpStatistics, SWT.NONE);
|
|---|
| 92 | lblNumTrieLeafs.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));
|
|---|
| 93 | lblNumTrieLeafs.setText("Size (Flattend FOM)");
|
|---|
| 94 |
|
|---|
| 95 | Label label_1 = new Label(grpStatistics, SWT.RIGHT);
|
|---|
| 96 | label_1.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1));
|
|---|
| 97 | label_1.setText(""+process.getNumFOMStates());
|
|---|
| 98 |
|
|---|
| 99 | Label lblEntropy = new Label(grpStatistics, SWT.NONE);
|
|---|
| 100 | lblEntropy.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));
|
|---|
| 101 | lblEntropy.setText("Entropy");
|
|---|
| 102 |
|
|---|
| 103 | final Label label_2 = new Label(grpStatistics, SWT.RIGHT);
|
|---|
| 104 | label_2.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));
|
|---|
| 105 | label_2.setText("####");
|
|---|
| 106 |
|
|---|
| 107 | Button btnCalculateEntropy = new Button(shlModelProperties, SWT.NONE);
|
|---|
| 108 | btnCalculateEntropy.addSelectionListener(new SelectionAdapter() {
|
|---|
| 109 | @Override
|
|---|
| 110 | public void widgetSelected(SelectionEvent e) {
|
|---|
| 111 | if( process instanceof FirstOrderMarkovModel) {
|
|---|
| 112 | label_2.setText(""+((FirstOrderMarkovModel) process).calcEntropy());
|
|---|
| 113 | } else {
|
|---|
| 114 | MessageBox messageBox = new MessageBox(shlModelProperties, SWT.NONE);
|
|---|
| 115 | messageBox.setText("Feature Not Available");
|
|---|
| 116 | messageBox.setMessage("The feature is currently only available for first-order Markov models.");
|
|---|
| 117 | messageBox.open();
|
|---|
| 118 | }
|
|---|
| 119 | }
|
|---|
| 120 | });
|
|---|
| 121 | btnCalculateEntropy.setText("Calculate Entropy");
|
|---|
| 122 |
|
|---|
| 123 | Button btnClose = new Button(shlModelProperties, SWT.NONE);
|
|---|
| 124 | btnClose.addSelectionListener(new SelectionAdapter() {
|
|---|
| 125 | @Override
|
|---|
| 126 | public void widgetSelected(SelectionEvent e) {
|
|---|
| 127 | shlModelProperties.dispose();
|
|---|
| 128 | }
|
|---|
| 129 | });
|
|---|
| 130 | btnClose.setText("Close");
|
|---|
| 131 |
|
|---|
| 132 | }
|
|---|
| 133 |
|
|---|
| 134 | public void setStochasticProcess(IStochasticProcess process) {
|
|---|
| 135 | this.process = process;
|
|---|
| 136 | }
|
|---|
| 137 | }
|
|---|