private void drawAvatarBullet(
      Graphics2D g2, double x, double y, double bulletWidth, double bulletHeight) {
    RoundRectangle2D bullet =
        new RoundRectangle2D.Double(
            0.0, 0.0, bulletWidth, bulletHeight, bulletHeight, bulletHeight);
    Ellipse2D curve =
        new Ellipse2D.Double(-20.0, bulletHeight / 2.0, bulletWidth + 40.0, bulletHeight);

    g2.translate(x, y);

    g2.translate(-1, -2);
    g2.setColor(new Color(0, 0, 0, 170));
    g2.fill(
        new RoundRectangle2D.Double(
            0.0, 0.0, bulletWidth + 2, bulletHeight + 4, bulletHeight + 4, bulletHeight + 4));
    g2.translate(1, 2);

    Color startColor = new Color(10, 0, 40);
    Color endColor = new Color(175, 165, 225);

    Paint paint = g2.getPaint();
    g2.setPaint(new GradientPaint(0.0f, 0.0f, startColor, 0.0f, (float) bulletHeight, endColor));
    g2.fill(bullet);

    startColor = new Color(5, 0, 50);
    endColor = new Color(105, 100, 155);
    g2.setPaint(new GradientPaint(0.0f, 0.0f, startColor, 0.0f, (float) bulletHeight, endColor));

    Area area = new Area(bullet);
    area.intersect(new Area(curve));
    g2.fill(area);

    g2.setPaint(paint);
    g2.translate(-x, -y);
  }
Esempio n. 2
0
  private void paintScaledTriangle(
      Graphics g, double x, double y, double size, int direction, boolean isEnabled) {
    size = Math.max(size, 2);
    Path2D.Double path = new Path2D.Double();
    path.moveTo(-size, size / 2);
    path.lineTo(size, size / 2);
    path.lineTo(0, -size / 2);
    path.closePath();
    AffineTransform affineTransform = new AffineTransform();
    affineTransform.rotate(Math.PI * (direction - 1) / 4);
    path.transform(affineTransform);

    Graphics2D g2d = (Graphics2D) g;
    double tx = x + size / 2;
    double ty = y + size / 2;
    g2d.translate(tx, ty);
    Color oldColor = g.getColor();
    if (!isEnabled) {
      g2d.translate(1, 0);
      g2d.setColor(highlight);
      g2d.fill(path);
      g2d.translate(-1, 0);
    }
    g2d.setColor(isEnabled ? darkShadow : shadow);
    g2d.fill(path);
    g2d.translate(-tx, -ty);
    g2d.setColor(oldColor);
  }
Esempio n. 3
0
  public void draw(Graphics2D g, boolean bVertical, boolean bRight) {
    if (!bValid) return;
    int tx = pX;
    int ty = pY;

    g.setColor(fgColor);

    if (bVertical) {
      if (bRight) {
        tx = pX + pWidth;
        ty = pY;
        g.translate(tx, ty);
        g.rotate(deg90);
      } else {
        tx = pX;
        ty = pY + pHeight;
        g.translate(tx, ty);
        g.rotate(-deg90);
      }
    } else {
      if (tx != 0 || ty != 0) g.translate(tx, ty);
    }

    g.drawLine(x, y, x2, y2);

    if (bVertical) {
      if (bRight) g.rotate(-deg90);
      else g.rotate(deg90);
    }
    if (tx != 0 || ty != 0) g.translate(-tx, -ty);
  }
Esempio n. 4
0
  @SuppressWarnings("unchecked")
  static <C extends JComponent & BackgroundPaintable> void paintBackground(C comp, Graphics2D g) {
    // we should be painting the background behind the painter if we have one
    // this prevents issues with buffer reuse where visual artifacts sneak in
    if (comp.isOpaque()
        || (comp instanceof AlphaPaintable && ((AlphaPaintable) comp).getAlpha() < 1f)
        || UIManager.getLookAndFeel().getID().equals("Nimbus")) {
      g.setColor(comp.getBackground());
      g.fillRect(0, 0, comp.getWidth(), comp.getHeight());
    }

    Painter<? super C> painter = comp.getBackgroundPainter();

    if (painter != null) {
      if (comp.isPaintBorderInsets()) {
        painter.paint(g, comp, comp.getWidth(), comp.getHeight());
      } else {
        Insets insets = comp.getInsets();
        g.translate(insets.left, insets.top);
        painter.paint(
            g,
            comp,
            comp.getWidth() - insets.left - insets.right,
            comp.getHeight() - insets.top - insets.bottom);
        g.translate(-insets.left, -insets.top);
      }
    }
  }
