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.apache.fop.render.java2d.Java2DBorderPainter.java

/** {@inheritDoc} */
protected void drawBorderLine( // CSOK: ParameterNumber
        int x1, int y1, int x2, int y2, boolean horz, boolean startOrBefore, int style, Color color) {
    float w = x2 - x1;
    float h = y2 - y1;
    if ((w < 0) || (h < 0)) {
        log.error("Negative extent received. Border won't be painted.");
        return;/*from  ww w.j  a  v a  2s.  c  om*/
    }
    switch (style) {
    case Constants.EN_DASHED:
        getG2D().setColor(color);
        if (horz) {
            float unit = Math.abs(2 * h);
            int rep = (int) (w / unit);
            if (rep % 2 == 0) {
                rep++;
            }
            unit = w / rep;
            float ym = y1 + (h / 2);
            BasicStroke s = new BasicStroke(h, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f,
                    new float[] { unit }, 0);
            getG2D().setStroke(s);
            getG2D().draw(new Line2D.Float(x1, ym, x2, ym));
        } else {
            float unit = Math.abs(2 * w);
            int rep = (int) (h / unit);
            if (rep % 2 == 0) {
                rep++;
            }
            unit = h / rep;
            float xm = x1 + (w / 2);
            BasicStroke s = new BasicStroke(w, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f,
                    new float[] { unit }, 0);
            getG2D().setStroke(s);
            getG2D().draw(new Line2D.Float(xm, y1, xm, y2));
        }
        break;
    case Constants.EN_DOTTED:
        getG2D().setColor(color);
        if (horz) {
            float unit = Math.abs(2 * h);
            int rep = (int) (w / unit);
            if (rep % 2 == 0) {
                rep++;
            }
            unit = w / rep;
            float ym = y1 + (h / 2);
            BasicStroke s = new BasicStroke(h, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER, 10.0f,
                    new float[] { 0, unit }, 0);
            getG2D().setStroke(s);
            getG2D().draw(new Line2D.Float(x1, ym, x2, ym));
        } else {
            float unit = Math.abs(2 * w);
            int rep = (int) (h / unit);
            if (rep % 2 == 0) {
                rep++;
            }
            unit = h / rep;
            float xm = x1 + (w / 2);
            BasicStroke s = new BasicStroke(w, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER, 10.0f,
                    new float[] { 0, unit }, 0);
            getG2D().setStroke(s);
            getG2D().draw(new Line2D.Float(xm, y1, xm, y2));
        }
        break;
    case Constants.EN_DOUBLE:
        getG2D().setColor(color);
        if (horz) {
            float h3 = h / 3;
            float ym1 = y1 + (h3 / 2);
            float ym2 = ym1 + h3 + h3;
            BasicStroke s = new BasicStroke(h3);
            getG2D().setStroke(s);
            getG2D().draw(new Line2D.Float(x1, ym1, x2, ym1));
            getG2D().draw(new Line2D.Float(x1, ym2, x2, ym2));
        } else {
            float w3 = w / 3;
            float xm1 = x1 + (w3 / 2);
            float xm2 = xm1 + w3 + w3;
            BasicStroke s = new BasicStroke(w3);
            getG2D().setStroke(s);
            getG2D().draw(new Line2D.Float(xm1, y1, xm1, y2));
            getG2D().draw(new Line2D.Float(xm2, y1, xm2, y2));
        }
        break;
    case Constants.EN_GROOVE:
    case Constants.EN_RIDGE:
        float colFactor = (style == Constants.EN_GROOVE ? 0.4f : -0.4f);
        if (horz) {
            Color uppercol = ColorUtil.lightenColor(color, -colFactor);
            Color lowercol = ColorUtil.lightenColor(color, colFactor);
            float h3 = h / 3;
            float ym1 = y1 + (h3 / 2);
            getG2D().setStroke(new BasicStroke(h3));
            getG2D().setColor(uppercol);
            getG2D().draw(new Line2D.Float(x1, ym1, x2, ym1));
            getG2D().setColor(color);
            getG2D().draw(new Line2D.Float(x1, ym1 + h3, x2, ym1 + h3));
            getG2D().setColor(lowercol);
            getG2D().draw(new Line2D.Float(x1, ym1 + h3 + h3, x2, ym1 + h3 + h3));
        } else {
            Color leftcol = ColorUtil.lightenColor(color, -colFactor);
            Color rightcol = ColorUtil.lightenColor(color, colFactor);
            float w3 = w / 3;
            float xm1 = x1 + (w3 / 2);
            getG2D().setStroke(new BasicStroke(w3));
            getG2D().setColor(leftcol);
            getG2D().draw(new Line2D.Float(xm1, y1, xm1, y2));
            getG2D().setColor(color);
            getG2D().draw(new Line2D.Float(xm1 + w3, y1, xm1 + w3, y2));
            getG2D().setColor(rightcol);
            getG2D().draw(new Line2D.Float(xm1 + w3 + w3, y1, xm1 + w3 + w3, y2));
        }
        break;
    case Constants.EN_INSET:
    case Constants.EN_OUTSET:
        colFactor = (style == Constants.EN_OUTSET ? 0.4f : -0.4f);
        if (horz) {
            color = ColorUtil.lightenColor(color, (startOrBefore ? 1 : -1) * colFactor);
            getG2D().setStroke(new BasicStroke(h));
            float ym1 = y1 + (h / 2);
            getG2D().setColor(color);
            getG2D().draw(new Line2D.Float(x1, ym1, x2, ym1));
        } else {
            color = ColorUtil.lightenColor(color, (startOrBefore ? 1 : -1) * colFactor);
            float xm1 = x1 + (w / 2);
            getG2D().setStroke(new BasicStroke(w));
            getG2D().setColor(color);
            getG2D().draw(new Line2D.Float(xm1, y1, xm1, y2));
        }
        break;
    case Constants.EN_HIDDEN:
        break;
    default:
        getG2D().setColor(color);
        if (horz) {
            float ym = y1 + (h / 2);
            getG2D().setStroke(new BasicStroke(h));
            getG2D().draw(new Line2D.Float(x1, ym, x2, ym));
        } else {
            float xm = x1 + (w / 2);
            getG2D().setStroke(new BasicStroke(w));
            getG2D().draw(new Line2D.Float(xm, y1, xm, y2));
        }
    }
}

