Ejemplo n.º 1
0
    /**
     * Draws the needle.
     *
     * @param g2  the graphics device.
     * @param plotArea  the plot area.
     * @param rotate  the rotation point.
     * @param angle  the angle.
     */
    protected void drawNeedle(Graphics2D g2, Rectangle2D plotArea,
                              Point2D rotate, double angle) {

        Arc2D shape = new Arc2D.Double(Arc2D.PIE);
        double radius = plotArea.getHeight();
        double halfX = plotArea.getWidth() / 2;
        double diameter = 2 * radius;

        shape.setFrame(plotArea.getMinX() + halfX - radius ,
                       plotArea.getMinY() - radius,
                       diameter, diameter);
        radius = Math.toDegrees(Math.asin(halfX / radius));
        shape.setAngleStart(270 - radius);
        shape.setAngleExtent(2 * radius);

        Area s = new Area(shape);

        if ((rotate != null) && (angle != 0)) {
            /// we have rotation houston, please spin me
            getTransform().setToRotation(angle, rotate.getX(), rotate.getY());
            s.transform(getTransform());
        }

        defaultDisplay(g2, s);
    }
Ejemplo n.º 2
0
 @Override
 public void paintComponent(Graphics g) {
   if (slices != null && !slices.isEmpty()) {
     Arc2D arc2D = null;
     double start = 0;
     int size = Math.min(getWidth(), getHeight()) - 10;
     int x = getWidth() / 2 - size / 2;
     int y = getHeight() / 2 - size / 2;
     if (g instanceof Graphics2D) {
       arc2D = new Arc2D.Double(Arc2D.PIE);
       arc2D.setFrame(x, y, size, size);
       ((Graphics2D) g)
           .setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
     }
     for (PieSlice slice : slices) {
       double arc = (slice.cost / total) * 360.0;
       if (g instanceof Graphics2D) {
         arc2D.setAngleStart(start);
         arc2D.setAngleExtent(arc);
         Color c = ScenarioColorPalette.getColor(slice.toString());
         g.setColor(slice.equals(highlighted) ? c.brighter() : c);
         ((Graphics2D) g).fill(arc2D);
         g.setColor(Color.BLACK);
         ((Graphics2D) g).draw(arc2D);
       } else {
         g.setColor(ScenarioColorPalette.getColor(slice.toString()));
         g.fillArc(x, y, size, size, (int) start, (int) arc);
         g.setColor(Color.BLACK);
         g.drawArc(x, y, size, size, (int) start, (int) arc);
       }
       start += arc;
     }
     g.setColor(ScenarioColorPalette.getColor("Untagged"));
     g.fillArc(x, y, size, size, (int) start, (int) (360.0 - start));
   }
 }
  /**
   * Returns the bargraph track image with the given with and height.
   *
   * @param WIDTH
   * @param START_ANGLE
   * @param ANGLE_EXTEND
   * @param APEX_ANGLE
   * @param BARGRAPH_OFFSET
   * @param image
   * @return buffered image containing the bargraph track image
   */
  protected BufferedImage create_BARGRAPH_TRACK_Image(
      final int WIDTH,
      final double START_ANGLE,
      final double ANGLE_EXTEND,
      final double APEX_ANGLE,
      final double BARGRAPH_OFFSET,
      BufferedImage image) {
    if (WIDTH <= 0) {
      return null;
    }

    if (image == null) {
      image = UTIL.createImage(WIDTH, WIDTH, Transparency.TRANSLUCENT);
    }
    final Graphics2D G2 = image.createGraphics();
    G2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    //        G2.setRenderingHint(RenderingHints.KEY_RENDERING,
    // RenderingHints.VALUE_RENDER_QUALITY);
    //        G2.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE);
    //        G2.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION,
    // RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
    //        G2.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING,
    // RenderingHints.VALUE_COLOR_RENDER_QUALITY);
    //        G2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
    // RenderingHints.VALUE_STROKE_NORMALIZE);

    final int IMAGE_WIDTH = image.getWidth();
    final int IMAGE_HEIGHT = image.getHeight();

    // Create led track
    final java.awt.geom.Arc2D BACK = new java.awt.geom.Arc2D.Double(java.awt.geom.Arc2D.PIE);
    BACK.setFrame(
        IMAGE_WIDTH * 0.1074766355,
        IMAGE_HEIGHT * 0.1074766355,
        IMAGE_WIDTH * 0.785046729,
        IMAGE_HEIGHT * 0.785046729);
    BACK.setAngleStart(START_ANGLE + 2);
    BACK.setAngleExtent(ANGLE_EXTEND - 5);

    final Ellipse2D BACK_SUB =
        new Ellipse2D.Double(
            IMAGE_WIDTH * 0.1822429907,
            IMAGE_HEIGHT * 0.1822429907,
            IMAGE_WIDTH * 0.6355140187,
            IMAGE_HEIGHT * 0.6355140187);

    final java.awt.geom.Area LED_TRACK_FRAME = new java.awt.geom.Area(BACK);
    LED_TRACK_FRAME.subtract(new java.awt.geom.Area(BACK_SUB));

    final Point2D LED_TRACK_FRAME_START =
        new Point2D.Double(0, LED_TRACK_FRAME.getBounds2D().getMinY());
    final Point2D LED_TRACK_FRAME_STOP =
        new Point2D.Double(0, LED_TRACK_FRAME.getBounds2D().getMaxY());
    final float[] LED_TRACK_FRAME_FRACTIONS = {0.0f, 0.22f, 0.76f, 1.0f};
    final Color[] LED_TRACK_FRAME_COLORS = {
      new Color(0, 0, 0, 255),
      new Color(51, 51, 51, 255),
      new Color(51, 51, 51, 255),
      new Color(100, 100, 100, 255)
    };
    final LinearGradientPaint LED_TRACK_FRAME_GRADIENT =
        new LinearGradientPaint(
            LED_TRACK_FRAME_START,
            LED_TRACK_FRAME_STOP,
            LED_TRACK_FRAME_FRACTIONS,
            LED_TRACK_FRAME_COLORS);
    G2.setPaint(LED_TRACK_FRAME_GRADIENT);
    G2.fill(LED_TRACK_FRAME);

    final java.awt.geom.Arc2D FRONT = new java.awt.geom.Arc2D.Double(java.awt.geom.Arc2D.PIE);
    FRONT.setFrame(
        IMAGE_WIDTH * 0.1121495327,
        IMAGE_HEIGHT * 0.1121495327,
        IMAGE_WIDTH * 0.7803738318,
        IMAGE_HEIGHT * 0.7803738318);
    FRONT.setAngleStart(START_ANGLE);
    FRONT.setAngleExtent(ANGLE_EXTEND);

    final Ellipse2D FRONT_SUB =
        new Ellipse2D.Double(
            IMAGE_WIDTH * 0.1822429907,
            IMAGE_HEIGHT * 0.1822429907,
            IMAGE_WIDTH * 0.6448598131,
            IMAGE_HEIGHT * 0.6448598131);

    final java.awt.geom.Area LED_TRACK_MAIN = new java.awt.geom.Area(BACK);
    LED_TRACK_MAIN.subtract(new java.awt.geom.Area(FRONT_SUB));

    final Point2D LED_TRACK_MAIN_START =
        new Point2D.Double(0, LED_TRACK_MAIN.getBounds2D().getMinY());
    final Point2D LED_TRACK_MAIN_STOP =
        new Point2D.Double(0, LED_TRACK_MAIN.getBounds2D().getMaxY());
    final float[] LED_TRACK_MAIN_FRACTIONS = {0.0f, 1.0f};
    final Color[] LED_TRACK_MAIN_COLORS = {new Color(17, 17, 17, 255), new Color(51, 51, 51, 255)};
    final LinearGradientPaint LED_TRACK_MAIN_GRADIENT =
        new LinearGradientPaint(
            LED_TRACK_MAIN_START,
            LED_TRACK_MAIN_STOP,
            LED_TRACK_MAIN_FRACTIONS,
            LED_TRACK_MAIN_COLORS);
    G2.setPaint(LED_TRACK_MAIN_GRADIENT);
    G2.fill(LED_TRACK_MAIN);

    // Draw the inactive leds
    final Point2D CENTER = new Point2D.Double(WIDTH / 2.0, WIDTH / 2.0);
    final Rectangle2D LED =
        new Rectangle2D.Double(
            WIDTH * 0.1168224299,
            WIDTH * 0.4859813084,
            WIDTH * 0.06074766355140187,
            WIDTH * 0.023364486);
    final Point2D LED_CENTER = new Point2D.Double(LED.getCenterX(), LED.getCenterY());

    final Color[] LED_COLORS = new Color[] {new Color(60, 60, 60, 255), new Color(50, 50, 50, 255)};
    final RadialGradientPaint LED_GRADIENT =
        new RadialGradientPaint(
            LED_CENTER, (float) (0.030373831775700934 * IMAGE_WIDTH), LED_FRACTIONS, LED_COLORS);
    G2.setPaint(LED_GRADIENT);

    final AffineTransform OLD_TRANSFORM = G2.getTransform();

    for (double angle = 0; angle <= APEX_ANGLE; angle += 5.0) {
      G2.rotate(Math.toRadians(angle + BARGRAPH_OFFSET), CENTER.getX(), CENTER.getY());
      G2.fill(LED);
      G2.setTransform(OLD_TRANSFORM);
    }

    G2.dispose();

    return image;
  }