Esempio n. 5
0
  /**
   * DOCUMENT ME!
   *
   * @param g2 DOCUMENT ME!
   * @param c DOCUMENT ME!
   */
  public void paintChildren(Graphics2D g2, Component c) {
    if ((c.getChildren() == null) || c.getChildren().isEmpty()) {
      return;
    }

    Rectangle bounds = c.getBounds();
    Graphics2D gcopy = (Graphics2D) g2.create();

    gcopy.translate(bounds.x, bounds.y);

    Insets padding = c.getPadding();

    if (padding != null) {
      gcopy.translate(padding.left, padding.top);
    }

    ArrayList childrenCopy = (ArrayList) c.getChildren();

    Comparator comparator = ComponentComparator.getInstance();
    Collections.sort(childrenCopy, comparator);

    Iterator iterator = childrenCopy.iterator();

    while (iterator.hasNext()) {
      Component component = (Component) iterator.next();
      paintChild(gcopy, component);
    }

    gcopy.dispose();
  }
Esempio n. 6
0
  private void drawSliders(Graphics2D g2d) {
    g2d.translate(sliderBaseLineRect.x, sliderBaseLineRect.y);
    g2d.setStroke(STROKE_1);
    for (int i = 0; i < getSliderCount(); i++) {
      if (isSliderVisible(i)) {
        double sliderPos = getRelativeSliderPos(getSliderSample(i));

        g2d.translate(sliderPos, 0.0);

        final Color sliderColor = getSliderColor(i);
        g2d.setPaint(sliderColor);
        g2d.fill(sliderShape);

        int gray = (sliderColor.getRed() + sliderColor.getGreen() + sliderColor.getBlue()) / 3;
        g2d.setColor(gray < 128 ? Color.white : Color.black);
        g2d.draw(sliderShape);

        String text = getFormattedValue(getSliderSample(i));
        g2d.setColor(Color.black);
        // save the old transformation
        final AffineTransform oldTransform = g2d.getTransform();
        g2d.transform(AffineTransform.getRotateInstance(Math.PI / 2));
        g2d.drawString(text, 3 + 0.5f * SLIDER_HEIGHT, 0.35f * FONT_SIZE);
        // restore the old transformation
        g2d.setTransform(oldTransform);

        g2d.translate(-sliderPos, 0.0);
      }
    }

    g2d.translate(-sliderBaseLineRect.x, -sliderBaseLineRect.y);
  }
Esempio n. 7
0
 @Override
 public void paint(Graphics g) {
   Graphics2D g2 = (Graphics2D) g;
   Stroke initialStroke = g2.getStroke();
   Color initialColor = g2.getColor();
   if (drawConcrete) {
     g2.setColor(Color.LIGHT_GRAY);
     g2.fill(getBounds());
   }
   g2.translate(loc.getX(), loc.getY());
   g2.rotate(rot);
   if (picture != null) {
     g2.drawImage(picture, -picture.getWidth(null) / 2, -picture.getHeight(null) / 2, null);
   }
   g2.setStroke(stroke);
   for (int i = 0; i < complexity; i++) {
     g2.translate(rLoc[i].getX(), rLoc[i].getY());
     g2.rotate(rRot[i]);
     g2.setColor(rCol[i]);
     if (rFill[i]) {
       g2.fill(rShape[i]);
     } else {
       g2.draw(rShape[i]);
     }
     g2.rotate(-rRot[i]);
     g2.translate(-rLoc[i].getX(), -rLoc[i].getY());
   }
   g2.setColor(initialColor);
   g2.setStroke(initialStroke);
   g2.rotate(-rot);
   g2.translate(-loc.getX(), -loc.getY());
 }