From source file:org.apache.fop.render.java2d.Java2DGraphicsPainter.java

public void drawBorderLine(int x1, int y1, int x2, int y2, boolean horz, boolean startOrBefore, int style,
        Color color) throws IOException {
    float w = x2 - x1;
    float h = y2 - y1;
    if ((w < 0) || (h < 0)) {
        log.error("Negative extent received. Border won't be painted.");
        return;//from  w ww .j  ava 2s .c o m
    }
    switch (style) {
    case Constants.EN_DASHED:
        getG2D().setColor(color);
        if (horz) {
            float unit = Math.abs(2 * h);
            int rep = (int) (w / unit);
            if (rep % 2 == 0) {
                rep++;
            }
            unit = w / rep;
            float ym = y1 + (h / 2);
            BasicStroke s = new BasicStroke(h, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f,
                    new float[] { unit }, 0);
            getG2D().setStroke(s);
            getG2D().draw(new Line2D.Float(x1, ym, x2, ym));
        } else {
            float unit = Math.abs(2 * w);
            int rep = (int) (h / unit);
            if (rep % 2 == 0) {
                rep++;
            }
            unit = h / rep;
            float xm = x1 + (w / 2);
            BasicStroke s = new BasicStroke(w, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f,
                    new float[] { unit }, 0);
            getG2D().setStroke(s);
            getG2D().draw(new Line2D.Float(xm, y1, xm, y2));
        }
        break;
    case Constants.EN_DOTTED:
        getG2D().setColor(color);
        if (horz) {
            float unit = Math.abs(2 * h);
            int rep = (int) (w / unit);
            if (rep % 2 == 0) {
                rep++;
            }
            unit = w / rep;
            float ym = y1 + (h / 2);
            BasicStroke s = new BasicStroke(h, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER, 10.0f,
                    new float[] { 0, unit }, 0);
            getG2D().setStroke(s);
            getG2D().draw(new Line2D.Float(x1, ym, x2, ym));
        } else {
            float unit = Math.abs(2 * w);
            int rep = (int) (h / unit);
            if (rep % 2 == 0) {
                rep++;
            }
            unit = h / rep;
            float xm = x1 + (w / 2);
            BasicStroke s = new BasicStroke(w, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER, 10.0f,
                    new float[] { 0, unit }, 0);
            getG2D().setStroke(s);
            getG2D().draw(new Line2D.Float(xm, y1, xm, y2));
        }
        break;
    case Constants.EN_DOUBLE:
        getG2D().setColor(color);
        if (horz) {
            float h3 = h / 3;
            float ym1 = y1 + (h3 / 2);
            float ym2 = ym1 + h3 + h3;
            BasicStroke s = new BasicStroke(h3);
            getG2D().setStroke(s);
            getG2D().draw(new Line2D.Float(x1, ym1, x2, ym1));
            getG2D().draw(new Line2D.Float(x1, ym2, x2, ym2));
        } else {
            float w3 = w / 3;
            float xm1 = x1 + (w3 / 2);
            float xm2 = xm1 + w3 + w3;
            BasicStroke s = new BasicStroke(w3);
            getG2D().setStroke(s);
            getG2D().draw(new Line2D.Float(xm1, y1, xm1, y2));
            getG2D().draw(new Line2D.Float(xm2, y1, xm2, y2));
        }
        break;
    case Constants.EN_GROOVE:
    case Constants.EN_RIDGE:
        float colFactor = (style == Constants.EN_GROOVE ? 0.4f : -0.4f);
        if (horz) {
            Color uppercol = ColorUtil.lightenColor(color, -colFactor);
            Color lowercol = ColorUtil.lightenColor(color, colFactor);
            float h3 = h / 3;
            float ym1 = y1 + (h3 / 2);
            getG2D().setStroke(new BasicStroke(h3));
            getG2D().setColor(uppercol);
            getG2D().draw(new Line2D.Float(x1, ym1, x2, ym1));
            getG2D().setColor(color);
            getG2D().draw(new Line2D.Float(x1, ym1 + h3, x2, ym1 + h3));
            getG2D().setColor(lowercol);
            getG2D().draw(new Line2D.Float(x1, ym1 + h3 + h3, x2, ym1 + h3 + h3));
        } else {
            Color leftcol = ColorUtil.lightenColor(color, -colFactor);
            Color rightcol = ColorUtil.lightenColor(color, colFactor);
            float w3 = w / 3;
            float xm1 = x1 + (w3 / 2);
            getG2D().setStroke(new BasicStroke(w3));
            getG2D().setColor(leftcol);
            getG2D().draw(new Line2D.Float(xm1, y1, xm1, y2));
            getG2D().setColor(color);
            getG2D().draw(new Line2D.Float(xm1 + w3, y1, xm1 + w3, y2));
            getG2D().setColor(rightcol);
            getG2D().draw(new Line2D.Float(xm1 + w3 + w3, y1, xm1 + w3 + w3, y2));
        }
        break;
    case Constants.EN_INSET:
    case Constants.EN_OUTSET:
        colFactor = (style == Constants.EN_OUTSET ? 0.4f : -0.4f);
        if (horz) {
            color = ColorUtil.lightenColor(color, (startOrBefore ? 1 : -1) * colFactor);
            getG2D().setStroke(new BasicStroke(h));
            float ym1 = y1 + (h / 2);
            getG2D().setColor(color);
            getG2D().draw(new Line2D.Float(x1, ym1, x2, ym1));
        } else {
            color = ColorUtil.lightenColor(color, (startOrBefore ? 1 : -1) * colFactor);
            float xm1 = x1 + (w / 2);
            getG2D().setStroke(new BasicStroke(w));
            getG2D().setColor(color);
            getG2D().draw(new Line2D.Float(xm1, y1, xm1, y2));
        }
        break;
    case Constants.EN_HIDDEN:
        break;
    default:
        getG2D().setColor(color);
        if (horz) {
            float ym = y1 + (h / 2);
            getG2D().setStroke(new BasicStroke(h));
            getG2D().draw(new Line2D.Float(x1, ym, x2, ym));
        } else {
            float xm = x1 + (w / 2);
            getG2D().setStroke(new BasicStroke(w));
            getG2D().draw(new Line2D.Float(xm, y1, xm, y2));
        }
    }
}

