Java 类java.awt.Graphics2D 实例源码

项目:sbc-qsystem    文件:FCallDialog.java   
private Image resizeToBig(Image originalImage, int biggerWidth, int biggerHeight) {
    final BufferedImage resizedImage = new BufferedImage(biggerWidth, biggerHeight,
        BufferedImage.TYPE_INT_ARGB);
    final Graphics2D g = resizedImage.createGraphics();

    g.setComposite(AlphaComposite.Src);
    g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
        RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    g.drawImage(originalImage, 0, 0, biggerWidth, biggerHeight, this);
    g.dispose();

    return resizedImage;
}
项目:parabuild-ci    文件:XYPlot.java   
/**
 * Utility method for drawing a vertical line on the data area of the plot.
 *
 * @param g2  the graphics device.
 * @param dataArea  the data area.
 * @param value  the coordinate, where to draw the line.
 * @param stroke  the stroke to use.
 * @param paint  the paint to use.
 */
protected void drawVerticalLine(Graphics2D g2, Rectangle2D dataArea,
                                double value, Stroke stroke, Paint paint) {

    ValueAxis axis = getDomainAxis();
    if (getOrientation() == PlotOrientation.HORIZONTAL) {
        axis = getRangeAxis();
    }
    if (axis.getRange().contains(value)) {
        double xx = axis.valueToJava2D(value, dataArea, 
                RectangleEdge.BOTTOM);
        Line2D line = new Line2D.Double(xx, dataArea.getMinY(), xx, 
                dataArea.getMaxY());
        g2.setStroke(stroke);
        g2.setPaint(paint);
        g2.draw(line);
    }

}
项目:spacesettlers    文件:FlagGraphics.java   
@Override
public void draw(Graphics2D graphics) {
    graphics.setStroke(JSpaceSettlersComponent.THIN_STROKE);

       final AffineTransform transform =
               AffineTransform.getTranslateInstance(drawLocation.getX(), drawLocation.getY());
       transform.rotate(-Math.PI / 2.0);

    transform.scale(scale, scale);

       Shape newFlagShape = transform.createTransformedShape(FLAG_SHAPE);

       // color the flag to match the team
       graphics.setPaint(flagColor);
       graphics.fill(newFlagShape);
}
项目:openjdk-jdk10    文件:PathGraphics.java   
protected PathGraphics(Graphics2D graphics, PrinterJob printerJob,
                       Printable painter, PageFormat pageFormat,
                       int pageIndex, boolean canRedraw) {
    super(graphics, printerJob);

    mPainter = painter;
    mPageFormat = pageFormat;
    mPageIndex = pageIndex;
    mCanRedraw = canRedraw;
}
项目:brModelo    文件:baseDrawerItem.java   
private void medidaH(Graphics2D g, int l, int t) {
    FontMetrics fm = g.getFontMetrics();
    String vl = dono.FormateUnidadeMedida(width);
    int xini = l;
    int pre_y = t;
    int xfim = l + width;
    int yfim = t + height / 2;

    int traco = height;
    int ytraco = pre_y;// - (traco/2);

    g.drawLine(xini, ytraco, xini, ytraco + traco);
    g.drawLine(xfim, ytraco, xfim, ytraco + traco);
    g.drawLine(xini, yfim, xfim, yfim);

    xini = xini + (width - fm.stringWidth(vl)) / 2;
    int yini = invertido ? yfim + (fm.getHeight() - fm.getDescent()) : yfim - fm.getDescent();// yfim + (fm.getHeight()) / 2 - fm.getDescent();
    g.drawString(vl, xini, yini);
}
项目:defense-solutions-proofs-of-concept    文件:RotatableImagePanel.java   
@Override
protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2d = (Graphics2D) g;
    AffineTransform origXform = g2d.getTransform();
    AffineTransform newXform = (AffineTransform) (origXform.clone());
    //center of rotation is center of the panel
    int xRot = this.getWidth() / 2;
    int yRot = this.getHeight() / 2;
    newXform.rotate((2 * Math.PI) - currentAngle, xRot, yRot);
    g2d.setTransform(newXform);
    //draw image centered in panel
    int x = (getWidth() - image.getWidth(this)) / 2;
    int y = (getHeight() - image.getHeight(this)) / 2;
    g2d.drawImage(image, x, y, this);
    g2d.setTransform(origXform);
}
项目:jdk8u-jdk    文件:GraphicsTests.java   
public void init(Graphics2D g2d, Context ctx, Dimension dim) {
    int w = dim.width;
    int h = dim.height;
    double theta = Math.toRadians(15);
    double cos = Math.cos(theta);
    double sin = Math.sin(theta);
    double xsize = sin * h + cos * w;
    double ysize = sin * w + cos * h;
    double scale = Math.min(w / xsize, h / ysize);
    xsize *= scale;
    ysize *= scale;
    AffineTransform at = new AffineTransform();
    at.translate((w - xsize) / 2.0, (h - ysize) / 2.0);
    at.translate(sin * h * scale, 0.0);
    at.rotate(theta);
    g2d.transform(at);
    dim.setSize(scaleForTransform(at, dim));
}
项目:parabuild-ci    文件:SimpleDialFrame.java   
/**
 * Draws the frame.  This method is called by the {@link DialPlot} class,
 * you shouldn't need to call it directly.
 *
 * @param g2  the graphics target (<code>null</code> not permitted).
 * @param plot  the plot (<code>null</code> not permitted).
 * @param frame  the frame (<code>null</code> not permitted).
 * @param view  the view (<code>null</code> not permitted).
 */
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, 
        Rectangle2D view) {

    Shape window = getWindow(frame);

    Rectangle2D f = DialPlot.rectangleByRadius(frame, this.radius + 0.02, 
            this.radius + 0.02);
    Ellipse2D e = new Ellipse2D.Double(f.getX(), f.getY(), f.getWidth(), 
            f.getHeight());

    Area area = new Area(e);
    Area area2 = new Area(window);
    area.subtract(area2);
    g2.setPaint(this.backgroundPaint);
    g2.fill(area);

    g2.setStroke(this.stroke);
    g2.setPaint(this.foregroundPaint);
    g2.draw(window);
    g2.draw(e);
}
项目:parabuild-ci    文件:TextTitle.java   
/**
 * Returns the preferred width of the title.  This will only be called when the title
 * is being drawn at the left or right of a chart.
 *
 * @param g2  the graphics device.
 * @param height  the height.
 *
 * @return The preferred width of the title.
 */
