java.awt.Graphics Java Examples

The following examples show how to use java.awt.Graphics. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Clock.java    From hottub with GNU General Public License v2.0 7 votes vote down vote up
@Override
public void paint(Graphics g) {
    g.setFont(clockFaceFont);
    // Draw the circle and numbers
    g.setColor(handColor);
    g.drawArc(xcenter - 50, ycenter - 50, 100, 100, 0, 360);
    g.setColor(numberColor);
    g.drawString("9", xcenter - 45, ycenter + 3);
    g.drawString("3", xcenter + 40, ycenter + 3);
    g.drawString("12", xcenter - 5, ycenter - 37);
    g.drawString("6", xcenter - 3, ycenter + 45);

    // Draw date and hands
    g.setColor(numberColor);
    g.drawString(lastdate, 5, 125);
    g.drawLine(xcenter, ycenter, lastxs, lastys);
    g.setColor(handColor);
    g.drawLine(xcenter, ycenter - 1, lastxm, lastym);
    g.drawLine(xcenter - 1, ycenter, lastxm, lastym);
    g.drawLine(xcenter, ycenter - 1, lastxh, lastyh);
    g.drawLine(xcenter - 1, ycenter, lastxh, lastyh);
}
 
Example #2
Source File: IconSelectMatrix.java    From lgmodeler with GNU General Public License v3.0 6 votes vote down vote up
public void paint(Graphics g){
	Graphics2D g2d = (Graphics2D)g;
	g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
	int cols = getWidth()/size;
	g.setColor(Color.GRAY);
	g.fillRect(0, 0, getWidth(), getHeight());
	g.setColor(Resources.SELECT_COLOR);
	for(int i = 0; i < icons.length; i++){
		int row = i/cols;
		int col = i%cols;
		if(selected == i){
			g.fillRoundRect(col*size+1, row*size+1, size-2, size-2, 12, 12);
		}
		g.drawImage(icons[i], col*size, row*size, null);
	}
}
 
Example #3
Source File: WeaponDescriptionCell.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
@Override
public void drawCell(Outline outline, Graphics gc, Rectangle bounds, Row row, Column column, boolean selected, boolean active) {
    Scale            scale       = Scale.get(outline);
    int              hMargin     = scale.scale(H_MARGIN);
    WeaponDisplayRow theRow      = (WeaponDisplayRow) row;
    Rectangle        insetBounds = new Rectangle(bounds.x + hMargin, bounds.y, bounds.width - hMargin * 2, bounds.height);
    String           notes       = getSecondaryText(theRow);
    Font             font        = scale.scale(UIManager.getFont(Fonts.KEY_FIELD_PRIMARY));
    gc.setColor(Colors.getListForeground(selected, active));
    gc.setFont(font);
    int pos = TextDrawing.draw(gc, insetBounds, getPrimaryText(theRow), SwingConstants.LEFT, SwingConstants.TOP);
    if (!notes.trim().isEmpty()) {
        insetBounds.height -= pos - insetBounds.y;
        insetBounds.y = pos;
        gc.setFont(scale.scale(UIManager.getFont(Fonts.KEY_FIELD_SECONDARY)));
        TextDrawing.draw(gc, insetBounds, notes, SwingConstants.LEFT, SwingConstants.TOP);
    }
}
 
Example #4
Source File: EnvelopeEditorBox.java    From jsyn with Apache License 2.0 6 votes vote down vote up
/**
 * Draw selected range.
 */
private void drawRange(Graphics g) {
    if (rangeStart >= 0) {
        int height = getHeight();
        int gx0 = 0, gx1 = 0;

        if (rangeEnd < rangeStart) {
            gx0 = rangeEnd;
            gx1 = rangeStart;
        } else {
            gx0 = rangeStart;
            gx1 = rangeEnd;
        }
        g.setColor(rangeColor);
        g.fillRect(gx0, 0, gx1 - gx0, height);
    }
}
 
Example #5
Source File: MotifGraphicsUtils.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void drawGroove(Graphics g, int x, int y, int w, int h,
                              Color shadow, Color highlight)
{
    Color oldColor = g.getColor();  // Make no net change to g
    g.translate(x, y);

    g.setColor(shadow);
    g.drawRect(0, 0, w-2, h-2);

    g.setColor(highlight);
    g.drawLine(1, h-3, 1, 1);
    g.drawLine(1, 1, w-3, 1);

    g.drawLine(0, h-1, w-1, h-1);
    g.drawLine(w-1, h-1, w-1, 0);

    g.translate(-x, -y);
    g.setColor(oldColor);
}
 
