//Title: Network Planning Terminal (NPT) File Reader //Version: //Copyright: Copyright (c) 1999 //Author: David W. Laflam //Company: NPS //Description: NPT File Reader Application package demo.helicopter; import java.awt.*; import java.awt.event.*; import java.text.*; // for class DecimalFormat import java.util.*; // for class Vector import mil.navy.nps.dis.*; import mil.navy.nps.testing.*; import mil.navy.nps.util.*; import mil.navy.nps.disEnumerations.*; import javax.swing.*; import javax.swing.UIManager; import javax.swing.filechooser.*; import java.io.* ; import java.io.FileReader; import java.io.FileWriter; import java.util.StringTokenizer; public class NetworkPlanningTerminalFileReaderFrame extends JFrame { JMenuBar menuBar1 = new JMenuBar(); JMenu menuFile = new JMenu(); JMenuItem menuFileExit = new JMenuItem(); JMenu menuHelp = new JMenu(); JMenuItem menuHelpAbout = new JMenuItem(); JToolBar toolBar = new JToolBar(); JButton jButton_OpenFile = new JButton(); JButton jButton_WriteFile = new JButton(); JButton jButton_Help = new JButton(); JButton jButton_Exit = new JButton(); ImageIcon image1; ImageIcon image2; ImageIcon image3; ImageIcon image4; JLabel statusBar = new JLabel(); JPanel jPanel1 = new JPanel(); JLabel jLabel1 = new JLabel(); // JButton ReadFile = new JButton(); //int lineCounter = 0; // an array for the antenna (number of line in the npt file ) //Antenna [] TestAnt ; private File file; // the file that I am reading ///////////// From the StartPanel.java ////////////////////// public AntennaStartPanel asp; // the antenna start panel private static int exitHash = 0; private static int redHash = 0; private static int blueHash = 0; private static int antennaHash = 0; private static int timeToLive = 15; // default ttl convention (local campus) private static int sleepTime = 0; private static boolean rtpMatch = false; private static int lastEventCode; // prevent multiple copies of a live entity by listening first, // > 5 seconds recommended // minimum listen time 2 sec needed or else panels will allow repeats... public static final int multicastListenDelay = 8; public static final int reportedMulticastListenDelay = multicastListenDelay + 2; ///////////// From the StartPanel.java ////////////////////// //layout for the panel and frame GridBagLayout gridBagLayout1 = new GridBagLayout(); GridBagLayout gridBagLayout2 = new GridBagLayout(); //Construct the frame public NetworkPlanningTerminalFileReaderFrame() { enableEvents(AWTEvent.WINDOW_EVENT_MASK); try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } //Component initialization private void jbInit() throws Exception { try { System.out.println ("initially trying /vrtp/demo/helicopter"); image1 = new ImageIcon("/vrtp/demo/helicopter/readin.gif"); image2 = new ImageIcon("/vrtp/demo/helicopter/process.gif"); image3 = new ImageIcon("/vrtp/demo/helicopter/about.gif"); image4 = new ImageIcon("/vrtp/demo/helicopter/exit.gif"); } catch (Exception ex1) { // this worked on dave's system but not don's ??? System.out.println ("now trying demo.helicopter.NetworkPlanningTerminalFileReaderFrame.class.getResource(\"fileName.gif\")"); try { image1 = new ImageIcon(demo.helicopter.NetworkPlanningTerminalFileReaderFrame.class.getResource("readin.gif")); image2 = new ImageIcon(demo.helicopter.NetworkPlanningTerminalFileReaderFrame.class.getResource("process.gif")); image3 = new ImageIcon(demo.helicopter.NetworkPlanningTerminalFileReaderFrame.class.getResource("about.gif")); image4 = new ImageIcon(demo.helicopter.NetworkPlanningTerminalFileReaderFrame.class.getResource("exit.gif")); } catch (Exception ex2) { System.out.println ("error loading button files in NetworkPlanningTerminalFileReaderFrame"); } } this.getContentPane().setLayout(gridBagLayout1); this.setResizable(false); this.setSize(new Dimension(500, 115)); this.setTitle("Network Planning Terminal File Reader"); statusBar.setText(" "); menuFile.setText("File"); menuFileExit.setText("Exit"); menuFileExit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { fileExit_actionPerformed(e); } }); menuHelp.setText("Help"); menuHelpAbout.setText("About"); // for the about box use of inner class menuHelpAbout.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { helpAbout_actionPerformed(e); } }); //=============================================================== jButton_OpenFile.setIcon(image1); jButton_OpenFile.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jButton_OpenFile_actionPerformed(e); } }); jButton_OpenFile.addMouseListener(new java.awt.event.MouseAdapter() { public void mousePressed(MouseEvent e) { jButton_OpenFile_mousePressed(e); } }); jButton_OpenFile.setToolTipText("Open File"); //====================================================== jButton_WriteFile.setIcon(image2); jButton_WriteFile.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { // jButton_WriteFile_actionPerformed(e); ReadFile_actionPerformed(e); } }); jButton_WriteFile.addMouseListener(new java.awt.event.MouseAdapter() { public void mousePressed(MouseEvent e) { // jButton_WriteFile_mousePressed(e); } }); jButton_WriteFile.setToolTipText("Process & Close File"); //============================================================== jButton_Help.setIcon(image3); jButton_Help.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jButton_Help_actionPerformed(e); } }); jButton_Help.setToolTipText("About"); //============================================================================ jButton_Exit.setIcon(image4); jButton_Exit.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }); jButton_Exit.addMouseListener(new java.awt.event.MouseAdapter() { public void mousePressed(MouseEvent e) { System.exit(0); } }); jButton_Exit.setToolTipText("Exit File"); //============================================================================ // // jPanel1.setBackground(Color.white); // jPanel1.setLayout(gridBagLayout2); // jLabel1.setFont(new java.awt.Font("Dialog", 1, 14)); // jLabel1.setForeground(Color.orange); //jLabel1.setBorder(BorderFactory.createLineBorder(Color.black)); //jLabel1.setText(" Push Button After Opening File to Read"); // ReadFile.setText("Process Antenna File "); // ReadFile.addMouseListener(new java.awt.event.MouseAdapter() { // public void mousePressed(MouseEvent e) { // ReadFile_mousePressed(e); // } // }); // ReadFile.addActionListener(new java.awt.event.ActionListener(){ // public void actionPerformed(ActionEvent e) { // ReadFile_actionPerformed(e); // } // }); toolBar.add(jButton_OpenFile); toolBar.add(jButton_WriteFile); toolBar.add(jButton_Help); toolBar.add(jButton_Exit); menuFile.add(menuFileExit); menuHelp.add(menuHelpAbout); menuBar1.add(menuFile); menuBar1.add(menuHelp); this.setJMenuBar(menuBar1); this.getContentPane().add(toolBar, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 235, 0)); this.getContentPane().add(statusBar, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 389, 0)); /* this.getContentPane().add(jPanel1, new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0 ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 52, 74)); jPanel1.add(jLabel1, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(39, 37, 74, 52), 17, 6)); jPanel1.add(ReadFile, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(55, 73, 0, 108), 56, 0)); */ } //File | Exit action performed public void fileExit_actionPerformed(ActionEvent e) { System.exit(0); } //============================================================================ //Help | About action performed public void helpAbout_actionPerformed(ActionEvent e) { NetworkPlanningTerminalFileReaderFrameAboutBox dlg = new NetworkPlanningTerminalFileReaderFrameAboutBox(this); Dimension dlgSize = dlg.getPreferredSize(); Dimension frmSize = getSize(); Point loc = getLocation(); dlg.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x, (frmSize.height - dlgSize.height) / 2 + loc.y); dlg.setModal(true); dlg.show(); } //============================================================================ //Overridden so we can exit on System Close protected void processWindowEvent(WindowEvent e) { super.processWindowEvent(e); if(e.getID() == WindowEvent.WINDOW_CLOSING) { fileExit_actionPerformed(null); } } //============================================================================ public Vector ReadFile_actionPerformed(ActionEvent e) { Vector antennaVector = new Vector (); int lineCounter = 0; // jLabel1.setForeground(new Color(0, 255, 0)); //System.out.println(" TEST ReadFile_actionPerformed "); // need to add code to readin file try { FileReader fr = new FileReader(file); BufferedReader br = new BufferedReader(fr); String s; StringTokenizer thisLineTokens ; Antenna ant = null, ant1=null; while (( s = br.readLine()) != null) { //System.out.println(s); // for debug lineCounter++; System.out.println("The line number is: " + lineCounter); if (lineCounter < 10) { // do nothing } else { thisLineTokens = new StringTokenizer(s); while ( thisLineTokens.hasMoreTokens()) { String AntSystem1 = new String(thisLineTokens.nextToken()); System.out.println( AntSystem1); String AntSystem2 = new String(thisLineTokens.nextToken()); System.out.println( AntSystem2); String AntSystem3 = new String(thisLineTokens.nextToken()); System.out.println( AntSystem3); String AntSystem4 = new String(thisLineTokens.nextToken()); System.out.println( AntSystem4); String AntSystem5 = new String(thisLineTokens.nextToken()); System.out.println( AntSystem5); String AntSystem6 = new String(thisLineTokens.nextToken()); System.out.println( AntSystem6); String AntSystem7 = new String(thisLineTokens.nextToken()); System.out.println( AntSystem7); if(ant != null) { System.out.println("old ant=" + ant); ant1 =ant; } else { System.out.println("ant is null"); } ant = new Antenna(AntSystem1, AntSystem2, AntSystem3, AntSystem4, AntSystem5, AntSystem6, AntSystem7); System.out.println("new antenna = " + ant + " old ant is " + ant1); antennaVector.add(ant); }//end while //System.out.println(); System.out.println(s); }// end else }//end while // colse the file fr.close(); }// end try catch (Exception x) { System.err.println(" -- Bad Input, not a % --" + x ); }//end catch for (int ix = 0; ix < antennaVector.size(); ix++) { System.out.println( ((Antenna)antennaVector.elementAt(ix)).toString()); } // from start Panel asp = new AntennaStartPanel (800, 650, antennaVector); // for the Antenna // asp.addAntennas(antennaVector); // add the antenna objects this.setVisible(false); asp.show(); asp.setTimeToLive (timeToLive); //asp.setRtpHeaderEnabled (rtpMatch); dispose(); return antennaVector; } // end method ReadFile_actionPerformed() //============================================================================ void jButton_WriteFile_actionPerformed(ActionEvent e) { System.out.println(" TEST jButton_WriteFile_actionPerformed "); try { // need to put source .wrl VRML File Here String source = " This will write out the file in the future \n" + " also will develop a MRGS to GeoVRML \n" + "conversion program. " ; char buffer[] = new char[source.length()]; source.getChars(0, source.length(), buffer, 0); FileWriter f1 = new FileWriter("file2.doc"); f1.write(buffer); f1.close(); FileWriter f2 = new FileWriter("file3.txt"); f2.write(buffer); f2.close(); }// end try catch (Exception x) { System.err.println(" -- Bad Input, not a % --"); }//end catch System.out.println(" File Written Out to file2.doc and file3.txt "); }// end jButton_WriteFile_actionPerformed() //============================================================================ void jButton_OpenFile_actionPerformed(ActionEvent e) { System.out.println(" TEST jButton_OpenFile_actionPerformed "); try { UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); } // end try catch (Exception exc) { System.err.println("Error loading Java Look&Feel: " + exc); } // end catch JFileChooser fileChooser = new JFileChooser(); fileChooser.setCurrentDirectory (new File ("/vrtp/demo/helicopter/NetworkPlanningTerminalData")); fileChooser.setFileSelectionMode( JFileChooser.FILES_ONLY ); int result = fileChooser.showOpenDialog( this ); // user clicked Cancel button on dialog if ( result == JFileChooser.CANCEL_OPTION ) file = null; else file = fileChooser.getSelectedFile(); } // end jButton_OpenFile_actionPerformed() //============================================================================ void jButton_Help_actionPerformed(ActionEvent e) { //System.out.println(" TEST jButton_Help_actionPerformed "); NetworkPlanningTerminalFileReaderFrameAboutBox dlg = new NetworkPlanningTerminalFileReaderFrameAboutBox(this); Dimension dlgSize = dlg.getPreferredSize(); Dimension frmSize = getSize(); Point loc = getLocation(); dlg.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x, (frmSize.height - dlgSize.height) / 2 + loc.y); dlg.setModal(true); dlg.show(); } // end jButton_Help_actionPerformed() //============================================================================ void jButton_OpenFile_mousePressed(MouseEvent e) { // need to add code here to open the file menu }// end jButton_openFile_mousePressed () //============================================================================ void jButton_WriteFile_mousePressed(MouseEvent e) { // need to add code here to write the file out } // end jButton_saveFile_mousePressed() //============================================================================ void ReadFile_mousePressed(MouseEvent e) throws Exception { } // end ReadFile_mousePressed () } // end class NetworkPlanningTerminalFileReaderFrame()