public float getPreferredWidth(Graphics2D g2, float height) {
    float result = 0.0f;
    if (this.text != null && !this.text.equals("")) {
        g2.setFont(this.font);
        TextBlock title = TextUtilities.createTextBlock(
            this.text, this.font, this.paint, height, new G2TextMeasurer(g2)
        );
        Size2D d = title.calculateDimensions(g2);
        result = (float) getSpacer().getAdjustedWidth(d.getHeight());
                                                 // use height here because the title
                                                 // is displayed rotated
    }
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Title preferred width = " + result);   
    }
    return result;
}
项目:rapidminer    文件:GenericArrowButton.java   
private void paintEastArrow(Graphics2D g2, int w, int h, boolean isPressed, boolean isRollover) {
    g2.setColor(Colors.SCROLLBAR_ARROW_BORDER);
    g2.drawLine(0, 0, w - 1, 0);

    if (isPressed) {
        g2.setColor(Colors.SCROLLBAR_ARROW_PRESSED);
    } else if (isRollover) {
        g2.setColor(Colors.SCROLLBAR_ARROW_ROLLOVER);
    } else {
        g2.setColor(Colors.SCROLLBAR_ARROW);
    }

    g2.setStroke(ARROW_STROKE);
    g2.drawLine(6, OFFSET, w - 6, h / 2);
    g2.drawLine(w - 6, h / 2, 6, h - OFFSET);
}
项目:openjdk-jdk10    文件:IndexingTest.java   
protected static BufferedImage createComponentImage(int w, int h,
                                                    ComponentColorModel cm)
{
    WritableRaster wr = cm.createCompatibleWritableRaster(w, h);

    BufferedImage img = new BufferedImage(cm, wr, false, null);
    Graphics2D g = img.createGraphics();
    int width = w / 8;
    Color[] colors = new Color[8];
    colors[0] = Color.red;
    colors[1] = Color.green;
    colors[2] = Color.blue;
    colors[3] = Color.white;
    colors[4] = Color.black;
    colors[5] = new Color(0x80, 0x80, 0x80, 0x00);
    colors[6] = Color.yellow;
    colors[7] = Color.cyan;

    for (int i = 0; i < 8; i++) {
        g.setColor(colors[i]);
        g.fillRect(i * width, 0, width, h);
    }
    return img;
}
项目:jaer    文件:LabyrinthTableTiltControllerGUI.java   
@Override
public void paint(Graphics g) {
    final int r = 6;
    super.paint(g);

    // paint cross hairs to show center
    Graphics2D g2 = (Graphics2D) calibrationPanel.getGraphics();
    int w = calibrationPanel.getWidth(), h = calibrationPanel.getHeight();
    g2.setColor(Color.gray);
    g2.drawLine(w / 2, 0, w / 2, h);
    g2.drawLine(0, h / 2, w, h / 2);
    g2.setColor(Color.red) ;
    float x=w/2+w/2*currentPanTiltRad.x/controller.getTiltLimitRad();
    float y=h/2+h/2*(-currentPanTiltRad.y/controller.getTiltLimitRad());
    final int s=20;
    g2.drawOval((int)x-s/2, (int)y-s/2, s, s);

    trajectory.paint();
}
项目:geomapapp    文件:PoleMapServer.java   
private static BufferedImage drawTileName(BufferedImage image, String name) {
    BufferedImage i2 = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = i2.createGraphics();
    g2.drawImage(image, null, 0, 0);
    g2.setColor(Color.red);
    g2.setStroke(new BasicStroke(4));
    g2.drawRect(8, 8, image.getWidth() - 8, image.getHeight() - 8);

    g2.setColor(Color.RED);
    g2.setFont(g2.getFont().deriveFont(Font.BOLD).deriveFont(13f));
    FontMetrics fm = g2.getFontMetrics();
    String[] parts = name.split("/");
    for (int i = 0; i < parts.length; i++) {
        String s = i == parts.length - 1 ? parts[i] : parts[i] + "/"; 
        int x = 40 + i * 5;
        int y = 40 + i * (fm.getHeight() + 5);
        Rectangle2D rect = fm.getStringBounds(s, g2);
        g2.setColor(Color.white);
        g2.fillRect(x, y - fm.getAscent(), (int)rect.getWidth(), fm.getHeight());
        g2.setColor(Color.red);
        g2.drawString(s, x, y);
    }
    return i2;
}
项目:jdk8u-jdk    文件:DrawRotatedStringUsingRotatedFont.java   
/**
 * Creates an BufferedImage and draws a text, using two transformations,
 * one for graphics and one for font.
 */
