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 |
@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: MiniMap.java From megamek with GNU General Public License v2.0 | 6 votes |
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 #3
Source File: WeaponDescriptionCell.java From gcs with Mozilla Public License 2.0 | 6 votes |
@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: MotifGraphicsUtils.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
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 File: ProfilerTreeTable.java From visualvm with GNU General Public License v2.0 | 6 votes |
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 File: EnvelopeEditorBox.java From jsyn with Apache License 2.0 | 6 votes |
/** * 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 File: ListCompletionView.java From netbeans with Apache License 2.0 | 6 votes |
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 File: IconSelectMatrix.java From lgmodeler with GNU General Public License v3.0 | 6 votes |
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 File: CardsCanvas.java From magarena with GNU General Public License v3.0 | 6 votes |
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 File: StretchIcon.java From lsdpatch with MIT License | 5 votes |
/** * 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
Source File: ReflectionDemo.java From filthy-rich-clients with BSD 3-Clause "New" or "Revised" License | 5 votes |
@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 File: ImageViewer.java From chipster with MIT License | 5 votes |
@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 File: MainPanel.java From javagame with MIT License | 5 votes |
/** * �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 File: ZoneBackgroundLabel.java From magarena with GNU General Public License v3.0 | 5 votes |
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 File: DrawableTextLine.java From osp with GNU General Public License v3.0 | 5 votes |
/** * 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 File: GridGraphDrawer.java From Any-Angle-Pathfinding with The Unlicense | 5 votes |
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
Source File: InfiniteValidationLoopTest.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
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 File: Buildings.java From JAVA-MVC-Swing-Monopoly with Apache License 2.0 | 5 votes |
/** * * ���ƽ����� * */ private void paintBuildings(Graphics g) { for(Building temp : this.building){ // ���ݻ��� paintBuilding(temp,g); } }
Example #19
Source File: DragManager.java From netbeans with Apache License 2.0 | 5 votes |
public void paint(Graphics g) { g.setXORMode(Color.white); //Color of line varies for (DragItem elem : allItems) { elem.paint(g); } }
Example #20
Source File: ShapeCreationUI.java From pumpernickel with MIT License | 5 votes |
/** * 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 File: FlatMenuBarBorder.java From FlatLaf with Apache License 2.0 | 5 votes |
@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
Source File: TextRenderTests.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
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 File: AltTabCrashTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
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 File: InternalWindow.java From stendhal with GNU General Public License v2.0 | 5 votes |
/** * 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 File: MainFrame.java From ECG-Viewer with GNU General Public License v2.0 | 5 votes |
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 File: Drawer.java From algorithms-nutshell-2ed with MIT License | 5 votes |
/** * 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 File: UncertaintyGraphPanel.java From ET_Redux with Apache License 2.0 | 5 votes |
/** * * @param g */ @Override protected void paintComponent ( Graphics g ) { super.paintComponent( g ); paint( (Graphics2D) g ); }
Example #28
Source File: AltTabCrashTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
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 File: XYZApp.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
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 File: BasicTextField.java From 3Dscript with BSD 2-Clause "Simplified" License | 5 votes |
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); } }