Java Code Examples for java.awt.Graphics2D

The following are top voted examples for showing how to use java.awt.Graphics2D. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: spacesettlers   File: FlagGraphics.java   Source Code and License 12 votes vote down vote up
@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);
}
 
Example 2
Project: sbc-qsystem   File: FCallDialog.java   Source Code and License 9 votes vote down vote up
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;
}
 
Example 3
Project: defense-solutions-proofs-of-concept   File: RotatableImagePanel.java   Source Code and License 8 votes vote down vote up
@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);
}
 
Example 4
Project: parabuild-ci   File: SimpleDialFrame.java   Source Code and License 8 votes vote down vote up
/**
 * 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);
}
 
Example 5
Project: parabuild-ci   File: XYPlot.java   Source Code and License 8 votes vote down vote up
/**
 * 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);
    }

}
 
Example 6
Project: openjdk-jdk10   File: PathGraphics.java   Source Code and License 7 votes vote down vote up
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;
}
 
Example 7
Project: brModelo   File: baseDrawerItem.java   Source Code and License 7 votes vote down vote up
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);
}
 
Example 8
Project: jdk8u-jdk   File: GraphicsTests.java   Source Code and License 7 votes vote down vote up
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));
}
 
Example 9
Project: parabuild-ci   File: TextTitle.java   Source Code and License 7 votes vote down vote up
/**
 * 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;
}
 
Example 10
Project: rapidminer   File: GenericArrowButton.java   Source Code and License 7 votes vote down vote up
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);
}
 
Example 11
Project: openjdk-jdk10   File: IndexingTest.java   Source Code and License 7 votes vote down vote up
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;
}
 
Example 12
Project: jaer   File: LabyrinthTableTiltControllerGUI.java   Source Code and License 7 votes vote down vote up
@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();
}
 
Example 13
Project: geomapapp   File: PoleMapServer.java   Source Code and License 7 votes vote down vote up
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;
}
 
Example 14
Project: jdk8u-jdk   File: DrawRotatedStringUsingRotatedFont.java   Source Code and License 7 votes vote down vote up
/**
 * 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;
}
 
Example 15
Project: Jupiter   File: Player.java   Source Code and License 7 votes vote down vote up
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;
}
 
Example 16
Project: Panako   File: FrequencyAxisLayer.java   Source Code and License 7 votes vote down vote up
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);
}
 
Example 17
Project: brModelo   File: PreCardinalidade.java   Source Code and License 7 votes vote down vote up
@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);
}
 
Example 18
Project: parabuild-ci   File: WaferMapPlot.java   Source Code and License 7 votes vote down vote up
/**
 * 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);
    
}
 
Example 19
Project: OpenJSharp   File: ShapeGraphicAttribute.java   Source Code and License 7 votes vote down vote up
/**
 * {@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);
    }
}
 
Example 20
Project: parabuild-ci   File: MarkerAxisBand.java   Source Code and License 7 votes vote down vote up
/**
 * 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())
    );
}
 
Example 21
Project: Mujeed-Arabic-Prolog   File: AquaBarTabbedPaneUI.java   Source Code and License 6 votes vote down vote up
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);
	}
}
 
Example 22
Project: openjdk-jdk10   File: AltTabCrashTest.java   Source Code and License 6 votes vote down vote up
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);
    }
}
 
Example 23
Project: What-Happened-to-Station-7   File: CompoundAnimation.java   Source Code and License 6 votes vote down vote up
@Override
public void drawOverGUI(Graphics2D g, int s)
{
	for (Animation a : this)
		if (a.stillGoing())
			a.drawOverGUI(g, s);
}
 
Example 24
Project: parabuild-ci   File: MeterNeedle.java   Source Code and License 6 votes vote down vote up
/**
 * 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);

}
 
Example 25
Project: lemon   File: CustomProcessDiagramGenerator.java   Source Code and License 6 votes vote down vote up
/**
 * 绘制子流程
 */
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);
}
 