Esempio n. 8
0
  public void paintComponent(Graphics g) {
    Color controle = UIManager.getColor("control");
    int width = getWidth() - 6;
    int height = getHeight() - 6;

    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setRenderingHint(
        RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    g2.setRenderingHint(
        RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);

    RoundRectangle2D rect = new RoundRectangle2D.Double(0, 0, width, height, 12, 12);
    drawShadow(g2, rect);

    Paint pinceau = g2.getPaint();
    if (!mouseOver) {
      g2.setPaint(new GradientPaint(this.icon.getIconWidth(), 0, Color.white, width, 0, controle));
    } else {
      g2.setColor(Color.white);
    }

    g2.translate(2, 2);
    if (mousePressed) {
      g2.translate(1, 1);
    }

    g2.fill(rect);
    g2.setPaint(pinceau);
    g2.translate(-2, -2);
  }
  @Override
  protected void paintIcon(JComponent c, Graphics2D g, Rectangle viewRect, Rectangle iconRect) {
    int rad = JBUI.scale(4);

    // Paint the radio button
    final int x = iconRect.x + (rad - (rad % 2 == 1 ? 1 : 0)) / 2;
    final int y = iconRect.y + (rad - (rad % 2 == 1 ? 1 : 0)) / 2;
    final int w = iconRect.width - rad;
    final int h = iconRect.height - rad;
    final boolean enabled = c.isEnabled();
    Color color = enabled ? Gray.x50 : Gray.xD3;
    g.translate(x, y);
    // setup AA for lines
    final GraphicsConfig config = GraphicsUtil.setupAAPainting(g);
    g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
    final boolean selected = ((AbstractButton) c).isSelected();
    g.setPaint(color);
    g.drawOval(0, 0, w, h);

    if (selected) {
      g.setColor(color);
      g.fillOval(JBUI.scale(3), JBUI.scale(3), w - 2 * JBUI.scale(3), h - 2 * JBUI.scale(3));
    }
    config.restore();
    g.translate(-x, -y);
  }
Esempio n. 10
0
  @Override
  public void paintIcon(Component c, Graphics g, int x, int y) {
    final Graphics2D g2d = (Graphics2D) g;

    // Turn AA on
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    final Font original = g2d.getFont();

    if (value != null) {
      String text = value.toString();
      final int textLen = text.length();

      g2d.translate(leftPad, (c.getHeight()) / 2);

      g2d.setColor(color);
      if (textLen > MAX_TEXT_LEN) {
        text = text.substring(0, 5) + "...";
        g2d.setFont(FONT_SMALL);
      } else g2d.setFont(FONT);

      g2d.drawString(text, 0, 0);
      g2d.translate(-leftPad, -((c.getHeight()) / 2));
    }

    g2d.setFont(original);
  }
Esempio n. 11
0
    /**
     * Hook for subclassers to paint the background page(s).
     *
     * @param g2 The graphics object to paint the background page(s) on.
     */
    protected void paintBackgroundPages(Graphics2D g2) {
      Point2D p = graph.toScreen(new Point2D.Double(pageFormat.getWidth(), pageFormat.getHeight()));
      Dimension pSize = graph.getPreferredSize();
      int w = (int) (p.getX() * pageScale);
      int h = (int) (p.getY() * pageScale);
      int cols = (int) Math.max(Math.ceil((double) (pSize.width - 5) / (double) w), 1);
      int rows = (int) Math.max(Math.ceil((double) (pSize.height - 5) / (double) h), 1);
      g2.setColor(graph.getHandleColor());

      // Draws the pages.
      Point offset = getViewPosition();
      g2.translate(-offset.x, -offset.y);
      g2.fillRect(0, 0, graph.getWidth(), graph.getHeight());
      g2.setColor(Color.darkGray);
      g2.fillRect(3, 3, cols * w, rows * h);
      g2.setColor(getGraph().getBackground());
      g2.fillRect(1, 1, cols * w - 1, rows * h - 1);

      // Draws the pagebreaks.
      Stroke previousStroke = g2.getStroke();
      g2.setStroke(
          new BasicStroke(
              1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, new float[] {1, 2}, 0));
      g2.setColor(Color.darkGray);
      for (int i = 1; i < cols; i++) g2.drawLine(i * w, 1, i * w, rows * h - 1);
      for (int i = 1; i < rows; i++) g2.drawLine(1, i * h, cols * w - 1, i * h);

      // Restores the graphics.
      g2.setStroke(previousStroke);
      g2.translate(offset.x, offset.y);
      g2.clipRect(0, 0, cols * w - 1 - offset.x, rows * h - 1 - offset.y);
    }
Esempio n. 12
0
  public void draw(Graphics2D g, boolean bVertical, boolean bRight) {
    if (!bValid || dataSize < 1) return;
    int tx = pX;
    int ty = pY;

    g.setColor(fgColor);
    if (bVertical) {
      if (bRight) {
        tx = pX + pWidth;
        ty = pY;
        g.translate(tx, ty);
        g.rotate(deg90);
      } else {
        tx = pX;
        ty = pY + pHeight;
        g.translate(tx, ty);
        g.rotate(-deg90);
      }
    } else {
      if (tx != 0 || ty != 0) g.translate(tx, ty);
    }

    if (dataSize > 1) g.drawPolyline(xPoints, yPoints, dataSize);
    else g.drawLine(xPoints[0], yPoints[0], xPoints[0], yPoints[0]);

    if (bVertical) {
      if (bRight) {
        g.rotate(-deg90);
      } else g.rotate(deg90);
    }
    if (tx != 0 || ty != 0) g.translate(-tx, -ty);
  }
    @Override
    protected void paintContextualTaskGroupOutlines(
        Graphics g, RibbonContextualTaskGroup group, Rectangle groupBounds) {
      Graphics2D g2d = (Graphics2D) g.create();

      // SubstanceColorScheme scheme = SubstanceColorSchemeUtilities
      // .getBorderColorScheme(ribbon, ComponentState.DEFAULT);

      g2d.translate(groupBounds.x, 0);
      SeparatorPainterUtils.paintSeparator(
          ribbon,
          g2d,
          2,
          groupBounds.height * 3 / 4,
          SwingConstants.VERTICAL,
          false,
          0,
          groupBounds.height / 3,
          true);

      g2d.translate(groupBounds.width - 1, 0);
      SeparatorPainterUtils.paintSeparator(
          ribbon,
          g2d,
          2,
          groupBounds.height * 3 / 4,
          SwingConstants.VERTICAL,
          false,
          0,
          groupBounds.height / 3,
          true);

      g2d.dispose();
    }
  @Override
  public void paintComponent(Graphics g) {
    super.paintComponent(g);

    Graphics2D g2D = (Graphics2D) g.create();

    // Draw each space
    for (int i = 0, degrees = 0; i < imageNames.size() / 2; ++i) {
      g2D.setColor(
          WHEEL_COLORS.get(imageNames.get(i).substring(0, imageNames.get(i).indexOf('.'))));
      g2D.fillArc(150, 45, 480, 480, degrees, DEGREES_EACH);
      degrees += DEGREES_EACH;
    }

    // Set the origin and rotate before drawing the images
    g2D.translate(390, 285);
    g2D.rotate(Math.toRadians(-100));

    // Draw wheel spaces
    for (int i = 0; i < imageNames.size() / 2; ++i) {
      g2D.drawImage(IMAGES.get(imageNames.get(i)), -42, 0, this);
      g2D.rotate(Math.toRadians(-DEGREES_EACH));
    }

    // Reset origin
    g2D.translate(-390, -285);

    // Draw the arrow to indicate where the wheel stopped
    g.drawImage(IMAGES.get("arrow.png"), 370, 10, this);
  }
  public BufferedImage getBackground(int width, int height) {
    BufferedImage result = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    Graphics2D graphics = result.createGraphics();

    BasicStroke bs =
        new BasicStroke(
            2.0f,
            BasicStroke.CAP_BUTT,
            BasicStroke.JOIN_MITER,
            2.0f,
            new float[] {2.0f, 2.0f},
            0.0f);
    graphics.setStroke(bs);
    AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.75f);
    graphics.setComposite(ac);

    graphics.translate(width * -1.0, 0.0);
    double delta = 5.0;
    double xt;
    double ts = 0.0;
    for (xt = 0.0; xt < (2.0 * width); xt += delta) {
      Arc2D arc = new Arc2D.Double(0, 0, width, height, 0.0, 360.0, Arc2D.OPEN);
      graphics.draw(arc);
      graphics.translate(delta, 0.0);
      ts += delta;
    }
    graphics.dispose();
    return result;
  }