Example #6
Source File: MiniMap.java    From megamek with GNU General Public License v2.0 6 votes vote down vote up
private void paintHeight(Graphics g, IHex h, int x, int y) {
    if (heightDisplayMode == SHOW_NO_HEIGHT) {
        return;
    }
    if (zoom > 2) {
        int baseX = (x * (hexSide[zoom] + hexSideBySin30[zoom])) + leftMargin;
        int baseY = (((2 * y) + 1 + (x % 2)) * hexSideByCos30[zoom]) + topMargin;
        g.setColor(Color.white);
        int height = 0;
        if ((h.getTerrain(Terrains.BUILDING) != null)
            && (heightDisplayMode == SHOW_BUILDING_HEIGHT)) {
            height = h.ceiling();
        } else if (heightDisplayMode == SHOW_GROUND_HEIGHT) {
            height = h.floor();
        } else if (heightDisplayMode == SHOW_TOTAL_HEIGHT) {
            height = ((h.getTerrain(Terrains.BUILDING) != null) || (h
                    .getTerrain(Terrains.FUEL_TANK) != null)) ? h.ceiling()
                    : h.floor();
        }
        if (height != 0) {
            g.drawString(height + "", baseX + 5, baseY + 5); //$NON-NLS-1$
        }
    }
}
 
Example #7
Source File: CardsCanvas.java    From magarena with GNU General Public License v3.0 6 votes vote down vote up
private void drawCardCount(Graphics g, int X, int Y, int W, int H, final CardCanvas card) {
    if (cardTypeCount.isEmpty()) {
        return;
    }
    final int cardCount = cardTypeCount.get(card.hashCode());
    if (cardCount > 1) {
        g.setColor(Color.WHITE);
        final String text = Integer.toString(cardCount);
        int h = (int)(H * 0.15);
        h = h > 8 ? (int)(H * 0.15) : 9;
        final Font f = new Font("Dialog", Font.BOLD, h);
        final int w = g.getFontMetrics(f).stringWidth(text);
        g.setFont(f);
        drawStringWithOutline(g, text, X + ((W - w) / 2), Y + ((H - h) / 3));
    }
}
 
Example #8
Source File: ProfilerTreeTable.java    From visualvm with GNU General Public License v2.0 6 votes vote down vote up
public void paint(Graphics g) {
    g.setColor(getBackground());
    int rectX = currentSelected || customRendering || !currentFirst ? 0 : currentX;
    g.fillRect(rectX, 0, getWidth() - rectX, rowHeight);
    
    g.translate(customRendering ? -currentX : 0, -currentRowOffset);

    // #269500 - performance workaround for BasicTreeUI
    if (workaroundVerticalLines && !rootVisible && currentRowOffset > 0) {
        rootVisible = true;
        super.paint(g);
        rootVisible = false;
    } else {
        super.paint(g);
    }
}
 
Example #9
Source File: ListCompletionView.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void renderHtml(Fix f, Graphics g, Font defaultFont, Color defaultColor,
int width, int height, boolean selected) {
    if (icon != null) {
        // The image of the ImageIcon should already be loaded
        // so no ImageObserver should be necessary
        g.drawImage(ImageUtilities.icon2Image(icon), BEFORE_ICON_GAP, (height - icon.getIconHeight()) /2, this);
    }
    int iconWidth = BEFORE_ICON_GAP + icon.getIconWidth() + AFTER_ICON_GAP;
    int textEnd = width - AFTER_ICON_GAP - subMenuIcon.getIconWidth() - AFTER_TEXT_GAP;
    FontMetrics fm = g.getFontMetrics(defaultFont);
    int textY = (height - fm.getHeight())/2 + fm.getHeight() - fm.getDescent();

    // Render left text
    if (textEnd > iconWidth) { // any space for left text?
        HtmlRenderer.renderHTML(f.getText(), g, iconWidth, textY, textEnd, textY,
            defaultFont, defaultColor, HtmlRenderer.STYLE_TRUNCATE, true);//, selected);
    }

    if (HintsControllerImpl.getSubfixes(f).iterator().hasNext()) {
        paintArrowIcon(g, textEnd + AFTER_TEXT_GAP, (height - subMenuIcon.getIconHeight()) /2);
    }
}
 
