Example usage for java.awt BasicStroke getDashPhase

List of usage examples for java.awt BasicStroke getDashPhase

Introduction

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

Prototype

public float getDashPhase() 

Source Link

Document

Returns the current dash phase.

Usage

From source file:Main.java

public static void main(String[] args) {
    BasicStroke stroke = new BasicStroke(10, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0.1F);
    System.out.println(stroke.getDashPhase());

}

From source file:Main.java

/**
 * Serialises a <code>Stroke</code> object.  This code handles the
 * <code>BasicStroke</code> class which is the only <code>Stroke</code>
 * implementation provided by the JDK (and isn't directly
 * <code>Serializable</code>).
 *
 * @param stroke  the stroke object (<code>null</code> permitted).
 * @param stream  the output stream (<code>null</code> not permitted).
 *
 * @throws IOException if there is an I/O error.
 */// ww w .  ja  v a 2 s . c  o m
public static void writeStroke(final Stroke stroke, final ObjectOutputStream stream) throws IOException {

    if (stream == null) {
        throw new IllegalArgumentException("Null 'stream' argument.");
    }
    if (stroke != null) {
        stream.writeBoolean(false);
        if (stroke instanceof BasicStroke) {
            final BasicStroke s = (BasicStroke) stroke;
            stream.writeObject(BasicStroke.class);
            stream.writeFloat(s.getLineWidth());
            stream.writeInt(s.getEndCap());
            stream.writeInt(s.getLineJoin());
            stream.writeFloat(s.getMiterLimit());
            stream.writeObject(s.getDashArray());
            stream.writeFloat(s.getDashPhase());
        } else {
            stream.writeObject(stroke.getClass());
            stream.writeObject(stroke);
        }
    } else {
        stream.writeBoolean(true);
    }
}

From source file:Main.java

public static void writeStroke(Stroke aStroke, ObjectOutputStream out) throws IOException {
    if (aStroke instanceof Serializable) {
        out.writeBoolean(true);//from  w ww  .j a v  a  2 s.c  o m
        out.writeBoolean(true);
        out.writeObject(aStroke);
    } else if (aStroke instanceof BasicStroke) {
        out.writeBoolean(true);
        out.writeBoolean(false);
        BasicStroke s = (BasicStroke) aStroke;

        float[] dash = s.getDashArray();

        if (dash == null) {
            out.write(0);
        } else {
            out.write(dash.length);
            for (int i = 0; i < dash.length; i++) {
                out.writeFloat(dash[i]);
            }
        }

        out.writeFloat(s.getLineWidth());
        out.writeInt(s.getEndCap());
        out.writeInt(s.getLineJoin());
        out.writeFloat(s.getMiterLimit());
        out.writeFloat(s.getDashPhase());
    } else {
        out.writeBoolean(false);
    }
}

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.//ww w.  j  a va 2  s.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:edu.umass.cs.iesl.pdf2meta.cli.extract.pdfbox.pagedrawer.StrokePath.java

/**
 * S stroke the path.//from w  ww  . j  a  va  2  s . c  om
 * @param operator The operator that is being executed.
 * @param arguments List
 *
 * @throws java.io.IOException If an error occurs while processing the font.
 */
public void process(PDFOperator operator, List<COSBase> arguments) throws IOException {
    ///dwilson 3/19/07 refactor
    try {
        GraphicsAwarePDFStreamEngine drawer = (GraphicsAwarePDFStreamEngine) context;

        float lineWidth = (float) context.getGraphicsState().getLineWidth();
        Matrix ctm = context.getGraphicsState().getCurrentTransformationMatrix();
        if (ctm != null && ctm.getXScale() > 0) {
            lineWidth = lineWidth * ctm.getXScale();
        }

        BasicStroke stroke = (BasicStroke) drawer.getStroke();
        if (stroke == null) {
            drawer.setStroke(new BasicStroke(lineWidth));
        } else {
            drawer.setStroke(new BasicStroke(lineWidth, stroke.getEndCap(), stroke.getLineJoin(),
                    stroke.getMiterLimit(), stroke.getDashArray(), stroke.getDashPhase()));
        }
        drawer.strokePath();
    } catch (Exception exception) {
        log.warn(exception, exception);
    }
}

