Example usage for java.awt Stroke Stroke

List of usage examples for java.awt Stroke Stroke

Introduction

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

Prototype

Stroke

Source Link

Usage

From source file:com.simiacryptus.mindseye.applications.ArtistryUtil.java

/**
 * Paint circles./*from  w w  w.ja  v a  2 s.c o  m*/
 *
 * @param canvas the canvas
 * @param scale  the scale
 */
public static void paint_Circles(final Tensor canvas, final int scale) {
    BufferedImage originalImage = canvas.toImage();
    BufferedImage newImage = new BufferedImage(originalImage.getWidth(), originalImage.getHeight(),
            BufferedImage.TYPE_INT_ARGB);
    Graphics2D graphics = (Graphics2D) newImage.getGraphics();
    IntStream.range(0, 10000).forEach(i -> {
        Random random = new Random();
        int positionX = random.nextInt(originalImage.getWidth());
        int positionY = random.nextInt(originalImage.getHeight());
        int width = 1 + random.nextInt(2 * scale);
        int height = 1 + random.nextInt(2 * scale);
        DoubleStatistics[] stats = { new DoubleStatistics(), new DoubleStatistics(), new DoubleStatistics() };
        canvas.coordStream(false).filter(c -> {
            int[] coords = c.getCoords();
            int x = coords[0];
            int y = coords[1];
            double relX = Math.pow(1 - 2 * ((double) (x - positionX) / width), 2);
            double relY = Math.pow(1 - 2 * ((double) (y - positionY) / height), 2);
            return relX + relY < 1.0;
        }).forEach(c -> stats[c.getCoords()[2]].accept(canvas.get(c)));
        graphics.setStroke(new Stroke() {
            @Override
            public Shape createStrokedShape(final Shape p) {
                return null;
            }
        });
        graphics.setColor(new Color((int) stats[0].getAverage(), (int) stats[1].getAverage(),
                (int) stats[2].getAverage()));
        graphics.fillOval(positionX, positionY, width, height);
    });
    canvas.set(Tensor.fromRGB(newImage));
}

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  av a2s  . co 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") {
        {//w w  w  . j av a2 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);
}