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