List of usage examples for java.awt Polygon Polygon
public Polygon()
From source file:rod_design_compute.ShowPanel.java
private void drawBlock(Rod rod, Point point, Graphics g) { int[] x = new int[4]; int[] y = new int[4]; int l = lengthBlock; double theta = rod.getAngle(); x[0] = (int) ((2 * Math.cos(theta) + Math.sin(theta)) * l / 4); y[0] = (int) ((2 * Math.sin(theta) - Math.cos(theta)) * l / 4); x[1] = (int) ((2 * Math.cos(theta) - Math.sin(theta)) * l / 4); y[1] = (int) ((2 * Math.sin(theta) + Math.cos(theta)) * l / 4); x[2] = -x[0];//from w w w .j av a 2 s . c o m y[2] = -y[0]; x[3] = -x[1]; y[3] = -y[1]; Polygon block = new Polygon(); for (int i = 0; i < 4; i++) { x[i] = toScreenX(point.X) + x[i]; y[i] = toScreenY(point.Y) - y[i]; block.addPoint(x[i], y[i]); } g.setColor(Color.white); g.fillPolygon(block); g.setColor(Color.black); g.drawPolygon(block); }
From source file:org.openfaces.component.chart.impl.renderers.XYLineFillRenderer.java
private void initializeRendererState(XYLineFillItemRendererState rendererState, XYPlot plot, double currentItemX, double zeroRangePoint) { rendererState.setLines(new ArrayList<Line2D>()); final Polygon polygon = new Polygon(); rendererState.setAreaPolygon(polygon); addPointToAreaPolygon(polygon, plot, currentItemX, zeroRangePoint); }
From source file:org.eurocarbdb.application.glycoworkbench.plugin.reporting.AnnotationReportCanvas.java
protected void computeConnections() { connections = new HashMap<AnnotationObject, Polygon>(); connections_cp = new HashMap<AnnotationObject, Point2D>(); for (AnnotationObject a : theDocument.getAnnotations()) { Rectangle rect = rectangles_complete.get(a); Point2D cp = dataToScreenCoords(theDocument.getControlPoint(a)); Point2D peak = dataToScreenCoords(a.getPeakPoint()); // select anchor Point2D anchor = computeAnchor(rect, cp, peak); boolean add_cp = (peak.getY() > bottom(rect)); if (anchor.distance(peak) > 10) { // create shape Polygon connection = new Polygon(); connection.addPoint((int) anchor.getX(), (int) anchor.getY()); if (add_cp) connection.addPoint((int) cp.getX(), (int) cp.getY()); connection.addPoint((int) peak.getX(), (int) peak.getY()); if (add_cp) connection.addPoint((int) cp.getX(), (int) cp.getY()); // save connections.put(a, connection); if (add_cp) connections_cp.put(a, cp); }//www.j a va2 s . c o m } }
From source file:dk.dma.epd.common.prototype.gui.voct.VOCTAdditionalInfoPanel.java
/** * {@inheritDoc}/*from w w w . java2 s.co m*/ */ @Override public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHints(GraphicsUtil.ANTIALIAS_HINT); // Define the content rectangle int x0 = pointerLeft ? pad + pointerWidth : pad; RoundRectangle2D.Double content = new RoundRectangle2D.Double(x0, pad, width - 2 * pad - pointerWidth, height - 2 * pad, cornerRadius, cornerRadius); // Define the pointer triangle int xp = pointerLeft ? pad + pointerWidth : width - pad - pointerWidth; int yp = pad + height - pointerFromBottom; Polygon pointer = new Polygon(); pointer.addPoint(xp, yp); pointer.addPoint(xp, yp - pointerHeight); pointer.addPoint(xp + pointerWidth * (pointerLeft ? -1 : 1), yp - pointerHeight / 2); // Combine content rectangle and pointer into one area Area area = new Area(content); area.add(new Area(pointer)); // Fill the pop-up background Color col = pointerLeft ? c.getBackground().darker() : c.getBackground().brighter(); g2.setColor(col); g2.fill(area); }
From source file:org.caleydo.view.domino.internal.Block.java
private Shape getOutlineShape() { if (this.nodeCount() == 1) return nodes().iterator().next().getRectangleBounds(); if (linearBlocks.size() == 1) { LinearBlock b = linearBlocks.get(0); Rect r1 = b.getNode(true).getRectBounds(); Rect r2 = b.getNode(false).getRectBounds(); Rectangle2D.Float r = new Rectangle2D.Float(); Rectangle2D.union(r1.asRectangle2D(), r2.asRectangle2D(), r); return r; }/*from w ww. ja v a 2s .c o m*/ Collection<Vec2f> outline = getOutline(); Polygon r = new Polygon(); for (Vec2f p : outline) r.addPoint((int) p.x(), (int) p.y()); return r; }
From source file:HelloUniverse.java
public WheelControls(float rotX, float rotY, float rotZ) { size = new Dimension(200, 200); xAngle = constrainAngle(rotX);/* ww w .j a v a2s. c o m*/ yAngle = constrainAngle(rotY); zAngle = constrainAngle(rotZ); yOrigAngle = yAngle; xOrigAngle = xAngle; zOrigAngle = zAngle; setSizes(); yPip = new Polygon(); yPip.addPoint(0, 0); yPip.addPoint(-pipSize / 2, pipSize); yPip.addPoint(pipSize / 2, pipSize); xPip = new Polygon(); xPip.addPoint(0, 0); xPip.addPoint(pipSize, -pipSize / 2); xPip.addPoint(pipSize, pipSize / 2); zPip = new Polygon(); zPip.addPoint(diameter / 2, pipOffset); zPip.addPoint(diameter / 2 - pipSize / 2, pipOffset - pipSize); zPip.addPoint(diameter / 2 + pipSize / 2, pipOffset - pipSize); addMouseListener(this); addMouseMotionListener(this); }
From source file:org.openfaces.component.chart.impl.renderers.XYLineFillRenderer.java
private Polygon createEntityArea(XYPlot plot, double previousItemX, double previousItemY, double currentItemX, double currentItemY, double nextItemX, double nextItemY, double zeroPoint) { Polygon entityAreaPolygon = new Polygon(); final int halfwayPrevX = (int) ((previousItemX + currentItemX) / 2.0); final int halfwayPrevY = (int) ((previousItemY + currentItemY) / 2.0); final int halfwayNextY = (int) ((currentItemY + nextItemY) / 2.0); final int halfwayNextX = (int) ((currentItemX + nextItemX) / 2.0); if (plot.getOrientation() == PlotOrientation.HORIZONTAL) { entityAreaPolygon.addPoint((int) zeroPoint, halfwayPrevX); entityAreaPolygon.addPoint(halfwayPrevY, halfwayPrevX); entityAreaPolygon.addPoint((int) currentItemY, (int) currentItemX); entityAreaPolygon.addPoint(halfwayNextY, halfwayNextX); entityAreaPolygon.addPoint((int) zeroPoint, halfwayNextX); } else {//from w w w .ja va2s . c o m entityAreaPolygon.addPoint(halfwayPrevX, (int) zeroPoint); entityAreaPolygon.addPoint(halfwayPrevX, halfwayPrevY); entityAreaPolygon.addPoint((int) currentItemX, (int) currentItemY); entityAreaPolygon.addPoint(halfwayNextX, halfwayNextY); entityAreaPolygon.addPoint(halfwayNextX, (int) zeroPoint); } return entityAreaPolygon; }
From source file:org.eurocarbdb.application.glycoworkbench.plugin.reporting.AnnotationReportCanvas.java
protected void paintAnnotations(Graphics2D g2d) { DecimalFormat mz_df = new DecimalFormat("0.0"); // set font/*w ww .j av a 2s. com*/ Font old_font = g2d.getFont(); Font new_font = new Font(theOptions.ANNOTATION_MZ_FONT, Font.PLAIN, theOptions.ANNOTATION_MZ_SIZE); // compute bboxes PositionManager pman = new PositionManager(); BBoxManager bbman = new BBoxManager(); computeRectangles(pman, bbman); // compute connections computeConnections(); // paint connections for (AnnotationObject a : theDocument.getAnnotations()) { boolean selected = !is_printing && selections.contains(a); // paint arrow Polygon connection = connections.get(a); if (connection != null) { g2d.setColor(theOptions.CONNECTION_LINES_COLOR); g2d.setStroke((selected) ? new BasicStroke((float) (1. + theOptions.ANNOTATION_LINE_WIDTH)) : new BasicStroke((float) theOptions.ANNOTATION_LINE_WIDTH)); g2d.draw(connection); g2d.setStroke(new BasicStroke(1)); } // paint control point if (selected) { g2d.setColor(Color.black); Point2D cp = connections_cp.get(a); if (cp != null) { int s = (int) (2 + theOptions.ANNOTATION_LINE_WIDTH); g2d.fill(new Rectangle((int) cp.getX() - s, (int) cp.getY() - s, 2 * s, 2 * s)); } } } // paint glycans for (AnnotationObject a : theDocument.getAnnotations()) { boolean highlighted = a.isHighlighted(); boolean selected = !is_printing && selections.contains(a); // set scale theGlycanRenderer.getGraphicOptions().setScale(theOptions.SCALE_GLYCANS * theDocument.getScale(a)); // paint highlighted region if (highlighted) { Rectangle c_bbox = rectangles_complete.get(a); g2d.setColor(theOptions.HIGHLIGHTED_COLOR); g2d.setXORMode(Color.white); g2d.fill(c_bbox); g2d.setPaintMode(); g2d.setColor(Color.black); g2d.draw(c_bbox); } // paint glycan for (Glycan s : a.getStructures()) theGlycanRenderer.paint(g2d, s, null, null, false, false, pman, bbman); // paint MZ text g2d.setFont(new_font); g2d.setColor(theOptions.MASS_TEXT_COLOR); String mz_text = mz_df.format(a.getPeakPoint().getX()); Rectangle mz_bbox = rectangles_text.get(a); g2d.drawString(mz_text, mz_bbox.x, mz_bbox.y + mz_bbox.height); // paint selection if (selected) { // paint rectangle Rectangle c_bbox = rectangles_complete.get(a); g2d.setStroke(new BasicStroke(highlighted ? 2 : 1)); g2d.setColor(Color.black); g2d.draw(c_bbox); g2d.setStroke(new BasicStroke(1)); // paint resize points Polygon p1 = new Polygon(); int cx1 = right(c_bbox); int cy1 = top(c_bbox); p1.addPoint(cx1, cy1); p1.addPoint(cx1 - 2 * theOptions.ANNOTATION_MARGIN / 3, cy1); p1.addPoint(cx1, cy1 + 2 * theOptions.ANNOTATION_MARGIN / 3); g2d.fill(p1); Polygon p2 = new Polygon(); int cx2 = left(c_bbox); int cy2 = top(c_bbox); p2.addPoint(cx2, cy2); p2.addPoint(cx2 + 2 * theOptions.ANNOTATION_MARGIN / 3, cy2); p2.addPoint(cx2, cy2 + 2 * theOptions.ANNOTATION_MARGIN / 3); g2d.fill(p2); } } g2d.setFont(old_font); }
From source file:at.tuwien.ifs.somtoolbox.visualization.thematicmap.SOMRegion.java
public void calcGrids() { Rectangle2D rect = getBounds2D(); double w = rect.getWidth(); double h = rect.getHeight(); if (h > 150 || w > 150) { Logger.getLogger("at.tuwien.ifs.somtoolbox").fine("Error: " + this); return;//from w w w . j ava2s .c o m } int x = (int) rect.getX(); int y = (int) rect.getY(); int xSteps = (int) (w / (int) Grid.SIZE); int ySteps = (int) (h / (int) Grid.SIZE); for (int i = 0; i < xSteps; i++) { for (int j = 0; j < ySteps; j++) { Polygon p = new Polygon(); p.addPoint((int) (x + i * Grid.SIZE), (int) (y + j * Grid.SIZE)); p.addPoint((int) (x + i * Grid.SIZE + Grid.SIZE), (int) (y + j * Grid.SIZE)); p.addPoint((int) (x + i * Grid.SIZE + Grid.SIZE), (int) (y + Grid.SIZE + j * Grid.SIZE)); p.addPoint((int) (x + i * Grid.SIZE), (int) (y + Grid.SIZE + j * Grid.SIZE)); if (this.contains(p.getBounds().x + Grid.SIZE / 2, p.getBounds().y + Grid.SIZE / 2)) { Pnt topLeft = new Pnt(x + i * Grid.SIZE, y + j * Grid.SIZE); Pnt bottomRight = new Pnt(x + i * Grid.SIZE + Grid.SIZE, y + Grid.SIZE + j * Grid.SIZE); Grid grid = new Grid(topLeft, bottomRight); grids.add(grid); } } } }
From source file:dk.dma.epd.common.prototype.gui.notification.ChatServicePanel.java
/** * {@inheritDoc}//from www . j ava 2 s. co m */ @Override public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHints(GraphicsUtil.ANTIALIAS_HINT); // Define the content rectangle int x0 = pointerLeft ? pad + pointerWidth : pad; RoundRectangle2D.Double content = new RoundRectangle2D.Double(x0, pad, width - 2 * pad - pointerWidth, height - 2 * pad, cornerRadius, cornerRadius); // Define the pointer triangle int xp = pointerLeft ? pad + pointerWidth : width - pad - pointerWidth; int yp = pad + height - pointerFromBottom; Polygon pointer = new Polygon(); pointer.addPoint(xp, yp); pointer.addPoint(xp, yp - pointerHeight); pointer.addPoint(xp + pointerWidth * (pointerLeft ? -1 : 1), yp - pointerHeight / 2); // Combine content rectangle and pointer into one area Area area = new Area(content); area.add(new Area(pointer)); // Fill the pop-up background Color col = pointerLeft ? c.getBackground().darker() : c.getBackground().brighter(); g2.setColor(col); g2.fill(area); if (message.getSeverity() == MaritimeTextingNotificationSeverity.WARNING || message.getSeverity() == MaritimeTextingNotificationSeverity.ALERT || message.getSeverity() == MaritimeTextingNotificationSeverity.SAFETY) { g2.setStroke(new BasicStroke(2.0f)); switch (message.getSeverity()) { case WARNING: g2.setColor(WARN_COLOR); case ALERT: g2.setColor(ALERT_COLOR); case SAFETY: g2.setColor(SAFETY_COLOR); default: g2.setColor(WARN_COLOR); } // g2.setColor(message.getSeverity() == MaritimeTextingNotificationSeverity.WARNING ? WARN_COLOR : ALERT_COLOR); g2.draw(area); } }