private static BufferedImage createImage(final boolean aa,
                                         final AffineTransform gtx,
                                         final AffineTransform ftx) {
    final BufferedImage bi = new BufferedImage(SIZE, SIZE, TYPE_INT_RGB);
    final Graphics2D bg = bi.createGraphics();
    bg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                        aa ? RenderingHints.VALUE_ANTIALIAS_ON
                           : RenderingHints.VALUE_ANTIALIAS_OFF);
    bg.setColor(Color.RED);
    bg.fillRect(0, 0, SIZE, SIZE);
    bg.translate(100, 100);
    bg.transform(gtx);
    bg.setColor(Color.BLACK);
    bg.setFont(bg.getFont().deriveFont(20.0f).deriveFont(ftx));
    bg.drawString(STR, 0, 0);
    bg.dispose();
    return bi;
}
项目:Jupiter    文件:Player.java   
public BufferedImage createMap(ItemMap mapItem) {
    new ArrayList<>();
    List<BaseFullChunk> chunks = new ArrayList<>();
    Color[][] blockColors = new Color[16][16];
    BufferedImage img = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2 = (Graphics2D)img.getGraphics();

    chunks.add(this.level.getChunk((int) this.x >> 4, (int) this.z >> 4, false));
    for(int x=0;x < 16;x++){
        for( int y=0;y < 16;y++){
            blockColors[x][y] = Block.get(chunks.get(0).getHighestBlockAt((int)this.x, (int)this.z)).getColor();
            g2.drawImage(img, x, y, blockColors[x][y], null);
        }
    }

    BufferedImage data = new BufferedImage(256, 256, BufferedImage.TYPE_INT_ARGB);
    data.createGraphics().drawImage(img, 0, 0, null);
    return data;
}
项目:Panako    文件:FrequencyAxisLayer.java   
public void draw(Graphics2D graphics){

    //draw legend
    graphics.setColor(Color.black);
    int minX = Math.round(cs.getMin(Axis.X));
    int maxY = Math.round(cs.getMax(Axis.Y));

    int wideMarkWidth = Math.round(LayerUtilities.pixelsToUnits(graphics,8, true));
    int smallMarkWidth = Math.round(LayerUtilities.pixelsToUnits(graphics,4, true));
    int textOffset = Math.round(LayerUtilities.pixelsToUnits(graphics,12, true));   
    int textLabelOffset = Math.round(LayerUtilities.pixelsToUnits(graphics,12, false));

    //Every 100 and 1200 cents
    for(int i = (int) cs.getMin(Axis.Y) ; i < cs.getMax(Axis.Y) ; i++){
        if(i%1200 == 0){
            graphics.drawLine(minX, i, minX+wideMarkWidth,i);
            String text = String.valueOf(i);                
            LayerUtilities.drawString(graphics,text,minX+textOffset,i,false,true,null);
        } else if(i%100 == 0){          
            graphics.drawLine(minX, i, minX+smallMarkWidth,i);
        }
    }

    LayerUtilities.drawString(graphics,"Frequency (cents)",minX+textOffset,maxY-textLabelOffset,false,true,Color.white);
}
项目:brModelo    文件:PreCardinalidade.java   
@Override
public void DoPaint(Graphics2D g) {
    if (!isVisible()) {
        return;
    }
    if (TamanhoAutmatico) {
        int tamLetra =  g.getFontMetrics(getFont()).stringWidth("M");
        int largura = g.getFontMetrics(getFont()).stringWidth(FullCard()) + tamLetra;//+ distSelecao * 2;
        int altura = g.getFontMetrics(getFont()).getHeight();
        if (getWidth() != largura || getHeight() != altura) {
            setStopRaize(true);
            setWidth(largura);
            setHeight(altura);
            setStopRaize(false);
            Posicione();
            if (isSelecionado()) Reposicione();
        }
    }
    super.DoPaint(g);
}
项目:parabuild-ci    文件:WaferMapPlot.java   
/**
 * Draws the wafermap view.
 * 
 * @param g2  the graphics device.
 * @param area  the plot area.
 * @param anchor  the anchor point (<code>null</code> permitted).
 * @param state  the plot state.
 * @param info  the plot rendering info.
 */
