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