1 | // Copyright 2012 Georg-August-Universität Göttingen, Germany
|
---|
2 | //
|
---|
3 | // Licensed under the Apache License, Version 2.0 (the "License");
|
---|
4 | // you may not use this file except in compliance with the License.
|
---|
5 | // You may obtain a copy of the License at
|
---|
6 | //
|
---|
7 | // http://www.apache.org/licenses/LICENSE-2.0
|
---|
8 | //
|
---|
9 | // Unless required by applicable law or agreed to in writing, software
|
---|
10 | // distributed under the License is distributed on an "AS IS" BASIS,
|
---|
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
12 | // See the License for the specific language governing permissions and
|
---|
13 | // limitations under the License.
|
---|
14 |
|
---|
15 | package de.ugoe.cs.autoquest.ui.swt;
|
---|
16 |
|
---|
17 | import org.eclipse.swt.widgets.Dialog;
|
---|
18 | import org.eclipse.swt.widgets.Display;
|
---|
19 | import org.eclipse.swt.widgets.MessageBox;
|
---|
20 | import org.eclipse.swt.widgets.Shell;
|
---|
21 | import org.eclipse.swt.widgets.List;
|
---|
22 | import org.eclipse.swt.SWT;
|
---|
23 | import org.eclipse.swt.widgets.Group;
|
---|
24 | import org.eclipse.swt.widgets.Label;
|
---|
25 | import org.eclipse.swt.widgets.Button;
|
---|
26 | import org.eclipse.swt.layout.GridLayout;
|
---|
27 | import org.eclipse.swt.layout.GridData;
|
---|
28 | import org.eclipse.swt.layout.FillLayout;
|
---|
29 |
|
---|
30 | import de.ugoe.cs.autoquest.usageprofiles.FirstOrderMarkovModel;
|
---|
31 | import de.ugoe.cs.autoquest.usageprofiles.IStochasticProcess;
|
---|
32 |
|
---|
33 | import org.eclipse.swt.events.SelectionAdapter;
|
---|
34 | import org.eclipse.swt.events.SelectionEvent;
|
---|
35 |
|
---|
36 | public class ModelPropertiesDialog extends Dialog {
|
---|
37 |
|
---|
38 | private IStochasticProcess process;
|
---|
39 |
|
---|
40 | protected Shell shlModelProperties;
|
---|
41 |
|
---|
42 | /**
|
---|
43 | * Create the dialog.
|
---|
44 | *
|
---|
45 | * @param parent
|
---|
46 | * @param style
|
---|
47 | */
|
---|
48 | public ModelPropertiesDialog(Shell parent, int style) {
|
---|
49 | super(parent, style);
|
---|
50 | setText("SWT Dialog");
|
---|
51 | }
|
---|
52 |
|
---|
53 | /**
|
---|
54 | * Open the dialog.
|
---|
55 | */
|
---|
56 | public void open() {
|
---|
57 | createContents();
|
---|
58 | shlModelProperties.open();
|
---|
59 | shlModelProperties.layout();
|
---|
60 | Display display = getParent().getDisplay();
|
---|
61 | while (!shlModelProperties.isDisposed()) {
|
---|
62 | if (!display.readAndDispatch()) {
|
---|
63 | display.sleep();
|
---|
64 | }
|
---|
65 | }
|
---|
66 | }
|
---|
67 |
|
---|
68 | /**
|
---|
69 | * Create contents of the dialog.
|
---|
70 | */
|
---|
71 | private void createContents() {
|
---|
72 | shlModelProperties = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.RESIZE);
|
---|
73 | shlModelProperties.setSize(230, 318);
|
---|
74 | shlModelProperties.setText("Model Properties");
|
---|
75 | shlModelProperties.setLayout(new GridLayout(2, false));
|
---|
76 |
|
---|
77 | Group grpEvents = new Group(shlModelProperties, SWT.NONE);
|
---|
78 | FillLayout fl_grpEvents = new FillLayout(SWT.HORIZONTAL);
|
---|
79 | fl_grpEvents.marginHeight = 5;
|
---|
80 | fl_grpEvents.marginWidth = 5;
|
---|
81 | grpEvents.setLayout(fl_grpEvents);
|
---|
82 | grpEvents.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
|
---|
83 | grpEvents.setText("Events");
|
---|
84 |
|
---|
85 | List list = new List(grpEvents, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
|
---|
86 | for (String symbol : process.getSymbolStrings()) {
|
---|
87 | if (symbol == null) {
|
---|
88 | list.add("null");
|
---|
89 | }
|
---|
90 | else {
|
---|
91 | list.add(symbol);
|
---|
92 | }
|
---|
93 | }
|
---|
94 |
|
---|
95 | Group grpStatistics = new Group(shlModelProperties, SWT.NONE);
|
---|
96 | grpStatistics.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
|
---|
97 | grpStatistics.setText("Statistics");
|
---|
98 | grpStatistics.setLayout(new GridLayout(2, false));
|
---|
99 |
|
---|
100 | Label lblNumEvents = new Label(grpStatistics, SWT.NONE);
|
---|
101 | lblNumEvents.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));
|
---|
102 | lblNumEvents.setText("Num. Events");
|
---|
103 |
|
---|
104 | Label label = new Label(grpStatistics, SWT.RIGHT);
|
---|
105 | label.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1));
|
---|
106 | label.setText("" + process.getNumSymbols());
|
---|
107 |
|
---|
108 | Label lblNumTrieLeafs = new Label(grpStatistics, SWT.NONE);
|
---|
109 | lblNumTrieLeafs.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));
|
---|
110 | lblNumTrieLeafs.setText("Size (Flattend FOM)");
|
---|
111 |
|
---|
112 | Label label_1 = new Label(grpStatistics, SWT.RIGHT);
|
---|
113 | label_1.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1));
|
---|
114 | label_1.setText("" + process.getNumFOMStates());
|
---|
115 |
|
---|
116 | Label lblEntropy = new Label(grpStatistics, SWT.NONE);
|
---|
117 | lblEntropy.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));
|
---|
118 | lblEntropy.setText("Entropy");
|
---|
119 |
|
---|
120 | final Label label_2 = new Label(grpStatistics, SWT.RIGHT);
|
---|
121 | label_2.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));
|
---|
122 | label_2.setText("####");
|
---|
123 |
|
---|
124 | Button btnCalculateEntropy = new Button(shlModelProperties, SWT.NONE);
|
---|
125 | btnCalculateEntropy.addSelectionListener(new SelectionAdapter() {
|
---|
126 | @Override
|
---|
127 | public void widgetSelected(SelectionEvent e) {
|
---|
128 | if (process instanceof FirstOrderMarkovModel) {
|
---|
129 | label_2.setText("" + ((FirstOrderMarkovModel) process).calcEntropy());
|
---|
130 | }
|
---|
131 | else {
|
---|
132 | MessageBox messageBox = new MessageBox(shlModelProperties, SWT.NONE);
|
---|
133 | messageBox.setText("Feature Not Available");
|
---|
134 | messageBox
|
---|
135 | .setMessage("The feature is currently only available for first-order Markov models.");
|
---|
136 | messageBox.open();
|
---|
137 | }
|
---|
138 | }
|
---|
139 | });
|
---|
140 | btnCalculateEntropy.setText("Calculate Entropy");
|
---|
141 |
|
---|
142 | Button btnClose = new Button(shlModelProperties, SWT.NONE);
|
---|
143 | btnClose.addSelectionListener(new SelectionAdapter() {
|
---|
144 | @Override
|
---|
145 | public void widgetSelected(SelectionEvent e) {
|
---|
146 | shlModelProperties.dispose();
|
---|
147 | }
|
---|
148 | });
|
---|
149 | btnClose.setText("Close");
|
---|
150 |
|
---|
151 | }
|
---|
152 |
|
---|
153 | public void setStochasticProcess(IStochasticProcess process) {
|
---|
154 | this.process = process;
|
---|
155 | }
|
---|
156 | }
|
---|