Example usage for java.awt BasicStroke CAP_BUTT

List of usage examples for java.awt BasicStroke CAP_BUTT

Introduction

In this page you can find the example usage for java.awt BasicStroke CAP_BUTT.

Prototype

int CAP_BUTT

To view the source code for java.awt BasicStroke CAP_BUTT.

Click Source Link

Document

Ends unclosed subpaths and dash segments with no added decoration.

Usage

From source file:org.pentaho.di.core.gui.SwingGC.java

private Stroke createStroke() {
    float[] dash;
    switch (lineStyle) {
    case SOLID:/*from  www. j av  a  2 s.  c  o m*/
        dash = null;
        break;
    case DOT:
        dash = new float[] { 5, };
        break;
    case DASHDOT:
        dash = new float[] { 10, 5, 5, 5, };
        break;
    case PARALLEL:
        dash = new float[] { 10, 5, 10, 5, };
        break;
    case DASH:
        dash = new float[] { 6, 2, };
        break;
    default:
        throw new RuntimeException("Unhandled line style!");
    }
    return new BasicStroke(lineWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 2, dash, 0);
}

From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.internal.PdfGraphics2D.java

private void setStrokeDiff(final Stroke newStroke, final Stroke oldStroke) {
    if (newStroke == oldStroke) {
        return;//from   w  w  w .  j  av a 2  s  .  c o m
    }
    if (!(newStroke instanceof BasicStroke)) {
        return;
    }
    final BasicStroke nStroke = (BasicStroke) newStroke;
    final boolean oldOk = (oldStroke instanceof BasicStroke);
    BasicStroke oStroke = null;
    if (oldOk) {
        oStroke = (BasicStroke) oldStroke;
    }
    if (!oldOk || nStroke.getLineWidth() != oStroke.getLineWidth()) {
        cb.setLineWidth(nStroke.getLineWidth());
    }
    if (!oldOk || nStroke.getEndCap() != oStroke.getEndCap()) {
        switch (nStroke.getEndCap()) {
        case BasicStroke.CAP_BUTT:
            cb.setLineCap(0);
            break;
        case BasicStroke.CAP_SQUARE:
            cb.setLineCap(2);
            break;
        default:
            cb.setLineCap(1);
        }
    }
    if (!oldOk || nStroke.getLineJoin() != oStroke.getLineJoin()) {
        switch (nStroke.getLineJoin()) {
        case BasicStroke.JOIN_MITER:
            cb.setLineJoin(0);
            break;
        case BasicStroke.JOIN_BEVEL:
            cb.setLineJoin(2);
            break;
        default:
            cb.setLineJoin(1);
        }
    }
    if (!oldOk || nStroke.getMiterLimit() != oStroke.getMiterLimit()) {
        cb.setMiterLimit(nStroke.getMiterLimit());
    }
    final boolean makeDash;
    if (oldOk) {
        if (nStroke.getDashArray() != null) {
            if (nStroke.getDashPhase() != oStroke.getDashPhase()) {
                makeDash = true;
            } else if (!Arrays.equals(nStroke.getDashArray(), oStroke.getDashArray())) {
                makeDash = true;
            } else {
                makeDash = false;
            }
        } else if (oStroke.getDashArray() != null) {
            makeDash = true;
        } else {
            makeDash = false;
        }
    } else {
        makeDash = true;
    }
    if (makeDash) {
        final float[] dash = nStroke.getDashArray();
        if (dash == null) {
            cb.setLiteral("[]0 d\n");
        } else {
            cb.setLiteral('[');
            final int lim = dash.length;
            for (int k = 0; k < lim; ++k) {
                cb.setLiteral(dash[k]);
                cb.setLiteral(' ');
            }
            cb.setLiteral(']');
            cb.setLiteral(nStroke.getDashPhase());
            cb.setLiteral(" d\n");
        }
    }
}

From source file:org.photovault.swingui.PhotoCollectionThumbView.java