public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor,
                 PlotState state, 
                 PlotRenderingInfo info) {

    // if the plot area is too small, just return...
    boolean b1 = (area.getWidth() <= MINIMUM_WIDTH_TO_DRAW);
    boolean b2 = (area.getHeight() <= MINIMUM_HEIGHT_TO_DRAW);
    if (b1 || b2) {
        return;
    }

    // record the plot area...
    if (info != null) {
        info.setPlotArea(area);
    }

    // adjust the drawing area for the plot insets (if any)...
    RectangleInsets insets = getInsets();
    insets.trim(area);

    drawChipGrid(g2, area);       
    drawWaferEdge(g2, area);

}
项目:OpenJSharp    文件:ShapeGraphicAttribute.java   
/**
 * {@inheritDoc}
 */
public void draw(Graphics2D graphics, float x, float y) {

    // translating graphics to draw Shape !!!
    graphics.translate((int)x, (int)y);

    try {
        if (fStroke == STROKE) {
            // REMIND: set stroke to correct size
            graphics.draw(fShape);
        }
        else {
            graphics.fill(fShape);
        }
    }
    finally {
        graphics.translate(-(int)x, -(int)y);
    }
}
项目:parabuild-ci    文件:MarkerAxisBand.java   
/**
 * A utility method that draws a string inside a rectangle.
 *
 * @param g2  the graphics device.
 * @param bounds  the rectangle.
 * @param font  the font.
 * @param text  the text.
 */
