List of usage examples for java.awt.geom GeneralPath GeneralPath
public GeneralPath()
From source file:ru.jcorp.smartstreets.gui.map.MapEditor.java
public MapEditor() { super(true);/*ww w . j a va2s . com*/ setBorder(new LineBorder(Color.BLACK)); setLayout(new BorderLayout()); loadImages(); graphModel = new DirectedSparseGraph<GraphNode, GraphLink>(); graphLayout = new StaticLayout<GraphNode, GraphLink>(graphModel); graphView = new VisualizationViewer<GraphNode, GraphLink>(graphLayout); NodesFactory nodesFactory = new NodesFactory(this); LinesFactory linesFactory = new LinesFactory(); final RenderContext<GraphNode, GraphLink> renderContext = graphView.getRenderContext(); graphMouse = new EditingModalGraphMouse<GraphNode, GraphLink>(renderContext, nodesFactory, linesFactory) { @Override protected void loadPlugins() { pickingPlugin = new PickingGraphMousePlugin<GraphNode, GraphLink>(); animatedPickingPlugin = new AnimatedPickingGraphMousePlugin<GraphNode, GraphLink>(); translatingPlugin = new TranslatingGraphMousePlugin(InputEvent.BUTTON1_MASK); scalingPlugin = new ScalingGraphMousePlugin(new CrossoverScalingControl(), 0, in, out); rotatingPlugin = new RotatingGraphMousePlugin(); shearingPlugin = new ShearingGraphMousePlugin(); labelEditingPlugin = new LabelEditingGraphMousePlugin<GraphNode, GraphLink>(); annotatingPlugin = new AnnotatingGraphMousePlugin<GraphNode, GraphLink>(rc); popupEditingPlugin = new GraphPopupMousePlugin(MapEditor.this, vertexFactory, edgeFactory); editingPlugin = new GraphEditMousePlugin(MapEditor.this, vertexFactory, edgeFactory); add(scalingPlugin); setMode(Mode.EDITING); } }; graphMouse.setMode(ModalGraphMouse.Mode.EDITING); graphView.setGraphMouse(graphMouse); renderContext.setVertexLabelTransformer(new NodesLabeler()); renderContext.setEdgeLabelTransformer(new LinesLabeler()); renderContext.setVertexIconTransformer(new Transformer<GraphNode, Icon>() { @Override public Icon transform(GraphNode graphNode) { SmartMapNode node = graphNode.getMapNode(); if (sourceNode == node) return sourceMarker; if (destNode == node) return destMarker; TrafficLight trafficLight = graphNode.getMapNode().getTrafficLight(); Policeman policeman = graphNode.getMapNode().getPoliceman(); boolean hasLighter = trafficLight != null && trafficLight.getGreenDuration() != null && trafficLight.getGreenDuration() > 0 && trafficLight.getRedDuration() != null && trafficLight.getGreenDuration() > 0; boolean hasPoliceman = policeman != null; if (hasPoliceman && hasLighter) return lightPolicemanMarker; if (hasPoliceman) return policeMarker; if (hasLighter) return lightMarker; return null; } }); renderContext.setEdgeShapeTransformer(new AbstractEdgeShapeTransformer<GraphNode, GraphLink>() { private GeneralPath instance = new GeneralPath(); @Override public Shape transform(Context<Graph<GraphNode, GraphLink>, GraphLink> graphGraphLinkContext) { instance.reset(); instance.moveTo(0.0f, 5.0f); instance.lineTo(1.0f, 5.0f); return instance; } }); graphView.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.CNTR); final Transformer<GraphLink, Paint> defaultEdgePainter = graphView.getRenderContext() .getEdgeDrawPaintTransformer(); Transformer<GraphLink, Paint> linkDrawer = new Transformer<GraphLink, Paint>() { private final Color PATH_COLOR = new Color(0x0C9E0C); @Override public Paint transform(GraphLink graphLink) { if (path != null) { SmartMapLine line = graphLink.getMapLine(); SmartMapNode startNode = line.getStartNode(); SmartMapNode endNode = line.getEndNode(); int startNodeIndex = path.indexOf(startNode); int endNodeIndex = path.indexOf(endNode); if (startNodeIndex >= 0 && endNodeIndex >= 0 && Math.abs(endNodeIndex - startNodeIndex) == 1) { if (graphLink.isCoDirectional() && (startNodeIndex > endNodeIndex)) return PATH_COLOR; if (!graphLink.isCoDirectional() && (startNodeIndex < endNodeIndex)) return PATH_COLOR; } } RoadSign sign = graphLink.getRoadSign(); if (sign != null && sign.getRuleType() == RuleType.JOURNEY_IS_FORBIDDEN) { return Color.WHITE; } return defaultEdgePainter.transform(graphLink); } }; graphView.getRenderContext().setEdgeDrawPaintTransformer(linkDrawer); graphView.getRenderContext().setArrowDrawPaintTransformer(linkDrawer); graphView.getRenderContext().setArrowFillPaintTransformer(linkDrawer); graphView.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { graphView.repaint(); } }); GraphZoomScrollPane scrollPane = new GraphZoomScrollPane(graphView); this.add(scrollPane, BorderLayout.CENTER); valueLabel = new Label(); this.add(valueLabel, BorderLayout.SOUTH); }
From source file:savant.view.tracks.ContinuousTrackRenderer.java
@Override public void render(Graphics2D g2, GraphPaneAdapter gp) throws RenderingException { renderPreCheck();// w w w. j av a 2 s .c o m AxisRange axisRange = (AxisRange) instructions.get(DrawingInstruction.AXIS_RANGE); gp.setXRange(axisRange.getXRange()); gp.setYRange(axisRange.getYRange()); if (gp.needsToResize()) return; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); ColourScheme cs = (ColourScheme) instructions.get(DrawingInstruction.COLOUR_SCHEME); Color fillcolor = cs.getColor(ColourKey.CONTINUOUS_FILL); Color linecolor = cs.getColor(ColourKey.CONTINUOUS_LINE); GeneralPath path = new GeneralPath(); double xFormXPos = Double.NaN, xFormYPos = Double.NaN; double yPixel0 = gp.transformYPos(0.0); LOG.debug("h=" + gp.getHeight() + ", yMin=" + gp.getYRange().getFrom() + ", unitHeight=" + gp.getUnitHeight() + " \u27A4 yPixel0=" + yPixel0); double maxData = 0; boolean haveOpenPath = false; boolean haveData = false; if (data != null) { for (int i = 0; i < data.size(); i++) { ContinuousRecord continuousRecord = (ContinuousRecord) data.get(i); int xPos = continuousRecord.getPosition(); float yPos = continuousRecord.getValue(); if (Float.isNaN(yPos)) { // Hit a position with no data. May need to close off the current path. if (haveOpenPath) { path.lineTo(xFormXPos, yPixel0); path.closePath(); haveOpenPath = false; } } else { haveData = true; xFormXPos = gp.transformXPos(xPos);//+gp.getUnitWidth()/2; xFormYPos = gp.transformYPos(yPos); if (!haveOpenPath) { // Start our path off with a vertical line. path.moveTo(xFormXPos, yPixel0); haveOpenPath = true; } path.lineTo(xFormXPos, xFormYPos); Rectangle2D rec = new Rectangle2D.Double( xFormXPos - ((xFormXPos - path.getCurrentPoint().getX()) / 2), 0, Math.max(xFormXPos - path.getCurrentPoint().getX(), 1), gp.getHeight()); recordToShapeMap.put(continuousRecord, rec); xFormXPos = gp.transformXPos(xPos + 1); path.lineTo(xFormXPos, xFormYPos); } if (yPos > maxData) { maxData = yPos; } } } if (!haveData) { throw new RenderingException("No data in range", RenderingException.INFO_PRIORITY); } if (haveOpenPath) { // Path needs to be closed. path.lineTo(xFormXPos, yPixel0); path.closePath(); } g2.setColor(fillcolor); g2.fill(path); g2.setColor(linecolor); g2.draw(path); if (axisRange.getYRange().getFrom() < 0) { g2.setColor(Color.darkGray); g2.draw(new Line2D.Double(0.0, yPixel0, gp.getWidth(), yPixel0)); } }