/** * @param g2 * @throws IOException */ private void drawNode(Map<String, Node> nodes, Graphics2D g2, Font font) throws IOException { for (Node node : nodes.values()) { String name = node.getName(); if (nodeInfos.get(node.getType()) != null) { BufferedImage bi2 = ImageIO.read(getClass().getResourceAsStream( "icons/48/" + nodeInfos.get(node.getType()))); g2.drawImage(bi2, node.getX(), node.getY(), null); } else { int x = node.getX(); int y = node.getY(); int w = node.getWitdth(); int h = node.getHeight(); g2.setColor(DEFAULT_FILL_COLOR); g2.fillRoundRect(x, y, w, h, RECT_ROUND, RECT_ROUND); g2.setColor(DEFAULT_STROKE_COLOR); g2.setStroke(DEFAULT_STROKE); g2.drawRoundRect(x, y, w, h, RECT_ROUND, RECT_ROUND); FontRenderContext frc = g2.getFontRenderContext(); Rectangle2D r2 = font.getStringBounds(name, frc); int xLabel = (int) (node.getX() + ((node.getWitdth() - r2.getWidth()) / 2)); int yLabel = (int) ((node.getY() + ((node.getHeight() - r2.getHeight()) / 2)) - r2.getY()); g2.setStroke(DEFAULT_LINE_STROKE); g2.setColor(Color.black); g2.drawString(name, xLabel, yLabel); } } }
/** * Hook for subclassers to paint the background page(s). * * @param g2 The graphics object to paint the background page(s) on. */ protected void paintBackgroundPages(Graphics2D g2) { Point2D p = graph.toScreen(new Point2D.Double(pageFormat.getWidth(), pageFormat.getHeight())); Dimension pSize = graph.getPreferredSize(); int w = (int) (p.getX() * pageScale); int h = (int) (p.getY() * pageScale); int cols = (int) Math.max(Math.ceil((double) (pSize.width - 5) / (double) w), 1); int rows = (int) Math.max(Math.ceil((double) (pSize.height - 5) / (double) h), 1); g2.setColor(graph.getHandleColor()); // Draws the pages. Point offset = getViewPosition(); g2.translate(-offset.x, -offset.y); g2.fillRect(0, 0, graph.getWidth(), graph.getHeight()); g2.setColor(Color.darkGray); g2.fillRect(3, 3, cols * w, rows * h); g2.setColor(getGraph().getBackground()); g2.fillRect(1, 1, cols * w - 1, rows * h - 1); // Draws the pagebreaks. Stroke previousStroke = g2.getStroke(); g2.setStroke( new BasicStroke( 1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, new float[] {1, 2}, 0)); g2.setColor(Color.darkGray); for (int i = 1; i < cols; i++) g2.drawLine(i * w, 1, i * w, rows * h - 1); for (int i = 1; i < rows; i++) g2.drawLine(1, i * h, cols * w - 1, i * h); // Restores the graphics. g2.setStroke(previousStroke); g2.translate(offset.x, offset.y); g2.clipRect(0, 0, cols * w - 1 - offset.x, rows * h - 1 - offset.y); }
@Override protected void paintComponent(Graphics g) { Graphics2D g2d = (Graphics2D) g; Rectangle b = getBounds(); // dessiner un fond de couleur Color bgColor = color != null ? color : Color.white; g2d.setColor(bgColor); g2d.fillRect(0, 0, b.width, b.height); // si la couleur est nulle, dessiner une diagonale if (color == null) { g2d.setColor(borderColor); g2d.setStroke(new BasicStroke(borderThickness + 1)); g2d.drawLine(0, 0, b.width, b.height); } // bordure g2d.setStroke(new BasicStroke(borderThickness)); g2d.setColor(borderColor); g2d.drawRect( borderThickness / 2, borderThickness / 2, b.width - borderThickness, b.height - borderThickness); }
private void drawShape(Shuttle shuttle) { Graphics2D g = shuttle.g; Shape oldclip = shuttle.g.getClip(); g.setClip(shuttle.clip); Composite oldcomposite = g.getComposite(); if (shuttle.opacity != 1f) { g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, shuttle.opacity)); } AffineTransform oldtr = g.getTransform(); g.setTransform(shuttle.transform); Stroke oldStroke = g.getStroke(); Stroke newStroke = new BasicStroke(shuttle.strokeWidth, shuttle.linecap.stroke(), shuttle.linejoin.stroke()); g.setStroke(newStroke); if (shuttle.fill != null) { g.setPaint(shuttle.fill); g.fill(shuttle.shape); } if (shuttle.stroke != null) { g.setPaint(shuttle.stroke); g.draw(shuttle.shape); } g.setClip(oldclip); g.setStroke(oldStroke); g.setTransform(oldtr); g.setComposite(oldcomposite); }
public void drawExclusiveGateway(int x, int y, int width, int height) { // rhombus drawGateway(x, y, width, height); int quarterWidth = width / 4; int quarterHeight = height / 4; // X inside rhombus Stroke orginalStroke = g.getStroke(); g.setStroke(GATEWAY_TYPE_STROKE); Line2D.Double line = new Line2D.Double( x + quarterWidth + 3, y + quarterHeight + 3, x + 3 * quarterWidth - 3, y + 3 * quarterHeight - 3); g.draw(line); line = new Line2D.Double( x + quarterWidth + 3, y + 3 * quarterHeight - 3, x + 3 * quarterWidth - 3, y + quarterHeight + 3); g.draw(line); g.setStroke(orginalStroke); }
private void showScale(Graphics g) { Graphics2D g2d = (Graphics2D) g; g2d.setColor(Color.lightGray); int y_step = 20; float[] dash1 = {2f, 0f, 2f}; Stroke strk = g2d.getStroke(); g2d.setStroke( new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 1.0f, dash1, 2f)); for (int y = m_y_offset - y_step; y > m_y_offset - (int) (m_height * 0.5); y -= y_step) g2d.drawLine(m_x_offset, y, m_width - m_x_offset, y); for (int y = m_y_offset + y_step; y < m_y_offset + (int) (m_height * 0.5); y += y_step) g2d.drawLine(m_x_offset, y, m_width - m_x_offset, y); for (int x = m_x_offset + y_step; x < m_width - m_x_offset; x += y_step) g2d.drawLine(x, m_y_offset - (int) (m_height * 0.5), x, m_y_offset + (int) (m_height * 0.5)); Font cur_Font = new Font("Arial", Font.BOLD, 8); g.setFont(cur_Font); int i = y_step; for (int y = m_y_offset - y_step; y > m_y_offset - (int) (m_height * 0.5); y -= y_step, i += y_step) g.drawString(i + "", m_width - m_x_offset, y); i = -y_step; for (int y = m_y_offset + y_step; y < m_y_offset + (int) (m_height * 0.5); y += y_step, i -= y_step) g.drawString(i + "", m_width - m_x_offset, y); g2d.setStroke(strk); }
private void drawSelectionBox(Graphics2D g2d) { // Draw the rectangular selection box if (leftMousePressed && !startedInMiniMap && !startedInHiveCreation) { Pt topLeft = new Pt(); topLeft.setX(Math.min(mouseGlobal.x(), startSelect.x())); topLeft.setY(Math.min(mouseGlobal.y(), startSelect.y())); int width = (int) Math.abs(mouseGlobal.x() - startSelect.x()); int height = (int) Math.abs(mouseGlobal.y() - startSelect.y()); g2d.setColor(Color.GREEN); Stroke original = g2d.getStroke(); int dashOneLength = 3; int dashInterval = 5; int dashTwoLength = dashOneLength * 5; g2d.setStroke( new BasicStroke( 1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] {dashOneLength, dashInterval, dashTwoLength, dashInterval}, 0)); g2d.drawRect(topLeft.intX(), topLeft.intY(), width, height); g2d.setStroke(original); } }
/** * Draws the circle. * * @param g2 the graphics device. * @param area the area in which to draw. */ public void draw(Graphics2D g2, Rectangle2D area) { Ellipse2D ellipse = new Ellipse2D.Double( area.getX(), area.getY(), area.getWidth(), area.getHeight()); if (this.fillPaint != null) { g2.setPaint(this.fillPaint); g2.fill(ellipse); } if (this.outlinePaint != null && this.outlineStroke != null) { g2.setPaint(this.outlinePaint); g2.setStroke(this.outlineStroke); g2.draw(ellipse); } g2.setPaint(Color.black); g2.setStroke(new BasicStroke(1.0f)); Line2D line1 = new Line2D.Double( area.getCenterX(), area.getMinY(), area.getCenterX(), area.getMaxY()); Line2D line2 = new Line2D.Double( area.getMinX(), area.getCenterY(), area.getMaxX(), area.getCenterY()); g2.draw(line1); g2.draw(line2); }
// Actually draws the rectangle public void draw(Graphics g) { Graphics2D g2 = (Graphics2D) g; // create a Graphics2D object if (getGradient()) { GradientPaint gradientPaint = new GradientPaint( getUpperLeftX(), getUpperLeftY(), getColor(), getUpperLeftX() + getWidth(), getUpperLeftY() + getHeight(), getColor2()); g2.setPaint(gradientPaint); } else g2.setPaint(getColor()); if (getDashed()) { float dash1[] = {10.0f}; BasicStroke dashedLine = new BasicStroke( getDashLength(), BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dash1, 0.0f); g2.setStroke(dashedLine); } else { g2.setStroke(new BasicStroke(getStrokeWidth())); } if (getFilledF()) g2.fill(new Rectangle2D.Double(getUpperLeftX(), getUpperLeftY(), getWidth(), getHeight())); else g2.draw(new Rectangle2D.Double(getUpperLeftX(), getUpperLeftY(), getWidth(), getHeight())); }
@Override public void paint( final Graphics2D g, final Rectangle srcRect, final double magnification, final boolean active, final int channels, final Layer active_layer, final List<Layer> layers) { AffineTransform gt = null; Stroke stroke = null; AffineTransform aff = this.at; // remove graphics transform if (!"true".equals(getProject().getProperty("dissector_zoom"))) { gt = g.getTransform(); g.setTransform(new AffineTransform()); // identity stroke = g.getStroke(); g.setStroke(new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER)); aff = new AffineTransform(gt); aff.concatenate(this.at); } for (final Item item : al_items) { item.paint(g, aff, active_layer); } // restore if (null != gt) g.setTransform(gt); if (null != stroke) g.setStroke(stroke); }
/** * Draws an arc. * * @param g2 the graphics device. * @param area the plot area. * @param minValue the minimum value. * @param maxValue the maximum value. * @param paint the paint. * @param stroke the stroke. */ protected void drawArc( Graphics2D g2, Rectangle2D area, double minValue, double maxValue, Paint paint, Stroke stroke) { double startAngle = valueToAngle(maxValue); double endAngle = valueToAngle(minValue); double extent = endAngle - startAngle; double x = area.getX(); double y = area.getY(); double w = area.getWidth(); double h = area.getHeight(); g2.setPaint(paint); g2.setStroke(stroke); if (paint != null && stroke != null) { Arc2D.Double arc = new Arc2D.Double(x, y, w, h, startAngle, extent, Arc2D.OPEN); g2.setPaint(paint); g2.setStroke(stroke); g2.draw(arc); } }
/** 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); } }
@Override public void paint(Graphics2D g) { g.setColor(Color.BLACK); for (NodeView view : nodes) { Node<String> node = view.getNode(); for (NodeView other : nodes) { Node<String> otherNode = other.getNode(); if (graph.connected(node, otherNode)) { Line2D l2d = new Line2D.Double(view.getX(), view.getY(), other.getX(), other.getY()); // stroke width asymptotically approaches 10 // 10 (1 - r^(w/k)) // w = weight // r = convergence time // k = scalar for weight // find edge Set<? extends WeightedEdge<String, Double>> neighboringEdges = graph.getNeighboringEdges(node); for (WeightedEdge<String, Double> edge : neighboringEdges) { if (edge.getTail() == otherNode) { Color headColor = mst != null && mst.contains(edge) ? Color.RED : Color.BLACK; Color tailColor = (edge instanceof DirectedEdge) ? new Color(headColor.getRGB() & 0x1FFFFFFF, true) : headColor; g.setPaint( new GradientPaint( new Point2D.Double(view.getX(), view.getY()), headColor, new Point2D.Double(other.getX(), other.getY()), tailColor)); float width = (float) (10 * (1f - Math.pow( 0.8f, Math.abs(edge.getWeight()) / (settings.useDistanceWeight ? 6f : 3f)))); if (edge.getWeight() >= 0) { g.setStroke(new BasicStroke(width)); } else { g.setStroke( new BasicStroke( width, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 10.0f, new float[] {width * 4}, 0)); } } } g.draw(l2d); } } super.paint(g); } }
private void plot(Graphics2D g, Material material, Shape shape, boolean subdued) { final Stroke savedStroke = g.getStroke(); g.setStroke(plotStroke); double yTensile = Inventory.tensileStrength(material, shape); final int iy = yPlotAreaBottom - (int) Math.round((yTensile / yMax) * heightPlotArea); g.setColor(subdued ? subduedBlue : Color.BLUE); g.drawLine(xPlotAreaLeft, iy, xPlotAreaRight, iy); final int nPlotPoints = 32; double yCompressive = Inventory.compressiveStrength(material, shape, 0.0); int iy0 = yPlotAreaBottom - (int) Math.round((yCompressive / yMax) * heightPlotArea); int ix0 = xPlotAreaLeft; g.setColor(subdued ? subduedRed : Color.RED); for (int i = 1; i <= nPlotPoints; i++) { double t = (double) i / nPlotPoints; double x = t * xMax; int ix1 = xPlotAreaLeft + (int) Math.round(t * widthPlotArea); yCompressive = Inventory.compressiveStrength(material, shape, x); int iy1 = yPlotAreaBottom - (int) Math.round((yCompressive / yMax) * heightPlotArea); g.drawLine(ix0, iy0, ix1, iy1); ix0 = ix1; iy0 = iy1; } g.setStroke(savedStroke); g.setColor(Color.BLACK); }
/** * Draw the decoration. If the curve is null when this is called, then curve will be set to the * exhibit displayed in the View, which should be of type PlaneCurveParameteric, if this * decoration is being used correctly. */ public void doDraw(Graphics2D g, View view, Transform limits) { if (curve == null && view != null) { Exhibit c = view.getExhibit(); if (c instanceof PlaneCurveParametric) // It better be! curve = (PlaneCurveParametric) c; else return; } if (Double.isNaN(t)) return; double x = curve.xValue(t); if (Double.isNaN(x) || Double.isInfinite(x)) return; double y = curve.yValue(t); if (Double.isNaN(y) || Double.isInfinite(y)) return; double dx = curve.xDerivativeValue(t); if (Double.isNaN(dx) || Double.isInfinite(dx)) return; double dy = curve.yDerivativeValue(t); if (Double.isNaN(dy) || Double.isInfinite(dy)) return; double length = Math.sqrt(dx * dx + dy * dy); if (length == 0) return; dx = dx / length * 40 * limits.getPixelWidth(); dy = dy / length * 40 * limits.getPixelHeight(); Color saveColor = g.getColor(); Stroke saveStroke = g.getStroke(); g.setStroke(new BasicStroke(2 * limits.getDefaultStrokeSize())); g.setColor(Color.red); g.draw(new Line2D.Double(x, y, x + dx, y + dy)); g.setColor(Color.blue); g.draw(new Line2D.Double(x, y, x - dy, y + dx)); g.setColor(saveColor); g.setStroke(saveStroke); }
public void draw(Graphics g) { Graphics2D g2d = (Graphics2D) g; int hGap = 0; int y1 = this.y1; if (hPosition) { hGap = hGap + grpage.hPosition; gapH = hGap; } y1 = y1 + hGap; Color oldC = g2d.getColor(); Stroke oldStroke = g2d.getStroke(); g2d.setColor(Color.BLUE); Composite compositeOld = g2d.getComposite(); if (selected) { g2d.setStroke(new BasicStroke(2.0f)); } g2d.drawRect(0, y1, width, height); g2d.setComposite(composite); g2d.setPaint(Color.BLUE); g2d.fill(new Rectangle(0, y1, width, height)); g2d.setComposite(compositeOld); g2d.setColor(oldC); g2d.setStroke(oldStroke); yRelative = y1; grpage.hPosition = y1 + height; }
/** 自定义虚线的绘制方法 */ protected void drawLine(Graphics2D g2d, int x1, int y1, int x2, int y2) { Stroke stroke = g2d.getStroke(); g2d.setStroke( new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, dashparams, 0)); super.drawLine(g2d, x1, y1, x2, y2); g2d.setStroke(stroke); }
@Override protected void fillTitleBar(Graphics2D g2) { Paint oldPaint = g2.getPaint(); Stroke oldStroke = g2.getStroke(); g2.setColor(new Color(241, 241, 241)); g2.setStroke(new BasicStroke(1)); g2.drawLine(0, 0, getWidth(), 0); LinearGradientPaint p = new LinearGradientPaint( 1f, 1f, 1f, getHeight() - 1, new float[] {0.0f, 0.499f, 0.5f, 1.0f}, new Color[] { new Color(230, 230, 230), new Color(202, 202, 202), new Color(202, 202, 202), new Color(178, 178, 178) }); g2.setPaint(p); g2.fillRect(0, 0, getWidth(), this.getHeight() - 1); g2.setPaint(oldPaint); g2.setColor(new Color(104, 104, 104)); g2.setStroke(new BasicStroke(1)); g2.drawLine(getX(), getHeight() - 1, getWidth(), getHeight() - 1); g2.setStroke(oldStroke); }
// 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); }
/* (non-Javadoc) * @see maptool.model.drawing.Drawable#draw(java.awt.Graphics2D, maptool.model.drawing.Pen) */ public void draw(Graphics2D g, Pen pen, int translateX, int translateY) { if (pen == null) { pen = Pen.DEFAULT; } Stroke oldStroke = g.getStroke(); g.setStroke(new BasicStroke(pen.getThickness(), BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); Composite oldComposite = g.getComposite(); if (pen.isEraser()) { g.setComposite(AlphaComposite.Clear); } if (pen.getBackgroundMode() == Pen.MODE_SOLID) { Color bgColor = new Color(pen.getBackgroundColor()); g.setColor(bgColor); drawBackground(g, translateX, translateY); } if (pen.getForegroundMode() == Pen.MODE_SOLID) { Color color = new Color(pen.getColor()); g.setColor(color); draw(g, translateX, translateY); } g.setComposite(oldComposite); g.setStroke(oldStroke); }
public void draw(Graphics g) { // 19-2-2008 Removed showing the horizontal and vertical segment constraints if (true) return; if ((m_seg.getM_parentStk().getM_type() == Stroke.TYPE_NORMAL) && (m_seg.isEnabled())) { Graphics2D g2d = (Graphics2D) g; // set the color of the graphics to the color of the segment Color prevColor = g.getColor(); g2d.setColor(getColor()); // create a dashed line for radii lines BasicStroke prevStroke = (BasicStroke) g2d.getStroke(); g2d.setColor(GVariables.DRAWING_ASSIST_COLOR); g2d.setStroke( new BasicStroke( prevStroke.getLineWidth(), prevStroke.getEndCap(), prevStroke.getLineJoin(), prevStroke.getMiterLimit(), new float[] {4, 4, 8, 4}, prevStroke.getDashPhase())); g2d.draw(marker_line); g2d.setStroke(prevStroke); g2d.draw(marker_rect); // reset the graphics color back g2d.setColor(prevColor); } }
@Override public void paintComponent(Graphics g) { Graphics2D g2d = (Graphics2D) g; super.paintComponent(g); /*TODO solution pas terrible pour les GLiens qui servent un peu ˆ rienÉ*/ for (int i = 0; i < gLiens.size(); i++) { g2d.setStroke(new BasicStroke(2)); g2d.drawLine( (int) gLiens.get(i).getA().getCentreX(), (int) gLiens.get(i).getA().getCentreY(), (int) gLiens.get(i).getB().getCentreX(), (int) gLiens.get(i).getB().getCentreY()); } for (int i = 0; i < gLiensConditionnels.size(); i++) { g2d.setColor(Color.RED); g2d.setStroke(new BasicStroke(2)); g2d.drawLine( (int) gLiensConditionnels.get(i).getA().getCentreX() - 2, (int) gLiensConditionnels.get(i).getA().getCentreY() - 2, (int) gLiensConditionnels.get(i).getB().getCentreX() - 2, (int) gLiensConditionnels.get(i).getB().getCentreY() - 2); } for (int i = 0; i < this.gLinksTrigger.size(); i++) { g2d.setColor(Color.ORANGE); g2d.setStroke(new BasicStroke(3)); g2d.drawLine( (int) gLinksTrigger.get(i).getA().getCentreX() - 2, (int) gLinksTrigger.get(i).getA().getCentreY() - 2, (int) gLinksTrigger.get(i).getB().getCentreX() - 2, (int) gLinksTrigger.get(i).getB().getCentreY() - 2); } }
protected void drawTask(String name, int x, int y, int width, int height, boolean thickBorder) { Paint originalPaint = g.getPaint(); // Create a new gradient paint for every task box, gradient depends on x and y and is not // relative g.setPaint(new GradientPaint(x + 50, y, Color.white, x + 50, y + 50, TASK_BOX_COLOR)); // shape RoundRectangle2D rect = new RoundRectangle2D.Double(x, y, width, height, 20, 20); g.fill(rect); g.setPaint(originalPaint); if (thickBorder) { Stroke originalStroke = g.getStroke(); g.setStroke(THICK_TASK_BORDER_STROKE); g.draw(rect); g.setStroke(originalStroke); } else { g.draw(rect); } // text if (name != null) { drawMultilineText(name, x, y, width, height); } }
@Override protected void paint(DecorationLayer layer, Graphics2D g, RadComponent container) { if (!layer.showSelection() || container.getClientProperty(SnapPointFeedbackHost.KEY) != null) { return; } Stroke stroke = g.getStroke(); g.setStroke(SnapPointFeedbackHost.STROKE); g.setColor(SnapPointFeedbackHost.COLOR); Rectangle bounds = container.getBounds(layer); Map<RadComponent, RelativeInfo> relativeInfos = container.getClientProperty(RelativeInfo.KEY); List<RadComponent> selection = layer.getArea().getSelection(); for (RadComponent component : selection) { RelativeInfo info = relativeInfos.get(component); if (info != null) { paintOutRelative(layer, g, component, info); paintContainerRelative(g, bounds, info); } } g.setStroke(stroke); g.setColor(JBColor.ORANGE); for (RadComponent component : selection) { RelativeInfo info = relativeInfos.get(component); if (info != null) { paintContainerMarginRelative(layer, g, bounds, (RadViewComponent) component, info); } } }
public void drawMultiInstanceMarker(boolean sequential, int x, int y, int width, int height) { int rectangleWidth = MARKER_WIDTH; int rectangleHeight = MARKER_WIDTH; int lineX = x + (width - rectangleWidth) / 2; int lineY = y + height - rectangleHeight - 3; Stroke orginalStroke = g.getStroke(); g.setStroke(MULTI_INSTANCE_STROKE); if (sequential) { g.draw(new Line2D.Double(lineX, lineY, lineX + rectangleWidth, lineY)); g.draw( new Line2D.Double( lineX, lineY + rectangleHeight / 2, lineX + rectangleWidth, lineY + rectangleHeight / 2)); g.draw( new Line2D.Double( lineX, lineY + rectangleHeight, lineX + rectangleWidth, lineY + rectangleHeight)); } else { g.draw(new Line2D.Double(lineX, lineY, lineX, lineY + rectangleHeight)); g.draw( new Line2D.Double( lineX + rectangleWidth / 2, lineY, lineX + rectangleWidth / 2, lineY + rectangleHeight)); g.draw( new Line2D.Double( lineX + rectangleWidth, lineY, lineX + rectangleWidth, lineY + rectangleHeight)); } g.setStroke(orginalStroke); }
/** * Draws the graphic item within the specified area. * * @param g2 the graphics device. * @param area the area. */ public void draw(Graphics2D g2, Rectangle2D area) { area = (Rectangle2D) area.clone(); area = trimMargin(area); drawBorder(g2, area); area = trimBorder(area); area = trimPadding(area); if (this.lineVisible) { Point2D location = RectangleAnchor.coordinates(area, this.shapeLocation); Shape aLine = ShapeUtilities.createTranslatedShape( getLine(), this.shapeAnchor, location.getX(), location.getY()); g2.setPaint(this.linePaint); g2.setStroke(this.lineStroke); g2.draw(aLine); } if (this.shapeVisible) { Point2D location = RectangleAnchor.coordinates(area, this.shapeLocation); Shape s = ShapeUtilities.createTranslatedShape( this.shape, this.shapeAnchor, location.getX(), location.getY()); if (this.shapeFilled) { g2.setPaint(this.fillPaint); g2.fill(s); } if (this.shapeOutlineVisible) { g2.setPaint(this.outlinePaint); g2.setStroke(this.outlineStroke); g2.draw(s); } } }
private void drawSelection(Graphics2D g2d) { if (srcx != destx || srcy != desty) { int x1 = (srcx < destx) ? srcx : destx; int y1 = (srcy < desty) ? srcy : desty; int x2 = (srcx > destx) ? srcx : destx; int y2 = (srcy > desty) ? srcy : desty; rectSelection.x = x1; rectSelection.y = y1; rectSelection.width = (x2 - x1) + 1; rectSelection.height = (y2 - y1) + 1; if (rectSelection.width > 0 && rectSelection.height > 0) { g2d.drawImage(scr_img.getSubimage(x1, y1, x2 - x1 + 1, y2 - y1 + 1), null, x1, y1); } g2d.setColor(selFrameColor); g2d.setStroke(bs); g2d.draw(rectSelection); int cx = (x1 + x2) / 2; int cy = (y1 + y2) / 2; g2d.setColor(selCrossColor); g2d.setStroke(_StrokeCross); g2d.drawLine(cx, y1, cx, y2); g2d.drawLine(x1, cy, x2, cy); if (Screen.getNumberScreens() > 1) { drawScreenFrame(g2d, srcScreenId); } } }
/** 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 paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g; g2d.setBackground(Color.LIGHT_GRAY); g2d.clearRect(0, 0, getParent().getWidth(), getParent().getHeight()); // Red line g2d.setPaint(Color.RED); // 5 visible, 5 invisible final float dash[] = {5, 5}; // 10 thick, end lines with no cap, // any joins make round, miter limit, // dash array, dash phase final BasicStroke dashed = new BasicStroke(10, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 0, dash, 0); g2d.setStroke(dashed); g2d.drawLine(100, 10, 10, 110); // White line g2d.setPaint(Color.WHITE); g2d.setStroke(new BasicStroke(10.0f)); g2d.draw(new Line2D.Float(150, 10, 10, 160)); // Blue line g2d.setPaint(Color.BLUE); Stroke solidStroke = new BasicStroke(10, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND); g2d.setStroke(solidStroke); g2d.draw(new Line2D.Float(new Point2D.Float(200, 10), new Point2D.Double(10, 210))); }
@Override public void draw(Graphics2D g2d, Surface s) { g2d.setPaint(getColor()); g2d.fill(getSurface()); if (getHover() && !selected) { Stroke outl = new BasicStroke(2f); g2d.setStroke(outl); if (getColor() != Color.red) g2d.setPaint(Color.red); else g2d.setPaint(Color.BLACK); g2d.drawPolygon(getSurface()); } else if (selected) { float[] dash = {4f, 0f, 2f}; BasicStroke outl = new BasicStroke( 2f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 1.0f, dash, getFramesAlive() * .2f); g2d.setStroke(outl); if (ownedby.equals(Player.NONE)) { g2d.setPaint(Color.black); } else if (ownedby.equals(Player.COMPUTER)) { g2d.setPaint(Color.RED); } else if (ownedby.equals(Player.PLAYER)) { g2d.setPaint(Color.BLUE); } g2d.drawPolygon(getSurface()); } g2d.setPaint(Color.BLUE.brighter()); for (Territory t : neighbors) { double distance; if (CalculateDistance(this.capital.x, this.capital.y, t.GetCapital().x, t.GetCapital().y) < 800) g2d.drawLine(this.capital.x, this.capital.y, t.GetCapital().x, t.GetCapital().y); else { if (CalculateDistance(this.capital.x, this.capital.y, 0, 0) < 500) { g2d.drawLine(this.capital.x, this.capital.y, 0, 70); } else if (CalculateDistance(this.capital.x, this.capital.y, 0, 0) > 500) { g2d.drawLine(this.capital.x, this.capital.y, 1280, 70); } } } if (ownedby.equals(Player.NONE)) { g2d.setPaint(Color.black); } else if (ownedby.equals(Player.COMPUTER)) { g2d.setPaint(Color.RED); } else if (ownedby.equals(Player.PLAYER)) { g2d.setPaint(Color.BLUE); } g2d.setFont(new Font("TimesRoman", Font.PLAIN, 18)); g2d.setStroke(new BasicStroke(1f)); g2d.fillOval(capital.x - 10, capital.y - 10, 20, 20); g2d.setPaint(Color.BLACK); g2d.drawOval(capital.x - 10, capital.y - 10, 20, 20); g2d.setPaint(Color.WHITE); g2d.drawString("" + armies, capital.x - 5, capital.y + 5); }