List of usage examples for java.awt BasicStroke getDashArray
public float[] getDashArray()
From source file:SWTGraphics2D.java
/** * Sets the stroke for this graphics context. For now, this implementation * only recognises the {@link BasicStroke} class. * * @param stroke the stroke (<code>null</code> not permitted). * * @see #getStroke()/* www . j a v a2s .c om*/ */ public void setStroke(Stroke stroke) { if (stroke instanceof BasicStroke) { BasicStroke bs = (BasicStroke) stroke; // linewidth this.gc.setLineWidth((int) bs.getLineWidth()); // line join switch (bs.getLineJoin()) { case BasicStroke.JOIN_BEVEL: this.gc.setLineJoin(SWT.JOIN_BEVEL); break; case BasicStroke.JOIN_MITER: this.gc.setLineJoin(SWT.JOIN_MITER); break; case BasicStroke.JOIN_ROUND: this.gc.setLineJoin(SWT.JOIN_ROUND); break; } // line cap switch (bs.getEndCap()) { case BasicStroke.CAP_BUTT: this.gc.setLineCap(SWT.CAP_FLAT); break; case BasicStroke.CAP_ROUND: this.gc.setLineCap(SWT.CAP_ROUND); break; case BasicStroke.CAP_SQUARE: this.gc.setLineCap(SWT.CAP_SQUARE); break; } // set the line style to solid by default this.gc.setLineStyle(SWT.LINE_SOLID); // apply dash style if any float[] dashes = bs.getDashArray(); if (dashes != null) { int[] swtDashes = new int[dashes.length]; for (int i = 0; i < swtDashes.length; i++) { swtDashes[i] = (int) dashes[i]; } this.gc.setLineDash(swtDashes); } } else { throw new RuntimeException("Can only handle 'Basic Stroke' at present."); } }
From source file:org.apache.fop.afp.AFPGraphics2D.java
/** * Apply the stroke to the AFP graphics object. * This takes the java stroke and outputs the appropriate settings * to the AFP graphics object so that the stroke attributes are handled. * * @param stroke the java stroke// ww w .j a v a 2 s . com */ protected void applyStroke(Stroke stroke) { if (stroke instanceof BasicStroke) { BasicStroke basicStroke = (BasicStroke) stroke; // set line width and correct it; NOTE: apparently we need to correct the width so that the // output looks OK since the default with depends on the output device float lineWidth = basicStroke.getLineWidth(); float correction = paintingState.getLineWidthCorrection(); graphicsObj.setLineWidth(lineWidth * correction); //No line join, miter limit and end cap support in GOCA. :-( // set line type/style (note: this is an approximation at best!) float[] dashArray = basicStroke.getDashArray(); if (paintingState.setDashArray(dashArray)) { byte type = GraphicsSetLineType.DEFAULT; // normally SOLID if (dashArray != null) { type = GraphicsSetLineType.DOTTED; // default to plain DOTTED if dashed line // float offset = basicStroke.getDashPhase(); if (dashArray.length == 2) { if (dashArray[0] < dashArray[1]) { type = GraphicsSetLineType.SHORT_DASHED; } else if (dashArray[0] > dashArray[1]) { type = GraphicsSetLineType.LONG_DASHED; } } else if (dashArray.length == 4) { if (dashArray[0] > dashArray[1] && dashArray[2] < dashArray[3]) { type = GraphicsSetLineType.DASH_DOT; } else if (dashArray[0] < dashArray[1] && dashArray[2] < dashArray[3]) { type = GraphicsSetLineType.DOUBLE_DOTTED; } } else if (dashArray.length == 6) { if (dashArray[0] > dashArray[1] && dashArray[2] < dashArray[3] && dashArray[4] < dashArray[5]) { type = GraphicsSetLineType.DASH_DOUBLE_DOTTED; } } } graphicsObj.setLineType(type); } } else { LOG.warn("Unsupported Stroke: " + stroke.getClass().getName()); } }
From source file:org.apache.pdfbox.util.operator.pagedrawer.StrokePath.java
/** * S stroke the path./*from w w w . j av a 2s . 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); } }
From source file:org.eclipse.birt.chart.device.svg.SVGGraphics2D.java
/** * Adds stroke color and style information to the element passed in. * //from w w w .j a va 2 s .c o m * @param currentElement * the element to add style information to. * @param isClipped * boolean that determines whether to defer the clipping of the * element */ protected void setStrokeStyle(Element currentElement, boolean deferClipped) { Element element = currentElement; if (deferStrokColor != null) { // Need to get the parent element. element = deferStrokColor; } String style = element.getAttribute("style"); //$NON-NLS-1$ if (style == null) style = ""; //$NON-NLS-1$ if (color != null) { style += "stroke:" + serializeToString(color) + ";"; //$NON-NLS-1$ //$NON-NLS-2$ } if ((stroke != null) && (stroke instanceof BasicStroke)) { BasicStroke bs = (BasicStroke) stroke; if (bs.getLineWidth() > 0) style += "stroke-width:" + bs.getLineWidth() + ";"; //$NON-NLS-1$ //$NON-NLS-2$ if (bs.getDashArray() != null) { StringBuffer dashArrayStr = new StringBuffer(); for (int x = 0; x < bs.getDashArray().length; x++) { dashArrayStr.append(" ").append(bs.getDashArray()[x]); //$NON-NLS-1$ } if (!(dashArrayStr.toString().equals(""))) //$NON-NLS-1$ style += "stroke-dasharray:" + dashArrayStr + ";"; //$NON-NLS-1$ //$NON-NLS-2$ } style += "stroke-miterlimit:" + bs.getMiterLimit() + ";"; //$NON-NLS-1$ //$NON-NLS-2$ switch (bs.getLineJoin()) { case BasicStroke.JOIN_BEVEL: style += "stroke-linejoin:bevel;"; //$NON-NLS-1$ break; case BasicStroke.JOIN_ROUND: style += "stroke-linejoin:round;"; //$NON-NLS-1$ break; } switch (bs.getEndCap()) { case BasicStroke.CAP_ROUND: style += "stroke-linecap:round;"; //$NON-NLS-1$ break; case BasicStroke.CAP_SQUARE: style += "stroke-linecap:square;"; //$NON-NLS-1$ break; } } element.setAttribute("style", style); //$NON-NLS-1$ if (styleClass != null) element.setAttribute("class", styleClass); //$NON-NLS-1$ if (id != null) element.setAttribute("id", id); //$NON-NLS-1$ if ((clip != null) && (!deferClipped)) element.setAttribute("clip-path", "url(#clip" + clip.hashCode() + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ }
From source file:org.kalypso.ogc.sensor.diagview.DiagViewUtils.java
/** * Builds the xml binding object using the given diagram view template * /*from ww w .j av a2 s . c om*/ * @return xml binding object (ready for marshalling for instance) */ public static Obsdiagview buildDiagramTemplateXML(final DiagView view, final IContainer context) { final Obsdiagview xmlTemplate = ODT_OF.createObsdiagview(); final Legend xmlLegend = ODT_OF.createObsdiagviewLegend(); xmlLegend.setTitle(view.getLegendName()); xmlLegend.setVisible(view.isShowLegend()); xmlTemplate.setLegend(xmlLegend); xmlTemplate.setTitle(view.getTitle()); xmlTemplate.setTitleFormat(view.getTitleFormat()); // only set timezone if defined final TimeZone timezone = view.getTimezone(); if (timezone != null) xmlTemplate.setTimezone(timezone.getID()); final List<TypeAxis> xmlAxes = xmlTemplate.getAxis(); final DiagramAxis[] diagramAxes = view.getDiagramAxes(); for (final DiagramAxis axis : diagramAxes) { final TypeAxis xmlAxis = ODT_OF.createTypeAxis(); xmlAxis.setDatatype(axis.getDataType()); xmlAxis.setDirection(TypeDirection.fromValue(axis.getDirection())); xmlAxis.setId(axis.getIdentifier()); xmlAxis.setInverted(axis.isInverted()); xmlAxis.setLabel(axis.getLabel()); xmlAxis.setPosition(TypePosition.fromValue(axis.getPosition())); xmlAxis.setUnit(axis.getUnit()); xmlAxes.add(xmlAxis); } xmlTemplate.setFeatures(StringUtils.join(view.getEnabledFeatures(), ';')); int ixCurve = 1; final List<TypeObservation> xmlThemes = xmlTemplate.getObservation(); final Map<IObservation, ArrayList<ObsViewItem>> map = ObsView.mapItems(view.getItems()); for (final Entry<IObservation, ArrayList<ObsViewItem>> entry : map.entrySet()) { final IObservation obs = entry.getKey(); if (obs == null) continue; final TypeObservation xmlTheme = ODT_OF.createTypeObservation(); final String href = obs.getHref(); final String xmlHref = ObsViewUtils.makeRelativ(context, href); xmlTheme.setHref(xmlHref); xmlTheme.setLinktype("zml"); //$NON-NLS-1$ final List<TypeCurve> xmlCurves = xmlTheme.getCurve(); final Iterator<ObsViewItem> itCurves = ((List<ObsViewItem>) entry.getValue()).iterator(); while (itCurves.hasNext()) { final DiagViewCurve curve = (DiagViewCurve) itCurves.next(); final TypeCurve xmlCurve = ODT_OF.createTypeCurve(); xmlCurve.setId("C" + ixCurve++); //$NON-NLS-1$ xmlCurve.setName(curve.getName()); xmlCurve.setColor(StringUtilities.colorToString(curve.getColor())); xmlCurve.setShown(curve.isShown()); final Stroke stroke = curve.getStroke(); if (stroke instanceof BasicStroke) { final BasicStroke bs = (BasicStroke) stroke; final TypeCurve.Stroke strokeType = ODT_OF.createTypeCurveStroke(); xmlCurve.setStroke(strokeType); strokeType.setWidth(bs.getLineWidth()); final float[] dashArray = bs.getDashArray(); if (dashArray != null) { final List<Float> dashList = strokeType.getDash(); for (final float element : dashArray) dashList.add(new Float(element)); } } final List<Mapping> xmlMappings = xmlCurve.getMapping(); final AxisMapping[] mappings = curve.getMappings(); for (final AxisMapping mapping : mappings) { final Mapping xmlMapping = ODT_OF.createTypeCurveMapping(); xmlMapping.setDiagramAxis(mapping.getDiagramAxis().getIdentifier()); xmlMapping.setObservationAxis(mapping.getObservationAxis().getName()); xmlMappings.add(xmlMapping); } xmlCurves.add(xmlCurve); } xmlThemes.add(xmlTheme); } return xmlTemplate; }
From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.internal.PdfGraphics2D.java
private Stroke transformStroke(final Stroke stroke) { if (!(stroke instanceof BasicStroke)) { return stroke; }/* www . j ava 2s . com*/ final BasicStroke st = (BasicStroke) stroke; final float scale = (float) Math.sqrt(Math.abs(transform.getDeterminant())); final float[] dash = st.getDashArray(); if (dash != null) { final int dashLength = dash.length; for (int k = 0; k < dashLength; ++k) { dash[k] *= scale; } } return new BasicStroke(st.getLineWidth() * scale, st.getEndCap(), st.getLineJoin(), st.getMiterLimit(), dash, st.getDashPhase() * scale); }
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;//ww w .j ava2s . c o 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"); } } }