private void paintThumbnail(Graphics2D g2, PhotoInfo photo, int startx, int starty, boolean isSelected) {
    log.debug("paintThumbnail entry " + photo.getUuid());
    long startTime = System.currentTimeMillis();
    long thumbReadyTime = 0;
    long thumbDrawnTime = 0;
    long endTime = 0;
    // Current position in which attributes can be drawn
    int ypos = starty + rowHeight / 2;
    boolean useOldThumbnail = false;

    Thumbnail thumbnail = null;//from  w ww  .  j a  v  a 2  s.  c  o m
    log.debug("finding thumb");
    boolean hasThumbnail = photo.hasThumbnail();
    log.debug("asked if has thumb");
    if (hasThumbnail) {
        log.debug("Photo " + photo.getUuid() + " has thumbnail");
        thumbnail = photo.getThumbnail();
        log.debug("got thumbnail");
    } else {
        /*
         Check if the thumbnail has been just invalidated. If so, use the 
         old one until we get the new thumbnail created.
         */
        thumbnail = photo.getOldThumbnail();
        if (thumbnail != null) {
            useOldThumbnail = true;
        } else {
            // No success, use default thumnail.
            thumbnail = Thumbnail.getDefaultThumbnail();
        }

        // Inform background task scheduler that we have some work to do
        ctrl.getBackgroundTaskScheduler().registerTaskProducer(this, TaskPriority.CREATE_VISIBLE_THUMBNAIL);
    }
    thumbReadyTime = System.currentTimeMillis();

    log.debug("starting to draw");
    // Find the position for the thumbnail
    BufferedImage img = thumbnail.getImage();
    if (img == null) {
        thumbnail = Thumbnail.getDefaultThumbnail();
        img = thumbnail.getImage();
    }

    float scaleX = ((float) thumbWidth) / ((float) img.getWidth());
    float scaleY = ((float) thumbHeight) / ((float) img.getHeight());
    float scale = Math.min(scaleX, scaleY);
    int w = (int) (img.getWidth() * scale);
    int h = (int) (img.getHeight() * scale);

    int x = startx + (columnWidth - w) / (int) 2;
    int y = starty + (rowHeight - h) / (int) 2;

    log.debug("drawing thumbnail");

    // Draw shadow
    int offset = isSelected ? 2 : 0;
    int shadowX[] = { x + 3 - offset, x + w + 1 + offset, x + w + 1 + offset };
    int shadowY[] = { y + h + 1 + offset, y + h + 1 + offset, y + 3 - offset };
    GeneralPath polyline = new GeneralPath(GeneralPath.WIND_EVEN_ODD, shadowX.length);
    polyline.moveTo(shadowX[0], shadowY[0]);
    for (int index = 1; index < shadowX.length; index++) {
        polyline.lineTo(shadowX[index], shadowY[index]);
    }
    ;
    BasicStroke shadowStroke = new BasicStroke(4.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER);
    Stroke oldStroke = g2.getStroke();
    g2.setStroke(shadowStroke);
    g2.setColor(Color.DARK_GRAY);
    g2.draw(polyline);
    g2.setStroke(oldStroke);

    // Paint thumbnail
    g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
    g2.drawImage(img, new AffineTransform(scale, 0f, 0f, scale, x, y), null);
    if (useOldThumbnail) {
        creatingThumbIcon.paintIcon(this, g2,
                startx + (columnWidth - creatingThumbIcon.getIconWidth()) / (int) 2,
                starty + (rowHeight - creatingThumbIcon.getIconHeight()) / (int) 2);
    }
    log.debug("Drawn, drawing decorations");
    if (isSelected) {
        Stroke prevStroke = g2.getStroke();
        Color prevColor = g2.getColor();
        g2.setStroke(new BasicStroke(3.0f));
        g2.setColor(Color.BLUE);
        g2.drawRect(x, y, w, h);
        g2.setColor(prevColor);
        g2.setStroke(prevStroke);
    }

    thumbDrawnTime = System.currentTimeMillis();

    boolean drawAttrs = (thumbWidth >= 100);
    if (drawAttrs) {
        // Increase ypos so that attributes are drawn under the image
        ypos += ((int) h) / 2 + 3;

        // Draw the attributes

        // Draw the qualoity icon to the upper left corner of the thumbnail
        int quality = photo.getQuality();
        if (showQuality && quality != 0) {
            int qx = startx + (columnWidth - quality * starIcon.getIconWidth()) / (int) 2;
            for (int n = 0; n < quality; n++) {
                starIcon.paintIcon(this, g2, qx, ypos);
                qx += starIcon.getIconWidth();
            }
            ypos += starIcon.getIconHeight();
        }
        ypos += 6;

        if (photo.getRawSettings() != null) {
            // Draw the "RAW" icon
            int rx = startx + (columnWidth + w - rawIcon.getIconWidth()) / (int) 2 - 5;
            int ry = starty + (columnWidth - h - rawIcon.getIconHeight()) / (int) 2 + 5;
            rawIcon.paintIcon(this, g2, rx, ry);
        }
        if (photo.getHistory().getHeads().size() > 1) {
            // Draw the "unresolved conflicts" icon
            int rx = startx + (columnWidth + w - 10) / (int) 2 - 20;
            int ry = starty + (columnWidth - h - 10) / (int) 2;
            g2.setColor(Color.RED);
            g2.fillRect(rx, ry, 10, 10);
        }

        Color prevBkg = g2.getBackground();
        if (isSelected) {
            g2.setBackground(Color.BLUE);
        } else {
            g2.setBackground(this.getBackground());
        }
        Font attrFont = new Font("Arial", Font.PLAIN, 10);
        FontRenderContext frc = g2.getFontRenderContext();
        if (showDate && photo.getShootTime() != null) {
            FuzzyDate fd = new FuzzyDate(photo.getShootTime(), photo.getTimeAccuracy());

            String dateStr = fd.format();
            TextLayout txt = new TextLayout(dateStr, attrFont, frc);
            // Calculate the position for the text
            Rectangle2D bounds = txt.getBounds();
            int xpos = startx + ((int) (columnWidth - bounds.getWidth())) / 2 - (int) bounds.getMinX();
            g2.clearRect(xpos - 2, ypos - 2, (int) bounds.getWidth() + 4, (int) bounds.getHeight() + 4);
            txt.draw(g2, xpos, (int) (ypos + bounds.getHeight()));
            ypos += bounds.getHeight() + 4;
        }
        String shootPlace = photo.getShootingPlace();
        if (showPlace && shootPlace != null && shootPlace.length() > 0) {
            TextLayout txt = new TextLayout(photo.getShootingPlace(), attrFont, frc);
            // Calculate the position for the text
            Rectangle2D bounds = txt.getBounds();
            int xpos = startx + ((int) (columnWidth - bounds.getWidth())) / 2 - (int) bounds.getMinX();

            g2.clearRect(xpos - 2, ypos - 2, (int) bounds.getWidth() + 4, (int) bounds.getHeight() + 4);
            txt.draw(g2, xpos, (int) (ypos + bounds.getHeight()));
            ypos += bounds.getHeight() + 4;
        }
        g2.setBackground(prevBkg);
    }
    endTime = System.currentTimeMillis();
    log.debug("paintThumbnail: exit " + photo.getUuid());
    log.debug("Thumb fetch " + (thumbReadyTime - startTime) + " ms");
    log.debug("Thumb draw " + (thumbDrawnTime - thumbReadyTime) + " ms");
    log.debug("Deacoration draw " + (endTime - thumbDrawnTime) + " ms");
    log.debug("Total " + (endTime - startTime) + " ms");
}

