source: trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/swt/ConsoleTabComposite.java @ 204

Last change on this file since 204 was 195, checked in by sherbold, 13 years ago

Further work on the SWT GUI prototype.
The GUI is still not finished, however, most features are implemented and the GUI can be used. It may cause some problems, and some features are still missing.

  • Property svn:mime-type set to text/plain
File size: 2.4 KB
Line 
1package de.ugoe.cs.eventbench.swt;
2
3import org.eclipse.swt.SWT;
4import org.eclipse.swt.widgets.Text;
5import org.eclipse.swt.widgets.Label;
6import org.eclipse.swt.widgets.Composite;
7import org.eclipse.swt.widgets.Button;
8import org.eclipse.swt.layout.GridLayout;
9import org.eclipse.swt.layout.GridData;
10import org.eclipse.swt.events.SelectionAdapter;
11import org.eclipse.swt.events.SelectionEvent;
12
13import org.eclipse.swt.events.KeyAdapter;
14import org.eclipse.swt.events.KeyEvent;
15
16
17import de.ugoe.cs.util.console.CommandExecuter;
18
19/**
20 * <p>
21 * Implements the composite for the console tab in the applications main window.
22 * </p>
23 *
24 * @author Steffen Herbold
25 * @version 1.0
26 */
27public class ConsoleTabComposite extends Composite {
28
29        protected Text textCommand;
30       
31        protected Text textConsoleOutput;
32       
33        /**
34         * Create the composite.
35         * @param parent
36         * @param style
37         */
38        public ConsoleTabComposite(Composite parent, int style) {
39                super(parent, style);
40                createContents();
41        }
42       
43        private void createContents() {
44                setLayout(new GridLayout(3, false));
45               
46                Label lblCommand = new Label(this, SWT.NONE);
47                lblCommand.setText("Command:");
48               
49                textCommand = new Text(this, SWT.BORDER);
50                textCommand.addKeyListener(new KeyAdapter() {
51                        @Override
52                        public void keyReleased(KeyEvent e) {
53                                if( e.keyCode==SWT.CR ) {
54                                        executeCommand();
55                                }
56                        }
57                });
58                GridData gd_textCommand = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
59                gd_textCommand.widthHint = 304;
60                textCommand.setLayoutData(gd_textCommand);
61               
62                Button btnEnter = new Button(this, SWT.NONE);
63                btnEnter.addSelectionListener(new SelectionAdapter() {
64                        @Override
65                        public void widgetSelected(SelectionEvent e) {
66                                executeCommand();
67                        }
68                });
69                btnEnter.setText("Enter");
70               
71                textConsoleOutput = new Text(this, SWT.BORDER | SWT.READ_ONLY | SWT.H_SCROLL | SWT.V_SCROLL | SWT.CANCEL);
72                GridData gd_textConsoleOutput = new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1);
73                gd_textConsoleOutput.heightHint = 102;
74                gd_textConsoleOutput.widthHint = 456;
75                textConsoleOutput.setLayoutData(gd_textConsoleOutput);
76        }
77       
78        private void executeCommand() {
79                String command = textCommand.getText().trim();
80                CommandExecuter.getInstance().exec(command);
81                textCommand.setText("");
82        }
83
84        @Override
85        protected void checkSubclass() {
86                // Disable the check that prevents subclassing of SWT components
87        }
88
89}
Note: See TracBrowser for help on using the repository browser.