From source file:org.apache.pdfbox.rendering.PageDrawer.java

/**
 * Draws the page to the requested context.
 * /*from   w w  w .j  a  v a 2s.  c o  m*/
 * @param g The graphics context to draw onto.
 * @param pageSize The size of the page to draw.
 * @throws IOException If there is an IO error while drawing the page.
 */
public void drawPage(Graphics g, PDRectangle pageSize) throws IOException {
    graphics = (Graphics2D) g;
    xform = graphics.getTransform();
    this.pageSize = pageSize;

    setRenderingHints();

    graphics.translate(0, pageSize.getHeight());
    graphics.scale(1, -1);

    // TODO use getStroke() to set the initial stroke
    graphics.setStroke(new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER));

    // adjust for non-(0,0) crop box
    graphics.translate(-pageSize.getLowerLeftX(), -pageSize.getLowerLeftY());

    processPage(getPage());

    for (PDAnnotation annotation : getPage().getAnnotations()) {
        showAnnotation(annotation);
    }

    graphics = null;
}

From source file:org.eclipse.smarthome.ui.internal.chart.defaultchartprovider.DefaultChartProvider.java

boolean addItem(Chart chart, QueryablePersistenceService service, Date timeBegin, Date timeEnd, Item item,
        int seriesCounter, ChartTheme chartTheme, int dpi) {
    Color color = chartTheme.getLineColor(seriesCounter);

    // Get the item label
    String label = null;/*from www . j  a  va 2 s . com*/
    if (itemUIRegistry != null) {
        // Get the item label
        label = itemUIRegistry.getLabel(item.getName());
        if (label != null && label.contains("[") && label.contains("]")) {
            label = label.substring(0, label.indexOf('['));
        }
    }
    if (label == null) {
        label = item.getName();
    }

    Iterable<HistoricItem> result;
    FilterCriteria filter;

    // Generate data collections
    List<Date> xData = new ArrayList<Date>();
    List<Number> yData = new ArrayList<Number>();

    // Declare state here so it will hold the last value at the end of the process
    State state = null;

    // First, get the value at the start time.
    // This is necessary for values that don't change often otherwise data will start
    // after the start of the graph (or not at all if there's no change during the graph period)
    filter = new FilterCriteria();
    filter.setEndDate(ZonedDateTime.ofInstant(timeBegin.toInstant(), timeZoneProvider.getTimeZone()));
    filter.setItemName(item.getName());
    filter.setPageSize(1);
    filter.setOrdering(Ordering.DESCENDING);
    result = service.query(filter);
    if (result.iterator().hasNext()) {
        HistoricItem historicItem = result.iterator().next();

        state = historicItem.getState();
        xData.add(timeBegin);
        yData.add(convertData(state));
    }

    // Now, get all the data between the start and end time
    filter.setBeginDate(ZonedDateTime.ofInstant(timeBegin.toInstant(), timeZoneProvider.getTimeZone()));
    filter.setEndDate(ZonedDateTime.ofInstant(timeEnd.toInstant(), timeZoneProvider.getTimeZone()));
    filter.setPageSize(Integer.MAX_VALUE);
    filter.setOrdering(Ordering.ASCENDING);

    // Get the data from the persistence store
    result = service.query(filter);
    Iterator<HistoricItem> it = result.iterator();

    // Iterate through the data
    while (it.hasNext()) {
        HistoricItem historicItem = it.next();

        // For 'binary' states, we need to replicate the data
        // to avoid diagonal lines
        if (state instanceof OnOffType || state instanceof OpenClosedType) {
            Calendar cal = Calendar.getInstance();
            cal.setTime(historicItem.getTimestamp());
            cal.add(Calendar.MILLISECOND, -1);
            xData.add(cal.getTime());
            yData.add(convertData(state));
        }

        state = historicItem.getState();
        xData.add(historicItem.getTimestamp());
        yData.add(convertData(state));
    }

    // Lastly, add the final state at the endtime
    if (state != null) {
        xData.add(timeEnd);
        yData.add(convertData(state));
    }

    // Add the new series to the chart - only if there's data elements to display
    // The chart engine will throw an exception if there's no data
    if (xData.size() == 0) {
        return false;
    }

    // If there's only 1 data point, plot it again!
    if (xData.size() == 1) {
        xData.add(xData.iterator().next());
        yData.add(yData.iterator().next());
    }

    Series series = chart.addSeries(label, xData, yData);
    float lineWidth = (float) chartTheme.getLineWidth(dpi);
    series.setLineStyle(new BasicStroke(lineWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER));
    series.setMarker(SeriesMarker.NONE);
    series.setLineColor(color);

    // If the start value is below the median, then count legend position down
    // Otherwise count up.
    // We use this to decide whether to put the legend in the top or bottom corner.
    if (yData.iterator().next().floatValue() > ((series.getYMax() - series.getYMin()) / 2 + series.getYMin())) {
        legendPosition++;
    } else {
        legendPosition--;
    }

    return true;
}

