Example usage for java.awt BasicStroke JOIN_ROUND

List of usage examples for java.awt BasicStroke JOIN_ROUND

Introduction

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

Prototype

int JOIN_ROUND

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

Click Source Link

Document

Joins path segments by rounding off the corner at a radius of half the line width.

Usage

From source file:org.pentaho.chart.plugin.jfreechart.utils.StrokeFactory.java

/**
* This method creates a BasicStroke object for border-style/line-style like dotted, solid etc
* It also incorporates border-width for the border/line width for the line.
* <p/>/*from  w w w.ja  v  a  2s . com*/
* NONE, HIDDEN, SOLID, DASHED, DOT-DASH and DOTTED are the only border-style/line-style
* that we currently support.
* The border-width/line-width: thin, medium and thick have been mapped to static widths.
*
* @param chartElement The current series element
* @param widthStyleKey The Width style key. 
* @param styleStyleKey The Style style key.
* @return BasicStroke  The basic stroke object that implements the style and width.
*/
private BasicStroke getBasicStroke(final ChartElement chartElement, final StyleKey styleStyleKey,
        final StyleKey widthStyleKey) {
    CSSValue cssValue = chartElement.getLayoutStyle().getValue(widthStyleKey);
    final String borderWidth = (cssValue != null ? cssValue.getCSSText() : null);

    float width = 0f;
    if (borderWidth != null) {
        if (borderWidth.equalsIgnoreCase(BorderWidth.THIN.toString())) {
            width = THIN;
        } else if (borderWidth.equalsIgnoreCase(BorderWidth.MEDIUM.toString())) {
            width = MEDIUM;
        } else if (borderWidth.equalsIgnoreCase(BorderWidth.THICK.toString())) {
            width = THICK;
        } else if (borderWidth.endsWith(PIXEL)) {
            final String borderWidthPixels = (borderWidth.substring(0, borderWidth.indexOf(PIXEL))).trim();
            width = Integer.parseInt(borderWidthPixels);
        } else if (borderWidth.endsWith(CENTIMETER)) {
            final String borderWidthCms = (borderWidth.substring(0, borderWidth.indexOf(CENTIMETER))).trim();
            // Convert centimeter to pixels
            width = Integer.parseInt(borderWidthCms) * CENTIMETER_TO_PIXEL;
        }
    }

    final CSSValue borderStyle = chartElement.getLayoutStyle().getValue(styleStyleKey);
    if ((borderStyle == null) || BorderStyle.NONE.getCSSText().equals(borderStyle.getCSSText())) {
        // TODO mlowery figure out why logging won't output a "lesser" priority for this call
        logger.warn(String.format("************style %s has value %s; stroke will be null", styleStyleKey.name,
                BorderStyle.NONE.getCSSText()));
        return null;
    }

    BasicStroke stroke = null;

    if (BorderStyle.SOLID.equals(borderStyle)) {
        stroke = new BasicStroke(width);
    } else if (BorderStyle.DASHED.equals(borderStyle)) {
        stroke = new BasicStroke(width, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0F,
                new float[] { 10.0F, 3.0F }, 0.F);
    } else if (BorderStyle.DOT_DASH.equals(borderStyle)) {
        stroke = new BasicStroke(width, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0F,
                new float[] { 10.0F, 3.0F, 2.0F, 2.0F }, 0.F);
    } else if (BorderStyle.DOTTED.equals(borderStyle)) {
        stroke = new BasicStroke(width, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0,
                new float[] { 0, 6, 0, 6 }, 0);
    }
    return stroke;
}

From source file:org.uva.itast.blended.omr.OMRUtils.java

