/** Adds the given componet to the given layer. */
  public void addEditorWindow(EditorWindowIndirectRef windowRef) {
    final JInternalFrame window = (JInternalFrame) windowRef;

    Dimension desktopSize = desktopPane.getSize();
    Dimension preferredSize = window.getPreferredSize();

    int x = desktopSize.width / 2 - preferredSize.width / 2;
    int y = desktopSize.height / 2 - preferredSize.height / 2;

    window.setBounds(x, y, preferredSize.width, preferredSize.height);

    // This line sometimes hangs, so I'm putting it in a watch process
    // so it can be stopped by the user. Not ideal.
    //        Window owner = (Window) getTopLevelAncestor();
    //
    //        new WatchedProcess(owner) {
    //            public void watch() {
    getDesktopPane().add(window);
    window.setLayer(100);
    window.moveToFront();

    try {
      window.setVisible(true);
    } catch (Exception e) {
      if (e instanceof ClassCastException || e instanceof NullPointerException) {
        // skip. These is being caused apparently the workbench
        // having labeled nodes and edges. Can't find a
        // workaround--probably a Java bug. jdramsey
      } else {
        e.printStackTrace();
      }
    }

    // prevents the component from being hidden.
    //                window.addComponentListener(new PositionListener());
    //            }
    //        };
  }
Exemple #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);
 }