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

Last change on this file since 927 was 927, checked in by sherbold, 12 years ago
  • added copyright under the Apache License, Version 2.0
  • Property svn:mime-type set to text/plain
File size: 3.8 KB
Line 
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
15package de.ugoe.cs.autoquest.ui.swt;
16
17import org.eclipse.swt.SWT;
18import org.eclipse.swt.widgets.Event;
19import org.eclipse.swt.widgets.Listener;
20import org.eclipse.swt.widgets.Text;
21import org.eclipse.swt.widgets.Label;
22import org.eclipse.swt.widgets.Composite;
23import org.eclipse.swt.widgets.Button;
24import org.eclipse.swt.layout.GridLayout;
25import org.eclipse.swt.layout.GridData;
26import org.eclipse.swt.custom.StyledText;
27import org.eclipse.swt.events.SelectionAdapter;
28import org.eclipse.swt.events.SelectionEvent;
29
30import org.eclipse.swt.events.KeyAdapter;
31import org.eclipse.swt.events.KeyEvent;
32
33import de.ugoe.cs.util.console.CommandExecuter;
34
35/**
36 * <p>
37 * Implements the composite for the console tab in the applications main window.
38 * </p>
39 *
40 * @author Steffen Herbold
41 * @version 1.0
42 */
43public class ConsoleTabComposite extends Composite {
44
45    protected Text textCommand;
46
47    protected StyledText textConsoleOutput;
48
49    /**
50     * Create the composite.
51     *
52     * @param parent
53     * @param style
54     */
55    public ConsoleTabComposite(Composite parent, int style) {
56        super(parent, style);
57        createContents();
58    }
59
60    private void createContents() {
61        setLayout(new GridLayout(3, false));
62
63        Label lblCommand = new Label(this, SWT.NONE);
64        lblCommand.setText("Command:");
65
66        textCommand = new Text(this, SWT.BORDER);
67        textCommand.addKeyListener(new KeyAdapter() {
68            @Override
69            public void keyReleased(KeyEvent e) {
70                if (e.keyCode == SWT.CR) {
71                    executeCommand();
72                }
73            }
74        });
75        GridData gd_textCommand = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
76        gd_textCommand.widthHint = 304;
77        textCommand.setLayoutData(gd_textCommand);
78        textCommand.setFocus();
79
80        Button btnEnter = new Button(this, SWT.NONE);
81        btnEnter.addSelectionListener(new SelectionAdapter() {
82            @Override
83            public void widgetSelected(SelectionEvent e) {
84                executeCommand();
85            }
86        });
87        btnEnter.setText("Enter");
88
89        textConsoleOutput =
90            new StyledText(this, SWT.BORDER | SWT.READ_ONLY | SWT.H_SCROLL | SWT.V_SCROLL |
91                SWT.CANCEL);
92        GridData gd_textConsoleOutput = new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1);
93        gd_textConsoleOutput.heightHint = 102;
94        gd_textConsoleOutput.widthHint = 456;
95        textConsoleOutput.setLayoutData(gd_textConsoleOutput);
96        textConsoleOutput.addListener(SWT.Modify, new Listener() {
97            public void handleEvent(Event e) {
98                textConsoleOutput.setTopIndex(textConsoleOutput.getLineCount() - 1);
99            }
100        });
101
102    }
103
104    private void executeCommand() {
105        String command = textCommand.getText().trim();
106        CommandExecuter.getInstance().exec(command);
107        textCommand.setText("");
108    }
109
110    @Override
111    protected void checkSubclass() {
112        // Disable the check that prevents subclassing of SWT components
113    }
114
115}
Note: See TracBrowser for help on using the repository browser.