Esempio n. 16
0
  public void render(int w, int h, Graphics2D g2) {

    g2.translate(w * .2, h * .2);

    GeneralPath p = new GeneralPath(GeneralPath.WIND_NON_ZERO);
    p.moveTo(0.0f, 0.0f);
    p.lineTo(w * .5f, 0.0f);
    p.lineTo(w * .5f, h * .2f);
    p.lineTo(0.0f, h * .2f);
    p.closePath();

    p.moveTo(w * .05f, h * .05f);
    p.lineTo(w * .55f, h * .05f);
    p.lineTo(w * .55f, h * .25f);
    p.lineTo(w * .05f, h * .25f);
    p.closePath();

    g2.setColor(LIGHT_GRAY);
    g2.fill(p);
    g2.setColor(BLACK);
    g2.draw(p);
    g2.drawString("NON_ZERO rule", 0, -5);

    g2.translate(0.0f, h * .45);

    p.setWindingRule(GeneralPath.WIND_EVEN_ODD);
    g2.setColor(LIGHT_GRAY);
    g2.fill(p);
    g2.setColor(BLACK);
    g2.draw(p);
    g2.drawString("EVEN_ODD rule", 0, -5);
  }
Esempio n. 17
0
 public void centrage(Graphics g) {
   Graphics2D g2;
   g2 = (Graphics2D) g;
   int largeurAffichage = physics.getLignes() * pixel_size,
       hauteurAffichage = physics.getColonnes() * pixel_size;
   double diffX = this.getWidth() / (double) largeurAffichage,
       diffY = this.getHeight() / (double) hauteurAffichage;
   if (diffY > diffX) {
     g2.translate(
         0,
         Math.max(
                 hauteurAffichage * diffX - this.getHeight(),
                 this.getHeight() - hauteurAffichage * diffX)
             / 2);
     g2.scale(diffX, diffX);
     // transform = (AffineTransform) g2.getTransform();
   } else {
     g2.translate(
         Math.max(
                 largeurAffichage * diffY - this.getWidth(),
                 this.getWidth() - largeurAffichage * diffY)
             / 2,
         0);
     g2.scale(diffY, diffY);
     // transform = (AffineTransform) g2.getTransform();
   }
 }
