Package java.awt

Examples of java.awt.Graphics2D


     */
    public ImageIcon createArrowIcon(BasicStroke stroke, int width, int height,
                                     int arrowHeadType) {

        BufferedImage bigImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
        Graphics2D g = (Graphics2D) bigImage.getGraphics();

        int middleY = height / 2;

        g.setBackground(OMColor.clear);
        g.setPaint(OMColor.clear);
        g.fillRect(0, 0, width, height);
        g.setPaint(Color.black);
        g.setStroke(stroke);
        g.drawLine(0, middleY, width, middleY);

        int upTip = (int) ((float) height * .25);
        int downTip = (int) ((float) height * .75);
        Polygon poly = null;
        if (arrowHeadType == OMArrowHead.ARROWHEAD_DIRECTION_FORWARD
                || arrowHeadType == OMArrowHead.ARROWHEAD_DIRECTION_BOTH) {
            int rightWingX = (int) ((float) width * .75);
            poly = new Polygon(new int[] { width, rightWingX, rightWingX }, new int[] {
                    middleY, upTip, downTip }, 3);
            g.fill(poly);
            g.draw(poly); // Seems to help with rendering problem.
        }

        if (arrowHeadType == OMArrowHead.ARROWHEAD_DIRECTION_BACKWARD
                || arrowHeadType == OMArrowHead.ARROWHEAD_DIRECTION_BOTH) {
            int leftWingX = (int) ((float) width * .25);
            poly = new Polygon(new int[] { 0, leftWingX, leftWingX }, new int[] {
                    middleY, upTip, downTip }, 3);
            g.fill(poly);
            g.draw(poly); // Seems to help with rendering problem.
        }

        return new ImageIcon(bigImage);
    }
View Full Code Here


                    w,
                    h,
                    imageType);
        } else {
            BufferedImage bufferedImage = new BufferedImage(w, h, imageType);
            Graphics2D g2d = bufferedImage.createGraphics();
            g2d.drawImage(image, x, y, null);
            g2d.dispose();
            return bufferedImage;
        }
    }
View Full Code Here

     */
    public static ImageIcon createIcon(BasicStroke stroke, int width,
                                       int height, boolean horizontalOrientation) {

        BufferedImage bigImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
        Graphics2D g = (Graphics2D) bigImage.getGraphics();

        g.setBackground(OMColor.clear);
        g.setPaint(OMColor.clear);
        g.fillRect(0, 0, width, height);
        g.setPaint(Color.black);
        g.setStroke(stroke);
        if (horizontalOrientation) {
            g.drawLine(0, height / 2, width, height / 2);
        } else {
            g.drawLine(width / 2, 0, width / 2, height);
        }

        return new ImageIcon(bigImage);
    }
View Full Code Here

     */
    public static ImageIcon createIcon(BasicStroke stroke, int width,
                                       int height, boolean horizontalOrientation) {

        BufferedImage bigImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
        Graphics2D g = (Graphics2D) bigImage.getGraphics();

        g.setBackground(OMColor.clear);
        g.setPaint(OMColor.clear);
        g.fillRect(0, 0, width, height);
        g.setPaint(Color.black);
        g.setStroke(stroke);
        if (horizontalOrientation) {
            g.drawLine(0, height / 2, width, height / 2);
        } else {
            g.drawLine(width / 2, 0, width / 2, height);
        }

        return new ImageIcon(bigImage);
    }
View Full Code Here

    public static ImageIcon createColorIcon(BasicStroke stroke, int width,
                                       int height, boolean horizontalOrientation,
                                       Color color, Color background, Color matting) {

      BufferedImage bigImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
      Graphics2D g = (Graphics2D) bigImage.getGraphics();
     
      g.setBackground(OMColor.clear);
      g.setPaint(OMColor.clear);
      g.fillRect(0, 0, width, height);
     
      g.setPaint(background);
      g.fillRect(0, 0, width, height);
      if (matting != null) {
        BasicStroke mattedStroke=new BasicStroke(((BasicStroke) stroke).getLineWidth() + 2f);
        g.setStroke(mattedStroke);
        g.setPaint(matting);
        g.drawLine(0,height/2,width,height/2);
      }
        g.setPaint(color);
        g.setStroke(stroke);
        if (horizontalOrientation) {
            g.drawLine(0, height / 2, width, height / 2);
        } else {
            g.drawLine(width / 2, 0, width / 2, height);
        }
        return new ImageIcon(bigImage);
    }
