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

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