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