Changeset 1236 for trunk/autoquest-ui-swt/src/main/java/de/ugoe
- Timestamp:
- 06/27/13 17:14:16 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-ui-swt/src/main/java/de/ugoe/cs/autoquest/ui/swt/ConsoleTabComposite.java
r927 r1236 15 15 package de.ugoe.cs.autoquest.ui.swt; 16 16 17 import java.util.LinkedList; 18 17 19 import org.eclipse.swt.SWT; 18 20 import org.eclipse.swt.widgets.Event; … … 27 29 import org.eclipse.swt.events.SelectionAdapter; 28 30 import org.eclipse.swt.events.SelectionEvent; 31 import org.eclipse.swt.events.TraverseEvent; 32 import org.eclipse.swt.events.TraverseListener; 29 33 30 34 import org.eclipse.swt.events.KeyAdapter; … … 32 36 33 37 import de.ugoe.cs.util.console.CommandExecuter; 38 import de.ugoe.cs.util.console.Console; 39 import de.ugoe.cs.util.console.listener.ICommandListener; 34 40 35 41 /** … … 41 47 * @version 1.0 42 48 */ 43 public class ConsoleTabComposite extends Composite { 49 public class ConsoleTabComposite extends Composite implements ICommandListener { 50 51 protected java.util.List<String> commandHistory = new LinkedList<String>(); 44 52 45 53 protected Text textCommand; … … 56 64 super(parent, style); 57 65 createContents(); 66 Console.getInstance().registerCommandListener(this); 67 } 68 69 @Override 70 public void commandNotification(String command) { 71 commandHistory.add(command); 58 72 } 59 73 … … 71 85 executeCommand(); 72 86 } 87 else if (e.keyCode == SWT.TAB) { 88 autoCompleteCommand(); 89 } 90 else if (e.keyCode == SWT.ARROW_UP) { 91 setToPreviousCommand(); 92 } 93 else if (e.keyCode == SWT.ARROW_DOWN) { 94 setToNextCommand(); 95 } 73 96 } 74 97 }); 98 textCommand.addTraverseListener(new TraverseListener() { 99 @Override 100 public void keyTraversed(TraverseEvent e) { 101 if ((e.detail == SWT.TRAVERSE_TAB_NEXT) || (e.detail == SWT.TRAVERSE_TAB_PREVIOUS)) 102 { 103 e.doit = false; 104 } 105 } 106 107 }); 108 75 109 GridData gd_textCommand = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1); 76 110 gd_textCommand.widthHint = 304; … … 108 142 } 109 143 144 private void autoCompleteCommand() { 145 String commandPrefix = textCommand.getText().trim(); 146 String completedPrefix = CommandExecuter.getInstance().autoCompleteCommand(commandPrefix); 147 148 textCommand.setText(completedPrefix.toString()); 149 textCommand.setSelection(completedPrefix.length()); 150 } 151 152 private void setToPreviousCommand() { 153 String currentCommand = textCommand.getText().trim(); 154 155 int index = 0; 156 for (index = 0; index < commandHistory.size(); index++) { 157 if (currentCommand.equals(commandHistory.get(index))) { 158 break; 159 } 160 } 161 162 if (index > 0) { 163 textCommand.setText(commandHistory.get(index - 1)); 164 textCommand.setSelection(commandHistory.get(index - 1).length()); 165 } 166 } 167 168 private void setToNextCommand() { 169 String currentCommand = textCommand.getText().trim(); 170 171 int index = 0; 172 for (index = 0; index < commandHistory.size(); index++) { 173 if (currentCommand.equals(commandHistory.get(index))) { 174 break; 175 } 176 } 177 178 if (index < (commandHistory.size() - 1)) { 179 textCommand.setText(commandHistory.get(index + 1)); 180 textCommand.setSelection(commandHistory.get(index + 1).length()); 181 } 182 } 183 110 184 @Override 111 185 protected void checkSubclass() {
Note: See TracChangeset
for help on using the changeset viewer.