private void drawStringInRect(Graphics2D g2, Rectangle2D bounds, Font font,
                              String text) {

    g2.setFont(font);
    FontMetrics fm = g2.getFontMetrics(font);
    Rectangle2D r = TextUtilities.getTextBounds(text, g2, fm);
    double x = bounds.getX();
    if (r.getWidth() < bounds.getWidth()) {
        x = x + (bounds.getWidth() - r.getWidth()) / 2;
    }
    LineMetrics metrics = font.getLineMetrics(text, g2.getFontRenderContext());
    g2.drawString(
        text, 
        (float) x, (float) (bounds.getMaxY() - this.bottomInnerGap - metrics.getDescent())
    );
}
项目:Mujeed-Arabic-Prolog    文件:AquaBarTabbedPaneUI.java   
protected void paintTabBackground(Graphics g, int tabPlacement,
        int tabIndex, int x, int y, int w, int h, boolean isSelected) {
    Graphics2D g2d = (Graphics2D) g;
    ColorSet colorSet;

    Rectangle rect = rects[tabIndex];

    if (isSelected) {
        colorSet = selectedColorSet;
    } else if (getRolloverTab() == tabIndex) {
        colorSet = hoverColorSet;
    } else {
        colorSet = defaultColorSet;
    }

    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_ON);

    int width = rect.width;
    int xpos = rect.x;
    if (tabIndex > 0) {
        width--;
        xpos++;
    }

    g2d.setPaint(new GradientPaint(xpos, 0, colorSet.topGradColor1, xpos,
            10, colorSet.topGradColor2));
    g2d.fillRect(xpos, 0, width, 10);

    g2d.setPaint(new GradientPaint(0, 10, colorSet.bottomGradColor1, 0, 21,
            colorSet.bottomGradColor2));
    g2d.fillRect(xpos, 10, width, 11);

    if (contentTopBorderDrawn) {
        g2d.setColor(lineColor);
        g2d.drawLine(rect.x, 20, rect.x + rect.width - 1, 20);
    }
}
项目:openjdk-jdk10    文件:AltTabCrashTest.java   
public void paint(Graphics g, Color c) {
    if (c == null) {
        Graphics2D g2d = (Graphics2D)g.create();
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                             RenderingHints.VALUE_ANTIALIAS_ON);
        g2d.setColor(color);
        g2d.fillOval(x, y, diameter, diameter);
    } else {
        g.setColor(c);
        g.fillOval(x-2, y-2, diameter+4, diameter+4);
    }
}
项目:What-Happened-to-Station-7    文件:CompoundAnimation.java   
@Override
public void drawOverGUI(Graphics2D g, int s)
{
    for (Animation a : this)
        if (a.stillGoing())
            a.drawOverGUI(g, s);
}
项目:parabuild-ci    文件:MeterNeedle.java   
/**
 * Draws the needle.
 *
 * @param g2  the graphics device.
 * @param plotArea  the plot area.
 * @param angle  the angle.
 */
public void draw(Graphics2D g2, Rectangle2D plotArea, double angle) {

    Point2D.Double pt = new Point2D.Double();
    pt.setLocation(
        plotArea.getMinX() + this.rotateX * plotArea.getWidth(),
        plotArea.getMinY() + this.rotateY * plotArea.getHeight()
    );
    draw(g2, plotArea, pt, angle);

}
项目:lemon    文件:CustomProcessDiagramGenerator.java   
/**
 * 绘制子流程
 */