Example 26
Project: openjdk-jdk10   File: GraphicComponent.java   Source Code and License 6 votes vote down vote up
public void handleDraw(Graphics2D g2d, float x, float y) {

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

            graphic.draw(g2d, x, y);
            x += graphicAdvance;
        }
    }
 
Example 27
Project: VTerminal   File: CharBoldShader.java   Source Code and License 6 votes vote down vote up
@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;
    }
}
 
Example 28
Project: GIFKR   File: BoolInterpolator.java   Source Code and License 6 votes vote down vote up
@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);
}
 
Example 29
Project: jdk8u-jdk   File: WPathGraphics.java   Source Code and License 6 votes vote down vote up
/**
 * 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());
}
 
Example 30
Project: litiengine   File: GameScreen.java   Source Code and License 6 votes vote down vote up
@Override
public void render(final Graphics2D g) {
  if (Game.getEnvironment() != null) {
    Game.getEnvironment().render(g);
  }

  super.render(g);
}
 
Example 31
Project: FreeCol   File: ColopediaGameObjectTypePanel.java   Source Code and License 6 votes vote down vote up
/**
 * 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);
}
 
Example 32
Project: bitcoin_wallet_recovery_tool   File: Main.java   Source Code and License 6 votes vote down vote up
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);
}
 
Example 33
Project: monarch   File: LifelineState.java   Source Code and License 6 votes vote down vote up
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);
}
 
Example 34
Project: jdk8u-jdk   File: LineBorder.java   Source Code and License 6 votes vote down vote up
/**
 * 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);
    }
}
 
Example 35
Project: parabuild-ci   File: XYPlot.java   Source Code and License 6 votes vote down vote up
/**
 * 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);
        }
    }
}
 
Example 36
Project: rapidminer   File: ProcessDrawer.java   Source Code and License 6 votes vote down vote up
/**
 * 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);
}
 
Example 37
Project: amelia   File: AuthorizeGoogleUser.java   Source Code and License 6 votes vote down vote up
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;
}
 
Example 38
Project: EasyDragDrop   File: MainFrame.java   Source Code and License 6 votes vote down vote up
@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
}
 
Example 39
Project: jmt   File: JobsDrawer.java   Source Code and License 6 votes vote down vote up
@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);
}
 
Example 40
Project: Pet-Supply-Store   File: ImageCreator.java   Source Code and License 6 votes vote down vote up
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);
}
 
Example 41
Project: JavaPPTX   File: PPWindowImage.java   Source Code and License 5 votes vote down vote up
private void fillBackground(Graphics2D g) {
   Graphics2D g2 = (Graphics2D) g.create();
   Rectangle2D window = new Rectangle2D.Double(0, 0, sw, sh);
   g2.setComposite(AlphaComposite.Clear);
   g2.fill(window);
   g2.dispose();
}
 
Example 42
Project: jdk8u-jdk   File: PSPrinterJob.java   Source Code and License 5 votes vote down vote up
/**
 * Examine the metrics captured by the
 * <code>PeekGraphics</code> instance and
 * if capable of directly converting this
 * print job to the printer's control language
 * or the native OS's graphics primitives, then
 * return a <code>PSPathGraphics</code> to perform
 * that conversion. If there is not an object
 * capable of the conversion then return
 * <code>null</code>. Returning <code>null</code>
 * causes the print job to be rasterized.
 */