From source file:org.structnetalign.util.GraphImageWriter.java

public void writeGraph(UndirectedGraph<Integer, Edge> graph, File file) throws IOException {

    Dimension dim = new Dimension(width, height);

    KKLayout<Integer, Edge> layout = new KKLayout<>(graph);
    // layout.setAttractionMultiplier(attraction);
    // layout.setRepulsionMultiplier(repulsion);
    // layout.setMaxIterations(1000);
    layout.setSize(new Dimension(width - xMargin, height - yMargin));

    VisualizationImageServer<Integer, Edge> vv = new VisualizationImageServer<>(layout, dim);

    vv.setPreferredSize(dim);//from   w w w.  j ava 2 s .  com

    Transformer<Integer, Paint> vertexPaint = new Transformer<Integer, Paint>() {
        @Override
        public Paint transform(Integer i) {
            return vertexColor;
        }
    };
    vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);

    Transformer<Edge, Stroke> edgeStrokeTransformer = new Transformer<Edge, Stroke>() {
        @Override
        public Stroke transform(Edge edge) {
            if (edge instanceof HomologyEdge) {
                final float thickness = (float) edge.getWeight() * homologyThicknessCoeff;
                return new BasicStroke(thickness, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f,
                        homologyDash, 0.0f);
            } else if (edge instanceof InteractionEdge) {
                final float thickness = (float) edge.getWeight() * interactionThicknessCoeff;
                return new BasicStroke(thickness, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f,
                        interactionDash, 0.0f);
            }
            throw new IllegalArgumentException("Unknown edge type");
        }
    };
    vv.getRenderContext().setEdgeStrokeTransformer(edgeStrokeTransformer);

    Transformer<Edge, String> edgeLabeler = new Transformer<Edge, String>() {
        @Override
        public String transform(Edge edge) {
            String color = "";
            if (edge instanceof InteractionEdge) {
                color = "rgb(" + interactionColor.getRed() + "," + interactionColor.getGreen() + ","
                        + interactionColor.getBlue() + ")";
            } else if (edge instanceof HomologyEdge) {
                color = "rgb(" + homologyColor.getRed() + "," + homologyColor.getGreen() + ","
                        + homologyColor.getBlue() + ")";
            } else {
                throw new IllegalArgumentException("Unknown edge type");
            }
            String prefix = "<html><font color=\"" + color + "\">";
            String suffix = "</font></html>";
            return prefix + PipelineProperties.getInstance().getOutputFormatter().format(edge.getWeight())
                    + suffix;
        }
    };
    vv.getRenderContext().setEdgeLabelTransformer(edgeLabeler);

    Transformer<Integer, Font> vertexFont = new Transformer<Integer, Font>() {
        private final Font font = new Font("Serif", Font.BOLD, vertexFontSize);

        @Override
        public Font transform(Integer edge) {
            return font;
        }
    };
    vv.getRenderContext().setVertexFontTransformer(vertexFont);

    Transformer<Edge, Font> edgeFont = new Transformer<Edge, Font>() {
        private final Font homologyFont = new Font("Serif", Font.BOLD, homologyFontSize);
        private final Font interactionFont = new Font("Serif", Font.BOLD, interactionFontSize);

        @Override
        public Font transform(Edge edge) {
            if (edge instanceof InteractionEdge) {
                return interactionFont;
            } else if (edge instanceof HomologyEdge) {
                return homologyFont;
            }
            throw new IllegalArgumentException("Unknown edge type");
        }
    };
    vv.getRenderContext().setEdgeFontTransformer(edgeFont);

    Transformer<Integer, Shape> vertexShape = new Transformer<Integer, Shape>() {
        private final Ellipse2D CIRCLE = new Ellipse2D.Double(-vertexSize / 2.0, -vertexSize / 2.0, vertexSize,
                vertexSize);

        @Override
        public Shape transform(Integer i) {
            return CIRCLE;
        }
    };
    vv.getRenderContext().setVertexShapeTransformer(vertexShape);

    Transformer<Edge, Paint> edgeDrawPaint = new Transformer<Edge, Paint>() {
        @Override
        public Paint transform(Edge edge) {
            if (edge instanceof InteractionEdge) {
                return interactionColor;
            } else if (edge instanceof HomologyEdge) {
                return homologyColor;
            }
            throw new IllegalArgumentException("Unknown edge type");
        }
    };
    vv.getRenderContext().setEdgeDrawPaintTransformer(edgeDrawPaint);

    vv.getRenderContext().setLabelOffset(labelOffset);
    vv.getRenderer().getVertexLabelRenderer().setPosition(Position.CNTR);
    vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<Integer>());
    vv.getRenderContext().getEdgeLabelRenderer().setRotateEdgeLabels(false);
    vv.setOpaque(false);
    vv.setBackground(new Color(255, 255, 255, 0));

    writeImage(vv, file);

}