protected static void drawSubProcess(int x, int y, int width, int height,
        Graphics2D graphics) {
    RoundRectangle2D rect = new RoundRectangle2D.Double(x + 1, y + 1,
            width - 2, height - 2, OFFSET_SUBPROCESS, OFFSET_SUBPROCESS);
    graphics.draw(rect);
}
项目:openjdk-jdk10    文件:GraphicComponent.java   
public void handleDraw(Graphics2D g2d, float x, float y) {

        for (int i=0; i < graphicCount; i++) {

            graphic.draw(g2d, x, y);
            x += graphicAdvance;
        }
    }
项目:VTerminal    文件:CharBoldShader.java   
@Override
public BufferedImage run(final @NonNull BufferedImage image, final @NonNull AsciiCharacter character) {
    if (character instanceof AsciiTile) {
        return image;
    }

    if (character.isForegroundAndBackgroundColorEqual()) {
        return image;
    }

    try {
        // Get the character image:
        final BufferedImage charImage = swapColor(image, character.getBackgroundColor(), new Color(0, 0, 0, 0));

        // Combine image and background
        final BufferedImage result = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB);
        final Graphics2D gc = (Graphics2D) result.getGraphics();

        gc.setColor(character.getBackgroundColor());
        gc.fillRect(0, 0, result.getWidth(), result.getHeight());
        gc.drawImage(charImage, 1, 0, null);
        gc.drawImage(charImage, 0, 0, null);
        gc.dispose();

        return result;
    } catch (final IllegalStateException e) {
        return image;
    }
}
项目:GIFKR    文件:BoolInterpolator.java   
@Override
public void paintButton(Graphics2D g, int width, int height) {
    g.setColor(new Color(255, 0, 0, 80));
    g.fillRect(0, height/2, width, height/2);
    g.setColor(new Color(0, 255, 0, 80));
    g.fillRect(0, 0, width, height/2);

    super.paintButton(g, width, height);
}
项目:jdk8u-jdk    文件:WPathGraphics.java   
/**
 * Creates a new <code>Graphics</code> object that is
 * a copy of this <code>Graphics</code> object.
 * @return     a new graphics context that is a copy of
 *                       this graphics context.
 * @since      JDK1.0
 */
@Override
public Graphics create() {

    return new WPathGraphics((Graphics2D) getDelegate().create(),
                             getPrinterJob(),
                             getPrintable(),
                             getPageFormat(),
                             getPageIndex(),
                             canDoRedraws());
}
项目:litiengine    文件:GameScreen.java   
@Override
public void render(final Graphics2D g) {
  if (Game.getEnvironment() != null) {
    Game.getEnvironment().render(g);
  }

  super.render(g);
}
项目:FreeCol    文件:ColopediaGameObjectTypePanel.java   
/**
 * Builds a subtree including all the given objects.
 *
 * @param root a {@code DefaultMutableTreeNode}
 * @param id The object identifier of the new branch node.
 * @param types a List of FreeColSpecObjectTypes
 */
