Changeset 195 for trunk/EventBenchConsole/src/de/ugoe/cs
- Timestamp:
- 09/26/11 20:24:03 (13 years ago)
- Location:
- trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/swt
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/swt/CommandHistoryDialog.java
r192 r195 1 1 package de.ugoe.cs.eventbench.swt; 2 3 import java.awt.Toolkit; 4 import java.awt.datatransfer.Clipboard; 5 import java.awt.datatransfer.StringSelection; 6 import java.io.File; 7 import java.io.FileOutputStream; 8 import java.io.IOException; 9 import java.io.OutputStreamWriter; 10 import java.util.LinkedList; 2 11 3 12 import org.eclipse.swt.widgets.Dialog; 4 13 import org.eclipse.swt.widgets.Display; 14 import org.eclipse.swt.widgets.FileDialog; 5 15 import org.eclipse.swt.widgets.Shell; 6 16 import org.eclipse.swt.widgets.List; … … 11 21 import org.eclipse.swt.layout.GridData; 12 22 13 public class CommandHistoryDialog extends Dialog { 14 23 import de.ugoe.cs.util.StringTools; 24 import de.ugoe.cs.util.console.CommandExecuter; 25 import de.ugoe.cs.util.console.Console; 26 import de.ugoe.cs.util.console.ConsoleObserver; 27 import org.eclipse.swt.events.DisposeListener; 28 import org.eclipse.swt.events.DisposeEvent; 29 import org.eclipse.swt.events.SelectionAdapter; 30 import org.eclipse.swt.events.SelectionEvent; 31 32 public class CommandHistoryDialog extends Dialog implements ConsoleObserver { 33 34 protected java.util.List<String> history = new LinkedList<String>(); 35 36 protected List commandHistoryList; 15 37 protected Object result; 16 38 protected Shell shell; 39 40 boolean isOpen; 17 41 18 42 /** … … 23 47 public CommandHistoryDialog(Shell parent, int style) { 24 48 super(parent, style); 25 setText("SWT Dialog"); 49 setText("Command History"); 50 isOpen = false; 51 Console.getInstance().registerObserver(this); 26 52 } 27 53 … … 34 60 shell.open(); 35 61 shell.layout(); 62 isOpen = true; 36 63 Display display = getParent().getDisplay(); 37 64 while (!shell.isDisposed()) { … … 47 74 */ 48 75 private void createContents() { 49 shell = new Shell(getParent(), SWT.DIALOG_TRIM); 76 shell = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.RESIZE); 77 shell.addDisposeListener(new DisposeListener() { 78 public void widgetDisposed(DisposeEvent arg0) { 79 isOpen = false; 80 } 81 }); 50 82 shell.setSize(450, 300); 51 83 shell.setText(getText()); … … 57 89 new Label(shell, SWT.NONE); 58 90 59 List list = new List(shell, SWT.BORDER | SWT.V_SCROLL | SWT.MULTI); 60 list.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1)); 91 commandHistoryList = new List(shell, SWT.BORDER | SWT.V_SCROLL | SWT.MULTI); 92 commandHistoryList.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1)); 93 for( String command : history ) { 94 commandHistoryList.add(command); 95 } 61 96 62 97 Button btnExec = new Button(shell, SWT.NONE); 98 btnExec.addSelectionListener(new SelectionAdapter() { 99 @Override 100 public void widgetSelected(SelectionEvent e) { 101 for( String command : commandHistoryList.getSelection() ) { 102 CommandExecuter.getInstance().exec(command); 103 } 104 } 105 }); 63 106 btnExec.setText("Execute"); 64 107 65 108 Button btnCopyToClipboard = new Button(shell, SWT.NONE); 109 btnCopyToClipboard.addSelectionListener(new SelectionAdapter() { 110 @Override 111 public void widgetSelected(SelectionEvent e) { 112 Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); 113 StringSelection content = new StringSelection(getSelectedCommands()); 114 clipboard.setContents(content, null); 115 } 116 }); 66 117 btnCopyToClipboard.setText("Copy to Clipboard"); 67 118 68 119 Button btnCreateBatchfile = new Button(shell, SWT.NONE); 120 btnCreateBatchfile.addSelectionListener(new SelectionAdapter() { 121 @Override 122 public void widgetSelected(SelectionEvent event) { 123 FileDialog fileDialog = new FileDialog(shell, SWT.SAVE); 124 String filename = fileDialog.open(); 125 if( filename!=null ) { 126 File file = new File(filename); 127 boolean fileCreated; 128 try { 129 fileCreated = file.createNewFile(); 130 if (!fileCreated) { 131 Console.traceln("Created batchfile " + filename); 132 } else { 133 Console.traceln("Overwrote file " + filename); 134 } 135 } catch (IOException e) { 136 Console.printerrln("Unable to create file " + filename); 137 Console.printStacktrace(e); 138 } 139 OutputStreamWriter writer = null; 140 try { 141 writer = new OutputStreamWriter(new FileOutputStream(file)); 142 } catch (IOException e) { 143 Console.printerrln("Unable to open file for writing (read-only file):" 144 + filename); 145 Console.printStacktrace(e); 146 } 147 try { 148 writer.write(getSelectedCommands()); 149 writer.close(); 150 } catch (IOException e) { 151 Console.printerrln("Unable to write to file."); 152 Console.printStacktrace(e); 153 } 154 } 155 } 156 }); 69 157 btnCreateBatchfile.setText("Create Batchfile"); 70 158 71 159 } 160 161 @Override 162 public void updateText(String newMessage) { 163 // ignore 164 } 165 166 @Override 167 public void errStream(String errMessage) { 168 // ignore 169 } 170 171 @Override 172 public void trace(String traceMessage) { 173 // ignore 174 } 175 176 @Override 177 public void printStacktrace(Exception e) { 178 // ignore 179 180 } 181 182 @Override 183 public void commandNotification(String command) { 184 history.add(command); 185 if( isOpen ) { 186 commandHistoryList.add(command); 187 } 188 } 189 190 public boolean isOpen() { 191 return isOpen; 192 } 193 194 private String getSelectedCommands() { 195 StringBuilder commands = new StringBuilder(); 196 for( String command : commandHistoryList.getSelection()) { 197 commands.append(command + StringTools.ENDLINE); 198 } 199 return commands.toString(); 200 } 72 201 } -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/swt/ConsoleTabComposite.java
r192 r195 69 69 btnEnter.setText("Enter"); 70 70 71 textConsoleOutput = new Text(this, SWT.BORDER | SWT. H_SCROLL | SWT.V_SCROLL | SWT.CANCEL);71 textConsoleOutput = new Text(this, SWT.BORDER | SWT.READ_ONLY | SWT.H_SCROLL | SWT.V_SCROLL | SWT.CANCEL); 72 72 GridData gd_textConsoleOutput = new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1); 73 73 gd_textConsoleOutput.heightHint = 102; -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/swt/MainWindow.java
r192 r195 5 5 import org.eclipse.swt.widgets.Menu; 6 6 import org.eclipse.swt.SWT; 7 import org.eclipse.swt.widgets.FileDialog; 7 8 import org.eclipse.swt.widgets.MenuItem; 8 9 import org.eclipse.swt.widgets.Text; … … 13 14 import org.eclipse.swt.events.SelectionAdapter; 14 15 import org.eclipse.swt.events.SelectionEvent; 16 17 import de.ugoe.cs.util.console.CommandExecuter; 15 18 16 19 public class MainWindow { … … 26 29 protected ModelsTabComposite modelsTabComposite; 27 30 protected DataTabComposite dataTabComposite; 31 32 protected CommandHistoryDialog historyDialog; 28 33 29 34 … … 36 41 createContents(); 37 42 new SWTConsole(getTextConsoleOutput()); 43 historyDialog = new CommandHistoryDialog(shell, SWT.NONE); 38 44 shell.open(); 39 45 shell.layout(); … … 64 70 65 71 MenuItem mntmShowHistory = new MenuItem(menu_1, SWT.NONE); 72 mntmShowHistory.addSelectionListener(new SelectionAdapter() { 73 @Override 74 public void widgetSelected(SelectionEvent e) { 75 if( !historyDialog.isOpen()) { 76 historyDialog.open(); 77 } 78 } 79 }); 66 80 mntmShowHistory.setText("Show History"); 67 81 68 82 MenuItem mntmExecBatchFile = new MenuItem(menu_1, SWT.NONE); 83 mntmExecBatchFile.addSelectionListener(new SelectionAdapter() { 84 @Override 85 public void widgetSelected(SelectionEvent e) { 86 FileDialog fileDialog = new FileDialog(shell, SWT.OPEN); 87 String filename = fileDialog.open(); 88 if( filename!=null ) { 89 String command = "exec '" + filename + "'"; 90 CommandExecuter.getInstance().exec(command); 91 } 92 } 93 }); 69 94 mntmExecBatchFile.setText("Exec. Batch File"); 70 95 … … 72 97 73 98 MenuItem mntmLoad = new MenuItem(menu_1, SWT.NONE); 99 mntmLoad.addSelectionListener(new SelectionAdapter() { 100 @Override 101 public void widgetSelected(SelectionEvent e) { 102 FileDialog fileDialog = new FileDialog(shell, SWT.OPEN); 103 String filename = fileDialog.open(); 104 if( filename!=null ) { 105 String command = "load '" + filename + "'"; 106 CommandExecuter.getInstance().exec(command); 107 } 108 } 109 }); 74 110 mntmLoad.setText("Load..."); 75 111 76 112 MenuItem mntmSave = new MenuItem(menu_1, SWT.NONE); 113 mntmSave.addSelectionListener(new SelectionAdapter() { 114 @Override 115 public void widgetSelected(SelectionEvent e) { 116 FileDialog fileDialog = new FileDialog(shell, SWT.SAVE); 117 String filename = fileDialog.open(); 118 if( filename!=null ) { 119 String command = "save '" + filename + "'"; 120 CommandExecuter.getInstance().exec(command); 121 } 122 } 123 }); 77 124 mntmSave.setText("Save..."); 78 125 … … 80 127 81 128 MenuItem mntmExit = new MenuItem(menu_1, SWT.NONE); 129 mntmExit.addSelectionListener(new SelectionAdapter() { 130 @Override 131 public void widgetSelected(SelectionEvent e) { 132 shell.dispose(); 133 } 134 }); 82 135 mntmExit.setText("Exit"); 83 136 … … 89 142 90 143 MenuItem mntmAbout = new MenuItem(menu_2, SWT.NONE); 144 mntmAbout.addSelectionListener(new SelectionAdapter() { 145 @Override 146 public void widgetSelected(SelectionEvent e) { 147 AboutDialog aboutDialog = new AboutDialog(shell, SWT.NONE); 148 aboutDialog.open(); 149 } 150 }); 91 151 mntmAbout.setText("About"); 92 152 … … 125 185 modelsTabComposite = new ModelsTabComposite(tabFolder, SWT.NO_BACKGROUND); 126 186 modelsTab.setControl(modelsTabComposite); 127 187 128 188 dataTab = new TabItem(tabFolder, SWT.NONE); 129 189 dataTab.setText("Data"); -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/swt/ModelPropertiesDialog.java
r194 r195 121 121 122 122 Button btnClose = new Button(shlModelProperties, SWT.NONE); 123 btnClose.addSelectionListener(new SelectionAdapter() { 124 @Override 125 public void widgetSelected(SelectionEvent e) { 126 shlModelProperties.dispose(); 127 } 128 }); 123 129 btnClose.setText("Close"); 124 130 -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/swt/SequencesTabComposite.java
r192 r195 8 8 import org.eclipse.swt.widgets.FileDialog; 9 9 import org.eclipse.swt.widgets.List; 10 import org.eclipse.swt.widgets.MessageBox; 10 11 import org.eclipse.swt.layout.GridLayout; 11 12 import org.eclipse.swt.layout.GridData; … … 38 39 39 40 Button btnEdit = new Button(this, SWT.NONE); 41 btnEdit.addSelectionListener(new SelectionAdapter() { 42 @Override 43 public void widgetSelected(SelectionEvent e) { 44 // TODO implement edit sequences. 45 MessageBox messageBox = new MessageBox(getShell(), SWT.ICON_INFORMATION); 46 messageBox.setText("Not implemented!"); 47 messageBox.setMessage("Sorry! This functionality has not been implemented yet!"); 48 messageBox.open(); 49 } 50 }); 40 51 btnEdit.setText("Edit"); 41 52 … … 91 102 92 103 Button btnParse = new Button(this, SWT.NONE); 104 btnParse.addSelectionListener(new SelectionAdapter() { 105 @Override 106 public void widgetSelected(SelectionEvent e) { 107 // TODO implement parsing of sequences 108 MessageBox messageBox = new MessageBox(getShell(), SWT.ICON_INFORMATION); 109 messageBox.setText("Not implemented!"); 110 messageBox.setMessage("Sorry! This functionality has not been implemented yet!"); 111 messageBox.open(); 112 } 113 }); 93 114 btnParse.setText("Parse"); 94 115 }
Note: See TracChangeset
for help on using the changeset viewer.