예제 #1
0
 /**
  * Return the graph items for this graph.
  *
  * @return the graph items for this graph.
  */
 public GraphItem[] getGraphItems() {
   GraphItem gia[] = new GraphItem[graphItems.size()];
   for (int i = 0; i < graphItems.size(); i++) {
     gia[i] = (GraphItem) graphItems.elementAt(i);
   }
   return gia;
 }
예제 #2
0
 /**
  * Add the graph item to the graph.
  *
  * @param graphItem Item to be added to the graph.
  */
 public void addGraphItem(GraphItem graphItem) {
   if (graphItem != null) {
     graphItems.addElement(graphItem);
     graphItem.addGraphItemListener(graphItemListener);
   }
   repaint();
 }
예제 #3
0
  /**
   * Called by the paint method to draw the graph and its graph items.
   *
   * @param g the graphics context.
   */
  public void paintComponent(Graphics g) {

    Dimension dim = getSize();
    Insets insets = getInsets();
    dataArea =
        new Rectangle(
            insets.left,
            insets.top,
            dim.width - insets.left - insets.right - 1,
            dim.height - insets.top - insets.bottom - 1);
    // background
    if (isOpaque()) {
      g.setColor(getBackground());
      g.fillRect(0, 0, dim.width, dim.height);
    }
    g.setColor(getForeground());
    // get axis tickmarks
    double xticks[] = xAxis.getTicks();
    double yticks[] = yAxis.getTicks();
    int yb = dataArea.y + dataArea.height;
    // draw grid
    if (showGrid) {
      g.setColor(gridColor != null ? gridColor : getBackground().darker());
      // vertical x grid lines
      for (int i = 0; i < xticks.length; i += 2) {
        int x = dataArea.x + (int) Math.round(xticks[i]);
        g.drawLine(x, dataArea.y, x, dataArea.y + dataArea.height);
      }
      // horizontal y grid lines
      for (int i = 0; i < yticks.length; i += 2) {
        int y = yb - (int) Math.round(yticks[i]);
        g.drawLine(dataArea.x, y, dataArea.x + dataArea.width, y);
      }
    }
    for (int i = 0; i < graphItems.size(); i++) {
      ((GraphItem) graphItems.elementAt(i)).draw(this, g, dataArea, xAxis, yAxis);
    }
    if (sPt != null && ePt != null) {
      g.setColor(getForeground());
      g.drawRect(
          Math.min(sPt.x, ePt.x), Math.min(sPt.y, ePt.y),
          Math.abs(ePt.x - sPt.x), Math.abs(ePt.y - sPt.y));
    }
  }
예제 #4
0
 /**
  * Remove the graph item from the graph.
  *
  * @param graphItem Item to be removed from the graph.
  */
 public void removeGraphItem(GraphItem graphItem) {
   graphItems.removeElement(graphItem);
   graphItem.removeGraphItemListener(graphItemListener);
   repaint();
 }