source: trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/swt/ModelPropertiesDialog.java @ 381

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