public void paintBoard(Graphics2D g2) { double gbwidth = boardGridSize * 8d + lineLoc, gbheight = boardGridSize * 9d + lineLoc; g2.setPaint(red); g2.draw3DRect((int) lineLoc / 2, (int) lineLoc / 2, (int) gbwidth, (int) gbheight, true); g2.draw3DRect( (int) lineLoc / 2 + 3, (int) lineLoc / 2 + 3, (int) gbwidth - 6, (int) gbheight - 7, false); g2.setPaint(fg); for (int i = 0; i < 10; i++) { g2.draw( new Line2D.Double( lineLoc, lineLoc + boardGridSize * i, lineLoc + boardGridSize * 8, lineLoc + boardGridSize * i)); } for (int i = 0; i < 9; i++) { g2.draw( new Line2D.Double( lineLoc + boardGridSize * i, lineLoc, lineLoc + boardGridSize * i, lineLoc + boardGridSize * 4)); if (i == 0 || i == 8) g2.draw( new Line2D.Double( lineLoc + boardGridSize * i, lineLoc + boardGridSize * 4, lineLoc + boardGridSize * i, lineLoc + boardGridSize * 9)); else g2.draw( new Line2D.Double( lineLoc + boardGridSize * i, lineLoc + boardGridSize * 5, lineLoc + boardGridSize * i, lineLoc + boardGridSize * 9)); } drawX(lineLoc + boardGridSize * 4, lineLoc + boardGridSize, g2); drawX(lineLoc + boardGridSize * 4, lineLoc + boardGridSize * 8, g2); // black Pao drawLocation(lineLoc + boardGridSize, lineLoc + boardGridSize * 2, center, g2); drawLocation(lineLoc + boardGridSize * 7, lineLoc + boardGridSize * 2, center, g2); // red Pao drawLocation(lineLoc + boardGridSize, lineLoc + boardGridSize * 7, center, g2); drawLocation(lineLoc + boardGridSize * 7, lineLoc + boardGridSize * 7, center, g2); // black Zu drawLocation(lineLoc, lineLoc + boardGridSize * 3, right, g2); drawLocation(lineLoc + boardGridSize * 2, lineLoc + boardGridSize * 3, center, g2); drawLocation(lineLoc + boardGridSize * 4, lineLoc + boardGridSize * 3, center, g2); drawLocation(lineLoc + boardGridSize * 6, lineLoc + boardGridSize * 3, center, g2); drawLocation(lineLoc + boardGridSize * 8, lineLoc + boardGridSize * 3, left, g2); // red bin drawLocation(lineLoc, lineLoc + boardGridSize * 6, right, g2); drawLocation(lineLoc + boardGridSize * 2, lineLoc + boardGridSize * 6, center, g2); drawLocation(lineLoc + boardGridSize * 4, lineLoc + boardGridSize * 6, center, g2); drawLocation(lineLoc + boardGridSize * 6, lineLoc + boardGridSize * 6, center, g2); drawLocation(lineLoc + boardGridSize * 8, lineLoc + boardGridSize * 6, left, 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); }
public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; currentX = leftMargin; currentY = topMargin; // Draw the links for (int i = 0; i < linkLines.length; i++) { if (weights[i].isActive()) { g2.setPaint(weights[i].getColor()); g2.draw(linkLines[i]); } } g2.setPaint(Color.black); // Draw the input neurons g2.drawString("Inputs", (float) currentX, (float) currentY); currentY += titleSpace; for (int i = 0; i < genome.getInputs(); i++) { g2.drawImage(inputNeuron, (int) currentX, (int) currentY, null); currentY += space; } // Draw the hidden Neurons currentX += space; currentY = topMargin; g2.drawString("Hidden Layers", (float) currentX, (float) currentY); for (int i = 0; i < genome.getHiddenLayers(); i++) { currentY = topMargin + titleSpace; for (int j = 0; j < genome.getNeuronsInHiddenLayer(); j++) { g2.drawImage(hiddenNeuron, (int) currentX, (int) currentY, null); currentY += space; } currentX += space; } // Draw the output neurons currentY = topMargin; g2.drawString("Outputs", (float) currentX, (float) currentY); currentY += titleSpace; for (int i = 0; i < genome.getOutputs(); i++) { g2.drawImage(outputNeuron, (int) currentX, (int) currentY, null); currentY += space; } // Draw the links for (int i = 0; i < linkLines.length; i++) { if (weights[i].isActive()) { g2.setPaint(weights[i].getColor()); g2.draw(linkLines[i]); } } }
/** * Render the View to the given graphic context. This implementation render the interior first, * then the outline. */ public void paint(Graphics2D g, Rectangle2D a) { if (!a.intersects(getBounds())) return; if (image != null) { // paint bitmap g.drawImage(image, text2ModelTr, null); // debug: g.setPaint(Color.red); g.draw(this.bounds); super.paint(g, a); // possibly paint framebox if non-null } else { // paint textlayout super.paint(g, a); // possibly paint framebox if non-null AffineTransform oldAT = g.getTransform(); // paint text in black g.setPaint(Color.black); // from now on, we work in Y-direct (<0) coordinates to avoid inextricable problems with font // being mirrored... g.transform(text2ModelTr); // also include rotation textLayout.draw(g, 0.0f, 0.0f); // [pending] ajouter un cadre si areDimensionsComputed (wysiwyg du pauvre) // get back to previous transform g.setTransform(oldAT); if (DEBUG) { g.setPaint(Color.red); g.draw(bounds); } } }
/** * Paints the icon. * * @param c the component on which it is painted * @param _g the graphics context * @param x the x coordinate of the icon * @param y the y coordinate of the icon */ public void paintIcon(Component c, Graphics _g, int x, int y) { Graphics2D g = (Graphics2D) _g; AffineTransform at = AffineTransform.getTranslateInstance(x + offsetX, y + offsetY); // save current graphics paint and clip Paint gPaint = g.getPaint(); Shape gClip = g.getClip(); // render shape(s) g.setPaint(color); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.clipRect(x, y, w, h); // paint shape, if any if (shape != null) { g.fill(at.createTransformedShape(shape)); } // paint decoration, if any if (decoration != null) { g.setPaint(decoColor); g.fill(at.createTransformedShape(decoration)); } // restore graphics paint and clip g.setPaint(gPaint); g.setClip(gClip); }
public static void smoothFillInverseHorGradient( Graphics g, Color[] colors, int x, int y, int w, int h) { if (colors != null) { Graphics2D g2D = (Graphics2D) g; Paint savedPaint = g2D.getPaint(); int steps = colors.length; double dy = (double) h / (double) steps; int y1 = y; for (int i = 0; i < steps; i++) { int y2 = y + (int) Math.round((double) i * dy); g.setColor(colors[colors.length - i - 1]); if (i == (steps - 1)) { g2D.setPaint(null); g2D.setColor(colors[colors.length - i - 1]); g.fillRect(x, y1, w, y + h - y1); } else { g2D.setPaint( new GradientPaint( 0, y1, colors[colors.length - i - 1], 0, y2, colors[colors.length - i - 2])); g.fillRect(x, y1, w, y2 - y1); } y1 = y2; } g2D.setPaint(savedPaint); } }
/** 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); }
@Override public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) { Graphics2D g2 = (Graphics2D) g.create(); g2.translate(x, y); g2.setPaint(borderSelectionColor); g2.drawRect(0, 0, w - 1, h - 1); g2.setPaint(getLineColor()); BasicGraphicsUtils.drawDashedRect(g2, 0, 0, w, h); g2.dispose(); }
@Override protected BufferedImage renderOffscreen() { BufferedImage bimage = null; if (getOrientation() == SwingConstants.HORIZONTAL) { bimage = new BufferedImage(DEFAULT_WIDTH, 10, BufferedImage.TYPE_4BYTE_ABGR); Graphics2D g2d = bimage.createGraphics(); int ncolors = colorMap.getMapSize(); double distance = colorMap.getMaximumValue() - colorMap.getMinimumValue(); double start = colorMap.getMinimumValue(); for (int i = 0; i < ncolors; i++) { ColorInterval ci = colorMap.getInterval(i); double size = ((ci.getMaximum() - ci.getMinimum()) / distance); double xpos = (ci.getMinimum() - start) / distance; Rectangle2D rect = new Rectangle2D.Double(xpos * DEFAULT_WIDTH, 0, size * DEFAULT_WIDTH, 10); float trans = (float) ci.getAlpha(); AlphaComposite comp = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, trans / 255f); g2d.setComposite(comp); g2d.setPaint(ci.getColor()); g2d.fill(rect); } } else { bimage = new BufferedImage(10, DEFAULT_HEIGHT, BufferedImage.TYPE_4BYTE_ABGR); int ncolors = colorMap.getMapSize(); double distance = colorMap.getMaximumValue() - colorMap.getMinimumValue(); double start = colorMap.getMinimumValue(); Graphics2D g2d = bimage.createGraphics(); for (int i = 0; i < ncolors; i++) { ColorInterval ci = colorMap.getInterval(i); double size = ((ci.getMaximum() - ci.getMinimum()) / distance); double ypos = (ci.getMinimum() - start) / distance; Rectangle2D rect = new Rectangle2D.Double(0, ypos * DEFAULT_HEIGHT, 10, size * DEFAULT_HEIGHT); float trans = (float) ci.getAlpha(); AlphaComposite comp = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, trans / 255f); g2d.setComposite(comp); g2d.setPaint(ci.getColor()); g2d.fill(rect); } } cachedImage = bimage; return cachedImage; }
private void paintBackgroundPressedAndDefault(Graphics2D g) { roundRect = decodeRoundRect1(); g.setPaint(color17); g.fill(roundRect); roundRect = decodeRoundRect2(); g.setPaint(decodeGradient4(roundRect)); g.fill(roundRect); roundRect = decodeRoundRect3(); g.setPaint(decodeGradient2(roundRect)); g.fill(roundRect); }
private void paintBackgroundMouseOverAndDefault(Graphics2D g) { roundRect = decodeRoundRect5(); g.setPaint(color1); g.fill(roundRect); roundRect = decodeRoundRect2(); g.setPaint(decodeGradient3(roundRect)); g.fill(roundRect); roundRect = decodeRoundRect3(); g.setPaint(decodeGradient2(roundRect)); g.fill(roundRect); }
private void paintBackgroundEnabled(Graphics2D g) { roundRect = decodeRoundRect1(); g.setPaint(color1); g.fill(roundRect); roundRect = decodeRoundRect2(); g.setPaint(decodeGradient7(roundRect)); g.fill(roundRect); roundRect = decodeRoundRect3(); g.setPaint(decodeGradient2(roundRect)); g.fill(roundRect); }
private void paintBackgroundPressedAndFocused(Graphics2D g) { roundRect = decodeRoundRect4(); g.setPaint(color9); g.fill(roundRect); roundRect = decodeRoundRect2(); g.setPaint(decodeGradient11(roundRect)); g.fill(roundRect); roundRect = decodeRoundRect3(); g.setPaint(decodeGradient2(roundRect)); g.fill(roundRect); }
private void paintBackgroundDisabled(Graphics2D g) { roundRect = decodeRoundRect1(); g.setPaint(color25); g.fill(roundRect); roundRect = decodeRoundRect2(); g.setPaint(decodeGradient5(roundRect)); g.fill(roundRect); roundRect = decodeRoundRect3(); g.setPaint(decodeGradient6(roundRect)); g.fill(roundRect); }
private void paintBackgroundMouseOverAndFocused(Graphics2D g) { roundRect = decodeRoundRect4(); g.setPaint(color9); g.fill(roundRect); roundRect = decodeRoundRect2(); g.setPaint(decodeGradient9(roundRect)); g.fill(roundRect); roundRect = decodeRoundRect3(); g.setPaint(decodeGradient10(roundRect)); g.fill(roundRect); }
/** * Paints background and children. * * @param g context. */ public void paint(Graphics g) { // Paint background int width = getSize().width; int height = getSize().height; Graphics2D g2 = (Graphics2D) g; Paint storedPaint = g2.getPaint(); g2.setPaint(new GradientPaint(0, 0, backgroundColor1, 0, height, backgroundColor2)); g2.fillRect(0, 0, width, height); g2.setPaint(storedPaint); paintChildren(g); }
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(); double theta, x, y; g2.setPaint(Color.blue); double x1 = w * 3 / 24, y1 = h * 3 / 32, x2 = w * 11 / 24, y2 = y1; g2.draw(new Line2D.Double(x1, y1, x2, y2)); // draw this arrow head at point x2, y2 and measure // angle theta relative to same point, ie, y2 - and x2 - theta = Math.atan2(y2 - y1, x2 - x1); drawArrow(g2, theta, x2, y2); x1 = w * 3 / 8; y1 = h * 13 / 15; x2 = w * 2 / 3; y2 = y1; g2.draw(new Line2D.Double(x1, y1, x2, y2)); theta = Math.atan2(y1 - y2, x1 - x2); drawArrow(g2, theta, x1, y1); g2.setPaint(Color.red); x1 = w * 3 / 24; y1 = h * 4 / 32; x2 = x1; y2 = h * 18 / 32; g2.draw(new Line2D.Double(x1, y1, x2, y2)); theta = Math.atan2(y2 - y1, x2 - x1); drawArrow(g2, theta, x2, y2); g2.setPaint(Color.orange); x1 = w * 5 / 32; y1 = h * 27 / 32; x2 = w * 27 / 32; y2 = h * 5 / 32; g2.draw(new Line2D.Double(x1, y1, x2, y2)); theta = Math.atan2(y2 - y1, x2 - x1); drawArrow(g2, theta, x2, y2); g2.setPaint(Color.green.darker()); x1 = w / 2; y1 = h / 2; x2 = w * 27 / 32; y2 = h * 27 / 32; g2.draw(new Line2D.Double(x1, y1, x2, y2)); theta = Math.atan2(y2 - y1, x2 - x1); drawArrow(g2, theta, x2, y2); }
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(); // Draw ordinate. g2.draw(new Line2D.Double(Points, Points, Points, h - Points)); // Draw abcissa. g2.draw(new Line2D.Double(Points, h - Points, w - Points, h - Points)); // Draw labels. Font font = g2.getFont(); FontRenderContext frc = g2.getFontRenderContext(); LineMetrics lm = font.getLineMetrics("0", frc); float sh = lm.getAscent() + lm.getDescent(); // Ordinate label. String s = "Strecke"; float sy = Points + ((h - 2 * Points) - s.length() * sh) / 2 + lm.getAscent(); for (int i = 0; i < s.length(); i++) { String letter = String.valueOf(s.charAt(i)); float sw = (float) font.getStringBounds(letter, frc).getWidth(); float sx = (Points - sw) / 2; g2.drawString(letter, sx, sy); sy += sh; } // Abcissa label. s = "Datum"; sy = h - Points + (Points - sh) / 2 + lm.getAscent(); float sw = (float) font.getStringBounds(s, frc).getWidth(); float sx = (w - sw) / 2; g2.drawString(s, sx, sy); // Draw lines. double xInc = (double) (w - 2 * Points) / (data.length - 1); double scale = (double) (h - 2 * Points) / getMax(); g2.setPaint(Color.green.darker()); for (int i = 0; i < data.length - 1; i++) { double x1 = Points + i * xInc; double y1 = h - Points - scale * data[i]; double x2 = Points + (i + 1) * xInc; double y2 = h - Points - scale * data[i + 1]; g2.draw(new Line2D.Double(x1, y1, x2, y2)); } // Mark data points. g2.setPaint(Color.red); for (int i = 0; i < data.length; i++) { double x = Points + i * xInc; double y = h - Points - scale * data[i]; g2.fill(new Ellipse2D.Double(x - 2, y - 2, 4, 4)); } }
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); } }
public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Dimension d = getSize(); Color fg3D = Color.lightGray; g2.setPaint(fg3D); g2.draw3DRect(0, 0, d.width - 1, d.height - 1, true); g2.draw3DRect(3, 3, d.width - 7, d.height - 7, false); g2.setPaint(fg); test.setBounds(boardGridSize * 4 + 10, boardGridSize * 5 - 20, 100, 50); this.add(test); paintBoard(g2); }
private void paintBackgroundEnabledAndWindowNotFocusedAndWindowMaximized(Graphics2D g) { roundRect = decodeRoundRect1(); g.setPaint(decodeGradient10(roundRect)); g.fill(roundRect); roundRect = decodeRoundRect2(); g.setPaint(decodeGradient11(roundRect)); g.fill(roundRect); rect = decodeRect1(); g.setPaint(color4); g.fill(rect); rect = decodeRect4(); g.setPaint(color54); g.fill(rect); rect = decodeRect5(); g.setPaint(color55); g.fill(rect); rect = decodeRect8(); g.setPaint(color56); g.fill(rect); path = decodePath1(); g.setPaint(color57); g.fill(path); path = decodePath2(); g.setPaint(color58); g.fill(path); }
private void paintBackgroundEnabledAndWindowNotFocused(Graphics2D g) { roundRect = decodeRoundRect1(); g.setPaint(decodeGradient10(roundRect)); g.fill(roundRect); roundRect = decodeRoundRect2(); g.setPaint(decodeGradient16(roundRect)); g.fill(roundRect); rect = decodeRect1(); g.setPaint(color4); g.fill(rect); path = decodePath4(); g.setPaint(color72); g.fill(path); }
/** 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); } } }
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; }
/** 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(); } } } }
@Override protected void paintIcon(JComponent c, Graphics2D g, Rectangle viewRect, Rectangle iconRect) { int rad = JBUI.scale(4); // Paint the radio button final int x = iconRect.x + (rad - (rad % 2 == 1 ? 1 : 0)) / 2; final int y = iconRect.y + (rad - (rad % 2 == 1 ? 1 : 0)) / 2; final int w = iconRect.width - rad; final int h = iconRect.height - rad; final boolean enabled = c.isEnabled(); Color color = enabled ? Gray.x50 : Gray.xD3; g.translate(x, y); // setup AA for lines final GraphicsConfig config = GraphicsUtil.setupAAPainting(g); g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); final boolean selected = ((AbstractButton) c).isSelected(); g.setPaint(color); g.drawOval(0, 0, w, h); if (selected) { g.setColor(color); g.fillOval(JBUI.scale(3), JBUI.scale(3), w - 2 * JBUI.scale(3), h - 2 * JBUI.scale(3)); } config.restore(); g.translate(-x, -y); }
// 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(); } }
public void paintComponent(Graphics g) { GradientPaint gradient = new GradientPaint(70, 70, Color.blue, 150, 150, Color.orange); Image image = new ImageIcon("a.jpg").getImage(); Random generator = new Random(); int x1 = generator.nextInt(200) + 1; int y1 = generator.nextInt(200) + 1; int x2 = x1 + generator.nextInt(100) + 1; int y2 = x1 + generator.nextInt(100) + 1; g.setColor(Color.blue); g.fillRect(70, 70, 200, 100); g.setColor(Color.black); g.fillOval(80, 80, 170, 70); Graphics2D g2d = (Graphics2D) g; g.setColor(Color.yellow); g2d.fill3DRect(10, 10, 100, 100, true); g.drawImage(image, 300, 300, this); g2d.setPaint(gradient); g2d.fillOval(x1, y1, x2, y2); }