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