/** * Write the given text string in the current font, left-aligned at (x, y). * * @param x the x-coordinate of the text * @param y the y-coordinate of the text * @param s the text */ public static void textLeft(double x, double y, String s) { offscreen.setFont(font); FontMetrics metrics = offscreen.getFontMetrics(); double xs = scaleX(x); double ys = scaleY(y); int hs = metrics.getDescent(); offscreen.drawString(s, (float) (xs), (float) (ys + hs)); draw(); }
private void paintString( Graphics g, int x, int y, int width, int height, int fillStart, int amountFull, Insets b) { if (!(g instanceof Graphics2D)) { return; } Graphics2D g2D = (Graphics2D) g; String progressString = progressBar.getString(); g2D.setFont(progressBar.getFont()); Point renderLocation = getStringPlacement(g2D, progressString, x, y, width, height); Rectangle savedClip = g2D.getClipBounds(); if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) { g2D.setColor(getSelectionBackground()); Utilities.drawString(progressBar, g2D, progressString, renderLocation.x, renderLocation.y); g2D.setColor(getSelectionForeground()); g2D.clipRect(fillStart, y, amountFull, height); Utilities.drawString(progressBar, g2D, progressString, renderLocation.x, renderLocation.y); } else { // VERTICAL g2D.setColor(getSelectionBackground()); AffineTransform rotate = AffineTransform.getRotateInstance(Math.PI / 2); g2D.setFont(progressBar.getFont().deriveFont(rotate)); renderLocation = getStringPlacement(g2D, progressString, x, y, width, height); Utilities.drawString(progressBar, g2D, progressString, renderLocation.x, renderLocation.y); g2D.setColor(getSelectionForeground()); g2D.clipRect(x, fillStart, width, amountFull); Utilities.drawString(progressBar, g2D, progressString, renderLocation.x, renderLocation.y); } g2D.setClip(savedClip); }
public void paint(Graphics gOld) { if (image == null || xsize != getSize().width || ysize != getSize().height) { xsize = getSize().width; ysize = getSize().height; image = createImage(xsize, ysize); g = (Graphics2D) image.getGraphics(); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); } // fill background g.setColor(Color.cyan); g.fillRect(0, 0, xsize, ysize); int x[] = {getX(0), getX(getWidth2()), getX(getWidth2()), getX(0), getX(0)}; int y[] = {getY(0), getY(0), getY(getHeight2()), getY(getHeight2()), getY(0)}; // fill border g.setColor(Color.black); g.fillPolygon(x, y, 4); // draw border g.setColor(Color.red); g.drawPolyline(x, y, 5); if (animateFirstTime) { gOld.drawImage(image, 0, 0, null); return; } if (gameOver) return; g.drawImage(outerSpaceImage, getX(0), getY(0), getWidth2(), getHeight2(), this); for (int index = 0; index < missile.length; index++) { if (missile[index].active) { g.setColor(Color.red); drawCircle(getX(missile[index].xPos), getYNormal(missile[index].yPos), 90, .3, 1.5); } } if (rocketRight) { drawRocket(rocketImage, getX(rocketXPos), getYNormal(rocketYPos), 0.0, 2.0, 2.0); } else { drawRocket(rocketImage, getX(rocketXPos), getYNormal(rocketYPos), 0.0, -2.0, 2.0); } for (int index = 0; index < numStars; index++) { g.setColor(Color.yellow); if (starActive[index]) drawCircle(getX(starXPos[index]), getYNormal(starYPos[index]), 0, 1.5, 1.5); } g.setColor(Color.magenta); g.setFont(new Font("Impact", Font.BOLD, 15)); g.drawString("Score: " + score, 10, 45); g.setColor(Color.magenta); g.setFont(new Font("Impact", Font.BOLD, 15)); g.drawString("HighScore: " + highScore, 300, 45); g.setColor(Color.magenta); g.setFont(new Font("Impact", Font.BOLD, 15)); g.drawString("Lives: " + rocketLife, 150, 45); if (rocketLife == 0) { g.setColor(Color.red); g.setFont(new Font("Impact", Font.BOLD, 60)); g.drawString("GAME OVER", getX(getWidth2() / 6), getYNormal(getHeight2() / 2)); } gOld.drawImage(image, 0, 0, null); }
/** * Drawer : draw the variable label of the component. * * @param g Graphics2D of the component (casted from getGraphics). * @param x x-cordinates of the label * @param y y-cordinates of the label * @param theta rotation (radians) of the label * @param label Drawn String. */ private void drawString2(Graphics2D g, double x, double y, double theta, String label) { g.setPaint(grid); AffineTransform fontAT = new AffineTransform(); Font theFont = g.getFont(); fontAT.rotate(theta); Font theDerivedFont = theFont.deriveFont(fontAT); g.setFont(theDerivedFont); g.drawString(label, (int) x, (int) y); g.setFont(theFont); }
@Override // TODO Auto-generated method stub public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; // Draws the two initial two YinYang symbols on the frame g2.setColor(color1); if (timeLeft < 6000) { g2.rotate(degrees, yin1X + (yin1Width / 2), yin1Y + (yin1Height / 2)); } g2.fill(new MyYinYang(yin1X, yin1Y, yin1Width, yin1Height)); if (timeLeft < 6000) { g2.rotate(-degrees, yin1X + (yin1Width / 2), yin1Y + (yin1Height / 2)); } g2.setColor(color2); if (timeLeft < 6000) { g2.rotate(degrees, yin2X + (yin2Width / 2), yin2Y + (yin2Height / 2)); } g2.fill(new MyYinYang(yin2X, yin2Y, yin2Width, yin2Height)); if (timeLeft < 6000) { g2.rotate(-degrees, yin2X + (yin2Width / 2), yin2Y + (yin2Height / 2)); } // Alters and prints the text on the screen g2.setColor(Color.BLACK); g2.setFont(font); g2.drawString("Score", 700, 25); g2.drawString(Integer.toString(points), 700, 75); g2.drawString("Misses", 800, 25); g2.drawString(Integer.toString(misses), 800, 75); g2.drawString("Time Left", 700, 110); timeDisplay = timeLeft / 100.0; g2.drawString(timeDisplay.toString(), 700, 160); }
private boolean paintPlaceholderText(Graphics2D g) { CharSequence hintText = myEditor.getPlaceholder(); EditorComponentImpl editorComponent = myEditor.getContentComponent(); if (myDocument.getTextLength() > 0 || hintText == null || hintText.length() == 0 || KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner() == editorComponent && !myEditor.getShowPlaceholderWhenFocused()) { return false; } hintText = SwingUtilities.layoutCompoundLabel( g.getFontMetrics(), hintText.toString(), null, 0, 0, 0, 0, editorComponent.getBounds(), new Rectangle(), new Rectangle(), 0); g.setColor(myEditor.getFoldingModel().getPlaceholderAttributes().getForegroundColor()); g.setFont(myEditor.getColorsScheme().getFont(EditorFontType.PLAIN)); g.drawString(hintText.toString(), 0, myView.getAscent()); return true; }
@Override public void paint(Graphics g) { Graphics2D g2d = (Graphics2D) g; Color old = g2d.getColor(); // Draw box g2d.setColor( clicked ? this.clickedBackColor : (hovering ? this.hoverBackColor : this.unclickedBackColor)); g2d.fillRect(0, 0, getWidth(), getHeight()); // Draw label g2d.setColor( clicked ? this.clickedForeColor : (hovering ? this.hoverForeColor : this.unclickedForeColor)); g2d.setFont(getFont()); int width = g2d.getFontMetrics().stringWidth(getText()); int textHeight = getFont().getSize(); int otherTextHeight = getFontMetrics(getFont()).getHeight(); textHeight = textHeight - (otherTextHeight - textHeight); int height = textHeight + (getHeight() - textHeight) / 2; g2d.drawString(getText(), (getWidth() - width) / 2, height); g2d.setColor(old); }
@Override protected void paintWidget() { Graphics2D g = getGraphics(); g.setStroke(Util.STROKE_2); g.setFont(getFont()); Rectangle bounds = getBounds(); String text = Util.node(this).toString(); if (text.length() == 0) { g.setColor((Color) getBackground()); g.fillOval(bounds.x, bounds.y, bounds.width - 1, bounds.height - 1); g.setColor(getForeground()); g.drawOval(bounds.x, bounds.y, bounds.width - 1, bounds.height - 1); } else { g.setColor((Color) getBackground()); int arc = (bounds.height - 1); g.fillRoundRect(bounds.x, bounds.y, bounds.width - 1, bounds.height - 1, arc, arc); g.setColor(getForeground()); g.drawString( text, bounds.x + (bounds.height - 1) / 2, bounds.y + bounds.height - vborder - 1 - g.getFontMetrics().getMaxDescent()); g.drawRoundRect(bounds.x, bounds.y, bounds.width - 1, bounds.height - 1, arc, arc); } }
protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); int w = getWidth(); int h = getHeight(); int pointSize = Math.max(Math.min(w, h) / 80, 4); double xInc = (double) (w - 2 * PAD) / (MAX_X - 1); double scale = (double) (h - 2 * PAD) / MAX_Y; // Draw abcissa. int tickInc = MAX_X / 10; for (int i = 0; i <= MAX_X; i += tickInc) { int x = PAD + (int) (i * xInc); int y = h - PAD; g.drawString(Integer.toString(i), x - 5, y + 20); g2.draw(new Line2D.Double(x, y - 5, x, y + 5)); } g2.draw(new Line2D.Double(PAD, h - PAD, w - PAD / 2, h - PAD)); AffineTransform orig = g2.getTransform(); g2.rotate(-Math.PI / 2); g2.setColor(Color.black); g2.drawString("Number of comparisons", -((h + PAD) / 2), PAD / 3); g2.setTransform(orig); // Draw ordinate. tickInc = (h - PAD) / 10; for (int i = tickInc; i < h - PAD; i += tickInc) { int x = PAD; int closest_10 = ((int) (i / scale) / 10) * 10; int y = h - PAD - (int) (closest_10 * scale); if (y < PAD) break; String tickMark = Integer.toString(closest_10); int stringLen = (int) g2.getFontMetrics().getStringBounds(tickMark, g2).getWidth(); g.drawString(tickMark, x - stringLen - 8, y + 5); g2.draw(new Line2D.Double(x - 5, y, x + 5, y)); } g2.draw(new Line2D.Double(PAD, PAD / 2, PAD, h - PAD)); g.drawString("Array Size", (w - PAD) / 2, h - PAD + 40); for (int index = 0; index < plot_data.size(); index++) { int[] data = plot_data.get(index); // Mark data points. g2.setPaint(plot_colors.get(index)); for (int i = 0; i < data.length; i++) { double x = PAD + i * xInc; double y = h - PAD - scale * data[i]; g2.fill(new Ellipse2D.Double(x - pointSize / 2, y - pointSize / 2, pointSize, pointSize)); } g2.setFont(textFont); int stringHeight = (int) g2.getFontMetrics().getStringBounds(plot_names.get(index), g2).getHeight(); g.drawString(plot_names.get(index), PAD + 20, PAD + (index + 1) * stringHeight); } }
public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; String message = "Hello, World!"; Font f = new Font("Serif", Font.BOLD, 36); g2.setFont(f); FontRenderContext context = g2.getFontRenderContext(); Rectangle2D bounds = f.getStringBounds(message, context); double x = (getWidth() - bounds.getWidth()) / 2; double y = (getHeight() - bounds.getHeight()) / 2; double ascent = -bounds.getY(); double baseY = y + ascent; g2.drawString(message, (int) x, (int) baseY); g2.setPaint(Color.LIGHT_GRAY); g2.draw(new Line2D.Double(x, baseY, x + bounds.getWidth(), baseY)); Rectangle2D rect = new Rectangle2D.Double(x, y, bounds.getWidth(), bounds.getHeight()); g2.draw(rect); }
@Override public void paint(Graphics g) { super.paint(g); if (g instanceof Graphics2D) { Graphics2D g2d = (Graphics2D) g; if (blackOutEnabled) { // background g2d.setColor(Color.BLACK); g2d.fillRect(0, 0, this.getWidth(), this.getHeight()); } else if (whiteOutEnabled) { // background g2d.setColor(Color.WHITE); g2d.fillRect(0, 0, this.getWidth(), this.getHeight()); } else { // background g2d.setColor(backgroundColor); g2d.fillRect(0, 0, this.getWidth(), this.getHeight()); // text if (font == null) font = GuiHelper.maxFontSize(frame.getWidth(), frame.getHeight(), fontName, timeFormat); if (textY == -1) textY = GuiHelper.getTextYForCenter(timeFormat, font, frame.getHeight()); g2d.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); g2d.setFont(font); g2d.setColor(textColor); g2d.drawString(timeToString(time), 0, textY); } } }
public void paint(java.awt.Graphics g) { if (element != null) { Rectangle bounds = element.jGetBounds(); Graphics2D g2 = (Graphics2D) g; g2.setFont(font); int mitteX = bounds.x + (bounds.width) / 2; int mitteY = bounds.y + (bounds.height) / 2; int distanceY = 10; g2.setColor(new Color(204, 204, 255)); g2.fillRect(bounds.x, mitteY - distanceY, bounds.width, 2 * distanceY); g2.setColor(Color.BLACK); g2.drawRect(bounds.x, mitteY - distanceY, bounds.width, 2 * distanceY); String caption = "dec(" + variable.getValue() + ")"; FontMetrics fm = g2.getFontMetrics(); Rectangle2D r = fm.getStringBounds(caption, g2); g2.setColor(Color.BLACK); g.drawString( caption, mitteX - (int) (r.getWidth() / 2), (int) (mitteY + fm.getHeight() / 2) - 3); } super.paint(g); }
public void paint(Graphics g) { gRef = (Graphics2D) g; // change size of font gRef.setFont(gRef.getFont().deriveFont(9.0f)); fmRef = g.getFontMetrics(); // Clear background if (Preferences.monochrome) { gRef.setColor(Preferences.whiteColor); } else { gRef.setColor(Preferences.backgroundColor); } gRef.fillRect(0, 0, getWidth(), getHeight()); // set colour to correct drawing colour if (Preferences.monochrome) { gRef.setColor(Preferences.blackColor); } else { gRef.setColor(Preferences.penColor); } gRef.translate(0, margin); // Call c code to draw tree gRef.scale(scale, scale); nativeDrawTree(); }
@Override protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g.create(); int width = getWidth(); int height = getHeight(); // rendering hints g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); // formatter DecimalFormat format = new DecimalFormat("##.#%"); // text to display String percentage = (value == null || Double.parseDouble(value.toString()) == -1) ? "" : format.format(Double.parseDouble(value.toString())); // paint text g2.setColor(Color.black); g2.setFont(g2.getFont().deriveFont(Font.BOLD)); FontMetrics fontMetrics = g2.getFontMetrics(); int textWidth = fontMetrics.stringWidth(percentage); int xPos = (width - textWidth) / 2; int yPos = height / 2 + fontMetrics.getDescent() + 2; g2.drawString(percentage, xPos, yPos); g2.dispose(); }
@Override public void paintComponent(Graphics window) { super.paintComponent(window); Image bufferedImage = createImage(getWidth(), getHeight()); Graphics2D g2d = (Graphics2D) bufferedImage.getGraphics(); g2d.setPaint(gradient1); g2d.fillRect(0, 0, 300, 1000); if (showInstructions == true) { g2d.setColor(Color.YELLOW); g2d.setFont(font1); g2d.drawString("Instructions:", 10, 150); g2d.setFont(font3); g2d.drawString("To Play, Click New Game", 10, 200); g2d.drawString("Each game costs $1", 10, 230); g2d.drawString("Hit adds a card to your hand", 10, 260); g2d.drawString("Stand stops the game and", 10, 290); g2d.drawString("calculates each persons score", 10, 320); g2d.drawString("To play dealer, click Play Dealer", 10, 350); g2d.drawString("Enter your desired wager", 10, 380); g2d.drawString("Every time you score 20 or 21", 10, 470); g2d.drawString("you get one arcade token", 10, 500); g2d.drawString("Arcade Tokens can be redeemed", 10, 530); g2d.drawString("By closing instructions and clicking", 10, 560); g2d.drawString("Play Arcade Game", 10, 590); } else { g2d.setColor(Color.YELLOW); g2d.setFont(font1); g2d.drawString("Arcade Game:", 10, 250); g2d.setFont(font3); g2d.drawString("Select the game you would like", 10, 320); g2d.drawString("Click Play to Play.", 10, 350); g2d.drawString("Hold and Drag the Mouse", 10, 380); g2d.drawString("to move in Cube Runner", 10, 410); g2d.drawString("Press the mouse to sprint", 10, 440); g2d.drawString("in Spiral Game, and click", 10, 500); g2d.drawString("to Jump", 10, 530); g2d.drawString("Each game costs one token", 10, 560); g2d.drawString("", 10, 590); } g2d.setColor(Color.YELLOW); g2d.setFont(font1); g2d.drawString("Tokens: " + tempObject.tokens, 10, 700); window.drawImage(bufferedImage, 0, 0, this); }
public void draw(Graphics2D g2, boolean shouldFlip) { Font font = new Font("Sans_Serif", Font.PLAIN, 30); g2.setColor(Color.orange); g2.fillOval((int) x - 10, (int) (FieldConstants.FIELD_HEIGHT - y - 10), 20, 20); font = new Font("Sans_Serif", Font.PLAIN, 18); g2.setFont(font); g2.drawString(Double.toString(confidence), x, FieldConstants.FIELD_HEIGHT - y + 60); }
public void paintComponent(Graphics g) { // необходиом чтобы текст коректно отрисовывался в окне super.paintComponent(g); // рисуем текст в окне Graphics2D g2 = (Graphics2D) g; AffineTransform t = g2.getTransform(); g.drawString("It is text", 5, 5); // создание шрифта Font f = new Font("SanasSerif", Font.ITALIC, 20); g2.setFont(f); g2.drawString("It is new text", 5, 33); String[] fontNames = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames(); for (int i = 5; i < 20; i++) { g2.rotate(-0.05); g2.setColor( new Color( (int) (Math.random() * 255), (int) (Math.random() * 255), (int) (Math.random() * 255))); Font f1 = new Font(fontNames[i], Font.BOLD, 20); g2.setFont(f1); g2.drawString(fontNames[i], 5, 20 * i); } // текст в центре g2.setTransform(t); // возращение к кординатам, которые запонилив начале Font f2 = new Font("SanasSerif", Font.ITALIC, 20); g2.setFont(f2); String s = "It is center!"; FontRenderContext context = g2.getFontRenderContext(); Rectangle2D r = f2.getStringBounds(s, context); double x1 = (getWidth() - r.getWidth()) / 2; double y1 = (getHeight() - r.getHeight()) / 2; double ascent = -r.getY(); // узнаем высоту текста double y2 = y1 + ascent; Rectangle2D rect = new Rectangle2D.Double(x1, y1, r.getWidth(), r.getHeight()); g2.setColor(Color.YELLOW); g2.fill(rect); g2.setColor(Color.red); g2.drawString(s, (int) x1, (int) y2); g2.setColor(Color.blue); g2.draw(new Line2D.Double(x1, y2, x1 + r.getWidth(), y2)); g2.draw(rect); }
public void paintComponent(Graphics graphics) { super.paintComponent(graphics); Graphics2D graphics2D = (Graphics2D) graphics; graphics2D.translate(getWidth() / 2, getHeight() / 2); graphics2D.setFont(font); graphics2D.drawString(string, 0, 0); }
private void drawTile(Graphics g2, Tile tile, int x, int y) { Graphics2D g = ((Graphics2D) g2); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE); int value = tile.value; int xOffset = offsetCoors(x); int yOffset = offsetCoors(y); g.setColor(tile.getBackground()); g.fillRoundRect(xOffset, yOffset, TILE_SIZE, TILE_SIZE, 14, 14); g.setColor(tile.getForeground()); final int size = value < 100 ? 36 : value < 1000 ? 32 : 24; final Font font = new Font(FONT_NAME, Font.BOLD, size); g.setFont(font); String s = String.valueOf(value); final FontMetrics fm = getFontMetrics(font); final int w = fm.stringWidth(s); final int h = -(int) fm.getLineMetrics(s, g).getBaselineOffsets()[2]; if (value != 0) g.drawString(s, xOffset + (TILE_SIZE - w) / 2, yOffset + TILE_SIZE - (TILE_SIZE - h) / 2 - 2); if (myWin || myLose) { g.setColor(new Color(255, 255, 255, 30)); g.fillRect(0, 0, getWidth(), getHeight()); g.setColor(new Color(78, 139, 202)); g.setFont(new Font(FONT_NAME, Font.BOLD, 48)); if (myWin) { g.drawString("You won!", 68, 150); } if (myLose) { g.drawString("Game over!", 50, 130); g.drawString("You lose!", 64, 200); } if (myWin || myLose) { g.setFont(new Font(FONT_NAME, Font.PLAIN, 16)); g.setColor(new Color(128, 128, 128, 128)); g.drawString("Press ESC to play again", 80, getHeight() - 40); } } g.setFont(new Font(FONT_NAME, Font.PLAIN, 18)); g.drawString("Score: " + myScore, 200, 365); }
/** * Draw every char in separate terminal cell to guaranty equal width for different lines. * Nevertheless to improve kerning we draw word characters as one block for monospaced fonts. */ private void drawChars(int x, int y, CharBuffer buf, TextStyle style, Graphics2D gfx) { final int blockLen = 1; int offset = 0; int drawCharsOffset = 0; // workaround to fix Swing bad rendering of bold special chars on Linux // TODO required for italic? CharBuffer renderingBuffer; if (mySettingsProvider.DECCompatibilityMode() && style.hasOption(TextStyle.Option.BOLD)) { renderingBuffer = CharUtils.heavyDecCompatibleBuffer(buf); } else { renderingBuffer = buf; } while (offset + blockLen <= buf.length()) { if (renderingBuffer.getBuf()[buf.getStart() + offset] == CharUtils.DWC) { offset += blockLen; drawCharsOffset += blockLen; continue; // dont' draw second part(fake one) of double width character } Font font = getFontToDisplay(buf.charAt(offset + blockLen - 1), style); // while (myMonospaced && (offset + blockLen < buf.getLength()) && // isWordCharacter(buf.charAt(offset + blockLen - 1)) // && (font == getFontToDisplay(buf.charAt(offset + blockLen - 1), style))) { // blockLen++; // } gfx.setFont(font); int descent = gfx.getFontMetrics(font).getDescent(); int baseLine = (y + 1) * myCharSize.height - descent; int xCoord = (x + drawCharsOffset) * myCharSize.width; int textLength = CharUtils.getTextLengthDoubleWidthAware( buf.getBuf(), buf.getStart() + offset, blockLen, mySettingsProvider.ambiguousCharsAreDoubleWidth()); int yCoord = y * myCharSize.height; gfx.setClip( xCoord, yCoord, Math.min(textLength * myCharSize.width, getWidth() - xCoord), Math.min(myCharSize.height, getHeight() - yCoord)); gfx.setColor(getPalette().getColor(myStyleState.getForeground(style.getForegroundForRun()))); gfx.drawChars(renderingBuffer.getBuf(), buf.getStart() + offset, blockLen, xCoord, baseLine); drawCharsOffset += blockLen; offset += blockLen; } gfx.setClip(null); }
/** Draw vertices on top of the edge structure */ public void drawNodes(Graphics2D gg) { Enumeration nodeList = argument.getBreadthFirstTraversal().elements(); // Run through the traversal and draw each vertex // using an Ellipse2D // The draw point has been determined previously in // calcNodeCoords() while (nodeList.hasMoreElements()) { TreeVertex vertex = (TreeVertex) nodeList.nextElement(); // Don't draw virtual nodes if (vertex.isVirtual()) continue; // If tree is incomplete and we're on the top layer, skip it if (argument.isMultiRoots() && vertex.getLayer() == 0) continue; Point corner = vertex.getDrawPoint(); Shape node = new Ellipse2D.Float(corner.x, corner.y, NODE_DIAM, NODE_DIAM); vertex.setShape(node, this); // Fill the interior of the node with vertex's fillPaint gg.setPaint(vertex.fillPaint); gg.fill(node); // Draw the outline with vertex's outlinePaint; bold if selected gg.setPaint(vertex.outlinePaint); if (vertex.isSelected()) { gg.setStroke(selectStroke); } else { gg.setStroke(solidStroke); } gg.draw(node); // Draw the short label on top of the vertex gg.setPaint(vertex.textPaint); String shortLabelString = new String(vertex.getShortLabel()); if (shortLabelString.length() == 1) { gg.setFont(labelFont1); gg.drawString(shortLabelString, corner.x + NODE_DIAM / 4, corner.y + 3 * NODE_DIAM / 4); } else if (shortLabelString.length() == 2) { gg.setFont(labelFont2); gg.drawString(shortLabelString, corner.x + NODE_DIAM / 5, corner.y + 3 * NODE_DIAM / 4); } } }
@Override public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; // paint ball, paddle, and brick configuration g2.drawImage(background.getImage(), 0, 0, null); bconfig.paint(g2); paddle.paint(g2); ball.paint(g2); g2.setColor(Color.WHITE); g2.setFont(new Font("Serif", Font.PLAIN, 20)); g2.drawString("Score: " + score, 15, 20); if (ball.getY() > 500) { g2.setColor(Color.WHITE); g2.setFont(new Font("Serif", Font.PLAIN, 30)); g2.drawString("Game Over!", 200, 300); g2.drawString("Your final score was " + score, 150, 330); timer.stop(); } }
public void draw(Graphics2D g) { g.setColor(fillColor); g.fill(gp); g.setColor(Color.black); g.draw(gp); for (int i = 0; i < points.size(); i++) { GlyphPoint p = points.get(i); g.setColor(Color.red); g.draw(p.gp); g.setColor(Color.blue); g.setFont(gfont); g.drawString(String.valueOf(i), p.x + 3, p.y + 3); } g.setColor(Color.black); // System.out.println("Advance: "+advance); g.draw(advp); if (name != null) { g.setFont(gfont); g.drawString(name, 0, -40); } }
@Override public void paintComponent(Graphics g) { g.setColor(Color.WHITE); super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; if (isDead) { g2.setColor(Color.BLACK); g2.setFont(new Font("Serif", Font.PLAIN, 30)); g2.drawString("Game Over!", 300, 300); g2.drawString("Your final score was " + score, 250, 330); moverTimer.stop(); scoreTimer.stop(); } else { topWall.paint(g2); bottomWall.paint(g2); bird.paint(g2); g2.setColor(Color.BLACK); g2.setFont(new Font("Serif", Font.PLAIN, 20)); g2.drawString("Score: " + score, 50, 50); } }
private synchronized void doBuffer(Graphics2D g2, boolean opq, Rectangle rt) { origTransform = g2.getTransform(); if (opq && rt != null) g2.clearRect(rt.x, rt.y, rt.width, rt.height); g2.setPaint(origPaint); g2.setFont(origFont); g2.setStroke(origStroke); if (inBuffer) { // System.out.println("upps"); for (int i = 0; i < a1x.size(); i++) doPaint(g2, a1x.get(i), a2x.get(i)); origTransform = null; return; } for (int i = 0; i < a1.size(); i++) doPaint(g2, a1.get(i), a2.get(i)); origTransform = null; }
@Override protected void paintComponent(final Graphics g) { String s = getText(); final Rectangle bounds = getBounds(); if (UIUtil.isUnderDarcula()) { g.setColor(UIUtil.getPanelBackground()); g.fillRect(bounds.x, bounds.y, bounds.width, bounds.height); } if (s == null) return; final Insets insets = getInsets(); final Graphics2D g2 = (Graphics2D) g; g2.setFont(getFont()); UIUtil.applyRenderingHints(g2); final FontMetrics fm = g2.getFontMetrics(); final int sWidth = fm.stringWidth(s); int x = insets.left; if (myAlignment == Component.CENTER_ALIGNMENT || myAlignment == Component.RIGHT_ALIGNMENT) { x = myAlignment == Component.CENTER_ALIGNMENT ? (bounds.width - sWidth) / 2 : bounds.width - insets.right - sWidth; } final Rectangle textR = new Rectangle(); final Rectangle iconR = new Rectangle(); final Rectangle viewR = new Rectangle(bounds); textR.x = textR.y = textR.width = textR.height = 0; viewR.width -= insets.left; viewR.width -= insets.right; final int maxWidth = bounds.width - insets.left - insets.right; if (sWidth > maxWidth) { s = truncateText(s, bounds, fm, textR, iconR, maxWidth); } final int y = UIUtil.getStringY(s, bounds, g2); if (SystemInfo.isMac && !UIUtil.isUnderDarcula() && myDecorate) { g2.setColor(myCustomColor == null ? Gray._215 : myCustomColor); g2.drawString(s, x, y + 1); } g2.setColor(myCustomColor == null ? getForeground() : myCustomColor); g2.drawString(s, x, y); }
/** * paintComponent schreibt alle Laendernamen an die entsprechende Stelle der Landkarte * (Hintergrundgrafik) und zeichnet die Laendergrenzen auf der Landkarte nach. * * @param g Zeichenflaeche der Landkarte */ public void paintComponent(Graphics g) { Shape shape; Graphics2D g2d = (Graphics2D) g; g2d.drawImage(img, 0, 0, this.getWidth(), this.getHeight(), this); Font myFont = new Font("Times New Roman", Font.BOLD, 12); g2d.setFont(myFont); g2d.setStroke(new BasicStroke(2.0f)); Territory territory; Color color; ListIterator territories = worldMap.getTerritories().listIterator(); while (territories.hasNext()) { territory = (Territory) territories.next(); if (territory.getOwner() != null) { color = territory.getOwner().getPlayerColor(); } else { color = Color.WHITE; } g2d.setColor(color); g2d.drawString( territory.getName(), (int) territory.getMidpoint().getX() - 15, (int) territory.getMidpoint().getY() - 10); g2d.drawString( new Integer(territory.getArmySize()).toString(), (int) territory.getMidpoint().getX(), (int) territory.getMidpoint().getY()); } if (territoryBattle.size() != 0) { for (int j = 0; j < territoryBattle.size(); j++) { g2d.setColor(territoryBattle.get(j).getOwner().getPlayerColor()); // g2d.fillPolygon(territoryTmp.getFrontiers()); Sieht bei unseren Grenzen nicht huebsch // aus g2d.drawPolygon(territoryBattle.get(j).getFrontiers()); } } repaint(); }
/** set the height, width, and zoom of this window */ public void setMySize(int w, int h, float zoom) { this.zoom = zoom; this.zoom = 1.0f; // ET hack this.setBounds(getX(), getY(), w, h); w -= reservedWidthRight; h -= reservedHeightBottom; lblCanvas.setBounds(0, 0, w, h); synchronized (imgLock) { img = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); Graphics2D gfx = (Graphics2D) img.getGraphics(); gfx.setBackground(Color.WHITE); gfx.setFont(Constants.FONT_DEFAULT); gfx.setComposite(Constants.COMPOSITE_OPAQUE); } }
@Override public void paint(Graphics g) { super.paint(g); Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); int textWidth = g2.getFontMetrics().stringWidth("00:00.00"); int fontSize = getFont().getSize() * getWidth() / textWidth; g2.setFont(getFont().deriveFont((float) Math.min(fontSize, getHeight()))); Rectangle2D bounds = g2.getFontMetrics().getStringBounds(this.text, g2); g2.drawString( this.text, (int) ((getWidth() - bounds.getWidth()) / 2 - bounds.getX()), (int) ((getHeight() - bounds.getHeight()) / 2 - bounds.getY())); }
@Override public void _setTextBadge(IdeFrame frame, String text) { if (!isValid(frame)) { return; } Object icon = null; if (text != null) { try { int size = 55; BufferedImage image = UIUtil.createImage(size, size, BufferedImage.TYPE_INT_ARGB); Graphics2D g = image.createGraphics(); int roundSize = 40; g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setPaint(ERROR_COLOR); g.fillRoundRect( size / 2 - roundSize / 2, size / 2 - roundSize / 2, roundSize, roundSize, size, size); g.setColor(Color.white); Font font = g.getFont(); g.setFont(new Font(font.getName(), font.getStyle(), 22)); FontMetrics fontMetrics = g.getFontMetrics(); int width = fontMetrics.stringWidth(text); g.drawString( text, size / 2 - width / 2, size / 2 - fontMetrics.getHeight() / 2 + fontMetrics.getAscent()); ByteArrayOutputStream bytes = new ByteArrayOutputStream(); Sanselan.writeImage(image, bytes, ImageFormat.IMAGE_FORMAT_ICO, new HashMap()); icon = Win7TaskBar.createIcon(bytes.toByteArray()); } catch (Throwable e) { LOG.error(e); } } try { Win7TaskBar.setOverlayIcon(frame, icon, icon != null); } catch (Throwable e) { LOG.error(e); } }