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