source: trunk/quest-ui-swt/src/main/java/de/ugoe/cs/quest/ui/swt/ModelPropertiesDialog.java @ 570

Last change on this file since 570 was 570, checked in by sherbold, 12 years ago
  • adapted to quest coding style
  • Property svn:mime-type set to text/plain
File size: 5.2 KB
Line 
1
2package de.ugoe.cs.quest.ui.swt;
3
4import org.eclipse.swt.widgets.Dialog;
5import org.eclipse.swt.widgets.Display;
6import org.eclipse.swt.widgets.MessageBox;
7import org.eclipse.swt.widgets.Shell;
8import org.eclipse.swt.widgets.List;
9import org.eclipse.swt.SWT;
10import org.eclipse.swt.widgets.Group;
11import org.eclipse.swt.widgets.Label;
12import org.eclipse.swt.widgets.Button;
13import org.eclipse.swt.layout.GridLayout;
14import org.eclipse.swt.layout.GridData;
15import org.eclipse.swt.layout.FillLayout;
16
17import de.ugoe.cs.quest.usageprofiles.FirstOrderMarkovModel;
18import de.ugoe.cs.quest.usageprofiles.IStochasticProcess;
19
20import org.eclipse.swt.events.SelectionAdapter;
21import org.eclipse.swt.events.SelectionEvent;
22
23public class ModelPropertiesDialog extends Dialog {
24
25    private IStochasticProcess process;
26
27    protected Shell shlModelProperties;
28
29    /**
30     * Create the dialog.
31     *
32     * @param parent
33     * @param style
34     */
35    public ModelPropertiesDialog(Shell parent, int style) {
36        super(parent, style);
37        setText("SWT Dialog");
38    }
39
40    /**
41     * Open the dialog.
42     */
43    public void open() {
44        createContents();
45        shlModelProperties.open();
46        shlModelProperties.layout();
47        Display display = getParent().getDisplay();
48        while (!shlModelProperties.isDisposed()) {
49            if (!display.readAndDispatch()) {
50                display.sleep();
51            }
52        }
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.H_SCROLL | SWT.V_SCROLL);
73        for (String symbol : process.getSymbolStrings()) {
74            if (symbol == null) {
75                list.add("null");
76            }
77            else {
78                list.add(symbol);
79            }
80        }
81
82        Group grpStatistics = new Group(shlModelProperties, SWT.NONE);
83        grpStatistics.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
84        grpStatistics.setText("Statistics");
85        grpStatistics.setLayout(new GridLayout(2, false));
86
87        Label lblNumEvents = new Label(grpStatistics, SWT.NONE);
88        lblNumEvents.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));
89        lblNumEvents.setText("Num. Events");
90
91        Label label = new Label(grpStatistics, SWT.RIGHT);
92        label.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1));
93        label.setText("" + process.getNumSymbols());
94
95        Label lblNumTrieLeafs = new Label(grpStatistics, SWT.NONE);
96        lblNumTrieLeafs.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));
97        lblNumTrieLeafs.setText("Size (Flattend FOM)");
98
99        Label label_1 = new Label(grpStatistics, SWT.RIGHT);
100        label_1.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1));
101        label_1.setText("" + process.getNumFOMStates());
102
103        Label lblEntropy = new Label(grpStatistics, SWT.NONE);
104        lblEntropy.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));
105        lblEntropy.setText("Entropy");
106
107        final Label label_2 = new Label(grpStatistics, SWT.RIGHT);
108        label_2.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));
109        label_2.setText("####");
110
111        Button btnCalculateEntropy = new Button(shlModelProperties, SWT.NONE);
112        btnCalculateEntropy.addSelectionListener(new SelectionAdapter() {
113            @Override
114            public void widgetSelected(SelectionEvent e) {
115                if (process instanceof FirstOrderMarkovModel) {
116                    label_2.setText("" + ((FirstOrderMarkovModel) process).calcEntropy());
117                }
118                else {
119                    MessageBox messageBox = new MessageBox(shlModelProperties, SWT.NONE);
120                    messageBox.setText("Feature Not Available");
121                    messageBox
122                        .setMessage("The feature is currently only available for first-order Markov models.");
123                    messageBox.open();
124                }
125            }
126        });
127        btnCalculateEntropy.setText("Calculate Entropy");
128
129        Button btnClose = new Button(shlModelProperties, SWT.NONE);
130        btnClose.addSelectionListener(new SelectionAdapter() {
131            @Override
132            public void widgetSelected(SelectionEvent e) {
133                shlModelProperties.dispose();
134            }
135        });
136        btnClose.setText("Close");
137
138    }
139
140    public void setStochasticProcess(IStochasticProcess process) {
141        this.process = process;
142    }
143}
Note: See TracBrowser for help on using the repository browser.