/* * First Created on Jun 20, 2003 * * v1.0 by Jing and Omair (05/11/2005) * -Fixed FileDialog box; made modal with respect to "this class" so that when it is clicked it stays on top. * * -Fixed Save as .bat --> so that now when there's incorrect *.ma filename or if there's no filename * you won't be able to save a *.bat file. * * -Fixed Error in testString() * currently the function is setup so that it seeks numbers in the string [no matter where] and contatenates them, adds 1 to the concatenated number and appends the number to the end of the string. * so if you make a file name called 4567i and you overwrite the file [using automatic] you will get a new file called: 4567i4568 when it should be 4567i1 * Fix: rewrote the function by checking from the back instead of from the front to find the location of a character. Then the numbers [after the char] will be chopped off as a substring and returned. * * -Fixed Error in setDigit() * When trying to save a *.bat file called "2" and saving another file called "2" using the automatic save will result in either window not responding or nothing happens. * Fix: altered the setDigit() [no more index out of bounds exception] so that when filename is a number it returns a string representation of the newly updated number. * * -Fixed Error for when canceling browse * BUG: When there's a file in the text box [text box filled] beside the browse button and if browse is clicked and you hit cancel to "cancel" file selection. * The file name will be erased from the text box [empty text box] and you will have to reselect the file. * Fix: Check for if the file returned from the file selection is equal to "" [nothing] if so then don't update text box field. * * -Fixed Error for when there's a space in file name * Bug: Drawlog cannot be created due to space in folder name * Fix: TempFile.write(string) now has the string enclosed in quotes. * * - Fixed the bug for browsing for files that contains spaces * Bug: Files with spaces will not run. * Fix: In collectParameters all file names are enclosed in quotes. * * Chiril Chidisiuc: * - Fixed loading errors * Bug: when "Load .bat" is used to load the parameters from a BAT file, the first letters of MA, LOG, OUT names * and time values have their first letters removed * Fix: changed indexes in loadBatButton.addSelectionListener * * - Added new features: * ==>the drawlog file name is generated in format [name]DRW_X.drw, where 'X' is a number. * if X==0, then [name]DRW.drw is created * ==> fields of drawlog dialog box are automatically filled when MA file is selected * (names are selected/created with respect to MA file name) * * new methods added: * -traverseVersions(list:String[], maName:String):int * -setVersion(maName:String):void * -setLogName(maName:String):String * -getTypeOfFileVersion(name:String, maName:String):int * -getNextBatVersion(batName:String):int * #getFileVersion(sequence:String):int * #getFileNames(extension:String):String[] */ package CDBuilder.buttons; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.HashMap; import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.swt.SWT; import org.eclipse.swt.events.KeyEvent; import org.eclipse.swt.events.KeyListener; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.FileDialog; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.MessageBox; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.part.FileEditorInput; import CDBuilder.CDBuilderPlugin; import CDBuilder.console.ConsoleDocument; import CDBuilder.console.StreamHandler; /** * @author sddsim * * To change the template for this generated type comment go to * Window>Preferences>Java>Code Generation>Code and Comments */ public class DrawlogGui extends Dialog { private boolean initialVersionSetup = true; private int latestDrawFileVersion; private IResource[] drawFiles; private IContainer container; private IWorkspaceRoot root; private IPath projectPath; private HashMap maVersions; static private Shell parentShell; private Shell parent; private String title; private String modelMessage; private String logMessage; private String timeMessage; private String coupleMessage; private String widthMessage; private String precisionMessage; private String sliceMessage; private String zeroMessage; private String outputMessage; private String outputAutoNameMessage; private static String modelValue; private static String logValue; private static String timeValue; private static String coupleValue; private static String widthValue; private static String precisionValue; private static String sliceValue; private static String outputValue; private Button loadBatButton; private Button saveBatButton; private Button drawlogButton; private Button closeButton; private Button killButton; private Button fileButtonOutput; private Button fileButtonModel; private Button fileButtonLog; private boolean modelExist; private Label colon1, colon2, colon3; private Text modelText; private Text logText; private Text textTime1,textTime2,textTime3,textTime4; private Combo coupleCombo; private Text outputText; private Text widthText; private Text precisionText; private Text sliceText; private Button zeroCheckBox; private Button autoNameDrw; private static boolean zeroValue= true; private static boolean checkedTime = false; private static boolean checkedWidth = true ; private static boolean checkedPrecision = true; private static boolean checkedSlice = false; private static boolean checkedAutoDrw = false; private static String drwAutoName; private static String stdDrwText; private Button checkBoxTime; private Button widthCheckBox; private Button precisionCheckBox; private Button sliceCheckBox; private Process drawlogProcess; private IPath path; private IPath internalPath; private boolean drawlogKilled = false; private RunDrawlog rDrawlog; private Composite composite; private boolean OK2Close = true; private int n;//used in SaveBatchFile class conWrite implements Runnable { String line; public conWrite(String line) { this.line = line; } public void run() { ConsoleDocument.getCDOS().set(line); } } class RunDrawlog extends Thread { IWorkspaceRoot root; String command; Dialog d; public RunDrawlog(String command, Dialog d,IWorkspaceRoot root) { this.command = command; this.root = root; this.d=d; } public void run() { try { ConsoleDocument cdos = ConsoleDocument.getCDOS(); IContainer container = ResourcesPlugin.getWorkspace().getRoot().getContainerForLocation(path); //create a temporary batch file and write the command in it FileWriter tempFile = new FileWriter(path.append("tempDraw.bat").toString()); System.out.println("tempFile.write: " + "\"" + internalPath + "drawlog.exe\" " + command); tempFile.write("\"" + internalPath + "drawlog.exe\" " + command); //the quotes are required to take account spaces in file names. tempFile.close(); // run batch file drawlogProcess = Runtime.getRuntime().exec("cmd /c tempDraw.bat", null, path.toFile()); StreamHandler outputHandler = new StreamHandler(drawlogProcess.getInputStream(), "OUTPUT", true); StreamHandler errorHandler = new StreamHandler(drawlogProcess.getErrorStream(), "ERROR", true); outputHandler.start(); errorHandler.start(); drawlogProcess.waitFor(); container.refreshLocal(1,null); //delete temporary file after finish running Process remove = Runtime.getRuntime().exec("rm tempDraw.bat",null,path.toFile()); outputHandler = new StreamHandler(remove.getInputStream(), "OUTPUT", true); errorHandler = new StreamHandler(remove.getErrorStream(), "ERROR", true); outputHandler.start(); errorHandler.start(); remove.waitFor(); container.refreshLocal(1,null); Display.getDefault().syncExec(new Runnable() { public void run(){ closeButton.setEnabled(true); killButton.setEnabled(false); drawlogButton.setEnabled(true); d.close(); IFile file=root.getFileForLocation(path.append(outputValue)); IEditorPart editor = null; IEditorInput input = new FileEditorInput(file); IWorkbenchPage page =PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); if (page != null) { editor = page.findEditor(input); if (editor != null) { page.bringToTop(editor); } else { try { editor = page.openEditor(input,"org.eclipse.ui.DefaultTextEditor",false); } catch (Exception e) { e.printStackTrace(); } } } try { file.refreshLocal(1,null); } catch (CoreException e) { e.printStackTrace(); } } }); //check if user cancel process if (drawlogKilled) { if (ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path.append("tempDraw.bat")).exists()){ container.refreshLocal(1,null); ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path.append("tempDraw.bat")).delete(true,null); } Display.getDefault().syncExec(new conWrite("***User has killed the simulation***" + "\n")); drawlogKilled = false; } Display.getDefault().syncExec(new conWrite("Drawlog file created" + "\n")); } catch (Throwable T) { T.printStackTrace(); } } } public DrawlogGui(Shell parent,IPath internalPath, IPath path) { super(parent); this.parent = parent; DrawlogGui.parentShell = this.parent; //Chiril Chidisiuc: make it accessible by modifiers this.title ="Drawlog"; modelMessage = "Coupled model file name (.ma)"; coupleMessage = "Cellular model name"; logMessage = "Log file name(.log)"; outputAutoNameMessage = "Generate name for output (\".drw\") file"; outputMessage = "Output file name (.drw)"; timeMessage = "stop time (hh:mm:ss:ms)"+"\n" +"(NOTE: unchecked time option means 'infinity' as stop time)"; widthMessage ="Enter the width"; precisionMessage = "Enter the number of digits after the decimal"; sliceMessage = "Number of slice (s) when used as 3D Models" ; zeroMessage = "Do not print the zero value"; this.path = path; this.internalPath = internalPath; this.root = (IWorkspaceRoot) PlatformUI.getWorkbench() .getActiveWorkbenchWindow().getActivePage().getInput(); this.projectPath = this.root.getLocation(); this.container = this.root.getContainerForLocation(this.projectPath); this.latestDrawFileVersion = this.getFileVersion("0"); //Chiril Chidisiuc: to keep the history of versions this.maVersions = new HashMap(); } protected void buttonPressed(int buttonId) { try{ String[] param = new String[10]; if (buttonId == IDialogConstants.CLOSE_ID) close(); if (buttonId == IDialogConstants.PROCEED_ID) { //get parameter name modelValue= modelText.getText().trim(); if (modelValue.length()==0) throw new Exception("Enter ma file"); String ma = modelValue.substring( modelValue.length()-3 ); if (!ma.equalsIgnoreCase(".ma")){ modelValue=modelValue.concat(".ma"); modelText.setText(modelValue); } if (!modelExist){ throw new Exception("model file does not exist"); } logValue= logText.getText().trim(); if (logValue.length()==0) throw new Exception("Enter log file"); if (!logValue.endsWith(".log")){ logValue=logValue.concat(".log"); logText.setText(logValue); } IWorkspaceRoot root = (IWorkspaceRoot)PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getInput(); IResource[] files; IFile fileHandle=null; //get handle of all file in the folder files = root.getContainerForLocation(path).members(); for(int i=0;i" + outputValue); System.out.println("command: " + command); rDrawlog = new RunDrawlog(command,this,root); rDrawlog.start(); } //open drawlog file when done IContainer container = ResourcesPlugin.getWorkspace().getRoot().getContainerForLocation(path); container.refreshLocal(1,null); //IFile file =WorkbenchPlugin.getPluginWorkspace().getRoot().getFileForLocation(path.append(outputValue)); super.buttonPressed(buttonId); }catch(Exception e){ e.printStackTrace(); MessageBox mb = new MessageBox(new Shell(),SWT.RETRY | SWT.ICON_ERROR | SWT.APPLICATION_MODAL); mb.setText("Simulation Stopped"); mb.setMessage(e.getMessage()); mb.open(); try { mb.wait(); } catch (InterruptedException e1) { e1.printStackTrace(); } closeButton.setEnabled(true); killButton.setEnabled(false); drawlogButton.setEnabled(true); return; } } protected void configureShell(Shell shell) { super.configureShell(shell); //the following line registers the shell of SimuGui to parent //which causes the file-dialog box modal to the SimuGui dialog //this fixes the problem associated with the file-dialog not being modal to SimuGui parent = shell; if (title != null) shell.setText(title); } protected void createButtonsForButtonBar(Composite parent) { // create OK and Cancel buttons by default //makes all the button and text field of the panel drawlogButton = createButton(parent, IDialogConstants.PROCEED_ID, "Drawlog", true); drawlogButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e){ killButton.setEnabled(true); drawlogButton.setEnabled(false); closeButton.setEnabled(false); } }); closeButton = createButton(parent, IDialogConstants.CLOSE_ID, IDialogConstants.CLOSE_LABEL, true); killButton = createButton(parent, IDialogConstants.STOP_ID, "Kill", true); killButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e){ closeButton.setEnabled(true); killButton.setEnabled(false); drawlogButton.setEnabled(true); drawlogProcess.destroy(); try { Process lookProcess = Runtime.getRuntime().exec("ps"); BufferedReader bf= new BufferedReader(new InputStreamReader(lookProcess.getInputStream())); String msg=null; while((msg=bf.readLine())!=null){ if (msg.indexOf(path.toString().substring(2))!=-1){ msg=msg.substring(2).trim(); Process killProcess=Runtime.getRuntime().exec("kill -9 " + msg.substring(0,msg.indexOf(" "))); } } } catch (IOException e1) { e1.printStackTrace(); } drawlogKilled = true; } }); killButton.setEnabled(false); modelText.setFocus(); } private Label createLabel(Composite parent, Composite composite, String message) { Label label = new Label(composite, SWT.NONE); label.setText(message); GridData gridData = new GridData(); gridData.horizontalAlignment = GridData.FILL; gridData.horizontalSpan=10; label.setLayoutData(gridData); label.setFont(parent.getFont()); return label; } private Text createText(Composite composite, int size) { Text text= new Text(composite, SWT.SINGLE | SWT.BORDER); GridData gridData = new GridData(); gridData.horizontalSpan=size; gridData.horizontalAlignment = GridData.FILL; gridData.grabExcessHorizontalSpace=true; gridData.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH); text.setLayoutData(gridData); return text; } private Button createFileButton(Composite composite, String description) { Button fileButton = new Button(composite, SWT.PUSH); fileButton.setText("Browse"); fileButton.setToolTipText(description); GridData gridData = new GridData(); gridData.horizontalAlignment = GridData.BEGINNING; fileButton.setLayoutData(gridData); return fileButton; } private Button createCheckBoxButton(Composite composite, boolean checked) { Button checkBox = new Button(composite, SWT.CHECK); GridData gridData = new GridData(); gridData.horizontalAlignment = GridData.BEGINNING; checkBox.setLayoutData(gridData); checkBox.setSelection(checked); return checkBox; } //inserted by Sameen Rehman ( being tested) private boolean isEmpty(String parameter,Text textBox){ String value = textBox.getText().trim(); if(value.length()== 0){ MessageBox mbox = new MessageBox(new Shell(),SWT.ICON_ERROR | SWT.OK); mbox.setText("Error"); mbox.setMessage(parameter+" is not entered"); mbox.open(); composite.setEnabled(true); closeButton.setEnabled(true); killButton.setEnabled(false); drawlogButton.setEnabled(true); saveBatButton.setEnabled(true); loadBatButton.setEnabled(true); OK2Close = true; closeButton.setEnabled(true); killButton.setEnabled(false); drawlogButton.setEnabled(true); return true; } return false; } public boolean close() { if (OK2Close) { boolean returnValue = super.close(); return returnValue; } return true; } /** * This method takes the fileName and concatenates the digits of n * [found through testString] to the end of the string [if required]. * Edited: by Jing Cao * * @param fileName * @param integer to be appended * @return String tempFileName [new file name with the number at end] */ private String setDigit(String fileName, int n) { //beg setDigit String tempFileName = new String(fileName); String tempString; char c; int i; //Note: the string array only extends from 0 -> (length of string-1) for (i = (fileName.length() - 1); i >= 0; i--) { //This for loop will find the location where the number starts. c = tempFileName.charAt(i); if ((c < '0') || (c > '9')) //if the chracter is not a number then break out of the for loop break; // the value of 'i' will be the index where there is a character [not a number] } tempFileName = tempFileName.trim(); //redundant, it gets rid of spaces infront or after the fileName tempString = new String(Integer.toString(n)); if (i < 0) //the fileName consists of all numbers return tempString; // then return the updated number as the file name! //else tempFileName = tempFileName.substring(0, i + 1); //get the character part of the string //note: the +1 is required because substring(beg,end) is "exclusive" of the end. return tempFileName.concat(tempString); //adds the updated number to the end of the characters and returns the string } //end setDigit /** * This method takes a file name (stripped off ".bat") and * returns the digits (numbers) at the end as a string. * Returns '0' if there's no number at the end of the file name. * Will return the file name if the string is composed of only numbers. * Edited by Jing Cao. * * @param fileName * @return number [of the type string] */ private String testString(String fileName) { //begin testString() //Variable Declarations String tempString = new String(fileName); //redunant but just to make shure that we don't make changes to testString() String number = new String(""); //this string stores the number int i; char c; //Note: the string array only extends from 0 -> (length of string-1) for (i = (fileName.length() - 1); i >= 0; i--) { //This for loop will find the location where the number starts. c = tempString.charAt(i); if ((c < '0') || (c > '9')) //if the chracter is not a number then break out of the for loop break; // the value of 'i' will be the index where there is a character [not a number] } //if statements to set the number string properly if (i == (fileName.length() - 1)) //sets number to 0 if no number found at end of the string. number = "0"; else if (i == -1) //means that the file name is a number! number = new String(fileName); //then set number to be the file name else number = tempString.substring(i + 1); //creates the number string by chopping off the letters number = number.trim(); //removes any spaces at the beginning or the end of the string return number; } //end testString() private boolean checkFileExistence(String file, String errMsg){ IWorkspaceRoot root = (IWorkspaceRoot)PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getInput(); IResource[] files; IFile fileHandle = null; try { files = root.getContainerForLocation(path).members(); for(int i=0;i[file name].drw //pause combine ="cd /D \"" + convertPathToCmd(path.toString())+ "\"" + "\n" + "\"" + internalPath + "drawlog.exe" + "\" " + combine + " "; //Chiril Chidisiuc: this is to achieve the format described in preceeding comments System.out.println("combine:" + combine); return combine; } private String NewFileGui(String filter) { composite.setEnabled(false); closeButton.setEnabled(false); drawlogButton.setEnabled(false); saveBatButton.setEnabled(false); loadBatButton.setEnabled(false); OK2Close = false; FileDialog fileDialog = new FileDialog(parent); String[] extention = new String[1]; extention[0] = filter; fileDialog.setFilterPath(path.toString()); fileDialog.setFilterExtensions(extention); fileDialog.open(); composite.setEnabled(true); closeButton.setEnabled(true); drawlogButton.setEnabled(true); saveBatButton.setEnabled(true); loadBatButton.setEnabled(true); OK2Close = true; return fileDialog.getFileName(); } /* * */ private int getNextBatVersion(String batName){ String [] batList = getFileNames("bat"); int latestVersion = 0; for(int i=0; ilatestVersion)){ latestVersion = number; } }else{ continue; } } } latestVersion++; return latestVersion; } private void SaveBatchFileGui(String filter) { String[] param = new String[10]; String command = collectParameters(); String temp; boolean fileExists = false; if(command == null){ composite.setEnabled(true); drawlogButton.setEnabled(true); saveBatButton.setEnabled(true); loadBatButton.setEnabled(true); closeButton.setEnabled(true); OK2Close = true; return; } composite.setEnabled(false); drawlogButton.setEnabled(false); closeButton.setEnabled(false); FileDialog fileDialog = new FileDialog(parent, SWT.SAVE); String[] extention = new String[1]; extention[0] = filter; fileDialog.setFilterPath(path.toString()); fileDialog.setFilterExtensions(extention); fileDialog.open(); String fileName = fileDialog.getFileName(); try { System.out.println(path.toString() + fileName); if (fileName.endsWith(".bat")) { fileName = fileName.substring(0, fileName.length()-4); } if(fileName == ""){ fileDialog.setFilterPath(""); fileDialog.setFilterExtensions(null); loadBatButton.setEnabled(true); composite.setEnabled(true); drawlogButton.setEnabled(true); saveBatButton.setEnabled(true); closeButton.setEnabled(true); OK2Close = true; return; } File existFile = new File(path.toString() + fileName + ".bat"); boolean cancelled = false; if (existFile.exists()) { fileExists = true; //Chiril Chidisiuc: for user to set his/her own *.bat file name... IPreferenceStore store = CDBuilderPlugin.getDefault().getPreferenceStore(); if (store.getInt("batchChoice") == 3) { OverwriteGui ovG = new OverwriteGui(new Shell()); ovG.open(); if (ovG.buttonPressed() == 0) { //Chiril Chidisiuc: cancel the promt System.out.print("canceled saving bat"); cancelled = true; loadBatButton.setEnabled(true); composite.setEnabled(true); drawlogButton.setEnabled(true); saveBatButton.setEnabled(true); closeButton.setEnabled(true); OK2Close = true; } if (ovG.buttonPressed() == 2) {//Chiril Chidisiuc: automatically generate the version of the selected file int newVersion = getNextBatVersion(fileName); fileName = fileName+"_"+newVersion; MessageBox mbox = new MessageBox( this.parent, SWT.ICON_INFORMATION | SWT.OK); mbox.setText("Saving File"); mbox.setMessage( "The file has been saved as " + fileName + ".bat"); mbox.open(); composite.setEnabled(true); drawlogButton.setEnabled(true); closeButton.setEnabled(true); saveBatButton.setEnabled(true); loadBatButton.setEnabled(true); if (ovG.noAskAgain()) store.setValue("batchChoice", 2); //Chiril Chidisiuc: "Don't ask again" selected... } if (ovG.buttonPressed() == 1) { if(ovG.noAskAgain() ) store.setValue("batchChoice", 1); } } else if(store.getInt("batchChoice") == 2) { // store.setValue("batchChoice", 3); run this once, or modify the CDPreferencePage.java to restore settings int newVersion = getNextBatVersion(fileName); fileName = fileName+"_"+newVersion; } else { } } if (!cancelled) { composite.setEnabled(false); drawlogButton.setEnabled(false); closeButton.setEnabled(false); /* if (fileExists==false){ //Chiril Chidisiuc: a new user-defined name for batch file is created //The following message will explain further use of "Save bat file" procedure (automated renaming system) MessageBox mbox = new MessageBox(this.parent, SWT.ICON_INFORMATION | SWT.OK); mbox.setText("Saving File"); mbox.setMessage("If at a later time you decide to reuse this name by adding the version id, follow these instructions:" +"\n" + "-- Select this file in 'Save As' window and click button." +"\n" + "-- When prompted to select action, click button" +"\n" + "The vesrion of the *.bat file will corresponds to the versions of out/log files stored in it." +"\n" + "Example: \"[file_name].bat\" will be renamed to \"[file_name]_[id].bat\""); mbox.open(); } */ FileWriter batchFile = new FileWriter(path.toString() + fileName + ".bat"); System.out.println(path.toString() + fileName + ".bat"); param[0] = "-m" +modelText.getText(); System.out.println(command); /* if(coupleCombo.getText().length()!=0){ param[1] = "-c"+coupleCombo.getText(); } if(textTime1.isEnabled()){ param[2] = "-t" + textTime1.getText()+":"+textTime2.getText()+":"+textTime3.getText()+":"+textTime4.getText(); } if(logText.getText().length() !=0 ) { param[3] = "-l" + logText.getText(); } if(widthText.isEnabled()){ param[4] = "-w" + widthText.getText(); } if(percisionText.isEnabled()){ param[5] = "-p" + percisionText.getText(); } if(zeroValue) param[6] = "-0"; if(sliceText.isEnabled()){ param[7] = "-f" + sliceText.getText(); } if(outputText.getText().length()!=0 ) { param[8] = "> " + outputText.getText(); } String combine = ""; for(int i=0; i<9;i++){ if (param[i] != null) combine = combine + " " + param[i]; } */ String command2 = (command); //String command2 = ("drawlog "+ command); System.out.println(command2); batchFile.write(command2 + "\n"); batchFile.write("pause"); batchFile.close(); loadBatButton.setEnabled(true); composite.setEnabled(true); drawlogButton.setEnabled(true); saveBatButton.setEnabled(true); closeButton.setEnabled(true); OK2Close = true; } } catch (Exception e) { e.printStackTrace(); } } /* * This method is required to determine the version of the file (applied to * *.out, *.log). This can later be used to determine the name of the next * version (if such must be created) See collectParameters method for * further use of this method. NOTE: this method has limits in max/min value * that it can return...[-2147483648,2147483647] * * @param sequence:String - sequence which must be traversed and converted * to integer representation * @return integer value of a string * @throws NumberFormatException * @author Chiril Chidisiuc * * @version 2006-06-09 */ protected int getFileVersion(String sequence){ try{ return Integer.parseInt(sequence, 10); } catch (NumberFormatException e){ // parseInt("2147483647", 10) returns 2147483647 // parseInt("-2147483648", 10) returns -2147483648 // parseInt("2147483648", 10) throws a NumberFormatException return -1; } } /* * This method is used to obtain the type of the file that is being read. * The types are as follows: * '-1'=>name is not the same as MA file * '0'==>name is the same as MA file, but doesn't contain version * 'fileVersion'==>(fileVersion stands for any positive integer) name is the same as MA file and * contains numerical version X. * * @param name:String - name of the file being checked * @param maName:String - name of the MA file * @return intger representation of the file version * @author Chiril Chidisiuc * @version 2006-06-24 */ private int getTypeOfFileVersion(String name, String maName){ String cleanName = ""; boolean needToClean = false; int startIndex = 0; if (name.contains("DRW")){ startIndex = name.indexOf("DRW"); needToClean = true; } if (needToClean == true) { int endIndex = startIndex + 3; name = name.substring(0, startIndex) + name.substring(endIndex); if (name.equals(maName)) { return 0; // name is the same as MA file } int startSequence = name.lastIndexOf("_"); if (startSequence == -1 && name.equals(maName)) { return 0; // name is the same as MA file, but doesn't contain // version } else if (startSequence == -1 && !name.equals(maName)) { return -1; // name is not the same as MA file, and does not // contain version } String baseName = name.substring(0, startSequence); String sequence = name.substring(startSequence + 1); int fileVersion = this.getFileVersion(sequence); if (fileVersion != -1) { // an integer is returned if (baseName.equals(maName)) { return fileVersion; // name is the same as MA file, and // contains version } else { return -1; // name is not the same as MA file, and contains // version } } } return -1; //name not associated with any MA file } /* * This method traverses the list of files provided and checks for the most recent version found... * * @param list:String[] - a string array containing the list of files * @return none * @author Chiril Chidisiuc * * @version 2006-06-29 */ private int traverseVersions(String[] list, String maName){ int versionToStore = ((Integer)this.maVersions.get(maName)).intValue(); for (int i = 0; i < list.length; i++) { if (list[i] == null){ //no more files to check break; } int checkVersion = this.getTypeOfFileVersion(list[i], maName); if (checkVersion>versionToStore){ versionToStore = checkVersion; } } return versionToStore; } /* * When this method is called, it checks for the latest version of the DRW files. * Example: if MA file life2D.MA was selected and if life2DDRW_1.drw or life2DDRW_3.drw already exist, * the new set will be named life2DDRW_4.drw * * @param none * @return next version of simulation results (for names of *.log and *.out files). * @author Chiril Chidisiuc * @version 2006-06-29 */ private void setVersion(String maName){ this.maVersions.put(maName,new Integer(-1)); String[] drwFileList = this.getFileNames("drw"); // Search for latest version of "*.drw" files int version1 = traverseVersions(drwFileList, maName); version1++; this.maVersions.put(maName, new Integer(version1)); } /* * This method searches through the log files in the project * and selects the closest match. Assuming the format of * log file is "[name]LOG_X.log" the following occurs: * 1) if [name] mathches name of MA file, and X is a number==> this file will be set * unless another file like this with greater value of X is found. * 2) if there are no files as described in (1), the default "[name]LOG.log" * is selected. * 3) If there are no such files as (1) or (2), first file which has [name]== MA file name * is selected * 4) Otherwise, first existing log file is chosen * 5) If none of the above return a log file name, a "null" is returned. * * @param maName:String - name of selected MA file * @return nameToSet:String - closest match to MA file name is returned as a string * @author Chiril Chidisiuc * @version 2006-06-30 */ private String setLogName(String maName){ String [] logList = this.getFileNames("log"); String nameToSet = ""; boolean priority = true; String rootName; String [] validNames = new String[logList.length]; int n = 0; int maxValue = 0; for (int i=0; imaxValue){ nameToSet = validNames[n]; }else if (nameToSet == "") { nameToSet = validNames[n]; } } n++; } } } if(nameToSet==""){ nameToSet = logList[0]; } return nameToSet; } /* * #getFileName(String extension):void - returns the list of all file names * with such extension as a String array. extension must be entered as * a parameter WITHOUT the ".". * Examples of proper extensions: "exe", "ma", "ev", "doc" etc. * * @param extension:String - the file with this extension is checked * @return fileName:String - name of the file is returned (without extension!) * @author Chiril Chidisiuc * * @version 2006-06-07 */ protected String[] getFileNames(String extension) { int count = 0; try { this.drawFiles = this.root.getContainerForLocation(path).members(); } catch (CoreException e) { Display.getDefault().syncExec( new conWrite( "Problem in SimuGui.java:getFileName(extension:String):String[] - " + e)); e.printStackTrace(); }//get files from working directory String [] fileNames = new String[drawFiles.length]; for (int i = 0; i < drawFiles.length; i++) { //search files if (drawFiles[i] instanceof IFile && (drawFiles[i].getName().toUpperCase() .endsWith("." + extension.toUpperCase()))) { //found the file with specified extension String fileNameWithExt = drawFiles[i].getName(); int offset = fileNameWithExt.length() - 1 - extension.length(); fileNames[count] = fileNameWithExt.substring(0, offset); count++; } } return fileNames; } /* * This method converts the given path to command line format by replacing * the path delimiters with Windows path delimiters. * (each '/' is replaced with '\') * * @param path:String - the given current path (e.g. "C:/eclipse/workspace") * @return converted path as a String - path with new delimiters (e.g. "C:\eclipse\workspace") * @author Chiril Chidisiuc * * @version 2006-06-20 */ protected String convertPathToCmd(String path){ char c1 = 47; // character 47 is: '/' char c2 = 92; // character 92 is: '\' return path.replace(c1,c2); //replace(char oldChar, char newChar) } //################################### Kirill 2006-12-11 ######################################################################################################################## //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! private void setDrwName(){ int offset = getMaOffset(); String maName = modelText.getText().substring(0, offset); // Chiril Chidisiuc: name is the same as makefile without ".ma" extension String[] maFiles = getFileNames("ma"); if (!maVersions.containsKey(maName)) { setVersion(maName); } int setThisVersion = ((Integer)maVersions.get(maName)).intValue(); if (checkedAutoDrw){ if (modelText.getText().length()!=0){ //set Drw file name if (setThisVersion!=0){ DrawlogGui.drwAutoName= maName + "DRW_" + setThisVersion +".drw"; outputText.setText(DrawlogGui.drwAutoName); //Chiril Chidisiuc: set appropriate name }else{ DrawlogGui.drwAutoName=maName + "DRW.drw"; outputText.setText(DrawlogGui.drwAutoName); //Chiril Chidisiuc: set appropriate name } } } } private int getMaOffset(){ int offset; if(modelText.getText().length() >= 3 && ( modelText.getText().toUpperCase().endsWith(".MA") ) ){ offset = modelText.getText().length()-3; }else{ offset = modelText.getText().length(); } return offset; } //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! //################################### end Kirill 2006-12-11 #################################################################################################################### protected Control createDialogArea(Composite parent) { composite = (Composite)super.createDialogArea(parent); GridLayout gridLayout = new GridLayout(); gridLayout.numColumns = 10; composite.setLayout(gridLayout); //Row One - Should be text description of ma text box Label modelLabel = createLabel(parent,composite, modelMessage); //Row Two - Text box and file loader for model file modelText = createText(composite, 9); modelText.addModifyListener( new ModifyListener() { public void modifyText(ModifyEvent e) { coupleCombo.removeAll(); int offset = getMaOffset(); if (modelText.getText().length()!=0){ String maName = modelText.getText().substring(0, offset); // Chiril Chidisiuc: name is the same as makefile without ".ma" extension //set Drw file name if (checkedAutoDrw) { //Chiril Chidisiuc setDrwName(); } String logName = setLogName(maName); if (logName == null){ MessageBox mBox = new MessageBox(new Shell(), SWT.ICON_INFORMATION | SWT.OK); mBox.setText("Looking for \"*.log\" file..."); mBox.setMessage("No log files found!"); mBox.open(); } if (logName == null){ logText.setText(""); }else{ logText.setText(logName+".log"); } // logText.setText(modelText.getText().substring(0,offset) + "LOG.log" ); //set Drw file name // outputText.setText(modelText.getText().substring(0,offset) + "_" + latestDrawFileVersion + ".drw" );//Chiril Chidisiuc: set version } modelExist=true; IWorkspaceRoot root = (IWorkspaceRoot)PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getInput(); try { IResource[] files; IFile dropFile = null; files = root.getContainerForLocation(path).members(); for(int i=0;i0) coupleCombo.setText(coupleCombo.getItem(0)); } } catch (Exception e1) { e1.printStackTrace(); } } }); fileButtonModel = createFileButton(composite, "Select ma file"); fileButtonModel.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e){ composite.setEnabled(false); closeButton.setEnabled(false); killButton.setEnabled(false); drawlogButton.setEnabled(false); saveBatButton.setEnabled(false); loadBatButton.setEnabled(false); OK2Close = false; String fileName = NewFileGui("*.ma"); if (!fileName.equals("")) modelText.setText(fileName); } }); //Row Three - Should be the text description of the log label Label logLabel = createLabel(parent, composite, logMessage); //Row Four - Text Box and file loader for log file and output file logText = createText(composite, 9); fileButtonLog = createFileButton(composite, "Select log file"); fileButtonLog.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e){ composite.setEnabled(false); closeButton.setEnabled(false); killButton.setEnabled(false); drawlogButton.setEnabled(false); saveBatButton.setEnabled(false); loadBatButton.setEnabled(false); OK2Close = false; String fileName = NewFileGui("*.log"); if (!fileName.equals("")) logText.setText(fileName); } }); //################################### Kirill 2006-12-10 ######################################################################################################################## //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! autoNameDrw = new Button(composite, SWT.CHECK); GridData gridDataAutoNameDrw = new GridData(); gridDataAutoNameDrw.horizontalAlignment = GridData.BEGINNING; gridDataAutoNameDrw.horizontalSpan = 1; autoNameDrw.setLayoutData(gridDataAutoNameDrw); autoNameDrw.setEnabled(true); autoNameDrw.setSelection(checkedAutoDrw); stdDrwText = ""; autoNameDrw.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { checkedAutoDrw = !checkedAutoDrw; if (checkedAutoDrw){ setDrwName(); } else { outputText.setText(stdDrwText); //TODO stdLogText } } }); Label labelAuto = new Label(composite, SWT.WRAP); labelAuto.setText(outputAutoNameMessage); GridData gridDataAuto = new GridData(); gridDataAuto.horizontalAlignment = GridData.FILL; gridDataAuto.horizontalSpan = 9; labelAuto.setLayoutData(gridDataAuto); labelAuto.setFont(parent.getFont()); //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! //################################### end Kirill 2006-12-10 #################################################################################################################### Label outputLabel = createLabel(parent, composite, outputMessage); outputText = createText(composite, 9); //################################### Kirill 2006-12-10 ######################################################################################################################## //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! outputText.addModifyListener(new ModifyListener() { //Chiril Chidisiuc public void modifyText(ModifyEvent e) { if (!checkedAutoDrw){ stdDrwText = outputText.getText(); } else { if (!DrawlogGui.drwAutoName.equals(outputText.getText())){ stdDrwText = outputText.getText(); checkedAutoDrw = !checkedAutoDrw; autoNameDrw.setSelection(false); } } } }); //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! //################################### end Kirill 2006-12-10 #################################################################################################################### fileButtonOutput = createFileButton(composite, "Select output file"); fileButtonOutput.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e){ composite.setEnabled(false); closeButton.setEnabled(false); killButton.setEnabled(false); drawlogButton.setEnabled(false); saveBatButton.setEnabled(false); loadBatButton.setEnabled(false); OK2Close = false; String fileName = NewFileGui("*.drw"); if (!fileName.equals("")) outputText.setText(fileName); } }); //Row Five - A text description of the couple label Label coupleLabel = createLabel(parent, composite, coupleMessage); //Row Six - Text Drop Box of the couple Loader GridData gridData12 = new GridData(); coupleCombo = new Combo (composite, SWT.READ_ONLY); gridData12.horizontalSpan=10; gridData12.horizontalAlignment = GridData.FILL; gridData12.grabExcessHorizontalSpace=true; gridData12.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH); coupleCombo.setLayoutData(gridData12); //Row Seven Label for the Time Label label5 = new Label(composite, SWT.WRAP); label5.setText(timeMessage); GridData gridData13 = new GridData(); gridData13.horizontalAlignment = GridData.BEGINNING; gridData13.horizontalSpan = 10; label5.setLayoutData(gridData13); label5.setFont(parent.getFont()); //Row ten - The check box and text box for time checkBoxTime = new Button(composite, SWT.CHECK); GridData gridData14 = new GridData(); gridData14.horizontalAlignment = GridData.BEGINNING; checkBoxTime.setLayoutData(gridData14); checkBoxTime.setSelection(checkedTime); checkBoxTime.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e){ if(textTime1.getEnabled() == true) { textTime1.setEnabled(false); textTime2.setEnabled(false); textTime3.setEnabled(false); textTime4.setEnabled(false); checkedTime = false; } else { textTime1.setEnabled(true); textTime2.setEnabled(true); textTime3.setEnabled(true); textTime4.setEnabled(true); checkedTime = true; } } }); textTime1= new Text(composite, SWT.SINGLE | SWT.BORDER); textTime1.setTextLimit(2); GridData gridData15 = new GridData(); gridData15.widthHint = 15; gridData15.heightHint = 13; textTime1.setLayoutData (gridData15); textTime1.setEnabled(checkedTime); textTime1.setToolTipText("Hours"); textTime1.setText("00"); textTime1.addKeyListener(new KeyListener(){ public void keyPressed(KeyEvent e) { try{ if(e.keyCode==SWT.ARROW_UP){ Integer time= new Integer(textTime1.getText()); time=new Integer(time.intValue()+1); if (time.intValue()>99){ textTime1.setText("00"); }else{ textTime1.setText(time.toString()); } } if(e.keyCode==SWT.ARROW_DOWN){ Integer time= new Integer(textTime1.getText()); time=new Integer(time.intValue()-1); if (time.intValue()<0){ textTime1.setText("99"); }else{ textTime1.setText(time.toString()); } } }catch(Exception e1){ e1.printStackTrace(); } } public void keyReleased(KeyEvent e) { } }); colon1 = new Label(composite,SWT.NONE); colon1.setText(":"); textTime2 =new Text(composite, SWT.SINGLE | SWT.BORDER); textTime2.setTextLimit(2); gridData15 = new GridData(); gridData15.widthHint = 15; gridData15.heightHint = 13; textTime2.setLayoutData (gridData15); textTime2.setEnabled(checkedTime); textTime2.setToolTipText("Minutes"); textTime2.setText("00"); textTime2.addKeyListener(new KeyListener(){ public void keyPressed(KeyEvent e) { try{ if(e.keyCode==SWT.ARROW_UP){ Integer time= new Integer(textTime2.getText()); time=new Integer(time.intValue()+1); if (time.intValue()>99){ textTime2.setText("00"); }else{ textTime2.setText(time.toString()); } } if(e.keyCode==SWT.ARROW_DOWN){ Integer time= new Integer(textTime2.getText()); time=new Integer(time.intValue()-1); if (time.intValue()<0){ textTime2.setText("99"); }else{ textTime2.setText(time.toString()); } } }catch(Exception e1){ e1.printStackTrace(); } } public void keyReleased(KeyEvent e) { } }); colon2 = new Label(composite,SWT.NONE); colon2.setText(":"); textTime3= new Text(composite, SWT.SINGLE | SWT.BORDER); textTime3.setTextLimit(2); gridData15 = new GridData(); gridData15.widthHint = 15; gridData15.heightHint = 13; textTime3.setLayoutData (gridData15); textTime3.setEnabled(checkedTime); textTime3.setToolTipText("Seconds"); textTime3.setText("00"); textTime3.addKeyListener(new KeyListener(){ public void keyPressed(KeyEvent e) { try{ if(e.keyCode==SWT.ARROW_UP){ Integer time= new Integer(textTime3.getText()); time=new Integer(time.intValue()+1); if (time.intValue()>99){ textTime3.setText("00"); }else{ textTime3.setText(time.toString()); } } if(e.keyCode==SWT.ARROW_DOWN){ Integer time= new Integer(textTime3.getText()); time=new Integer(time.intValue()-1); if (time.intValue()<0){ textTime3.setText("99"); }else{ textTime3.setText(time.toString()); } } }catch(Exception e1){ e1.printStackTrace(); } } public void keyReleased(KeyEvent e) { } }); colon2 = new Label(composite,SWT.NONE); colon2.setText(":"); textTime4= new Text(composite, SWT.SINGLE | SWT.BORDER); textTime4.setTextLimit(3); textTime4.setText("000"); gridData15 = new GridData(); gridData15.widthHint = 20; gridData15.heightHint = 13; textTime4.setLayoutData (gridData15); textTime4.setToolTipText("Milliseconds"); textTime4.setEnabled(checkedTime); textTime4.addKeyListener(new KeyListener(){ public void keyPressed(KeyEvent e) { try{ if(e.keyCode==SWT.ARROW_UP){ Integer time= new Integer(textTime4.getText()); time=new Integer(time.intValue()+1); if (time.intValue()>999){ textTime4.setText("000"); }else{ textTime4.setText(time.toString()); } } if(e.keyCode==SWT.ARROW_DOWN){ Integer time= new Integer(textTime4.getText()); time=new Integer(time.intValue()-1); if (time.intValue()<0){ textTime4.setText("999"); }else{ textTime4.setText(time.toString()); } } }catch(Exception e1){ e1.printStackTrace(); } } public void keyReleased(KeyEvent e) { } }); //Row Nine Label for width Label widthLabel = createLabel(parent, composite, widthMessage); //Row Ten Checkbox and Text for Width widthCheckBox = createCheckBoxButton(composite, checkedWidth); widthCheckBox.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e){ if(widthText.getEnabled() == true) { widthText.setEnabled(false); checkedWidth = false; } else { widthText.setEnabled(true); checkedWidth = true; } } }); widthText = createText(composite,9); widthText.setEnabled(checkedWidth); //Row Eleven Label for percision Label percisionLabel = createLabel(parent, composite, precisionMessage); //Row Twelve Checkbox and Text for percision precisionCheckBox = createCheckBoxButton(composite, checkedPrecision); precisionCheckBox.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e){ if(precisionText.getEnabled() == true) { precisionText.setEnabled(false); checkedPrecision = false; } else { precisionText.setEnabled(true); checkedPrecision = true; } } }); precisionText = createText(composite,9); precisionText.setEnabled(checkedPrecision); //Row Thirteen Label for slice Label sliceLabel = createLabel(parent, composite, sliceMessage); //Row Fourteen Checkbox and Text for Slice sliceCheckBox = createCheckBoxButton(composite, checkedSlice); sliceCheckBox.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e){ if(sliceText.getEnabled() == true) { sliceText.setEnabled(false); checkedSlice = false; } else { sliceText.setEnabled(true); checkedSlice = true; } } }); sliceText = createText(composite,9); sliceText.setEnabled(checkedSlice); //Row Fifteen Label for zero zeroCheckBox = createCheckBoxButton(composite, zeroValue); zeroCheckBox.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e){ if(zeroValue) { zeroValue = false; } else { zeroValue = true; } } }); //Row Sixteen CheckBox for Zero Label label = new Label(composite, SWT.NONE); label.setText(zeroMessage); GridData gridData = new GridData(); gridData.horizontalAlignment = GridData.FILL; gridData.horizontalSpan=9; label.setLayoutData(gridData); label.setFont(parent.getFont()); saveBatButton = new Button(composite, SWT.PUSH); saveBatButton.setText("Save as .bat"); saveBatButton.setToolTipText("Save Settings to batch file"); GridData gridDataSBB= new GridData(); gridDataSBB.horizontalAlignment = GridData.END; gridDataSBB.horizontalSpan = 9; saveBatButton.setLayoutData(gridDataSBB); saveBatButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e){ loadBatButton.setEnabled(false); composite.setEnabled(false); drawlogButton.setEnabled(false); saveBatButton.setEnabled(false); closeButton.setEnabled(false); OK2Close = false; SaveBatchFileGui("*.bat"); } }); //Row seventeen - Load Batch button loadBatButton = new Button(composite, SWT.PUSH); loadBatButton.setText("Load .bat"); loadBatButton.setToolTipText("Load Batch from file"); GridData gridDataLBB = new GridData(); gridDataLBB.horizontalAlignment = GridData.BEGINNING; loadBatButton.setLayoutData(gridDataLBB); loadBatButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e){ try { loadBatButton.setEnabled(false); composite.setEnabled(false); drawlogButton.setEnabled(false); saveBatButton.setEnabled(false); closeButton.setEnabled(false); OK2Close = false; BufferedReader batchReader = new BufferedReader(new FileReader(path.toString() + NewFileGui("*.bat"))); String command; command = batchReader.readLine(); if (command.trim().startsWith("..\\")) { command=command.substring(3).trim(); } while (!command.startsWith("pause")){ if (command.contains("drawlog")){ break; } command = batchReader.readLine(); } if (!command.contains("drawlog")) { MessageBox mbox = new MessageBox(new Shell(), SWT.ICON_ERROR | SWT.OK); mbox.setText("Error"); mbox.setMessage("This is not a Drawlog file"); mbox.open(); try { composite.setEnabled(true); closeButton.setEnabled(true); killButton.setEnabled(false); drawlogButton.setEnabled(true); saveBatButton.setEnabled(true); loadBatButton.setEnabled(true); OK2Close = true; mbox.wait(); } catch (InterruptedException exc) { exc.printStackTrace(); } } /* if (!command.trim().startsWith("drawlog")) { MessageBox mbox = new MessageBox(new Shell(), SWT.ICON_ERROR | SWT.OK); mbox.setText("Error"); mbox.setMessage("This is not a Drawlog file"); mbox.open(); try { composite.setEnabled(true); closeButton.setEnabled(true); killButton.setEnabled(false); drawlogButton.setEnabled(true); saveBatButton.setEnabled(true); loadBatButton.setEnabled(true); OK2Close = true; mbox.wait(); } catch (InterruptedException exc) { exc.printStackTrace(); } } while(!command.trim().startsWith("drawlog")||command.indexOf("-m")==-1){ command = batchReader.readLine(); if (command.trim().startsWith("..\\")) command=command.substring(3).trim(); } if (command.contains("drawlog")){ int startDrawlog = command.indexOf("drawlog"); int endDrawlog; if (command.charAt(startDrawlog+8)==' '){ endDrawlog = startDrawlog + 8; } else { endDrawlog = startDrawlog + 7; } command = command.substring(0,startDrawlog) + command.substring(endDrawlog); } */ int indexStartMa = command.indexOf("-m"); int indexEndMa = command.indexOf(".ma"); int indexStartCouple = command.indexOf("-c"); int indexEndCouple = command.indexOf(" ",indexStartCouple); int indexWidth = command.indexOf("-w"); int indexStartLog = command.indexOf("-l"); int indexEndLog = command.indexOf(".log"); int hourIndexStart = command.indexOf("-t"); int hourIndexEnd = command.indexOf(":", hourIndexStart); int minuteIndexStart = command.indexOf(":"); int minuteIndexEnd = command.indexOf(":", minuteIndexStart+1); int secondIndexStart = command.indexOf(":",minuteIndexEnd); int secondIndexEnd = command.indexOf(":", secondIndexStart+1); int mSecondIndexStart = command.indexOf(":",secondIndexEnd); int mSecondIndexEnd = command.indexOf(" ", mSecondIndexStart+1); int indexPrecision=command.indexOf("-p"); int indexSlice=command.indexOf("-f"); int indexOutput=command.indexOf(">"); if (indexStartMa != -1) { modelText.setText(command.substring(indexStartMa+3, indexEndMa + 3 ).trim()); //+2 first +4 second originally }else{ modelText.setText(""); } if (indexOutput != -1) { outputText.setText(command.substring(indexOutput+1).trim()); }else{ outputText.setText(""); } if (indexStartLog != -1) { logText.setText(command.substring(indexStartLog+3, indexEndLog + 4)); //originally +2 first } else { logText.setText(""); } if (hourIndexStart != -1) { textTime1.setText(command.substring(hourIndexStart+2, hourIndexEnd)); textTime2.setText(command.substring(minuteIndexStart+1, minuteIndexEnd)); textTime3.setText(command.substring(secondIndexStart+1, secondIndexEnd)); textTime4.setText(command.substring(mSecondIndexStart+1,mSecondIndexEnd)); checkedTime = true; checkBoxTime.setSelection(checkedTime); textTime1.setEnabled(checkedTime); textTime2.setEnabled(checkedTime); textTime3.setEnabled(checkedTime); textTime4.setEnabled(checkedTime); } else { textTime1.setText("00"); textTime2.setText("00"); textTime3.setText("00"); textTime4.setText("000"); checkedTime = false; checkBoxTime.setSelection(checkedTime); textTime1.setEnabled(checkedTime); textTime2.setEnabled(checkedTime); textTime3.setEnabled(checkedTime); textTime4.setEnabled(checkedTime); } if (indexWidth != -1) { widthText.setText(command.substring(indexWidth+3,command.indexOf(" ",indexWidth)-1)); //originally: +2 first 0 second checkedWidth = true; widthCheckBox.setSelection(true); widthText.setEnabled(true); } else { widthText.setText(""); checkedWidth = false; widthCheckBox.setSelection(false); widthText.setEnabled(false); } if (indexPrecision != -1) { precisionText.setText(command.substring(indexPrecision+3,command.indexOf(" ",indexPrecision)-1)); //originally: +2 first 0 second checkedPrecision = true; precisionCheckBox.setSelection(true); precisionText.setEnabled(true); } else { precisionText.setText(""); checkedPrecision = false; precisionCheckBox.setSelection(false); precisionText.setEnabled(false); } if (indexSlice != -1) { sliceText.setText(command.substring(indexSlice+2,command.indexOf(" ",indexSlice))); checkedSlice = true; sliceCheckBox.setSelection(true); sliceText.setEnabled(true); } else { sliceText.setText(""); checkedSlice = false; sliceCheckBox.setSelection(false); sliceText.setEnabled(false); } if (command.indexOf("-0") != -1) { zeroValue=true; zeroCheckBox.setSelection(true); } else { zeroValue=false; zeroCheckBox.setSelection(false); } } catch (Exception error) { error.printStackTrace(); } composite.setEnabled(true); loadBatButton.setEnabled(true); drawlogButton.setEnabled(true); closeButton.setEnabled(true); saveBatButton.setEnabled(true); OK2Close = true; } }); return composite; } }