From source file:org.tellervo.desktop.graph.SkeletonPlot.java

protected BasicStroke makeStroke(float width, boolean dotted) {
    if (dotted)//ww  w. ja  v  a2  s .  c o  m
        return new BasicStroke(width, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 10f, new float[] { 8f },
                0f);
    else
        return new BasicStroke(width, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL);
}

From source file:org.wmediumd.WmediumdGraphView.java

private void setupVisualization() {
    // Create a Layout to display our graph data
    Layout<MyNode, MyLink> layout = new FRLayout<MyNode, MyLink>(graph);
    layout.setSize(new Dimension(640, 480)); // Sets the initial size of the space

    Transformer<MyNode, Paint> vertexPaint = new Transformer<MyNode, Paint>() {

        @Override//from  w  w  w. jav  a2s . com
        public Paint transform(MyNode arg0) {
            // TODO Auto-generated method stub
            return Color.ORANGE;
        }
    };
    // Transformer to draw links with dark blue color
    //      Transformer<MyLink,Paint> edgePaint = new Transformer<MyLink, Paint>() {
    //
    //         @Override
    //         public Paint transform(MyLink arg0) {
    //            // TODO Auto-generated method stub
    //            return new Color(68, 68, 68);
    //         }
    //      };

    // Set up a new stroke Transformer for the edges
    Transformer<MyLink, Stroke> edgeStrokeTransformer = new Transformer<MyLink, Stroke>() {

        @Override
        public Stroke transform(MyLink s) {

            float plossSum = s.getPlossSumFloat();

            if (plossSum > 0.0f) {
                // For each Link estimate the quality and create a custom stroke
                float dash[] = { 12.5f - s.getPlossSumFloat(), s.getPlossSumFloat() };
                return new BasicStroke(1.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 1.0f, dash, 0.0f);
            } else {
                return new BasicStroke(1.5f);
            }
        }
    };

    // Create a Visualization viewer to draw our Layout
    vViewer = new VisualizationViewer<MyNode, MyLink>(layout);
    vViewer.setPreferredSize(new Dimension(640, 480)); //Sets the viewing area size
    vViewer.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
    //vViewer.getRenderContext().setEdgeDrawPaintTransformer(edgePaint);
    vViewer.getRenderContext().setEdgeStrokeTransformer(edgeStrokeTransformer);
    vViewer.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<MyNode>());
    vViewer.getRenderer().getVertexLabelRenderer().setPosition(Position.CNTR);

}