protected Graphics2D createPathGraphics(PeekGraphics peekGraphics,
                                        PrinterJob printerJob,
                                        Printable painter,
                                        PageFormat pageFormat,
                                        int pageIndex) {

    PSPathGraphics pathGraphics;
    PeekMetrics metrics = peekGraphics.getMetrics();

    /* If the application has drawn anything that
     * out PathGraphics class can not handle then
     * return a null PathGraphics.
     */
    if (forcePDL == false && (forceRaster == true
                    || metrics.hasNonSolidColors()
                    || metrics.hasCompositing())) {

        pathGraphics = null;
    } else {

        BufferedImage bufferedImage = new BufferedImage(8, 8,
                                        BufferedImage.TYPE_INT_RGB);
        Graphics2D bufferedGraphics = bufferedImage.createGraphics();
        boolean canRedraw = peekGraphics.getAWTDrawingOnly() == false;

        pathGraphics =  new PSPathGraphics(bufferedGraphics, printerJob,
                                           painter, pageFormat, pageIndex,
                                           canRedraw);
    }

    return pathGraphics;
}
 
Example 43
Project: incubator-netbeans   File: SynchronousXYItemMarker.java   Source Code and License 5 votes vote down vote up
public void paintItem(ChartItem item, List<ItemSelection> highlighted,
                          List<ItemSelection> selected, Graphics2D g,
                          Rectangle dirtyArea, ChartContext context) {
//        if (!(item instanceof ProfilerXYItem))
//            throw new UnsupportedOperationException("Unsupported item: " + item); // NOI18N
//        if (!(context instanceof ProfilerXYChartComponent.Context))
//            throw new UnsupportedOperationException("Unsupported context: " + context);
        
        paint((SynchronousXYItem)item, highlighted, selected, g, dirtyArea,
              (SynchronousXYChartContext)context);
    }
 
Example 44
Project: rapidminer   File: SOMModelPlotter.java   Source Code and License 5 votes vote down vote up
@Override
public void paintComponent(Graphics graphics) {
	super.paintComponent(graphics);
	// painting only if approved
	if (show) {
		// init graphics
		Graphics2D g = (Graphics2D) graphics;

		int pixWidth = getWidth() - 2 * MARGIN;
		int pixHeight = getHeight() - 2 * MARGIN;

		// painting background
		g.drawImage(this.image, MARGIN, MARGIN, pixWidth, pixHeight, Color.WHITE, null);

		// painting transparent class overlay
		g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alphaLevel));
		g.drawImage(this.classImage, MARGIN, MARGIN, pixWidth, pixHeight, Color.WHITE, null);
		g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1));
		// painting points
		drawPoints(g);

		// painting Legend
		drawLegend(graphics, this.dataTable, colorColumn);

		// paint Tooltip
		drawToolTip((Graphics2D) graphics);
	}
}
 
Example 45
Project: JuggleMasterPro   File: AnimationJFrame.java   Source Code and License 5 votes vote down vote up
/**
 * Method description
 * 
 * @see
 * @param objPgraphics2D
 * @param objPballTrail
 */