Esempio n. 18
0
  @Override
  public void paint(Graphics g) {
    onResize();
    double speed = this.speed;
    float rotation = 0;
    Graphics2D g2d = (Graphics2D) g;

    drawBackground(g2d);

    // needle
    g2d.translate(getNeedleLocation().x, getNeedleLocation().y); // translate begin middle
    drawFrom00Center(g2d);
    g2d.rotate(getNeedleStartRotation()); // rotate begin needle
    rotation += getNeedleStartRotation();
    drawBackgroundWithNeedleStartRotation(g2d);

    g2d.rotate(step1Speed * speed); // rotate begin speed
    rotation += step1Speed * speed;

    drawNeedle(g2d);
    drawOnNeedleSpeedRotation(g2d);

    g2d.rotate(-rotation); // rotate end,rotate end
    g2d.translate(-getNeedleLocation().x, -getNeedleLocation().y); // //translate end
    rotation = 0;

    super.paint(g2d);
  }
Esempio n. 19
0
  // <editor-fold defaultstate="collapsed" desc="Visualization">
  @Override
  protected void paintComponent(Graphics g) {
    final Graphics2D G2 = (Graphics2D) g.create();

    G2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    G2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    G2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);
    G2.setRenderingHint(
        RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

    // Translate the coordinate system related to insets
    G2.translate(getFramelessOffset().getX(), getFramelessOffset().getY());

    // Draw combined background image
    G2.drawImage(bImage, 0, 0, null);

    // Draw the symbol image
    if (on) {
      G2.drawImage(symbolOnImage, 0, 0, null);
    } else {
      G2.drawImage(symbolOffImage, 0, 0, null);
    }

    // Draw combined foreground image
    G2.drawImage(fImage, 0, 0, null);

    if (!isEnabled()) {
      G2.drawImage(disabledImage, 0, 0, null);
    }

    // Translate the coordinate system back to original
    G2.translate(-getInnerBounds().x, -getInnerBounds().y);

    G2.dispose();
  }
Esempio n. 20
0
 @Override
 public void drawOn(Graphics2D g) {
   super.drawOn(g);
   g.translate(this.getPosition().getX() + 36, this.getPosition().getY() + 36);
   g.drawImage(image, -36, -36, 36, 36, 0, 0, image.getWidth(), image.getHeight(), null);
   g.translate(-this.getPosition().getX() - 36, -this.getPosition().getY() - 36);
 }
