Java Code Examples for java.awt.Graphics

The following examples show how to use java.awt.Graphics. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: megamek   Source File: MiniMap.java    License: 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 2
Source Project: gcs   Source File: WeaponDescriptionCell.java    License: 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 3
Source Project: hottub   Source File: Clock.java    License: GNU General Public License v2.0 6 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 4
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 5
Source Project: visualvm   Source File: ProfilerTreeTable.java    License: 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 6
Source Project: jsyn   Source File: EnvelopeEditorBox.java    License: 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 7
Source Project: netbeans   Source File: ListCompletionView.java    License: 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 8
Source Project: lgmodeler   Source File: IconSelectMatrix.java    License: 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 9
Source Project: magarena   Source File: CardsCanvas.java    License: 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 10
Source Project: lsdpatch   Source File: StretchIcon.java    License: MIT License 5 votes vote down vote up
/**
 * Paints the icon. The image is reduced or magnified to fit the component to which it is painted.
 * <P>
 * If the proportion has not been specified, or has been specified as <code>true</code>, the aspect ratio of the image will be preserved
 * by padding and centering the image horizontally or vertically. Otherwise the image may be distorted to fill the component it is
 * painted to.
 * <P>
 * If this icon has no image observer,this method uses the <code>c</code> component as the observer.
 *
 * @param c the component to which the Icon is painted. This is used as the observer if this icon has no image observer
 * @param g the graphics context
 * @param x not used.
 * @param y not used.
 *
 * @see ImageIcon#paintIcon(java.awt.Component, java.awt.Graphics, int, int)
 */
@Override
public synchronized void paintIcon(Component c, Graphics g, int x, int y)
{
    Image image = getImage();
    if (image == null)
    {
        return;
    }
    Insets insets = ((Container) c).getInsets();
    x = insets.left;
    y = insets.top;

    int w = c.getWidth() - x - insets.right;
    int h = c.getHeight() - y - insets.bottom;

    if (proportionate)
    {
        int iw = image.getWidth(c);
        int ih = image.getHeight(c);

        if ((iw * h) < (ih * w))
        {
            iw = (h * iw) / ih;
            x += (w - iw) / 2;
            w = iw;
        }
        else
        {
            ih = (w * ih) / iw;
            y += (h - ih) / 2;
            h = ih;
        }
    }
    ImageObserver io = getImageObserver();
    g.drawImage(image, x, y, w, h, io == null ? c : io);
}
 
Example 11
@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 12
Source Project: chipster   Source File: ImageViewer.java    License: 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 13
Source Project: javagame   Source File: MainPanel.java    License: 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 14
Source Project: magarena   Source File: ZoneBackgroundLabel.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void drawThemeBackground(final Graphics g) {
    switch (MagicStyle.getTheme().getValue(Theme.VALUE_GAME_LAYOUT)) {
        case 1:
            drawLayout1(g);
            break;
        case 2:
            drawLayout2(g);
            break;
        case 3:
            drawLayout3(g);
            break;
    }
    drawBattlefieldBorder(g);
}
 
Example 15
Source Project: osp   Source File: DrawableTextLine.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
* Draws the TextLine using world units for x and y.
*
* @param panel DrawingPanel
* @param g Graphics
*/
  
  void drawWithPix(DrawingPanel panel, Graphics g) {
	  if(OSPRuntime.isMac()){
		  drawWithPixMac( panel,  g);
	  }else{
		  drawWithPixWindows( panel,  g);	 
	  }
  }
 
Example 16
Source Project: Any-Angle-Pathfinding   Source File: GridGraphDrawer.java    License: The Unlicense 5 votes vote down vote up
private void drawSquare(Graphics g, int x, int y) {
    float width = (float)resX/gridGraph.sizeX;
    float height = (float)resY/gridGraph.sizeY;
    float xPos = width*x;
    float yPos = height*y;
    
    g.fillRect((int)xPos,(int)yPos,(int)width+1,(int)height+1);
}
 