public static void logFrame(PageImage pageImage, PagePoint topleft, PagePoint topright, PagePoint bottomleft,
        PagePoint bottomright, Color color, String label) {
    if (topleft == null || topright == null || bottomleft == null || bottomright == null)
        return;// w ww . j  a v a 2 s  . c o  m

    Graphics2D g = pageImage.getReportingGraphics();
    AffineTransform t = g.getTransform();
    g.setColor(color);
    g.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND, 1,
            new float[] { (float) (3 / t.getScaleX()), (float) (6 / t.getScaleY()) }, 0));

    // Point framePxUL=pageImage.toPixels(topleft.getX(), topleft.getY());
    // Point framePxUR=pageImage.toPixels(topright.getX(), topright.getY());
    // Point framePxBL=pageImage.toPixels(bottomleft.getX(),
    // bottomleft.getY());
    // Point framePxBR=pageImage.toPixels(bottomright.getX(),
    // bottomright.getY());

    g.drawLine(topleft.getXpx(), topleft.getYpx(), topright.getXpx(), topright.getYpx());
    g.drawLine(topleft.getXpx(), topleft.getYpx(), bottomleft.getXpx(), bottomleft.getYpx());
    g.drawLine(topright.getXpx(), topright.getYpx(), bottomright.getXpx(), bottomright.getYpx());
    g.drawLine(bottomleft.getXpx(), bottomleft.getYpx(), bottomright.getXpx(), bottomright.getYpx());
    if (label != null) {
        g.drawString(label, topleft.getXpx(), topleft.getYpx());
    }
}

From source file:org.uva.itast.blended.omr.scanners.BarcodeScanner.java

/**
 * @param campo//ww  w  .j  a va2  s .  c om
 */
public void markBarcode(Field campo) {
    try {
        //get bbox in pixels
        Rectangle rect = pageImage.toPixels(campo.getBBox());
        // expand the area for some tolerance
        Rectangle2D expandedArea = getExpandedArea(campo.getBBox(), (float) BARCODE_AREA_PERCENT);
        Rectangle expandedRect = pageImage.toPixels(expandedArea);

        Graphics2D g = pageImage.getReportingGraphics();
        AffineTransform t = g.getTransform();
        g.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND, 1,
                new float[] { (float) (3 / t.getScaleX()), (float) (6 / t.getScaleY()) }, 0));
        if (lastResult != null)
            g.setColor(Color.BLUE);
        else
            g.setColor(Color.RED);

        g.drawRoundRect(rect.x, rect.y, rect.width, rect.height, 3, 3);
        g.drawRoundRect(expandedRect.x, expandedRect.y, expandedRect.width, expandedRect.height, 3, 3);

        g.setFont(new Font("Arial", Font.BOLD, (int) (12 / t.getScaleX())));
        String message;
        if (lastResult != null)
            message = ((Result) lastResult.getResult()).getBarcodeFormat().toString() + "="
                    + getParsedCode(lastResult);
        else
            message = "UNRECOGNIZED!";
        g.drawString(message, rect.x, rect.y);

    } catch (Exception e) {
        logger.error("Unexpected errr while logging the image:", e);
    }

}

From source file:org.uva.itast.blended.omr.scanners.SolidSquareMarkScanner.java

/**
 * @param pageImage//ww w .j a v a  2  s  .co  m
 */
public void putEmphasisMarkOnImage(PageImage pageImage, Color color) {

    Graphics2D g = pageImage.getReportingGraphics();
    // int centerColor=imagen.getRGB(maxsimX, maxsimY);
    // g.setXORMode(new Color(centerColor));
    // g.setColor(Color.RED);
    // g.fillOval(maxsimX - markWidth/2, maxsimY - markHeight/2, markWidth,
    // markHeight);
    // g.setPaintMode();
    Dimension2D markDimsPx = pageImage.sizeInPixels(new Size(markWidth, markHeight));
    int markWidth = (int) markDimsPx.getWidth();
    int markHeight = (int) markDimsPx.getHeight();
    g.setColor(color);
    AffineTransform t = g.getTransform();
    g.drawLine(maxsimX, maxsimY - markHeight / 2 - 1, maxsimX,
            maxsimY - markHeight / 2 - (int) (20 / t.getScaleY()));
    Polygon arrowHead = new Polygon();
    arrowHead.addPoint(maxsimX, (int) (maxsimY - markHeight / 2 - 1 / t.getScaleY()));
    arrowHead.addPoint((int) (maxsimX - 6 / t.getScaleX()),
            (int) (maxsimY - markHeight / 2 - 6 / t.getScaleY()));
    arrowHead.addPoint((int) (maxsimX + 6 / t.getScaleX()),
            (int) (maxsimY - markHeight / 2 - 6 / t.getScaleY()));
    g.fillPolygon(arrowHead);

    g.setStroke(new BasicStroke(2, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND, 1,
            new float[] { (float) (3 / t.getScaleX()), (float) (3 / t.getScaleY()) }, 0));
    g.drawRect(maxsimX - markWidth / 2 - 1, maxsimY - markHeight / 2 - 1, markWidth + 1, markHeight + 1);

}

