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

Last change on this file since 238 was 238, checked in by sherbold, 13 years ago
  • beautification of SWT console output; trace messages are now displayed in blue, errors in red
  • 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               
63                Button btnEnter = new Button(this, SWT.NONE);
64                btnEnter.addSelectionListener(new SelectionAdapter() {
65                        @Override
66                        public void widgetSelected(SelectionEvent e) {
67                                executeCommand();
68                        }
69                });
70                btnEnter.setText("Enter");
71               
72                textConsoleOutput = new StyledText(this, SWT.BORDER | SWT.READ_ONLY | SWT.H_SCROLL | SWT.V_SCROLL | SWT.CANCEL);
73                GridData gd_textConsoleOutput = new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1);
74                gd_textConsoleOutput.heightHint = 102;
75                gd_textConsoleOutput.widthHint = 456;
76                textConsoleOutput.setLayoutData(gd_textConsoleOutput);
77        }
78       
79        private void executeCommand() {
80                String command = textCommand.getText().trim();
81                CommandExecuter.getInstance().exec(command);
82                textCommand.setText("");
83        }
84
85        @Override
86        protected void checkSubclass() {
87                // Disable the check that prevents subclassing of SWT components
88        }
89
90}
Note: See TracBrowser for help on using the repository browser.