Example #1
0
 public void setCurrentTool(RegionOfInterestTool regionOfInterestTool) {
   for (Component c : this.getComponents()) {
     if (c instanceof DataPanel) {
       ((DataPanel) c).setCurrentTool(regionOfInterestTool);
     }
   }
 }
Example #2
0
  /**
   * Paint to an offscreen graphic, e.g. a graphic for an image or svg file.
   *
   * @param g
   * @param rect
   */
  public void paintOffscreen(Graphics2D g, Rectangle rect) {

    // Get the components of the sort by X position.
    Component[] components = getComponents();
    Arrays.sort(
        components,
        new Comparator<Component>() {
          public int compare(Component component, Component component1) {
            return component.getX() - component1.getX();
          }
        });

    for (Component c : this.getComponents()) {

      if (c instanceof DataPanel) {
        Graphics2D g2d = (Graphics2D) g.create();
        Rectangle clipRect = new Rectangle(c.getBounds());
        clipRect.height = rect.height;
        g2d.setClip(clipRect);
        g2d.translate(c.getX(), 0);
        ((DataPanel) c).paintOffscreen(g2d, rect);
      }
    }
    // super.paintBorder(g);
  }
Example #3
0
  /** Initializes the painting algorithm in the DataPanel */
  private void initPainter() {
    getContentPane().remove(DataPanel);

    topx1 = 0;
    topx2 = 120;
    bottomx1 = 150;
    bottomx2 = 0;
    timer = new javax.swing.Timer(10, this);
    timer.start();

    DataPanel =
        new JPanel() {
          public void paint(Graphics g) {
            super.paint(g);
            Graphics2D g2d = (Graphics2D) g;

            panelLength = getSize().width;
            panelHeight = getSize().height;

            g2d.setStroke(new BasicStroke(10));

            GradientPaint topBarPaint =
                new GradientPaint(topx1, topy1, Color.black, topx2, topy2, Color.blue, true);

            g2d.setPaint(topBarPaint);
            g2d.drawLine(0, 0, panelLength, 0);

            GradientPaint bottomBarPaint =
                new GradientPaint(
                    bottomx1, bottomy1, Color.black, bottomx2, bottomy2, Color.blue, true);

            g2d.setPaint(bottomBarPaint);
            g2d.drawLine(0, panelHeight, panelLength, panelHeight);

            if (drawVerticalLines) {
              GradientPaint verticalBarPaint =
                  new GradientPaint(0, 0, Color.black, 0, panelHeight, Color.lightGray, true);

              g2d.setStroke(new BasicStroke(2));
              g2d.setPaint(verticalBarPaint);
              g2d.drawLine(vertx1, 6, vertx2, panelHeight - 6);
              g2d.drawLine(vert2x1, 6, vert2x2, panelHeight - 6);
            }

            g2d.setPaint(new GradientPaint(50, 0, Color.darkGray, 450, 0, Color.black));
            g2d.setFont(new Font("Verdana", 0, 18));

            double strWidth = g2d.getFontMetrics().getStringBounds(upperMessage, g2d).getWidth();
            g2d.drawString(
                upperMessage,
                (float) (panelLength / 2) - (float) (strWidth / 2),
                (float) panelHeight / 3);

            strWidth = g2d.getFontMetrics().getStringBounds(lowerMessage, g2d).getWidth();
            g2d.drawString(
                lowerMessage,
                (float) (panelLength / 2) - (float) (strWidth / 2),
                (float) panelHeight / (1.5f));
          }
        };

    DataPanel.setMinimumSize(new Dimension(450, 100));
    DataPanel.setPreferredSize(new Dimension(450, 100));
    DataPanel.setMaximumSize(new Dimension(450, 100));

    getContentPane().add(DataPanel);
    this.pack();
    centerOnScreen();
  }