From source file:org.jcurl.demo.tactics.sg.BroomPromptScenario.java

public BroomPromptScenario() {
    // create the scene
    final boolean stickUp = false;
    final boolean bothSides = true;
    final int pieAngle = 150;
    final Color sp = Color.BLACK;
    final Color bgc = new Color(1, 1, 1, 0.5f);
    final Stroke fine = new BasicStroke(0.01f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER);
    final Stroke bold = new BasicStroke(0.03f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER);
    // final Font fo = new Font("SansSerif", Font.BOLD, 1);
    final float halo = RockProps.DEFAULT.getRadius();
    final float outer = 0.8f * RockProps.DEFAULT.getRadius();
    stickLength = (stickUp ? 1 : -1) * 5 * outer;
    final float inner = 0.5F * outer;

    final SGGroup me = new SGGroup();
    // the transparent background
    {/* w w  w.j a va 2 s  .co  m*/
        final SGShape bg = node(new Arc2D.Float(-halo, -halo, 2 * halo, 2 * halo, 0, 360, Arc2D.OPEN), null,
                null, scale0);
        bg.setFillPaint(bgc);
        bg.addMouseListener(new MoveHandler());
        bg.setMouseBlocker(true);
        bg.setCursor(moveC);
        me.add(bg);
    }
    // the cross-hair and stick
    {
        final int off = 90;
        final int pieOff = 180;
        final int arrowLengthDegrees = 7;
        // colored pie:
        pie = node(new Arc2D.Float(-outer, -outer, 2 * outer, 2 * outer, off - pieOff, pieAngle, Arc2D.PIE),
                null, null, scale0);
        me.add(pie);
        // inner circle:
        me.add(node(new Arc2D.Float(-inner, -inner, 2 * inner, 2 * inner, off, pieOff + pieAngle, Arc2D.OPEN),
                fine, sp, scale50));
        // outer circle:
        me.add(node(new Arc2D.Float(-outer, -outer, 2 * outer, 2 * outer, off,
                pieOff + pieAngle - (14 + arrowLengthDegrees), Arc2D.OPEN), fine, sp, scale50));
        // Semantic zooming: me.add(node(new Arc2D.Float(-outer, -outer, 2 *
        // outer, 2 * outer,
        // off, pieOff + pieAngle, Arc2D.OPEN), fine, sp, -scale50));
        final double ar = Math.PI * (off + pieAngle) / 180.0;
        // radius
        // if (pieAngle % 90 != 0)
        me.add(node(new Line2D.Double(0, 0, -outer * Math.cos(ar), outer * Math.sin(ar)), bold, sp, scale0));

        // arrow:
        final float f = outer / 10;
        final SGShape s = node(IceShapes.createArrowHead(f, 3 * f, 0.5f * f), null, null, scale50);
        s.setFillPaint(sp);
        final double a = Math.PI * (off + pieAngle - arrowLengthDegrees) / 180.0;
        final AffineTransform a_ = new AffineTransform();
        a_.translate(-outer * Math.cos(a), outer * Math.sin(a));
        a_.rotate(Math.PI * (90 - (off + pieAngle) + 8 + arrowLengthDegrees) / 180.0);
        final Affine s_ = SGTransform.createAffine(a_, s);
        me.add(s_);
    }
    { // y-axis:
        me.add(node(new Line2D.Float(0, -Math.signum(stickLength) * halo, 0, stickLength), fine, sp, scale0));
        // x-axis:
        me.add(node(new Line2D.Float(-halo, 0, halo, 0), fine, sp, scale0));
    }
    { // slider
        sli = new SGShape();
        sli.setShape(IceShapes.createSlider(0.4f * outer, bothSides));
        // sli.setFillPaint(sp);
        sli.setDrawStroke(fine);
        sli.setDrawPaint(sp);
        sli.setMode(Mode.STROKE_FILL);
        sli.setAntialiasingHint(RenderingHints.VALUE_ANTIALIAS_ON);
        me.add(slider = SGTransform.createAffine(new AffineTransform(), sli));
        slider.setCursor(moveC);
        slider.addMouseListener(new SpeedHandler());
        slider.setMouseBlocker(true);
    }
    handle = SGTransform.createAffine(new AffineTransform(), me);
    scene = SGTransform.createAffine(new AffineTransform(), handle);
    scene.setVisible(false);
}