Example #10
Source File: CSSBorder.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public void paint(Polygon shape, Graphics g, Color color, int side) {
    Rectangle r = shape.getBounds();
    int length = Math.max(r.height / 2, 1);
    int[] lengthPattern = { length, length };
    Color[] colorPattern =
                     ((side + 1) % 4 < 2) == (type == Value.GROOVE) ?
        new Color[] { getShadowColor(color), getLightColor(color) } :
        new Color[] { getLightColor(color), getShadowColor(color) };
    paintStrokes(r, g, View.Y_AXIS, lengthPattern, colorPattern);
}
 
Example #11
Source File: PrintJob2D.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Prints the page at the specified index into the specified
 * {@link Graphics} context in the specified
 * format.  A <code>PrinterJob</code> calls the
 * <code>Printable</code> interface to request that a page be
 * rendered into the context specified by
 * <code>graphics</code>.  The format of the page to be drawn is
 * specified by <code>pageFormat</code>.  The zero based index
 * of the requested page is specified by <code>pageIndex</code>.
 * If the requested page does not exist then this method returns
 * NO_SUCH_PAGE; otherwise PAGE_EXISTS is returned.
 * The <code>Graphics</code> class or subclass implements the
 * {@link PrinterGraphics} interface to provide additional
 * information.  If the <code>Printable</code> object
 * aborts the print job then it throws a {@link PrinterException}.
 * @param graphics the context into which the page is drawn
 * @param pageFormat the size and orientation of the page being drawn
 * @param pageIndex the zero based index of the page to be drawn
 * @return PAGE_EXISTS if the page is rendered successfully
 *         or NO_SUCH_PAGE if <code>pageIndex</code> specifies a
 *         non-existent page.
 * @exception java.awt.print.PrinterException
 *         thrown when the print job is terminated.
 */
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex)
             throws PrinterException {

    int result;

    /* This method will be called by the PrinterJob on a thread other
     * that the application's thread. We hold on to the graphics
     * until we can rendevous with the application's thread and
     * hand over the graphics. The application then does all the
     * drawing. When the application is done drawing we rendevous
     * again with the PrinterJob thread and release the Graphics
     * so that it knows we are done.
     */

    /* Add the graphics to the message queue of graphics to
     * be rendered. This is really a one slot queue. The
     * application's thread will come along and remove the
     * graphics from the queue when the app asks for a graphics.
     */
    graphicsToBeDrawn.append( (Graphics2D) graphics);

    /* We now wait for the app's thread to finish drawing on
     * the Graphics. This thread will sleep until the application
     * release the graphics by placing it in the graphics drawn
     * message queue. If the application signals that it is
     * finished drawing the entire document then we'll get null
     * returned when we try and pop a finished graphic.
     */
    if (graphicsDrawn.pop() != null) {
        result = PAGE_EXISTS;
    } else {
        result = NO_SUCH_PAGE;
    }

    return result;
}
 
Example #12
Source File: BasicTextField.java    From 3Dscript with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void paint(Graphics g) {
	((Graphics2D)g).setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);;
	g.setFont(font);
	Rectangle2D r = g.getFontMetrics().getStringBounds(text, g);
	int px = 0, py = 0;
	switch(justifyx) {
	case JUSTIFY_LEFT:   px = x + padding; break;
	case JUSTIFY_RIGHT:  px = x - padding - (int)Math.round(r.getWidth()); break;
	case JUSTIFY_CENTER: px = x - (int)Math.round(r.getWidth() / 2); break;
	}

	switch(justifyy) {
	case JUSTIFY_TOP:       py = y + padding; break;
	case JUSTIFY_BOTTOM:    py = y - padding - (int)Math.round(r.getHeight()); break;
	case JUSTIFY_CENTER:    py = y - (int)Math.round(r.getHeight() / 2); break;
	}

	rectangle.x = px;
	rectangle.width = (int)Math.round(r.getWidth());
	rectangle.y = py;
	rectangle.height = (int)Math.round(r.getHeight());

	g.setColor(selectall ? Color.BLACK : Color.WHITE);
	((Graphics2D)g).fill(rectangle);
	g.setColor(selectall ? Color.WHITE : Color.BLACK);
	g.drawString(text, px, py - (int)Math.round(r.getY()));

	if(editing) {
		g.drawRect(rectangle.x - 2, rectangle.y - 2, rectangle.width + 4, rectangle.height + 4);
	}
}
 
