List of usage examples for java.awt BasicStroke getLineWidth
public float getLineWidth()
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:/*ww w. j av a2 s . 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: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()// w w w . jav a 2s .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.jfree.experimental.swt.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()/*w w w .ja v a 2 s . co m*/ */ public void setStroke(Stroke stroke) { if (stroke == null) { throw new IllegalArgumentException("Null 'stroke' argument."); } if (stroke instanceof BasicStroke) { BasicStroke bs = (BasicStroke) stroke; this.gc.setLineWidth((int) bs.getLineWidth()); this.gc.setLineJoin(toSwtLineJoin(bs.getLineJoin())); this.gc.setLineCap(toSwtLineCap(bs.getEndCap())); // 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: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()); }//ww w. j ava2s .co 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.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//from w w w. ja v a 2 s . c om */ 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.bigwiv.blastgraph.gui.graphvisualization.EdgePainter.java
@Override public Paint transform(ValueEdge ve) { Layout<HitVertex, ValueEdge> layout = vv.getGraphLayout(); BlastGraph<HitVertex, ValueEdge> graph = (BlastGraph<HitVertex, ValueEdge>) layout.getGraph(); Pair<HitVertex> p = graph.getEndpoints(ve); HitVertex b = p.getFirst();//from ww w .j ava 2 s. co m HitVertex f = p.getSecond(); BasicStroke stroke = (BasicStroke) strokeTransformer.transform(ve); float lineWith = stroke.getLineWidth(); Point2D pb = transformer.transform(layout.transform(b)); Point2D pf = transformer.transform(layout.transform(f)); float xB = (float) pb.getX(); float yB = (float) pb.getY(); float xF = (float) pf.getX(); float yF = (float) pf.getY(); return null; }
From source file:org.eclipse.birt.chart.device.svg.SVGGraphics2D.java
/** * Adds stroke color and style information to the element passed in. * /*from ww w.ja va2 s . co 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 * /*ww w. ja va 2s.co m*/ * @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.graphics.internal.LogicalPageDrawable.java
protected boolean drawDrawable(final RenderableReplacedContentBox content, final Graphics2D g2, final DrawableWrapper d) { final double x = StrictGeomUtility.toExternalValue(content.getX()); final double y = StrictGeomUtility.toExternalValue(content.getY()); final double width = StrictGeomUtility.toExternalValue(content.getWidth()); final double height = StrictGeomUtility.toExternalValue(content.getHeight()); if ((width < 0 || height < 0) || (width == 0 && height == 0)) { return false; }//www . ja va 2s.c o m final Graphics2D clone = (Graphics2D) g2.create(); final StyleSheet styleSheet = content.getStyleSheet(); final Object attribute = styleSheet.getStyleProperty(ElementStyleKeys.ANTI_ALIASING); if (attribute != null) { if (Boolean.TRUE.equals(attribute)) { clone.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); } else if (Boolean.FALSE.equals(attribute)) { clone.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } } if (RenderUtility.isFontSmooth(styleSheet, metaData)) { clone.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); } else { clone.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); } if (strictClipping == false) { final double extraPadding; final Object o = styleSheet.getStyleProperty(ElementStyleKeys.STROKE); if (o instanceof BasicStroke) { final BasicStroke stroke = (BasicStroke) o; extraPadding = stroke.getLineWidth() / 2.0; } else { extraPadding = 0.5; } final Rectangle2D.Double clipBounds = new Rectangle2D.Double(x - extraPadding, y - extraPadding, width + 2 * extraPadding, height + 2 * extraPadding); clone.clip(clipBounds); clone.translate(x, y); } else { final Rectangle2D.Double clipBounds = new Rectangle2D.Double(x, y, width + 1, height + 1); clone.clip(clipBounds); clone.translate(x, y); } configureGraphics(styleSheet, clone); configureStroke(styleSheet, clone); final Rectangle2D.Double bounds = new Rectangle2D.Double(0, 0, width, height); d.draw(clone, bounds); clone.dispose(); return true; }
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; }//from w ww .ja va 2 s . c om 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); }