Example 17
private void runTest(Graphics g) {
    int status = IMAGE_OK;
    int count1 = 0;
    do {
        GraphicsConfiguration gc = getGraphicsConfiguration();
        int count2 = 0;
        while (vi == null || (status = vi.validate(gc)) != IMAGE_OK) {
            if (++count2 > LOOP_THRESHOLD) {
                System.err.println("Infinite loop detected: count2="+count2);
                failed = true;
                return;
            }
            if (vi == null || status == IMAGE_INCOMPATIBLE) {
                if (vi != null) { vi.flush(); vi = null; }
                vi = gc.createCompatibleVolatileImage(100, 100);
                continue;
            }
            if (status == IMAGE_RESTORED) {
                Graphics gg = vi.getGraphics();
                gg.setColor(Color.green);
                gg.fillRect(0, 0, vi.getWidth(), vi.getHeight());
                break;
            }
        }
        g.drawImage(vi, getInsets().left, getInsets().top, null);
        if (++count1 > LOOP_THRESHOLD) {
            System.err.println("Infinite loop detected: count1="+count1);
            failed = true;
            return;
        }
    } while (vi.contentsLost());
}
 
Example 18
Source Project: JAVA-MVC-Swing-Monopoly   Source File: Buildings.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 
 * ���ƽ�����
 * 
 */
private void paintBuildings(Graphics g) {
	for(Building temp : this.building){
		// ���ݻ���
		paintBuilding(temp,g);
	}
}
 
Example 19
Source Project: netbeans   Source File: DragManager.java    License: 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 20
Source Project: pumpernickel   Source File: ShapeCreationUI.java    License: 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 21
Source Project: FlatLaf   Source File: FlatMenuBarBorder.java    License: 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 22
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 23
Source Project: openjdk-jdk9   Source File: AltTabCrashTest.java    License: 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 24
Source Project: stendhal   Source File: InternalWindow.java    License: 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);
}
 
Example 25
Source Project: ECG-Viewer   Source File: MainFrame.java    License: 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 26
Source Project: algorithms-nutshell-2ed   Source File: Drawer.java    License: 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 27
Source Project: ET_Redux   Source File: UncertaintyGraphPanel.java    License: 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 28
Source Project: openjdk-jdk9   Source File: AltTabCrashTest.java    License: 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 29
Source Project: openjdk-jdk8u-backup   Source File: XYZApp.java    License: GNU General Public License v2.0 5 votes vote down vote up
void paint(Graphics gc, int x, int y, int r) {
    Image ba[] = balls;
    if (ba == null) {
        Setup();
        ba = balls;
    }
    Image i = ba[r];
    int size = 10 + r;
    gc.drawImage(i, x - (size >> 1), y - (size >> 1), size, size, applet);
}
 
Example 30
Source Project: 3Dscript   Source File: BasicTextField.java    License: 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 31
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 32
Source Project: TencentKona-8   Source File: bug7181438.java    License: 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 33
Source Project: JDKSourceCode1.8   Source File: ParsedSynthStyle.java    License: 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 34
Source Project: openjdk-8-source   Source File: XYZApp.java    License: 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 35
Source Project: jdk8u-jdk   Source File: BasicIconFactory.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void paintIcon(Component c, Graphics g, int x, int y) {
    AbstractButton b = (AbstractButton) c;
    ButtonModel model = b.getModel();
    if (b.isSelected() == true) {
        g.fillOval(x+1, y+1, getIconWidth(), getIconHeight());
    }
}
 
Example 36
Source Project: openjdk-jdk8u   Source File: CLSFractal.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void draw(Graphics g) {
    float x = X + (float) Math.cos(angle) * scaleX;
    float y = Y + (float) Math.sin(angle) * scaleY;
    g.drawLine((int) X + xoff, (int) Y + yoff,
            (int) x + xoff, (int) y + yoff);
    X = x;
    Y = y;
}
 
Example 37
Source Project: Bytecoder   Source File: ParsedSynthStyle.java    License: Apache License 2.0 5 votes vote down vote up
public void paintTabbedPaneTabAreaBackground(SynthContext context,
                                             Graphics g, int x, int y,
                                             int w, int h,
                                             int orientation) {
    for (SynthPainter painter: painters) {
        painter.paintTabbedPaneTabAreaBackground(context, g, x, y, w, h,
                                                 orientation);
    }
}
 
Example 38
Source Project: hottub   Source File: PrintJob2D.java    License: 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 39
Source Project: openjdk-8-source   Source File: CSSBorder.java    License: 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 40
Source Project: Java8CN   Source File: ParsedSynthStyle.java    License: Apache License 2.0 4 votes vote down vote up
public void paintSeparatorBorder(SynthContext context, Graphics g,
                                 int x, int y, int w, int h) {
    for (SynthPainter painter: painters) {
        painter.paintSeparatorBorder(context, g, x, y, w, h);
    }
}