Example #13
Source File: ImageViewer.java    From chipster with MIT License 5 votes vote down vote up
@Override
protected void paintComponent(Graphics g) {
	super.paintComponent(g);
	Dimension size = ImageViewer.this.calculateSize();
	
	//Has to be done after the visualisation has its parent to know the size
	ImageViewer.this.updateCursor();
	
	Graphics2D g2 = (Graphics2D)g;
	g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
			RenderingHints.VALUE_INTERPOLATION_BILINEAR);
	g2.drawImage(original, 0, 0, (int)size.getWidth(), (int)size.getHeight(), null);
}
 
Example #14
Source File: MainPanel.java    From javagame with MIT License 5 votes vote down vote up
/**
 * �o�b�t�@����ʂɕ`��
 * 
 */
private void paintScreen() {
    Graphics g = getGraphics();
    // �o�b�t�@�C���[�W����ʂɕ`��
    if ((g != null) && (dbImage != null)) {
        g.drawImage(dbImage, 0, 0, null);
    }
    Toolkit.getDefaultToolkit().sync();
    if (g != null) {
        g.dispose();
    }
}
 
Example #15
Source File: AltTabCrashTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void paint(Graphics g, Color c) {
    if (c == null) {
        g.setColor(color);
    } else {
        g.setColor(c);
    }
    g.fillOval(x, y, diameter, diameter);
}
 
Example #16
Source File: ReflectionDemo.java    From filthy-rich-clients with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected void paintComponent(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    Rectangle clip = g2.getClipBounds();
    Paint paint = g2.getPaint();
    g2.setPaint(new GradientPaint(0.0f, getHeight() * 0.22f,
                                  new Color(0x202737),
                                  0.0f, getHeight() * 0.7f,
                                  Color.BLACK));
    g2.fillRect(clip.x, clip.y, clip.width, clip.height);
    g2.setPaint(paint);
}
 
Example #17
Source File: XYZApp.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void paint(Graphics g) {
    if (md != null) {
        md.mat.unit();
        md.mat.translate(-(md.xmin + md.xmax) / 2,
                -(md.ymin + md.ymax) / 2,
                -(md.zmin + md.zmax) / 2);
        md.mat.mult(amat);
        // md.mat.scale(xfac, -xfac, 8 * xfac / getSize().width);
        md.mat.scale(xfac, -xfac, 16 * xfac / getSize().width);
        md.mat.translate(getSize().width / 2, getSize().height / 2, 8);
        md.transformed = false;
        if (backBuffer != null) {
            if (!backSize.equals(getSize())) {
                newBackBuffer();
            }
            backGC.setColor(getBackground());
            backGC.fillRect(0, 0, getSize().width, getSize().height);
            md.paint(backGC);
            g.drawImage(backBuffer, 0, 0, this);
        } else {
            md.paint(g);
        }
        setPainted();
    } else if (message != null) {
        g.drawString("Error in model:", 3, 20);
        g.drawString(message, 10, 40);
    }
}
 
Example #18
Source File: MainFrame.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
public void mouseReleased(MouseEvent e) {
	if(e.getButton() == MouseEvent.BUTTON1) {
		Graphics g = local.getGraphics();
		local.paintComponents(g);

		parent.selectLeadsInBox(corner, e.getPoint());
	}
}
 
Example #19
Source File: Buildings.java    From JAVA-MVC-Swing-Monopoly with Apache License 2.0 5 votes vote down vote up
/**
 * 
 * ���ƽ�����
 * 
 */
private void paintBuildings(Graphics g) {
	for(Building temp : this.building){
		// ���ݻ���
		paintBuilding(temp,g);
	}
}
 
Example #20
Source File: UncertaintyGraphPanel.java    From ET_Redux with Apache License 2.0 5 votes vote down vote up
/**
 *
 * @param g
 */
@Override
protected void paintComponent ( Graphics g ) {
    super.paintComponent( g );

    paint( (Graphics2D) g );
}
 
Example #21
Source File: ParsedSynthStyle.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
public void paintTabbedPaneTabBorder(SynthContext context,
             Graphics g, int x, int y, int w, int h, int tabIndex,
             int direction) {
    getPainter(context, "tabbedpanetabborder", direction).
        paintTabbedPaneTabBorder(context, g, x, y, w, h, tabIndex,
                                 direction);
}
 
Example #22
Source File: DragManager.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void paint(Graphics g) {
    g.setXORMode(Color.white); //Color of line varies
    
    for (DragItem elem : allItems) {
        elem.paint(g);
    }
}
 
