Пример #1
1
 /**
  * Updates the data set for both charts with the contents of the supplied Hashtable. The Hashtable
  * is expected to contain the following items:
  *
  * <ul>
  *   <li>down - The number of links currently in a down state
  *   <li>up - The number of links currently in an up state
  *   <li>unknown - The number of links currently in an unknown state
  * </ul>
  *
  * @param linkStats The hashtable containing the entries indicating current link statistics.
  */
 public void updateData(Hashtable<String, Integer> linkStats) {
   dpdCurrentData.insertValue(0, "Link Down", linkStats.get("down"));
   dpdCurrentData.insertValue(1, "Link Up", linkStats.get("up"));
   dpdCurrentData.insertValue(2, "Link State Unknown", linkStats.get("unknown"));
   dcdPreviousData.addValue(
       linkStats.get("down"), "Link Down", Calendar.getInstance().getTime().toString());
   dcdPreviousData.addValue(
       linkStats.get("up"), "Link Up", Calendar.getInstance().getTime().toString());
   dcdPreviousData.addValue(
       linkStats.get("unknown"),
       "Link State Unknown",
       Calendar.getInstance().getTime().toString());
 }
Пример #2
0
 /**
  * Initialises the class and internal logger. Uses the supplied arguments to receive data from the
  * application and add data to the charts dynamically.
  *
  * @param title The title of the charts on display. Whether the displayed data is for <code>new
  *     </code> or <code>old</code> links. That is whether the data is for newly discovered links
  *     or existing (old) links already stored within the database.
  * @param parent The instance of <code>COMPortClient</code> that acts as the data source for the
  *     charts.
  */
 public LinkChart(String title, COMPortClient parent) {
   super("Charts", true, true, true, true);
   super.setLayer(1);
   identifier = title.toLowerCase();
   // Obtain an instance of Logger for the class
   log = LoggerFactory.getLogger(className);
   owner = parent;
   // Setup a hashtable to hold the values for up, down and unknown link states
   Hashtable<String, Integer> linkStats = new Hashtable<String, Integer>();
   if (identifier.equals("old")) {
     this.setTitle("Recognised Link Status on " + owner.getPortName() + ":");
     // Get the current figures from the link table
     linkStats = ((LinkTable) owner.getLinkTable().getModel()).getInitialFigures();
   } else if (identifier.equals("new")) {
     this.setTitle("Discovered Link Status on " + owner.getPortName() + ":");
     linkStats = ((LinkTable) owner.getNewLinkTable().getModel()).getInitialFigures();
   } else {
     // If the identifier was set to something other than old or new then it's not right.
     log.warning("An instance of LinkChart has been created for an unknown purpose.");
     return;
   }
   // Initialise the dataset for the pie chart
   dpdCurrentData = new DefaultPieDataset();
   dpdCurrentData.insertValue(0, "Link Down", linkStats.get("down"));
   dpdCurrentData.insertValue(1, "Link Up", linkStats.get("up"));
   dpdCurrentData.insertValue(2, "Link State Unknown", linkStats.get("unknown"));
   // Initialise the dataset for the line chart
   dcdPreviousData = new DefaultCategoryDataset();
   dcdPreviousData.addValue(
       linkStats.get("down"), "Link Down", Calendar.getInstance().getTime().toString());
   dcdPreviousData.addValue(
       linkStats.get("up"), "Link Up", Calendar.getInstance().getTime().toString());
   dcdPreviousData.addValue(
       linkStats.get("unknown"),
       "Link State Unknown",
       Calendar.getInstance().getTime().toString());
   // Set the variables we need for holding the charts
   JFreeChart jfcCurrentStatus; // This will be displayed as a pie chart
   JFreeChart jfcPreviousStatus; // This will be displayed as a line chart
   ChartPanel cpCurrent; // Chartpanels hold the JFreeChart
   ChartPanel cpPrevious;
   // Use the factory to create the charts
   jfcCurrentStatus =
       ChartFactory.createPieChart("Current Status", dpdCurrentData, true, true, false);
   jfcPreviousStatus =
       ChartFactory.createLineChart(
           "Previous Status",
           "Time received",
           "Number of Links",
           dcdPreviousData,
           PlotOrientation.VERTICAL,
           true,
           true,
           false);
   // Add them to the chart panels
   cpCurrent = new ChartPanel(jfcCurrentStatus);
   cpPrevious = new ChartPanel(jfcPreviousStatus);
   // Add the chart panels to the content pane
   this.add(cpCurrent, BorderLayout.EAST);
   this.add(cpPrevious, BorderLayout.WEST);
   // Change the layout to show them next to each other
   this.setLayout(new GridLayout(1, 2));
   // Add a listener to the window
   this.addInternalFrameListener(new CloseLinkChart(this));
   log.finest("Adding frame to the desktop");
   // Set the window properties and display it
   Client.getJNWindow().addToDesktop(this);
   this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
   this.setSize(650, 400);
   this.setVisible(true);
   owner.addChartWindow(title, this);
 }