Esempio n. 21
0
  public void drawOSDText(Graphics2D g) {
    String message = "<html>" + tr("<h2>Filter active</h2>");

    if (disabledCount == 0 && disabledAndHiddenCount == 0) return;

    if (disabledAndHiddenCount != 0) {
      message += tr("<p><b>{0}</b> objects hidden", disabledAndHiddenCount);
    }

    if (disabledAndHiddenCount != 0 && disabledCount != 0) {
      message += "<br>";
    }

    if (disabledCount != 0) {
      message += tr("<b>{0}</b> objects disabled", disabledCount);
    }

    message += tr("</p><p>Close the filter dialog to see all objects.<p></html>");

    lblOSD.setText(message);
    lblOSD.setSize(lblOSD.getPreferredSize());

    int dx = Main.map.mapView.getWidth() - lblOSD.getPreferredSize().width - 15;
    int dy = 15;
    g.translate(dx, dy);
    lblOSD.paintComponent(g);
    g.translate(-dx, -dy);
  }
 private static void drawCircle(Graphics2D g2, float x, float y) {
   g2.setColor(blue);
   g2.translate(x, y);
   g2.fillArc(0, 0, 8, 8, 0, 360);
   g2.setColor(Color.BLACK);
   g2.drawArc(0, 0, 8, 8, 0, 360);
   g2.translate(-x, -y);
 }
Esempio n. 23
0
 @Override
 public void setup(Graphics2D g2d, float fraction) {
   // translate back and forth to rotate around the right point
   g2d.translate(xCenter, yCenter);
   g2d.rotate(Math.toRadians(fraction * degrees));
   g2d.translate(-xCenter, -yCenter);
   super.setup(g2d, fraction);
 }
Esempio n. 24
0
 /**
  * Draws this multi-line string inside a given rectangle.
  *
  * @param pGraphics2D the graphics context
  * @param pRectangle the rectangle into which to place this multi-line string
  */
 public void draw(Graphics2D pGraphics2D, Rectangle2D pRectangle) {
   JLabel label = getLabel();
   label.setFont(pGraphics2D.getFont());
   label.setBounds(0, 0, (int) pRectangle.getWidth(), (int) pRectangle.getHeight());
   pGraphics2D.translate(pRectangle.getX(), pRectangle.getY());
   label.paint(pGraphics2D);
   pGraphics2D.translate(-pRectangle.getX(), -pRectangle.getY());
 }
Esempio n. 25
0
  public void paint(Graphics g) {
    super.paint(g);

    Graphics2D g2 = (Graphics2D) g;
    int size =
        Math.min(
            MAX_SIZE,
            Math.min(
                getWidth() - imagePadding.left - imagePadding.right,
                getHeight() - imagePadding.top - imagePadding.bottom));

    g2.translate(getWidth() / 2 - size / 2, getHeight() / 2 - size / 2);
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    Shape shape;

    if (mode == ColorPicker.SAT || mode == ColorPicker.BRI) {
      shape = new Ellipse2D.Float(0, 0, size, size);
    } else {
      Rectangle r = new Rectangle(0, 0, size, size);
      shape = r;
    }

    if (hasFocus()) {
      PaintUtils.paintFocus(g2, shape, 5);
    }

    if (!(shape instanceof Rectangle)) {
      // paint a circular shadow
      g2.translate(2, 2);
      g2.setColor(new Color(0, 0, 0, 20));
      g2.fill(new Ellipse2D.Float(-2, -2, size + 4, size + 4));
      g2.setColor(new Color(0, 0, 0, 40));
      g2.fill(new Ellipse2D.Float(-1, -1, size + 2, size + 2));
      g2.setColor(new Color(0, 0, 0, 80));
      g2.fill(new Ellipse2D.Float(0, 0, size, size));
      g2.translate(-2, -2);
    }

    g2.drawImage(image, 0, 0, size, size, 0, 0, size, size, null);

    if (shape instanceof Rectangle) {
      Rectangle r = (Rectangle) shape;
      PaintUtils.drawBevel(g2, r);
    } else {
      g2.setColor(new Color(0, 0, 0, 120));
      g2.draw(shape);
    }

    g2.setColor(Color.white);
    g2.setStroke(new BasicStroke(1));
    g2.draw(new Ellipse2D.Float(point.x - 3, point.y - 3, 6, 6));
    g2.setColor(Color.black);
    g2.draw(new Ellipse2D.Float(point.x - 4, point.y - 4, 8, 8));

    g.translate(-imagePadding.left, -imagePadding.top);
  }
