Thread: [Javanetsim-cvs] javaNetSim/guiUI MainScreen.java,1.51,1.52
Status: Beta
Brought to you by:
darkkey
From: Alexander B. <da...@us...> - 2007-09-13 15:07:24
|
Update of /cvsroot/javanetsim/javaNetSim/guiUI In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv681/guiUI Modified Files: MainScreen.java Log Message: New color table used instead plain textarea for packets log. Some color/usability tuning and also testing of it needed... Index: MainScreen.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/guiUI/MainScreen.java,v retrieving revision 1.51 retrieving revision 1.52 diff -C2 -d -r1.51 -r1.52 *** MainScreen.java 22 Nov 2006 21:18:38 -0000 1.51 --- MainScreen.java 13 Sep 2007 15:07:20 -0000 1.52 *************** *** 128,131 **** --- 128,137 ---- import guiUI.RunCMD; import javax.swing.JViewport; + import javax.swing.table.*; + import java.awt.*; + import java.awt.event.*; + import javax.swing.*; + import java.util.*; + import java.text.SimpleDateFormat; *************** *** 218,228 **** //This is the consol window used to display feedback from the sim ! private JTextArea pnlConsole = new JTextArea(); private JTextArea pnlNodeInformation = new JTextArea(); ! ! ! ! private JScrollPane scrConsole = new JScrollPane(pnlConsole); private JScrollPane scrNodeInformation = new JScrollPane(pnlNodeInformation); --- 224,256 ---- //This is the consol window used to display feedback from the sim ! //private JTextArea pnlConsole = new JTextArea(); private JTextArea pnlNodeInformation = new JTextArea(); ! ! ColorRenderer colorRenderer; ! ! DefaultTableModel mConsole = new DefaultTableModel(); ! ! ! ! String columnNames[] = { "English", "Japanese", "Boolean", "Date", "ImageIcon" }; ! ! JTable pnlConsole = new JTable(mConsole) ! { ! public Class getColumnClass(int column) ! { ! return getValueAt(0, column).getClass(); ! } ! ! public Component prepareRenderer( ! TableCellRenderer renderer, int row, int column) ! { ! Component c = super.prepareRenderer(renderer, row, column); ! colorRenderer.setBackground(c, row, column); ! return c; ! } ! }; ! ! private JScrollPane scrConsole = new JScrollPane(pnlConsole); private JScrollPane scrNodeInformation = new JScrollPane(pnlNodeInformation); *************** *** 252,256 **** SimulationToolBar SimToolBar; ! /** --- 280,399 ---- SimulationToolBar SimToolBar; ! ! class ColorRenderer implements ActionListener ! { ! private JTable table; ! private AbstractTableModel model; ! private Map colors; ! private Point location; ! ! public ColorRenderer(JTable table) ! { ! this.table = table; ! model = (AbstractTableModel)table.getModel(); ! colors = new HashMap(); ! location = new Point(); ! } ! ! public void setBackground(Component c, int row, int column) ! { ! if ( table.isCellSelected(row, column) ) return; ! ! if (c instanceof DefaultTableCellRenderer) ! { ! c.setBackground( table.getBackground() ); ! } ! ! column = table.convertColumnIndexToModel(column); ! ! // cell color ! ! Object key = getKey(row, column); ! Object o = colors.get( key ); ! ! if (o != null) ! { ! c.setBackground( (Color)o ); ! return; ! } ! ! // row color ! ! key = getKey(row, -1); ! o = colors.get( key ); ! ! if (o != null) ! { ! c.setBackground( (Color)o ); ! return; ! } ! ! // column color ! ! key = getKey(-1, column); ! o = colors.get( key ); ! ! if (o != null) ! { ! c.setBackground( (Color)o ); ! return; ! } ! ! } ! ! public void setCellColor(int row, int column, Color color) ! { ! Point key = new Point(row, column); ! colors.put(key, color); ! } ! ! public void setColumnColor(int column, Color color) ! { ! setCellColor(-1, column, color); ! } ! ! public void setRowColor(int row, Color color) ! { ! setCellColor(row, -1, color); ! } ! ! private Object getKey(int row, int column) ! { ! location.x = row; ! location.y = column; ! return location; ! } ! ! public void actionPerformed(ActionEvent e) ! { ! ! Iterator it = colors.keySet().iterator(); ! ! while ( it.hasNext() ) ! { ! Point key = (Point)it.next(); ! int row = key.x; ! int column = key.y; ! ! if (column == -1) ! { ! model.fireTableRowsUpdated(row, row); ! } ! else if (row == -1) ! { ! int rows = table.getRowCount(); ! ! for (int i = 0; i < rows; i++) ! { ! model.fireTableCellUpdated(i, column); ! } ! } ! else ! { ! model.fireTableCellUpdated(row, column); ! } ! } ! } ! } /** *************** *** 375,379 **** tabConsole.add("Node Information", scrNodeInformation); ! pnlConsole.setEditable(false); pnlNodeInformation.setEditable(false); --- 518,523 ---- tabConsole.add("Node Information", scrNodeInformation); ! //EDITABLE << FIXME!!! ! //pnlConsole.setEditable(false); pnlNodeInformation.setEditable(false); *************** *** 406,411 **** //this.setExtendedState(MAXIMIZED_BOTH); ! ! } --- 550,566 ---- //this.setExtendedState(MAXIMIZED_BOTH); ! ! colorRenderer = new ColorRenderer( pnlConsole ); ! ! mConsole.setColumnIdentifiers(new Object[]{"Time","Node","Packet","Layer","Info"}); ! pnlConsole.getColumnModel().getColumn(0).setMaxWidth(100); ! pnlConsole.getColumnModel().getColumn(0).setMinWidth(100); ! pnlConsole.getColumnModel().getColumn(1).setMaxWidth(100); ! pnlConsole.getColumnModel().getColumn(1).setMinWidth(100); ! pnlConsole.getColumnModel().getColumn(2).setMaxWidth(200); ! pnlConsole.getColumnModel().getColumn(2).setMinWidth(200); ! pnlConsole.getColumnModel().getColumn(3).setMaxWidth(100); ! pnlConsole.getColumnModel().getColumn(3).setMinWidth(100); ! pnlConsole.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); } *************** *** 547,551 **** this.setAllHighlightsOff(); ! pnlConsole.append("Added PC "+result+" to simulation\n"); } catch (InvalidNodeNameException e) { --- 702,708 ---- this.setAllHighlightsOff(); ! //pnlConsole.append("Added PC "+result+" to simulation\n"); ! ! //mConsole.insertRow(mConsole.getRowCount(), new Object[]{"1","2,"3","4"}); } catch (InvalidNodeNameException e) { *************** *** 637,641 **** this.setAllHighlightsOff(); ! pnlConsole.append("Added Router "+result+" to simulation \n"); } catch (InvalidNodeNameException e) { --- 794,798 ---- this.setAllHighlightsOff(); ! //pnlConsole.append("Added Router "+result+" to simulation \n"); } catch (InvalidNodeNameException e) { *************** *** 701,705 **** this.setAllHighlightsOff(); ! pnlConsole.append("Added Hub "+result+" to simulation\n"); } catch (InvalidNodeNameException e) { --- 858,862 ---- this.setAllHighlightsOff(); ! //pnlConsole.append("Added Hub "+result+" to simulation\n"); } catch (InvalidNodeNameException e) { *************** *** 763,767 **** this.setAllHighlightsOff(); ! pnlConsole.append("Added Hub "+result+" to simulation\n"); } catch (InvalidNodeNameException e) { --- 920,924 ---- this.setAllHighlightsOff(); ! //pnlConsole.append("Added Hub "+result+" to simulation\n"); } catch (InvalidNodeNameException e) { *************** *** 827,831 **** this.setAllHighlightsOff(); ! pnlConsole.append("Added Switch "+result+" to simulation\n"); } catch (InvalidNodeNameException e) { --- 984,988 ---- this.setAllHighlightsOff(); ! //pnlConsole.append("Added Switch "+result+" to simulation\n"); } catch (InvalidNodeNameException e) { *************** *** 1011,1015 **** tempSecondNode.setConnectedLinkName(strLinkName,2, inNode1); ! pnlConsole.append("Added Link between "+ inNode1 +" and " + inNode2 + "\n"); } --- 1168,1172 ---- tempSecondNode.setConnectedLinkName(strLinkName,2, inNode1); ! //pnlConsole.append("Added Link between "+ inNode1 +" and " + inNode2 + "\n"); } *************** *** 1147,1174 **** } ! catch(LowLinkException e){ ! ! pnlConsole.append(e.toString()+"\n"); } catch(CommunicationException e){ ! ! pnlConsole.append(e.toString()+"\n"); } catch(InvalidNetworkLayerDeviceException e){ ! ! pnlConsole.append(e.toString()+"\n"); ! } catch(InvalidNodeNameException e){ ! ! // This should never be actually thrown ! ! pnlConsole.append(e.toString()+"\n"); ! } --- 1304,1323 ---- } ! catch(LowLinkException e){ ! insertInConsole("(none)", "(none)", "*SYSTEM*", e.toString()); } catch(CommunicationException e){ ! insertInConsole("(none)", "(none)", "*SYSTEM*", e.toString()); } catch(InvalidNetworkLayerDeviceException e){ ! insertInConsole("(none)", "(none)", "*SYSTEM*", e.toString()); } catch(InvalidNodeNameException e){ ! insertInConsole("(none)", "(none)", "*SYSTEM*", e.toString()); } *************** *** 1191,1209 **** setStatus("Starting network transfer..."); ! pnlConsole.append("**************************************************************************************************************** \n"); ! pnlConsole.append("Starting network transfer... \n"); ! pnlConsole.append("**************************************************************************************************************** \n"); ! pnlConsole.append("\n"); } public void printLayerInfo(boolean header){ ! if(header) pnlConsole.append("\n"); Vector vecRecordedInfo = Sim.getRecordedInfo(); --- 1340,1383 ---- setStatus("Starting network transfer..."); ! //pnlConsole.append("**************************************************************************************************************** \n"); ! //pnlConsole.append("Starting network transfer... \n"); ! //pnlConsole.append("**************************************************************************************************************** \n"); ! //pnlConsole.append("\n"); } + + public static final String DATE_FORMAT_NOW = "HH:mm:ss-SSS"; + public static String now() { + Calendar cal = Calendar.getInstance(); + SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW); + return sdf.format(cal.getTime()); + } + + public void insertInConsole(String Node, String Packet, String Layer, String Info){ + mConsole.insertRow(mConsole.getRowCount(), new Object[]{now(), Node,Packet,Layer,Info}); + if(Layer.contains("Network")){ + colorRenderer.setRowColor(mConsole.getRowCount() - 1, Color.CYAN); + }else if(Layer.contains("Link")){ + colorRenderer.setRowColor(mConsole.getRowCount() - 1, Color.YELLOW); + }else if(Layer.contains("Transport")){ + colorRenderer.setRowColor(mConsole.getRowCount() - 1, Color.LIGHT_GRAY); + }else if(Layer.contains("Application")){ + colorRenderer.setRowColor(mConsole.getRowCount() - 1, Color.GREEN); + }else if(Layer.contains("Hardware")){ + colorRenderer.setRowColor(mConsole.getRowCount() - 1, Color.ORANGE); + }else if(Layer.contains("*SYSTEM*")){ + colorRenderer.setRowColor(mConsole.getRowCount() - 1, Color.RED); + } + + } public void printLayerInfo(boolean header){ ! //if(header) pnlConsole.append("\n"); Vector vecRecordedInfo = Sim.getRecordedInfo(); *************** *** 1216,1224 **** if(header){ ! pnlConsole.append("**************************************************************************************************************** \n"); ! pnlConsole.append("The following is a record of the last Transactions movements. \n"); ! pnlConsole.append("**************************************************************************************************************** \n"); } --- 1390,1398 ---- if(header){ ! //pnlConsole.append("**************************************************************************************************************** \n"); ! //pnlConsole.append("The following is a record of the last Transactions movements. \n"); ! //pnlConsole.append("**************************************************************************************************************** \n"); } *************** *** 1238,1242 **** if(filters2[1]) layer = pad(recording[4],15,' '); else layer=""; ! pnlConsole.append(pad(recording[1],15,' ')+packet+pad(recording[3],10,' ')+layer+recording[5]+ "\n"); } --- 1412,1417 ---- if(filters2[1]) layer = pad(recording[4],15,' '); else layer=""; ! //pnlConsole.append(pad(recording[1],15,' ')+packet+pad(recording[3],10,' ')+layer+recording[5]+ "\n"); ! insertInConsole(recording[1], packet, layer, recording[5]); } *************** *** 1244,1248 **** if(header){ ! pnlConsole.append("****************************************************************************************************************\n"); } --- 1419,1423 ---- if(header){ ! //pnlConsole.append("****************************************************************************************************************\n"); } *************** *** 1254,1267 **** public void addFooter(){ ! pnlConsole.append("****************************************************************************************************************\n"); } public void addHeader(){ ! pnlConsole.append("**************************************************************************************************************** \n"); ! pnlConsole.append("The following is a record of the last Transactions movements. \n"); ! pnlConsole.append("**************************************************************************************************************** \n"); } /** --- 1429,1442 ---- public void addFooter(){ ! //pnlConsole.append("****************************************************************************************************************\n"); } public void addHeader(){ ! //pnlConsole.append("**************************************************************************************************************** \n"); ! //pnlConsole.append("The following is a record of the last Transactions movements. \n"); ! //pnlConsole.append("**************************************************************************************************************** \n"); } /** *************** *** 1683,1687 **** this.Sandbox.repaint(); ! pnlConsole.append(inNode.getName() +", and any connected links have been deleted\n"); this.refreshNodeInformationTab(); --- 1858,1862 ---- this.Sandbox.repaint(); ! //pnlConsole.append(inNode.getName() +", and any connected links have been deleted\n"); this.refreshNodeInformationTab(); *************** *** 2531,2536 **** Sim.Reset(InNodeName); ! pnlConsole.append("Device " + InNodeName + " reseted.\n"); ! } --- 2706,2710 ---- Sim.Reset(InNodeName); ! insertInConsole(InNodeName, "(none)", "Hardware", "Device reseted."); } *************** *** 2647,2654 **** public void clearConsole() ! { ! ! pnlConsole.setText(""); ! } --- 2821,2826 ---- public void clearConsole() ! { ! mConsole.setRowCount(0); } *************** *** 3040,3045 **** public void addToConsole(String msg){ ! pnlConsole.append(msg); ! } --- 3212,3217 ---- public void addToConsole(String msg){ ! //pnlConsole.append(msg); ! System.out.println("CONSOLE:!!!!" + msg); } |