Example #23
Source File: ShapeCreationUI.java    From pumpernickel with MIT License 5 votes vote down vote up
/**
 * Invokes {@link #paintShapes(Graphics2D, ShapeCreationPanel)} and then
 * {@link #paintControls(Graphics2D, ShapeCreationPanel)}
 */
@Override
public void paint(Graphics g0, JComponent c) {
	ShapeCreationPanel scp = (ShapeCreationPanel) c;
	Graphics2D g = (Graphics2D) g0.create();
	g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
			RenderingHints.VALUE_ANTIALIAS_ON);
	g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
			RenderingHints.VALUE_STROKE_PURE);
	paintShapes((Graphics2D) g, scp);
	paintControls((Graphics2D) g, scp);
	g.dispose();
}
 
Example #24
Source File: FlatMenuBarBorder.java    From FlatLaf with Apache License 2.0 5 votes vote down vote up
@Override
public void paintBorder( Component c, Graphics g, int x, int y, int width, int height ) {
	Graphics2D g2 = (Graphics2D) g.create();
	try {
		float lineHeight = scale( (float) 1 );

		FlatUIUtils.setRenderingHints( g2 );
		g2.setColor( borderColor );
		g2.fill( new Rectangle2D.Float( x, y + height - lineHeight, width, lineHeight ) );
	} finally {
		g2.dispose();
	}
}
 
Example #25
Source File: bug7181438.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static BufferedImage createBufferedImage() {
    final BufferedImage bi = new BufferedImage(SIZE, SIZE,
                                               BufferedImage.TYPE_INT_RGB);
    final Graphics bg = bi.getGraphics();
    //Black color and alpha = 0
    bg.setColor(new Color(0, 0, 0, 0));
    bg.fillRect(0, 0, SIZE, SIZE);
    bg.dispose();
    return bi;
}
 
Example #26
Source File: bug8032667_image_diff.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
static BufferedImage getImage(JComponent component, int scale, int width, int height) {
    final BufferedImage image = new BufferedImage(
            scale * width, scale * height, BufferedImage.TYPE_INT_ARGB);
    final Graphics g = image.getGraphics();
    ((Graphics2D) g).scale(scale, scale);
    component.paint(g);
    g.dispose();
    return image;
}
 
Example #27
Source File: TextRenderTests.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public void runTest(Object ctx, int numReps) {
    TextContext tctx = (TextContext)ctx;
    Graphics g = tctx.graphics;
    g.setFont(tctx.font);
    try {
        byte[] bytes = tctx.text.getBytes("ASCII"); // only good for english
        do {
            g.drawBytes(bytes, 0, bytes.length, 40, 40);
        } while (--numReps >= 0);
    }
    catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example #28
Source File: AltTabCrashTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void paint(Graphics g, Color c) {
    if (c == null) {
        g.setColor(color);
    } else {
        g.setColor(c);
    }
    g.drawString(text, x, y);
}
 
Example #29
Source File: Drawer.java    From algorithms-nutshell-2ed with MIT License 5 votes vote down vote up
/**
 * Draw marker for player in specific location.
 * 
 * @param g    Graphics object that controls the drawing
 * @param c    column of cell to draw
 * @param r    row of cell to draw
 * @param m    char to draw (or ' ' for empty space)
 */
private void drawSpot(Graphics g, int c, int r, char m) {
	// erase if SPACE
	if (m == TicTacToeBoard.EMPTY) {
		g.setColor(Color.lightGray);
		g.fillRect(30 + CELLSIZE*c, 30+CELLSIZE*r, 40, 40);
		return;
	}
	
	// draw extra large character. 
	// NOTE THAT DRAW STRING IS THE ONLY METHOD THAT DEMANDS
	// THE ANCHOR FOR THE COORDINATES BE LOWER LEFT CORNER
	g.setColor (Color.black);
	g.drawString ("" + m, 40+CELLSIZE*c, 60+CELLSIZE*r);
}
 
Example #30
Source File: InternalWindow.java    From stendhal with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create the close and minimize icons.
 */
private static void createIcons() {
	GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
	Image bg = createIconBackground(gc);

	// copy bg for drawing
	Image image = gc.createCompatibleImage(TITLEBAR_HEIGHT, TITLEBAR_HEIGHT, Transparency.OPAQUE);
	Graphics g = image.getGraphics();
	g.drawImage(bg, 0, 0, null);
	closeIcon = createCloseIcon(image);

	// now we can draw over the background image
	minimizeIcon = createMinimizeIcon(bg);
}