From source file:paquete.HollywoodUI.java

private void Mostrar_grafoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Mostrar_grafoActionPerformed
    SimpleGraphView sgv = new SimpleGraphView();
    sgv.setGrafo(HollyUniverseGraph);/*from w w  w.j  av a 2 s . c o  m*/
    Layout<Actor, Arista> layout = new CircleLayout(sgv.grafo);
    layout.setSize(new Dimension(800, 600));
    BasicVisualizationServer<Actor, Arista> bvs = new BasicVisualizationServer<>(layout);
    bvs.setPreferredSize(new Dimension(850, 650));
    //agregando etiquetas al grafo
    Transformer<Actor, Paint> vertexPaint = new Transformer<Actor, Paint>() {
        public Paint transform(Actor i) {
            return Color.GREEN;
        }
    };
    float dash[] = { 10.0f };
    final Stroke edgeStroke = new BasicStroke(3.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 10.0f, dash,
            0.0f);
    Transformer<Arista, Stroke> edgeStrokeTransformer = new Transformer<Arista, Stroke>() {
        public Stroke transform(Arista s) {
            return edgeStroke;
        }
    };

    bvs.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
    //        bvs.getRenderContext().setEdgeStrokeTransformer(edgeStrokeTransformer);
    bvs.getRenderContext().setVertexLabelTransformer(new ToStringLabeller());
    bvs.getRenderContext().setEdgeLabelTransformer(new ToStringLabeller());
    bvs.getRenderer().getVertexLabelRenderer().setPosition(Position.CNTR);

    JFrame frame = new JFrame("Vista del grafo con libreria JUNG2");
    frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
    frame.getContentPane().add(bvs);
    frame.pack();
    frame.setLocationRelativeTo(this);
    frame.setVisible(true);
}

From source file:s3ml.DFA.DFA.java

