Example usage for java.awt BasicStroke BasicStroke

List of usage examples for java.awt BasicStroke BasicStroke

Introduction

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

Prototype

@ConstructorProperties({ "lineWidth", "endCap", "lineJoin", "miterLimit", "dashArray", "dashPhase" })
public BasicStroke(float width, int cap, int join, float miterlimit, float[] dash, float dash_phase) 

Source Link

Document

Constructs a new BasicStroke with the specified attributes.

Usage

From source file:DashedStrokeDemo.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    float dash[] = { 10.0f };
    g2.setStroke(new BasicStroke(3.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dash, 0.0f));

    g2.setPaint(Color.blue);/*w w  w. j  a  va2 s  .c  om*/

    Rectangle r = new Rectangle(5, 5, 200, 200);

    g2.draw(r);
}

From source file:Java2DUtils.java

/**
 * This function provides a way to cancel the effects of the zoom on a particular Stroke.
 * All the stroke values (as line width, dashes, etc...) are divided by the zoom factor.
 * This allow to have essentially a fixed Stroke independent by the zoom.
 * The returned Stroke is a copy./*from  w  w w.j  a  v a2s  . co m*/
 * Remember to restore the right stroke in the graphics when done.
 * 
 * It works only with instances of BasicStroke
 * 
 * zoom is the zoom factor.
 */
public static Stroke getInvertedZoomedStroke(Stroke stroke, double zoom) {
    if (stroke == null || !(stroke instanceof BasicStroke))
        return stroke;

    BasicStroke bs = (BasicStroke) stroke;
    float[] dashArray = bs.getDashArray();

    float[] newDashArray = null;
    if (dashArray != null) {
        newDashArray = new float[dashArray.length];
        for (int i = 0; i < newDashArray.length; ++i) {
            newDashArray[i] = (float) (dashArray[i] / zoom);
        }
    }

    BasicStroke newStroke = new BasicStroke((float) (bs.getLineWidth() / zoom), bs.getEndCap(),
            bs.getLineJoin(), bs.getMiterLimit(),
            //(float)(bs.getMiterLimit() / zoom),
            newDashArray, (float) (bs.getDashPhase() / zoom));
    return newStroke;
}

From source file:BasicDraw.java

public void paint(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    float strokeThickness = 5.0f;

    float miterLimit = 10f;
    float[] dashPattern = { 10f };
    float dashPhase = 5f;
    BasicStroke stroke = new BasicStroke(strokeThickness, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER,
            miterLimit, dashPattern, dashPhase);
    g2d.setStroke(stroke);/*from w  w  w .j a v a2  s.  com*/

    g2d.draw(new Rectangle(20, 20, 200, 200));

}

From source file:MainClass.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

    Stroke stroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] { 3, 1 },
            0);/*from   w w  w  .j  av  a  2  s  . c  o m*/
    g2.setStroke(stroke);

    g2.setPaint(Color.black);
    g2.draw(shape);

}

From source file:edu.asu.mgb.gui.IndividualTransformer.java

@Override
public Transformer<Action, Stroke> getEdgeStrokeTransformer() {
    return new Transformer<Action, Stroke>() {
        final float dash[] = { 1.0f };

        @Override/*from ww w  . j  a v a  2s.  co m*/
        public Stroke transform(Action s) {
            return new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dash, 0.0f);
        }
    };
}

From source file:com.itemanalysis.jmetrik.swing.JmetrikXYLineAndShapeRenderer.java

@Override
public Stroke getItemStroke(int row, int col) {
    Stroke stroke = new BasicStroke(1.0f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, 10.0f,
            getLineStyle(row), 0.0f);/*from w w  w . j  ava  2  s  . c  o m*/
    return stroke;
}

From source file:grafos.JUNGraph.java

/**
 * Cria visualizao grfica do grafo//from   ww  w  . j  av  a 2  s  .co m
 * @param grafo 
 * @return  
 */