final private void doDrawThrow(Graphics2D objPgraphics2D, BallTrail objPballTrail, boolean bolPlighterColors) {

	objPgraphics2D.setFont(objPballTrail.intGcolor != Constants.bytS_UNCLASS_NO_VALUE
							|| this.objGjuggleMasterPro.getControlValue(Constants.bytS_BYTE_LOCAL_HEIGHT) < Constants.bytS_ENGINE_THROWS_VALUES_NUMBER
																																						? this.objGthrowValuesBoldFont
																																						: this.objGthrowValuesNormalFont);
	final String strLthrow = Tools.getThrowValueString(objPballTrail.bytGthrow);
	final int intLthrowStringWidth = objPgraphics2D.getFontMetrics().stringWidth(strLthrow);

	// Writing the throw back value :
	final boolean bolLlightColor =
									this.objGballColorValueAHashMap.get(this.objGjuggleMasterPro.getPatternBooleanValue(Constants.bytS_BOOLEAN_LOCAL_COLORS)
																																						? objPballTrail.intGcolor
																																						: BallsColors.intS_BALLS_COLORS_DEFAULT_VALUE)[bolPlighterColors
																																																						? Constants.bytS_ENGINE_LIGHT
																																																						: Constants.bytS_ENGINE_DARK];
	objPgraphics2D.setColor(bolLlightColor ? Color.WHITE : Color.BLACK);
	objPgraphics2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
	objPgraphics2D.drawString(	strLthrow,
								(Constants.intS_GRAPHICS_CORRECTION_X + objPballTrail.intGposX + Constants.intS_GRAPHICS_BALL_MAXIMUM_RADIUS)
									* this.fltGframeSizeRatio - intLthrowStringWidth / 2 + 1,
								(objPballTrail.intGposY + Constants.intS_GRAPHICS_BALL_MAXIMUM_RADIUS) * this.fltGframeSizeRatio
									+ objPgraphics2D.getFontMetrics().getAscent() / 2 - 1);
	objPgraphics2D.setFont(this.objGthrowValuesNormalFont);

	// Writing the throw front value :
	objPgraphics2D.setColor(bolLlightColor ? Color.BLACK : Color.WHITE);
	objPgraphics2D.drawString(	strLthrow,
								(Constants.intS_GRAPHICS_CORRECTION_X + objPballTrail.intGposX + Constants.intS_GRAPHICS_BALL_MAXIMUM_RADIUS)
									* this.fltGframeSizeRatio - intLthrowStringWidth / 2,
								(objPballTrail.intGposY + Constants.intS_GRAPHICS_BALL_MAXIMUM_RADIUS) * this.fltGframeSizeRatio
									+ objPgraphics2D.getFontMetrics().getAscent() / 2 - 2);
}
 
Example 46
Project: QN-ACTR-Release   File: QueueDrawer.java   Source Code and License 5 votes vote down vote up
private void drawOccupiedPercentage2(Color startC, Color border, boolean gradientFill, Graphics2D g2d, int cpu) {
	//processor.setFrame(x+PROC_RAD/2 , y + cpu*PROC_RAD, 2 * PROC_RAD /2, 2 * PROC_RAD /2);

	//		if (remainingTime[cpu] != 0) {
	double x = getProcessorXY().x, y = getProcessorXY().y;
	occupiedRect = new Rectangle2D.Double(x + PROC_RAD / 2, y + cpu * PROC_RAD + ELEMS_GAP * cpu - ELEMS_GAP / 2, 2 * PROC_RAD / 2, 2 * PROC_RAD
			* (1 - (double) remainingTime[cpu] / (double) totTime[cpu]) / 2);
	occupiedEll = new Ellipse2D.Double(x + PROC_RAD / 2, y + cpu * PROC_RAD + ELEMS_GAP * cpu - ELEMS_GAP / 2, 2 * PROC_RAD / 2, 2 * PROC_RAD / 2);
	if (gradientFill) {
		GradientPaint gp = new GradientPaint((float) x, (float) y, startC.brighter(), (float) x, (float) (y + 2 * PROC_RAD), startC.darker(),
				false);
		g2d.setPaint(gp);
	} else {
		g2d.setPaint(startC);
	}
	occupiedArea = new Area(occupiedEll);
	occupiedArea.subtract(new Area(occupiedRect));
	g2d.fill(occupiedArea);
	g2d.setPaint(Color.BLACK);
	g2d.draw(occupiedArea);

	// draw orizontal line parallel to occupation
	Line2D.Double l = new Line2D.Double(x + PROC_RAD * 2 + ELEMS_GAP, y + cpu * PROC_RAD + ELEMS_GAP * cpu - ELEMS_GAP / 2 + 2 * PROC_RAD
			* (1 - (double) remainingTime[cpu] / (double) totTime[cpu]) / 2,//y + PROC_RAD * 2 * (1 - (double) remainingTime / (double) totTime) /2 + ELEMS_GAP * cpu -  ELEMS_GAP /2  , 
			x + PROC_RAD * 2 + 2 * ELEMS_GAP, y + cpu * PROC_RAD + ELEMS_GAP * cpu - ELEMS_GAP / 2 + 2 * PROC_RAD
					* (1 - (double) remainingTime[cpu] / (double) totTime[cpu]) / 2);//y + PROC_RAD * 2 * (1 - (double) remainingTime / (double) totTime) /2 + ELEMS_GAP * cpu -  ELEMS_GAP /2 );
	g2d.draw(l);

	// draw vertical line
	l = new Line2D.Double(x + PROC_RAD * 2 + 2 * ELEMS_GAP, y + cpu * PROC_RAD + ELEMS_GAP * cpu - ELEMS_GAP / 2 + 2 * PROC_RAD
			* (1 - (double) remainingTime[cpu] / (double) totTime[cpu]) / 2, x + PROC_RAD * 2 + 2 * ELEMS_GAP, y + PROC_RAD * 2 / 2 + cpu
			* PROC_RAD + ELEMS_GAP * cpu - ELEMS_GAP / 2);
	g2d.draw(l);

	//		}
}
 