From source file:org.jcurl.zui.piccolo.BroomPromptSimple.java

public BroomPromptSimple() {
    final boolean stickUp = false;
    final boolean bothSides = true;
    final int pieAngle = 150;
    final Color sp = Color.BLACK;
    final Color bgc = new Color(1, 1, 1, 0.5f);
    final Stroke fine = new BasicStroke(0.01f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER);
    final Stroke bold = new BasicStroke(0.03f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER);
    // final Font fo = new Font("SansSerif", Font.BOLD, 1);
    final float halo = RockProps.DEFAULT.getRadius();
    final float outer = 0.8f * RockProps.DEFAULT.getRadius();
    stickLength = (stickUp ? 1 : -1) * 5 * outer;
    final float inner = 0.5F * outer;
    setPickable(false);/*from   w ww .ja  va  2 s. co  m*/
    final BroomPromptSimple self = this;
    handle = new PNode() {
        private static final long serialVersionUID = -7641452321842902940L;

        /**
         * Return true if this node or any pickable descendends are picked.
         * If a pick occurs the pickPath is modified so that this node is
         * always returned as the picked node, event if it was a decendent
         * node that initialy reported the pick.
         * 
         * @see PComposite
         */
        @Override
        public boolean fullPick(final PPickPath pickPath) {
            if (super.fullPick(pickPath)) {
                PNode picked = pickPath.getPickedNode();
                // this code won't work with internal cameras, because
                // it doesn't pop
                // the cameras view transform.
                while (picked != self) {
                    pickPath.popTransform(picked.getTransformReference(false));
                    pickPath.popNode(picked);
                    picked = pickPath.getPickedNode();
                }
                return true;
            }
            return false;
        }
    };
    { // opaque Background
        final PNode bg = node(new Arc2D.Float(-halo, -halo, 2 * halo, 2 * halo, 0, 360, Arc2D.OPEN), null, null,
                scale0);
        bg.setPaint(bgc);
        bg.setPickable(true);
        handle.addChild(bg);
    }
    { // Cross-hair circles and pie
        final int off = 90;
        final int pieOff = 180;
        final int arrowLengthDegrees = 7;
        // colored pie:
        pie = node(new Arc2D.Float(-outer, -outer, 2 * outer, 2 * outer, off - pieOff, pieAngle, Arc2D.PIE),
                null, null, scale0);
        handle.addChild(pie);
        // inner circle:
        handle.addChild(
                node(new Arc2D.Float(-inner, -inner, 2 * inner, 2 * inner, off, pieOff + pieAngle, Arc2D.OPEN),
                        fine, sp, scale50));
        // outer circle:
        handle.addChild(node(new Arc2D.Float(-outer, -outer, 2 * outer, 2 * outer, off,
                pieOff + pieAngle - (14 + arrowLengthDegrees), Arc2D.OPEN), fine, sp, scale50));
        handle.addChild(
                node(new Arc2D.Float(-outer, -outer, 2 * outer, 2 * outer, off, pieOff + pieAngle, Arc2D.OPEN),
                        fine, sp, -scale50));
        final double ar = Math.PI * (off + pieAngle) / 180.0;
        // radius
        // if (pieAngle % 90 != 0)
        handle.addChild(
                node(new Line2D.Double(0, 0, -outer * Math.cos(ar), outer * Math.sin(ar)), bold, sp, scale0));

        // arrow:
        final float f = outer / 10;
        final PPath s = node(IceShapes.createArrowHead(f, 3 * f, 0.5f * f), null, null, scale50);
        s.setPaint(sp);
        final double a = Math.PI * (off + pieAngle - arrowLengthDegrees) / 180.0;
        s.translate(-outer * Math.cos(a), outer * Math.sin(a));
        s.rotate(Math.PI * (90 - (off + pieAngle) + 8 + arrowLengthDegrees) / 180.0);
        handle.addChild(s);

        this.addChild(handle);
    }
    { // y-axis:
        handle.addChild(
                node(new Line2D.Float(0, -Math.signum(stickLength) * halo, 0, stickLength), fine, sp, scale0));
        // x-axis:
        handle.addChild(node(new Line2D.Float(-halo, 0, halo, 0), fine, sp, scale0));
    }
    { // slider
        slider = new PPath(IceShapes.createSlider(0.4f * outer, bothSides), fine);
        slider.setStrokePaint(sp);
        slider.setPickable(true);
        this.addChild(slider);
    }
    // Set up Event handling
    addInputEventListener(new PDragEventHandler() {

        /** double-click: flip handle */
        @Override
        public void mouseClicked(final PInputEvent arg0) {
            super.mouseClicked(arg0);
            if (arg0.getClickCount() > 1) {
                arg0.setHandled(true);
                first = new HandleMemento(getModel(), getModel().getOutTurn());
                last = new HandleMemento(getModel(), !getModel().getOutTurn());
                ChangeManager.getTrivial(changer).undoable(first, last);
                first = last = null;
            }
        }

        /** drag/move */
        @Override
        public void mouseDragged(final PInputEvent arg0) {
            arg0.setHandled(true);
            getModel().setValueIsAdjusting(true);
            if (false) {
                final Point2D p = arg0.getPositionRelativeTo(self.getParent());
                getModel().setBroom(p);
            } else
                view2model(new XYMemento(getModel(), arg0.getPositionRelativeTo(self.getParent())));
        }

        @Override
        public void mouseEntered(final PInputEvent arg0) {
            super.mouseEntered(arg0);
            arg0.pushCursor(MOVE_CURSOR);
        }

        @Override
        public void mouseExited(final PInputEvent arg0) {
            super.mouseExited(arg0);
            arg0.popCursor();
        }

        @Override
        public void mousePressed(final PInputEvent arg0) {
            arg0.setHandled(true);
            first = new XYMemento(getModel(), getModel().getBroom());
        }

        @Override
        public void mouseReleased(final PInputEvent pinputevent) {
            getModel().setValueIsAdjusting(false);
            if (first != null && last != null && first != last)
                ChangeManager.getTrivial(changer).undoable(first, last);
            first = last = null;
        }
    });
    slider.addInputEventListener(new PDragEventHandler() {
        @Override
        protected void endDrag(final PInputEvent pinputevent) {
            log.debug("speed");
        }

        /** adjust the slider */
        @Override
        public void mouseDragged(final PInputEvent arg0) {
            arg0.setHandled(true);
            final Point2D p = arg0.getPositionRelativeTo(self);
            final BoundedRangeModel r = self.getModel().getSplitTimeMillis();
            if (r == null)
                return;
            r.setValueIsAdjusting(true);
            view2model(new SplitMemento(getModel(), ratio2value(p.getY() / stickLength, r)));
        }

        @Override
        public void mouseEntered(final PInputEvent arg0) {
            super.mouseEntered(arg0);
            arg0.pushCursor(UPDN_CURSOR);
        }

        @Override
        public void mouseExited(final PInputEvent arg0) {
            super.mouseExited(arg0);
            arg0.popCursor();
        }

        @Override
        public void mousePressed(final PInputEvent arg0) {
            arg0.setHandled(true);
            first = new SplitMemento(getModel(), getModel().getSplitTimeMillis().getValue());
        }

        @Override
        public void mouseReleased(final PInputEvent pinputevent) {
            log.debug("speed");
            final BoundedRangeModel r = self.getModel().getSplitTimeMillis();
            if (r == null)
                return;
            r.setValueIsAdjusting(false);
            if (first != null && last != null && first != last)
                ChangeManager.getTrivial(changer).undoable(first, last);
            first = last = null;
        }
    });
}

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  .j  a  v a2  s . co  m
* 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.pentaho.di.core.gui.SwingDirectGC.java