From source file:savant.view.swing.GraphPane.java

@Override
protected void paintComponent(Graphics g) {
    if (tracks != null && tracks.length > 0) {
        LOG.trace("GraphPane.paintComponent(" + tracks[0].getName() + ")");
    }// w  ww  .  java2 s  .  c  o  m
    super.paintComponent(g);

    Graphics2D g2 = (Graphics2D) g;
    boolean trueRender = render(g2);

    GraphPaneController gpc = GraphPaneController.getInstance();
    int h = getHeight();

    // Aiming adjustments.
    if (gpc.isAiming() && mouseInside) {
        g2.setColor(Color.BLACK);
        Font thickfont = g2.getFont().deriveFont(Font.BOLD, 15.0F);
        g2.setFont(thickfont);
        int genomeX = gpc.getMouseXPosition();
        double genomeY = gpc.getMouseYPosition();
        String target = "";
        target += "X: " + MiscUtils.numToString(genomeX);
        if (!Double.isNaN(genomeY)) {
            target += " Y: " + MiscUtils.numToString(genomeY);
        }

        g2.drawLine(mouseX, 0, mouseX, h);
        if (genomeY != -1) {
            g.drawLine(0, mouseY, this.getWidth(), mouseY);
        }
        g2.drawString(target, mouseX + 5, mouseY - 5);
    }

    double x1 = transformXPos(gpc.getMouseClickPosition());
    double x2 = transformXPos(gpc.getMouseReleasePosition());

    double width = x1 - x2;

    selectionRect = new Rectangle2D.Double(width < 0 ? x1 : x2, 0.0, Math.max(2.0, Math.abs(width)), h);

    if (gpc.isPanning()) {
        // Panning adjustments (none).
    } else if (gpc.isZooming() || gpc.isSelecting()) {
        // Zooming adjustments.
        Rectangle2D rectangle = new Rectangle2D.Double(selectionRect.getX(), selectionRect.getY() - 10.0,
                selectionRect.getWidth(), selectionRect.getHeight() + 10.0);
        g2.setColor(Color.gray);
        g2.setStroke(
                new BasicStroke(1f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 3f, new float[] { 4f }, 4f));
        g2.draw(rectangle);

        if (gpc.isZooming()) {
            g.setColor(ColourSettings.getColor(ColourKey.GRAPH_PANE_ZOOM_FILL));
        } else if (gpc.isSelecting()) {
            g.setColor(ColourSettings.getColor(ColourKey.GRAPH_PANE_SELECTION_FILL));
        }
        g2.fill(selectionRect);
    }

    // Plumbing adjustments.
    Range xRange = getXRange();
    if (gpc.isPlumbing()) {
        g2.setColor(Color.BLACK);
        double spos = transformXPos(gpc.getMouseXPosition());
        g2.draw(new Line2D.Double(spos, 0, spos, h));
        double rpos = transformXPos(gpc.getMouseXPosition() + 1);
        g2.draw(new Line2D.Double(rpos, 0, rpos, h));
    }

    // Spotlight
    if (gpc.isSpotlight() && !gpc.isZooming()) {

        int center = gpc.getMouseXPosition();
        int left = center - gpc.getSpotlightSize() / 2;
        int right = left + gpc.getSpotlightSize();

        g2.setColor(new Color(0, 0, 0, 200));

        // draw left of spotlight
        if (left >= xRange.getFrom()) {
            g2.fill(new Rectangle2D.Double(0.0, 0.0, transformXPos(left), h));
        }
        // draw right of spotlight
        if (right <= xRange.getTo()) {
            double pix = transformXPos(right);
            g2.fill(new Rectangle2D.Double(pix, 0, getWidth() - pix, h));
        }
    }

    if (isLocked()) {
        drawMessage((Graphics2D) g, "Locked");
    }
    if (trueRender) {
        gpc.delistRenderingGraphpane(this);
    }
}

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 ww. j a  v  a  2 s  .co 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();
}