From source file:net.sf.jasperreports.customizers.marker.AbstractMarkerCustomizer.java

protected BasicStroke getStroke(Float strokeWidth) {
    BasicStroke basicStroke = new BasicStroke(strokeWidth);

    StrokeStyleEnum strokeStyle = StrokeStyleEnum.getByName(getProperty(PROPERTY_STROKE_STYLE));
    if (strokeStyle != null) {
        switch (strokeStyle) {
        case SOLID: {
            //do nothing; already created stroke is good
            break;
        }//from w  ww . ja  va  2 s  .  co  m
        case DOTTED: {
            basicStroke = new BasicStroke(basicStroke.getLineWidth(), basicStroke.getEndCap(),
                    basicStroke.getLineJoin(), basicStroke.getMiterLimit(), new float[] { 1.0f, 1.0f },
                    basicStroke.getDashPhase());
            break;
        }
        case DASHED: {
            basicStroke = new BasicStroke(basicStroke.getLineWidth(), basicStroke.getEndCap(),
                    basicStroke.getLineJoin(), basicStroke.getMiterLimit(), new float[] { 10.0f, 10.0f },
                    basicStroke.getDashPhase());
            break;
        }
        }
    }

    return basicStroke;
}

From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.PlotInstanceLegendCreator.java

private CustomLegendItem createValueSourceLegendItem(PlotConfiguration plotConfig, ValueSource valueSource) {

    Set<PlotDimension> dimensions = new HashSet<PlotDimension>();
    for (PlotDimension dimension : PlotDimension.values()) {
        switch (dimension) {
        case DOMAIN:
        case VALUE:
            break;
        default:/*  w w w.  j  a v  a  2s . c  om*/
            if (valueSource.useSeriesFormatForDimension(plotConfig, dimension)) {
                dimensions.add(dimension);
            }
        }
    }
    if (dimensions.isEmpty()) {
        return null;
    }

    SeriesFormat format = valueSource.getSeriesFormat();
    String description = "";
    String toolTipText = "";
    String urlText = "";
    boolean shapeVisible = true;
    Shape shape;
    boolean shapeFilled = true;
    Paint fillPaint = UNDEFINED_COLOR_PAINT;
    boolean shapeOutlineVisible = true;
    Paint outlinePaint = PlotConfiguration.DEFAULT_OUTLINE_COLOR;
    Stroke outlineStroke = DEFAULT_OUTLINE_STROKE;
    boolean lineVisible = format.getLineStyle() != LineStyle.NONE
            && format.getSeriesType() == SeriesFormat.VisualizationType.LINES_AND_SHAPES;

    // configure fill paint and line paint
    Paint linePaint;
    String label = valueSource.toString();
    if (label == null) {
        label = "";
    }
    if (dimensions.contains(PlotDimension.COLOR)) {
        Color color = format.getItemColor();
        fillPaint = format.getAreaFillPaint(color);
        linePaint = fillPaint;
    } else {
        if (format.getAreaFillStyle() == FillStyle.NONE) {
            fillPaint = new Color(0, 0, 0, 0);
            linePaint = fillPaint;
        } else if (format.getAreaFillStyle() == FillStyle.SOLID) {
            fillPaint = UNDEFINED_COLOR_PAINT;
            linePaint = UNDEFINED_LINE_COLOR;
        } else {
            fillPaint = format.getAreaFillPaint(UNDEFINED_COLOR);
            linePaint = fillPaint;
        }

    }

    VisualizationType seriesType = valueSource.getSeriesFormat().getSeriesType();
    if (seriesType == VisualizationType.LINES_AND_SHAPES) {
        if (dimensions.contains(PlotDimension.SHAPE)) {
            shape = format.getItemShape().getShape();
        } else if (dimensions.contains(PlotDimension.COLOR)) {
            shape = UNDEFINED_SHAPE;
        } else {
            shape = UNDEFINED_SHAPE_AND_COLOR;
        }

        if (dimensions.contains(PlotDimension.SIZE)) {
            AffineTransform transformation = new AffineTransform();
            double scalingFactor = format.getItemSize();
            transformation.scale(scalingFactor, scalingFactor);
            shape = transformation.createTransformedShape(shape);
        }
    } else if (seriesType == VisualizationType.BARS) {
        shape = BAR_SHAPE;
    } else if (seriesType == VisualizationType.AREA) {
        shape = AREA_SHAPE;
    } else {
        throw new RuntimeException("Unknown SeriesType. This should not happen.");
    }

    // configure line shape
    float lineLength = 0;
    if (lineVisible) {
        lineLength = format.getLineWidth();
        if (lineLength < 1) {
            lineLength = 1;
        }
        if (lineLength > 1) {
            lineLength = 1 + (float) Math.log(lineLength) / 2;
        }

        // line at least 30 pixels long, and show at least 2 iterations of stroke
        lineLength = Math.max(lineLength * 30, format.getStrokeLength() * 2);

        // line at least 2x longer than shape width
        if (shape != null) {
            lineLength = Math.max(lineLength, (float) shape.getBounds().getWidth() * 2f);
        }
    }

    // now create line shape and stroke
    Shape line = new Line2D.Float(0, 0, lineLength, 0);
    BasicStroke lineStroke = format.getStroke();
    if (lineStroke == null) {
        lineStroke = new BasicStroke();
    }

    // unset line ending decoration to prevent drawing errors in legend
    {
        BasicStroke s = lineStroke;
        lineStroke = new BasicStroke(s.getLineWidth(), BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND,
                s.getMiterLimit(), s.getDashArray(), s.getDashPhase());
    }

    return new CustomLegendItem(label, description, toolTipText, urlText, shapeVisible, shape, shapeFilled,
            fillPaint, shapeOutlineVisible, outlinePaint, outlineStroke, lineVisible, line, lineStroke,
            linePaint);
}

