List of usage examples for java.awt.geom Path2D.Double moveTo
public abstract void moveTo(double x, double y);
From source file:it.unibo.alchemist.model.implementations.linkingrules.ConnectionBeam.java
private boolean projectedBeamOvercomesObstacle(final Position pos1, final Position pos2) { final double p1x = pos1.getCoordinate(0); final double p1y = pos1.getCoordinate(1); final double p2x = pos2.getCoordinate(0); final double p2y = pos2.getCoordinate(1); final double x = p2x - p1x; final double y = p2y - p1y; /*//from w w w. j a v a 2s . c o m * Compute the angle */ final double angle = atan2(y, x); /* * Deduce surrounding beam vertices */ final double dx = range * cos(PI / 2 + angle); final double dy = range * sin(PI / 2 + angle); /* * Enlarge the beam */ final double cx = range * cos(angle); final double cy = range * sin(angle); /* * Create the beam */ final Path2D.Double beamShape = new Path2D.Double(); beamShape.moveTo(p1x + dx - cx, p1y + dy - cy); beamShape.lineTo(p1x - dx - cx, p1y - dy - cy); beamShape.lineTo(p2x - dx + cx, p2y - dy + cy); beamShape.lineTo(p2x + dx + cx, p2y + dy + cy); beamShape.closePath(); final Area beam = new Area(beamShape); /* * Perform subtraction */ beam.subtract(obstacles); /* * Rebuild single areas */ final List<Path2D.Double> subareas = new ArrayList<>(); Path2D.Double curpath = new Path2D.Double(); final PathIterator pi = beam.getPathIterator(null); final double[] coords = new double[COORDS]; while (!pi.isDone()) { switch (pi.currentSegment(coords)) { case PathIterator.SEG_MOVETO: curpath = new Path2D.Double(); curpath.moveTo(coords[0], coords[1]); break; case PathIterator.SEG_LINETO: curpath.lineTo(coords[0], coords[1]); break; case PathIterator.SEG_CLOSE: curpath.closePath(); subareas.add(curpath); break; default: throw new IllegalArgumentException(); } pi.next(); } /* * At least one area must contain both points */ for (final Path2D.Double p : subareas) { if (p.contains(p1x, p1y) && p.contains(p2x, p2y)) { return true; } } return false; }
From source file:vteaexploration.plotgatetools.gates.PolygonGate.java
@Override public Path2D createPath2D() { Point2D p;/* w w w .j a v a 2s . co m*/ Path2D.Double polygon = new Path2D.Double(); ListIterator<Point2D.Double> itr = vertices.listIterator(); p = (Point2D) vertices.get(0); polygon.moveTo(p.getX(), p.getY()); while (itr.hasNext()) { p = (Point2D) itr.next(); polygon.lineTo(p.getX(), p.getY()); } polygon.closePath(); return polygon; }
From source file:vteaexploration.plotgatetools.gates.PolygonGate.java
@Override public Path2D createPath2DInChartSpace() { Point2D p;//from ww w . j a va2s .com Path2D.Double polygon = new Path2D.Double(); ListIterator<Point2D.Double> itr = verticesInChartSpace.listIterator(); p = (Point2D) verticesInChartSpace.get(0); //System.out.println(verticesInChartSpace.size() + " Gate points"); //System.out.println("First Point: " + p); polygon.moveTo(p.getX(), p.getY()); while (itr.hasNext()) { p = (Point2D) itr.next(); //System.out.println("Next Point: " + p); polygon.lineTo(p.getX(), p.getY()); } polygon.closePath(); return polygon; }
From source file:business.ImageManager.java
private void doDrawPath(Graphics2D big, Point ori, Point dest, Color color) { //setup para os rastros big.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); big.setStroke(new BasicStroke(0.75f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1f, new float[] { 3f, 5f, 7f, 5f, 11f, 5f, 15f, 5f, 21f, 5f, 27f, 5f, 33f, 5f }, 0f)); big.setColor(color);/*from ww w. j a va2s .c om*/ //draw path Path2D.Double path = new Path2D.Double(); path.moveTo(ori.getX(), ori.getY()); path.lineTo(dest.getX(), dest.getY()); //draw on graph big.draw(path); }
From source file:business.ImageManager.java
private void doDrawRastro(Graphics2D big, int direcao, int x, int y, Color color) { //setup para os rastros big.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); big.setStroke(/*from w w w . j a v a2 s . c o m*/ new BasicStroke(2f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1f, new float[] { 5f }, 0f)); big.setColor(color); //draw path Path2D.Double path = new Path2D.Double(); path.moveTo(x + 38, y + 38); path.lineTo(x + coordRastros[direcao - 1][0], y + coordRastros[direcao - 1][1]); //draw on graph big.draw(path); }
From source file:business.ImageManager.java
private void doDrawPathOrdemArmy(Graphics2D big, Point ori, Point dest, Color color) { //setup para os rastros big.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); big.setComposite(alcom);/*from w w w .j a va 2s .c om*/ big.setStroke(new BasicStroke(3f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1f, new float[] { 3f, 5f, 7f, 5f, 11f, 5f, 15f, 5f, 21f, 5f, 27f, 5f, 33f, 5f }, 0f)); big.setColor(color); //draw path Path2D.Double path = new Path2D.Double(); path.moveTo(ori.getX(), ori.getY()); path.curveTo(dest.getX() + 10, dest.getY() - 10, dest.getX() - 10, dest.getY() + 10, dest.getX(), dest.getY()); //draw on graph big.draw(path); }
From source file:business.ImageManager.java
private void doDrawPathOrdem(Graphics2D big, Point ori, Point dest, Color color) { //setup para os rastros big.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); big.setStroke(new BasicStroke(1.75f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1f, new float[] { 3f, 5f, 7f, 5f, 11f, 5f, 15f, 5f, 21f, 5f, 27f, 5f, 33f, 5f }, 0f)); big.setColor(color);//from w ww .j a v a 2 s . c o m //draw path Path2D.Double path = new Path2D.Double(); path.moveTo(ori.getX(), ori.getY()); path.curveTo(dest.getX() - 20, dest.getY() + 20, dest.getX() + 20, dest.getY() - 20, dest.getX() + 12, dest.getY()); //path.lineTo(dest.getX(), dest.getY()); //draw on graph big.draw(path); }
From source file:business.ImageManager.java
private Path2D.Double createArrow() { int length = this.getYellowBall().getIconWidth() - 5; int barb = this.getYellowBall().getIconWidth() / 5; double angle = Math.toRadians(20); Path2D.Double path = new Path2D.Double(); path.moveTo(-length / 2, 0); path.lineTo(length / 2, 0);//from w w w. ja v a 2s .c om double x = length / 2 - barb * Math.cos(angle); double y = barb * Math.sin(angle); path.lineTo(x, y); x = length / 2 - barb * Math.cos(-angle); y = barb * Math.sin(-angle); path.moveTo(length / 2, 0); path.lineTo(x, y); return path; }
From source file:projects.wdlf47tuc.ProcessAllSwathcal.java
/** * Plots the CMD using the existing dataset. Used whenever chart annotations change, without the * underlying plot data changing. This method identifies all sources lying within the boxed region * and loads them into the secondary list {@link #boxedSources}. * //from w ww. j a va 2s .com * @param allSources * The {@link Source}s to plot * @return * A JFreeChart presenting the colour-magnitude diagram for the current selection criteria and colours. */ private JFreeChart plotCmd() { XYSeries outside = new XYSeries("Outside"); XYSeries inside = new XYSeries("Inside"); // Use a Path2D.Double instance to determine polygon intersection Path2D.Double path = new Path2D.Double(); boxedSources.clear(); boolean performBoxSelection = (points.size() > 2); if (performBoxSelection) { // Initialise Path2D object path.moveTo(points.get(0)[0], points.get(0)[1]); for (double[] point : points) { path.lineTo(point[0], point[1]); } } for (Source source : selectedSources) { double magnitude = source.getMag(magFilter); double col1 = source.getMag(col1Filter); double col2 = source.getMag(col2Filter); double x = col1 - col2; double y = magnitude; if (performBoxSelection) { Point2D.Double point = new Point2D.Double(x, y); if (path.contains(point)) { inside.add(x, y); boxedSources.add(source); } else { outside.add(x, y); } } else { outside.add(x, y); } } final XYSeriesCollection data = new XYSeriesCollection(); data.addSeries(outside); data.addSeries(inside); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesLinesVisible(0, false); renderer.setSeriesShapesVisible(0, true); renderer.setSeriesShape(0, new Ellipse2D.Float(-0.5f, -0.5f, 1, 1)); renderer.setSeriesPaint(0, ChartColor.BLACK); renderer.setSeriesLinesVisible(1, false); renderer.setSeriesShapesVisible(1, true); renderer.setSeriesShape(1, new Ellipse2D.Float(-0.5f, -0.5f, 1, 1)); renderer.setSeriesPaint(1, ChartColor.RED); NumberAxis xAxis = new NumberAxis(col1Filter.toString() + " - " + col2Filter.toString()); xAxis.setRange(getXRange()); NumberAxis yAxis = new NumberAxis(magFilter.toString()); yAxis.setRange(getYRange()); yAxis.setInverted(true); // Configure plot XYPlot xyplot = new XYPlot(data, xAxis, yAxis, renderer); xyplot.setBackgroundPaint(Color.lightGray); xyplot.setDomainGridlinePaint(Color.white); xyplot.setDomainGridlinesVisible(true); xyplot.setRangeGridlinePaint(Color.white); // Specify selection box, if points have been specified if (!points.isEmpty()) { double[] coords = new double[points.size() * 2]; for (int i = 0; i < points.size(); i++) { double[] point = points.get(i); coords[2 * i + 0] = point[0]; coords[2 * i + 1] = point[1]; } XYPolygonAnnotation box = new XYPolygonAnnotation(coords, new BasicStroke(2.0f), Color.BLUE); xyplot.addAnnotation(box); } // Configure chart JFreeChart chart = new JFreeChart("47 Tuc CMD", xyplot); chart.setBackgroundPaint(Color.white); chart.setTitle("47 Tuc colour-magnitude diagram"); chart.removeLegend(); return chart; }
From source file:com.hp.autonomy.frontend.reports.powerpoint.PowerPointServiceImpl.java
/** * Internal implementation to add a topic map to a slide. * @param slide the slide to add to./*from w w w.j a va 2 s .c om*/ * @param anchor bounding rectangle to draw onto, in PowerPoint coordinates. * @param data the topic map data. */ private static void addTopicMap(final XSLFSlide slide, final Rectangle2D.Double anchor, final TopicMapData data) { for (final TopicMapData.Path reqPath : data.getPaths()) { final XSLFFreeformShape shape = slide.createFreeform(); final Path2D.Double path = new Path2D.Double(); boolean first = true; for (double[] point : reqPath.getPoints()) { final double x = point[0] * anchor.getWidth() + anchor.getMinX(); final double y = point[1] * anchor.getHeight() + anchor.getMinY(); if (first) { path.moveTo(x, y); first = false; } else { path.lineTo(x, y); } } path.closePath(); shape.setPath(path); shape.setStrokeStyle(2); shape.setLineColor(Color.GRAY); shape.setHorizontalCentered(true); shape.setVerticalAlignment(VerticalAlignment.MIDDLE); shape.setTextAutofit(TextShape.TextAutofit.NORMAL); final XSLFTextParagraph text = shape.addNewTextParagraph(); final XSLFTextRun textRun = text.addNewTextRun(); textRun.setText(reqPath.name); textRun.setFontColor(Color.WHITE); textRun.setBold(true); final CTShape cs = (CTShape) shape.getXmlObject(); double max = 100, min = 1, scale = 100; final CTTextNormalAutofit autoFit = cs.getTxBody().getBodyPr().getNormAutofit(); final double availHeight = path.getBounds2D().getHeight(); final int RESIZE_ATTEMPTS = 7; for (int attempts = 0; attempts < RESIZE_ATTEMPTS; ++attempts) { // PowerPoint doesn't resize the text till you edit it once, which means the text initially looks too // large when you first view the slide; so we binary-chop to get a sensible initial approximation. // OpenOffice does the text resize on load so it doesn't have this problem. autoFit.setFontScale(Math.max(1, (int) (scale * 1000))); final double textHeight = shape.getTextHeight(); if (textHeight < availHeight) { min = scale; scale = 0.5 * (min + max); } else if (textHeight > availHeight) { max = scale; scale = 0.5 * (min + max); } else { break; } } final int opacity = (int) (100000 * reqPath.getOpacity()); final Color c1 = Color.decode(reqPath.getColor()); final Color c2 = Color.decode(reqPath.getColor2()); final CTGradientFillProperties gFill = cs.getSpPr().addNewGradFill(); gFill.addNewLin().setAng(3300000); final CTGradientStopList list = gFill.addNewGsLst(); final CTGradientStop stop1 = list.addNewGs(); stop1.setPos(0); final CTSRgbColor color1 = stop1.addNewSrgbClr(); color1.setVal(new byte[] { (byte) c1.getRed(), (byte) c1.getGreen(), (byte) c1.getBlue() }); color1.addNewAlpha().setVal(opacity); final CTGradientStop stop2 = list.addNewGs(); stop2.setPos(100000); final CTSRgbColor color2 = stop2.addNewSrgbClr(); color2.setVal(new byte[] { (byte) c2.getRed(), (byte) c2.getGreen(), (byte) c2.getBlue() }); color2.addNewAlpha().setVal(opacity); if (reqPath.level > 0) { // The nodes which aren't leaf nodes can be clicked on to hide them so you can see the nodes underneath. // This only works in PowerPoint; OpenOffice doesn't seem to support it. OpenOffice has its own syntax // to do something similar, but we don't use it since PowerPoint treats it as corrupt. final String shapeId = Integer.toString(shape.getShapeId()); final CTSlide slXML = slide.getXmlObject(); final CTTimeNodeList childTnLst; final CTBuildList bldLst; if (!slXML.isSetTiming()) { final CTSlideTiming timing = slXML.addNewTiming(); final CTTLCommonTimeNodeData ctn = timing.addNewTnLst().addNewPar().addNewCTn(); ctn.setDur("indefinite"); ctn.setRestart(STTLTimeNodeRestartTypeImpl.NEVER); ctn.setNodeType(STTLTimeNodeType.TM_ROOT); childTnLst = ctn.addNewChildTnLst(); bldLst = timing.addNewBldLst(); } else { final CTSlideTiming timing = slXML.getTiming(); childTnLst = timing.getTnLst().getParArray(0).getCTn().getChildTnLst(); bldLst = timing.getBldLst(); } final CTTLTimeNodeSequence seq = childTnLst.addNewSeq(); seq.setConcurrent(true); seq.setNextAc(STTLNextActionType.SEEK); final CTTLCommonTimeNodeData common = seq.addNewCTn(); common.setRestart(STTLTimeNodeRestartType.WHEN_NOT_ACTIVE); common.setFill(STTLTimeNodeFillType.HOLD); common.setEvtFilter("cancelBubble"); common.setNodeType(STTLTimeNodeType.INTERACTIVE_SEQ); final CTTLTimeConditionList condList = common.addNewStCondLst(); final CTTLTimeCondition cond = condList.addNewCond(); cond.setEvt(STTLTriggerEvent.ON_CLICK); cond.setDelay(0); cond.addNewTgtEl().addNewSpTgt().setSpid(shapeId); final CTTLTimeCondition endSync = common.addNewEndSync(); endSync.setEvt(STTLTriggerEvent.END); endSync.setDelay(0); endSync.addNewRtn().setVal(STTLTriggerRuntimeNode.ALL); // These holdCtn* 'hold' transitions with zero delay might seem redundant; but they're exported in the // PowerPoint XML, and the online PowerPoint Office365 viewer won't support the click animations // unless they're present (e.g. from the 'Start Slide Show' button in the browser). final CTTLCommonTimeNodeData holdCtn1 = common.addNewChildTnLst().addNewPar().addNewCTn(); holdCtn1.setFill(STTLTimeNodeFillType.HOLD); holdCtn1.addNewStCondLst().addNewCond().setDelay(0); final CTTLCommonTimeNodeData holdCtn2 = holdCtn1.addNewChildTnLst().addNewPar().addNewCTn(); holdCtn2.setFill(STTLTimeNodeFillType.HOLD); holdCtn2.addNewStCondLst().addNewCond().setDelay(0); final CTTLCommonTimeNodeData clickCtn = holdCtn2.addNewChildTnLst().addNewPar().addNewCTn(); clickCtn.setPresetID(10); clickCtn.setPresetClass(STTLTimeNodePresetClassType.EXIT); clickCtn.setPresetSubtype(0); clickCtn.setFill(STTLTimeNodeFillType.HOLD); clickCtn.setGrpId(0); clickCtn.setNodeType(STTLTimeNodeType.CLICK_EFFECT); clickCtn.addNewStCondLst().addNewCond().setDelay(0); final CTTimeNodeList clickChildTnList = clickCtn.addNewChildTnLst(); final CTTLAnimateEffectBehavior animEffect = clickChildTnList.addNewAnimEffect(); animEffect.setTransition(STTLAnimateEffectTransition.OUT); animEffect.setFilter("fade"); final CTTLCommonBehaviorData cBhvr = animEffect.addNewCBhvr(); final CTTLCommonTimeNodeData bhvrCtn = cBhvr.addNewCTn(); bhvrCtn.setDur(500); cBhvr.addNewTgtEl().addNewSpTgt().setSpid(shapeId); final CTTLSetBehavior clickSet = clickChildTnList.addNewSet(); final CTTLCommonBehaviorData clickSetBhvr = clickSet.addNewCBhvr(); final CTTLCommonTimeNodeData hideCtn = clickSetBhvr.addNewCTn(); hideCtn.setDur(1); hideCtn.setFill(STTLTimeNodeFillType.HOLD); hideCtn.addNewStCondLst().addNewCond().setDelay(499); clickSetBhvr.addNewTgtEl().addNewSpTgt().setSpid(shapeId); clickSetBhvr.addNewAttrNameLst().addAttrName("style.visibility"); clickSet.addNewTo().addNewStrVal().setVal("hidden"); final CTTLBuildParagraph bldP = bldLst.addNewBldP(); bldP.setSpid(shapeId); bldP.setGrpId(0); bldP.setAnimBg(true); } } }