diff --git a/trick_source/java/src/main/java/trick/rtperf/rtPerf.java b/trick_source/java/src/main/java/trick/rtperf/rtPerf.java index 1c362ed8..961e33af 100644 --- a/trick_source/java/src/main/java/trick/rtperf/rtPerf.java +++ b/trick_source/java/src/main/java/trick/rtperf/rtPerf.java @@ -193,8 +193,8 @@ public class rtPerf extends TrickApplication implements PropertyChangeListener final private static String LOCALHOST = "localhost"; - final private Dimension FULL_SIZE = new Dimension(680, 640); - final private Dimension LITE_SIZE = new Dimension(340, 360); + final private Dimension FULL_SIZE = new Dimension(680, 640); + final private Dimension LITE_SIZE = new Dimension(340, 360); private DefaultPieDataset dataset; private JFreeChart chart; @@ -209,49 +209,49 @@ public class rtPerf extends TrickApplication implements PropertyChangeListener public void connect() { System.err.println("Host is " + host + " and port is " + port); - // get host and port for selected sim + // get host and port for selected sim // if (runningSimList != null && runningSimList.getSelectedItem() != null) // { // System.err.println("Line 1\n"); -// String selectedStr = runningSimList.getSelectedItem().toString(); -// // remove the run info if it is shown -// int leftPre = selectedStr.indexOf("("); -// if (leftPre != -1) +// String selectedStr = runningSimList.getSelectedItem().toString(); +// // remove the run info if it is shown +// int leftPre = selectedStr.indexOf("("); +// if (leftPre != -1) // { // System.err.println("Line 2\n"); -// selectedStr = selectedStr.substring(0, leftPre); -// } -// // can be separated either by : or whitespace -// String[] elements = selectedStr.split(":"); -// -// if (elements == null || elements.length < 2) +// selectedStr = selectedStr.substring(0, leftPre); +// } +// // can be separated either by : or whitespace +// String[] elements = selectedStr.split(":"); +// +// if (elements == null || elements.length < 2) // { // System.err.println("Line 3\n"); -// elements = selectedStr.split("\\s+"); -// } -// -// if (elements == null || elements.length < 2) +// elements = selectedStr.split("\\s+"); +// } +// +// if (elements == null || elements.length < 2) // { // System.err.println("Line 4\n"); -// String errMsg = "Can't connect! Please provide valid host name and port number separated by : or whitespace!"; +// String errMsg = "Can't connect! Please provide valid host name and port number separated by : or whitespace!"; // printErrorMessage(errMsg); -// return; -// } +// return; +// } // // System.err.println("Line 5\n"); -// host = elements[0].trim(); -// +// host = elements[0].trim(); +// // try // { -// port = Integer.parseInt(elements[1].trim()); -// } +// port = Integer.parseInt(elements[1].trim()); +// } // catch (NumberFormatException nfe) // { // System.err.println("Line 6\n"); -// String errMsg = elements[1] + " is not a valid port number!"; -// printErrorMessage(errMsg); -// return; -// } +// String errMsg = elements[1] + " is not a valid port number!"; +// printErrorMessage(errMsg); +// return; +// } // } getInitializationPacket(); @@ -259,8 +259,8 @@ public class rtPerf extends TrickApplication implements PropertyChangeListener if (commandSimcom == null) { System.err.println("Line 7\n"); - String errMsg = "Sorry, can't connect. Please make sure the availability of both server and port!"; - printErrorMessage(errMsg); + String errMsg = "Sorry, can't connect. Please make sure the availability of both server and port!"; + printErrorMessage(errMsg); return; } else @@ -286,22 +286,22 @@ public class rtPerf extends TrickApplication implements PropertyChangeListener * Gets the initialization packet from Variable Server if it is up. */ public void getInitializationPacket() - { + { String simRunDir = null; String[] results = null; try { - String errMsg = "Error: RealTimePerformanceApplication:getInitializationPacket()"; + String errMsg = "Error: RealTimePerformanceApplication:getInitializationPacket()"; try { - if (host != null && port != -1) + if (host != null && port != -1) { - commandSimcom = new VariableServerConnection(host, port, varServerTimeout); - } + commandSimcom = new VariableServerConnection(host, port, varServerTimeout); + } else { - commandSimcom = null; - } + commandSimcom = null; + } } catch (UnknownHostException host_exception) { @@ -309,7 +309,7 @@ public class rtPerf extends TrickApplication implements PropertyChangeListener errMsg += "\n Unknown host \""+host+"\""; errMsg += "\n Please use a valid host name (e.g. localhost)"; errOnInitConnect = true; - printErrorMessage(errMsg); + printErrorMessage(errMsg); } catch (SocketTimeoutException ste) { @@ -327,13 +327,13 @@ public class rtPerf extends TrickApplication implements PropertyChangeListener errMsg += "\n IOException ..." + ioe; errMsg += "\n If there is no connection, please make sure SIM is up running properly!"; errOnInitConnect = true; - printErrorMessage(errMsg); + printErrorMessage(errMsg); } if (commandSimcom == null) { - (new RetrieveHostPortTask()).execute(); - return; + (new RetrieveHostPortTask()).execute(); + return; } actionController.setVariableServerConnection(commandSimcom); @@ -354,7 +354,7 @@ public class rtPerf extends TrickApplication implements PropertyChangeListener // long terminateTime = Long.parseLong(results[2]); // if (terminateTime >= Long.MAX_VALUE - 1) // { -// enableProgressBar = false; +// enableProgressBar = false; // } // // // need to minus the sim start time as it could be a number other than 0.0 @@ -386,7 +386,7 @@ public class rtPerf extends TrickApplication implements PropertyChangeListener // // for (int i = 1; i < simRunDirField.length; i++) // { -// simRunDirField[i].setText("Slave " + i); +// simRunDirField[i].setText("Slave " + i); // } // // @@ -480,21 +480,21 @@ public class rtPerf extends TrickApplication implements PropertyChangeListener @Override protected void ready() { - super.ready(); + super.ready(); - //logoImagePanel.start(); + //logoImagePanel.start(); - // The following code was commented out and moved to the end of startup() - // due to framework having issues with certain Java versions. In certain Java - // version such as JDK1.6.0_20, ready() never gets called??? - // 05-24-2011, found out that if there was any SwingTask or Thread started - // before ready() in application framework, JDK1.6.0_20 would fail to realize - // the startup() is done. That's why ready() never gets called even though startup() - // is done. So modified the code to start the logo animation player after startup() - // and moved the following code back to where it should be. + // The following code was commented out and moved to the end of startup() + // due to framework having issues with certain Java versions. In certain Java + // version such as JDK1.6.0_20, ready() never gets called??? + // 05-24-2011, found out that if there was any SwingTask or Thread started + // before ready() in application framework, JDK1.6.0_20 would fail to realize + // the startup() is done. That's why ready() never gets called even though startup() + // is done. So modified the code to start the logo animation player after startup() + // and moved the following code back to where it should be. if (commandSimcom == null) { - //logoImagePanel.pause(); + //logoImagePanel.pause(); Object[] keys = actionMap.allKeys(); // If there is no server connection, disable all actions except connect and quit. for (int i = 0; i < keys.length; i++) @@ -506,13 +506,13 @@ public class rtPerf extends TrickApplication implements PropertyChangeListener } } String errMsg = "No server connection. Please connect!"; - printErrorMessage(errMsg); + printErrorMessage(errMsg); return; } if (isRestartOptionOn) { - printSendHS(); + printSendHS(); } scheduleGetSimState(); @@ -532,7 +532,7 @@ public class rtPerf extends TrickApplication implements PropertyChangeListener super.startup(); // dont't want to the confirmation dialog for sim control panel - removeExitListener(exitListener); + removeExitListener(exitListener); View view = getMainView(); view.setComponent(createMainPanel()); @@ -552,43 +552,43 @@ public class rtPerf extends TrickApplication implements PropertyChangeListener /** - * Prints an error message to the status message pane. In the event there is an error with it, a JOptionPane will pop up. - * @param err - */ - protected void printErrorMessage(String err) + * Prints an error message to the status message pane. In the event there is an error with it, a JOptionPane will pop up. + * @param err + */ + protected void printErrorMessage(String err) { - try + try { - // Get the document attached to the Status Message Pane - Document doc = statusMsgPane.getDocument(); + // Get the document attached to the Status Message Pane + Document doc = statusMsgPane.getDocument(); - // Set the font color to red and the background to black - StyleContext sc = new StyleContext(); - Style redStyle = sc.addStyle("Red", null); + // Set the font color to red and the background to black + StyleContext sc = new StyleContext(); + Style redStyle = sc.addStyle("Red", null); - // Add the error message to the bottom of the message pane - doc.insertString(doc.getLength(), err + "\n", redStyle); + // Add the error message to the bottom of the message pane + doc.insertString(doc.getLength(), err + "\n", redStyle); - // If Lite mode is engaged, or the window is small enough - // to obscure the message pane, create a popup for the error as well. - if (liteButton.isSelected() || getMainFrame().getSize().height <= LITE_SIZE.height + 50) + // If Lite mode is engaged, or the window is small enough + // to obscure the message pane, create a popup for the error as well. + if (liteButton.isSelected() || getMainFrame().getSize().height <= LITE_SIZE.height + 50) { - JOptionPane.showMessageDialog(getMainFrame(), err, "Sim Control Panel Error", JOptionPane.ERROR_MESSAGE); - } - } + JOptionPane.showMessageDialog(getMainFrame(), err, "Sim Control Panel Error", JOptionPane.ERROR_MESSAGE); + } + } catch (BadLocationException ble) { - JOptionPane.showMessageDialog(getMainFrame(), - "Status Message Pane had an issue when printing: " + err, - "Status Message Pane Error", - JOptionPane.ERROR_MESSAGE); - } + JOptionPane.showMessageDialog(getMainFrame(), + "Status Message Pane had an issue when printing: " + err, + "Status Message Pane Error", + JOptionPane.ERROR_MESSAGE); + } catch (NullPointerException npe) { - System.err.println( "Sim Control Error at Initialization: \n" + err); - } + System.err.println( "Sim Control Error at Initialization: \n" + err); + } return; - } + } /** @@ -596,59 +596,59 @@ public class rtPerf extends TrickApplication implements PropertyChangeListener */ private void printSendHS() { - if (simState != null) + if (simState != null) { - File sendHS = new File(simState.getRunPath() + java.io.File.separator + "send_hs"); - if (!sendHS.exists()) + File sendHS = new File(simState.getRunPath() + java.io.File.separator + "send_hs"); + if (!sendHS.exists()) { - return; - } - - String lineText = null; - - Document doc = statusMsgPane.getDocument(); + return; + } + + String lineText = null; + + Document doc = statusMsgPane.getDocument(); StyleContext sc = new StyleContext(); // normal style is white on black Style defaultStyle = sc.addStyle("Default", null); BufferedReader reader = null; - try - { - reader = new BufferedReader(new FileReader(sendHS)); - while ((lineText = reader.readLine()) != null) + try + { + reader = new BufferedReader(new FileReader(sendHS)); + while ((lineText = reader.readLine()) != null) { - doc.insertString(doc.getLength(), lineText+System.getProperty("line.separator"), defaultStyle); - } - } + doc.insertString(doc.getLength(), lineText+System.getProperty("line.separator"), defaultStyle); + } + } catch (FileNotFoundException fnfe) { - // do nothing - } + // do nothing + } catch (IOException ioe) { - // do nothing - } + // do nothing + } catch (BadLocationException ble) { - // do nothing - } - - finally + // do nothing + } + + finally { - try + try { - if (reader != null) + if (reader != null) { - reader.close(); - } - } + reader.close(); + } + } catch (IOException ioe) { - - } - } - } + + } + } + } } /** @@ -704,74 +704,74 @@ public class rtPerf extends TrickApplication implements PropertyChangeListener //======================================== private class RetrieveHostPortTask extends SwingWorker { - - private MulticastSocket multicastSocket = null; - - @Override + + private MulticastSocket multicastSocket = null; + + @Override public Void doInBackground() { - while (getAction("connect").isEnabled()) + while (getAction("connect").isEnabled()) { - retrieveHostPort(); - } + retrieveHostPort(); + } return null; } - - @Override - public void done() + + @Override + public void done() { - if (multicastSocket != null) + if (multicastSocket != null) { multicastSocket.close(); } - } - - /** - * Helper method for retrieving the host and its listening ports. - * - */ - //for Java 7, the type of elements of JComboBox needs to be specified to avoid the warning and it's not supported in Java 6 - @SuppressWarnings("unchecked") - private void retrieveHostPort() + } + + /** + * Helper method for retrieving the host and its listening ports. + * + */ + //for Java 7, the type of elements of JComboBox needs to be specified to avoid the warning and it's not supported in Java 6 + @SuppressWarnings("unchecked") + private void retrieveHostPort() { - try + try { - multicastSocket = new MulticastSocket(9265); - InetAddress group = InetAddress.getByName("239.3.14.15"); - multicastSocket.joinGroup(group); - - byte[] buffer = new byte[1024]; - DatagramPacket packet = new DatagramPacket(buffer, buffer.length); - multicastSocket.receive(packet); + multicastSocket = new MulticastSocket(9265); + InetAddress group = InetAddress.getByName("239.3.14.15"); + multicastSocket.joinGroup(group); + + byte[] buffer = new byte[1024]; + DatagramPacket packet = new DatagramPacket(buffer, buffer.length); + multicastSocket.receive(packet); - // Remove the trailing newline, and split the tab-delimitted message. - String[] info = new String(packet.getData(), packet.getOffset(), packet.getLength()).replace("\n", "").split("\t"); - // Reset the packet length or future messages will be clipped. - packet.setLength(buffer.length); - // version Trick 10 or later - if (info[7] != null) - { - if (runningSimList != null) + // Remove the trailing newline, and split the tab-delimitted message. + String[] info = new String(packet.getData(), packet.getOffset(), packet.getLength()).replace("\n", "").split("\t"); + // Reset the packet length or future messages will be clipped. + packet.setLength(buffer.length); + // version Trick 10 or later + if (info[7] != null) + { + if (runningSimList != null) { - String hostPort = info[0] + " : " + info[1] + " (" + info[5] + " " + info[6] + ")"; - if (!UIUtils.comboBoxContains((DefaultComboBoxModel)runningSimList.getModel(), hostPort)) + String hostPort = info[0] + " : " + info[1] + " (" + info[5] + " " + info[6] + ")"; + if (!UIUtils.comboBoxContains((DefaultComboBoxModel)runningSimList.getModel(), hostPort)) { - // only show localhost's resource - // TODO: may want to have whole network resource - if (InetAddress.getLocalHost().equals(InetAddress.getByName(info[0]))) + // only show localhost's resource + // TODO: may want to have whole network resource + if (InetAddress.getLocalHost().equals(InetAddress.getByName(info[0]))) { - runningSimList.addItem(hostPort); - runningSimList.setSelectedItem(hostPort); - } - } - } - } - } + runningSimList.addItem(hostPort); + runningSimList.setSelectedItem(hostPort); + } + } + } + } + } catch (IOException ioe) { - // do nothing - } - } + // do nothing + } + } } @@ -930,7 +930,7 @@ public class rtPerf extends TrickApplication implements PropertyChangeListener switch (modeIndex) { case SimState.INITIALIZATION_MODE: - //currentSimStatusDesc = "Ready to Run"; + //currentSimStatusDesc = "Ready to Run"; //setSimStateDesc(currentSimStatusDesc); //break; case SimState.DEBUG_STEPPING_MODE: @@ -940,8 +940,8 @@ public class rtPerf extends TrickApplication implements PropertyChangeListener // during this mode and that could have a new elapsed time. case SimState.FREEZE_MODE: case SimState.RUN_MODE: - // need to minus the sim start time as it could be a negative number - setProgress(Math.abs((float)((simState.getExecOutTime()-simStartTime)/simStopTime))); + // need to minus the sim start time as it could be a negative number + setProgress(Math.abs((float)((simState.getExecOutTime()-simStartTime)/simStopTime))); break; } ii++ ; @@ -1015,7 +1015,7 @@ public class rtPerf extends TrickApplication implements PropertyChangeListener } if (isAutoExitOn) { - exit(); + exit(); } } catch (IOException e) @@ -1026,58 +1026,61 @@ public class rtPerf extends TrickApplication implements PropertyChangeListener public static void main(String[] args) { + Application.launch(rtPerf.class, args); // Arrays.toString(args) converts such as localhost 7000 -r to [localhost, 7000, -r], // so need to remove [, ] and all white spaces. String commandLine = (Arrays.toString(args)).replace("[","").replace("]", "").replaceAll("\\s+", ""); - // check to see if -r or -restart is used - Pattern restartOptionPattern = Pattern.compile("(\\-r|\\-restart)(,|$)"); - Matcher matcher = restartOptionPattern.matcher(commandLine); +// // check to see if -r or -restart is used +// Pattern restartOptionPattern = Pattern.compile("(\\-r|\\-restart)(,|$)"); +// Matcher matcher = restartOptionPattern.matcher(commandLine); - // if -r | -restart is used, set the flag and then remove it from the command line - if (matcher.find()) - { - isRestartOptionOn = true; - commandLine = matcher.replaceAll(""); - } +// // if -r | -restart is used, set the flag and then remove it from the command line +// if (matcher.find()) +// { +// isRestartOptionOn = true; +// commandLine = matcher.replaceAll(""); +// } - // check to see if -auto_exit is used - Pattern autoExitOptionPattern = Pattern.compile("(\\-auto\\_exit)(,|$)"); - Matcher autoExitMatcher = autoExitOptionPattern.matcher(commandLine); +// // check to see if -auto_exit is used +// Pattern autoExitOptionPattern = Pattern.compile("(\\-auto\\_exit)(,|$)"); +// Matcher autoExitMatcher = autoExitOptionPattern.matcher(commandLine); - if (autoExitMatcher.find()) - { - isAutoExitOn = true; - commandLine = autoExitMatcher.replaceAll(""); - } +// if (autoExitMatcher.find()) +// { +// isAutoExitOn = true; +// commandLine = autoExitMatcher.replaceAll(""); +// } Scanner commandScanner = new Scanner(commandLine).useDelimiter(","); // now need to figure out host and port, if not specified, available host&port will be listed if (commandScanner.hasNextInt()) { - port = commandScanner.nextInt(); - if (commandScanner.hasNext()) + port = commandScanner.nextInt(); + if (commandScanner.hasNext()) { - host = commandScanner.next(); - } + host = commandScanner.next(); + } } else { - if (commandScanner.hasNext()) + if (commandScanner.hasNext()) { - host = commandScanner.next(); - if (commandScanner.hasNextInt()) + host = commandScanner.next(); + if (commandScanner.hasNextInt()) { - port = commandScanner.nextInt(); - } - } + port = commandScanner.nextInt(); + } + } } if (commandScanner != null) { - commandScanner.close(); + commandScanner.close(); } + + System.out.println("host is "+host+"\nPort is "+port+"\n"); } }