From source file:org.moeaframework.analysis.plot.Plot.java

/**
 * Modifies the line thickness or point size in the last dataset.  The
 * size is applied to all series in the dataset.
 * /*from   w  w  w.  j a  v a 2s  . c  o  m*/
 * @param size the size
 * @return a reference to this {@code Plot} instance
 */
public Plot withSize(float size) {
    if (chart.getPlot() instanceof XYPlot) {
        XYPlot plot = chart.getXYPlot();
        XYItemRenderer renderer = plot.getRenderer(currentDataset);

        if (renderer instanceof XYDotRenderer) {
            ((XYDotRenderer) renderer).setDotWidth((int) (size * 2));
            ((XYDotRenderer) renderer).setDotHeight((int) (size * 2));
        } else if (renderer.getBaseStroke() instanceof BasicStroke) {
            BasicStroke oldStroke = (BasicStroke) renderer.getBaseStroke();

            BasicStroke newStroke = new BasicStroke(size, oldStroke.getEndCap(), oldStroke.getLineJoin(),
                    oldStroke.getMiterLimit(), oldStroke.getDashArray(), oldStroke.getDashPhase());

            renderer.setBaseStroke(newStroke);
        } else {
            renderer.setBaseStroke(new BasicStroke(size, 1, 1));
        }
    }

    return this;
}

From source file:com.mgmtp.perfload.loadprofiles.ui.AppFrame.java