public JFrame print(boolean visible) {
    DirectedSparseGraph<State, Transition> graph = new DirectedSparseGraph<>();

    for (State s : states) {
        graph.addVertex(s);/* ww  w .j ava2s.  c o  m*/
    }

    for (Transition t : transitions) {
        graph.addEdge(t, t.a, t.b, EdgeType.DIRECTED);
    }

    KKLayout<State, Transition> kkLayout = new KKLayout(graph);
    kkLayout.setSize(new Dimension(600, 600));

    final VisualizationViewer<State, Transition> vv = new VisualizationViewer<>(kkLayout);

    vv.getRenderContext().setVertexLabelTransformer(new Transformer<State, String>() {

        @Override
        public String transform(State i) {
            return i.name;
        }

    });
    vv.getRenderContext().setEdgeLabelTransformer(new Transformer<Transition, String>() {

        @Override
        public String transform(Transition i) {
            return "" + i.symbol;
        }

    });
    final Stroke stroke = new Stroke() {
        private Stroke stroke1, stroke2;

        {
            this.stroke1 = new BasicStroke(5f);
            this.stroke2 = new BasicStroke(1f);
        }

        @Override
        public Shape createStrokedShape(Shape shape) {
            return stroke2.createStrokedShape(stroke1.createStrokedShape(shape));
        }
    };
    vv.getRenderContext().setVertexStrokeTransformer(new Transformer<State, Stroke>() {
        @Override
        public Stroke transform(State i) {
            if (i.startState) {
                return new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f,
                        new float[] { 2.0f }, 0.0f);
            } else if (i.finalState) {
                return stroke;
            } else {
                return vv.getRenderContext().getGraphicsContext().getStroke();
            }
        }
    });

    vv.getRenderContext().setVertexFillPaintTransformer(new Transformer<State, Paint>() {
        @Override
        public Paint transform(State i) {
            if (i.finalState) {
                return Color.RED;
            } else if (i.startState) {
                return Color.CYAN;
            } else {
                return Color.LIGHT_GRAY;
            }
        }
    });

    DefaultModalGraphMouse gm = new DefaultModalGraphMouse();
    gm.setMode(ModalGraphMouse.Mode.TRANSFORMING);
    vv.setGraphMouse(gm);
    final JFrame frame = new JFrame("V:" + graph.getVertexCount() + " E:" + graph.getEdgeCount());
    JMenuBar jMenuBar = new JMenuBar();
    jMenuBar.add(gm.getModeMenu());
    frame.setJMenuBar(jMenuBar);
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    frame.getContentPane().add(vv);
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(visible);
    return frame;
}

From source file:s3ml.DFABuilder.java

public DFABuilder() {
    super.setName("DFA Builder");
    super.setLayout(new BorderLayout());

    textArea.setFont(new Font("monospaced", Font.PLAIN, 15));

    add(new JButton(new AbstractAction("Build DFA") {
        {//from  w w w. ja  va 2 s.com
            setPreferredSize(new Dimension(200, 100));
        }

        @Override
        public void actionPerformed(ActionEvent ae) {
            new Thread() {
                @Override
                public void run() {
                    BuildDFA();
                }
            }.start();
        }
    }), BorderLayout.PAGE_START);

    Layout<State, Transition> layout = new SpringLayout<>(graph);
    layout.setSize(new Dimension(1400, 1300));

    final VisualizationViewer<State, Transition> vv = new VisualizationViewer<>(layout);

    vv.getRenderContext().setVertexLabelTransformer(new Transformer<State, String>() {

        @Override
        public String transform(State i) {
            return i.name + "-" + i.outputSymbol;
        }

    });
    vv.getRenderContext().setEdgeLabelTransformer(new Transformer<Transition, String>() {

        @Override
        public String transform(Transition i) {
            return "" + i.symbol;
        }

    });
    final Stroke stroke = new Stroke() {
        private Stroke stroke1, stroke2;

        {
            this.stroke1 = new BasicStroke(5f);
            this.stroke2 = new BasicStroke(1f);
        }

        @Override
        public Shape createStrokedShape(Shape shape) {
            return stroke2.createStrokedShape(stroke1.createStrokedShape(shape));
        }
    };
    vv.getRenderContext().setVertexStrokeTransformer(new Transformer<State, Stroke>() {
        @Override
        public Stroke transform(State i) {
            if (i.startState) {
                return new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f,
                        new float[] { 2.0f }, 0.0f);
            } else if (i.finalState) {
                return stroke;
            } else {
                return vv.getRenderContext().getGraphicsContext().getStroke();
            }
        }
    });

    vv.getRenderContext().setVertexFillPaintTransformer(new Transformer<State, Paint>() {
        @Override
        public Paint transform(State i) {
            if (i.finalState) {
                return Color.RED;
            } else if (i.startState) {
                return Color.CYAN;
            } else {
                return Color.LIGHT_GRAY;
            }
        }
    });

    add(new JScrollPane(textArea), BorderLayout.CENTER);
}

