source: trunk/autoquest-ui-swt/src/main/java/de/ugoe/cs/autoquest/ui/swt/MainWindow.java @ 2218

Last change on this file since 2218 was 2218, checked in by pharms, 7 years ago
  • java doc issues removal
  • Property svn:mime-type set to text/plain
File size: 9.5 KB
RevLine 
[927]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
[922]15package de.ugoe.cs.autoquest.ui.swt;
[526]16
17import java.util.List;
[674]18import java.util.logging.Level;
[526]19
20import org.eclipse.swt.widgets.Display;
21import org.eclipse.swt.widgets.Shell;
22import org.eclipse.swt.widgets.Menu;
23import org.eclipse.swt.SWT;
24import org.eclipse.swt.widgets.FileDialog;
25import org.eclipse.swt.widgets.MenuItem;
26import org.eclipse.swt.widgets.TabFolder;
27import org.eclipse.swt.widgets.TabItem;
28import org.eclipse.swt.layout.GridLayout;
29import org.eclipse.swt.layout.GridData;
30import org.eclipse.swt.events.SelectionAdapter;
31import org.eclipse.swt.events.SelectionEvent;
32
33import de.ugoe.cs.util.console.CommandExecuter;
34
35/**
36 * <p>
37 * Main window of the SWT GUI.
38 * </p>
39 *
40 * @author Steffen Herbold
41 * @version 1.0
42 */
43public class MainWindow {
44
[570]45    private List<String> startupCommands;
[674]46   
47    private final Level traceLevel;
[526]48
[570]49    protected Shell shlEventbenchConsole;
[526]50
[570]51    protected TabItem consoleTab;
52    protected TabItem sequencesTab;
53    protected TabItem modelsTab;
[658]54    protected TabItem guiModelsTab;
[1495]55    protected TabItem usabilityTab;
[570]56    protected TabItem dataTab;
57    protected ConsoleTabComposite consoleTabComposite;
58    protected SequencesTabComposite sequencesTabComposite;
59    protected ModelsTabComposite modelsTabComposite;
[658]60    protected GuiModelTabComposite guiModelTabComposite;
[1495]61    protected UsabilityTabComposite usabilityTabComposite;
[570]62    protected DataTabComposite dataTabComposite;
[526]63
[570]64    protected CommandHistoryDialog historyDialog;
[526]65
[674]66    public MainWindow(List<String> startupCommands, Level traceLevel) {
[570]67        this.startupCommands = startupCommands;
[674]68        this.traceLevel = traceLevel;
[570]69    }
[526]70
[570]71    /**
72     * <p>
73     * Open the window.
74     * </p>
75     */
76    public void open() {
77        Display display = Display.getDefault();
78        createContents();
[674]79        new SWTConsole(consoleTabComposite.textConsoleOutput, traceLevel);
[570]80        historyDialog = new CommandHistoryDialog(shlEventbenchConsole, SWT.NONE);
81        shlEventbenchConsole.open();
82        shlEventbenchConsole.layout();
83        for (String command : startupCommands) {
84            CommandExecuter.getInstance().exec(command);
85        }
86        while (!shlEventbenchConsole.isDisposed()) {
87            if (!display.readAndDispatch()) {
88                display.sleep();
89            }
90        }
91    }
[526]92
[570]93    /**
94     * <p>
95     * Create contents of the window.
96     * </p>
97     */
98    protected void createContents() {
99        shlEventbenchConsole = new Shell();
100        shlEventbenchConsole.setSize(800, 600);
[1237]101        shlEventbenchConsole.setText("AutoQUEST Console");
[570]102        shlEventbenchConsole.setLayout(new GridLayout(1, false));
[526]103
[570]104        createMenu();
105        createTabs();
106    }
[526]107
[570]108    /**
109     * </p> Creates the menu of the window. </p>
110     */
111    private void createMenu() {
112        Menu menu = new Menu(shlEventbenchConsole, SWT.BAR);
113        shlEventbenchConsole.setMenuBar(menu);
[526]114
[570]115        MenuItem mntmFile = new MenuItem(menu, SWT.CASCADE);
116        mntmFile.setText("File");
[526]117
[570]118        Menu menu_1 = new Menu(mntmFile);
119        mntmFile.setMenu(menu_1);
[526]120
[570]121        MenuItem mntmShowHistory = new MenuItem(menu_1, SWT.NONE);
122        mntmShowHistory.addSelectionListener(new SelectionAdapter() {
123            @Override
124            public void widgetSelected(SelectionEvent e) {
125                if (!historyDialog.isOpen()) {
126                    historyDialog.open();
127                }
128            }
129        });
130        mntmShowHistory.setText("Show History");
[526]131
[570]132        MenuItem mntmExecBatchFile = new MenuItem(menu_1, SWT.NONE);
133        mntmExecBatchFile.addSelectionListener(new SelectionAdapter() {
134            @Override
135            public void widgetSelected(SelectionEvent e) {
136                FileDialog fileDialog = new FileDialog(shlEventbenchConsole, SWT.OPEN);
137                String filename = fileDialog.open();
138                if (filename != null) {
139                    String command = "exec '" + filename + "'";
140                    CommandExecuter.getInstance().exec(command);
141                }
142            }
143        });
144        mntmExecBatchFile.setText("Exec. Batch File");
[526]145
[570]146        new MenuItem(menu_1, SWT.SEPARATOR);
[526]147
[570]148        MenuItem mntmLoad = new MenuItem(menu_1, SWT.NONE);
149        mntmLoad.addSelectionListener(new SelectionAdapter() {
150            @Override
151            public void widgetSelected(SelectionEvent e) {
152                FileDialog fileDialog = new FileDialog(shlEventbenchConsole, SWT.OPEN);
153                String filename = fileDialog.open();
154                if (filename != null) {
155                    String command = "load '" + filename + "'";
156                    CommandExecuter.getInstance().exec(command);
157                }
158            }
159        });
160        mntmLoad.setText("Load...");
[526]161
[570]162        MenuItem mntmSave = new MenuItem(menu_1, SWT.NONE);
163        mntmSave.addSelectionListener(new SelectionAdapter() {
164            @Override
165            public void widgetSelected(SelectionEvent e) {
166                FileDialog fileDialog = new FileDialog(shlEventbenchConsole, SWT.SAVE);
167                String filename = fileDialog.open();
168                if (filename != null) {
169                    String command = "save '" + filename + "'";
170                    CommandExecuter.getInstance().exec(command);
171                }
172            }
173        });
174        mntmSave.setText("Save...");
[526]175
[570]176        new MenuItem(menu_1, SWT.SEPARATOR);
[526]177
[570]178        MenuItem mntmExit = new MenuItem(menu_1, SWT.NONE);
179        mntmExit.addSelectionListener(new SelectionAdapter() {
180            @Override
181            public void widgetSelected(SelectionEvent e) {
182                shlEventbenchConsole.dispose();
183            }
184        });
185        mntmExit.setText("Exit");
[526]186
[570]187        MenuItem mntmHelp = new MenuItem(menu, SWT.CASCADE);
188        mntmHelp.setText("Help");
[526]189
[570]190        Menu menu_2 = new Menu(mntmHelp);
191        mntmHelp.setMenu(menu_2);
[526]192
[570]193        MenuItem mntmAbout = new MenuItem(menu_2, SWT.NONE);
194        mntmAbout.addSelectionListener(new SelectionAdapter() {
195            @Override
196            public void widgetSelected(SelectionEvent e) {
197                AboutDialog aboutDialog = new AboutDialog(shlEventbenchConsole, SWT.NONE);
198                aboutDialog.open();
199            }
200        });
201        mntmAbout.setText("About");
202    }
[526]203
[570]204    /**
205     * <p>
206     * Creates the central TabFolder of the window.
207     * </p>
208     */
209    private void createTabs() {
210        TabFolder tabFolder = new TabFolder(shlEventbenchConsole, SWT.NONE);
211        tabFolder.addSelectionListener(new SelectionAdapter() {
212            @Override
213            public void widgetSelected(SelectionEvent e) {
214                if (e.item == sequencesTab) {
215                    sequencesTabComposite.updateSequenceList();
216                }
217                else if (e.item == modelsTab) {
218                    modelsTabComposite.updateModelList();
219                }
[658]220                else if (e.item == guiModelsTab) {
221                    guiModelTabComposite.updateModelList();
222                }
[1495]223                else if (e.item == usabilityTab) {
224                    usabilityTabComposite.updateResultList();
225                }
[570]226                else if (e.item == dataTab) {
227                    dataTabComposite.updateDataList();
228                }
229            }
230        });
231        tabFolder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
[526]232
[570]233        consoleTab = new TabItem(tabFolder, SWT.NONE);
234        consoleTab.setText("Console");
[526]235
[570]236        consoleTabComposite = new ConsoleTabComposite(tabFolder, SWT.NO_BACKGROUND);
237        consoleTab.setControl(consoleTabComposite);
[526]238
[570]239        sequencesTab = new TabItem(tabFolder, SWT.NONE);
240        sequencesTab.setText("Sequences");
[526]241
[570]242        sequencesTabComposite = new SequencesTabComposite(tabFolder, SWT.NO_BACKGROUND);
243        sequencesTab.setControl(sequencesTabComposite);
[526]244
[570]245        modelsTab = new TabItem(tabFolder, SWT.NONE);
246        modelsTab.setText("Models");
[526]247
[570]248        modelsTabComposite = new ModelsTabComposite(tabFolder, SWT.NO_BACKGROUND);
249        modelsTab.setControl(modelsTabComposite);
[658]250       
251        guiModelsTab = new TabItem(tabFolder, SWT.NONE);
252        guiModelsTab.setText("GUI Models");
[570]253
[658]254        guiModelTabComposite = new GuiModelTabComposite(tabFolder, SWT.NO_BACKGROUND);
255        guiModelsTab.setControl(guiModelTabComposite);
256
[1495]257        usabilityTab = new TabItem(tabFolder, SWT.NONE);
258        usabilityTab.setText("Usability Evaluation Results");
259
260        usabilityTabComposite = new UsabilityTabComposite(tabFolder, SWT.NO_BACKGROUND);
261        usabilityTab.setControl(usabilityTabComposite);
262
[570]263        dataTab = new TabItem(tabFolder, SWT.NONE);
264        dataTab.setText("Data");
265
266        dataTabComposite = new DataTabComposite(tabFolder, SWT.NO_BACKGROUND);
267        dataTab.setControl(dataTabComposite);
268    }
[526]269}
Note: See TracBrowser for help on using the repository browser.