Example 47
Project: jdk8u-jdk   File: CompositionArea.java   Source Code and License 5 votes vote down vote up
public void paint(Graphics g) {
    super.paint(g);
    g.setColor(getForeground());
    TextLayout layout = composedTextLayout;
    if (layout != null) {
        layout.draw((Graphics2D) g, TEXT_ORIGIN_X, TEXT_ORIGIN_Y);
    }
    if (caret != null) {
        Rectangle rectangle = getCaretRectangle(caret);
        g.setXORMode(getBackground());
        g.fillRect(rectangle.x, rectangle.y, 1, rectangle.height);
        g.setPaintMode();
    }
}
 
Example 48
Project: parabuild-ci   File: CategoryPlot.java   Source Code and License 5 votes vote down vote up
/**
 * Draws the annotations...
 *
 * @param g2  the graphics device.
 * @param dataArea  the data area.
 */
protected void drawAnnotations(Graphics2D g2, Rectangle2D dataArea) {

    if (getAnnotations() != null) {
        Iterator iterator = getAnnotations().iterator();
        while (iterator.hasNext()) {
            CategoryAnnotation annotation 
                    = (CategoryAnnotation) iterator.next();
            annotation.draw(g2, this, dataArea, getDomainAxis(), 
                    getRangeAxis());
        }
    }

}
 
Example 49
Project: ramus   File: TestFrame.java   Source Code and License 5 votes vote down vote up
private Container createContentPanel() {
    final JPanel panel = new JPanel() {

        @Override
        public void paint(Graphics g) {
            super.paint(g);
            model.paint((Graphics2D) g, this.getBounds());
        }
    };

    final JPanel res = new JPanel(new BorderLayout());
    res.add(panel, BorderLayout.CENTER);
    final JSpinner slider = new JSpinner(
            new SpinnerNumberModel(4, 2, 8, 1) {

            });
    res.add(slider, BorderLayout.SOUTH);
    slider.addChangeListener(new ChangeListener() {

        public void stateChanged(final ChangeEvent e) {
            model.setCount(((Number) slider.getValue()).intValue());
            TestFrame.this.repaint();
        }

    });
    return res;
}
 
Example 50
Project: incubator-netbeans   File: BrandingModel.java   Source Code and License 5 votes vote down vote up
private static Runnable getScaleAndStoreIconTask(final BrandedFile icon, final int width, final int height) throws IOException {
    return new Runnable() {
        @Override
        public void run() {
            BufferedImage bi = new BufferedImage(
                    width,
                    height,
                    BufferedImage.TYPE_INT_ARGB);
            
            Graphics2D g2 = bi.createGraphics();
            ImageIcon image = new ImageIcon(icon.getBrandingSource());
            g2.drawImage(image.getImage(),0, 0, 
                    width, height, null);
            
            g2.dispose();
            try {
                File iconLocation = icon.getFileLocation();
                if( !iconLocation.exists() )
                    iconLocation.createNewFile();
                FileObject fo = FileUtil.toFileObject(iconLocation);
                OutputStream os = fo == null ? new FileOutputStream(iconLocation) : fo.getOutputStream();
                try {
                    ImageIO.write(bi, "png", os);
                } finally {
                    os.close();
                }
            } catch (IOException ex) {
                ErrorManager.getDefault().notify(ex);
            }
        }
    };
}
 
