List of usage examples for java.awt Polygon Polygon
public Polygon()
From source file:ec.util.chart.swing.JTimeSeriesRendererSupport.java
private static Shape createShape(double x, double y, Rectangle2D hotspot) { Area result = new Area(new RoundRectangle2D.Double(hotspot.getX(), hotspot.getY(), hotspot.getWidth(), hotspot.getHeight(), 8, 8)); boolean right = hotspot.getMinX() > x; Polygon po = new Polygon(); po.addPoint(0, 0);// w ww. jav a 2s .co m po.addPoint(0, 10); po.addPoint(10, 0); AffineTransform af = new AffineTransform(); if (right) { af.translate(hotspot.getX() - 7, hotspot.getY() + hotspot.getHeight() / 2); af.rotate(-Math.PI / 4); } else { af.translate(hotspot.getMaxX() + 7, hotspot.getY() + hotspot.getHeight() / 2); af.rotate(Math.PI * 3 / 4); } Shape shape = af.createTransformedShape(po); result.add(new Area(shape)); return result; }
From source file:org.squidy.designer.zoom.ActionShape.java
@Override protected void paintShapeZoomedIn(PPaintContext paintContext) { Graphics2D g = paintContext.getGraphics(); RectangularShape r = (RectangularShape) getZoomedOutShape(); if (r instanceof RoundRectangle2D) { // int width = (int)(r.getMaxX()-r.getMinX()); // int height = (int)(r.getMaxY()-r.getMinY()); // BufferedImage shadeStarted = new BufferedImage(width, height, // BufferedImage.TYPE_INT_RGB); // BufferedImage shadeStopped = new BufferedImage(width, height, // BufferedImage.TYPE_INT_RGB); // BufferedImage shadeFailure = new BufferedImage(width, height, // BufferedImage.TYPE_INT_RGB); // shadeStarted.getGraphics().setColor(COLOR_STARTED); // shadeStopped.getGraphics().setColor(COLOR_STOPPED); // shadeFailure.getGraphics().setColor(COLOR_FAILURE); // shadeStarted.getGraphics().fillRect(0, 0, width, height); // shadeStopped.getGraphics().fillRect(0, 0, width, height); // shadeFailure.getGraphics().fillRect(0, 0, width, height); // g.setStroke(STROKE_ZOOMED_IN); g.setStroke(StrokeUtils.getBasicStroke(7f)); g.setColor(failure ? COLOR_FAILURE : started ? COLOR_STARTED : COLOR_STOPPED); if (polygonRendering) { if (isRenderPrimitiveRect()) { if (!isHierarchicalZoomInProgress()) { Polygon shadeHorizontal = new Polygon(); Polygon shadeVertical = new Polygon(); double shift = 1; shapeZoomedIn.setFrame(r.getMinX() + shift, r.getMinY() + shift, r.getMaxX() + shift, r.getMaxY() + shift); Rectangle bounds = shapeZoomedIn.getBounds(); shadeHorizontal.addPoint(bounds.x, bounds.y + bounds.height); shadeHorizontal.addPoint(bounds.x + bounds.width, bounds.y + bounds.height); shadeVertical.addPoint(bounds.x + bounds.width, bounds.y); shadeVertical.addPoint(bounds.x + bounds.width, bounds.y + bounds.height); shift = 5;//from www. j a v a 2 s .c o m shapeZoomedIn.setFrame(r.getMinX() + shift, r.getMinY() + shift, r.getMaxX() + shift, r.getMaxY() + shift); bounds = shapeZoomedIn.getBounds(); shadeHorizontal.addPoint(bounds.x + bounds.width, bounds.y + bounds.height); shadeHorizontal.addPoint(bounds.x, bounds.y + bounds.height); shadeVertical.addPoint(bounds.x + bounds.width, bounds.y + bounds.height); shadeVertical.addPoint(bounds.x + bounds.width, bounds.y); g.fillPolygon(shadeHorizontal); g.fillPolygon(shadeVertical); } } else { g.draw(shapeZoomedIn); } } else { for (double shift = 6.; shift >= 1.; shift -= 1.) { shapeZoomedIn.setFrame(r.getMinX() + shift, r.getMinY() + shift, r.getMaxX() + shift, r.getMaxY() + shift); if (isRenderPrimitiveRect()) { if (!isHierarchicalZoomInProgress()) { Rectangle bounds = shapeZoomedIn.getBounds(); // g.drawImage(shadeStarted,null,bounds.x, // bounds.y); // g.fillRect(bounds.x, bounds.y, bounds.width, // bounds.height); g.drawLine(bounds.x + 1, bounds.y + bounds.height, bounds.x + bounds.width - 3, bounds.y + bounds.height); g.drawLine(bounds.x + bounds.width, bounds.y + 1, bounds.x + bounds.width, bounds.y + bounds.height - 3); } } else { g.draw(shapeZoomedIn); } } } } super.paintShapeZoomedIn(paintContext); }
From source file:org.squidy.designer.zoom.ActionShape.java
@Override protected void paintShapeZoomedOut(PPaintContext paintContext) { Graphics2D g = paintContext.getGraphics(); RectangularShape r = (RectangularShape) getZoomedOutShape(); if (r instanceof RoundRectangle2D) { // g.setStroke(STROKE_ZOOMED_OUT); g.setColor(failure ? COLOR_FAILURE : started ? COLOR_STARTED : COLOR_STOPPED); g.setStroke(StrokeUtils.getBasicStroke(20f)); if (polygonRendering) { if (isRenderPrimitiveRect()) { if (!isHierarchicalZoomInProgress()) { Polygon shadeHorizontal = new Polygon(); Polygon shadeVertical = new Polygon(); double shift = 1; shapeZoomedOut.setFrame(r.getMinX() + shift, r.getMinY() + shift, r.getMaxX() + shift, r.getMaxY() + shift); Rectangle bounds = shapeZoomedOut.getBounds(); shadeHorizontal.addPoint(bounds.x, bounds.y + bounds.height); shadeHorizontal.addPoint(bounds.x + bounds.width, bounds.y + bounds.height); shadeVertical.addPoint(bounds.x + bounds.width, bounds.y); shadeVertical.addPoint(bounds.x + bounds.width, bounds.y + bounds.height); shift = 30;// ww w. j a v a 2s . co m shapeZoomedOut.setFrame(r.getMinX() + shift, r.getMinY() + shift, r.getMaxX() + shift, r.getMaxY() + shift); bounds = shapeZoomedOut.getBounds(); shadeHorizontal.addPoint(bounds.x + bounds.width, bounds.y + bounds.height); shadeHorizontal.addPoint(bounds.x, bounds.y + bounds.height); shadeVertical.addPoint(bounds.x + bounds.width, bounds.y + bounds.height); shadeVertical.addPoint(bounds.x + bounds.width, bounds.y); g.fillPolygon(shadeHorizontal); g.fillPolygon(shadeVertical); } } else { g.draw(shapeZoomedOut); } } else { for (double shift = 30.; shift >= 1.; shift -= 5.) { shapeZoomedOut.setFrame(r.getMinX() + shift, r.getMinY() + shift, r.getMaxX() + shift, r.getMaxY() + shift); if (isRenderPrimitiveRect()) { if (!isHierarchicalZoomInProgress()) { Rectangle bounds = shapeZoomedOut.getBounds(); // g.fillRect(bounds.x, bounds.y, bounds.width, // bounds.height); g.drawLine(bounds.x + 1, bounds.y + bounds.height, bounds.x + bounds.width - 3, bounds.y + bounds.height); g.drawLine(bounds.x + bounds.width, bounds.y + 1, bounds.x + bounds.width, bounds.y + bounds.height - 3); } } else { g.draw(shapeZoomedOut); } } } } super.paintShapeZoomedOut(paintContext); }
From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.internal.PdfGraphics2D.java
/** * @see Graphics#drawPolygon(int[], int[], int) *//*from ww w. j a va2 s. co m*/ @Override public void drawPolygon(final int[] xPoints, final int[] yPoints, final int nPoints) { final Polygon poly = new Polygon(); for (int i = 0; i < nPoints; i++) { poly.addPoint(xPoints[i], yPoints[i]); } draw(poly); }
From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.internal.PdfGraphics2D.java
/** * @see Graphics#fillPolygon(int[], int[], int) *///from w ww .java2 s .com @Override public void fillPolygon(final int[] xPoints, final int[] yPoints, final int nPoints) { final Polygon poly = new Polygon(); for (int i = 0; i < nPoints; i++) { poly.addPoint(xPoints[i], yPoints[i]); } fill(poly); }
From source file:lu.fisch.unimozer.Diagram.java
private void drawCompoAggregation2(Graphics2D g, MyClass thisClass, MyClass otherClass, Hashtable<MyClass, Vector<MyClass>> classUsings, boolean isComposition) { if (thisClass != otherClass) { Point thisTop = new Point(thisClass.getX() + thisClass.getWidth() / 2, thisClass.getY()); Point thisBottom = new Point(thisClass.getX() + thisClass.getWidth() / 2, thisClass.getY() + thisClass.getHeight()); Point thisLeft = new Point(thisClass.getX(), thisClass.getY() + thisClass.getHeight() / 2); Point thisRight = new Point(thisClass.getX() + thisClass.getWidth(), thisClass.getY() + thisClass.getHeight() / 2); Point[] thisPoints = { thisTop, thisBottom, thisLeft, thisRight }; Point otherTop = new Point(otherClass.getX() + otherClass.getWidth() / 2, otherClass.getY()); Point otherBottom = new Point(otherClass.getX() + otherClass.getWidth() / 2, otherClass.getY() + otherClass.getHeight()); Point otherLeft = new Point(otherClass.getX(), otherClass.getY() + otherClass.getHeight() / 2); Point otherRight = new Point(otherClass.getX() + otherClass.getWidth(), otherClass.getY() + otherClass.getHeight() / 2); Point[] otherPoints = { otherTop, otherBottom, otherLeft, otherRight }; double min = Double.MAX_VALUE; Point thisPoint = null;//from ww w. j a v a2 s . com Point otherPoint = null; double thisMin; // determine closest middelst for (int i = 0; i < thisPoints.length; i++) for (int j = 0; j < otherPoints.length; j++) { thisMin = thisPoints[i].distance(otherPoints[j]); if (thisMin < min) { min = thisMin; thisPoint = thisPoints[i]; otherPoint = otherPoints[j]; } } //Vector<MyClass> others = classUsings.get(thisClass); Vector<MyClass> usingsThisClass = classUsings.get(thisClass); // iterate through all usages /*Set<MyClass> set = classUsings.keySet(); Iterator<MyClass> itr = set.iterator(); while (itr.hasNext()) { // get the actual class ... MyClass actual = itr.next(); // ... and the list of classes it uses Vector<MyClass> actualUses = classUsings.get(actual); // iterate through that list for(MyClass used : actualUses) { // add the actual class if // - it usesd the "otherClass" // - and the actual class has not yet been captured if(used==thisClass && !usingsThisClass.contains(actual)) usingsThisClass.add(actual); } }*/ /* let's try this one ... */ for (Entry<MyClass, Vector<MyClass>> entry : classUsings.entrySet()) { // get the actual class ... MyClass actual = entry.getKey(); // ... and the list of classes it uses Vector<MyClass> actualUses = classUsings.get(actual); // iterate through that list for (MyClass used : actualUses) { // add the actual class if // - it usesd the "otherClass" // - and the actual class has not yet been captured if (used == thisClass && !usingsThisClass.contains(actual)) usingsThisClass.add(actual); } } Stroke oldStroke = g.getStroke(); if (thisPoint == thisTop) { // init number of connectionx int thisCon = 1; // init the direction into which to move int thisDir = 1; if (thisPoint.x > otherPoint.x) thisDir = -1; // loop through others to determine position for (MyClass other : usingsThisClass) { // check goto right if ((other.getCenter().y < thisClass.getCenter().y) && (other.getCenter().x >= thisClass.getCenter().x) && (other.getCenter().y > otherClass.getCenter().y) && (thisDir == 1)) thisCon++; // check goto left if ((other.getCenter().y < thisClass.getCenter().y) && (other.getCenter().x < thisClass.getCenter().x) && (other.getCenter().y > otherClass.getCenter().y) && (thisDir == -1)) thisCon++; } int con = thisCon; thisCon = (int) ((thisCon - 0.5) * (12 * thisDir)); Polygon p = new Polygon(); p.addPoint(thisCon + thisClass.getPosition().x + thisClass.getWidth() / 2, thisClass.getPosition().y); p.addPoint(thisCon + thisClass.getPosition().x + thisClass.getWidth() / 2 - 4, thisClass.getPosition().y - 8); p.addPoint(thisCon + thisClass.getPosition().x + thisClass.getWidth() / 2, thisClass.getPosition().y - 16); p.addPoint(thisCon + thisClass.getPosition().x + thisClass.getWidth() / 2 + 4, thisClass.getPosition().y - 8); if (isComposition) g.fillPolygon(p); else g.drawPolygon(p); thisPoint.y -= 15; thisPoint.x += thisCon; Point movePoint = new Point(thisPoint); movePoint.y -= (usingsThisClass.size() - con) * 8; g.setStroke(dashed); drawLine(g, thisPoint, movePoint); thisPoint = movePoint; } else if (thisPoint == thisBottom) { // init number of connectionx int thisCon = 1; // init the direction into which to move int thisDir = 1; if (thisPoint.x > otherPoint.x) thisDir = -1; // loop through others to determine position for (MyClass other : usingsThisClass) { // check goto right if ((other.getCenter().y >= thisClass.getCenter().y) && (other.getCenter().x >= thisClass.getCenter().x) && (other.getCenter().y > otherClass.getCenter().y) && (thisDir == 1)) thisCon++; // check goto left if ((other.getCenter().y >= thisClass.getCenter().y) && (other.getCenter().x < thisClass.getCenter().x) && (other.getCenter().y > otherClass.getCenter().y) && (thisDir == -1)) thisCon++; } int con = thisCon; thisCon = (int) ((thisCon - 0.5) * (12 * thisDir)); // bottom Polygon p = new Polygon(); p.addPoint(thisCon + thisClass.getPosition().x + thisClass.getWidth() / 2, thisClass.getPosition().y + thisClass.getHeight()); p.addPoint(thisCon + thisClass.getPosition().x + thisClass.getWidth() / 2 - 4, thisClass.getPosition().y + thisClass.getHeight() + 8); p.addPoint(thisCon + thisClass.getPosition().x + thisClass.getWidth() / 2, thisClass.getPosition().y + thisClass.getHeight() + 16); p.addPoint(thisCon + thisClass.getPosition().x + thisClass.getWidth() / 2 + 4, thisClass.getPosition().y + thisClass.getHeight() + 8); if (isComposition) g.fillPolygon(p); else g.drawPolygon(p); thisPoint.y += 15; thisPoint.x += thisCon; Point movePoint = new Point(thisPoint); movePoint.y += (usingsThisClass.size() - con) * 8; g.setStroke(dashed); drawLine(g, thisPoint, movePoint); thisPoint = movePoint; } else if (thisPoint == thisRight) { // init number of connectionx int thisCon = 1; // init the direction into which to move int thisDir = 1; if (thisPoint.y > otherPoint.y) thisDir = -1; // loop through others to determine position for (MyClass other : usingsThisClass) { // check goto up if ((other.getCenter().x >= thisClass.getCenter().x) && (other.getCenter().y >= thisClass.getCenter().y) && (other.getCenter().x > otherClass.getCenter().x) && (thisDir == 1)) thisCon++; // check goto down if ((other.getCenter().x >= thisClass.getCenter().x) && (other.getCenter().y < thisClass.getCenter().y) && (other.getCenter().x > otherClass.getCenter().x) && (thisDir == -1)) thisCon++; } int con = thisCon; thisCon = (int) ((thisCon - 0.5) * (12 * thisDir)); // right Polygon p = new Polygon(); //thisCON = thisClass.getConnector().getNewBottom(otherDIR); p.addPoint(thisClass.getPosition().x + thisClass.getWidth(), thisCon + thisClass.getPosition().y + thisClass.getHeight() / 2); p.addPoint(thisClass.getPosition().x + thisClass.getWidth() + 8, thisCon + thisClass.getPosition().y + thisClass.getHeight() / 2 - 4); p.addPoint(thisClass.getPosition().x + thisClass.getWidth() + 16, thisCon + thisClass.getPosition().y + thisClass.getHeight() / 2); p.addPoint(thisClass.getPosition().x + thisClass.getWidth() + 8, thisCon + thisClass.getPosition().y + thisClass.getHeight() / 2 + 4); if (isComposition) g.fillPolygon(p); else g.drawPolygon(p); thisPoint.x += 15; thisPoint.y += thisCon; Point movePoint = new Point(thisPoint); movePoint.x += (usingsThisClass.size() - con) * 8; g.setStroke(dashed); drawLine(g, thisPoint, movePoint); thisPoint = movePoint; } else // left { // init number of connectionx int thisCon = 1; // init the direction into which to move int thisDir = 1; if (thisPoint.y > otherPoint.y) thisDir = -1; // loop through others to determine position for (MyClass other : usingsThisClass) { // check goto up if ((other.getCenter().x < thisClass.getCenter().x) && (other.getCenter().y >= thisClass.getCenter().y) && (other.getCenter().x > otherClass.getCenter().x) && (thisDir == 1)) thisCon++; // check goto down if ((other.getCenter().x < thisClass.getCenter().x) && (other.getCenter().y < thisClass.getCenter().y) && (other.getCenter().x > otherClass.getCenter().x) && (thisDir == -1)) thisCon++; } int con = thisCon; thisCon = (int) ((thisCon - 0.5) * (12 * thisDir)); Polygon p = new Polygon(); p.addPoint(thisClass.getPosition().x, thisCon + thisClass.getPosition().y + thisClass.getHeight() / 2); p.addPoint(thisClass.getPosition().x - 8, thisCon + thisClass.getPosition().y + thisClass.getHeight() / 2 - 4); p.addPoint(thisClass.getPosition().x - 16, thisCon + thisClass.getPosition().y + thisClass.getHeight() / 2); p.addPoint(thisClass.getPosition().x - 8, thisCon + thisClass.getPosition().y + thisClass.getHeight() / 2 + 4); if (isComposition) g.fillPolygon(p); else g.drawPolygon(p); thisPoint.y += thisCon; thisPoint.x -= 15; Point movePoint = new Point(thisPoint); movePoint.x -= (usingsThisClass.size() - con) * 8; g.setStroke(dashed); drawLine(g, thisPoint, movePoint); thisPoint = movePoint; } //Vector<MyClass> others = classUsings.get(otherClass); Vector<MyClass> usingsOtherClass = classUsings.get(otherClass); /* // iterate through all usages set = classUsings.keySet(); itr = set.iterator(); while (itr.hasNext()) { // get the actual class ... MyClass actual = itr.next(); // ... and the list of classes it uses Vector<MyClass> actualUses = classUsings.get(actual); // iterate through that list for(MyClass used : actualUses) { // add the actual class if // - it usesd the "otherClass" // - and the actual class has not yet been captured if(used==otherClass && !usingsOtherClass.contains(actual)) usingsOtherClass.add(actual); } } */ /* let's try this one ... */ for (Entry<MyClass, Vector<MyClass>> entry : classUsings.entrySet()) { // get the actual class ... MyClass actual = entry.getKey(); // ... and the list of classes it uses Vector<MyClass> actualUses = classUsings.get(actual); // iterate through that list for (MyClass used : actualUses) { // add the actual class if // - it usesd the "otherClass" // - and the actual class has not yet been captured if (used == otherClass && !usingsOtherClass.contains(actual)) usingsOtherClass.add(actual); } } Point stopUp; Point stopDown; Point stopOut; Point step; Point start = thisPoint; Point stop; if (otherPoint == otherTop) { // init number of connectionx int otherCon = 1; // init the direction into which to move int otherDir = 1; if (otherPoint.x > thisPoint.x) otherDir = -1; // loop through others to determine position for (MyClass other : usingsOtherClass) { // check goto right if ((other.getCenter().y < otherClass.getCenter().y) && (other.getCenter().x >= otherClass.getCenter().x) && (other.getCenter().y < thisClass.getCenter().y) && (otherDir == 1)) otherCon++; // check goto left if ((other.getCenter().y < otherClass.getCenter().y) && (other.getCenter().x < otherClass.getCenter().x) && (other.getCenter().y < thisClass.getCenter().y) && (otherDir == -1)) otherCon++; } otherCon = (int) ((otherCon - 0.5) * (12 * otherDir)); otherPoint.x += otherCon; stopUp = new Point(otherPoint.x - 4, otherPoint.y - 8); stopDown = new Point(otherPoint.x + 4, otherPoint.y - 8); stopOut = new Point(otherPoint.x, otherPoint.y - 8); stop = stopOut; step = new Point(stop.x, start.y); } else if (otherPoint == otherBottom) { // init number of connectionx int otherCon = 1; // init the direction into which to move int otherDir = 1; if (otherPoint.x > thisPoint.x) otherDir = -1; // loop through others to determine position for (MyClass other : usingsOtherClass) { // check goto right if ((other.getCenter().y >= otherClass.getCenter().y) && (other.getCenter().x >= otherClass.getCenter().x) && (other.getCenter().y > thisClass.getCenter().y) && (otherDir == 1)) otherCon++; // check goto left if ((other.getCenter().y >= otherClass.getCenter().y) && (other.getCenter().x < otherClass.getCenter().x) && (other.getCenter().y > thisClass.getCenter().y) && (otherDir == -1)) otherCon++; } otherCon = (int) ((otherCon - 0.5) * (12 * otherDir)); otherPoint.x += otherCon; stopUp = new Point(otherPoint.x - 4, otherPoint.y + 8); stopDown = new Point(otherPoint.x + 4, otherPoint.y + 8); stopOut = new Point(otherPoint.x, otherPoint.y + 8); stop = stopOut; step = new Point(stop.x, start.y); } else if (otherPoint == otherRight) { // init number of connectionx int otherCon = 1; // init the direction into which to move int otherDir = 1; if (otherPoint.y > thisPoint.y) otherDir = -1; // loop through others to determine position for (MyClass other : usingsOtherClass) { // check goto up if ((other.getCenter().x >= otherClass.getCenter().x) && (other.getCenter().y >= otherClass.getCenter().y) && (other.getCenter().x > thisClass.getCenter().x) && (otherDir == 1)) otherCon++; // check goto down if ((other.getCenter().x >= otherClass.getCenter().x) && (other.getCenter().y < otherClass.getCenter().y) && (other.getCenter().x > thisClass.getCenter().x) && (otherDir == -1)) otherCon++; } otherCon = (int) ((otherCon - 0.5) * (12 * otherDir)); otherPoint.y += otherCon; stopUp = new Point(otherPoint.x + 8, otherPoint.y - 4); stopDown = new Point(otherPoint.x + 8, otherPoint.y + 4); stopOut = new Point(otherPoint.x + 8, otherPoint.y); stop = stopOut; step = new Point(start.x, stop.y); } else // left { // init number of connectionx int otherCon = 1; // init the direction into which to move int otherDir = 1; if (otherPoint.y > thisPoint.y) otherDir = -1; // loop through others to determine position for (MyClass other : usingsOtherClass) { // check goto up if ((other.getCenter().x < otherClass.getCenter().x) && (other.getCenter().y >= otherClass.getCenter().y) && (other.getCenter().x < thisClass.getCenter().x) && (otherDir == 1)) otherCon++; // check goto down if ((other.getCenter().x < otherClass.getCenter().x) && (other.getCenter().y < otherClass.getCenter().y) && (other.getCenter().x < thisClass.getCenter().x) && (otherDir == -1)) otherCon++; } otherCon = (int) ((otherCon - 0.5) * (12 * otherDir)); otherPoint.y += otherCon; stopUp = new Point(otherPoint.x - 8, otherPoint.y - 4); stopDown = new Point(otherPoint.x - 8, otherPoint.y + 4); stopOut = new Point(otherPoint.x + 8, otherPoint.y); stop = stopOut; step = new Point(start.x, stop.y); } // drawLine(g,thisPoint,otherPoint); boolean inter = false; /* if(otherClass.getPosition().y+otherClass.getHeight()/2 < thisClass.getPosition().y+thisClass.getHeight()/2) { // top if(stop.y>start.y) { step = new Point(start.x,thisClass.getPosition().y); inter = true; } else { step = new Point(start.x,stop.y); } } else { // bottom if(stop.y<thisClass.getPosition().y+thisClass.getHeight() || thisClass==otherClass) { step = new Point(start.x, thisClass.getPosition().y+thisClass.getHeight()); inter = true; } else { step = new Point(start.x,stop.y); } } drawLine(g,start,step); if(inter==true) { int middle; if(thisClass==otherClass) { middle = otherClass.getPosition().x+otherClass.getWidth()+16;//-otherCON; } else if(otherClass.getPosition().x+otherClass.getWidth()/2 > thisClass.getPosition().x+thisClass.getWidth()/2) { // left middle = (-(thisClass.getPosition().x+thisClass.getWidth())+(otherClass.getPosition().x))/2+thisClass.getPosition().x+thisClass.getWidth(); } else { // right middle = (-(otherClass.getPosition().x+otherClass.getWidth())+(thisClass.getPosition().x))/2+otherClass.getPosition().x+otherClass.getWidth(); } Point next = new Point(middle,step.y); drawLine(g,step,next); step = new Point(middle,stop.y); drawLine(g,step,next); } */ /* g.setColor(Color.red); drawLine(g,start,step); drawLine(g,step,stop); g.setColor(Color.blue); step = new Point(stop.x,start.y); drawLine(g,start,step); drawLine(g,step,stop); g.setColor(Color.orange); drawLine(g,start, new Point(start.x,(start.y+stop.y)/2)); drawLine(g,new Point(start.x,(start.y+stop.y)/2), new Point((start.x+stop.y)/2,(start.y+stop.y)/2)); drawLine(g,new Point((start.x+stop.y)/2,(start.y+stop.y)/2), new Point((start.x+stop.y)/2,stop.y)); drawLine(g,new Point((start.x+stop.y)/2,stop.y), stop); g.setColor(Color.black);/**/ drawLine(g, start, step); drawLine(g, step, stop); drawLine(g, otherPoint, stop); g.setStroke(oldStroke); drawLine(g, stopUp, otherPoint); drawLine(g, stopDown, otherPoint); } }
From source file:genlab.gui.jfreechart.EnhancedSpiderWebPlot.java
/** * Draws a radar plot polygon.//ww w . ja v a2s . c o m * * @param g2 the graphics device. * @param plotArea the area we are plotting in (already adjusted). * @param centre the centre point of the radar axes * @param info chart rendering info. * @param series the series within the dataset we are plotting * @param catCount the number of categories per radar plot * @param headH the data point height * @param headW the data point width */ protected void drawRadarPoly(Graphics2D g2, Rectangle2D plotArea, Point2D centre, PlotRenderingInfo info, int series, int catCount, double headH, double headW) { Polygon polygon = new Polygon(); EntityCollection entities = null; if (info != null) { entities = info.getOwner().getEntityCollection(); } // plot the data... for (int cat = 0; cat < catCount; cat++) { Number dataValue = getPlotValue(series, cat); if (dataValue != null) { double value = dataValue.doubleValue(); if (value >= 0) { // draw the polygon series... // Finds our starting angle from the centre for this axis double angle = getStartAngle() + (getDirection().getFactor() * cat * 360 / (catCount > 2 ? catCount : 3)); // The following angle calc will ensure there isn't a top // vertical axis - this may be useful if you don't want any // given criteria to 'appear' move important than the // others.. // + (getDirection().getFactor() // * (cat + 0.5) * 360 / catCount); // find the point at the appropriate distance end point // along the axis/angle identified above and add it to the // polygon Point2D point = getWebPoint(plotArea, angle, value / this.maxValue); polygon.addPoint((int) point.getX(), (int) point.getY()); // put an elipse at the point being plotted.. Paint paint = getSeriesPaint(series); Paint outlinePaint = getSeriesOutlinePaint(series); Stroke outlineStroke = getSeriesOutlineStroke(series); Ellipse2D head = new Ellipse2D.Double(point.getX() - headW / 2, point.getY() - headH / 2, headW, headH); g2.setPaint(paint); g2.fill(head); g2.setStroke(outlineStroke); g2.setPaint(outlinePaint); g2.draw(head); if (entities != null) { int row = 0; int col = 0; if (this.dataExtractOrder == TableOrder.BY_ROW) { row = series; col = cat; } else { row = cat; col = series; } String tip = null; if (this.toolTipGenerator != null) { tip = this.toolTipGenerator.generateToolTip(this.dataset, row, col); } String url = null; if (this.urlGenerator != null) { url = this.urlGenerator.generateURL(this.dataset, row, col); } Shape area = new Rectangle((int) (point.getX() - headW), (int) (point.getY() - headH), (int) (headW * 2), (int) (headH * 2)); CategoryItemEntity entity = new CategoryItemEntity(area, tip, url, this.dataset, this.dataset.getRowKey(row), this.dataset.getColumnKey(col)); entities.add(entity); } } } } // Plot the polygon Paint paint = getSeriesPaint(series); g2.setPaint(paint); g2.setStroke(getSeriesOutlineStroke(series)); g2.draw(polygon); // Lastly, fill the web polygon if this is required if (this.webFilled) { g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.1f)); g2.fill(polygon); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getForegroundAlpha())); } }
From source file:spinworld.gui.RadarPlot.java
/** * Draws a radar plot polygon./*from www . j ava2s . c o m*/ * * @param g2 the graphics device. * @param plotArea the area we are plotting in (already adjusted). * @param centre the centre point of the radar axes * @param info chart rendering info. * @param series the series within the dataset we are plotting * @param catCount the number of categories per radar plot * @param headH the data point height * @param headW the data point width */ protected void drawRadarPoly(Graphics2D g2, Rectangle2D plotArea, Point2D centre, PlotRenderingInfo info, int series, int catCount, double headH, double headW) { Polygon polygon = new Polygon(); EntityCollection entities = null; if (info != null) { entities = info.getOwner().getEntityCollection(); } // plot the data... for (int cat = 0; cat < catCount; cat++) { Number dataValue = getPlotValue(series, cat); if (dataValue != null) { double value = dataValue.doubleValue(); // Finds our starting angle from the centre for this axis double angle = getStartAngle() + (getDirection().getFactor() * cat * 360 / catCount); // The following angle calc will ensure there isn't a top // vertical axis - this may be useful if you don't want any // given criteria to 'appear' move important than the // others.. // + (getDirection().getFactor() // * (cat + 0.5) * 360 / catCount); // find the point at the appropriate distance end point // along the axis/angle identified above and add it to the // polygon double _maxValue = getMaxValue(cat).doubleValue(); double _origin = getOrigin(cat).doubleValue(); double lowerBound = Math.min(_origin, _maxValue); double upperBound = Math.max(_origin, _maxValue); boolean lesser = value < lowerBound; boolean greater = value > upperBound; if ((lesser || greater) && !drawOutOfRangePoints) { continue; } if (lesser) { value = lowerBound; } if (greater) { value = upperBound; } double length = _maxValue == _origin ? 0 : (value - lowerBound) / (upperBound - lowerBound); if (_maxValue < _origin) { // inversed length = 1 - length; } Point2D point = getWebPoint(plotArea, angle, length); polygon.addPoint((int) point.getX(), (int) point.getY()); Paint paint = getSeriesPaint(series); Paint outlinePaint = getSeriesOutlinePaint(series); double px = point.getX(); double py = point.getY(); g2.setPaint(paint); if (lesser || greater) { // user crosshair for out-of-range data points distinguish g2.setStroke(new BasicStroke(1.5f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_BEVEL)); double delta = 3; g2.draw(new Line2D.Double(px - delta, py, px + delta, py)); g2.draw(new Line2D.Double(px, py - delta, px, py + delta)); } else { // put an elipse at the point being plotted.. Ellipse2D head = new Ellipse2D.Double(px - headW / 2, py - headH / 2, headW, headH); g2.fill(head); g2.setStroke(getHeadOutlineStroke(series)); g2.setPaint(outlinePaint); g2.draw(head); } if (entities != null) { int row = 0; int col = 0; if (this.dataExtractOrder == TableOrder.BY_ROW) { row = series; col = cat; } else { row = cat; col = series; } String tip = null; if (this.toolTipGenerator != null) { tip = this.toolTipGenerator.generateToolTip(this.dataset, row, col); } String url = null; if (this.urlGenerator != null) { url = this.urlGenerator.generateURL(this.dataset, row, col); } Shape area = new Rectangle((int) (point.getX() - headW), (int) (point.getY() - headH), (int) (headW * 2), (int) (headH * 2)); CategoryItemEntity entity = new CategoryItemEntity(area, tip, url, this.dataset, this.dataset.getRowKey(row), this.dataset.getColumnKey(col)); entities.add(entity); } } } // Plot the polygon Paint paint = getSeriesPaint(series); g2.setPaint(paint); g2.setStroke(getSeriesOutlineStroke(series)); g2.draw(polygon); // Lastly, fill the web polygon if this is required if (this.webFilled) { g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.1f)); g2.fill(polygon); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getForegroundAlpha())); } }
From source file:smlm.util.SRutil.java
public static double area(Point[] points) { Polygon polygon = new Polygon(); for (int i = 0; i < points.length; i++) { polygon.addPoint((int) (points[i].x + 0.5D), (int) (points[i].y + 0.5D)); }// w ww . j av a 2 s . c o m return area(polygon); }
From source file:com.actelion.research.table.view.JVisualization.java
public void mousePressed(MouseEvent e) { mMouseX1 = mMouseX2 = e.getX();//from w w w. j a v a 2s .c o m mMouseY1 = mMouseY2 = e.getY(); mMouseIsDown = true; if (System.getProperty("touch") != null) { new Thread() { public void run() { try { Thread.sleep(1000); } catch (InterruptedException ie) { } if (Math.abs(mMouseX2 - mMouseX1) < 5 && Math.abs(mMouseY2 - mMouseY1) < 5 && mMouseIsDown) { SwingUtilities.invokeLater(new Runnable() { public void run() { activateTouchFunction(); } }); } } }.start(); } mRectangleSelecting = false; mLassoSelecting = false; if (!handlePopupTrigger(e) && (e.getModifiers() & InputEvent.BUTTON3_MASK) == 0) { mAddingToSelection = e.isShiftDown(); if (e.isAltDown()) mRectangleSelecting = true; else { mLassoSelecting = true; mLassoRegion = new Polygon(); mLassoRegion.addPoint(mMouseX1, mMouseY1); mLassoRegion.addPoint(mMouseX1, mMouseY1); } } }