Esempio n. 26
0
  public BufferedImage filter(BufferedImage src, BufferedImage dst) {
    if (dst == null) dst = createCompatibleDestImage(src, null);
    BufferedImage tsrc = src;
    float cx = (float) src.getWidth() * centreX;
    float cy = (float) src.getHeight() * centreY;
    float imageRadius = (float) Math.sqrt(cx * cx + cy * cy);
    float translateX = (float) (distance * Math.cos(angle));
    float translateY = (float) (distance * -Math.sin(angle));
    float scale = zoom;
    float rotate = rotation;
    float maxDistance = distance + Math.abs(rotation * imageRadius) + zoom * imageRadius;
    int steps = log2((int) maxDistance);

    translateX /= maxDistance;
    translateY /= maxDistance;
    scale /= maxDistance;
    rotate /= maxDistance;

    if (steps == 0) {
      Graphics2D g = dst.createGraphics();
      g.drawRenderedImage(src, null);
      g.dispose();
      return dst;
    }

    BufferedImage tmp = createCompatibleDestImage(src, null);
    for (int i = 0; i < steps; i++) {
      Graphics2D g = tmp.createGraphics();
      g.drawImage(tsrc, null, null);
      g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      g.setRenderingHint(
          RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
      g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));

      g.translate(cx + translateX, cy + translateY);
      g.scale(
          1.0001 + scale,
          1.0001
              + scale); // The .0001 works round a bug on Windows where drawImage throws an
                        // ArrayIndexOutofBoundException
      if (rotation != 0) g.rotate(rotate);
      g.translate(-cx, -cy);

      g.drawImage(dst, null, null);
      g.dispose();
      BufferedImage ti = dst;
      dst = tmp;
      tmp = ti;
      tsrc = dst;

      translateX *= 2;
      translateY *= 2;
      scale *= 2;
      rotate *= 2;
    }
    return dst;
  }
  /**
   * Draws the label.
   *
   * @param g2 the graphics context
   */
  private void drawLabel(Graphics2D g2) {
    Rectangle2D labelBounds = getLabelBounds();
    double x = labelBounds.getX();
    double y = labelBounds.getY();

    g2.translate(x, y);
    label.paint(g2);
    g2.translate(-x, -y);
  }
Esempio n. 28
0
  @Override
  public void paintComponent(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    // obtengo el alto y el ancho de la pantalla
    width = getWidth();
    height = getHeight();
    diameter = Math.min(width, height);
    centreX = width / 2;
    centreY = diameter / 2;
    diameterCircleMax = ((diameter * 8) / 10);
    g2.setColor(Color.WHITE);
    g2.fillRect(0, 0, (int) width, (int) height);
    // we traslate the origin to the centre
    g2.translate(centreX, centreY);
    g2.setColor(Color.getHSBColor((float) 0.001, (float) 0.001, (float) 0.4));
    g2.fillOval(
        (int) (-diameterCircleMax) / 2,
        (int) (-diameterCircleMax) / 2,
        (int) diameterCircleMax,
        (int) diameterCircleMax);
    g2.setColor(Color.BLACK);
    // we define a width for the lines
    g2.setStroke(new BasicStroke(5));
    // we draw a circle
    g2.drawOval(
        (int) (-diameterCircleMax) / 2,
        (int) (-diameterCircleMax) / 2,
        (int) diameterCircleMax,
        (int) diameterCircleMax);

    //        g2.setColor(Color.WHITE);
    //        g2.fillOval((int)(-diameter*9)/20, (int)(-diameter*9)/20, (int)(diameter*9)/10,
    // (int)(diameter*9)/10);
    //        g2.setColor(Color.BLACK);

    // we draw a little circle
    if (activate) {
      // return the centre of the circle
      g2.translate(-width / 2, -diameter / 2);
      g2.translate((int) positionX, (int) positionY);
      //        g2.setColor(Color.WHITE);
      //        g2.fillOval((int)(-diameter)/2, (int)(-diameter)/2, (int)(diameter),
      // (int)(diameter));
      //        g2.setColor(Color.BLACK);
    }
    g2.setStroke(new BasicStroke(1));
    g2.setColor(Color.getHSBColor((float) 0.001, (float) 0.001, (float) 0.3));
    g2.fillOval(
        (int) (-diameter) / 12, (int) (-diameter) / 12, (int) (diameter) / 6, (int) (diameter) / 6);
    g2.setColor(Color.getHSBColor((float) 0.001, (float) 0.001, (float) 0.1));
    g2.fillOval(
        (int) (-diameter) / 20,
        (int) (-diameter) / 20,
        (int) (diameter) / 10,
        (int) (diameter) / 10);
  }
