/** Paints selection for the specified <code>component</code>. */ public static void paintSelectionDecoration( @NotNull RadComponent component, Graphics g, boolean focused) { if (component.isSelected()) { if (focused) { g.setColor(PlatformColors.BLUE); } else { g.setColor(Color.GRAY); } final Point[] points = getPoints(component.getWidth(), component.getHeight()); for (final Point point : points) { g.fillRect(point.x - R, point.y - R, 2 * R + 1, 2 * R + 1); } } else if (component.getWidth() < FormEditingUtil.EMPTY_COMPONENT_SIZE || component.getHeight() < FormEditingUtil.EMPTY_COMPONENT_SIZE) { Graphics2D g2d = (Graphics2D) g; Composite oldComposite = g2d.getComposite(); Stroke oldStroke = g2d.getStroke(); Color oldColor = g2d.getColor(); g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 0.5f)); g2d.setStroke(new BasicStroke(0.7f)); g2d.setColor(Color.black); g2d.drawRect( 0, 0, Math.max(component.getWidth(), FormEditingUtil.EMPTY_COMPONENT_SIZE), Math.max(component.getHeight(), FormEditingUtil.EMPTY_COMPONENT_SIZE)); g2d.setComposite(oldComposite); g2d.setStroke(oldStroke); g2d.setColor(oldColor); } }
/** 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(); } } } }
// From: http://forum.java.sun.com/thread.jspa?threadID=378460&tstart=135 void drawArrow( Graphics2D g2d, int xCenter, int yCenter, int x, int y, float stroke, BasicStroke drawStroke) { double aDir = Math.atan2(xCenter - x, yCenter - y); // Line can be dashed. g2d.setStroke(drawStroke); g2d.drawLine(x, y, xCenter, yCenter); // make the arrow head solid even if dash pattern has been specified g2d.setStroke(lineStroke); Polygon tmpPoly = new Polygon(); int i1 = 12 + (int) (stroke * 2); // make the arrow head the same size regardless of the length length int i2 = 6 + (int) stroke; tmpPoly.addPoint(x, y); tmpPoly.addPoint(x + xCor(i1, aDir + .5), y + yCor(i1, aDir + .5)); tmpPoly.addPoint(x + xCor(i2, aDir), y + yCor(i2, aDir)); tmpPoly.addPoint(x + xCor(i1, aDir - .5), y + yCor(i1, aDir - .5)); tmpPoly.addPoint(x, y); // arrow tip g2d.drawPolygon(tmpPoly); // Remove this line to leave arrow head unpainted: g2d.fillPolygon(tmpPoly); }
private void paintFirms(Graphics2D g2d) { Rectangle2D rec = new Rectangle2D.Double(); ArrayList<Firm> firms = SleepStoneTest.firms; Stroke normalStroke = new BasicStroke(); Stroke boldStroke = new BasicStroke(4f); g2d.setStroke(boldStroke); for (Firm x : firms) { rec.setRect(firmsPlace.get(x)); FirmStatus status = x.getStatus(); g2d.setColor(Color.black); g2d.drawString(x.getFirmName(), Math.round(rec.getMinX()), Math.round(rec.getMaxY() + 15d)); g2d.drawString( Integer.toString(x.getWorkers().size()), Math.round(rec.getMinX()), Math.round(rec.getMinY() - 15d)); // g2d.setColor(Color.RED); g2d.drawImage( firmIcon.getImage(), (int) rec.getX(), (int) rec.getY(), (int) rec.getWidth(), (int) rec.getHeight(), FirmStatus.getStatusColor(status), null); // draw the jobs done indicator if (status == FirmStatus.PRODUCING) { g2d.setColor(Color.black); g2d.setStroke(boldStroke); Rectangle jobsIndicator = new Rectangle( (int) rec.getMaxX() + 5, (int) rec.getMinY(), (int) (firmSpacing / 2d), (int) rec.getHeight()); g2d.draw(jobsIndicator); float jobsToDo = x.getJobsToDo(); float jobsDone = x.getJobsDone().availablePermits(); float percentComplete = jobsDone / jobsToDo; g2d.setColor(Color.BLUE); jobsIndicator.setBounds( (int) rec.getMaxX() + 5, (int) rec.getMinY(), (int) (firmSpacing / 2d), (int) (((float) (rec.getHeight())) * percentComplete)); g2d.fill(jobsIndicator); g2d.setStroke(normalStroke); } // index++; } }
public static void paintButtonGroupLines( RadRootContainer rootContainer, RadButtonGroup group, Graphics g) { List<RadComponent> components = rootContainer.getGroupContents(group); if (components.size() < 2) return; Rectangle[] allBounds = new Rectangle[components.size()]; int lastTop = -1; int minLeft = Integer.MAX_VALUE; for (int i = 0; i < components.size(); i++) { final Rectangle rc = SwingUtilities.convertRectangle( components.get(i).getParent().getDelegee(), components.get(i).getBounds(), rootContainer.getDelegee()); allBounds[i] = rc; minLeft = Math.min(minLeft, rc.x); if (i == 0) { lastTop = rc.y; } else if (lastTop != rc.y) { lastTop = Integer.MIN_VALUE; } } Graphics2D g2d = (Graphics2D) g; Stroke oldStroke = g2d.getStroke(); g2d.setStroke(new BasicStroke(2.0f)); g2d.setColor(new Color(104, 107, 130)); if (lastTop != Integer.MIN_VALUE) { // all items in group have same Y int left = Integer.MAX_VALUE; int right = Integer.MIN_VALUE; for (Rectangle rc : allBounds) { final int midX = (int) rc.getCenterX(); left = Math.min(left, midX); right = Math.max(right, midX); g2d.drawLine(midX, lastTop - 8, midX, lastTop); } g2d.drawLine(left, lastTop - 8, right, lastTop - 8); } else { int top = Integer.MAX_VALUE; int bottom = Integer.MIN_VALUE; for (Rectangle rc : allBounds) { final int midY = (int) rc.getCenterY(); top = Math.min(top, midY); bottom = Math.max(bottom, midY); g2d.drawLine(minLeft - 8, midY, rc.x, midY); } g2d.drawLine(minLeft - 8, top, minLeft - 8, bottom); } g2d.setStroke(oldStroke); }
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(); }
@Override protected void paintComponent(Graphics g) { super.paintComponent(g); width = getWidth(); height = getHeight(); g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.translate(width / 2, getHeight() / 2); drawGrid(g2); drawAxes(g2); g2.setColor(EMERALD); g2.setStroke(new BasicStroke(3)); System.out.println("REPAINTED " + countTest++ + " times by now..."); try { drawPlot(); } catch (ScriptException e) { e.printStackTrace(); } }
/** 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); } }
@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); } }
/** 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; }
/** * Drawer : draw the historic curve of the component. * * @param g Graphics2D of the component (casted from getGraphics). */ private void drawCurve(Graphics2D g) { // calculate resizing an graphical zone. float spaceBetween = (float) ((this.getWidth() - (retrieveBarLeft + retrieveBarRight)) / (1.0 * nbPoints)); float multiplicatorHeight = (float) ((this.getHeight() - (retrieveBarTop + retrieveBarBottom)) / (1.0 * maxValue)); shapes = new ArrayList<>(); for (int i = 0; i < values.length - 1; i++) { // generating shape array Point p1 = new Point( (int) (retrieveBarLeft + (i * spaceBetween)), (int) ((getHeight() - retrieveBarBottom) - (values[i] * multiplicatorHeight))); Point p2 = new Point( (int) (retrieveBarLeft + ((i + 1) * spaceBetween)), (int) ((getHeight() - retrieveBarBottom) - (values[i + 1] * multiplicatorHeight))); currentShape = new Line2D.Double(p1, p2); shapes.add(currentShape); } // draw the curve from shape array g.setPaint(line); g.setStroke(new BasicStroke(1)); for (Shape shape : shapes) { g.draw(shape); } }
private void placerPostes(Graphics2D g) { g.setStroke(new BasicStroke()); for (PlanSalle.Poste poste : modele.listerPostes()) { g.setColor(Color.gray); int xPoste = Parametres.posteX(poste.getPosition().getTravee(), poste.getOrientation()); int yPoste = Parametres.posteY(poste.getPosition().getRangee(), poste.getOrientation()); int xPersonne = Parametres.personneX(poste.getPosition().getTravee(), poste.getOrientation()); int yPersonne = Parametres.personneY(poste.getPosition().getRangee(), poste.getOrientation()); if (poste.getOrientation() == Orientation.NORD || poste.getOrientation() == Orientation.SUD) { g.fill3DRect(xPoste, yPoste, Parametres.LONGUEUR_POSTE, Parametres.LARGEUR_POSTE, true); } else { g.fill3DRect(xPoste, yPoste, Parametres.LARGEUR_POSTE, Parametres.LONGUEUR_POSTE, true); } g.drawOval(xPersonne, yPersonne, Parametres.LARGEUR_PERSONNE, Parametres.LARGEUR_PERSONNE); if (poste.peutVoir()) { g.setColor(Color.red); } else { g.setColor(Color.blue); } g.fillOval(xPersonne, yPersonne, 20, 20); } }
public void paintComponent(Graphics g) { super.paintComponent(g); int centerX = getWidth() / 2; int centerY = getHeight() / 2; Graphics2D g2d = (Graphics2D) g.create(); g2d.translate(centerX, centerY); // Set Graphics2D transform origin to center of panel g2d.setColor(fgColor); bar.setFrame(-barWidth / 2, -barHeight / 2 + barHeight * barPosition, barWidth, barHeight); g2d.fill(bar); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); for (Spike spike : spikes) { if (spike != null) { double opacity = 255; if (spike.getDirection() == 0) { opacity = getWidth() * 0.5 - 70 - spike.getPosition().getX(); } else { opacity = spike.getPosition().getX() + getWidth() * 0.5 - 70; } g2d.setColor(new Color(0, 0, 0, (int) clamp(opacity * 10, 0, 255))); g2d.fill(spike); } } g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); g2d.setColor(Color.BLACK); g2d.draw(barCross); g2d.setStroke(new BasicStroke(2)); g2d.draw(barFrame); g2d.dispose(); }
@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); } } }
void drawLine(Graphics g, DrawObject L) { if (L == null) { return; } if ((sequencingOn) && (L.sequenceNum != currentSequenceNumDisplay)) { return; } Graphics2D g2 = (Graphics2D) g; g2.setStroke(L.drawStroke); int x1 = (int) ((L.x - minX) / (maxX - minX) * (D.width - 2 * inset)); int y1 = (int) ((L.y - minY) / (maxY - minY) * (D.height - 2.0 * inset)); int x2 = (int) ((L.x2 - minX) / (maxX - minX) * (D.width - 2 * inset)); int y2 = (int) ((L.y2 - minY) / (maxY - minY) * (D.height - 2.0 * inset)); if (L.isArrow) { drawArrow( (Graphics2D) g, inset + x1, D.height - y1 - inset, inset + x2, D.height - y2 - inset, 1.0f, L.drawStroke); } else { g.drawLine(inset + x1, D.height - y1 - inset, inset + x2, D.height - y2 - inset); } }
/** * Draws this without refreshing steps. * * @param panel the drawing panel requesting the drawing * @param _g the graphics context on which to draw */ public void drawMe(DrawingPanel panel, Graphics _g) { // position and show inspector if requested during loading if (inspectorX != Integer.MIN_VALUE && trackerPanel != null && trackerPanel.getTFrame() != null) { positionInspector(); Runnable runner = new Runnable() { public void run() { showInspector = false; inspector.setVisible(true); } }; if (showInspector) SwingUtilities.invokeLater(runner); } if (isVisible() && isTraceVisible()) { // draw trace only if fixed coords & (non-worldview or no ref frame) TrackerPanel tPanel = (TrackerPanel) panel; ImageCoordSystem coords = tPanel.getCoords(); // get active coords boolean isRefFrame = coords instanceof ReferenceFrame; if (isRefFrame) { coords = ((ReferenceFrame) coords).getCoords(); } boolean fixed = coords.isFixedAngle() && coords.isFixedOrigin() && coords.isFixedScale(); if (fixed && (!(tPanel instanceof WorldTView) || !isRefFrame)) { trace.reset(); for (int i = 0; i < traceX.length; i++) { if (Double.isNaN(traceX[i])) continue; tracePt.setLocation(traceX[i], traceY[i]); java.awt.Point p = tracePt.getScreenPosition(tPanel); if (trace.getCurrentPoint() == null) trace.moveTo((float) p.getX(), (float) p.getY()); else trace.lineTo((float) p.getX(), (float) p.getY()); } Graphics2D g2 = (Graphics2D) _g; Color color = g2.getColor(); Stroke stroke = g2.getStroke(); g2.setColor(getFootprint().getColor()); g2.setStroke(traceStroke); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); g2.draw(trace); // restore original color and stroke g2.setColor(color); g2.setStroke(stroke); } } super.draw(panel, _g); }
/** * Set the radius of the pen to the given size. * * @param r the radius of the pen * @throws RuntimeException if r is negative */ public static void setPenRadius(double r) { if (r < 0) throw new RuntimeException("pen radius must be positive"); penRadius = r * DEFAULT_SIZE; BasicStroke stroke = new BasicStroke((float) penRadius, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND); // BasicStroke stroke = new BasicStroke((float) penRadius); offscreen.setStroke(stroke); }
@Override protected void paintBorder(Graphics g) { if (state == "normal") { Graphics2D g2d = (Graphics2D) g; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.setColor(Color.WHITE); g2d.setStroke(new BasicStroke(3)); g2d.fillRoundRect(0, 0, getWidth() - 1, getHeight() - 1, 20, 20); } else { Graphics2D g2d = (Graphics2D) g; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.setColor(Color.WHITE); g2d.setColor(new Color(79, 196, 122)); g2d.setStroke(new BasicStroke(3)); g2d.fillRoundRect(0, 0, getWidth() - 1, getHeight() - 1, 20, 20); } }
/** PaintComponent to draw everything. */ @Override public void paintComponent(Graphics g) { super.paintComponent(g); setBackground(Color.WHITE); // If using images, use cool dragon background if (useImages) g.drawImage(background, 0, 0, 310, 300, null); // Use light gray to not overpower the background image g.setColor(Color.LIGHT_GRAY); for (int y = 1; y < ROWS; ++y) g.fillRoundRect(0, cellSize * y - 4, (cellSize * COLS) - 1, 8, 8, 8); for (int x = 1; x < COLS; ++x) g.fillRoundRect(cellSize * x - 4, 0, 8, (cellSize * ROWS) - 1, 8, 8); // Use graphics2d for when not using the images Graphics2D g2d = (Graphics2D) g; g2d.setStroke(new BasicStroke(4, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); for (int y = 0; y < ROWS; ++y) { for (int x = 0; x < COLS; ++x) { int x1 = x * cellSize + 16; int y1 = y * cellSize + 16; if (board[y][x] == Symbol.X) { // use image if set to true, otherwise use g2d // for thicker, better looking X's and O's if (useImages) g.drawImage(imageX, x1, y1, 75, 75, null); else { g2d.setColor(PURPLE); int x2 = (x + 1) * cellSize - 16; int y2 = (y + 1) * cellSize - 16; g2d.drawLine(x1, y1, x2, y2); g2d.drawLine(x2, y1, x1, y2); } } else if (board[y][x] == Symbol.O) { if (useImages) g.drawImage(imageO, x1, y1, 75, 75, null); else { g2d.setColor(Color.BLUE); g2d.drawOval(x1, y1, 70, 70); } } } // end for } // Set status bar based on gamestate. If CONTINUE, show whose turn it is if (gameStatus == GameStatus.CONTINUE) { statusBar.setForeground(Color.BLACK); if (currentPlayer == Symbol.X) statusBar.setText("X's Turn"); else statusBar.setText("O's Turn"); } else if (gameStatus == GameStatus.DRAW) { statusBar.setForeground(Color.RED); statusBar.setText("Draw! Click to play again!"); } else if (gameStatus == GameStatus.X_WIN) { statusBar.setForeground(Color.RED); statusBar.setText("X has won! Click to play again!"); } else if (gameStatus == GameStatus.O_WIN) { statusBar.setForeground(Color.RED); statusBar.setText("O has won! Click to play again!"); } }
private void renderClusters() { Graphics2D g2 = workImage.createGraphics(); FastQueue<Polygon2D_F64> squares = alg.getFindSeeds().getDetectorSquare().getFound(); for (int i = 0; i < squares.size(); i++) { Polygon2D_F64 p = squares.get(i); g2.setColor(Color.black); g2.setStroke(new BasicStroke(4)); VisualizeShapes.drawPolygon(p, true, g2, true); g2.setColor(Color.white); g2.setStroke(new BasicStroke(2)); VisualizeShapes.drawPolygon(p, true, g2, true); } List<SquareGrid> grids = alg.getFindSeeds().getGrids().getGrids(); for (int i = 0; i < grids.size(); i++) { SquareGrid g = grids.get(i); int a = grids.size() == 1 ? 0 : 255 * i / (grids.size() - 1); int rgb = a << 16 | (255 - a) << 8; g2.setStroke(new BasicStroke(3)); for (int j = 0; j < g.nodes.size() - 1; j++) { double fraction = j / ((double) g.nodes.size() - 1); fraction = fraction * 0.6 + 0.4; int lineRGB = (int) (fraction * a) << 16 | (int) (fraction * (255 - a)) << 8; g2.setColor(new Color(lineRGB)); SquareNode p0 = g.nodes.get(j); SquareNode p1 = g.nodes.get(j + 1); g2.drawLine((int) p0.center.x, (int) p0.center.y, (int) p1.center.x, (int) p1.center.y); } g2.setColor(new Color(rgb)); for (int j = 0; j < g.nodes.size(); j++) { SquareNode n = g.nodes.get(j); VisualizeShapes.drawPolygon(n.corners, true, g2, true); } } }
public void paint(Graphics g) { super.paint(g); Graphics2D g2 = (Graphics2D) g; int size = Math.min( MAX_SIZE, Math.min( getWidth() - imagePadding.left - imagePadding.right, getHeight() - imagePadding.top - imagePadding.bottom)); g2.translate(getWidth() / 2 - size / 2, getHeight() / 2 - size / 2); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Shape shape; if (mode == ColorPicker.SAT || mode == ColorPicker.BRI) { shape = new Ellipse2D.Float(0, 0, size, size); } else { Rectangle r = new Rectangle(0, 0, size, size); shape = r; } if (hasFocus()) { PaintUtils.paintFocus(g2, shape, 5); } if (!(shape instanceof Rectangle)) { // paint a circular shadow g2.translate(2, 2); g2.setColor(new Color(0, 0, 0, 20)); g2.fill(new Ellipse2D.Float(-2, -2, size + 4, size + 4)); g2.setColor(new Color(0, 0, 0, 40)); g2.fill(new Ellipse2D.Float(-1, -1, size + 2, size + 2)); g2.setColor(new Color(0, 0, 0, 80)); g2.fill(new Ellipse2D.Float(0, 0, size, size)); g2.translate(-2, -2); } g2.drawImage(image, 0, 0, size, size, 0, 0, size, size, null); if (shape instanceof Rectangle) { Rectangle r = (Rectangle) shape; PaintUtils.drawBevel(g2, r); } else { g2.setColor(new Color(0, 0, 0, 120)); g2.draw(shape); } g2.setColor(Color.white); g2.setStroke(new BasicStroke(1)); g2.draw(new Ellipse2D.Float(point.x - 3, point.y - 3, 6, 6)); g2.setColor(Color.black); g2.draw(new Ellipse2D.Float(point.x - 4, point.y - 4, 8, 8)); g.translate(-imagePadding.left, -imagePadding.top); }
static void paintFocus( Graphics g, int x, int y, int width, int height, int r1, int r2, float grosor, Color color) { Graphics2D g2d = (Graphics2D) g; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Stroke oldStroke = g2d.getStroke(); g2d.setColor(color); g2d.setStroke(new BasicStroke(grosor)); if (r1 == 0 && r2 == 0) { g.drawRect(x, y, width, height); } else { g.drawRoundRect(x, y, width - 1, height - 1, r1, r2); } g2d.setStroke(oldStroke); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_DEFAULT); }
/** * Set the radius of the pen to the given size. * * @param r the radius of the pen * @throws IllegalArgumentException if r is negative */ public static void setPenRadius(double r) { if (r < 0) throw new IllegalArgumentException("pen radius must be nonnegative"); penRadius = r; float scaledPenRadius = (float) (r * DEFAULT_SIZE); BasicStroke stroke = new BasicStroke(scaledPenRadius, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND); // BasicStroke stroke = new BasicStroke(scaledPenRadius); offscreen.setStroke(stroke); }
@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)); }
public void paintComponent(Graphics g) { setSize(xSize, ySize); super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; if (PedigreeExplorer.thickLines) { // turn this off so they don't look blurry when exported g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } else { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } g2.setColor(Color.black); if (PedigreeExplorer.thickLines) { g2.setStroke(new BasicStroke(2)); } else { g2.setStroke(new BasicStroke(1)); } if (sex == male) { if (PedigreeExplorer.thickLines) { g2.drawRect(1, 1, symbolSize - 2, symbolSize - 2); } else { g2.drawRect(0, 0, symbolSize, symbolSize); } if (affection == affected) { g2.fillRect(0, 0, symbolSize, symbolSize); } } if (sex == female) { if (PedigreeExplorer.thickLines) { g2.drawArc(1, 1, symbolSize - 2, symbolSize - 2, 0, 360); } else { g2.drawArc(0, 0, symbolSize, symbolSize, 0, 360); } if (affection == affected) { g2.fillArc(0, 0, symbolSize, symbolSize, 0, 360); } } }
@Override protected void paintComponent(Graphics g) { Graphics2D g2d = (Graphics2D) g.create(); Rectangle2D.Float re = new Rectangle2D.Float(0, 0, getWidth(), getHeight()); Line2D.Float L1 = new Line2D.Float(new Point(3, 3), new Point(12, 12)); Line2D.Float L2 = new Line2D.Float(new Point(12, 3), new Point(3, 12)); g2d.draw(re); g2d.fill(re); g2d.setColor(MyColor.GREY.getColor()); g2d.setStroke(new BasicStroke(2F)); g2d.draw(L1); g2d.setStroke(new BasicStroke(2F)); g2d.draw(L2); g2d.dispose(); }
/** 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); } } }
public void paint(Graphics g) { System.out.println("paint"); Graphics2D g2d = (Graphics2D) g; Point1 p1, p2; n = paintInfo.size(); if (toolFlag == 2) g2d.clearRect(0, 0, getSize().width - 100, getSize().height - 100); // 清除 for (int i = 0; i < n - 1; i++) { p1 = (Point1) paintInfo.elementAt(i); p2 = (Point1) paintInfo.elementAt(i + 1); size = new BasicStroke(p1.boarder, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL); g2d.setColor(p1.col); g2d.setStroke(size); if (p1.tool == p2.tool) { switch (p1.tool) { case 0: // 画笔 Line2D line1 = new Line2D.Double(p1.x, p1.y, p2.x, p2.y); g2d.draw(line1); break; case 1: // 橡皮 g.clearRect(p1.x, p1.y, p1.boarder, p1.boarder); break; case 3: // 画直线 Line2D line2 = new Line2D.Double(p1.x, p1.y, p2.x, p2.y); g2d.draw(line2); break; case 4: // 画圆 Ellipse2D ellipse = new Ellipse2D.Double(p1.x, p1.y, Math.abs(p2.x - p1.x), Math.abs(p2.y - p1.y)); g2d.draw(ellipse); break; case 5: // 画矩形 Rectangle2D rect = new Rectangle2D.Double(p1.x, p1.y, Math.abs(p2.x - p1.x), Math.abs(p2.y - p1.y)); g2d.draw(rect); break; case 6: // 截断,跳过 i = i + 1; break; default: } // end switch } // end if } // end for }
/** * @param points * @param color * @param g */ private void paintSequence( Slot type, List<List<ValuePointColored>> points, Color color, Graphics2D g) { int i = 0; int size = points.size(); if (size > 0) { double increment = 200 / size; for (List<ValuePointColored> valuePoints : points) { int alpha = (int) (i * increment) + 55; Color c = new Color(color.getRed(), color.getGreen(), color.getBlue(), alpha); for (ValuePointColored valuePoint : valuePoints) { double[] coordinates = valuePoint.getPoint().toArray(); int x = xToPix(coordinates[0]); int y = yToPix(coordinates[1]); // if minimum then red, else black if (valuePoint.getBest() == true) { g.setColor(Color.red); } else { g.setColor(c); } g.setStroke(LINE); switch (type) { case CIRCLE: g.drawOval(x - RADIUS / 2 - 3, y - RADIUS / 2 - 3, RADIUS * 2, RADIUS * 2); break; case SQUARE: g.drawRect(x - RADIUS / 2 - 2, y - RADIUS / 2 - 2, RADIUS * 2 - 2, RADIUS * 2 - 2); break; case TRIANGLE: GeneralPath polyline = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 3); polyline.moveTo(x, y - RADIUS / 2 - 4); polyline.lineTo(x + RADIUS / 2 + 3, y + RADIUS / 2 + 1); polyline.lineTo(x - RADIUS / 2 - 3, y + RADIUS / 2 + 1); polyline.closePath(); g.draw(polyline); break; case CROSS: int xLow = x - RADIUS / 2 - 1; int xHigh = x + RADIUS / 2 + 1; int yLow = y - RADIUS / 2 - 1; int yHigh = y + RADIUS / 2 + 1; g.drawLine(xLow, yLow, xHigh, yHigh); g.drawLine(xHigh, yLow, xLow, yHigh); break; } } i++; } } }