public void addSubTrees(DefaultMutableTreeNode root, String id,
                        List<T> types) {
    String name = getName();
    ColopediaTreeItem cti = new ColopediaTreeItem(this, id, name, null);
    DefaultMutableTreeNode node = new DefaultMutableTreeNode(cti);
    int width = ImageLibrary.ICON_SIZE.width;
    int height = ImageLibrary.ICON_SIZE.height;
    for (FreeColSpecObjectType type : types) {
        Image image = (type instanceof GoodsType)
            ? ImageLibrary.getMiscImage("image.icon." + type.getId(),
                                        ImageLibrary.ICON_SIZE)
            : (type instanceof ResourceType)
            ? ImageLibrary.getMiscImage("image.tileitem." + type.getId(),
                                        ImageLibrary.ICON_SIZE)
            : (type instanceof Nation)
            ? ImageLibrary.getMiscIconImage(type, ImageLibrary.ICON_SIZE)
            : (type instanceof BuildableType)
            ? ImageLibrary.getBuildableImage((BuildableType)type,
                                             ImageLibrary.ICON_SIZE)
            : ImageLibrary.getMiscImage(ResourceManager.REPLACEMENT_IMAGE,
                                        ImageLibrary.ICON_SIZE);
        int x = (width - image.getWidth(null)) / 2;
        int y = (height - image.getHeight(null)) / 2;
        BufferedImage centeredImage
            = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
        Graphics2D g = centeredImage.createGraphics();
        g.drawImage(image, x, y, null);
        g.dispose();
        node.add(buildItem(type, new ImageIcon(centeredImage)));
    }
    root.add(node);
}
项目:bitcoin_wallet_recovery_tool    文件:Main.java   
private static void createQRImage(File qrFile, String qrCodeText, int size, String fileType)
        throws WriterException, IOException {
    // Create the ByteMatrix for the QR-Code that encodes the given String
    Hashtable hintMap = new Hashtable();
    hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
    QRCodeWriter qrCodeWriter = new QRCodeWriter();
    BitMatrix byteMatrix = qrCodeWriter.encode(qrCodeText, BarcodeFormat.QR_CODE, size, size, hintMap);
    // Make the BufferedImage that are to hold the QRCode
    int matrixWidth = byteMatrix.getWidth();
    BufferedImage image = new BufferedImage(matrixWidth, matrixWidth, BufferedImage.TYPE_INT_RGB);
    image.createGraphics();

    Graphics2D graphics = (Graphics2D) image.getGraphics();
    graphics.setColor(Color.WHITE);
    graphics.fillRect(0, 0, matrixWidth, matrixWidth);
    // Paint and save the image using the ByteMatrix
    graphics.setColor(Color.BLACK);

    for (int i = 0; i < matrixWidth; i++) {
        for (int j = 0; j < matrixWidth; j++) {
            if (byteMatrix.get(i, j)) {
                graphics.fillRect(i, j, 1, 1);
            }
        }
    }
    ImageIO.write(image, fileType, qrFile);
}
项目:monarch    文件:LifelineState.java   
public void highlight(Graphics2D g) {
  Rectangle bounds = g.getClipBounds();
  if (startY > bounds.getMaxY() || startY + height < bounds.getMinY()) {
    return;
  }

  int x = line.getX();
  int width = line.getWidth();

  g.drawRoundRect(x, startY, width, height, ARC_SIZE, ARC_SIZE);
}
项目:jdk8u-jdk    文件:LineBorder.java   
/**
 * Paints the border for the specified component with the
 * specified position and size.
 * @param c the component for which this border is being painted
 * @param g the paint graphics
 * @param x the x position of the painted border
 * @param y the y position of the painted border
 * @param width the width of the painted border
 * @param height the height of the painted border
 */
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    if ((this.thickness > 0) && (g instanceof Graphics2D)) {
        Graphics2D g2d = (Graphics2D) g;

        Color oldColor = g2d.getColor();
        g2d.setColor(this.lineColor);

        Shape outer;
        Shape inner;

        int offs = this.thickness;
        int size = offs + offs;
        if (this.roundedCorners) {
            float arc = .2f * offs;
            outer = new RoundRectangle2D.Float(x, y, width, height, offs, offs);
            inner = new RoundRectangle2D.Float(x + offs, y + offs, width - size, height - size, arc, arc);
        }
        else {
            outer = new Rectangle2D.Float(x, y, width, height);
            inner = new Rectangle2D.Float(x + offs, y + offs, width - size, height - size);
        }
        Path2D path = new Path2D.Float(Path2D.WIND_EVEN_ODD);
        path.append(outer, false);
        path.append(inner, false);
        g2d.fill(path);
        g2d.setColor(oldColor);
    }
}
项目:parabuild-ci    文件:XYPlot.java   
/**
 * Draws the domain tick bands, if any.
 *
 * @param g2  the graphics device.
 * @param dataArea  the data area.
 * @param ticks  the ticks.
 * 
 * @see #setDomainTickBandPaint(Paint)
 */
