/** * 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); }
/** This method is invoked before the rendered image of the figure is composited. */ public void drawFigure(Graphics2D g) { AffineTransform savedTransform = null; if (get(TRANSFORM) != null) { savedTransform = g.getTransform(); g.transform(get(TRANSFORM)); } if (get(FILL_STYLE) != ODGConstants.FillStyle.NONE) { Paint paint = ODGAttributeKeys.getFillPaint(this); if (paint != null) { g.setPaint(paint); drawFill(g); } } if (get(STROKE_STYLE) != ODGConstants.StrokeStyle.NONE) { Paint paint = ODGAttributeKeys.getStrokePaint(this); if (paint != null) { g.setPaint(paint); g.setStroke(ODGAttributeKeys.getStroke(this)); drawStroke(g); } } if (get(TRANSFORM) != null) { g.setTransform(savedTransform); } }
public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; Rectangle2D rect = new Rectangle2D.Double(0, 0, getWidth() - 1, getHeight() - 1); g2.setPaint(Color.YELLOW); g2.fill(rect); g2.setPaint(Color.BLUE); g2.draw(rect); }
public void draw(Graphics2D g2) { g2.setPaint(selected ? selColor : bgColor); g2.fill(rect); // g2.fill(new Rectangle2D.Double(row,col,10,10)); // g2.fill(new Rectangle2D.Double(rect.x,rect.y,rect.height, rect.width)); g2.setPaint(color); g2.draw(rect); }
public void paint(Graphics g, Shape a) { Graphics2D g2 = (Graphics2D) g; Rectangle2D abounds = a.getBounds2D(); AffineTransform saveTransform = g2.getTransform(); Paint savePaint = g2.getPaint(); try { g2.translate(abounds.getX() - bounds.getX(), abounds.getY() - bounds.getY()); g2.setPaint(Color.BLACK); // FIXME p.paint(g2); } finally { g2.setTransform(saveTransform); g2.setPaint(savePaint); } }
/** the paintComponent -- paints the board every repaint() call. */ public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; for (int i = 0; i < B_WIDTH; i++) { for (int j = 0; j < B_HEIGHT; j++) { Rectangle2D rect = new Rectangle2D.Double((i * 40) + 1, (j * 40) + 1, 38, 38); g2.setPaint(balls[i][j].getColor()); g2.fill(rect); Ellipse2D circle = new Ellipse2D.Double(); circle.setFrame(rect); g2.setPaint(balls[i][j].getcColor()); g2.fill(circle); } } }
/** paint the canvas into a image file of given width and height */ public void writeToImage(String s, int w, int h) { String ext; File f; try { ext = s.substring(s.lastIndexOf(".") + 1); f = new File(s); } catch (Exception e) { System.out.println(e); return; } if (!ext.equals("jpg") && !ext.equals("png")) { System.out.println("Cannot write to file: Illegal extension " + ext); return; } boolean opq = true; if (theOpaque != null) opq = theOpaque; BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); g2.setBackground(Color.white); g2.setPaint(Color.black); g2.setStroke(new BasicStroke(1)); g2.setRenderingHint( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); doBuffer(g2, true, new Rectangle(0, 0, w, h)); try { ImageIO.write(image, ext, f); } catch (Exception e) { System.out.println(e); } }
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 savePDF(){ // Rectangle suggestedPageSize = getITextPageSize(page1.getPageSize()); // Rectangle pageSize = rotatePageIfNecessary(suggestedPageSize); // //rotate if we need landscape // Document document = new Document(pageSize); // // PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(outputFile)); // document.open(); // Graphics2D graphics = cb.createGraphics(pageSize.getWidth(), pageSize.getHeight()); // // // call your GTRenderer here // GTRenderer draw = new StreamingRenderer(); // draw.setMapContent(mapContent); // // draw.paint(graphics, outputArea, mapContent.getLayerBounds() ); // // // cleanup // graphics.dispose(); // // //cleanup // document.close(); // writer.close(); // } public void saveImage(final MapContent map, final String file, final int imageWidth) { GTRenderer renderer = new StreamingRenderer(); renderer.setMapContent(map); Rectangle imageBounds = null; ReferencedEnvelope mapBounds = null; try { mapBounds = map.getMaxBounds(); double heightToWidth = mapBounds.getSpan(1) / mapBounds.getSpan(0); imageBounds = new Rectangle(0, 0, imageWidth, (int) Math.round(imageWidth * heightToWidth)); } catch (Exception e) { // failed to access mapContent layers throw new RuntimeException(e); } BufferedImage image = new BufferedImage(imageBounds.width, imageBounds.height, BufferedImage.TYPE_INT_RGB); Graphics2D gr = image.createGraphics(); gr.setPaint(Color.WHITE); gr.fill(imageBounds); try { renderer.paint(gr, imageBounds, mapBounds); File fileToSave = new File(file); ImageIO.write(image, "jpeg", fileToSave); } catch (Exception e) { e.printStackTrace(); } }
/** Draws the edge structure of the tree */ public void drawEdges(Graphics2D gg) { gg.setPaint(Color.black); Enumeration nodeList = argument.getBreadthFirstTraversal().elements(); // For each vertex... while (nodeList.hasMoreElements()) { // Get its edge list... TreeVertex vertex = (TreeVertex) nodeList.nextElement(); Enumeration edges = vertex.getEdgeList().elements(); // For each edge in the list... while (edges.hasMoreElements()) { TreeEdge edge = (TreeEdge) edges.nextElement(); // If we have several vertices on layer 0, only draw // edges for layers below that if (!(argument.isMultiRoots() && vertex.getLayer() == 0)) { // If the edge has been selected with the mouse, // use a thick line if (edge.isSelected()) { gg.setStroke(selectStroke); } gg.draw(edge.getShape(this)); // If we used a thick line, reset the stroke to normal // line for next edge. if (edge.isSelected()) { gg.setStroke(solidStroke); } TreeVertex edgeSource = edge.getDestVertex(); } } } }
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_ */ }
protected float drawBoxedString(Graphics2D g2, String s, Color c1, Color c2, double x) { // Calculate the width of the string. FontRenderContext frc = g2.getFontRenderContext(); TextLayout subLayout = new TextLayout(s, mFont, frc); float advance = subLayout.getAdvance(); // Fill the background rectangle with a gradient. GradientPaint gradient = new GradientPaint((float) x, 0, c1, (float) (x + advance), 0, c2); g2.setPaint(gradient); Rectangle2D bounds = mLayout.getBounds(); Rectangle2D back = new Rectangle2D.Double(x, 0, advance, bounds.getHeight()); g2.fill(back); // Draw the string over the gradient rectangle. g2.setPaint(Color.white); g2.setFont(mFont); g2.drawString(s, (float) x, (float) -bounds.getY()); return advance; }
@Override public void paintIcon(Component c, Graphics g, int x, int y) { Graphics2D g2 = (Graphics2D) g.create(); g2.translate(x, y); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setPaint(Color.ORANGE); g2.fill(star); g2.dispose(); }
public void paintBackground(Graphics2D g, ButtonInfo info) { if (info.button.isContentAreaFilled()) { g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Paint fillPaint = fill.getFill(info.button, info.fillBounds); g.setPaint(fillPaint); g.fill(info.fill); } }
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setPaint(BACKGROUND); g2.fill( new Rectangle2D.Float( 0f, 0f, (float) g2.getClipBounds().width, (float) g2.getClipBounds().height)); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); canvas.paint(g2); }
@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); }
/** 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 protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; Insets i = getInsets(); // int y = g2.getFontMetrics().getHeight()*getLineAtCaret(this)+i.top; int y = caret.y + caret.height - 1; g2.setPaint(cfc); g2.drawLine(i.left, y, getSize().width - i.left - i.right, y); }
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 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 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 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; }
protected BufferedImage makeImage() { BufferedImage image = new BufferedImage(IMAGE_SIZE, IMAGE_SIZE, BufferedImage.TYPE_4BYTE_ABGR); Graphics2D g = image.createGraphics(); g.setPaint(Color.WHITE); g.fill3DRect(0, 0, IMAGE_SIZE, IMAGE_SIZE, false); g.setPaint(Color.RED); g.setFont(Font.decode("ARIAL-BOLD-50")); g.drawString(Long.toString(++this.counter) + " frames", 10, IMAGE_SIZE / 4); g.drawString( Long.toString((System.currentTimeMillis() - start) / 1000) + " sec", 10, IMAGE_SIZE / 2); g.drawString( "Heap:" + Long.toString(Runtime.getRuntime().totalMemory()), 10, 3 * IMAGE_SIZE / 4); g.dispose(); return image; }
private JPopupTrayIcon createTrayIcon(Dimension size) { ImageIcon icon; if (size.height < 24) icon = Images.loadIcon("tray16_invert.png"); else icon = Images.loadIcon("tray24_invert.png"); BufferedImage img = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_ARGB); Graphics2D d = img.createGraphics(); Color color1 = config.getColor("tray.bgColor1", null); if (color1 != null) { Color color2 = config.getColor("tray.bgColor2", null); if (color2 == null) color2 = color1; Paint old = d.getPaint(); d.setPaint(new GradientPaint(0, 0, color1, 0, size.height, color2)); d.fillRect(0, 0, size.width, size.height); d.setPaint(old); } d.drawImage(icon.getImage(), 0, 0, size.width, size.height, icon.getImageObserver()); return new JPopupTrayIcon(img); }
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; }
public void paintStroke(Graphics2D g, ButtonInfo info) { if (isStrokePainted(info.button)) { Paint strokeColor = fill.getStroke(info.button, info.fillBounds); g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE); if (isStrokeAntialiased()) { g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); } else { g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } g.setPaint(strokeColor); g.draw(info.stroke); } }
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; }
public static BufferedImage rotateImage(BufferedImage bi) { int w = bi.getWidth(); int h = bi.getHeight(); BufferedImage image = new BufferedImage(h, w, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); g2.setRenderingHint( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g2.setPaint(Color.white); // getBackground()); g2.fillRect(0, 0, h, w); g2.rotate(90 * Math.PI / 180); g2.drawImage(bi, 0, -h, w, h, null); // this); g2.dispose(); return image; }
@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); }
@Override public void paintIcon(Component c, Graphics g, int x, int y) { Graphics2D g2 = (Graphics2D) g.create(); g2.setPaint(Objects.nonNull(c) ? c.getBackground() : Color.WHITE); g2.fillRect(x, y, getIconWidth(), getIconHeight()); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(ELLIPSE_COLOR); g2.translate(x, y); int size = list.size(); for (int i = 0; i < size; i++) { float alpha = isRunning ? (i + 1) / (float) size : .5f; g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha)); g2.fill(list.get(i)); } // g2.translate(-x, -y); g2.dispose(); }