private void shadeExt(Graphics2D g2, int r, int g, int b, int a) { g2.setPaint(new Color(r, g, b, a)); g2.fillRect(0, 0, iw, rect.y); /* _N_ */ g2.fillRect( rect.x + rect.width + 1, rect.y, iw - rect.x - rect.width - 1, rect.height + 1); /* E */ g2.fillRect(0, rect.y, rect.x, rect.height + 1); /* W */ g2.fillRect(0, rect.y + rect.height + 1, iw, ih - rect.y - rect.height - 1); /* _S_ */ }
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); }
// draw on screen public synchronized void draw(Graphics2D g) { Window w = s.getFullScreenWindow(); g.setColor(w.getBackground()); g.fillRect(0, 0, s.getWidth(), s.getHeight()); g.setColor(w.getForeground()); g.drawString(mess, 100, 100); }
// =========================================================== paintComponent @Override public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; // Downcast to Graphics2D // ... One time initialization of in-memory, saved image. if (_bufImage == null) { // ... This is the first time, initialize _bufImage int w = this.getWidth(); int h = this.getHeight(); _bufImage = (BufferedImage) this.createImage(w, h); Graphics2D gc = _bufImage.createGraphics(); gc.setColor(COLOR_BACKGROUND); gc.fillRect(0, 0, w, h); // fill in background } // ... Display the saved image. g2.drawImage(_bufImage, null, 0, 0); // ... Overwrite the screen display with currently dragged image. if (_state == State.DRAGGING) { // ... Write shape that is being dragged over the screen image, // but not into the saved buffered image. It will be written // on the saved image when the mouse is released. drawCurrentShape(g2); } }
/** * Paint a background for all groups and a round blue border and background when a cell is * selected. * * @param g2 the <tt>Graphics2D</tt> object through which we paint */ private void internalPaintComponent(Graphics2D g2) { Color borderColor = Color.GRAY; if (isSelected) { g2.setPaint( new GradientPaint( 0, 0, Constants.SELECTED_COLOR, 0, getHeight(), Constants.SELECTED_GRADIENT_COLOR)); borderColor = Constants.SELECTED_COLOR; } else if (treeNode instanceof GroupNode) { g2.setPaint( new GradientPaint( 0, 0, Constants.CONTACT_LIST_GROUP_BG_GRADIENT_COLOR, 0, getHeight(), Constants.CONTACT_LIST_GROUP_BG_COLOR)); borderColor = Constants.CONTACT_LIST_GROUP_BG_COLOR; } g2.fillRect(0, 0, getWidth(), getHeight()); g2.setColor(borderColor); g2.drawLine(0, 0, getWidth(), 0); g2.drawLine(0, getHeight() - 1, getWidth(), getHeight() - 1); }
@Override protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D gfx = (Graphics2D) g; gfx.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // Clear screen gfx.setColor(Constants.BACKGROUND_COLOR); gfx.fillRect(0, 0, getWidth(), getHeight()); // Render next frame grid.draw(gfx); // Trace path line if (tracing) { gfx.setColor(Constants.PATH_COLOR); gfx.setStroke(new BasicStroke(2)); for (int i = 1; i < pathLine.size(); i++) { Coordinate p = pathLine.get(i - 1); Coordinate n = pathLine.get(i); gfx.drawLine( (Constants.TILESIZE + Constants.MARGIN) * p.x + (Constants.TILESIZE / 2) + Constants.MARGIN, (Constants.TILESIZE + Constants.MARGIN) * p.y + (Constants.TILESIZE / 2) + Constants.MARGIN, (Constants.TILESIZE + Constants.MARGIN) * n.x + (Constants.TILESIZE / 2) + Constants.MARGIN, (Constants.TILESIZE + Constants.MARGIN) * n.y + (Constants.TILESIZE / 2) + Constants.MARGIN); } } }
/** [Internal] */ private void paintBackground(Graphics2D g2, Color theBackground) { Color color1 = g2.getColor(); if (theBackground == null) theBackground = Color.white; g2.setColor(theBackground); g2.fillRect(0, 0, 30000, 30000); g2.setColor(color1); }
// Scaling relative to the center of the screen @Override public void paintComponent(Graphics g) { super.paintComponent(g); if (bufferImage == null) { bufferImage = createImage(getWidth(), getHeight()); bufferg = (Graphics2D) bufferImage.getGraphics(); updateAffineTransform(); preSize = getSize(); } bufferg.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); bufferg.setTransform(new AffineTransform()); bufferg.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f)); bufferg.setColor(Color.WHITE); bufferg.fillRect(0, 0, getWidth(), getHeight()); bufferg.setTransform(affineTransform); Graphics2D g2d = bufferg; if (ORIPA.doc.hasModel) { g2d.setStroke(Config.STROKE_CUT); if (Globals.modelDispMode == Constants.ModelDispMode.FILL_ALPHA) { g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.1f)); } drawModel(g2d); g.drawImage(bufferImage, 0, 0, this); } }
private void fillRectangle(int x, int y, int width, int height, int symbolType) { if (!Preferences.monochrome) { setFillColor(symbolType); gRef.fillRect(x, y, width, height); restoreColor(); } }
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(); }
/** * All purpose paint method that should do the right thing for all linear bouncing-box progress * bars. Override this if you are making another kind of progress bar. * * @see #paintDeterminate * @since 1.4 */ protected void paintIndeterminate(Graphics g, JComponent c) { if (!(g instanceof Graphics2D)) { return; } Insets b = progressBar.getInsets(); // area for border int barRectWidth = progressBar.getWidth() - (b.right + b.left); int barRectHeight = progressBar.getHeight() - (b.top + b.bottom); if (barRectWidth <= 0 || barRectHeight <= 0) { return; } Graphics2D g2 = (Graphics2D) g; // Paint the bouncing box. boxRect = getBox(boxRect); if (boxRect != null) { g2.setColor(progressBar.getForeground()); g2.fillRect(boxRect.x, boxRect.y, boxRect.width, boxRect.height); } // Deal with possible text painting if (progressBar.isStringPainted()) { if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) { paintString(g2, b.left, b.top, barRectWidth, barRectHeight, boxRect.x, boxRect.width, b); } else { paintString(g2, b.left, b.top, barRectWidth, barRectHeight, boxRect.y, boxRect.height, b); } } }
private BufferedImage createGrid() { if (transformCells.getScaleY() < SHOW_GRID_MIN_SCALE) { return null; } Point2D cellSize = getCellSizeAfterScale(); cellWidth = round(cellSize.getX()); cellHeight = round(cellSize.getY()); BufferedImage image = new BufferedImage( getWidth() + 2 * (cellWidth), getHeight() + 2 * (cellHeight), BufferedImage.TYPE_INT_ARGB); Graphics2D graphics2D = image.createGraphics(); graphics2D.setColor(new Color(0, true)); graphics2D.fillRect(0, 0, image.getWidth(), image.getHeight()); graphics2D.setPaint(Color.YELLOW); graphics2D.setStroke(new BasicStroke(1)); for (int x = 0; x < image.getWidth(); x += cellWidth) { graphics2D.drawLine(x, 0, x, image.getHeight()); } for (int y = 0; y < image.getHeight(); y += cellHeight) { graphics2D.drawLine(0, y, image.getWidth(), y); } transformGrid.setToIdentity(); calculateGridTranslation(); graphics2D.dispose(); return image; }
public void paintComponent(Graphics g) { Graphics2D g2d = (Graphics2D) g.create(); g2d.setStroke(new BasicStroke(1.0f)); if (isOpaque()) { g2d.setColor(getBackground()); g2d.fillRect(0, 0, getWidth(), getHeight()); } g2d.setColor(Color.black); g2d.drawLine(0, frameHeight / 2, frameWidth, frameHeight / 2); g2d.drawLine(frameWidth / 2, 0, frameWidth / 2, frameHeight); for (int i = unityX; i < frameWidth / 2; i += unityX) { g2d.drawLine( frameWidth / 2 + i, frameHeight / 2 - 3, frameWidth / 2 + i, frameHeight / 2 + 3); g2d.drawLine( frameWidth / 2 - i, frameHeight / 2 - 3, frameWidth / 2 - i, frameHeight / 2 + 3); } for (int i = unityY; i < frameHeight / 2; i += unityY) { g2d.drawLine( frameWidth / 2 - 3, frameHeight / 2 + i, frameWidth / 2 + 3, frameHeight / 2 + i); g2d.drawLine( frameWidth / 2 - 3, frameHeight / 2 - i, frameWidth / 2 + 3, frameHeight / 2 - i); } g2d.setColor(Color.blue); function.drawFunctionToGraphic(g2d, frameWidth, frameHeight, unityX, unityY); paintCurrentMethodState(g2d); g2d.dispose(); }
static void renderSplashFrame(Graphics2D g, int frame) { final String[] comps = {"foo", "bar", "baz"}; g.setComposite(AlphaComposite.Clear); g.fillRect(120, 140, 200, 40); g.setPaintMode(); g.setColor(Color.BLACK); g.drawString("Loading " + comps[(frame / 5) % 3] + "...", 120, 150); }
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); }
// initialize default image private BufferedImage getDefaultImage(int w, int h) { BufferedImage defaultImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); Graphics2D graphics2D = defaultImage.createGraphics(); graphics2D.setColor(new Color(200, 200, 200)); graphics2D.fillRect(0, 0, w, h); graphics2D.setColor(new Color(130, 130, 130)); graphics2D.drawRect(0, 0, w - 1, h - 1); return defaultImage; }
@Override public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = ((Graphics2D) g); g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); g2d.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); g2d.setRenderingHint( RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_OFF); g2d.setRenderingHint( RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_SPEED); g2d.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_DISABLE); g2d.setColor(Color.BLACK); g2d.fillRect(0, 0, getWidth(), getHeight()); if (bufferedImage != null) { synchronized (LOCKER) { g2d.drawImage(bufferedImage, transformCells, null); } } // draw struct preview if (structurePreview != null) { Composite composite = g2d.getComposite(); g2d.setComposite(compositeStructPreview); g2d.drawImage(structurePreview, previewTransform, null); g2d.setComposite(composite); } // draw grid if (transformCells.getScaleX() > SHOW_GRID_MIN_SCALE) { Composite composite = g2d.getComposite(); g2d.setComposite(compositeGrid); g2d.drawImage(bufferedImageGrid, transformGrid, null); g2d.setComposite(composite); } // draw border for preview if (structurePreview != null && Math.abs(transformCells.getScaleX()) >= 0.95) { Shape shape = new Rectangle(0, 0, structurePreview.getWidth(), structurePreview.getHeight()); shape = previewTransform.createTransformedShape(shape); g2d.setColor(Color.RED); g2d.draw(shape); } // draw border double x = transformCells.getTranslateX(); double y = transformCells.getTranslateY(); g2d.setColor(BORDER_COLOR); g2d.setStroke(new BasicStroke(BORDER_WIDTH)); g2d.drawRect( round(x - BORDER_WIDTH), round(y - BORDER_WIDTH), round(getAutomatonWidth() * transformCells.getScaleX() + 2 * BORDER_WIDTH), round(getAutomatonHeight() * transformCells.getScaleY() + 2 * BORDER_WIDTH)); }
@Override protected void paintSafely(Graphics g) { Graphics2D g2d = (Graphics2D) g; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.setPaint( new GradientPaint( 0, 0, new Color(63, 63, 63), 0, textFormattedField.getHeight(), new Color(76, 76, 76))); g2d.fillRect(0, 0, textFormattedField.getWidth(), textFormattedField.getHeight()); g2d.setPaint( new GradientPaint( 0, 0, new Color(21, 21, 21), 0, textFormattedField.getHeight(), new Color(24, 24, 24))); g2d.fillRect(1, 1, textFormattedField.getWidth() - 2, textFormattedField.getHeight() - 2); g2d.setPaint(new Color(53, 53, 53)); g2d.fillRect(2, 2, textFormattedField.getWidth() - 4, textFormattedField.getHeight() - 4); super.paintSafely(g); }
private void paintSelection(Graphics2D g) { int selectionStartOffset = editor.getSelectionModel().getSelectionStart(); int selectionEndOffset = editor.getSelectionModel().getSelectionEnd(); int firstSelectedLine = coords.offsetToScreenSpace(selectionStartOffset); int firstSelectedCharacter = coords.offsetToCharacterInLine(selectionStartOffset); int lastSelectedLine = coords.offsetToScreenSpace(selectionEndOffset); int lastSelectedCharacter = coords.offsetToCharacterInLine(selectionEndOffset); g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.90f)); g.setColor( editor .getColorsScheme() .getColor(ColorKey.createColorKey("SELECTION_BACKGROUND", JBColor.BLUE))); if (firstSelectedLine == lastSelectedLine) { // Single line is easy g.fillRect( firstSelectedCharacter, firstSelectedLine, lastSelectedCharacter - firstSelectedCharacter, config.pixelsPerLine); } else { // Draw the line leading in g.fillRect( firstSelectedCharacter, firstSelectedLine, getWidth() - firstSelectedCharacter, config.pixelsPerLine); // Then the line at the end g.fillRect(0, lastSelectedLine, lastSelectedCharacter, config.pixelsPerLine); if (firstSelectedLine + 1 != lastSelectedLine) { // And if there is anything in between, fill it in g.fillRect( 0, firstSelectedLine + config.pixelsPerLine, getWidth(), lastSelectedLine - firstSelectedLine - config.pixelsPerLine); } } }
@Override public void paintIcon(Component c, Graphics g, int x, int y) { icon.paintIcon(c, g, x, y); int w = getIconWidth(); int h = getIconHeight(); Graphics2D g2 = (Graphics2D) g; g2.setPaint(FOREGROUND); g2.translate(x, y); g2.fillRect(a, (h - b) / 2, w - a - a, b); g2.translate(-x, -y); }
public void drawBuffer() { Graphics2D b = buffer.createGraphics(); b.setColor(Color.black); b.fillRect(0, 0, 800, 600); if (hast.collision == false) { b.setColor(Color.red); b.fillRect(hast.getX(), hast.getY(), hast.getWidth(), hast.getHeight()); for (int i = 0; i < 20; i++) { b.setColor(Color.blue); b.fillRect(box[i].getX(), box[i].getY(), box[i].getWidth(), box[i].getHeight()); } b.dispose(); } else b.setColor(Color.white); b.drawString("Horsie is DEAD!!!!", 350, 300); b.dispose(); }
public void render(int w, int h, Graphics2D g2) { int w2 = w / 2; int h2 = h / 2; g2.setPaint(new GradientPaint(0, 0, outerC, w * .35f, h * .35f, innerC)); g2.fillRect(0, 0, w2, h2); g2.setPaint(new GradientPaint(w, 0, outerC, w * .65f, h * .35f, innerC)); g2.fillRect(w2, 0, w2, h2); g2.setPaint(new GradientPaint(0, h, outerC, w * .35f, h * .65f, innerC)); g2.fillRect(0, h2, w2, h2); g2.setPaint(new GradientPaint(w, h, outerC, w * .65f, h * .65f, innerC)); g2.fillRect(w2, h2, w2, h2); g2.setColor(Color.black); TextLayout tl = new TextLayout("GradientPaint", g2.getFont(), g2.getFontRenderContext()); tl.draw( g2, (int) (w / 2 - tl.getBounds().getWidth() / 2), (int) (h / 2 + tl.getBounds().getHeight() / 2)); }
@Override public void paintComponent(Graphics g) { super.paintComponent(g); if (nodes.get(0) == null) { return; } Graphics2D g2 = (Graphics2D) g; g2.setColor(Color.blue); int x = 0; int y = 0; double xs = (double) (this.getWidth() - b - (nodes.get(0).r * nodeScaling)); double ys = (double) (this.getHeight() - b - (nodes.get(0).r * nodeScaling) - noticeBorder); g2.setColor(Color.black); g2.fillRect(0, 0, this.getWidth(), this.getHeight()); g2.setColor(Color.blue); drawNode s; drawNode d; RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHints(rh); g2.setColor(Color.white); if (!ignoreLinks) { for (drawLink L : links.values()) { g2.setColor(L.color); s = nodes.get(L.sid); d = nodes.get(L.eid); if (s != null && d != null) { g2.drawLine( (int) ((s.x * xs) + (s.r * nodeScaling) / 2d), (int) ((s.y * ys) + (s.r * nodeScaling) / 2d), (int) ((d.x * xs) + (d.r * nodeScaling) / 2d), (int) ((d.y * ys) + (d.r * nodeScaling) / 2d)); } } } for (drawNode N : nodes.values()) { g2.setColor(N.color); g2.fill(new Ellipse2D.Double(N.x * xs, N.y * ys, N.r * nodeScaling, N.r * nodeScaling)); g2.setColor(Color.black); g2.draw(new Ellipse2D.Double(N.x * xs, N.y * ys, N.r * nodeScaling, N.r * nodeScaling)); } if (showInfoForNode != -1 && nodeInfo.containsKey(showInfoForNode)) { drawNode N = nodes.get(showInfoForNode); x = (int) (N.x * xs + N.r * nodeScaling) + 3; y = (int) (N.y * ys); CTB.flipShift = (int) (N.r * nodeScaling) + 5; CTB.draw(g2, x, y, this.getWidth(), this.getHeight(), nodeInfo.get(showInfoForNode)); } g2.setColor(Color.white); g2.setFont(new Font("Arial", Font.PLAIN, 10)); g2.drawString("Ruud van de Bovenkamp - NAS", b, this.getHeight() - b); doneDrawing = true; }
public void drawMissile(int xpos, int ypos, double rot, double xscale, double yscale) { g.translate(xpos, ypos); g.rotate(rot * Math.PI / 180.0); g.scale(xscale, yscale); g.fillRect(-10, -10, 20, 20); g.scale(1.0 / xscale, 1.0 / yscale); g.rotate(-rot * Math.PI / 180.0); g.translate(-xpos, -ypos); }
public static BufferedImage cropImage(BufferedImage bi, int x, int y, int w, int h) { BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); g2.setRenderingHint( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g2.setPaint(Color.white); g2.fillRect(0, 0, w, h); g2.drawImage(bi, -x, -y, null); // this); g2.dispose(); return image; }
public void paintComponent(Graphics g) { Graphics2D g2d = RenderSetter.OpenRender(g); center_x = getWidth() / 2; center_y = getHeight() / 2; // ʹ�������� g2d.setColor(new Color(1f, 1f, 1f, 0f)); g2d.fillRect(0, 0, getWidth(), getHeight()); for (int i = 0; i < balls.length; i++) { balls[i].draw(g2d); } }
public static BufferedImage tileImage(BufferedImage im, int width, int height) { GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment() .getDefaultScreenDevice() .getDefaultConfiguration(); int transparency = Transparency.OPAQUE; // Transparency.BITMASK; BufferedImage compatible = gc.createCompatibleImage(width, height, transparency); Graphics2D g = (Graphics2D) compatible.getGraphics(); g.setPaint(new TexturePaint(im, new Rectangle(0, 0, im.getWidth(), im.getHeight()))); g.fillRect(0, 0, width, height); return compatible; }
public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setColor(Color.black); g2.fillRect(0, 0, 10, 70); g2.fillRect(60, 0, 10, 70); g2.fillRect(120, 0, 10, 70); g2.fillRect(0, 0, 130, 10); g2.fillRect(0, 60, 130, 10); g2.fillRect(70, 30, 50, 10); g2.fillRect(90, 10, 10, 50); fill(g2, fullRect, RoadDirection.CENTER); fill(g2, nw, RoadDirection.NW); fill(g2, ne, RoadDirection.NE); fill(g2, sw, RoadDirection.SW); fill(g2, se, RoadDirection.SE); g2.setFont(Font.decode("Arial-10")); g2.setColor(Color.black); SwingUtils.drawCenteredString(g, "CENTER", (int) fullRectStrPos.x, (int) fullRectStrPos.y); SwingUtils.drawCenteredString(g, "NW", (int) nwStrPos.x, (int) nwStrPos.y); SwingUtils.drawCenteredString(g, "NE", (int) neStrPos.x, (int) neStrPos.y); SwingUtils.drawCenteredString(g, "SW", (int) swStrPos.x, (int) swStrPos.y); SwingUtils.drawCenteredString(g, "SE", (int) seStrPos.x, (int) seStrPos.y); }
public static BufferedImage scaleImage(BufferedImage bi, double scale) { int w1 = (int) (Math.round(scale * bi.getWidth())); int h1 = (int) (Math.round(scale * bi.getHeight())); BufferedImage image = new BufferedImage(w1, h1, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); g2.setRenderingHint( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g2.setPaint(Color.white); g2.fillRect(0, 0, w1, h1); g2.drawImage(bi, 0, 0, w1, h1, null); // this); g2.dispose(); return image; }
private void paintVisibleWindow(Graphics2D g) { Rectangle visibleArea = editor.getScrollingModel().getVisibleArea(); int firstVisibleLine = getMapYFromEditorY((int) visibleArea.getMinY()); int height = coords.linesToPixels( (int) ((visibleArea.getMaxY() - visibleArea.getMinY()) / editor.getLineHeight())); // Draw the current viewport g.setColor(viewportColor); g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.50f)); g.drawRect(0, firstVisibleLine, getWidth(), height); g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.20f)); g.fillRect(0, firstVisibleLine, getWidth(), height); }