private Stroke createStroke() {
    float[] dash;
    switch (lineStyle) {
    case SOLID://from   ww  w.j  ava2 s  .  c om
        dash = null;
        break;
    case DOT:
        dash = new float[] { 5, };
        break;
    case DASHDOT:
        dash = new float[] { 10, 5, 5, 5, };
        break;
    case PARALLEL:
        dash = new float[] { 10, 5, 10, 5, };
        break;
    default:
        throw new RuntimeException("Unhandled line style!");
    }
    return new BasicStroke(lineWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 2, dash, 0);
}

From source file:org.pentaho.di.core.gui.SwingGC.java

private Stroke createStroke() {
    float[] dash;
    switch (lineStyle) {
    case SOLID://  ww  w . j  ava 2s  .c  o  m
        dash = null;
        break;
    case DOT:
        dash = new float[] { 5, };
        break;
    case DASHDOT:
        dash = new float[] { 10, 5, 5, 5, };
        break;
    case PARALLEL:
        dash = new float[] { 10, 5, 10, 5, };
        break;
    case DASH:
        dash = new float[] { 6, 2, };
        break;
    default:
        throw new RuntimeException("Unhandled line style!");
    }
    return new BasicStroke(lineWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 2, dash, 0);
}

From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.internal.PdfGraphics2D.java