From source file:se.ngm.ditaaeps.EpsRenderer.java

public static void renderToEps(Diagram diagram, PrintWriter out, RenderingOptions options) {
    //RenderedImage renderedImage = image;
    EpsGraphics2D g2 = new EpsGraphics2D(out,
            new Rectangle2D.Double(0, -diagram.getHeight(), diagram.getWidth(), diagram.getHeight()));

    g2.scale(1, -1); // g2 origo is top-left, eps is bottom-left

    Object antialiasSetting = antialiasSetting = RenderingHints.VALUE_ANTIALIAS_OFF;
    if (options.performAntialias())
        antialiasSetting = RenderingHints.VALUE_ANTIALIAS_ON;

    //g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, antialiasSetting);

    g2.setColor(Color.white);//from  w  w  w .  j a v  a2  s .  c o  m
    //TODO: find out why the next line does not work
    //g2.fillRect(0, 0, image.getWidth()+10, image.getHeight()+10);
    /*for(int y = 0; y < diagram.getHeight(); y ++)
      g2.drawLine(0, y, diagram.getWidth(), y);*/

    g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND));

    ArrayList shapes = diagram.getAllDiagramShapes();

    if (DEBUG)
        System.out.println("Rendering " + shapes.size() + " shapes (groups flattened)");

    Iterator shapesIt;
    if (options.dropShadows()) {
        //render shadows
        shapesIt = shapes.iterator();
        while (shapesIt.hasNext()) {
            DiagramShape shape = (DiagramShape) shapesIt.next();

            if (shape.getPoints().isEmpty())
                continue;

            //GeneralPath path = shape.makeIntoPath();
            GeneralPath path;
            path = shape.makeIntoRenderPath(diagram);

            float offset = diagram.getMinimumOfCellDimension() / 3.333f;

            if (path != null && shape.dropsShadow()) {
                GeneralPath shadow = new GeneralPath(path);
                AffineTransform translate = new AffineTransform();
                translate.setToTranslation(offset, offset);
                shadow.transform(translate);
                g2.setColor(new Color(150, 150, 150));
                g2.fill(shadow);

            }
        }

        //blur shadows

        //            if(true) {
        //                int blurRadius = 6;
        //                int blurRadius2 = blurRadius * blurRadius;
        //                float blurRadius2F = blurRadius2;
        //                float weight = 1.0f / blurRadius2F;
        //                float[] elements = new float[blurRadius2];
        //                for (int k = 0; k < blurRadius2; k++)
        //                    elements[k] = weight;
        //                Kernel myKernel = new Kernel(blurRadius, blurRadius, elements);
        //
        //                //if EDGE_NO_OP is not selected, EDGE_ZERO_FILL is the default which creates a black border
        //                ConvolveOp simpleBlur =
        //                        new ConvolveOp(myKernel, ConvolveOp.EDGE_NO_OP, null);
        //                //BufferedImage destination = new BufferedImage(image.getWidth()+blurRadius, image.getHeight()+blurRadius, image.getType());
        //                BufferedImage destination =
        //                        new BufferedImage(
        //                        image.getWidth(),
        //                        image.getHeight(),
        //                        image.getType());
        //                simpleBlur.filter(image, destination);
        //                //destination = destination.getSubimage(blurRadius/2, blurRadius/2, image.getWidth(), image.getHeight());
        //                g2 = destination.createGraphics();
        //                g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, antialiasSetting);
        //                renderedImage = destination;
        //            }
    }

    //fill and stroke

    float dashInterval = Math.min(diagram.getCellWidth(), diagram.getCellHeight()) / 2;
    //Stroke normalStroke = g2.getStroke();

    float strokeWeight = diagram.getMinimumOfCellDimension() / 10;

    Stroke normalStroke = new BasicStroke(strokeWeight,
            //10,
            BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);

    Stroke dashStroke = new BasicStroke(strokeWeight, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 0,
            new float[] { dashInterval }, 0);

    //find storage shapes
    ArrayList storageShapes = new ArrayList();
    shapesIt = shapes.iterator();
    while (shapesIt.hasNext()) {
        DiagramShape shape = (DiagramShape) shapesIt.next();
        if (shape.getType() == DiagramShape.TYPE_STORAGE) {
            storageShapes.add(shape);
            continue;
        }
    }

    //render storage shapes
    //special case since they are '3d' and should be
    //rendered bottom to top
    //TODO: known bug: if a storage object is within a bigger normal box, it will be overwritten in the main drawing loop
    //(BUT this is not possible since tags are applied to all shapes overlaping shapes)

    Collections.sort(storageShapes, new Shape3DOrderingComparator());

    g2.setStroke(normalStroke);
    shapesIt = storageShapes.iterator();
    while (shapesIt.hasNext()) {
        DiagramShape shape = (DiagramShape) shapesIt.next();

        GeneralPath path;
        path = shape.makeIntoRenderPath(diagram);

        if (!shape.isStrokeDashed()) {
            if (shape.getFillColor() != null)
                g2.setColor(shape.getFillColor());
            else
                g2.setColor(Color.white);
            g2.fill(path);
        }

        if (shape.isStrokeDashed())
            g2.setStroke(dashStroke);
        else
            g2.setStroke(normalStroke);
        g2.setColor(shape.getStrokeColor());
        g2.draw(path);
    }

    //render the rest of the shapes
    ArrayList pointMarkers = new ArrayList();
    shapesIt = shapes.iterator();
    while (shapesIt.hasNext()) {
        DiagramShape shape = (DiagramShape) shapesIt.next();
        if (shape.getType() == DiagramShape.TYPE_POINT_MARKER) {
            pointMarkers.add(shape);
            continue;
        }
        if (shape.getType() == DiagramShape.TYPE_STORAGE) {
            continue;
        }

        if (shape.getPoints().isEmpty())
            continue;

        int size = shape.getPoints().size();

        GeneralPath path;
        path = shape.makeIntoRenderPath(diagram);

        if (path != null && shape.isClosed() && !shape.isStrokeDashed()) {
            if (shape.getFillColor() != null)
                g2.setColor(shape.getFillColor());
            else
                g2.setColor(Color.white);
            g2.fill(path);
        }
        if (shape.getType() != DiagramShape.TYPE_ARROWHEAD) {
            g2.setColor(shape.getStrokeColor());
            if (shape.isStrokeDashed())
                g2.setStroke(dashStroke);
            else
                g2.setStroke(normalStroke);
            g2.draw(path);
        }
    }

    //render point markers

    g2.setStroke(normalStroke);
    shapesIt = pointMarkers.iterator();
    while (shapesIt.hasNext()) {
        DiagramShape shape = (DiagramShape) shapesIt.next();
        //if(shape.getType() != DiagramShape.TYPE_POINT_MARKER) continue;

        GeneralPath path;
        path = shape.makeIntoRenderPath(diagram);

        g2.setColor(Color.white);
        g2.fill(path);
        g2.setColor(shape.getStrokeColor());
        g2.draw(path);
    }

    //handle text
    //g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);

    Iterator textIt = diagram.getTextObjects().iterator();
    while (textIt.hasNext()) {
        DiagramText text = (DiagramText) textIt.next();
        g2.setColor(text.getColor());
        g2.setFont(text.getFont());
        g2.drawString(text.getText(), text.getXPos(), text.getYPos());
    }

    if (options.renderDebugLines() || DEBUG) {
        Stroke debugStroke = new BasicStroke(1, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
        g2.setStroke(debugStroke);
        g2.setColor(new Color(170, 170, 170));
        g2.setXORMode(Color.white);
        for (int x = 0; x < diagram.getWidth(); x += diagram.getCellWidth())
            g2.drawLine(x, 0, x, diagram.getHeight());
        for (int y = 0; y < diagram.getHeight(); y += diagram.getCellHeight())
            g2.drawLine(0, y, diagram.getWidth(), y);
    }

    g2.dispose();
}