private void updateGraph() {
    XYSeriesCollection dataset = new XYSeriesCollection();
    Collection<Stairs> loadProfileEnities = transform(
            filter(loadProfilesController.getTreeItems(), new IsStairsPredicate()),
            new LoadProfileEntityToStairsFunction());
    GraphPointsCalculator calc = new GraphPointsCalculator();
    Map<String, Set<Point>> pointsMap = calc.calculatePoints(loadProfileEnities);

    for (Entry<String, Set<Point>> entry : pointsMap.entrySet()) {
        final XYSeries series = new XYSeries(entry.getKey());
        for (Point point : entry.getValue()) {
            series.add(point.getX(), point.getY());
        }//from  w  ww .j a  v a2  s  .  c o  m
        dataset.addSeries(series);
    }

    String name = txtName.getText();
    chart = ChartFactory.createXYLineChart(name, "t (min)", "Executions (1/h)", dataset,
            PlotOrientation.VERTICAL, true, true, false);

    XYPlot plot = chart.getXYPlot();

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    plot.setRenderer(renderer);

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    double maxX = 0;

    for (OneTime oneTime : getOneTimes()) {
        String key = oneTime.operation.getName();
        XYSeries series;
        try {
            // We need the series in order to retrieve paint and stroke
            series = dataset.getSeries(key);
        } catch (UnknownKeyException ex) {
            series = new XYSeries(key);
            dataset.addSeries(series);
        }

        int index = dataset.getSeriesIndex(key);
        BasicStroke stroke = (BasicStroke) renderer.lookupSeriesStroke(index);
        stroke = new BasicStroke(stroke.getLineWidth() + 1f, stroke.getEndCap(), stroke.getLineJoin(),
                stroke.getMiterLimit(), stroke.getDashArray(), stroke.getDashPhase());
        Color paint = (Color) renderer.lookupSeriesPaint(index);
        paint = new Color(paint.getRed(), paint.getGreen(), paint.getBlue(), 160);

        double height = rangeAxis.getUpperBound() * .05; // five percent of range
        double width = domainAxis.getUpperBound() * .01; // one percent of range
        double center = oneTime.t0;
        double left = center - width / 2;
        double right = center + width / 2;

        // We only add annotations for one times, but nothing to the series
        plot.addAnnotation(new XYPolygonAnnotation(new double[] { left, 0d, center, height, right, 0d }, stroke,
                paint, paint));

        maxX = max(maxX, right);
    }

    for (Marker marker : getMarkers()) {
        IntervalMarker im = new IntervalMarker(marker.left, marker.right);
        im.setLabel(marker.name);
        im.setLabelFont(new Font(getFont().getName(), getFont().getStyle(), getFont().getSize() + 1));
        im.setLabelAnchor(RectangleAnchor.TOP);
        im.setLabelOffset(new RectangleInsets(8d, 0d, 0d, 0d));
        im.setLabelPaint(Color.BLACK);
        im.setAlpha(.3f);
        im.setPaint(Color.WHITE);
        im.setOutlinePaint(Color.BLACK);
        im.setOutlineStroke(new BasicStroke(1.0f));
        plot.addDomainMarker(im, Layer.BACKGROUND);

        maxX = max(maxX, marker.right);
    }

    if (domainAxis.getUpperBound() < maxX) {
        domainAxis.setUpperBound(maxX * 1.05);
    }
    chartPanel.setChart(chart);
}

From source file:org.apache.pdfbox.util.operator.pagedrawer.StrokePath.java

/**
 * S stroke the path.// w  w  w.  j a v a  2  s.  c o  m
 * @param operator The operator that is being executed.
 * @param arguments List
 *
 * @throws IOException If an error occurs while processing the font.
 */
public void process(PDFOperator operator, List<COSBase> arguments) throws IOException {
    ///dwilson 3/19/07 refactor
    try {
        PageDrawer drawer = (PageDrawer) context;

        float lineWidth = (float) context.getGraphicsState().getLineWidth();
        Matrix ctm = context.getGraphicsState().getCurrentTransformationMatrix();
        if (ctm != null && ctm.getXScale() > 0) {
            lineWidth = lineWidth * ctm.getXScale();
        }

        BasicStroke stroke = (BasicStroke) drawer.getStroke();
        if (stroke == null) {
            drawer.setStroke(new BasicStroke(lineWidth));
        } else {
            drawer.setStroke(new BasicStroke(lineWidth, stroke.getEndCap(), stroke.getLineJoin(),
                    stroke.getMiterLimit(), stroke.getDashArray(), stroke.getDashPhase()));
        }
        drawer.strokePath();
    } catch (Exception exception) {
        log.warn(exception, exception);
    }
}