View Full Code Here

                    }
                }
            }

            BufferedImage bi = new BufferedImage(8, 8, BufferedImage.TYPE_INT_ARGB);
            Graphics2D big = bi.createGraphics();
            big.setColor(new Color(0, true)); // clear
            big.fillRect(0, 0, 8, 8);
            big.setPaint(fillPaint);

            if (fillPatternString.equalsIgnoreCase(LPC_HORIZONTAL_PATTERN)) {
                big.draw(new Line2D.Double(0, 0, 7, 0));
                big.draw(new Line2D.Double(0, 4, 7, 4));
            } else if (fillPatternString.equalsIgnoreCase(LPC_VERTICAL_PATTERN)) {
                big.draw(new Line2D.Double(0, 0, 0, 7));
                big.draw(new Line2D.Double(4, 0, 4, 7));
            } else if (fillPatternString.equalsIgnoreCase(LPC_CROSS_PATTERN)) {
                big.draw(new Line2D.Double(0, 0, 7, 0));
                big.draw(new Line2D.Double(0, 4, 7, 4));
                big.draw(new Line2D.Double(0, 0, 0, 7));
                big.draw(new Line2D.Double(4, 0, 4, 7));
            } else if (fillPatternString.equalsIgnoreCase(LPC_DIAG_CROSS_PATTERN)) {
                big.draw(new Line2D.Double(0, 0, 7, 7));
                big.draw(new Line2D.Double(0, 4, 3, 7));
                big.draw(new Line2D.Double(4, 0, 7, 3));
                big.draw(new Line2D.Double(0, 7, 7, 0));
                big.draw(new Line2D.Double(0, 3, 3, 0));
                big.draw(new Line2D.Double(4, 7, 7, 4));
            } else if (fillPatternString.equalsIgnoreCase(LPC_BACKWARD_DIAG_PATTERN)) {
                big.draw(new Line2D.Double(0, 0, 7, 7));
                big.draw(new Line2D.Double(0, 4, 3, 7));
                big.draw(new Line2D.Double(4, 0, 7, 3));
            } else if (fillPatternString.equalsIgnoreCase(LPC_FORWARD_DIAG_PATTERN)) {
                big.draw(new Line2D.Double(0, 7, 7, 0));
                big.draw(new Line2D.Double(0, 3, 3, 0));
                big.draw(new Line2D.Double(4, 7, 7, 4));
            } else {
                // default to solid
                big.fillRect(0, 0, 8, 8);
            }

            Rectangle r = new Rectangle(0, 0, 8, 8);
            TexturePaint texturePaint = new TexturePaint(bi, r);
View Full Code Here

     * @param width icon pixel width
     * @param height icon pixel height
     */
    public static ImageIcon getPaletteIcon(Paint paint, int width, int height) {
        BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        Graphics2D graphics = (Graphics2D) bufferedImage.getGraphics();
        graphics.setPaint(paint);
        graphics.fillRect(0, 0, width, height);

        return new ImageIcon(bufferedImage);
    }
View Full Code Here

                                                     int width,
                                                     int height,
                                                     boolean horizontalOrientation) {

        BufferedImage bigImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
        Graphics2D g = (Graphics2D) bigImage.getGraphics();

        g.setBackground(OMColor.clear);

        if (attributes.enableFillPaintChoice) {
            g.setPaint(attributes.fillPaint);
            g.fillRect(0, 0, width, height);
        }

        if (attributes.matted) {
            BasicStroke mattedStroke = new BasicStroke(((BasicStroke) attributes.stroke).getLineWidth() + 2f);
            g.setStroke(mattedStroke);
            g.setPaint(attributes.mattingPaint);
            g.drawLine(0, height / 2, width, height / 2);
        }

        g.setPaint(attributes.linePaint);
        g.setStroke(attributes.stroke);
        if (horizontalOrientation) {
            g.drawLine(0 + 3, height / 2, width - 3, height / 2);
        } else {
            g.drawLine(width / 2, 0 + 3, width / 2, height - 3);
        }

        return new ImageIcon(bigImage);
    }
View Full Code Here

            if (h > height) {
                h /= 2;
                if (h < height) h = height;
            }
            BufferedImage tmp = new BufferedImage(w, h, type);
            Graphics2D g2 = tmp.createGraphics();
            g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
            g2.drawImage(ret, 0, 0, w, h, null);
            g2.dispose();
            ret = tmp;
        }
        return ret;
    }
View Full Code Here

    final double width = bounds.getWidth();
    final double height = bounds.getHeight();

    final Shape scaledShape = ShapeTransform.transformShape
        (shape, scale, keepAspectRatio, width, height);
    final Graphics2D clone = (Graphics2D) g2.create();
    final double extraPadding;
    if (layoutContext != null)
    {
      final Object o = layoutContext.getStyleProperty(ElementStyleKeys.STROKE);
      if (o instanceof BasicStroke)
      {
        final BasicStroke stroke = (BasicStroke) o;
        extraPadding = stroke.getLineWidth() / 2.0;
      }
      else
      {
        extraPadding = 0.5;
      }
    }
    else
    {
      extraPadding = 0.5;
    }

    final Rectangle2D.Double drawAreaBounds = new Rectangle2D.Double
        (x - extraPadding, y - extraPadding, width + 2 * extraPadding, height + 2 * extraPadding);

    clone.clip(drawAreaBounds);
    clone.translate(x, y);
    if (shouldFill)
    {
      configureFillColor(layoutContext, clone);
      clone.fill(scaledShape);
    }
    if (shouldDraw)
    {
      configureGraphics(layoutContext, clone);
      clone.draw(scaledShape);
    }
    clone.dispose();
  }
View Full Code Here

TOP

Related Classes of java.awt.Graphics2D

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.