Esempio n. 29
0
  public static void generateColorMap(
      Location[] locs,
      Double[] vals,
      Graphics2D destination,
      double width,
      double height,
      int alpha,
      ColorMap colorMap) {
    generateInterpolatedColorMap(locs, vals, destination, width, height, alpha, colorMap);
    Point2D[] points = new Point2D[locs.length];

    double minLong = -locs[0].getAbsoluteLongitudeDouble();
    double maxLat = locs[0].getAbsoluteLatitudeDouble();

    for (int i = 0; i < locs.length; i++) {
      if (-locs[i].getAbsoluteLongitudeDouble() < minLong)
        minLong = -locs[i].getAbsoluteLongitudeDouble();
      if (locs[i].getAbsoluteLatitudeDouble() > maxLat)
        maxLat = locs[i].getAbsoluteLatitudeDouble();
    }

    Location topCorner = new Location(maxLat, minLong);

    double[] of = locs[0].getNEDOffsetFrom(topCorner);
    double minX = of[1];
    double minY = -of[0];
    double maxX = of[1];
    double maxY = -of[0];

    for (int i = 0; i < locs.length; i++) {
      double[] offsets = locs[i].getNEDOffsetFrom(topCorner);
      points[i] = new Point2D.Double(offsets[1], -offsets[0]);

      if (-offsets[0] > maxY) maxY = -offsets[0];
      if (offsets[1] > maxX) maxX = offsets[1];
      if (-offsets[0] < minY) minY = -offsets[0];
      if (offsets[1] < minX) minX = offsets[1];
    }

    Graphics2D g = destination;

    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g.setColor(Color.black);

    double scaleX = width / (maxX - minX);
    double scaleY = height / (maxY - minY);
    for (int i = 0; i < points.length; i++) {
      double dx = (points[i].getX() - minX) * scaleX;
      double dy = (points[i].getY() - minY) * scaleY;
      g.translate(dx, dy);
      g.drawLine(-3, -3, 3, 3);
      g.drawLine(-3, 3, 3, -3);
      g.drawString("" + vals[i], 10, 10);
      g.translate(-dx, -dy);
    }
  }
Esempio n. 30
0
  @Override
  public void paint(Graphics g, JComponent c) {
    JButton button = (JButton) c;
    String text = button.getText();
    Icon icon = (button.isEnabled()) ? button.getIcon() : button.getDisabledIcon();

    if ((icon == null) && (text == null)) {
      return;
    }

    FontMetrics fm = g.getFontMetrics();
    paintViewInsets = c.getInsets(paintViewInsets);

    paintViewR.x = paintViewInsets.left;
    paintViewR.y = paintViewInsets.top;

    // Use inverted height &amp; width
    paintViewR.height = c.getWidth() - (paintViewInsets.left + paintViewInsets.right);
    paintViewR.width = c.getHeight() - (paintViewInsets.top + paintViewInsets.bottom);

    paintIconR.x = paintIconR.y = paintIconR.width = paintIconR.height = 0;
    paintTextR.x = paintTextR.y = paintTextR.width = paintTextR.height = 0;

    Graphics2D g2 = (Graphics2D) g;
    AffineTransform tr = g2.getTransform();

    if (angle == 90) {
      g2.rotate(Math.PI / 2);
      g2.translate(0, -c.getWidth());
      paintViewR.x = c.getHeight() / 2 - (int) fm.getStringBounds(text, g).getWidth() / 2;
      paintViewR.y = c.getWidth() / 2 - (int) fm.getStringBounds(text, g).getHeight() / 2;
    } else if (angle == 270) {
      g2.rotate(-Math.PI / 2);
      g2.translate(-c.getHeight(), 0);
      paintViewR.x = c.getHeight() / 2 - (int) fm.getStringBounds(text, g).getWidth() / 2;
      paintViewR.y = c.getWidth() / 2 - (int) fm.getStringBounds(text, g).getHeight() / 2;
    }

    if (icon != null) {
      icon.paintIcon(c, g, paintIconR.x, paintIconR.y);
    }

    if (text != null) {
      int textX = paintTextR.x;
      int textY = paintTextR.y + fm.getAscent();

      if (button.isEnabled()) {
        paintText(g, c, new Rectangle(paintViewR.x, paintViewR.y, textX, textY), text);
      } else {
        paintText(g, c, new Rectangle(paintViewR.x, paintViewR.y, textX, textY), text);
      }
    }

    g2.setTransform(tr);
  }