//public static void createGraphVisualization(List<Grafo> grafo, List<Vertex> path, String origem, String destino){
public static BasicVisualizationServer<Integer, String> createGraphVisualization(List<Grafo> grafo) {

    JUNGraph sgv = new JUNGraph(grafo);

    Layout<Integer, String> layout = new CircleLayout(sgv.g);
    layout.setSize(new Dimension(500, 500));
    BasicVisualizationServer<Integer, String> vv = new BasicVisualizationServer<>(layout);
    vv.setPreferredSize(new Dimension(500, 500));

    Transformer<Integer, Paint> vertexPaint = new Transformer<Integer, Paint>() {
        @Override
        public Paint transform(Integer i) {
            return Color.ORANGE;
        }
    };

    float dash[] = { 5.0f };
    final Stroke edgeStroke = new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 5.0f, dash,
            0.0f);
    Transformer<String, Stroke> edgeStrokeTransformer = new Transformer<String, Stroke>() {
        @Override
        public Stroke transform(String s) {
            return edgeStroke;
        }
    };

    vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
    vv.getRenderContext().setEdgeStrokeTransformer(edgeStrokeTransformer);
    vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller());
    vv.getRenderContext().setEdgeLabelTransformer(new ToStringLabeller());

    vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.CNTR);

    return vv;

}

From source file:StrokeUtility.java

/**
 * Creates a new Stroke-Object for the given type and with.
 * //from   www.j  a  v  a 2s  .com
 * @param type
 *          the stroke-type. (Must be one of the constants defined in this
 *          class.)
 * @param width
 *          the stroke's width.
 * @return the stroke, never null.
 */
public static Stroke createStroke(final int type, final float width) {

    final boolean useWidthForStrokes = true;

    final float effectiveWidth;
    if (useWidthForStrokes) {
        effectiveWidth = width;
    } else {
        effectiveWidth = 1;
    }

    switch (type) {
    case STROKE_DASHED:
        return new BasicStroke(width, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, 10.0f,
                new float[] { 6 * effectiveWidth, 6 * effectiveWidth }, 0.0f);
    case STROKE_DOTTED:
        return new BasicStroke(width, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, 5.0f,
                new float[] { 0.0f, 2 * effectiveWidth }, 0.0f);
    case STROKE_DOT_DASH:
        return new BasicStroke(width, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, 10.0f,
                new float[] { 0, 2 * effectiveWidth, 6 * effectiveWidth, 2 * effectiveWidth }, 0.0f);
    case STROKE_DOT_DOT_DASH:
        return new BasicStroke(
                width, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, 10.0f, new float[] { 0,
                        2 * effectiveWidth, 0, 2 * effectiveWidth, 6 * effectiveWidth, 2 * effectiveWidth },
                0.0f);
    default:
        return new BasicStroke(width);
    }
}

From source file:org.apache.qpid.disttest.charting.chartbuilder.SeriesPainter.java

private BasicStroke buildStrokeOfWidth(float width, boolean dashed) {
    final BasicStroke stroke;
    if (dashed) {
        stroke = new BasicStroke(width, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f,
                new float[] { 3.0f, 3.0f }, 0.0f);
    } else {/*w w w. j a v  a 2  s . co m*/
        stroke = new BasicStroke(width, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
    }
    return stroke;
}

From source file:Main.java

/**
 * Reads a <code>Stroke</code> object that has been serialised by the
 * {@link SerialUtilities#writeStroke(Stroke, ObjectOutputStream)} method.
 *
 * @param stream  the input stream (<code>null</code> not permitted).
 *
 * @return The stroke object (possibly <code>null</code>).
 *
 * @throws IOException  if there is an I/O problem.
 * @throws ClassNotFoundException  if there is a problem loading a class.
 *///from   www.  j  av a  2 s .c  o m
public static Stroke readStroke(final ObjectInputStream stream) throws IOException, ClassNotFoundException {

    if (stream == null) {
        throw new IllegalArgumentException("Null 'stream' argument.");
    }
    Stroke result = null;
    final boolean isNull = stream.readBoolean();
    if (!isNull) {
        final Class c = (Class) stream.readObject();
        if (c.equals(BasicStroke.class)) {
            final float width = stream.readFloat();
            final int cap = stream.readInt();
            final int join = stream.readInt();
            final float miterLimit = stream.readFloat();
            final float[] dash = (float[]) stream.readObject();
            final float dashPhase = stream.readFloat();
            result = new BasicStroke(width, cap, join, miterLimit, dash, dashPhase);
        } else {
            result = (Stroke) stream.readObject();
        }
    }
    return result;

}