From source file:uk.ac.liverpool.narrative.SolutionGraphics.java

public void createVisualStateGraph(boolean dynamic, int iterations) {

    KKLayout<STRIPSState, Action> layout = new KKLayout<STRIPSState, Action>(sg.ggraph);// , new SDist<STRIPSState, Action>(ggraph));

    layout.setLengthFactor(1.7);//from  w  w w  .j  a  v a2  s .c  om
    layout.setAdjustForGravity(false);
    // layout.setDisconnectedDistanceMultiplier(1.5);
    // layout.setExchangeVertices(true);
    layout.setSize(new Dimension(2000, 1200)); // sets the initial size of
    int i = 0;
    if (!dynamic) {
        layout.setMaxIterations(iterations);
        while (!layout.done() && i++ < iterations) {
            layout.step();
        }
        layout.lock(true);
    }
    final VisualizationViewer<STRIPSState, Action> vv = new VisualizationViewer<STRIPSState, Action>(layout);
    vvv = vv;
    vv.setPreferredSize(new Dimension(2000, 1200)); // Sets the viewing area

    final DefaultModalGraphMouse graphMouse = new DefaultModalGraphMouse();
    graphMouse.setMode(ModalGraphMouse.Mode.PICKING);
    vv.setGraphMouse(graphMouse);

    vv.setBackground(Color.white);
    vv.getRenderContext().setVertexLabelTransformer(new ConstantTransformer(""));
    vv.getRenderContext().setEdgeFontTransformer(new Transformer<Action, Font>() {
        @Override
        public Font transform(Action s) {

            Action ra = sg.realActions.get(s);
            Collection<Action> set = sg.actionToEdges.get(template.apply_template(ra));
            if (set != null && set.size() > 1)
                return DERIVE_FONT;
            return DERIVE_FONT2;
        }
    });

    vv.getRenderContext().setEdgeLabelTransformer(new Transformer<Action, String>() {
        @Override
        public String transform(Action a) {
            try {
                return sg.actionToString(template, a);
            } catch (IOException e) {
                e.printStackTrace();
                return "";
            }
        }
    });

    vv.getRenderContext().setEdgeDrawPaintTransformer(new Transformer<Action, Paint>() {
        @Override
        public Paint transform(Action s) {
            sg.realActions.get(s);
            EdgeColor v = sg.edgeColors.get(s);
            if (v == null)
                return Color.yellow;
            if (v == EdgeColor.black)
                return Color.red;
            else
                return Color.lightGray;
        }
    });
    vv.getRenderContext().setVertexStrokeTransformer(new ConstantTransformer(new BasicStroke(0)));
    vv.getRenderContext().setVertexFillPaintTransformer(new Transformer<STRIPSState, Paint>() {

        @Override
        public Paint transform(STRIPSState s) {
            if (vv.getPickedVertexState().isPicked(s))
                return new Color(250, 250, 0, 207);
            Color c = cm.get(s);
            if (c != null)
                return c;

            if (sg.start.equals(s))
                return new Color(10, 200, 10, 197);
            else if (sg.ends.contains(s))
                return new Color(220, 10, 10, 197);
            return new Color(255, 210, 40, 197);
        }
    });
    vv.getRenderContext().setVertexShapeTransformer(new StoryStateTransformer());
    vv.getRenderContext()
            .setEdgeArrowTransformer(new DirectionalEdgeArrowTransformer<STRIPSState, Action>(10, 8, 1) {
                @Override
                public Shape transform(Context<Graph<STRIPSState, Action>, Action> context) {
                    if (sg.frequency.get(sg.ggraph.getEndpoints(context.element).getFirst()) != null) {
                        double c = Math.log(
                                sg.frequency.get(sg.ggraph.getEndpoints(context.element).getFirst())) * 0.8;
                        if (c > 1) {
                            Shape ss = AffineTransform.getScaleInstance(c, c)
                                    .createTransformedShape(super.transform(context));
                            return ss;
                        }
                    }

                    return super.transform(context);
                }

            });

    vv.setRenderer(new LabelsLastRenderer());

    vv.getRenderer().getVertexLabelRenderer().setPosition(Position.AUTO);
    vv.getRenderContext().setEdgeStrokeTransformer(new Transformer<Action, Stroke>() {

        @Override
        public Stroke transform(Action a) {
            if (false)
                return new BasicStroke(
                        (sg.actionToEdges.get(template.apply_template(sg.realActions.get(a))).size()),
                        BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
            if (sg.frequency.get(sg.ggraph.getEndpoints(a).getFirst()) != null)
                return new BasicStroke(
                        (float) (Math.log(sg.frequency.get(sg.ggraph.getEndpoints(a).getFirst())) * 6.0),
                        BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
            else
                return new BasicStroke(1);
        }
    });
    vv.getRenderContext().setEdgeLabelRenderer(new DefaultEdgeLabelRenderer(Color.gray, false));
    vv.getRenderContext().setLabelOffset(20);
    vv.getRenderContext().setArrowFillPaintTransformer(new ConstantTransformer(Color.lightGray));

    final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv);

    JPanel jp = new JPanel();
    jp.setBackground(Color.WHITE);
    jp.setLayout(new BorderLayout());
    jp.add(panel, BorderLayout.CENTER);
    JPanel top = new JPanel(new FlowLayout());

    jp.add(top, BorderLayout.NORTH);
    JFrame frame = new JFrame("Story state graph");
    frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    frame.getContentPane().add(jp);
    frame.pack();
    frame.setVisible(true);

}

From source file:uk.co.modularaudio.service.gui.impl.racktable.back.AbstractLinkImage.java

private void drawLinkWireIntoImage(final Point sourcePoint, final Point sinkPoint) {
    //      log.debug("Drawing link from " + sourcePoint + " to " + sinkPoint);

    final int fromX = sourcePoint.x;
    final int fromY = sourcePoint.y;
    final int toX = sinkPoint.x;
    final int toY = sinkPoint.y;

    float f1, f2, f3, f4, f5, f6, f7, f8 = 0.0f;
    f1 = fromX;/*from  ww w .ja  va  2  s  .c  o m*/
    f2 = fromY;
    f3 = fromX;
    f4 = fromY + WIRE_DIP_PIXELS;
    f5 = toX;
    f6 = toY + WIRE_DIP_PIXELS;
    f7 = toX;
    f8 = toY;
    final CubicCurve2D cubicCurve = new CubicCurve2D.Float(f1, f2, f3, f4, f5, f6, f7, f8);
    final Rectangle cubicCurveBounds = cubicCurve.getBounds();

    final int imageWidthToUse = cubicCurveBounds.width + LINK_IMAGE_PADDING_FOR_WIRE_RADIUS;
    //      int imageHeightToUse = cubicCurveBounds.height + WIRE_DIP_PIXELS;
    int imageHeightToUse = cubicCurveBounds.height;
    // If the wire is close to vertical (little Y difference) we make the image a little bigger to account for the wire "dip"
    if (Math.abs(sinkPoint.y - sourcePoint.y) <= WIRE_DIP_PIXELS) {
        imageHeightToUse += (WIRE_DIP_PIXELS / 2);
    }

    //      bufferedImage = new BufferedImage( imageWidthToUse, imageHeightToUse, BufferedImage.TYPE_INT_ARGB );
    try {
        tiledBufferedImage = bufferImageAllocationService.allocateBufferedImage(allocationSource,
                allocationMatchToUse, AllocationLifetime.SHORT, AllocationBufferType.TYPE_INT_ARGB,
                imageWidthToUse, imageHeightToUse);

        bufferedImage = tiledBufferedImage.getUnderlyingBufferedImage();
        final Graphics2D g2d = bufferedImage.createGraphics();

        g2d.setComposite(AlphaComposite.Clear);
        g2d.fillRect(0, 0, imageWidthToUse, imageHeightToUse);

        g2d.setComposite(AlphaComposite.SrcOver);

        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        f1 += LINK_IMAGE_DIST_TO_CENTER - cubicCurveBounds.x;
        f2 += LINK_IMAGE_DIST_TO_CENTER - cubicCurveBounds.y;
        f3 += LINK_IMAGE_DIST_TO_CENTER - cubicCurveBounds.x;
        f4 += LINK_IMAGE_DIST_TO_CENTER - cubicCurveBounds.y;
        f5 += LINK_IMAGE_DIST_TO_CENTER - cubicCurveBounds.x;
        f6 += LINK_IMAGE_DIST_TO_CENTER - cubicCurveBounds.y;
        f7 += LINK_IMAGE_DIST_TO_CENTER - cubicCurveBounds.x;
        f8 += LINK_IMAGE_DIST_TO_CENTER - cubicCurveBounds.y;

        final CubicCurve2D offSetCubicCurve = new CubicCurve2D.Float(f1, f2, f3, f4, f5, f6, f7, f8);

        // Draw the highlight and shadow
        if (DRAW_HIGHTLIGHT_AND_SHADOW) {
            final Graphics2D sG2d = (Graphics2D) g2d.create();
            sG2d.translate(WIRE_SHADOW_X_OFFSET, WIRE_SHADOW_Y_OFFSET);
            sG2d.setColor(Color.BLUE.darker());
            sG2d.setStroke(new BasicStroke(WIRE_SHADOW_WIDTH, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
            sG2d.draw(offSetCubicCurve);

            final Graphics2D hG2d = (Graphics2D) g2d.create();
            hG2d.translate(WIRE_HIGHLIGHT_X_OFFSET, WIRE_HIGHLIGHT_Y_OFFSET);
            hG2d.setColor(Color.WHITE);
            hG2d.setStroke(
                    new BasicStroke(WIRE_HIGHLIGHT_WIDTH, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
            hG2d.draw(offSetCubicCurve);
        }

        g2d.setColor(Color.BLACK);
        g2d.setStroke(wireStroke);
        g2d.draw(offSetCubicCurve);

        g2d.setColor(Color.BLUE);
        g2d.setStroke(wireBodyStroke);
        g2d.draw(offSetCubicCurve);

        // For debugging, draw a green line around the outside of this image.
        if (DRAW_WIRE_BOUNDING_BOX) {
            g2d.setStroke(basicStrokeOfOne);
            g2d.setColor(Color.GREEN);
            g2d.drawRect(0, 0, imageWidthToUse - 1, imageHeightToUse - 1);
        }

        rectangle.x = cubicCurveBounds.x - LINK_IMAGE_DIST_TO_CENTER;
        rectangle.y = cubicCurveBounds.y - LINK_IMAGE_DIST_TO_CENTER;
        rectangle.width = imageWidthToUse;
        rectangle.height = imageHeightToUse;
    } catch (final Exception e) {
        final String msg = "Exception caught allocating buffered image: " + e.toString();
        log.error(msg, e);
    }
}

From source file:VASSAL.build.module.map.MapShader.java

protected void buildStroke(double zoom) {
    stroke = new BasicStroke((float) Math.min(borderWidth * zoom, 1.0), BasicStroke.CAP_ROUND,
            BasicStroke.JOIN_ROUND);
}