Example usage for java.awt BasicStroke JOIN_MITER

List of usage examples for java.awt BasicStroke JOIN_MITER

Introduction

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

Prototype

int JOIN_MITER

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

Click Source Link

Document

Joins path segments by extending their outside edges until they meet.

Usage

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;//  www .java2  s  .  co 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 ww .  j av  a 2s.  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.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 ww  . j  a va 2s.c o m*/
        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:s3ml.DFA.DFA.java

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

    for (State s : states) {
        graph.addVertex(s);/*from   www. j av a 2 s  . c  om*/
    }

    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  ww  w  . ja  va2 s .c o  m*/
            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);
}