Changeset 570 for trunk/quest-ui-swt/src/main/java/de/ugoe/cs/quest
- Timestamp:
- 08/17/12 11:38:43 (12 years ago)
- Location:
- trunk/quest-ui-swt/src/main/java/de/ugoe/cs/quest/ui/swt
- Files:
-
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/quest-ui-swt/src/main/java/de/ugoe/cs/quest/ui/swt/AboutDialog.java
r526 r570 1 1 2 package de.ugoe.cs.quest.ui.swt; 2 3 … … 14 15 public class AboutDialog extends Dialog { 15 16 16 17 17 protected Shell shlAboutEventbenchconsole; 18 private final FormToolkit formToolkit = new FormToolkit(Display.getDefault()); 18 19 19 /** 20 * Create the dialog. 21 * @param parent 22 * @param style 23 */ 24 public AboutDialog(Shell parent, int style) { 25 super(parent, style); 26 setText("SWT Dialog"); 27 } 20 /** 21 * Create the dialog. 22 * 23 * @param parent 24 * @param style 25 */ 26 public AboutDialog(Shell parent, int style) { 27 super(parent, style); 28 setText("SWT Dialog"); 29 } 28 30 29 30 31 32 33 34 35 36 37 38 39 40 41 42 31 /** 32 * Open the dialog. 33 */ 34 public void open() { 35 createContents(); 36 shlAboutEventbenchconsole.open(); 37 shlAboutEventbenchconsole.layout(); 38 Display display = getParent().getDisplay(); 39 while (!shlAboutEventbenchconsole.isDisposed()) { 40 if (!display.readAndDispatch()) { 41 display.sleep(); 42 } 43 } 44 } 43 45 44 /** 45 * Create contents of the dialog. 46 */ 47 private void createContents() { 48 shlAboutEventbenchconsole = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL); 49 shlAboutEventbenchconsole.setSize(283, 113); 50 shlAboutEventbenchconsole.setText("About EventBenchConsole"); 51 52 Label lblEventbenchconsole = new Label(shlAboutEventbenchconsole, SWT.CENTER); 53 lblEventbenchconsole.setBounds(10, 10, 267, 15); 54 lblEventbenchconsole.setText("EventBenchConsole"); 55 56 Label lblFurtherInformationAbout = new Label(shlAboutEventbenchconsole, SWT.WRAP); 57 lblFurtherInformationAbout.setBounds(10, 31, 267, 31); 58 lblFurtherInformationAbout.setText("Further information about this software is provided on our homepage."); 59 60 final Hyperlink hprlnkHttpeventbenchinformatikunigoettingende = formToolkit.createHyperlink(shlAboutEventbenchconsole, "http://eventbench.informatik.uni-goettingen.de", SWT.NONE); 61 hprlnkHttpeventbenchinformatikunigoettingende.addMouseListener(new MouseAdapter() { 62 @Override 63 public void mouseDown(MouseEvent e) { 64 Program.launch(hprlnkHttpeventbenchinformatikunigoettingende.getText()); 65 } 66 }); 67 hprlnkHttpeventbenchinformatikunigoettingende.setBounds(10, 68, 267, 17); 68 formToolkit.paintBordersFor(hprlnkHttpeventbenchinformatikunigoettingende); 69 hprlnkHttpeventbenchinformatikunigoettingende.setBackground(null); 46 /** 47 * Create contents of the dialog. 48 */ 49 private void createContents() { 50 shlAboutEventbenchconsole = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL); 51 shlAboutEventbenchconsole.setSize(283, 113); 52 shlAboutEventbenchconsole.setText("About EventBenchConsole"); 70 53 71 } 54 Label lblEventbenchconsole = new Label(shlAboutEventbenchconsole, SWT.CENTER); 55 lblEventbenchconsole.setBounds(10, 10, 267, 15); 56 lblEventbenchconsole.setText("EventBenchConsole"); 57 58 Label lblFurtherInformationAbout = new Label(shlAboutEventbenchconsole, SWT.WRAP); 59 lblFurtherInformationAbout.setBounds(10, 31, 267, 31); 60 lblFurtherInformationAbout 61 .setText("Further information about this software is provided on our homepage."); 62 63 final Hyperlink hprlnkHttpeventbenchinformatikunigoettingende = 64 formToolkit.createHyperlink(shlAboutEventbenchconsole, 65 "http://eventbench.informatik.uni-goettingen.de", SWT.NONE); 66 hprlnkHttpeventbenchinformatikunigoettingende.addMouseListener(new MouseAdapter() { 67 @Override 68 public void mouseDown(MouseEvent e) { 69 Program.launch(hprlnkHttpeventbenchinformatikunigoettingende.getText()); 70 } 71 }); 72 hprlnkHttpeventbenchinformatikunigoettingende.setBounds(10, 68, 267, 17); 73 formToolkit.paintBordersFor(hprlnkHttpeventbenchinformatikunigoettingende); 74 hprlnkHttpeventbenchinformatikunigoettingende.setBackground(null); 75 76 } 72 77 } -
trunk/quest-ui-swt/src/main/java/de/ugoe/cs/quest/ui/swt/AbstractInsertEventComposite.java
r548 r570 1 1 2 package de.ugoe.cs.quest.ui.swt; 2 3 … … 9 10 abstract public class AbstractInsertEventComposite extends Composite { 10 11 11 12 13 14 15 16 17 18 public abstract Event getEvent(); 12 protected SortedSet<String> targets; 13 14 public AbstractInsertEventComposite(Composite parent, int style, SortedSet<String> targets) { 15 super(parent, style); 16 this.targets = targets; 17 } 18 19 public abstract Event getEvent(); 19 20 20 21 } -
trunk/quest-ui-swt/src/main/java/de/ugoe/cs/quest/ui/swt/CommandHistoryDialog.java
r526 r570 1 1 2 package de.ugoe.cs.quest.ui.swt; 2 3 … … 32 33 33 34 public class CommandHistoryDialog extends Dialog implements ICommandListener { 34 35 protected java.util.List<String> history = new LinkedList<String>();36 37 protected List commandHistoryList;38 protected Shell shell;39 40 boolean isOpen;41 35 42 /** 43 * Create the dialog. 44 * @param parent 45 * @param style 46 */ 47 public CommandHistoryDialog(Shell parent, int style) { 48 super(parent, style); 49 setText("Command History"); 50 isOpen = false; 51 Console.getInstance().registerCommandListener(this); 52 } 36 protected java.util.List<String> history = new LinkedList<String>(); 53 37 54 /** 55 * Open the dialog. 56 */ 57 public void open() { 58 createContents(); 59 shell.open(); 60 shell.layout(); 61 isOpen = true; 62 Display display = getParent().getDisplay(); 63 while (!shell.isDisposed()) { 64 if (!display.readAndDispatch()) { 65 display.sleep(); 66 } 67 } 68 } 38 protected List commandHistoryList; 39 protected Shell shell; 69 40 70 /** 71 * Create contents of the dialog. 72 */ 73 private void createContents() { 74 shell = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.RESIZE); 75 shell.addDisposeListener(new DisposeListener() { 76 public void widgetDisposed(DisposeEvent arg0) { 77 isOpen = false; 78 } 79 }); 80 shell.setSize(450, 300); 81 shell.setText(getText()); 82 shell.setLayout(new GridLayout(3, false)); 83 84 Label lblRecentCommands = new Label(shell, SWT.NONE); 85 lblRecentCommands.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1)); 86 lblRecentCommands.setText("Recent Commands:"); 87 new Label(shell, SWT.NONE); 88 89 commandHistoryList = new List(shell, SWT.BORDER | SWT.V_SCROLL | SWT.MULTI); 90 commandHistoryList.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1)); 91 for( String command : history ) { 92 commandHistoryList.add(command); 93 } 94 95 Button btnExec = new Button(shell, SWT.NONE); 96 btnExec.addSelectionListener(new SelectionAdapter() { 97 @Override 98 public void widgetSelected(SelectionEvent e) { 99 for( String command : commandHistoryList.getSelection() ) { 100 CommandExecuter.getInstance().exec(command); 101 } 102 } 103 }); 104 btnExec.setText("Execute"); 105 106 Button btnCopyToClipboard = new Button(shell, SWT.NONE); 107 btnCopyToClipboard.addSelectionListener(new SelectionAdapter() { 108 @Override 109 public void widgetSelected(SelectionEvent e) { 110 Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); 111 StringSelection content = new StringSelection(getSelectedCommands()); 112 clipboard.setContents(content, null); 113 } 114 }); 115 btnCopyToClipboard.setText("Copy to Clipboard"); 116 117 Button btnCreateBatchfile = new Button(shell, SWT.NONE); 118 btnCreateBatchfile.addSelectionListener(new SelectionAdapter() { 119 @Override 120 public void widgetSelected(SelectionEvent event) { 121 FileDialog fileDialog = new FileDialog(shell, SWT.SAVE); 122 String filename = fileDialog.open(); 123 if( filename!=null ) { 124 File file = new File(filename); 125 boolean fileCreated; 126 try { 127 fileCreated = file.createNewFile(); 128 if (!fileCreated) { 129 Console.traceln("Created batchfile " + filename); 130 } else { 131 Console.traceln("Overwrote file " + filename); 132 } 133 } catch (IOException e) { 134 Console.printerrln("Unable to create file " + filename); 135 Console.logException(e); 136 } 137 OutputStreamWriter writer = null; 138 try { 139 writer = new OutputStreamWriter(new FileOutputStream(file), "UTF-8"); 140 } catch (IOException e) { 141 Console.printerrln("Unable to open file for writing (read-only file):" 142 + filename); 143 Console.logException(e); 144 return; 145 } 146 try { 147 writer.write(getSelectedCommands()); 148 writer.close(); 149 } catch (IOException e) { 150 Console.printerrln("Unable to write to file."); 151 Console.logException(e); 152 } 153 } 154 } 155 }); 156 btnCreateBatchfile.setText("Create Batchfile"); 41 boolean isOpen; 157 42 158 } 43 /** 44 * Create the dialog. 45 * 46 * @param parent 47 * @param style 48 */ 49 public CommandHistoryDialog(Shell parent, int style) { 50 super(parent, style); 51 setText("Command History"); 52 isOpen = false; 53 Console.getInstance().registerCommandListener(this); 54 } 159 55 160 @Override 161 public void commandNotification(String command) { 162 history.add(command); 163 if( isOpen ) { 164 commandHistoryList.add(command); 165 } 166 } 167 168 public boolean isOpen() { 169 return isOpen; 170 } 171 172 private String getSelectedCommands() { 173 StringBuilder commands = new StringBuilder(); 174 for( String command : commandHistoryList.getSelection()) { 175 commands.append(command + StringTools.ENDLINE); 176 } 177 return commands.toString(); 178 } 56 /** 57 * Open the dialog. 58 */ 59 public void open() { 60 createContents(); 61 shell.open(); 62 shell.layout(); 63 isOpen = true; 64 Display display = getParent().getDisplay(); 65 while (!shell.isDisposed()) { 66 if (!display.readAndDispatch()) { 67 display.sleep(); 68 } 69 } 70 } 71 72 /** 73 * Create contents of the dialog. 74 */ 75 private void createContents() { 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 }); 82 shell.setSize(450, 300); 83 shell.setText(getText()); 84 shell.setLayout(new GridLayout(3, false)); 85 86 Label lblRecentCommands = new Label(shell, SWT.NONE); 87 lblRecentCommands.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1)); 88 lblRecentCommands.setText("Recent Commands:"); 89 new Label(shell, SWT.NONE); 90 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 } 96 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 }); 106 btnExec.setText("Execute"); 107 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 }); 117 btnCopyToClipboard.setText("Copy to Clipboard"); 118 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 } 133 else { 134 Console.traceln("Overwrote file " + filename); 135 } 136 } 137 catch (IOException e) { 138 Console.printerrln("Unable to create file " + filename); 139 Console.logException(e); 140 } 141 OutputStreamWriter writer = null; 142 try { 143 writer = new OutputStreamWriter(new FileOutputStream(file), "UTF-8"); 144 } 145 catch (IOException e) { 146 Console.printerrln("Unable to open file for writing (read-only file):" + 147 filename); 148 Console.logException(e); 149 return; 150 } 151 try { 152 writer.write(getSelectedCommands()); 153 writer.close(); 154 } 155 catch (IOException e) { 156 Console.printerrln("Unable to write to file."); 157 Console.logException(e); 158 } 159 } 160 } 161 }); 162 btnCreateBatchfile.setText("Create Batchfile"); 163 164 } 165 166 @Override 167 public void commandNotification(String command) { 168 history.add(command); 169 if (isOpen) { 170 commandHistoryList.add(command); 171 } 172 } 173 174 public boolean isOpen() { 175 return isOpen; 176 } 177 178 private String getSelectedCommands() { 179 StringBuilder commands = new StringBuilder(); 180 for (String command : commandHistoryList.getSelection()) { 181 commands.append(command + StringTools.ENDLINE); 182 } 183 return commands.toString(); 184 } 179 185 } -
trunk/quest-ui-swt/src/main/java/de/ugoe/cs/quest/ui/swt/ConsoleTabComposite.java
r526 r570 1 1 2 package de.ugoe.cs.quest.ui.swt; 2 3 … … 17 18 import org.eclipse.swt.events.KeyEvent; 18 19 19 20 20 import de.ugoe.cs.util.console.CommandExecuter; 21 21 22 22 /** 23 23 * <p> 24 * Implements the composite for the console tab in the applications main window. 24 * Implements the composite for the console tab in the applications main window. 25 25 * </p> 26 26 * … … 30 30 public class ConsoleTabComposite extends Composite { 31 31 32 protected Text textCommand; 33 34 protected StyledText textConsoleOutput; 35 36 /** 37 * Create the composite. 38 * @param parent 39 * @param style 40 */ 41 public ConsoleTabComposite(Composite parent, int style) { 42 super(parent, style); 43 createContents(); 44 } 45 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 = new StyledText(this, SWT.BORDER | SWT.READ_ONLY | SWT.H_SCROLL | SWT.V_SCROLL | SWT.CANCEL); 76 GridData gd_textConsoleOutput = new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1); 77 gd_textConsoleOutput.heightHint = 102; 78 gd_textConsoleOutput.widthHint = 456; 79 textConsoleOutput.setLayoutData(gd_textConsoleOutput); 80 textConsoleOutput.addListener(SWT.Modify, new Listener(){ 81 public void handleEvent(Event e){ 82 textConsoleOutput.setTopIndex(textConsoleOutput.getLineCount() - 1); 83 } 84 }); 32 protected Text textCommand; 85 33 86 } 87 88 private void executeCommand() { 89 String command = textCommand.getText().trim(); 90 CommandExecuter.getInstance().exec(command); 91 textCommand.setText(""); 92 } 34 protected StyledText textConsoleOutput; 93 35 94 @Override 95 protected void checkSubclass() { 96 // Disable the check that prevents subclassing of SWT components 97 } 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 } 98 101 99 102 } -
trunk/quest-ui-swt/src/main/java/de/ugoe/cs/quest/ui/swt/DataTabComposite.java
r526 r570 1 1 2 package de.ugoe.cs.quest.ui.swt; 2 3 … … 19 20 public class DataTabComposite extends Composite { 20 21 21 List dataList; 22 23 /** 24 * Create the composite. 25 * @param parent 26 * @param style 27 */ 28 public DataTabComposite(Composite parent, int style) { 29 super(parent, style); 30 createContent(); 31 } 32 33 private void createContent() { 34 setLayout(new GridLayout(3, false)); 35 36 dataList = new List(this, SWT.BORDER | SWT.V_SCROLL); 37 dataList.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1)); 38 39 Button btnLoad = new Button(this, SWT.NONE); 40 btnLoad.addSelectionListener(new SelectionAdapter() { 41 @Override 42 public void widgetSelected(SelectionEvent e) { 43 GetObjectNameDialog getObjectNameDialog = new GetObjectNameDialog(getShell(), SWT.NONE); 44 getObjectNameDialog.open(); 45 String objectName = getObjectNameDialog.getObjectName(); 46 if( "".equals(objectName) ) { 47 return; 48 } 49 FileDialog fileDialog = new FileDialog(getShell(), SWT.OPEN); 50 String filename = fileDialog.open(); 51 if( filename==null ) { 52 return; 53 } 54 String command = "loadObject " + filename + " " + objectName; 55 CommandExecuter.getInstance().exec(command); 56 updateDataList(); 57 } 58 }); 59 btnLoad.setText("Load"); 60 61 Button btnSave = new Button(this, SWT.NONE); 62 btnSave.addSelectionListener(new SelectionAdapter() { 63 @Override 64 public void widgetSelected(SelectionEvent e) { 65 String[] selectedStrings = dataList.getSelection(); 66 if( selectedStrings.length==0 ) { 67 SWTHelpers.noSelectionError(getShell()); 68 return; 69 } 70 if( selectedStrings.length>1 ) { 71 MessageBox messageBox = new MessageBox(getShell(), SWT.ERROR); 72 messageBox.setText("Error"); 73 messageBox.setMessage("Only one object storable at a time." + StringTools.ENDLINE + "Please select only one object."); 74 return; 75 } 76 FileDialog fileDialog = new FileDialog(getShell(), SWT.SAVE); 77 String filename = fileDialog.open(); 78 if( filename==null ) { 79 return; 80 } 81 String command = "saveObject " + filename + " " + selectedStrings[0]; 82 CommandExecuter.getInstance().exec(command); 83 } 84 }); 85 btnSave.setText("Save"); 86 87 Button btnDelete_2 = new Button(this, SWT.NONE); 88 btnDelete_2.addSelectionListener(new SelectionAdapter() { 89 @Override 90 public void widgetSelected(SelectionEvent e) { 91 if( SWTHelpers.deleteSelectedFromStorage(dataList)) { 92 updateDataList(); 93 } else { 94 SWTHelpers.noSelectionError(getShell()); 95 } 96 } 97 }); 98 btnDelete_2.setText("Delete"); 99 } 22 List dataList; 100 23 101 @Override 102 protected void checkSubclass() { 103 // Disable the check that prevents subclassing of SWT components 104 } 105 106 public void updateDataList() { 107 dataList.removeAll(); 108 for( String sequencesName : GlobalDataContainer.getInstance().getAllKeys() ) { 109 dataList.add(sequencesName); 110 } 111 } 24 /** 25 * Create the composite. 26 * 27 * @param parent 28 * @param style 29 */ 30 public DataTabComposite(Composite parent, int style) { 31 super(parent, style); 32 createContent(); 33 } 34 35 private void createContent() { 36 setLayout(new GridLayout(3, false)); 37 38 dataList = new List(this, SWT.BORDER | SWT.V_SCROLL); 39 dataList.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1)); 40 41 Button btnLoad = new Button(this, SWT.NONE); 42 btnLoad.addSelectionListener(new SelectionAdapter() { 43 @Override 44 public void widgetSelected(SelectionEvent e) { 45 GetObjectNameDialog getObjectNameDialog = 46 new GetObjectNameDialog(getShell(), SWT.NONE); 47 getObjectNameDialog.open(); 48 String objectName = getObjectNameDialog.getObjectName(); 49 if ("".equals(objectName)) { 50 return; 51 } 52 FileDialog fileDialog = new FileDialog(getShell(), SWT.OPEN); 53 String filename = fileDialog.open(); 54 if (filename == null) { 55 return; 56 } 57 String command = "loadObject " + filename + " " + objectName; 58 CommandExecuter.getInstance().exec(command); 59 updateDataList(); 60 } 61 }); 62 btnLoad.setText("Load"); 63 64 Button btnSave = new Button(this, SWT.NONE); 65 btnSave.addSelectionListener(new SelectionAdapter() { 66 @Override 67 public void widgetSelected(SelectionEvent e) { 68 String[] selectedStrings = dataList.getSelection(); 69 if (selectedStrings.length == 0) { 70 SWTHelpers.noSelectionError(getShell()); 71 return; 72 } 73 if (selectedStrings.length > 1) { 74 MessageBox messageBox = new MessageBox(getShell(), SWT.ERROR); 75 messageBox.setText("Error"); 76 messageBox.setMessage("Only one object storable at a time." + 77 StringTools.ENDLINE + "Please select only one object."); 78 return; 79 } 80 FileDialog fileDialog = new FileDialog(getShell(), SWT.SAVE); 81 String filename = fileDialog.open(); 82 if (filename == null) { 83 return; 84 } 85 String command = "saveObject " + filename + " " + selectedStrings[0]; 86 CommandExecuter.getInstance().exec(command); 87 } 88 }); 89 btnSave.setText("Save"); 90 91 Button btnDelete_2 = new Button(this, SWT.NONE); 92 btnDelete_2.addSelectionListener(new SelectionAdapter() { 93 @Override 94 public void widgetSelected(SelectionEvent e) { 95 if (SWTHelpers.deleteSelectedFromStorage(dataList)) { 96 updateDataList(); 97 } 98 else { 99 SWTHelpers.noSelectionError(getShell()); 100 } 101 } 102 }); 103 btnDelete_2.setText("Delete"); 104 } 105 106 @Override 107 protected void checkSubclass() { 108 // Disable the check that prevents subclassing of SWT components 109 } 110 111 public void updateDataList() { 112 dataList.removeAll(); 113 for (String sequencesName : GlobalDataContainer.getInstance().getAllKeys()) { 114 dataList.add(sequencesName); 115 } 116 } 112 117 113 118 } -
trunk/quest-ui-swt/src/main/java/de/ugoe/cs/quest/ui/swt/EditSequenceDialog.java
r548 r570 1 1 2 package de.ugoe.cs.quest.ui.swt; 2 3 … … 23 24 public class EditSequenceDialog extends Dialog { 24 25 25 26 27 28 26 protected Shell shell; 27 private Table table; 28 private TableColumn tblclmnEventType; 29 private TableColumn tblclmnEventTarget; 29 30 30 31 31 private java.util.List<Event> sequence; 32 private SortedSet<String> targets; 32 33 33 34 35 36 37 38 39 40 41 42 43 34 /** 35 * Create the dialog. 36 * 37 * @param parent 38 * @param style 39 */ 40 public EditSequenceDialog(Shell parent, int style, SortedSet<String> targets) { 41 super(parent, style); 42 setText("SWT Dialog"); 43 this.targets = targets; 44 } 44 45 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 46 /** 47 * Open the dialog. 48 */ 49 public void open(java.util.List<Event> sequence) { 50 this.sequence = sequence; 51 createContents(); 52 shell.open(); 53 shell.layout(); 54 Display display = getParent().getDisplay(); 55 while (!shell.isDisposed()) { 56 if (!display.readAndDispatch()) { 57 display.sleep(); 58 } 59 } 60 } 60 61 61 /** 62 * Create contents of the dialog. 63 */ 64 private void createContents() { 65 shell = new Shell(getParent(), SWT.SHELL_TRIM | SWT.BORDER 66 | SWT.APPLICATION_MODAL); 67 shell.setSize(450, 300); 68 shell.setText(getText()); 69 shell.setLayout(new GridLayout(3, false)); 62 /** 63 * Create contents of the dialog. 64 */ 65 private void createContents() { 66 shell = new Shell(getParent(), SWT.SHELL_TRIM | SWT.BORDER | SWT.APPLICATION_MODAL); 67 shell.setSize(450, 300); 68 shell.setText(getText()); 69 shell.setLayout(new GridLayout(3, false)); 70 70 71 72 73 74 71 table = new Table(shell, SWT.BORDER | SWT.FULL_SELECTION); 72 table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1)); 73 table.setHeaderVisible(true); 74 table.setLinesVisible(true); 75 75 76 77 78 76 tblclmnEventType = new TableColumn(table, SWT.NONE); 77 tblclmnEventType.setWidth(100); 78 tblclmnEventType.setText("Event Type"); 79 79 80 81 82 80 tblclmnEventTarget = new TableColumn(table, SWT.NONE); 81 tblclmnEventTarget.setWidth(100); 82 tblclmnEventTarget.setText("Event Target"); 83 83 84 // this listener makes the table entries multiline 85 Listener paintListener = new Listener() { 86 public void handleEvent(org.eclipse.swt.widgets.Event event) { 87 switch (event.type) { 88 case SWT.MeasureItem: { 89 TableItem item = (TableItem) event.item; 90 String text = item.getText(event.index); 91 Point size = event.gc.textExtent(text); 92 event.width = size.x; 93 event.height = Math.max(event.height, size.y); 94 break; 95 } 96 case SWT.PaintItem: { 97 TableItem item = (TableItem) event.item; 98 String text = item.getText(event.index); 99 Point size = event.gc.textExtent(text); 100 int offset = event.index == 0 ? Math.max(0, 101 (event.height - size.y) / 2) : 0; 102 event.gc.drawText(text, event.x, event.y + offset, true); 103 break; 104 } 105 case SWT.EraseItem: 106 event.detail &= ~SWT.FOREGROUND; 107 break; 108 default: 109 break; 110 } 111 } 84 // this listener makes the table entries multiline 85 Listener paintListener = new Listener() { 86 public void handleEvent(org.eclipse.swt.widgets.Event event) { 87 switch (event.type) 88 { 89 case SWT.MeasureItem: { 90 TableItem item = (TableItem) event.item; 91 String text = item.getText(event.index); 92 Point size = event.gc.textExtent(text); 93 event.width = size.x; 94 event.height = Math.max(event.height, size.y); 95 break; 96 } 97 case SWT.PaintItem: { 98 TableItem item = (TableItem) event.item; 99 String text = item.getText(event.index); 100 Point size = event.gc.textExtent(text); 101 int offset = 102 event.index == 0 ? Math.max(0, (event.height - size.y) / 2) : 0; 103 event.gc.drawText(text, event.x, event.y + offset, true); 104 break; 105 } 106 case SWT.EraseItem: 107 event.detail &= ~SWT.FOREGROUND; 108 break; 109 default: 110 break; 111 } 112 } 112 113 113 114 115 116 114 }; 115 table.addListener(SWT.MeasureItem, paintListener); 116 table.addListener(SWT.PaintItem, paintListener); 117 table.addListener(SWT.EraseItem, paintListener); 117 118 118 119 updateTableContents(); 119 120 120 Button btnInsertBefore = new Button(shell, SWT.NONE); 121 btnInsertBefore.addSelectionListener(new SelectionAdapter() { 122 @Override 123 public void widgetSelected(SelectionEvent e) { 124 int index = table.getSelectionIndex(); 125 if (index == -1) { 126 MessageBox messageBox = new MessageBox(shell, SWT.ERROR); 127 messageBox.setMessage("No event selected!"); 128 messageBox.setText("Error"); 129 messageBox.open(); 130 } else { 131 openInsertDialog(index); 132 } 133 } 134 }); 135 btnInsertBefore.setText("Insert Before"); 121 Button btnInsertBefore = new Button(shell, SWT.NONE); 122 btnInsertBefore.addSelectionListener(new SelectionAdapter() { 123 @Override 124 public void widgetSelected(SelectionEvent e) { 125 int index = table.getSelectionIndex(); 126 if (index == -1) { 127 MessageBox messageBox = new MessageBox(shell, SWT.ERROR); 128 messageBox.setMessage("No event selected!"); 129 messageBox.setText("Error"); 130 messageBox.open(); 131 } 132 else { 133 openInsertDialog(index); 134 } 135 } 136 }); 137 btnInsertBefore.setText("Insert Before"); 136 138 137 Button btnInsertAfter = new Button(shell, SWT.NONE); 138 btnInsertAfter.addSelectionListener(new SelectionAdapter() { 139 @Override 140 public void widgetSelected(SelectionEvent e) { 141 int index = table.getSelectionIndex(); 142 if (index == -1) { 143 MessageBox messageBox = new MessageBox(shell, SWT.ERROR); 144 messageBox.setMessage("No event selected!"); 145 messageBox.setText("Error"); 146 messageBox.open(); 147 } else { 148 openInsertDialog(index + 1); 149 } 150 } 151 }); 152 btnInsertAfter.setText("Insert After"); 139 Button btnInsertAfter = new Button(shell, SWT.NONE); 140 btnInsertAfter.addSelectionListener(new SelectionAdapter() { 141 @Override 142 public void widgetSelected(SelectionEvent e) { 143 int index = table.getSelectionIndex(); 144 if (index == -1) { 145 MessageBox messageBox = new MessageBox(shell, SWT.ERROR); 146 messageBox.setMessage("No event selected!"); 147 messageBox.setText("Error"); 148 messageBox.open(); 149 } 150 else { 151 openInsertDialog(index + 1); 152 } 153 } 154 }); 155 btnInsertAfter.setText("Insert After"); 153 156 154 155 156 157 158 159 160 161 157 Button btnClose = new Button(shell, SWT.NONE); 158 btnClose.addSelectionListener(new SelectionAdapter() { 159 @Override 160 public void widgetSelected(SelectionEvent e) { 161 shell.dispose(); 162 } 163 }); 164 btnClose.setText("Close"); 162 165 163 166 } 164 167 165 private void updateTableContents() { 166 table.removeAll(); 167 for (Event event : sequence) { 168 TableItem tableItem = new TableItem(table, SWT.NONE); 169 String target = event.getTarget(); 170 if (target != null) { 171 // the target is split into multiple lines, as one line may 172 // only be 259 characters in tables with Windows 173 target = target.replace("].", "].\n"); 174 } 175 tableItem.setText(new String[] { event.getType().toString(), target }); 176 } 177 for (int i = 0; i < table.getColumnCount(); i++) { 178 table.getColumn(i).pack(); 179 } 180 } 168 private void updateTableContents() { 169 table.removeAll(); 170 for (Event event : sequence) { 171 TableItem tableItem = new TableItem(table, SWT.NONE); 172 // TODO check if toString is sufficient 173 String target = event.getTarget().toString(); 174 if (target != null) { 175 // the target is split into multiple lines, as one line may 176 // only be 259 characters in tables with Windows 177 target = target.replace("].", "].\n"); 178 } 179 tableItem.setText(new String[] 180 { event.getType().toString(), target }); 181 } 182 for (int i = 0; i < table.getColumnCount(); i++) { 183 table.getColumn(i).pack(); 184 } 185 } 181 186 182 private void openInsertDialog(int position) { 183 InsertAssertionDialog insertDialog = new InsertAssertionDialog(shell, 184 SWT.NONE, targets); 185 Event event = insertDialog.open(); 186 if (event != null) { 187 sequence.add(position, event); 188 updateTableContents(); 189 } 190 } 187 private void openInsertDialog(int position) { 188 InsertAssertionDialog insertDialog = new InsertAssertionDialog(shell, SWT.NONE, targets); 189 Event event = insertDialog.open(); 190 if (event != null) { 191 sequence.add(position, event); 192 updateTableContents(); 193 } 194 } 191 195 192 196 } -
trunk/quest-ui-swt/src/main/java/de/ugoe/cs/quest/ui/swt/GenerateSequencesDialog.java
r526 r570 1 1 2 package de.ugoe.cs.quest.ui.swt; 2 3 … … 22 23 public class GenerateSequencesDialog extends Dialog { 23 24 24 private String processName; 25 26 protected Button btnNumberAll; 27 protected Button btnLengthAll; 28 protected Spinner numberSpinner; 29 protected Spinner iterationsSpinner; 30 protected Spinner minLengthSpinner; 31 protected Spinner maxLengthSpinner; 32 33 protected Shell shlGenerateSequences; 34 private Text sequencesNameText; 35 private final FormToolkit formToolkit = new FormToolkit(Display.getDefault()); 36 37 /** 38 * Create the dialog. 39 * @param parent 40 * @param style 41 */ 42 public GenerateSequencesDialog(Shell parent, int style) { 43 super(parent, style); 44 setText("SWT Dialog"); 45 } 46 47 /** 48 * Open the dialog. 49 */ 50 public void open() { 51 createContents(); 52 shlGenerateSequences.open(); 53 shlGenerateSequences.layout(); 54 Display display = getParent().getDisplay(); 55 while (!shlGenerateSequences.isDisposed()) { 56 if (!display.readAndDispatch()) { 57 display.sleep(); 58 } 59 } 60 } 61 62 /** 63 * Create contents of the dialog. 64 */ 65 private void createContents() { 66 shlGenerateSequences = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL); 67 shlGenerateSequences.setSize(201, 303); 68 shlGenerateSequences.setText("Generate Sequences"); 69 shlGenerateSequences.setLayout(new GridLayout(2, false)); 70 71 Group group = new Group(shlGenerateSequences, SWT.NONE); 72 group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1)); 73 group.setText("Name"); 74 group.setLayout(new GridLayout(1, false)); 75 76 sequencesNameText = new Text(group, SWT.BORDER); 77 sequencesNameText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); 78 79 Group grpNumber = new Group(shlGenerateSequences, SWT.NONE); 80 grpNumber.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1)); 81 grpNumber.setText("Number"); 82 grpNumber.setLayout(new GridLayout(2, false)); 83 84 numberSpinner = new Spinner(grpNumber, SWT.BORDER); 85 numberSpinner.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); 86 numberSpinner.setMinimum(1); 87 numberSpinner.setMaximum(Integer.MAX_VALUE); 88 89 btnNumberAll = new Button(grpNumber, SWT.CHECK); 90 btnNumberAll.addSelectionListener(new SelectionAdapter() { 91 @Override 92 public void widgetSelected(SelectionEvent e) { 93 numberSpinner.setEnabled(!btnNumberAll.getSelection()); 94 btnLengthAll.setEnabled(!btnNumberAll.getSelection()); 95 iterationsSpinner.setEnabled(!btnNumberAll.getSelection()); 96 } 97 }); 98 btnNumberAll.setText("All"); 99 100 Group grpIterations = new Group(shlGenerateSequences, SWT.NONE); 101 grpIterations.setLayout(new GridLayout(1, false)); 102 grpIterations.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1)); 103 grpIterations.setText("Iterations"); 104 105 iterationsSpinner = new Spinner(grpIterations, SWT.BORDER); 106 iterationsSpinner.setMinimum(1); 107 iterationsSpinner.setMaximum(Integer.MAX_VALUE); 108 iterationsSpinner.setSelection(100000); 109 iterationsSpinner.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); 110 111 Group grpLength = new Group(shlGenerateSequences, SWT.NONE); 112 grpLength.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1)); 113 grpLength.setText("Length"); 114 grpLength.setLayout(new GridLayout(4, false)); 115 116 btnLengthAll = new Button(grpLength, SWT.CHECK); 117 btnLengthAll.addSelectionListener(new SelectionAdapter() { 118 @Override 119 public void widgetSelected(SelectionEvent e) { 120 minLengthSpinner.setEnabled(!btnLengthAll.getSelection()); 121 maxLengthSpinner.setEnabled(!btnLengthAll.getSelection()); 122 } 123 }); 124 btnLengthAll.setText("All"); 125 new Label(grpLength, SWT.NONE); 126 new Label(grpLength, SWT.NONE); 127 new Label(grpLength, SWT.NONE); 128 129 Label label = new Label(grpLength, SWT.NONE); 130 label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1)); 131 label.setText("Min."); 132 133 minLengthSpinner = new Spinner(grpLength, SWT.BORDER); 134 minLengthSpinner.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); 135 minLengthSpinner.setMinimum(1); 136 137 Label label_1 = new Label(grpLength, SWT.NONE); 138 label_1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, true, 1, 1)); 139 label_1.setText("Max."); 140 141 maxLengthSpinner = new Spinner(grpLength, SWT.BORDER); 142 maxLengthSpinner.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); 143 maxLengthSpinner.setToolTipText("0 means no limitations"); 144 maxLengthSpinner.setMinimum(1); 145 146 Button btnGenerate = formToolkit.createButton(shlGenerateSequences, "Generate!", SWT.NONE); 147 btnGenerate.addSelectionListener(new SelectionAdapter() { 148 @Override 149 public void widgetSelected(SelectionEvent e) { 150 if("".equals(sequencesNameText.getText())) { 151 MessageBox messageBox = new MessageBox(shlGenerateSequences, SWT.ERROR); 152 messageBox.setText("Error"); 153 messageBox.setMessage("Sequences name not defined!"); 154 messageBox.open(); 155 return; 156 } 157 String sequencesName = sequencesNameText.getText(); 158 int number = numberSpinner.getSelection(); 159 int minLength = minLengthSpinner.getSelection(); 160 int maxLength = maxLengthSpinner.getSelection(); 161 int maxIter = iterationsSpinner.getSelection(); 162 if( maxIter<=number ) { 163 maxIter = number; 164 } 165 String command = ""; 166 if( btnNumberAll.getSelection() ) { 167 if( minLength>maxLength ) { 168 MessageBox messageBox = new MessageBox(shlGenerateSequences, SWT.ERROR); 169 messageBox.setText("Error"); 170 messageBox.setMessage("Min. length must be smaller than or equal to max. length!"); 171 messageBox.open(); 172 return; 173 } 174 command = "generateFixedLengthSequences " + processName + " " + sequencesName + " " + minLength + " " + maxLength + " true"; 175 } else { 176 command = "generateRandomSequences " + processName + " " + sequencesName + " " + number + " " + maxIter; 177 if( !btnLengthAll.getSelection() ) { 178 if( minLength>maxLength ) { 179 MessageBox messageBox = new MessageBox(shlGenerateSequences, SWT.ERROR); 180 messageBox.setText("Error"); 181 messageBox.setMessage("Min. length must be smaller than or equal to max. length!"); 182 messageBox.open(); 183 return; 184 } 185 command += " " + minLength + " " + maxLength; 186 } 187 } 188 CommandExecuter.getInstance().exec(command); 189 shlGenerateSequences.dispose(); 190 } 191 }); 192 193 Button btnAbort = formToolkit.createButton(shlGenerateSequences, "Abort", SWT.NONE); 194 btnAbort.addSelectionListener(new SelectionAdapter() { 195 @Override 196 public void widgetSelected(SelectionEvent e) { 197 shlGenerateSequences.dispose(); 198 } 199 }); 200 201 } 202 203 public void setProcessName(String name) { 204 this.processName = name; 205 } 25 private String processName; 26 27 protected Button btnNumberAll; 28 protected Button btnLengthAll; 29 protected Spinner numberSpinner; 30 protected Spinner iterationsSpinner; 31 protected Spinner minLengthSpinner; 32 protected Spinner maxLengthSpinner; 33 34 protected Shell shlGenerateSequences; 35 private Text sequencesNameText; 36 private final FormToolkit formToolkit = new FormToolkit(Display.getDefault()); 37 38 /** 39 * Create the dialog. 40 * 41 * @param parent 42 * @param style 43 */ 44 public GenerateSequencesDialog(Shell parent, int style) { 45 super(parent, style); 46 setText("SWT Dialog"); 47 } 48 49 /** 50 * Open the dialog. 51 */ 52 public void open() { 53 createContents(); 54 shlGenerateSequences.open(); 55 shlGenerateSequences.layout(); 56 Display display = getParent().getDisplay(); 57 while (!shlGenerateSequences.isDisposed()) { 58 if (!display.readAndDispatch()) { 59 display.sleep(); 60 } 61 } 62 } 63 64 /** 65 * Create contents of the dialog. 66 */ 67 private void createContents() { 68 shlGenerateSequences = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL); 69 shlGenerateSequences.setSize(201, 303); 70 shlGenerateSequences.setText("Generate Sequences"); 71 shlGenerateSequences.setLayout(new GridLayout(2, false)); 72 73 Group group = new Group(shlGenerateSequences, SWT.NONE); 74 group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1)); 75 group.setText("Name"); 76 group.setLayout(new GridLayout(1, false)); 77 78 sequencesNameText = new Text(group, SWT.BORDER); 79 sequencesNameText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); 80 81 Group grpNumber = new Group(shlGenerateSequences, SWT.NONE); 82 grpNumber.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1)); 83 grpNumber.setText("Number"); 84 grpNumber.setLayout(new GridLayout(2, false)); 85 86 numberSpinner = new Spinner(grpNumber, SWT.BORDER); 87 numberSpinner.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); 88 numberSpinner.setMinimum(1); 89 numberSpinner.setMaximum(Integer.MAX_VALUE); 90 91 btnNumberAll = new Button(grpNumber, SWT.CHECK); 92 btnNumberAll.addSelectionListener(new SelectionAdapter() { 93 @Override 94 public void widgetSelected(SelectionEvent e) { 95 numberSpinner.setEnabled(!btnNumberAll.getSelection()); 96 btnLengthAll.setEnabled(!btnNumberAll.getSelection()); 97 iterationsSpinner.setEnabled(!btnNumberAll.getSelection()); 98 } 99 }); 100 btnNumberAll.setText("All"); 101 102 Group grpIterations = new Group(shlGenerateSequences, SWT.NONE); 103 grpIterations.setLayout(new GridLayout(1, false)); 104 grpIterations.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1)); 105 grpIterations.setText("Iterations"); 106 107 iterationsSpinner = new Spinner(grpIterations, SWT.BORDER); 108 iterationsSpinner.setMinimum(1); 109 iterationsSpinner.setMaximum(Integer.MAX_VALUE); 110 iterationsSpinner.setSelection(100000); 111 iterationsSpinner.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); 112 113 Group grpLength = new Group(shlGenerateSequences, SWT.NONE); 114 grpLength.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1)); 115 grpLength.setText("Length"); 116 grpLength.setLayout(new GridLayout(4, false)); 117 118 btnLengthAll = new Button(grpLength, SWT.CHECK); 119 btnLengthAll.addSelectionListener(new SelectionAdapter() { 120 @Override 121 public void widgetSelected(SelectionEvent e) { 122 minLengthSpinner.setEnabled(!btnLengthAll.getSelection()); 123 maxLengthSpinner.setEnabled(!btnLengthAll.getSelection()); 124 } 125 }); 126 btnLengthAll.setText("All"); 127 new Label(grpLength, SWT.NONE); 128 new Label(grpLength, SWT.NONE); 129 new Label(grpLength, SWT.NONE); 130 131 Label label = new Label(grpLength, SWT.NONE); 132 label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1)); 133 label.setText("Min."); 134 135 minLengthSpinner = new Spinner(grpLength, SWT.BORDER); 136 minLengthSpinner.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); 137 minLengthSpinner.setMinimum(1); 138 139 Label label_1 = new Label(grpLength, SWT.NONE); 140 label_1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, true, 1, 1)); 141 label_1.setText("Max."); 142 143 maxLengthSpinner = new Spinner(grpLength, SWT.BORDER); 144 maxLengthSpinner.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); 145 maxLengthSpinner.setToolTipText("0 means no limitations"); 146 maxLengthSpinner.setMinimum(1); 147 148 Button btnGenerate = formToolkit.createButton(shlGenerateSequences, "Generate!", SWT.NONE); 149 btnGenerate.addSelectionListener(new SelectionAdapter() { 150 @Override 151 public void widgetSelected(SelectionEvent e) { 152 if ("".equals(sequencesNameText.getText())) { 153 MessageBox messageBox = new MessageBox(shlGenerateSequences, SWT.ERROR); 154 messageBox.setText("Error"); 155 messageBox.setMessage("Sequences name not defined!"); 156 messageBox.open(); 157 return; 158 } 159 String sequencesName = sequencesNameText.getText(); 160 int number = numberSpinner.getSelection(); 161 int minLength = minLengthSpinner.getSelection(); 162 int maxLength = maxLengthSpinner.getSelection(); 163 int maxIter = iterationsSpinner.getSelection(); 164 if (maxIter <= number) { 165 maxIter = number; 166 } 167 String command = ""; 168 if (btnNumberAll.getSelection()) { 169 if (minLength > maxLength) { 170 MessageBox messageBox = new MessageBox(shlGenerateSequences, SWT.ERROR); 171 messageBox.setText("Error"); 172 messageBox 173 .setMessage("Min. length must be smaller than or equal to max. length!"); 174 messageBox.open(); 175 return; 176 } 177 command = 178 "generateFixedLengthSequences " + processName + " " + sequencesName + " " + 179 minLength + " " + maxLength + " true"; 180 } 181 else { 182 command = 183 "generateRandomSequences " + processName + " " + sequencesName + " " + 184 number + " " + maxIter; 185 if (!btnLengthAll.getSelection()) { 186 if (minLength > maxLength) { 187 MessageBox messageBox = new MessageBox(shlGenerateSequences, SWT.ERROR); 188 messageBox.setText("Error"); 189 messageBox 190 .setMessage("Min. length must be smaller than or equal to max. length!"); 191 messageBox.open(); 192 return; 193 } 194 command += " " + minLength + " " + maxLength; 195 } 196 } 197 CommandExecuter.getInstance().exec(command); 198 shlGenerateSequences.dispose(); 199 } 200 }); 201 202 Button btnAbort = formToolkit.createButton(shlGenerateSequences, "Abort", SWT.NONE); 203 btnAbort.addSelectionListener(new SelectionAdapter() { 204 @Override 205 public void widgetSelected(SelectionEvent e) { 206 shlGenerateSequences.dispose(); 207 } 208 }); 209 210 } 211 212 public void setProcessName(String name) { 213 this.processName = name; 214 } 206 215 } -
trunk/quest-ui-swt/src/main/java/de/ugoe/cs/quest/ui/swt/GetObjectNameDialog.java
r526 r570 1 1 2 package de.ugoe.cs.quest.ui.swt; 2 3 … … 16 17 public class GetObjectNameDialog extends Dialog { 17 18 18 String objectName = ""; 19 20 protected Shell shlObjectName; 21 private Text text; 19 String objectName = ""; 22 20 23 /** 24 * Create the dialog. 25 * @param parent 26 * @param style 27 */ 28 public GetObjectNameDialog(Shell parent, int style) { 29 super(parent, style); 30 setText("SWT Dialog"); 31 } 21 protected Shell shlObjectName; 22 private Text text; 32 23 33 /** 34 * Open the dialog. 35 */ 36 public void open() { 37 createContents(); 38 shlObjectName.open(); 39 shlObjectName.layout(); 40 Display display = getParent().getDisplay(); 41 while (!shlObjectName.isDisposed()) { 42 if (!display.readAndDispatch()) { 43 display.sleep(); 44 } 45 } 46 } 24 /** 25 * Create the dialog. 26 * 27 * @param parent 28 * @param style 29 */ 30 public GetObjectNameDialog(Shell parent, int style) { 31 super(parent, style); 32 setText("SWT Dialog"); 33 } 47 34 48 /** 49 * Create contents of the dialog. 50 */ 51 private void createContents() { 52 shlObjectName = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL); 53 shlObjectName.setSize(171, 109); 54 shlObjectName.setText("Object Name"); 55 shlObjectName.setLayout(new GridLayout(2, false)); 56 57 Label lblPleaseEnterThe = new Label(shlObjectName, SWT.NONE); 58 lblPleaseEnterThe.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1)); 59 lblPleaseEnterThe.setText("Please enter the object name:"); 60 61 text = new Text(shlObjectName, SWT.BORDER); 62 text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1)); 63 64 Button btnOk = new Button(shlObjectName, SWT.NONE); 65 btnOk.addSelectionListener(new SelectionAdapter() { 66 @Override 67 public void widgetSelected(SelectionEvent e) { 68 if( text.getText().equals("") ) { 69 MessageBox messageBox = new MessageBox(shlObjectName, SWT.ERROR); 70 messageBox.setText("Error"); 71 messageBox.setMessage("No name entered!"); 72 return; 73 } 74 objectName = text.getText(); 75 shlObjectName.dispose(); 76 } 77 }); 78 btnOk.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); 79 btnOk.setText("Ok"); 80 81 Button btnAbort = new Button(shlObjectName, SWT.NONE); 82 btnAbort.addSelectionListener(new SelectionAdapter() { 83 @Override 84 public void widgetSelected(SelectionEvent e) { 85 shlObjectName.dispose(); 86 } 87 }); 88 btnAbort.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); 89 btnAbort.setText("Abort"); 35 /** 36 * Open the dialog. 37 */ 38 public void open() { 39 createContents(); 40 shlObjectName.open(); 41 shlObjectName.layout(); 42 Display display = getParent().getDisplay(); 43 while (!shlObjectName.isDisposed()) { 44 if (!display.readAndDispatch()) { 45 display.sleep(); 46 } 47 } 48 } 90 49 91 } 92 93 public String getObjectName() { 94 return objectName; 95 } 50 /** 51 * Create contents of the dialog. 52 */ 53 private void createContents() { 54 shlObjectName = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL); 55 shlObjectName.setSize(171, 109); 56 shlObjectName.setText("Object Name"); 57 shlObjectName.setLayout(new GridLayout(2, false)); 58 59 Label lblPleaseEnterThe = new Label(shlObjectName, SWT.NONE); 60 lblPleaseEnterThe.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1)); 61 lblPleaseEnterThe.setText("Please enter the object name:"); 62 63 text = new Text(shlObjectName, SWT.BORDER); 64 text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1)); 65 66 Button btnOk = new Button(shlObjectName, SWT.NONE); 67 btnOk.addSelectionListener(new SelectionAdapter() { 68 @Override 69 public void widgetSelected(SelectionEvent e) { 70 if (text.getText().equals("")) { 71 MessageBox messageBox = new MessageBox(shlObjectName, SWT.ERROR); 72 messageBox.setText("Error"); 73 messageBox.setMessage("No name entered!"); 74 return; 75 } 76 objectName = text.getText(); 77 shlObjectName.dispose(); 78 } 79 }); 80 btnOk.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); 81 btnOk.setText("Ok"); 82 83 Button btnAbort = new Button(shlObjectName, SWT.NONE); 84 btnAbort.addSelectionListener(new SelectionAdapter() { 85 @Override 86 public void widgetSelected(SelectionEvent e) { 87 shlObjectName.dispose(); 88 } 89 }); 90 btnAbort.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); 91 btnAbort.setText("Abort"); 92 93 } 94 95 public String getObjectName() { 96 return objectName; 97 } 96 98 } -
trunk/quest-ui-swt/src/main/java/de/ugoe/cs/quest/ui/swt/InsertAssertionDialog.java
r548 r570 1 1 2 package de.ugoe.cs.quest.ui.swt; 2 3 … … 21 22 public class InsertAssertionDialog extends Dialog { 22 23 23 protected Event result; 24 protected Shell shell; 25 26 private TabFolder tabFolder; 27 28 List<AbstractInsertEventComposite> insertEventComposites; 29 SortedSet<String> targets; 24 protected Event result; 25 protected Shell shell; 30 26 31 /** 32 * Create the dialog. 33 * @param parent 34 * @param style 35 */ 36 public InsertAssertionDialog(Shell parent, int style, SortedSet<String> targets) { 37 super(parent, style); 38 setText("SWT Dialog"); 39 this.targets = targets; 40 } 27 private TabFolder tabFolder; 41 28 42 /** 43 * Open the dialog. 44 * @return the result 45 */ 46 public Event open() { 47 result = null; 48 insertEventComposites = new ArrayList<AbstractInsertEventComposite>(); 49 createContents(); 50 shell.open(); 51 shell.layout(); 52 Display display = getParent().getDisplay(); 53 while (!shell.isDisposed()) { 54 if (!display.readAndDispatch()) { 55 display.sleep(); 56 } 57 } 58 return result; 59 } 29 List<AbstractInsertEventComposite> insertEventComposites; 30 SortedSet<String> targets; 60 31 61 /** 62 * Create contents of the dialog. 63 */ 64 private void createContents() { 65 shell = new Shell(getParent(), SWT.SHELL_TRIM | SWT.BORDER | SWT.APPLICATION_MODAL); 66 shell.setSize(450, 300); 67 shell.setText(getText()); 68 shell.setLayout(new GridLayout(2, false)); 69 70 tabFolder = new TabFolder(shell, SWT.NONE); 71 tabFolder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); 72 73 74 TabItem tbtmTextEquals = new TabItem(tabFolder, SWT.NONE); 75 tbtmTextEquals.setText("TextEquals"); 76 AbstractInsertEventComposite compTextEquals = new InsertTextEquals(tabFolder, SWT.NO_BACKGROUND, targets); 77 tbtmTextEquals.setControl(compTextEquals); 78 insertEventComposites.add(compTextEquals); 79 80 TabItem tbtmFileEquals = new TabItem(tabFolder, SWT.NONE); 81 tbtmFileEquals.setText("FileEquals"); 82 AbstractInsertEventComposite compFileEquals = new InsertFileEquals(tabFolder, SWT.NO_BACKGROUND, targets); 83 tbtmFileEquals.setControl(compFileEquals); 84 insertEventComposites.add(compFileEquals); 85 86 Button btnInsert = new Button(shell, SWT.NONE); 87 btnInsert.setText("Insert"); 88 btnInsert.addSelectionListener(new SelectionAdapter() { 89 @Override 90 public void widgetSelected(SelectionEvent e) { 91 int index = tabFolder.getSelectionIndex(); 92 result = insertEventComposites.get(index).getEvent(); 93 shell.dispose(); 94 } 95 }); 96 97 Button btnAbort = new Button(shell, SWT.NONE); 98 btnAbort.setText("Abort"); 99 btnAbort.addSelectionListener(new SelectionAdapter() { 100 @Override 101 public void widgetSelected(SelectionEvent e) { 102 shell.dispose(); 103 } 104 }); 105 } 32 /** 33 * Create the dialog. 34 * 35 * @param parent 36 * @param style 37 */ 38 public InsertAssertionDialog(Shell parent, int style, SortedSet<String> targets) { 39 super(parent, style); 40 setText("SWT Dialog"); 41 this.targets = targets; 42 } 43 44 /** 45 * Open the dialog. 46 * 47 * @return the result 48 */ 49 public Event open() { 50 result = null; 51 insertEventComposites = new ArrayList<AbstractInsertEventComposite>(); 52 createContents(); 53 shell.open(); 54 shell.layout(); 55 Display display = getParent().getDisplay(); 56 while (!shell.isDisposed()) { 57 if (!display.readAndDispatch()) { 58 display.sleep(); 59 } 60 } 61 return result; 62 } 63 64 /** 65 * Create contents of the dialog. 66 */ 67 private void createContents() { 68 shell = new Shell(getParent(), SWT.SHELL_TRIM | SWT.BORDER | SWT.APPLICATION_MODAL); 69 shell.setSize(450, 300); 70 shell.setText(getText()); 71 shell.setLayout(new GridLayout(2, false)); 72 73 tabFolder = new TabFolder(shell, SWT.NONE); 74 tabFolder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); 75 76 TabItem tbtmTextEquals = new TabItem(tabFolder, SWT.NONE); 77 tbtmTextEquals.setText("TextEquals"); 78 AbstractInsertEventComposite compTextEquals = 79 new InsertTextEquals(tabFolder, SWT.NO_BACKGROUND, targets); 80 tbtmTextEquals.setControl(compTextEquals); 81 insertEventComposites.add(compTextEquals); 82 83 TabItem tbtmFileEquals = new TabItem(tabFolder, SWT.NONE); 84 tbtmFileEquals.setText("FileEquals"); 85 AbstractInsertEventComposite compFileEquals = 86 new InsertFileEquals(tabFolder, SWT.NO_BACKGROUND, targets); 87 tbtmFileEquals.setControl(compFileEquals); 88 insertEventComposites.add(compFileEquals); 89 90 Button btnInsert = new Button(shell, SWT.NONE); 91 btnInsert.setText("Insert"); 92 btnInsert.addSelectionListener(new SelectionAdapter() { 93 @Override 94 public void widgetSelected(SelectionEvent e) { 95 int index = tabFolder.getSelectionIndex(); 96 result = insertEventComposites.get(index).getEvent(); 97 shell.dispose(); 98 } 99 }); 100 101 Button btnAbort = new Button(shell, SWT.NONE); 102 btnAbort.setText("Abort"); 103 btnAbort.addSelectionListener(new SelectionAdapter() { 104 @Override 105 public void widgetSelected(SelectionEvent e) { 106 shell.dispose(); 107 } 108 }); 109 } 106 110 } -
trunk/quest-ui-swt/src/main/java/de/ugoe/cs/quest/ui/swt/InsertFileEquals.java
r548 r570 1 1 2 package de.ugoe.cs.quest.ui.swt; 2 3 … … 20 21 21 22 public class InsertFileEquals extends AbstractInsertEventComposite { 22 23 23 private Text actualText; 24 private Text expectedText; 24 25 25 public InsertFileEquals(Composite parent, int style) { 26 this(parent, style, null); 27 } 28 29 /** 30 * Create the composite. 31 * @param parent 32 * @param style 33 */ 34 public InsertFileEquals(Composite parent, int style, SortedSet<String> targets) { 35 super(parent, style, targets); 36 setLayout(new GridLayout(3, false)); 37 38 39 Label lblExpectedFile = new Label(this, SWT.NONE); 40 lblExpectedFile.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); 41 lblExpectedFile.setText("Expected file:"); 42 43 expectedText = new Text(this, SWT.BORDER); 44 expectedText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); 45 46 Button btnSearch = new Button(this, SWT.NONE); 47 btnSearch.addSelectionListener(new SelectionAdapter() { 48 @Override 49 public void widgetSelected(SelectionEvent e) { 50 FileDialog fileDialog = new FileDialog(getShell(), SWT.OPEN); 51 String filename = fileDialog.open(); 52 if( filename!= null ) { 53 expectedText.setText(filename); 54 } 55 } 56 }); 57 btnSearch.setText("Search..."); 58 59 Label lblActualFile = new Label(this, SWT.NONE); 60 61 lblActualFile.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); 62 lblActualFile.setText("Actual file:"); 63 64 actualText = new Text(this, SWT.BORDER); 65 actualText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); 66 new Label(this, SWT.NONE); 26 public InsertFileEquals(Composite parent, int style) { 27 this(parent, style, null); 28 } 67 29 68 } 30 /** 31 * Create the composite. 32 * 33 * @param parent 34 * @param style 35 */ 36 public InsertFileEquals(Composite parent, int style, SortedSet<String> targets) { 37 super(parent, style, targets); 38 setLayout(new GridLayout(3, false)); 69 39 70 @Override 71 protected void checkSubclass() { 72 // Disable the check that prevents subclassing of SWT components 73 } 40 Label lblExpectedFile = new Label(this, SWT.NONE); 41 lblExpectedFile.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); 42 lblExpectedFile.setText("Expected file:"); 74 43 75 @Override 76 public Event getEvent() { 77 FileEqualsReplay replay = new FileEqualsReplay(expectedText.getText(), actualText.getText()); 78 Event event = new Event(new FileEqualsAssertEvent()); 79 event.addReplayable(replay); 80 return event; 81 } 44 expectedText = new Text(this, SWT.BORDER); 45 expectedText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); 46 47 Button btnSearch = new Button(this, SWT.NONE); 48 btnSearch.addSelectionListener(new SelectionAdapter() { 49 @Override 50 public void widgetSelected(SelectionEvent e) { 51 FileDialog fileDialog = new FileDialog(getShell(), SWT.OPEN); 52 String filename = fileDialog.open(); 53 if (filename != null) { 54 expectedText.setText(filename); 55 } 56 } 57 }); 58 btnSearch.setText("Search..."); 59 60 Label lblActualFile = new Label(this, SWT.NONE); 61 62 lblActualFile.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); 63 lblActualFile.setText("Actual file:"); 64 65 actualText = new Text(this, SWT.BORDER); 66 actualText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); 67 new Label(this, SWT.NONE); 68 69 } 70 71 @Override 72 protected void checkSubclass() { 73 // Disable the check that prevents subclassing of SWT components 74 } 75 76 @Override 77 public Event getEvent() { 78 FileEqualsReplay replay = 79 new FileEqualsReplay(expectedText.getText(), actualText.getText()); 80 Event event = new Event(new FileEqualsAssertEvent()); 81 event.addReplayable(replay); 82 return event; 83 } 82 84 83 85 } -
trunk/quest-ui-swt/src/main/java/de/ugoe/cs/quest/ui/swt/InsertTextEquals.java
r548 r570 1 1 2 package de.ugoe.cs.quest.ui.swt; 2 3 … … 13 14 import org.eclipse.swt.widgets.TreeItem; 14 15 15 import de.ugoe.cs.quest.assertions.AssertEvent;16 16 import de.ugoe.cs.quest.assertions.TextEqualsAssertEventType; 17 import de.ugoe.cs.quest.assertions.TextEqualsReplay;18 17 import de.ugoe.cs.quest.eventcore.Event; 19 import de.ugoe.cs.quest.eventcore.IEventTarget;20 18 import de.ugoe.cs.util.ArrayTools; 21 19 … … 24 22 25 23 public class InsertTextEquals extends AbstractInsertEventComposite { 26 private Text expectedText; 27 private Tree targetTree; 28 private Text targetText; 29 30 /** 31 * Create the composite. 32 * @param parent 33 * @param style 34 */ 35 public InsertTextEquals(Composite parent, int style, SortedSet<String> targets) { 36 super(parent, style, targets); 37 setLayout(new GridLayout(3, false)); 38 39 Label lblExpectedValue = new Label(this, SWT.NONE); 40 lblExpectedValue.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); 41 lblExpectedValue.setText("Expected Value:"); 42 43 expectedText = new Text(this, SWT.BORDER); 44 expectedText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1)); 45 46 Label lblTargetWidget = new Label(this, SWT.NONE); 47 lblTargetWidget.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); 48 lblTargetWidget.setText("Target Widget:"); 49 50 targetText = new Text(this, SWT.BORDER); 51 targetText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1)); 52 new Label(this, SWT.NONE); 53 54 targetTree = new Tree(this, SWT.BORDER); 55 targetTree.addSelectionListener(new SelectionAdapter() { 56 @Override 57 public void widgetSelected(SelectionEvent e) { 58 TreeItem[] selection = targetTree.getSelection(); 59 if( selection.length==1 ) { 60 TreeItem item = selection[0]; 61 String targetString = item.getText(); 62 item = item.getParentItem(); 63 while( item!=null ) { 64 // TODO the "." is hard coded for the JFCMonitor. should be flexible 65 targetString = item.getText()+"."+targetString; 66 item = item.getParentItem(); 67 } 68 targetText.setText(targetString); 69 } 70 } 71 }); 72 targetTree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); 73 buildTargetTree(); 74 new Label(this, SWT.NONE); 75 76 Button btnExpandAll = new Button(this, SWT.NONE); 77 btnExpandAll.addSelectionListener(new SelectionAdapter() { 78 @Override 79 public void widgetSelected(SelectionEvent e) { 80 expandAll(targetTree, true); 81 } 82 }); 83 btnExpandAll.setText("Expand all"); 84 85 Button btnCollapseAll = new Button(this, SWT.NONE); 86 btnCollapseAll.addSelectionListener(new SelectionAdapter() { 87 @Override 88 public void widgetSelected(SelectionEvent e) { 89 expandAll(targetTree, false); 90 } 91 }); 92 btnCollapseAll.setText("Collapse all"); 24 private Text expectedText; 25 private Tree targetTree; 26 private Text targetText; 93 27 94 } 28 /** 29 * Create the composite. 30 * 31 * @param parent 32 * @param style 33 */ 34 public InsertTextEquals(Composite parent, int style, SortedSet<String> targets) { 35 super(parent, style, targets); 36 setLayout(new GridLayout(3, false)); 95 37 96 @Override 97 protected void checkSubclass() { 98 // Disable the check that prevents subclassing of SWT components 99 } 38 Label lblExpectedValue = new Label(this, SWT.NONE); 39 lblExpectedValue.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); 40 lblExpectedValue.setText("Expected Value:"); 100 41 101 @Override 102 public Event getEvent() { 103 IEventTarget target = targetText.getText(); 104 TextEqualsReplay replay = new TextEqualsReplay(expectedText.getText(), target); 105 Event event = new Event(new TextEqualsAssertEventType()); 106 event.setTarget(target); 107 event.addReplayable(replay); 108 return event; 109 } 110 111 private void buildTargetTree() { 112 for( String target : targets ) { 113 TreeItem currentParent = null; 114 TreeItem[] currentItems = targetTree.getItems(); 115 116 //TODO needs rule for target splitting. currently its hard coded for JFCEvent targets. 117 String[] targetParts = target.split("\\.\\["); 118 for( String targetPart : targetParts) { 119 String[] currentTexts = new String[currentItems.length]; 120 for( int i=0; i<currentItems.length ; i++ ) { 121 currentTexts[i] = currentItems[i].getText(); 122 } 123 if( currentParent!=null ) { 124 targetPart = "["+targetPart; 125 } 126 int index = ArrayTools.findIndex(currentTexts, targetPart); 127 if( index>= 0 ) { 128 currentParent = currentItems[index]; 129 } else { 130 if( currentParent==null ) { 131 currentParent = new TreeItem(targetTree, SWT.NULL); 132 currentParent.setText(targetPart); 133 } else { 134 currentParent = new TreeItem(currentParent, SWT.NULL); 135 currentParent.setText(targetPart); 136 } 137 } 138 currentItems = currentParent.getItems(); 139 } 140 } 42 expectedText = new Text(this, SWT.BORDER); 43 expectedText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1)); 141 44 142 } 143 144 private void expandAll(Tree tree, boolean expanded) { 145 for( TreeItem item : tree.getItems() ) { 146 expandAll(item, expanded); 147 } 148 } 149 150 private void expandAll(TreeItem item, boolean expanded) { 151 item.setExpanded(expanded); 152 for( TreeItem childItem : item.getItems() ) { 153 expandAll(childItem, expanded); 154 } 155 } 156 157 45 Label lblTargetWidget = new Label(this, SWT.NONE); 46 lblTargetWidget.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); 47 lblTargetWidget.setText("Target Widget:"); 48 49 targetText = new Text(this, SWT.BORDER); 50 targetText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1)); 51 new Label(this, SWT.NONE); 52 53 targetTree = new Tree(this, SWT.BORDER); 54 targetTree.addSelectionListener(new SelectionAdapter() { 55 @Override 56 public void widgetSelected(SelectionEvent e) { 57 TreeItem[] selection = targetTree.getSelection(); 58 if (selection.length == 1) { 59 TreeItem item = selection[0]; 60 String targetString = item.getText(); 61 item = item.getParentItem(); 62 while (item != null) { 63 // TODO the "." is hard coded for the JFCMonitor. should be flexible 64 targetString = item.getText() + "." + targetString; 65 item = item.getParentItem(); 66 } 67 targetText.setText(targetString); 68 } 69 } 70 }); 71 targetTree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); 72 buildTargetTree(); 73 new Label(this, SWT.NONE); 74 75 Button btnExpandAll = new Button(this, SWT.NONE); 76 btnExpandAll.addSelectionListener(new SelectionAdapter() { 77 @Override 78 public void widgetSelected(SelectionEvent e) { 79 expandAll(targetTree, true); 80 } 81 }); 82 btnExpandAll.setText("Expand all"); 83 84 Button btnCollapseAll = new Button(this, SWT.NONE); 85 btnCollapseAll.addSelectionListener(new SelectionAdapter() { 86 @Override 87 public void widgetSelected(SelectionEvent e) { 88 expandAll(targetTree, false); 89 } 90 }); 91 btnCollapseAll.setText("Collapse all"); 92 93 } 94 95 @Override 96 protected void checkSubclass() { 97 // Disable the check that prevents subclassing of SWT components 98 } 99 100 @Override 101 public Event getEvent() { 102 // TODO make compatible to new event core 103 /* 104 * IEventTarget target = targetText.getText(); TextEqualsReplay replay = new 105 * TextEqualsReplay(expectedText.getText(), target); 106 */ 107 Event event = new Event(new TextEqualsAssertEventType()); 108 /* 109 * event.setTarget(target); event.addReplayable(replay); 110 */ 111 return event; 112 } 113 114 private void buildTargetTree() { 115 for (String target : targets) { 116 TreeItem currentParent = null; 117 TreeItem[] currentItems = targetTree.getItems(); 118 119 // TODO needs rule for target splitting. currently its hard coded for JFCEvent targets. 120 String[] targetParts = target.split("\\.\\["); 121 for (String targetPart : targetParts) { 122 String[] currentTexts = new String[currentItems.length]; 123 for (int i = 0; i < currentItems.length; i++) { 124 currentTexts[i] = currentItems[i].getText(); 125 } 126 if (currentParent != null) { 127 targetPart = "[" + targetPart; 128 } 129 int index = ArrayTools.findIndex(currentTexts, targetPart); 130 if (index >= 0) { 131 currentParent = currentItems[index]; 132 } 133 else { 134 if (currentParent == null) { 135 currentParent = new TreeItem(targetTree, SWT.NULL); 136 currentParent.setText(targetPart); 137 } 138 else { 139 currentParent = new TreeItem(currentParent, SWT.NULL); 140 currentParent.setText(targetPart); 141 } 142 } 143 currentItems = currentParent.getItems(); 144 } 145 } 146 147 } 148 149 private void expandAll(Tree tree, boolean expanded) { 150 for (TreeItem item : tree.getItems()) { 151 expandAll(item, expanded); 152 } 153 } 154 155 private void expandAll(TreeItem item, boolean expanded) { 156 item.setExpanded(expanded); 157 for (TreeItem childItem : item.getItems()) { 158 expandAll(childItem, expanded); 159 } 160 } 161 158 162 } -
trunk/quest-ui-swt/src/main/java/de/ugoe/cs/quest/ui/swt/MainWindow.java
r526 r570 1 1 2 package de.ugoe.cs.quest.ui.swt; 2 3 … … 27 28 */ 28 29 public class MainWindow { 29 30 private List<String> startupCommands; 31 32 protected Shell shlEventbenchConsole; 33 34 protected TabItem consoleTab; 35 protected TabItem sequencesTab; 36 protected TabItem modelsTab; 37 protected TabItem dataTab; 38 protected ConsoleTabComposite consoleTabComposite; 39 protected SequencesTabComposite sequencesTabComposite; 40 protected ModelsTabComposite modelsTabComposite; 41 protected DataTabComposite dataTabComposite; 42 43 protected CommandHistoryDialog historyDialog; 44 45 public MainWindow(List<String> startupCommands) { 46 this.startupCommands = startupCommands; 47 } 48 49 /** 50 * <p> 51 * Open the window. 52 * </p> 53 * 54 * @wbp.parser.entryPoint 55 */ 56 public void open() { 57 Display display = Display.getDefault(); 58 createContents(); 59 new SWTConsole(consoleTabComposite.textConsoleOutput); 60 historyDialog = new CommandHistoryDialog(shlEventbenchConsole, SWT.NONE); 61 shlEventbenchConsole.open(); 62 shlEventbenchConsole.layout(); 63 for(String command : startupCommands ) { 64 CommandExecuter.getInstance().exec(command); 65 } 66 while (!shlEventbenchConsole.isDisposed()) { 67 if (!display.readAndDispatch()) { 68 display.sleep(); 69 } 70 } 71 } 72 73 /** 74 * <p> 75 * Create contents of the window. 76 * </p> 77 */ 78 protected void createContents() { 79 shlEventbenchConsole = new Shell(); 80 shlEventbenchConsole.setSize(800, 600); 81 shlEventbenchConsole.setText("EventBench Console"); 82 shlEventbenchConsole.setLayout(new GridLayout(1, false)); 83 84 createMenu(); 85 createTabs(); 86 } 87 88 /** 89 * </p> Creates the menu of the window. </p> 90 */ 91 private void createMenu() { 92 Menu menu = new Menu(shlEventbenchConsole, SWT.BAR); 93 shlEventbenchConsole.setMenuBar(menu); 94 95 MenuItem mntmFile = new MenuItem(menu, SWT.CASCADE); 96 mntmFile.setText("File"); 97 98 Menu menu_1 = new Menu(mntmFile); 99 mntmFile.setMenu(menu_1); 100 101 MenuItem mntmShowHistory = new MenuItem(menu_1, SWT.NONE); 102 mntmShowHistory.addSelectionListener(new SelectionAdapter() { 103 @Override 104 public void widgetSelected(SelectionEvent e) { 105 if (!historyDialog.isOpen()) { 106 historyDialog.open(); 107 } 108 } 109 }); 110 mntmShowHistory.setText("Show History"); 111 112 MenuItem mntmExecBatchFile = new MenuItem(menu_1, SWT.NONE); 113 mntmExecBatchFile.addSelectionListener(new SelectionAdapter() { 114 @Override 115 public void widgetSelected(SelectionEvent e) { 116 FileDialog fileDialog = new FileDialog(shlEventbenchConsole, 117 SWT.OPEN); 118 String filename = fileDialog.open(); 119 if (filename != null) { 120 String command = "exec '" + filename + "'"; 121 CommandExecuter.getInstance().exec(command); 122 } 123 } 124 }); 125 mntmExecBatchFile.setText("Exec. Batch File"); 126 127 new MenuItem(menu_1, SWT.SEPARATOR); 128 129 MenuItem mntmLoad = new MenuItem(menu_1, SWT.NONE); 130 mntmLoad.addSelectionListener(new SelectionAdapter() { 131 @Override 132 public void widgetSelected(SelectionEvent e) { 133 FileDialog fileDialog = new FileDialog(shlEventbenchConsole, 134 SWT.OPEN); 135 String filename = fileDialog.open(); 136 if (filename != null) { 137 String command = "load '" + filename + "'"; 138 CommandExecuter.getInstance().exec(command); 139 } 140 } 141 }); 142 mntmLoad.setText("Load..."); 143 144 MenuItem mntmSave = new MenuItem(menu_1, SWT.NONE); 145 mntmSave.addSelectionListener(new SelectionAdapter() { 146 @Override 147 public void widgetSelected(SelectionEvent e) { 148 FileDialog fileDialog = new FileDialog(shlEventbenchConsole, 149 SWT.SAVE); 150 String filename = fileDialog.open(); 151 if (filename != null) { 152 String command = "save '" + filename + "'"; 153 CommandExecuter.getInstance().exec(command); 154 } 155 } 156 }); 157 mntmSave.setText("Save..."); 158 159 new MenuItem(menu_1, SWT.SEPARATOR); 160 161 MenuItem mntmExit = new MenuItem(menu_1, SWT.NONE); 162 mntmExit.addSelectionListener(new SelectionAdapter() { 163 @Override 164 public void widgetSelected(SelectionEvent e) { 165 shlEventbenchConsole.dispose(); 166 } 167 }); 168 mntmExit.setText("Exit"); 169 170 MenuItem mntmHelp = new MenuItem(menu, SWT.CASCADE); 171 mntmHelp.setText("Help"); 172 173 Menu menu_2 = new Menu(mntmHelp); 174 mntmHelp.setMenu(menu_2); 175 176 MenuItem mntmAbout = new MenuItem(menu_2, SWT.NONE); 177 mntmAbout.addSelectionListener(new SelectionAdapter() { 178 @Override 179 public void widgetSelected(SelectionEvent e) { 180 AboutDialog aboutDialog = new AboutDialog(shlEventbenchConsole, 181 SWT.NONE); 182 aboutDialog.open(); 183 } 184 }); 185 mntmAbout.setText("About"); 186 } 187 188 /** 189 * <p> 190 * Creates the central TabFolder of the window. 191 * </p> 192 */ 193 private void createTabs() { 194 TabFolder tabFolder = new TabFolder(shlEventbenchConsole, SWT.NONE); 195 tabFolder.addSelectionListener(new SelectionAdapter() { 196 @Override 197 public void widgetSelected(SelectionEvent e) { 198 if (e.item == sequencesTab) { 199 sequencesTabComposite.updateSequenceList(); 200 } else if (e.item == modelsTab) { 201 modelsTabComposite.updateModelList(); 202 } else if (e.item == dataTab) { 203 dataTabComposite.updateDataList(); 204 } 205 } 206 }); 207 tabFolder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 208 1)); 209 210 consoleTab = new TabItem(tabFolder, SWT.NONE); 211 consoleTab.setText("Console"); 212 213 consoleTabComposite = new ConsoleTabComposite(tabFolder, 214 SWT.NO_BACKGROUND); 215 consoleTab.setControl(consoleTabComposite); 216 217 sequencesTab = new TabItem(tabFolder, SWT.NONE); 218 sequencesTab.setText("Sequences"); 219 220 sequencesTabComposite = new SequencesTabComposite(tabFolder, 221 SWT.NO_BACKGROUND); 222 sequencesTab.setControl(sequencesTabComposite); 223 224 modelsTab = new TabItem(tabFolder, SWT.NONE); 225 modelsTab.setText("Models"); 226 227 modelsTabComposite = new ModelsTabComposite(tabFolder, 228 SWT.NO_BACKGROUND); 229 modelsTab.setControl(modelsTabComposite); 230 231 dataTab = new TabItem(tabFolder, SWT.NONE); 232 dataTab.setText("Data"); 233 234 dataTabComposite = new DataTabComposite(tabFolder, SWT.NO_BACKGROUND); 235 dataTab.setControl(dataTabComposite); 236 } 30 31 private List<String> startupCommands; 32 33 protected Shell shlEventbenchConsole; 34 35 protected TabItem consoleTab; 36 protected TabItem sequencesTab; 37 protected TabItem modelsTab; 38 protected TabItem dataTab; 39 protected ConsoleTabComposite consoleTabComposite; 40 protected SequencesTabComposite sequencesTabComposite; 41 protected ModelsTabComposite modelsTabComposite; 42 protected DataTabComposite dataTabComposite; 43 44 protected CommandHistoryDialog historyDialog; 45 46 public MainWindow(List<String> startupCommands) { 47 this.startupCommands = startupCommands; 48 } 49 50 /** 51 * <p> 52 * Open the window. 53 * </p> 54 * 55 * @wbp.parser.entryPoint 56 */ 57 public void open() { 58 Display display = Display.getDefault(); 59 createContents(); 60 new SWTConsole(consoleTabComposite.textConsoleOutput); 61 historyDialog = new CommandHistoryDialog(shlEventbenchConsole, SWT.NONE); 62 shlEventbenchConsole.open(); 63 shlEventbenchConsole.layout(); 64 for (String command : startupCommands) { 65 CommandExecuter.getInstance().exec(command); 66 } 67 while (!shlEventbenchConsole.isDisposed()) { 68 if (!display.readAndDispatch()) { 69 display.sleep(); 70 } 71 } 72 } 73 74 /** 75 * <p> 76 * Create contents of the window. 77 * </p> 78 */ 79 protected void createContents() { 80 shlEventbenchConsole = new Shell(); 81 shlEventbenchConsole.setSize(800, 600); 82 shlEventbenchConsole.setText("EventBench Console"); 83 shlEventbenchConsole.setLayout(new GridLayout(1, false)); 84 85 createMenu(); 86 createTabs(); 87 } 88 89 /** 90 * </p> Creates the menu of the window. </p> 91 */ 92 private void createMenu() { 93 Menu menu = new Menu(shlEventbenchConsole, SWT.BAR); 94 shlEventbenchConsole.setMenuBar(menu); 95 96 MenuItem mntmFile = new MenuItem(menu, SWT.CASCADE); 97 mntmFile.setText("File"); 98 99 Menu menu_1 = new Menu(mntmFile); 100 mntmFile.setMenu(menu_1); 101 102 MenuItem mntmShowHistory = new MenuItem(menu_1, SWT.NONE); 103 mntmShowHistory.addSelectionListener(new SelectionAdapter() { 104 @Override 105 public void widgetSelected(SelectionEvent e) { 106 if (!historyDialog.isOpen()) { 107 historyDialog.open(); 108 } 109 } 110 }); 111 mntmShowHistory.setText("Show History"); 112 113 MenuItem mntmExecBatchFile = new MenuItem(menu_1, SWT.NONE); 114 mntmExecBatchFile.addSelectionListener(new SelectionAdapter() { 115 @Override 116 public void widgetSelected(SelectionEvent e) { 117 FileDialog fileDialog = new FileDialog(shlEventbenchConsole, SWT.OPEN); 118 String filename = fileDialog.open(); 119 if (filename != null) { 120 String command = "exec '" + filename + "'"; 121 CommandExecuter.getInstance().exec(command); 122 } 123 } 124 }); 125 mntmExecBatchFile.setText("Exec. Batch File"); 126 127 new MenuItem(menu_1, SWT.SEPARATOR); 128 129 MenuItem mntmLoad = new MenuItem(menu_1, SWT.NONE); 130 mntmLoad.addSelectionListener(new SelectionAdapter() { 131 @Override 132 public void widgetSelected(SelectionEvent e) { 133 FileDialog fileDialog = new FileDialog(shlEventbenchConsole, SWT.OPEN); 134 String filename = fileDialog.open(); 135 if (filename != null) { 136 String command = "load '" + filename + "'"; 137 CommandExecuter.getInstance().exec(command); 138 } 139 } 140 }); 141 mntmLoad.setText("Load..."); 142 143 MenuItem mntmSave = new MenuItem(menu_1, SWT.NONE); 144 mntmSave.addSelectionListener(new SelectionAdapter() { 145 @Override 146 public void widgetSelected(SelectionEvent e) { 147 FileDialog fileDialog = new FileDialog(shlEventbenchConsole, SWT.SAVE); 148 String filename = fileDialog.open(); 149 if (filename != null) { 150 String command = "save '" + filename + "'"; 151 CommandExecuter.getInstance().exec(command); 152 } 153 } 154 }); 155 mntmSave.setText("Save..."); 156 157 new MenuItem(menu_1, SWT.SEPARATOR); 158 159 MenuItem mntmExit = new MenuItem(menu_1, SWT.NONE); 160 mntmExit.addSelectionListener(new SelectionAdapter() { 161 @Override 162 public void widgetSelected(SelectionEvent e) { 163 shlEventbenchConsole.dispose(); 164 } 165 }); 166 mntmExit.setText("Exit"); 167 168 MenuItem mntmHelp = new MenuItem(menu, SWT.CASCADE); 169 mntmHelp.setText("Help"); 170 171 Menu menu_2 = new Menu(mntmHelp); 172 mntmHelp.setMenu(menu_2); 173 174 MenuItem mntmAbout = new MenuItem(menu_2, SWT.NONE); 175 mntmAbout.addSelectionListener(new SelectionAdapter() { 176 @Override 177 public void widgetSelected(SelectionEvent e) { 178 AboutDialog aboutDialog = new AboutDialog(shlEventbenchConsole, SWT.NONE); 179 aboutDialog.open(); 180 } 181 }); 182 mntmAbout.setText("About"); 183 } 184 185 /** 186 * <p> 187 * Creates the central TabFolder of the window. 188 * </p> 189 */ 190 private void createTabs() { 191 TabFolder tabFolder = new TabFolder(shlEventbenchConsole, SWT.NONE); 192 tabFolder.addSelectionListener(new SelectionAdapter() { 193 @Override 194 public void widgetSelected(SelectionEvent e) { 195 if (e.item == sequencesTab) { 196 sequencesTabComposite.updateSequenceList(); 197 } 198 else if (e.item == modelsTab) { 199 modelsTabComposite.updateModelList(); 200 } 201 else if (e.item == dataTab) { 202 dataTabComposite.updateDataList(); 203 } 204 } 205 }); 206 tabFolder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); 207 208 consoleTab = new TabItem(tabFolder, SWT.NONE); 209 consoleTab.setText("Console"); 210 211 consoleTabComposite = new ConsoleTabComposite(tabFolder, SWT.NO_BACKGROUND); 212 consoleTab.setControl(consoleTabComposite); 213 214 sequencesTab = new TabItem(tabFolder, SWT.NONE); 215 sequencesTab.setText("Sequences"); 216 217 sequencesTabComposite = new SequencesTabComposite(tabFolder, SWT.NO_BACKGROUND); 218 sequencesTab.setControl(sequencesTabComposite); 219 220 modelsTab = new TabItem(tabFolder, SWT.NONE); 221 modelsTab.setText("Models"); 222 223 modelsTabComposite = new ModelsTabComposite(tabFolder, SWT.NO_BACKGROUND); 224 modelsTab.setControl(modelsTabComposite); 225 226 dataTab = new TabItem(tabFolder, SWT.NONE); 227 dataTab.setText("Data"); 228 229 dataTabComposite = new DataTabComposite(tabFolder, SWT.NO_BACKGROUND); 230 dataTab.setControl(dataTabComposite); 231 } 237 232 } -
trunk/quest-ui-swt/src/main/java/de/ugoe/cs/quest/ui/swt/ModelPropertiesDialog.java
r526 r570 1 1 2 package de.ugoe.cs.quest.ui.swt; 2 3 … … 22 23 public class ModelPropertiesDialog extends Dialog { 23 24 24 private IStochasticProcess process; 25 26 protected Shell shlModelProperties; 25 private IStochasticProcess process; 27 26 28 /** 29 * Create the dialog. 30 * @param parent 31 * @param style 32 */ 33 public ModelPropertiesDialog(Shell parent, int style) { 34 super(parent, style); 35 setText("SWT Dialog"); 36 } 27 protected Shell shlModelProperties; 37 28 38 /** 39 * Open the dialog. 40 */ 41 public void open() { 42 createContents(); 43 shlModelProperties.open(); 44 shlModelProperties.layout(); 45 Display display = getParent().getDisplay(); 46 while (!shlModelProperties.isDisposed()) { 47 if (!display.readAndDispatch()) { 48 display.sleep(); 49 } 50 } 51 } 29 /** 30 * Create the dialog. 31 * 32 * @param parent 33 * @param style 34 */ 35 public ModelPropertiesDialog(Shell parent, int style) { 36 super(parent, style); 37 setText("SWT Dialog"); 38 } 52 39 53 /** 54 * Create contents of the dialog. 55 */ 56 private void createContents() { 57 shlModelProperties = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.RESIZE); 58 shlModelProperties.setSize(230, 318); 59 shlModelProperties.setText("Model Properties"); 60 shlModelProperties.setLayout(new GridLayout(2, false)); 61 62 Group grpEvents = new Group(shlModelProperties, SWT.NONE); 63 FillLayout fl_grpEvents = new FillLayout(SWT.HORIZONTAL); 64 fl_grpEvents.marginHeight = 5; 65 fl_grpEvents.marginWidth = 5; 66 grpEvents.setLayout(fl_grpEvents); 67 grpEvents.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); 68 grpEvents.setText("Events"); 69 70 List list = new List(grpEvents, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); 71 for( String symbol : process.getSymbolStrings() ) { 72 if( symbol==null ) { 73 list.add("null"); 74 } else { 75 list.add(symbol); 76 } 77 } 78 79 Group grpStatistics = new Group(shlModelProperties, SWT.NONE); 80 grpStatistics.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1)); 81 grpStatistics.setText("Statistics"); 82 grpStatistics.setLayout(new GridLayout(2, false)); 83 84 Label lblNumEvents = new Label(grpStatistics, SWT.NONE); 85 lblNumEvents.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1)); 86 lblNumEvents.setText("Num. Events"); 87 88 Label label = new Label(grpStatistics, SWT.RIGHT); 89 label.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1)); 90 label.setText(""+process.getNumSymbols()); 91 92 Label lblNumTrieLeafs = new Label(grpStatistics, SWT.NONE); 93 lblNumTrieLeafs.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1)); 94 lblNumTrieLeafs.setText("Size (Flattend FOM)"); 95 96 Label label_1 = new Label(grpStatistics, SWT.RIGHT); 97 label_1.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1)); 98 label_1.setText(""+process.getNumFOMStates()); 99 100 Label lblEntropy = new Label(grpStatistics, SWT.NONE); 101 lblEntropy.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1)); 102 lblEntropy.setText("Entropy"); 103 104 final Label label_2 = new Label(grpStatistics, SWT.RIGHT); 105 label_2.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1)); 106 label_2.setText("####"); 107 108 Button btnCalculateEntropy = new Button(shlModelProperties, SWT.NONE); 109 btnCalculateEntropy.addSelectionListener(new SelectionAdapter() { 110 @Override 111 public void widgetSelected(SelectionEvent e) { 112 if( process instanceof FirstOrderMarkovModel) { 113 label_2.setText(""+((FirstOrderMarkovModel) process).calcEntropy()); 114 } else { 115 MessageBox messageBox = new MessageBox(shlModelProperties, SWT.NONE); 116 messageBox.setText("Feature Not Available"); 117 messageBox.setMessage("The feature is currently only available for first-order Markov models."); 118 messageBox.open(); 119 } 120 } 121 }); 122 btnCalculateEntropy.setText("Calculate Entropy"); 123 124 Button btnClose = new Button(shlModelProperties, SWT.NONE); 125 btnClose.addSelectionListener(new SelectionAdapter() { 126 @Override 127 public void widgetSelected(SelectionEvent e) { 128 shlModelProperties.dispose(); 129 } 130 }); 131 btnClose.setText("Close"); 40 /** 41 * Open the dialog. 42 */ 43 public void open() { 44 createContents(); 45 shlModelProperties.open(); 46 shlModelProperties.layout(); 47 Display display = getParent().getDisplay(); 48 while (!shlModelProperties.isDisposed()) { 49 if (!display.readAndDispatch()) { 50 display.sleep(); 51 } 52 } 53 } 132 54 133 } 134 135 public void setStochasticProcess(IStochasticProcess process) { 136 this.process = process; 137 } 55 /** 56 * Create contents of the dialog. 57 */ 58 private void createContents() { 59 shlModelProperties = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.RESIZE); 60 shlModelProperties.setSize(230, 318); 61 shlModelProperties.setText("Model Properties"); 62 shlModelProperties.setLayout(new GridLayout(2, false)); 63 64 Group grpEvents = new Group(shlModelProperties, SWT.NONE); 65 FillLayout fl_grpEvents = new FillLayout(SWT.HORIZONTAL); 66 fl_grpEvents.marginHeight = 5; 67 fl_grpEvents.marginWidth = 5; 68 grpEvents.setLayout(fl_grpEvents); 69 grpEvents.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); 70 grpEvents.setText("Events"); 71 72 List list = new List(grpEvents, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); 73 for (String symbol : process.getSymbolStrings()) { 74 if (symbol == null) { 75 list.add("null"); 76 } 77 else { 78 list.add(symbol); 79 } 80 } 81 82 Group grpStatistics = new Group(shlModelProperties, SWT.NONE); 83 grpStatistics.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1)); 84 grpStatistics.setText("Statistics"); 85 grpStatistics.setLayout(new GridLayout(2, false)); 86 87 Label lblNumEvents = new Label(grpStatistics, SWT.NONE); 88 lblNumEvents.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1)); 89 lblNumEvents.setText("Num. Events"); 90 91 Label label = new Label(grpStatistics, SWT.RIGHT); 92 label.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1)); 93 label.setText("" + process.getNumSymbols()); 94 95 Label lblNumTrieLeafs = new Label(grpStatistics, SWT.NONE); 96 lblNumTrieLeafs.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1)); 97 lblNumTrieLeafs.setText("Size (Flattend FOM)"); 98 99 Label label_1 = new Label(grpStatistics, SWT.RIGHT); 100 label_1.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1)); 101 label_1.setText("" + process.getNumFOMStates()); 102 103 Label lblEntropy = new Label(grpStatistics, SWT.NONE); 104 lblEntropy.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1)); 105 lblEntropy.setText("Entropy"); 106 107 final Label label_2 = new Label(grpStatistics, SWT.RIGHT); 108 label_2.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1)); 109 label_2.setText("####"); 110 111 Button btnCalculateEntropy = new Button(shlModelProperties, SWT.NONE); 112 btnCalculateEntropy.addSelectionListener(new SelectionAdapter() { 113 @Override 114 public void widgetSelected(SelectionEvent e) { 115 if (process instanceof FirstOrderMarkovModel) { 116 label_2.setText("" + ((FirstOrderMarkovModel) process).calcEntropy()); 117 } 118 else { 119 MessageBox messageBox = new MessageBox(shlModelProperties, SWT.NONE); 120 messageBox.setText("Feature Not Available"); 121 messageBox 122 .setMessage("The feature is currently only available for first-order Markov models."); 123 messageBox.open(); 124 } 125 } 126 }); 127 btnCalculateEntropy.setText("Calculate Entropy"); 128 129 Button btnClose = new Button(shlModelProperties, SWT.NONE); 130 btnClose.addSelectionListener(new SelectionAdapter() { 131 @Override 132 public void widgetSelected(SelectionEvent e) { 133 shlModelProperties.dispose(); 134 } 135 }); 136 btnClose.setText("Close"); 137 138 } 139 140 public void setStochasticProcess(IStochasticProcess process) { 141 this.process = process; 142 } 138 143 } -
trunk/quest-ui-swt/src/main/java/de/ugoe/cs/quest/ui/swt/ModelsTabComposite.java
r526 r570 1 1 2 package de.ugoe.cs.quest.ui.swt; 2 3 … … 20 21 public class ModelsTabComposite extends Composite { 21 22 22 List modelList; 23 24 /** 25 * Create the composite. 26 * @param parent 27 * @param style 28 */ 29 public ModelsTabComposite(Composite parent, int style) { 30 super(parent, style); 31 createContents(); 32 } 33 34 private void createContents() { 35 setLayout(new GridLayout(5, false)); 36 37 modelList = new List(this, SWT.BORDER | SWT.V_SCROLL); 38 modelList.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 5, 1)); 39 40 Button btnShow = new Button(this, SWT.NONE); 41 btnShow.addSelectionListener(new SelectionAdapter() { 42 @Override 43 public void widgetSelected(SelectionEvent e) { 44 String[] selectedStrings = modelList.getSelection(); 45 if( selectedStrings.length==0 ) { 46 SWTHelpers.noSelectionError(getShell()); 47 return; 48 } 49 IStochasticProcess process = (IStochasticProcess) GlobalDataContainer.getInstance().getData(selectedStrings[0]); 50 if( process instanceof FirstOrderMarkovModel ) { 51 String command = "showMarkovModel " + selectedStrings[0]; 52 CommandExecuter.getInstance().exec(command); 53 } else { 54 MessageBox messageBox = new MessageBox(getShell(), SWT.NONE); 55 messageBox.setText("Feature Not Available"); 56 messageBox.setMessage("The feature is currently only available for first-order Markov models."); 57 messageBox.open(); 58 } 59 } 60 }); 61 btnShow.setText("Visualize"); 62 63 Button btnDelete_1 = new Button(this, SWT.NONE); 64 btnDelete_1.addSelectionListener(new SelectionAdapter() { 65 @Override 66 public void widgetSelected(SelectionEvent e) { 67 if( SWTHelpers.deleteSelectedFromStorage(modelList) ) { 68 updateModelList(); 69 } else { 70 SWTHelpers.noSelectionError(getShell()); 71 } 72 } 73 }); 74 btnDelete_1.setText("Delete"); 75 76 Button btnGenSequences = new Button(this, SWT.NONE); 77 btnGenSequences.addSelectionListener(new SelectionAdapter() { 78 @Override 79 public void widgetSelected(SelectionEvent e) { 80 String[] selectedStrings = modelList.getSelection(); 81 if( selectedStrings.length==0 ) { 82 SWTHelpers.noSelectionError(getShell()); 83 return; 84 } 85 GenerateSequencesDialog generateSequencesDialog = new GenerateSequencesDialog(getShell(), SWT.NONE); 86 generateSequencesDialog.setProcessName(selectedStrings[0]); 87 generateSequencesDialog.open(); 88 } 89 }); 90 btnGenSequences.setText("Gen. Sequences"); 91 92 Button btnProperties = new Button(this, SWT.NONE); 93 btnProperties.addSelectionListener(new SelectionAdapter() { 94 @Override 95 public void widgetSelected(SelectionEvent e) { 96 String[] selectedStrings = modelList.getSelection(); 97 if( selectedStrings.length==0 ) { 98 SWTHelpers.noSelectionError(getShell()); 99 return; 100 } 101 IStochasticProcess process = (IStochasticProcess) GlobalDataContainer.getInstance().getData(selectedStrings[0]); 102 ModelPropertiesDialog modelPropertiesDialog = new ModelPropertiesDialog(getShell(), SWT.NONE); 103 modelPropertiesDialog.setStochasticProcess(process); 104 modelPropertiesDialog.open(); 105 } 106 }); 107 btnProperties.setText("Properties"); 108 109 Button btnCreateDot = new Button(this, SWT.NONE); 110 btnCreateDot.addSelectionListener(new SelectionAdapter() { 111 @Override 112 public void widgetSelected(SelectionEvent e) { 113 String[] selectedStrings = modelList.getSelection(); 114 if( selectedStrings.length==0 ) { 115 SWTHelpers.noSelectionError(getShell()); 116 return; 117 } 118 IStochasticProcess process = (IStochasticProcess) GlobalDataContainer.getInstance().getData(selectedStrings[0]); 119 String command = ""; 120 if( process instanceof IDotCompatible ) { 121 command = "printDot "; 122 } else { 123 command = "printTrieDot "; 124 } 125 command += selectedStrings[0]; 126 CommandExecuter.getInstance().exec(command); 127 } 128 }); 129 btnCreateDot.setText("Create DOT"); 130 } 23 List modelList; 131 24 132 @Override 133 protected void checkSubclass() { 134 // Disable the check that prevents subclassing of SWT components 135 } 136 137 public void updateModelList() { 138 modelList.removeAll(); 139 for( String sequencesName : GlobalDataContainer.getInstance().getAllModelNames() ) { 140 modelList.add(sequencesName); 141 } 142 } 25 /** 26 * Create the composite. 27 * 28 * @param parent 29 * @param style 30 */ 31 public ModelsTabComposite(Composite parent, int style) { 32 super(parent, style); 33 createContents(); 34 } 35 36 private void createContents() { 37 setLayout(new GridLayout(5, false)); 38 39 modelList = new List(this, SWT.BORDER | SWT.V_SCROLL); 40 modelList.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 5, 1)); 41 42 Button btnShow = new Button(this, SWT.NONE); 43 btnShow.addSelectionListener(new SelectionAdapter() { 44 @Override 45 public void widgetSelected(SelectionEvent e) { 46 String[] selectedStrings = modelList.getSelection(); 47 if (selectedStrings.length == 0) { 48 SWTHelpers.noSelectionError(getShell()); 49 return; 50 } 51 IStochasticProcess process = 52 (IStochasticProcess) GlobalDataContainer.getInstance() 53 .getData(selectedStrings[0]); 54 if (process instanceof FirstOrderMarkovModel) { 55 String command = "showMarkovModel " + selectedStrings[0]; 56 CommandExecuter.getInstance().exec(command); 57 } 58 else { 59 MessageBox messageBox = new MessageBox(getShell(), SWT.NONE); 60 messageBox.setText("Feature Not Available"); 61 messageBox 62 .setMessage("The feature is currently only available for first-order Markov models."); 63 messageBox.open(); 64 } 65 } 66 }); 67 btnShow.setText("Visualize"); 68 69 Button btnDelete_1 = new Button(this, SWT.NONE); 70 btnDelete_1.addSelectionListener(new SelectionAdapter() { 71 @Override 72 public void widgetSelected(SelectionEvent e) { 73 if (SWTHelpers.deleteSelectedFromStorage(modelList)) { 74 updateModelList(); 75 } 76 else { 77 SWTHelpers.noSelectionError(getShell()); 78 } 79 } 80 }); 81 btnDelete_1.setText("Delete"); 82 83 Button btnGenSequences = new Button(this, SWT.NONE); 84 btnGenSequences.addSelectionListener(new SelectionAdapter() { 85 @Override 86 public void widgetSelected(SelectionEvent e) { 87 String[] selectedStrings = modelList.getSelection(); 88 if (selectedStrings.length == 0) { 89 SWTHelpers.noSelectionError(getShell()); 90 return; 91 } 92 GenerateSequencesDialog generateSequencesDialog = 93 new GenerateSequencesDialog(getShell(), SWT.NONE); 94 generateSequencesDialog.setProcessName(selectedStrings[0]); 95 generateSequencesDialog.open(); 96 } 97 }); 98 btnGenSequences.setText("Gen. Sequences"); 99 100 Button btnProperties = new Button(this, SWT.NONE); 101 btnProperties.addSelectionListener(new SelectionAdapter() { 102 @Override 103 public void widgetSelected(SelectionEvent e) { 104 String[] selectedStrings = modelList.getSelection(); 105 if (selectedStrings.length == 0) { 106 SWTHelpers.noSelectionError(getShell()); 107 return; 108 } 109 IStochasticProcess process = 110 (IStochasticProcess) GlobalDataContainer.getInstance() 111 .getData(selectedStrings[0]); 112 ModelPropertiesDialog modelPropertiesDialog = 113 new ModelPropertiesDialog(getShell(), SWT.NONE); 114 modelPropertiesDialog.setStochasticProcess(process); 115 modelPropertiesDialog.open(); 116 } 117 }); 118 btnProperties.setText("Properties"); 119 120 Button btnCreateDot = new Button(this, SWT.NONE); 121 btnCreateDot.addSelectionListener(new SelectionAdapter() { 122 @Override 123 public void widgetSelected(SelectionEvent e) { 124 String[] selectedStrings = modelList.getSelection(); 125 if (selectedStrings.length == 0) { 126 SWTHelpers.noSelectionError(getShell()); 127 return; 128 } 129 IStochasticProcess process = 130 (IStochasticProcess) GlobalDataContainer.getInstance() 131 .getData(selectedStrings[0]); 132 String command = ""; 133 if (process instanceof IDotCompatible) { 134 command = "printDot "; 135 } 136 else { 137 command = "printTrieDot "; 138 } 139 command += selectedStrings[0]; 140 CommandExecuter.getInstance().exec(command); 141 } 142 }); 143 btnCreateDot.setText("Create DOT"); 144 } 145 146 @Override 147 protected void checkSubclass() { 148 // Disable the check that prevents subclassing of SWT components 149 } 150 151 public void updateModelList() { 152 modelList.removeAll(); 153 for (String sequencesName : GlobalDataContainer.getInstance().getAllModelNames()) { 154 modelList.add(sequencesName); 155 } 156 } 143 157 144 158 } -
trunk/quest-ui-swt/src/main/java/de/ugoe/cs/quest/ui/swt/SWTConsole.java
r526 r570 1 1 2 package de.ugoe.cs.quest.ui.swt; 2 3 … … 12 13 import de.ugoe.cs.util.console.listener.ITraceListener; 13 14 14 public class SWTConsole implements IOutputListener, IErrorListener, ITraceListener, ICommandListener { 15 public class SWTConsole implements IOutputListener, IErrorListener, ITraceListener, 16 ICommandListener 17 { 15 18 16 StyledText output; 17 18 public SWTConsole(StyledText styledText) { 19 Console.getInstance().registerOutputListener(this); 20 Console.getInstance().registerErrorListener(this); 21 Console.getInstance().registerTraceListener(this); 22 Console.getInstance().registerCommandListener(this); 23 this.output = styledText; 24 } 25 26 @Override 27 public void outputMsg(String newMessage) { 28 output.append(newMessage); 29 } 19 StyledText output; 30 20 31 @Override 32 public void errorMsg(String errMessage) { 33 appendColored(errMessage, SWT.COLOR_RED); 34 } 21 public SWTConsole(StyledText styledText) { 22 Console.getInstance().registerOutputListener(this); 23 Console.getInstance().registerErrorListener(this); 24 Console.getInstance().registerTraceListener(this); 25 Console.getInstance().registerCommandListener(this); 26 this.output = styledText; 27 } 35 28 36 @Override 37 public void traceMsg(String traceMessage) { 38 appendColored(traceMessage, SWT.COLOR_BLUE); 39 } 40 41 @Override 42 public void commandNotification(String command) { 43 output.append("> " + command + StringTools.ENDLINE); 44 } 45 46 private void appendColored(String str, int id) { 47 StyleRange styleRange = new StyleRange(); 48 styleRange.start = output.getText().length(); 49 styleRange.length = str.length(); 50 styleRange.foreground = output.getDisplay().getSystemColor(id); 51 output.append(str); 52 output.setStyleRange(styleRange); 53 } 29 @Override 30 public void outputMsg(String newMessage) { 31 output.append(newMessage); 32 } 33 34 @Override 35 public void errorMsg(String errMessage) { 36 appendColored(errMessage, SWT.COLOR_RED); 37 } 38 39 @Override 40 public void traceMsg(String traceMessage) { 41 appendColored(traceMessage, SWT.COLOR_BLUE); 42 } 43 44 @Override 45 public void commandNotification(String command) { 46 output.append("> " + command + StringTools.ENDLINE); 47 } 48 49 private void appendColored(String str, int id) { 50 StyleRange styleRange = new StyleRange(); 51 styleRange.start = output.getText().length(); 52 styleRange.length = str.length(); 53 styleRange.foreground = output.getDisplay().getSystemColor(id); 54 output.append(str); 55 output.setStyleRange(styleRange); 56 } 54 57 } -
trunk/quest-ui-swt/src/main/java/de/ugoe/cs/quest/ui/swt/SWTHelpers.java
r526 r570 1 1 2 package de.ugoe.cs.quest.ui.swt; 2 3 … … 9 10 10 11 public class SWTHelpers { 11 12 public static boolean deleteSelectedFromStorage(final List list) { 13 String[] selectedStrings = list.getSelection(); 14 if( selectedStrings.length==0 ) { 15 return false; 16 } else { 17 for( String selected : selectedStrings) { 18 String command = "deleteObject " + selected; 19 CommandExecuter.getInstance().exec(command); 20 } 21 return true; 22 } 23 } 24 25 public static void noSelectionError(final Shell shell) { 26 MessageBox messageBox = new MessageBox(shell, SWT.ERROR); 27 messageBox.setMessage("No objects selected!"); 28 messageBox.setText("Error"); 29 messageBox.open(); 30 } 12 13 public static boolean deleteSelectedFromStorage(final List list) { 14 String[] selectedStrings = list.getSelection(); 15 if (selectedStrings.length == 0) { 16 return false; 17 } 18 else { 19 for (String selected : selectedStrings) { 20 String command = "deleteObject " + selected; 21 CommandExecuter.getInstance().exec(command); 22 } 23 return true; 24 } 25 } 26 27 public static void noSelectionError(final Shell shell) { 28 MessageBox messageBox = new MessageBox(shell, SWT.ERROR); 29 messageBox.setMessage("No objects selected!"); 30 messageBox.setText("Error"); 31 messageBox.open(); 32 } 31 33 32 34 } -
trunk/quest-ui-swt/src/main/java/de/ugoe/cs/quest/ui/swt/SequencesDialog.java
r548 r570 1 1 2 package de.ugoe.cs.quest.ui.swt; 2 3 … … 24 25 public class SequencesDialog extends Dialog { 25 26 26 private String sequencesName; 27 28 private List sequenceList; 29 private Collection<java.util.List<Event>> sequences; 30 private SortedSet<String> targets; 31 32 protected Shell shell; 27 private String sequencesName; 33 28 34 /** 35 * Create the dialog. 36 * @param parent 37 * @param style 38 */ 39 public SequencesDialog(Shell parent, int style) { 40 super(parent, style); 41 setText("SWT Dialog"); 42 } 29 private List sequenceList; 30 private Collection<java.util.List<Event>> sequences; 31 private SortedSet<String> targets; 43 32 44 /** 45 * Open the dialog. 46 */ 47 public void open(String sequencesName) { 48 this.sequencesName = sequencesName; 49 sequences = null; 50 createContents(); 51 shell.open(); 52 shell.layout(); 53 Display display = getParent().getDisplay(); 54 while (!shell.isDisposed()) { 55 if (!display.readAndDispatch()) { 56 display.sleep(); 57 } 58 } 59 } 33 protected Shell shell; 60 34 61 /** 62 * Create contents of the dialog. 63 */ 64 private void createContents() { 65 shell = new Shell(getParent(), SWT.SHELL_TRIM | SWT.BORDER | SWT.APPLICATION_MODAL); 66 shell.setSize(248, 299); 67 shell.setText(getText()); 68 shell.setLayout(new GridLayout(2, false)); 69 70 sequenceList = new List(shell, SWT.BORDER | SWT.V_SCROLL); 71 sequenceList.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); 72 updateSequenceList(); 73 74 Button btnShow = new Button(shell, SWT.NONE); 75 btnShow.addSelectionListener(new SelectionAdapter() { 76 @Override 77 public void widgetSelected(SelectionEvent e) { 78 int index = sequenceList.getSelectionIndex(); 79 if( index==-1 ) { 80 MessageBox messageBox = new MessageBox(shell, SWT.ERROR); 81 messageBox.setMessage("No sequence selected!"); 82 messageBox.setText("Error"); 83 messageBox.open(); 84 } else { 85 EditSequenceDialog editSequenceDialog = new EditSequenceDialog(shell, SWT.NONE, targets); 86 int counter = 0; 87 java.util.List<Event> selectedSequence = null; 88 for( java.util.List<Event> sequence : sequences ) { 89 if( counter==index ) { 90 selectedSequence = sequence; 91 break; 92 } 93 counter++; 94 } 95 editSequenceDialog.open(selectedSequence); 96 updateSequenceList(); 97 } 98 } 99 }); 100 btnShow.setText("Show"); 101 102 Button btnClose = new Button(shell, SWT.NONE); 103 btnClose.addSelectionListener(new SelectionAdapter() { 104 @Override 105 public void widgetSelected(SelectionEvent e) { 106 shell.dispose(); 107 } 108 }); 109 btnClose.setText("Close"); 35 /** 36 * Create the dialog. 37 * 38 * @param parent 39 * @param style 40 */ 41 public SequencesDialog(Shell parent, int style) { 42 super(parent, style); 43 setText("SWT Dialog"); 44 } 110 45 111 } 112 113 @SuppressWarnings("unchecked") 114 private void updateSequenceList() { 115 sequenceList.removeAll(); 116 Object dataObject = GlobalDataContainer.getInstance().getData(sequencesName); 117 if( SequenceInstanceOf.isCollectionOfSequences(dataObject)) { 118 sequences = (Collection<java.util.List<Event>>) dataObject; 119 int seqDigits = Integer.toString(sequences.size()).length(); 120 int counter = 1; 121 for( java.util.List<Event> sequence : sequences ) { 122 String seqName = "#"+String.format("%0"+seqDigits+"d", counter)+": "+sequence.size(); 123 sequenceList.add(seqName); 124 counter++; 125 } 126 Object targetObject = GlobalDataContainer.getInstance().getData(sequencesName+"_targets"); 127 targets = null; 128 if( targetObject instanceof SortedSet ) { 129 if( !((SortedSet<?>) targetObject).isEmpty() ) { 130 if( ((SortedSet<?>) targetObject).first() instanceof String ) { 131 targets = (SortedSet<String>) targetObject; 132 } 133 } 134 } 135 if( targets==null ) { 136 targets = new TreeSet<String>(); 137 for( java.util.List<Event> sequence : sequences ) { 138 for( Event event : sequence ) { 139 String target = event.getTarget(); 140 if( target!=null ) { 141 targets.add(target); 142 } 143 } 144 } 145 } 146 } else { 147 MessageBox messageBox = new MessageBox(shell, SWT.ERROR); 148 messageBox.setMessage("Internal error. Sequences object not of expected type!"); 149 messageBox.setText("Error"); 150 messageBox.open(); 151 } 152 } 46 /** 47 * Open the dialog. 48 */ 49 public void open(String sequencesName) { 50 this.sequencesName = sequencesName; 51 sequences = null; 52 createContents(); 53 shell.open(); 54 shell.layout(); 55 Display display = getParent().getDisplay(); 56 while (!shell.isDisposed()) { 57 if (!display.readAndDispatch()) { 58 display.sleep(); 59 } 60 } 61 } 62 63 /** 64 * Create contents of the dialog. 65 */ 66 private void createContents() { 67 shell = new Shell(getParent(), SWT.SHELL_TRIM | SWT.BORDER | SWT.APPLICATION_MODAL); 68 shell.setSize(248, 299); 69 shell.setText(getText()); 70 shell.setLayout(new GridLayout(2, false)); 71 72 sequenceList = new List(shell, SWT.BORDER | SWT.V_SCROLL); 73 sequenceList.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); 74 updateSequenceList(); 75 76 Button btnShow = new Button(shell, SWT.NONE); 77 btnShow.addSelectionListener(new SelectionAdapter() { 78 @Override 79 public void widgetSelected(SelectionEvent e) { 80 int index = sequenceList.getSelectionIndex(); 81 if (index == -1) { 82 MessageBox messageBox = new MessageBox(shell, SWT.ERROR); 83 messageBox.setMessage("No sequence selected!"); 84 messageBox.setText("Error"); 85 messageBox.open(); 86 } 87 else { 88 EditSequenceDialog editSequenceDialog = 89 new EditSequenceDialog(shell, SWT.NONE, targets); 90 int counter = 0; 91 java.util.List<Event> selectedSequence = null; 92 for (java.util.List<Event> sequence : sequences) { 93 if (counter == index) { 94 selectedSequence = sequence; 95 break; 96 } 97 counter++; 98 } 99 editSequenceDialog.open(selectedSequence); 100 updateSequenceList(); 101 } 102 } 103 }); 104 btnShow.setText("Show"); 105 106 Button btnClose = new Button(shell, SWT.NONE); 107 btnClose.addSelectionListener(new SelectionAdapter() { 108 @Override 109 public void widgetSelected(SelectionEvent e) { 110 shell.dispose(); 111 } 112 }); 113 btnClose.setText("Close"); 114 115 } 116 117 @SuppressWarnings("unchecked") 118 private void updateSequenceList() { 119 sequenceList.removeAll(); 120 Object dataObject = GlobalDataContainer.getInstance().getData(sequencesName); 121 if (SequenceInstanceOf.isCollectionOfSequences(dataObject)) { 122 sequences = (Collection<java.util.List<Event>>) dataObject; 123 int seqDigits = Integer.toString(sequences.size()).length(); 124 int counter = 1; 125 for (java.util.List<Event> sequence : sequences) { 126 String seqName = 127 "#" + String.format("%0" + seqDigits + "d", counter) + ": " + sequence.size(); 128 sequenceList.add(seqName); 129 counter++; 130 } 131 Object targetObject = 132 GlobalDataContainer.getInstance().getData(sequencesName + "_targets"); 133 targets = null; 134 if (targetObject instanceof SortedSet) { 135 if (!((SortedSet<?>) targetObject).isEmpty()) { 136 if (((SortedSet<?>) targetObject).first() instanceof String) { 137 targets = (SortedSet<String>) targetObject; 138 } 139 } 140 } 141 if (targets == null) { 142 targets = new TreeSet<String>(); 143 for (java.util.List<Event> sequence : sequences) { 144 for (Event event : sequence) { 145 // TODO check if toString() is sufficient 146 String target = event.getTarget().toString(); 147 if (target != null) { 148 targets.add(target); 149 } 150 } 151 } 152 } 153 } 154 else { 155 MessageBox messageBox = new MessageBox(shell, SWT.ERROR); 156 messageBox.setMessage("Internal error. Sequences object not of expected type!"); 157 messageBox.setText("Error"); 158 messageBox.open(); 159 } 160 } 153 161 154 162 } -
trunk/quest-ui-swt/src/main/java/de/ugoe/cs/quest/ui/swt/SequencesTabComposite.java
r526 r570 1 1 2 package de.ugoe.cs.quest.ui.swt; 2 3 3 4 import org.eclipse.swt.widgets.Composite; 4 5 5 6 6 import org.eclipse.swt.SWT; … … 18 18 19 19 public class SequencesTabComposite extends Composite { 20 21 protected List sequenceList;22 23 /**24 * Create the composite.25 * @param parent26 * @param style27 */28 public SequencesTabComposite(Composite parent, int style) {29 super(parent, style);30 createContents();31 }32 20 33 private void createContents() { 34 setLayout(new GridLayout(5, false)); 35 36 sequenceList = new List(this, SWT.BORDER | SWT.V_SCROLL | SWT.MULTI); 37 sequenceList.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 5, 1)); 38 sequenceList.setItems(new String[] {}); 39 40 Button btnEdit = new Button(this, SWT.NONE); 41 btnEdit.addSelectionListener(new SelectionAdapter() { 42 @Override 43 public void widgetSelected(SelectionEvent e) { 44 String[] selectedSequences = sequenceList.getSelection(); 45 if( selectedSequences.length==0 ) { 46 SWTHelpers.noSelectionError(getShell()); 47 } 48 else if(selectedSequences.length>1) { 49 MessageBox messageBox = new MessageBox(getShell(), SWT.ERROR); 50 messageBox.setMessage("Only one sequence can be edited at a time!"); 51 messageBox.setText("Error"); 52 messageBox.open(); 53 } else { 54 SequencesDialog sequencesDialog = new SequencesDialog(getShell(), SWT.NONE); 55 sequencesDialog.open(selectedSequences[0]); 56 } 57 } 58 }); 59 btnEdit.setText("Edit"); 60 61 Button btnDelete = new Button(this, SWT.NONE); 62 btnDelete.addSelectionListener(new SelectionAdapter() { 63 @Override 64 public void widgetSelected(SelectionEvent e) { 65 if( SWTHelpers.deleteSelectedFromStorage(sequenceList)) { 66 updateSequenceList(); 67 } else { 68 SWTHelpers.noSelectionError(getShell()); 69 } 70 } 71 }); 72 btnDelete.setText("Delete"); 73 74 Button btnReplay = new Button(this, SWT.NONE); 75 btnReplay.addSelectionListener(new SelectionAdapter() { 76 @Override 77 public void widgetSelected(SelectionEvent e) { 78 String[] selectedSequences = sequenceList.getSelection(); 79 if( selectedSequences.length==0 ) { 80 SWTHelpers.noSelectionError(getShell()); 81 } else { 82 StringBuilder commandString = new StringBuilder("generateReplayfile "); 83 FileDialog fileDialog = new FileDialog(getShell()); 84 String filename = fileDialog.open(); 85 commandString.append(filename + " "); 86 for( String selected : selectedSequences ) { 87 commandString.append(selected + " "); 88 } 89 CommandExecuter.getInstance().exec(commandString.toString().trim()); 90 } 91 } 92 }); 93 btnReplay.setText("Replay"); 94 95 Button btnTrainModel = new Button(this, SWT.NONE); 96 btnTrainModel.addSelectionListener(new SelectionAdapter() { 97 @Override 98 public void widgetSelected(SelectionEvent e) { 99 String[] selectedSequences = sequenceList.getSelection(); 100 if( selectedSequences.length==0 ) { 101 SWTHelpers.noSelectionError(getShell()); 102 } else { 103 TrainModelDialog trainDialog = new TrainModelDialog(getShell(), SWT.NONE); 104 trainDialog.setSequenceNames(selectedSequences); 105 trainDialog.open(); 106 } 107 } 108 }); 109 btnTrainModel.setText("Train Model"); 110 111 Button btnParse = new Button(this, SWT.NONE); 112 btnParse.addSelectionListener(new SelectionAdapter() { 113 @Override 114 public void widgetSelected(SelectionEvent e) { 115 // TODO implement parsing of sequences 116 MessageBox messageBox = new MessageBox(getShell(), SWT.ICON_INFORMATION); 117 messageBox.setText("Not implemented!"); 118 messageBox.setMessage("Sorry! This functionality has not been implemented yet!"); 119 messageBox.open(); 120 } 121 }); 122 btnParse.setText("Parse"); 123 } 124 125 public void updateSequenceList() { 126 sequenceList.removeAll(); 127 for( String sequencesName : GlobalDataContainer.getInstance().getAllSequencesNames() ) { 128 sequenceList.add(sequencesName); 129 } 130 } 131 132 @Override 133 protected void checkSubclass() { 134 // Disable the check that prevents subclassing of SWT components 135 } 21 protected List sequenceList; 22 23 /** 24 * Create the composite. 25 * 26 * @param parent 27 * @param style 28 */ 29 public SequencesTabComposite(Composite parent, int style) { 30 super(parent, style); 31 createContents(); 32 } 33 34 private void createContents() { 35 setLayout(new GridLayout(5, false)); 36 37 sequenceList = new List(this, SWT.BORDER | SWT.V_SCROLL | SWT.MULTI); 38 sequenceList.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 5, 1)); 39 sequenceList.setItems(new String[] { }); 40 41 Button btnEdit = new Button(this, SWT.NONE); 42 btnEdit.addSelectionListener(new SelectionAdapter() { 43 @Override 44 public void widgetSelected(SelectionEvent e) { 45 String[] selectedSequences = sequenceList.getSelection(); 46 if (selectedSequences.length == 0) { 47 SWTHelpers.noSelectionError(getShell()); 48 } 49 else if (selectedSequences.length > 1) { 50 MessageBox messageBox = new MessageBox(getShell(), SWT.ERROR); 51 messageBox.setMessage("Only one sequence can be edited at a time!"); 52 messageBox.setText("Error"); 53 messageBox.open(); 54 } 55 else { 56 SequencesDialog sequencesDialog = new SequencesDialog(getShell(), SWT.NONE); 57 sequencesDialog.open(selectedSequences[0]); 58 } 59 } 60 }); 61 btnEdit.setText("Edit"); 62 63 Button btnDelete = new Button(this, SWT.NONE); 64 btnDelete.addSelectionListener(new SelectionAdapter() { 65 @Override 66 public void widgetSelected(SelectionEvent e) { 67 if (SWTHelpers.deleteSelectedFromStorage(sequenceList)) { 68 updateSequenceList(); 69 } 70 else { 71 SWTHelpers.noSelectionError(getShell()); 72 } 73 } 74 }); 75 btnDelete.setText("Delete"); 76 77 Button btnReplay = new Button(this, SWT.NONE); 78 btnReplay.addSelectionListener(new SelectionAdapter() { 79 @Override 80 public void widgetSelected(SelectionEvent e) { 81 String[] selectedSequences = sequenceList.getSelection(); 82 if (selectedSequences.length == 0) { 83 SWTHelpers.noSelectionError(getShell()); 84 } 85 else { 86 StringBuilder commandString = new StringBuilder("generateReplayfile "); 87 FileDialog fileDialog = new FileDialog(getShell()); 88 String filename = fileDialog.open(); 89 commandString.append(filename + " "); 90 for (String selected : selectedSequences) { 91 commandString.append(selected + " "); 92 } 93 CommandExecuter.getInstance().exec(commandString.toString().trim()); 94 } 95 } 96 }); 97 btnReplay.setText("Replay"); 98 99 Button btnTrainModel = new Button(this, SWT.NONE); 100 btnTrainModel.addSelectionListener(new SelectionAdapter() { 101 @Override 102 public void widgetSelected(SelectionEvent e) { 103 String[] selectedSequences = sequenceList.getSelection(); 104 if (selectedSequences.length == 0) { 105 SWTHelpers.noSelectionError(getShell()); 106 } 107 else { 108 TrainModelDialog trainDialog = new TrainModelDialog(getShell(), SWT.NONE); 109 trainDialog.setSequenceNames(selectedSequences); 110 trainDialog.open(); 111 } 112 } 113 }); 114 btnTrainModel.setText("Train Model"); 115 116 Button btnParse = new Button(this, SWT.NONE); 117 btnParse.addSelectionListener(new SelectionAdapter() { 118 @Override 119 public void widgetSelected(SelectionEvent e) { 120 // TODO implement parsing of sequences 121 MessageBox messageBox = new MessageBox(getShell(), SWT.ICON_INFORMATION); 122 messageBox.setText("Not implemented!"); 123 messageBox.setMessage("Sorry! This functionality has not been implemented yet!"); 124 messageBox.open(); 125 } 126 }); 127 btnParse.setText("Parse"); 128 } 129 130 public void updateSequenceList() { 131 sequenceList.removeAll(); 132 for (String sequencesName : GlobalDataContainer.getInstance().getAllSequencesNames()) { 133 sequenceList.add(sequencesName); 134 } 135 } 136 137 @Override 138 protected void checkSubclass() { 139 // Disable the check that prevents subclassing of SWT components 140 } 136 141 137 142 } -
trunk/quest-ui-swt/src/main/java/de/ugoe/cs/quest/ui/swt/TrainModelDialog.java
r526 r570 1 1 2 package de.ugoe.cs.quest.ui.swt; 2 3 … … 22 23 public class TrainModelDialog extends Dialog { 23 24 24 protected Shell shlTrainUsageModel; 25 26 private Button btnFirstorderMarkovModel; 27 private Button btnHighorderMarkovModel; 28 private Button btnPredictionByPartial; 29 private Button btnDeterministicFiniteAutomaton; 30 31 private Spinner minOrderSpinner; 32 private Spinner maxOrderSpinner; 33 private Text modelnameText; 34 35 private String[] sequenceNames; 36 private Text probEscapeText; 37 private Label lblEscapeProbability; 38 39 /** 40 * Create the dialog. 41 * @param parent 42 * @param style 43 */ 44 public TrainModelDialog(Shell parent, int style) { 45 super(parent, style); 46 setText("SWT Dialog"); 47 } 48 49 /** 50 * Open the dialog. 51 */ 52 public void open() { 53 createContents(); 54 shlTrainUsageModel.open(); 55 shlTrainUsageModel.layout(); 56 Display display = getParent().getDisplay(); 57 while (!shlTrainUsageModel.isDisposed()) { 58 if (!display.readAndDispatch()) { 59 display.sleep(); 60 } 61 } 62 } 63 64 /** 65 * Create contents of the dialog. 66 */ 67 private void createContents() { 68 shlTrainUsageModel = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.MIN | SWT.APPLICATION_MODAL); 69 shlTrainUsageModel.setSize(219, 330); 70 shlTrainUsageModel.setText("Train Usage Model"); 71 shlTrainUsageModel.setLayout(new GridLayout(2, false)); 72 73 Group grpGeneralInformation = new Group(shlTrainUsageModel, SWT.NONE); 74 grpGeneralInformation.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 2, 1)); 75 grpGeneralInformation.setText("Name"); 76 grpGeneralInformation.setLayout(new GridLayout(1, false)); 77 78 modelnameText = new Text(grpGeneralInformation, SWT.BORDER); 79 modelnameText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1)); 80 81 Group grpType = new Group(shlTrainUsageModel, SWT.NONE); 82 grpType.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 2, 1)); 83 grpType.setText("Type"); 84 grpType.setLayout(new GridLayout(2, false)); 85 86 btnFirstorderMarkovModel = new Button(grpType, SWT.RADIO); 87 btnFirstorderMarkovModel.addSelectionListener(new SelectionAdapter() { 88 @Override 89 public void widgetSelected(SelectionEvent e) { 90 minOrderSpinner.setEnabled(false); 91 maxOrderSpinner.setEnabled(false); 92 probEscapeText.setEnabled(false); 93 } 94 }); 95 btnFirstorderMarkovModel.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, false, 2, 1)); 96 btnFirstorderMarkovModel.setText("First-Order Markov Model"); 97 btnFirstorderMarkovModel.setSelection(true); 98 99 btnHighorderMarkovModel = new Button(grpType, SWT.RADIO); 100 btnHighorderMarkovModel.addSelectionListener(new SelectionAdapter() { 101 @Override 102 public void widgetSelected(SelectionEvent e) { 103 minOrderSpinner.setEnabled(false); 104 maxOrderSpinner.setEnabled(true); 105 probEscapeText.setEnabled(false); 106 } 107 }); 108 btnHighorderMarkovModel.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, false, 2, 1)); 109 btnHighorderMarkovModel.setText("High-Order Markov Model"); 110 111 btnPredictionByPartial = new Button(grpType, SWT.RADIO); 112 btnPredictionByPartial.addSelectionListener(new SelectionAdapter() { 113 @Override 114 public void widgetSelected(SelectionEvent e) { 115 minOrderSpinner.setEnabled(true); 116 maxOrderSpinner.setEnabled(true); 117 probEscapeText.setEnabled(true); 118 } 119 }); 120 btnPredictionByPartial.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, true, false, 2, 1)); 121 btnPredictionByPartial.setText("Prediction by Partial Match"); 122 123 lblEscapeProbability = new Label(grpType, SWT.NONE); 124 lblEscapeProbability.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, false, 1, 1)); 125 lblEscapeProbability.setText("Escape Probability:"); 126 127 probEscapeText = new Text(grpType, SWT.BORDER); 128 probEscapeText.setText("0.1"); 129 probEscapeText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); 130 probEscapeText.setEnabled(false); 131 132 btnDeterministicFiniteAutomaton = new Button(grpType, SWT.RADIO); 133 btnDeterministicFiniteAutomaton.addSelectionListener(new SelectionAdapter() { 134 @Override 135 public void widgetSelected(SelectionEvent e) { 136 minOrderSpinner.setEnabled(false); 137 maxOrderSpinner.setEnabled(false); 138 probEscapeText.setEnabled(false); 139 } 140 }); 141 btnDeterministicFiniteAutomaton.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, false, 2, 1)); 142 btnDeterministicFiniteAutomaton.setText("Deterministic Finite Automaton"); 143 144 Group grpModelProperties = new Group(shlTrainUsageModel, SWT.NONE); 145 grpModelProperties.setLayout(new GridLayout(4, false)); 146 grpModelProperties.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 2, 1)); 147 grpModelProperties.setText("Order"); 148 149 Label lblMin = new Label(grpModelProperties, SWT.NONE); 150 lblMin.setText("Min."); 151 152 minOrderSpinner = new Spinner(grpModelProperties, SWT.BORDER); 153 minOrderSpinner.setEnabled(false); 154 155 Label lblMax = new Label(grpModelProperties, SWT.NONE); 156 lblMax.setText("Max."); 157 158 maxOrderSpinner = new Spinner(grpModelProperties, SWT.BORDER); 159 maxOrderSpinner.setEnabled(false); 160 maxOrderSpinner.setMinimum(2); 161 162 Button btnTrain = new Button(shlTrainUsageModel, SWT.NONE); 163 btnTrain.addSelectionListener(new SelectionAdapter() { 164 @Override 165 public void widgetSelected(SelectionEvent e) { 166 String command = ""; 167 String modelname = modelnameText.getText(); 168 if( modelname.equals("")) { 169 MessageBox messageBox = new MessageBox(shlTrainUsageModel, SWT.ERROR); 170 messageBox.setText("Error"); 171 messageBox.setMessage("No modelname defined!"); 172 messageBox.open(); 173 return; 174 } 175 if( btnFirstorderMarkovModel.getSelection() ) { 176 command = "trainMarkovModel " + modelname + " " + sequenceNames[0]; 177 178 } 179 else if( btnHighorderMarkovModel.getSelection() ) { 180 int modelOrder = maxOrderSpinner.getSelection(); 181 command = "trainMarkovModel " + modelname + " " + sequenceNames[0] + " " + modelOrder; 182 } 183 else if( btnPredictionByPartial.getSelection() ) { 184 int minOrder = minOrderSpinner.getSelection(); 185 int maxOrder = maxOrderSpinner.getSelection(); 186 if( minOrder>maxOrder ) { 187 MessageBox messageBox = new MessageBox(shlTrainUsageModel, SWT.ERROR); 188 messageBox.setText("Error"); 189 messageBox.setMessage("Min. Order must be smaller than or equal to max. order!"); 190 messageBox.open(); 191 return; 192 } 193 double probEscape = Double.parseDouble(probEscapeText.getText()); 194 if( probEscape<0.0 || probEscape>1.0) { 195 MessageBox messageBox = new MessageBox(shlTrainUsageModel, SWT.ERROR); 196 messageBox.setText("Error"); 197 messageBox.setMessage("Escape probability must be in [0,1]!"); 198 messageBox.open(); 199 return; 200 } 201 command = "trainPPM " + modelname + " " + sequenceNames[0] + " " + probEscape + " " + maxOrder + " " + minOrder; 202 } 203 else if( btnDeterministicFiniteAutomaton.getSelection() ) { 204 command = "trainDFA " + modelname + " " + sequenceNames[0]; 205 } 206 CommandExecuter.getInstance().exec(command); 207 for( int i=1; i<sequenceNames.length; i++ ) { 208 command = "updateModel " + sequenceNames[i]; 209 CommandExecuter.getInstance().exec(command); 210 } 211 shlTrainUsageModel.dispose(); 212 } 213 }); 214 btnTrain.setText("Train!"); 215 216 Button btnAbort = new Button(shlTrainUsageModel, SWT.NONE); 217 btnAbort.addSelectionListener(new SelectionAdapter() { 218 @Override 219 public void widgetSelected(SelectionEvent e) { 220 shlTrainUsageModel.dispose(); 221 } 222 }); 223 btnAbort.setText("Abort"); 224 225 } 226 227 public void setSequenceNames(String[] sequenceNames) { 228 this.sequenceNames = Arrays.copyOf(sequenceNames, sequenceNames.length); 229 } 25 protected Shell shlTrainUsageModel; 26 27 private Button btnFirstorderMarkovModel; 28 private Button btnHighorderMarkovModel; 29 private Button btnPredictionByPartial; 30 private Button btnDeterministicFiniteAutomaton; 31 32 private Spinner minOrderSpinner; 33 private Spinner maxOrderSpinner; 34 private Text modelnameText; 35 36 private String[] sequenceNames; 37 private Text probEscapeText; 38 private Label lblEscapeProbability; 39 40 /** 41 * Create the dialog. 42 * 43 * @param parent 44 * @param style 45 */ 46 public TrainModelDialog(Shell parent, int style) { 47 super(parent, style); 48 setText("SWT Dialog"); 49 } 50 51 /** 52 * Open the dialog. 53 */ 54 public void open() { 55 createContents(); 56 shlTrainUsageModel.open(); 57 shlTrainUsageModel.layout(); 58 Display display = getParent().getDisplay(); 59 while (!shlTrainUsageModel.isDisposed()) { 60 if (!display.readAndDispatch()) { 61 display.sleep(); 62 } 63 } 64 } 65 66 /** 67 * Create contents of the dialog. 68 */ 69 private void createContents() { 70 shlTrainUsageModel = 71 new Shell(getParent(), SWT.DIALOG_TRIM | SWT.MIN | SWT.APPLICATION_MODAL); 72 shlTrainUsageModel.setSize(219, 330); 73 shlTrainUsageModel.setText("Train Usage Model"); 74 shlTrainUsageModel.setLayout(new GridLayout(2, false)); 75 76 Group grpGeneralInformation = new Group(shlTrainUsageModel, SWT.NONE); 77 grpGeneralInformation.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 2, 1)); 78 grpGeneralInformation.setText("Name"); 79 grpGeneralInformation.setLayout(new GridLayout(1, false)); 80 81 modelnameText = new Text(grpGeneralInformation, SWT.BORDER); 82 modelnameText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1)); 83 84 Group grpType = new Group(shlTrainUsageModel, SWT.NONE); 85 grpType.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 2, 1)); 86 grpType.setText("Type"); 87 grpType.setLayout(new GridLayout(2, false)); 88 89 btnFirstorderMarkovModel = new Button(grpType, SWT.RADIO); 90 btnFirstorderMarkovModel.addSelectionListener(new SelectionAdapter() { 91 @Override 92 public void widgetSelected(SelectionEvent e) { 93 minOrderSpinner.setEnabled(false); 94 maxOrderSpinner.setEnabled(false); 95 probEscapeText.setEnabled(false); 96 } 97 }); 98 btnFirstorderMarkovModel 99 .setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, false, 2, 1)); 100 btnFirstorderMarkovModel.setText("First-Order Markov Model"); 101 btnFirstorderMarkovModel.setSelection(true); 102 103 btnHighorderMarkovModel = new Button(grpType, SWT.RADIO); 104 btnHighorderMarkovModel.addSelectionListener(new SelectionAdapter() { 105 @Override 106 public void widgetSelected(SelectionEvent e) { 107 minOrderSpinner.setEnabled(false); 108 maxOrderSpinner.setEnabled(true); 109 probEscapeText.setEnabled(false); 110 } 111 }); 112 btnHighorderMarkovModel.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, false, 2, 1)); 113 btnHighorderMarkovModel.setText("High-Order Markov Model"); 114 115 btnPredictionByPartial = new Button(grpType, SWT.RADIO); 116 btnPredictionByPartial.addSelectionListener(new SelectionAdapter() { 117 @Override 118 public void widgetSelected(SelectionEvent e) { 119 minOrderSpinner.setEnabled(true); 120 maxOrderSpinner.setEnabled(true); 121 probEscapeText.setEnabled(true); 122 } 123 }); 124 btnPredictionByPartial.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, true, false, 2, 1)); 125 btnPredictionByPartial.setText("Prediction by Partial Match"); 126 127 lblEscapeProbability = new Label(grpType, SWT.NONE); 128 lblEscapeProbability.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, false, 1, 1)); 129 lblEscapeProbability.setText("Escape Probability:"); 130 131 probEscapeText = new Text(grpType, SWT.BORDER); 132 probEscapeText.setText("0.1"); 133 probEscapeText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); 134 probEscapeText.setEnabled(false); 135 136 btnDeterministicFiniteAutomaton = new Button(grpType, SWT.RADIO); 137 btnDeterministicFiniteAutomaton.addSelectionListener(new SelectionAdapter() { 138 @Override 139 public void widgetSelected(SelectionEvent e) { 140 minOrderSpinner.setEnabled(false); 141 maxOrderSpinner.setEnabled(false); 142 probEscapeText.setEnabled(false); 143 } 144 }); 145 btnDeterministicFiniteAutomaton.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, 146 false, 2, 1)); 147 btnDeterministicFiniteAutomaton.setText("Deterministic Finite Automaton"); 148 149 Group grpModelProperties = new Group(shlTrainUsageModel, SWT.NONE); 150 grpModelProperties.setLayout(new GridLayout(4, false)); 151 grpModelProperties.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 2, 1)); 152 grpModelProperties.setText("Order"); 153 154 Label lblMin = new Label(grpModelProperties, SWT.NONE); 155 lblMin.setText("Min."); 156 157 minOrderSpinner = new Spinner(grpModelProperties, SWT.BORDER); 158 minOrderSpinner.setEnabled(false); 159 160 Label lblMax = new Label(grpModelProperties, SWT.NONE); 161 lblMax.setText("Max."); 162 163 maxOrderSpinner = new Spinner(grpModelProperties, SWT.BORDER); 164 maxOrderSpinner.setEnabled(false); 165 maxOrderSpinner.setMinimum(2); 166 167 Button btnTrain = new Button(shlTrainUsageModel, SWT.NONE); 168 btnTrain.addSelectionListener(new SelectionAdapter() { 169 @Override 170 public void widgetSelected(SelectionEvent e) { 171 String command = ""; 172 String modelname = modelnameText.getText(); 173 if (modelname.equals("")) { 174 MessageBox messageBox = new MessageBox(shlTrainUsageModel, SWT.ERROR); 175 messageBox.setText("Error"); 176 messageBox.setMessage("No modelname defined!"); 177 messageBox.open(); 178 return; 179 } 180 if (btnFirstorderMarkovModel.getSelection()) { 181 command = "trainMarkovModel " + modelname + " " + sequenceNames[0]; 182 183 } 184 else if (btnHighorderMarkovModel.getSelection()) { 185 int modelOrder = maxOrderSpinner.getSelection(); 186 command = 187 "trainMarkovModel " + modelname + " " + sequenceNames[0] + " " + modelOrder; 188 } 189 else if (btnPredictionByPartial.getSelection()) { 190 int minOrder = minOrderSpinner.getSelection(); 191 int maxOrder = maxOrderSpinner.getSelection(); 192 if (minOrder > maxOrder) { 193 MessageBox messageBox = new MessageBox(shlTrainUsageModel, SWT.ERROR); 194 messageBox.setText("Error"); 195 messageBox 196 .setMessage("Min. Order must be smaller than or equal to max. order!"); 197 messageBox.open(); 198 return; 199 } 200 double probEscape = Double.parseDouble(probEscapeText.getText()); 201 if (probEscape < 0.0 || probEscape > 1.0) { 202 MessageBox messageBox = new MessageBox(shlTrainUsageModel, SWT.ERROR); 203 messageBox.setText("Error"); 204 messageBox.setMessage("Escape probability must be in [0,1]!"); 205 messageBox.open(); 206 return; 207 } 208 command = 209 "trainPPM " + modelname + " " + sequenceNames[0] + " " + probEscape + " " + 210 maxOrder + " " + minOrder; 211 } 212 else if (btnDeterministicFiniteAutomaton.getSelection()) { 213 command = "trainDFA " + modelname + " " + sequenceNames[0]; 214 } 215 CommandExecuter.getInstance().exec(command); 216 for (int i = 1; i < sequenceNames.length; i++) { 217 command = "updateModel " + sequenceNames[i]; 218 CommandExecuter.getInstance().exec(command); 219 } 220 shlTrainUsageModel.dispose(); 221 } 222 }); 223 btnTrain.setText("Train!"); 224 225 Button btnAbort = new Button(shlTrainUsageModel, SWT.NONE); 226 btnAbort.addSelectionListener(new SelectionAdapter() { 227 @Override 228 public void widgetSelected(SelectionEvent e) { 229 shlTrainUsageModel.dispose(); 230 } 231 }); 232 btnAbort.setText("Abort"); 233 234 } 235 236 public void setSequenceNames(String[] sequenceNames) { 237 this.sequenceNames = Arrays.copyOf(sequenceNames, sequenceNames.length); 238 } 230 239 } -
trunk/quest-ui-swt/src/main/java/de/ugoe/cs/quest/ui/swt/commands/CMDshowSequences.java
r526 r570 1 1 2 package de.ugoe.cs.quest.ui.swt.commands; 2 3 … … 23 24 public class CMDshowSequences implements Command { 24 25 25 26 27 28 29 30 31 32 33 26 /* 27 * (non-Javadoc) 28 * 29 * @see de.ugoe.cs.util.console.Command#help() 30 */ 31 @Override 32 public void help() { 33 Console.println("Usage: showSequences <sequencesName>"); 34 } 34 35 35 /* 36 * (non-Javadoc) 37 * 38 * @see de.ugoe.cs.util.console.Command#run(java.util.List) 39 */ 40 @Override 41 public void run(List<Object> parameters) { 42 String sequencesName; 43 try { 44 sequencesName = (String) parameters.get(0); 45 } catch (Exception e) { 46 throw new InvalidParameterException(); 47 } 36 /* 37 * (non-Javadoc) 38 * 39 * @see de.ugoe.cs.util.console.Command#run(java.util.List) 40 */ 41 @Override 42 public void run(List<Object> parameters) { 43 String sequencesName; 44 try { 45 sequencesName = (String) parameters.get(0); 46 } 47 catch (Exception e) { 48 throw new InvalidParameterException(); 49 } 48 50 49 Object dataObject = GlobalDataContainer.getInstance().getData( 50 sequencesName); 51 if (dataObject == null) { 52 CommandHelpers.objectNotFoundMessage(sequencesName); 53 return; 54 } 55 if (!SequenceInstanceOf.isCollectionOfSequences(dataObject)) { 56 CommandHelpers.objectNotType(sequencesName, 57 "Collection<List<Event<?>>>"); 58 return; 59 } 51 Object dataObject = GlobalDataContainer.getInstance().getData(sequencesName); 52 if (dataObject == null) { 53 CommandHelpers.objectNotFoundMessage(sequencesName); 54 return; 55 } 56 if (!SequenceInstanceOf.isCollectionOfSequences(dataObject)) { 57 CommandHelpers.objectNotType(sequencesName, "Collection<List<Event<?>>>"); 58 return; 59 } 60 60 61 62 63 64 65 66 67 68 61 Shell shell = new Shell(SWT.NONE); 62 shell.open(); 63 shell.layout(); 64 shell.setSize(0, 0); 65 SequencesDialog sequencesDialog = new SequencesDialog(shell, SWT.NONE); 66 sequencesDialog.open(sequencesName); 67 shell.dispose(); 68 } 69 69 }
Note: See TracChangeset
for help on using the changeset viewer.