public void drawDomainTickBands(Graphics2D g2, Rectangle2D dataArea,
                                List ticks) {
    // draw the domain tick bands, if any...
    Paint bandPaint = getDomainTickBandPaint();
    if (bandPaint != null) {
        boolean fillBand = false;
        ValueAxis xAxis = getDomainAxis();
        double previous = xAxis.getLowerBound();
        Iterator iterator = ticks.iterator();
        while (iterator.hasNext()) {
            ValueTick tick = (ValueTick) iterator.next();
            double current = tick.getValue();
            if (fillBand) {
                getRenderer().fillDomainGridBand(g2, this, xAxis, dataArea,
                        previous, current);
            }
            previous = current;
            fillBand = !fillBand;
        }
        double end = xAxis.getUpperBound();
        if (fillBand) {
            getRenderer().fillDomainGridBand(g2, this, xAxis, dataArea, 
                    previous, end);
        }
    }
}
项目:rapidminer    文件:ProcessDrawer.java   
/**
 * Draws the drag border.
 *
 * @param process
 *            the process for which to render the background
 * @param g2
 *            the graphics context to draw upon
 */
private void drawDragBorder(final ExecutionUnit process, final Graphics2D g2) {
    double width = model.getProcessWidth(process);
    double height = model.getProcessHeight(process);
    Shape dragFrame = new RoundRectangle2D.Double(DRAG_BORDER_PADDING, DRAG_BORDER_PADDING, width - 2
            * DRAG_BORDER_PADDING, height - 2 * DRAG_BORDER_PADDING, DRAG_BORDER_CORNER, DRAG_BORDER_CORNER);
    g2.setColor(BORDER_DRAG_COLOR);
    g2.setStroke(BORDER_DRAG_STROKE);
    g2.draw(dragFrame);
}
项目:amelia    文件:AuthorizeGoogleUser.java   
private static BufferedImage toBufferedImage(Image img){
      if (img instanceof BufferedImage){
          return (BufferedImage) img;
      }

      BufferedImage bimage = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.SCALE_SMOOTH);

      Graphics2D bGr = bimage.createGraphics();
      bGr.drawImage(img, 0, 0, null);
      bGr.dispose();
      return bimage;
}
项目:EasyDragDrop    文件:MainFrame.java   
@Override
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    Dimension arcs = new Dimension(40, 40);
    Graphics2D graphics = (Graphics2D) g;
    graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    graphics.setColor(new Color(106, 117, 144));
    graphics.fillRoundRect(0, 0, width - 1, height - 1, arcs.width, arcs.height);//paint background

    graphics.setClip(null);
    graphics.drawRoundRect(0, 0, width - 1, height - 1, arcs.width, arcs.height);//paint border
}
项目:jmt    文件:JobsDrawer.java   
@Override
public void paint(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2d.clearRect(0, 0, this.getWidth(), this.getHeight());
    g2d.setStroke(dCst.getDrawStroke());
    changeDrawSettings(dCst);

    //draw jobs
    drawJobsRemaining(donejobs, totjobs, panelW * 0.15f, 10.0f, panelW * 0.7f, panelH / 2.0f, g2d);
}
项目:Pet-Supply-Store    文件:ImageCreator.java   
private static void makeOval(Graphics2D graphics, ImageSize maxSize, Random rand) {
    switchColor(graphics, rand);

    int x = rand.nextInt(maxSize.getWidth());
    int y = rand.nextInt(maxSize.getHeight());
    int width = rand.nextInt(maxSize.getWidth() - x) + 1;
    int height = rand.nextInt(maxSize.getHeight() - y) + 1;

    if (rand.nextBoolean()) {
        graphics.fillOval(x, y, width, height);
    }

    graphics.drawOval(x, y, width, height);
}