Example 51
Project: sbc-qsystem   File: FWelcome.java   Source Code and License 5 votes vote down vote up
/**
 * @param str text for positioning
 * @param alignment -1 left, 0 center, 1 right
 * @return coordinate X
 */
private static int getHAlignment(Graphics2D g2, String str, int alignment, double kx) {
    if (alignment < 0) {
        return WelcomeParams.getInstance().leftMargin;
    }
    final int sw = (int) (CMP.getFontMetrics(g2.getFont()).stringWidth(str) * kx);
    int pos = alignment == 0 ? (WelcomeParams.getInstance().paperWidht - sw) / 2
        : (WelcomeParams.getInstance().paperWidht - sw);

    return (int) Math.round(pos / kx);
}
 
Example 52
Project: AWGW   File: GridPanel.java   Source Code and License 5 votes vote down vote up
/**
 * Draw one occupant object. First verify that the object is actually
 * visible before any drawing, set up the clip appropriately and use the
 * DisplayMap to determine which object to call upon to render this
 * particular Locatable. Note that we save and restore the graphics
 * transform to restore back to normalcy no matter what the renderer did to
 * to the coordinate system.
 *
 * @param g2    the Graphics2D object to use to render
 * @param xleft the leftmost pixel of the rectangle
 * @param ytop  the topmost pixel of the rectangle
 * @param obj   the Locatable object to draw
 */
private void drawOccupant(Graphics2D g2, int xleft, int ytop, Object obj) {
    Rectangle cellToDraw = new Rectangle(xleft, ytop, cellSize, cellSize);

    // Only draw if the object is visible within the current clipping
    // region.
    if (cellToDraw.intersects(g2.getClip().getBounds())) {
        Graphics2D g2copy = (Graphics2D) g2.create();
        g2copy.clip(cellToDraw);
        // Get the drawing object to display this occupant.
        Display displayObj = displayMap.findDisplayFor(obj.getClass());
        displayObj.draw(obj, this, g2copy, cellToDraw);
        g2copy.dispose();
    }
}
 
Example 53
Project: OpenJSharp   File: NimbusLookAndFeel.java   Source Code and License 5 votes vote down vote up
@Override
public Icon getDisabledIcon(JComponent component, Icon icon) {
    if (icon instanceof SynthIcon) {
        SynthIcon si = (SynthIcon)icon;
        BufferedImage img = EffectUtils.createCompatibleTranslucentImage(
                si.getIconWidth(), si.getIconHeight());
        Graphics2D gfx = img.createGraphics();
        si.paintIcon(component, gfx, 0, 0);
        gfx.dispose();
        return new ImageIconUIResource(GrayFilter.createDisabledImage(img));
    } else {
        return super.getDisabledIcon(component, icon);
    }
}
 
Example 54
Project: AWGW   File: DisplayMap.java   Source Code and License 5 votes vote down vote up
public void paintIcon(Component comp, Graphics g, int x, int y)
{
    Graphics2D g2 = (Graphics2D) g;
    AffineTransform savedTransform = g2.getTransform(); // save current
    displayObj.draw(null, comp, g2, new Rectangle(x, y, getIconWidth(),
            getIconHeight()));
    g2.setTransform(savedTransform); // restore coordinate system
}
 
