| 1 | package de.ugoe.cs.eventbench.swt;
|
|---|
| 2 |
|
|---|
| 3 | import org.eclipse.swt.SWT;
|
|---|
| 4 | import org.eclipse.swt.widgets.Text;
|
|---|
| 5 | import org.eclipse.swt.widgets.Label;
|
|---|
| 6 | import org.eclipse.swt.widgets.Composite;
|
|---|
| 7 | import org.eclipse.swt.widgets.Button;
|
|---|
| 8 | import org.eclipse.swt.layout.GridLayout;
|
|---|
| 9 | import org.eclipse.swt.layout.GridData;
|
|---|
| 10 | import org.eclipse.swt.custom.StyledText;
|
|---|
| 11 | import org.eclipse.swt.events.SelectionAdapter;
|
|---|
| 12 | import org.eclipse.swt.events.SelectionEvent;
|
|---|
| 13 |
|
|---|
| 14 | import org.eclipse.swt.events.KeyAdapter;
|
|---|
| 15 | import org.eclipse.swt.events.KeyEvent;
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 | import 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 | */
|
|---|
| 28 | public 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 | }
|
|---|