private void setStrokeDiff(final Stroke newStroke, final Stroke oldStroke) {
    if (newStroke == oldStroke) {
        return;//from w  ww. ja  v a2s.co  m
    }
    if (!(newStroke instanceof BasicStroke)) {
        return;
    }
    final BasicStroke nStroke = (BasicStroke) newStroke;
    final boolean oldOk = (oldStroke instanceof BasicStroke);
    BasicStroke oStroke = null;
    if (oldOk) {
        oStroke = (BasicStroke) oldStroke;
    }
    if (!oldOk || nStroke.getLineWidth() != oStroke.getLineWidth()) {
        cb.setLineWidth(nStroke.getLineWidth());
    }
    if (!oldOk || nStroke.getEndCap() != oStroke.getEndCap()) {
        switch (nStroke.getEndCap()) {
        case BasicStroke.CAP_BUTT:
            cb.setLineCap(0);
            break;
        case BasicStroke.CAP_SQUARE:
            cb.setLineCap(2);
            break;
        default:
            cb.setLineCap(1);
        }
    }
    if (!oldOk || nStroke.getLineJoin() != oStroke.getLineJoin()) {
        switch (nStroke.getLineJoin()) {
        case BasicStroke.JOIN_MITER:
            cb.setLineJoin(0);
            break;
        case BasicStroke.JOIN_BEVEL:
            cb.setLineJoin(2);
            break;
        default:
            cb.setLineJoin(1);
        }
    }
    if (!oldOk || nStroke.getMiterLimit() != oStroke.getMiterLimit()) {
        cb.setMiterLimit(nStroke.getMiterLimit());
    }
    final boolean makeDash;
    if (oldOk) {
        if (nStroke.getDashArray() != null) {
            if (nStroke.getDashPhase() != oStroke.getDashPhase()) {
                makeDash = true;
            } else if (!Arrays.equals(nStroke.getDashArray(), oStroke.getDashArray())) {
                makeDash = true;
            } else {
                makeDash = false;
            }
        } else if (oStroke.getDashArray() != null) {
            makeDash = true;
        } else {
            makeDash = false;
        }
    } else {
        makeDash = true;
    }
    if (makeDash) {
        final float[] dash = nStroke.getDashArray();
        if (dash == null) {
            cb.setLiteral("[]0 d\n");
        } else {
            cb.setLiteral('[');
            final int lim = dash.length;
            for (int k = 0; k < lim; ++k) {
                cb.setLiteral(dash[k]);
                cb.setLiteral(' ');
            }
            cb.setLiteral(']');
            cb.setLiteral(nStroke.getDashPhase());
            cb.setLiteral(" d\n");
        }
    }
}