Example 55
Project: rapidminer   File: SimilarityKDistanceVisualization.java   Source Code and License 5 votes vote down vote up
private void drawHorizontalTic(Graphics2D g, int ticNumber, DecimalFormat format, double dx, double dy, double sx,
		double sy) {
	double y = ticNumber * yTicSize + minY;
	g.setColor(GRID_COLOR);
	g.draw(new Line2D.Double((minX + dx) * sx, (y + dy) * sy, (maxX + dx) * sx, (y + dy) * sy));
	g.setColor(Color.black);
	String label = format.format(y) + " ";
	Rectangle2D stringBounds = SCALED_LABEL_FONT.getStringBounds(label, g.getFontRenderContext());
	g.drawString(label, (float) ((minX + dx) * sx - stringBounds.getWidth()),
			(float) ((y + dy) * sy - stringBounds.getHeight() / 2 - stringBounds.getY()));
}
 
Example 56
Project: openjdk-jdk10   File: ReaderListenersTest.java   Source Code and License 5 votes vote down vote up
protected static BufferedImage createTestImage() {
    BufferedImage res = new BufferedImage(100, 100,
                                          BufferedImage.TYPE_INT_RGB);
    Graphics2D g = res.createGraphics();
    g.setColor(Color.red);
    g.fillRect(0,0, 100,100);
    return res;
}
 
Example 57
Project: geomapapp   File: SurveyPlannerSelector.java   Source Code and License 5 votes vote down vote up
void finish(MouseEvent e) {
	double wrap = map.getWrap();
	if (p0==null) {
		return;
	}
	drawLine();
	Graphics2D g = map.getGraphics2D();
	g.setStroke( new BasicStroke(4f/(float)map.getZoom()) );
	g.setColor( Color.white );
	//g.setXORMode(Color.white);
	g.draw( currentPath );
	if( wrap>0.) {
		g.translate(wrap,0.);
		g.draw( currentPath );
	}
	Point p1 = e.getPoint();
	if( p0.x==p1.x && p0.y==p1.y ) {
		if( line!=null ) {
			line=null;
			if(dialog!=null)dialog.setVisible(false);
			map.repaint();
		}
		p0=null;
		return;
	}

	Point2D pA = map.getScaledPoint( p0 );
	Point2D pB = map.getScaledPoint( e.getPoint());
	Point2D latLonA = map.getProjection().getRefXY(pA);
	Point2D latLonB = map.getProjection().getRefXY(pB);
	
	startLonTF.setText(df.format(latLonA.getX()));
	startLatTF.setText(df.format(latLonA.getY()));
	endLonTF.setText(df.format(latLonB.getX()));
	endLatTF.setText(df.format(latLonB.getY()));

	currentLine = null;
	currentPath = null;
	p0=null;
}
 
Example 58
Project: TrabalhoFinalEDA2   File: mxGraphicsCanvas2D.java   Source Code and License 5 votes vote down vote up
/**
 * Saves the current canvas state.
 */
public void save()
{
	stack.push(state);
	state = cloneState(state);
	state.g = (Graphics2D) state.g.create();
}
 
Example 59
Project: VASSAL-src   File: SourceTileOpBitmapImpl.java   Source Code and License 5 votes vote down vote up
public BufferedImage eval() throws Exception {
  final BufferedImage src = sop.getImage(null);
  final BufferedImage dst = ImageUtils.createCompatibleImage(
    size.width, size.height, src.getTransparency() != BufferedImage.OPAQUE
  );

  final Graphics2D g = dst.createGraphics();
  g.drawImage(src, 0, 0, size.width, size.height, x0, y0, x1, y1, null);
  g.dispose();

  return dst;
}
 
Example 60
Project: openjdk-jdk10   File: bug8132119.java   Source Code and License 5 votes vote down vote up
private static void checkNullArguments() {

        Graphics2D g = null;
        try {
            String text = "Test";
            JComponent component = new JLabel(text);
            BufferedImage img = createBufferedImage(100, 100);
            g = img.createGraphics();
            checkNullArguments(component, g, text);
        } finally {
            g.dispose();
        }
    }