java.awt.Stroke Java Examples

The following examples show how to use java.awt.Stroke. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FXGraphics2D.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * Sets the stroke that will be used to draw shapes.
 * 
 * @param s  the stroke ({@code null} not permitted).
 * 
 * @see #getStroke() 
 */
@Override
public void setStroke(Stroke s) {
    nullNotPermitted(s, "s");
    this.stroke = s;
    if (stroke instanceof BasicStroke) {
        BasicStroke bs = (BasicStroke) s;
        double lineWidth = bs.getLineWidth();
        if (lineWidth == 0.0) {
            lineWidth = this.zeroStrokeWidth;
        }
        this.gc.setLineWidth(lineWidth);
        this.gc.setLineCap(awtToJavaFXLineCap(bs.getEndCap()));
        this.gc.setLineJoin(awtToJavaFXLineJoin(bs.getLineJoin()));
        this.gc.setMiterLimit(bs.getMiterLimit());
    }
}
 
Example #2
Source File: Crosshair.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a new crosshair value with the specified value and line style.
 *
 * @param value  the value.
 * @param paint  the line paint (<code>null</code> not permitted).
 * @param stroke  the line stroke (<code>null</code> not permitted).
 */
public Crosshair(double value, Paint paint, Stroke stroke) {
    ParamChecks.nullNotPermitted(paint, "paint");
    ParamChecks.nullNotPermitted(stroke, "stroke");
    this.visible = true;
    this.value = value;
    this.paint = paint;
    this.stroke = stroke;
    this.labelVisible = false;
    this.labelGenerator = new StandardCrosshairLabelGenerator();
    this.labelAnchor = RectangleAnchor.BOTTOM_LEFT;
    this.labelXOffset = 3.0;
    this.labelYOffset = 3.0;
    this.labelFont = new Font("Tahoma", Font.PLAIN, 12);
    this.labelPaint = Color.black;
    this.labelBackgroundPaint = new Color(0, 0, 255, 63);
    this.labelOutlineVisible = true;
    this.labelOutlinePaint = Color.black;
    this.labelOutlineStroke = new BasicStroke(0.5f);
    this.pcs = new PropertyChangeSupport(this);
}
 
Example #3
Source File: BlockWidget.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void paintWidget() {
    super.paintWidget();
    Graphics2D g = this.getGraphics();
    Stroke old = g.getStroke();
    g.setColor(Color.BLUE);
    Rectangle r = new Rectangle(this.getPreferredBounds());
    r.width--;
    r.height--;
    if (this.getBounds().width > 0 && this.getBounds().height > 0) {
        g.setStroke(new BasicStroke(2));
        g.drawRect(r.x, r.y, r.width, r.height);
    }

    Color titleColor = Color.BLACK;
    g.setColor(titleColor);
    g.setFont(titleFont);

    String s = "B" + blockNode.getName();
    Rectangle2D r1 = g.getFontMetrics().getStringBounds(s, g);
    g.drawString(s, r.x + 5, r.y + (int) r1.getHeight());
    g.setStroke(old);
}
 
Example #4
Source File: DFDSRole.java    From ramus with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void paint(Graphics2D g) {

    g.setColor(function.getBackground());
    final Rectangle2D rect = movingArea.getBounds(getBounds());

    RoundRectangle2D.Double rec = new RoundRectangle2D.Double(rect.getX(),
            rect.getY(), rect.getWidth(), rect.getHeight(),
            movingArea.getIDoubleOrdinate(4),
            movingArea.getIDoubleOrdinate(4));

    g.fill(rec);
    g.setFont(function.getFont());
    paintText(g);

    paintBorder(g);

    final Stroke tmp = g.getStroke();
    g.draw(rec);
    g.setStroke(tmp);
    paintTringle(g);

}
 
Example #5
Source File: StrokeMap.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Tests this map for equality with an arbitrary object.
 *
 * @param obj  the object (<code>null</code> permitted).
 *
 * @return A boolean.
 */
@Override
public boolean equals(Object obj) {
    if (obj == this) {
        return true;
    }
    if (!(obj instanceof StrokeMap)) {
        return false;
    }
    StrokeMap that = (StrokeMap) obj;
    if (this.store.size() != that.store.size()) {
        return false;
    }
    Set keys = this.store.keySet();
    Iterator iterator = keys.iterator();
    while (iterator.hasNext()) {
        Comparable key = (Comparable) iterator.next();
        Stroke s1 = getStroke(key);
        Stroke s2 = that.getStroke(key);
        if (!ObjectUtilities.equal(s1, s2)) {
            return false;
        }
    }
    return true;
}
 
Example #6
Source File: CloseTabComponent.java    From wpcleaner with Apache License 2.0 6 votes vote down vote up
@Override
protected void paintComponent(Graphics g) {
  super.paintComponent(g);
  Graphics2D g2 = (Graphics2D) g;
  Stroke stroke = g2.getStroke();
  //shift the image for pressed buttons
  if (!getModel().isPressed()) {
    g2.translate(-1, -1);
  }
  g2.setStroke(new BasicStroke(2));
  g.setColor(Color.BLACK);
  if (getModel().isRollover()) {
    g.setColor(Color.MAGENTA);
  }
  int delta = 6;
  g.drawLine(delta, delta, getWidth() - delta - 1, getHeight() - delta - 1);
  g.drawLine(getWidth() - delta - 1, delta, delta, getHeight() - delta - 1);
  //leave the graphics unchanged
  if (!getModel().isPressed()) {
    g.translate(1, 1);
  }
  g2.setStroke(stroke);
}
 
Example #7
Source File: Cardumen_00143_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Utility method for drawing a line perpendicular to the range axis (used
 * for crosshairs).
 *
 * @param g2  the graphics device.
 * @param dataArea  the area defined by the axes.
 * @param value  the data value.
 * @param stroke  the line stroke (<code>null</code> not permitted).
 * @param paint  the line paint (<code>null</code> not permitted).
 */
protected void drawRangeLine(Graphics2D g2, Rectangle2D dataArea,
        double value, Stroke stroke, Paint paint) {

    double java2D = getRangeAxis().valueToJava2D(value, dataArea, 
            getRangeAxisEdge());
    Line2D line = null;
    if (this.orientation == PlotOrientation.HORIZONTAL) {
        line = new Line2D.Double(java2D, dataArea.getMinY(), java2D, 
                dataArea.getMaxY());
    }
    else if (this.orientation == PlotOrientation.VERTICAL) {
        line = new Line2D.Double(dataArea.getMinX(), java2D, 
                dataArea.getMaxX(), java2D);
    }
    g2.setStroke(stroke);
    g2.setPaint(paint);
    g2.draw(line);

}
 
Example #8
Source File: Underline.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
void drawUnderline(Graphics2D g2d,
                   float thickness,
                   float x1,
                   float x2,
                   float y) {

    Stroke saveStroke = g2d.getStroke();
    g2d.setStroke(stroke);

    Line2D.Float drawLine = new Line2D.Float(x1, y, x2, y);
    g2d.draw(drawLine);

    drawLine.y1 += DEFAULT_THICKNESS;
    drawLine.y2 += DEFAULT_THICKNESS;
    drawLine.x1 += DEFAULT_THICKNESS;

    g2d.draw(drawLine);

    g2d.setStroke(saveStroke);
}
 
Example #9
Source File: TabbedPaneWidget.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void paint(Graphics2D g2, Rectangle rect) {
    Paint oldPaint = g2.getPaint();
    
    Arc2D arc = new Arc2D.Double(rect.x - radius + 0.5f, rect.y + rect.height - radius *2 +0.5f,
            radius*2, radius*2, -90, 90, Arc2D.OPEN);
    GeneralPath gp = new GeneralPath(arc);
    arc = new Arc2D.Double(rect.x+radius+0.5f, rect.y+0.5f,
            radius*4, radius*4, 180, -90, Arc2D.OPEN);
    gp.append(arc,true);
    arc = new Arc2D.Double(rect.x + rect.width - radius*6 +1f, rect.y+0.5f,
            radius*4, radius*4, 90, -90, Arc2D.OPEN);
    gp.append(arc,true);
    arc = new Arc2D.Double(rect.x + rect.width - radius*2 +1f, rect.y + rect.height - radius*2 +0.5f,
            radius*2, radius*2, 180, 90, Arc2D.OPEN);
    gp.append(arc,true);
    if (tabbedPane.selectedTab==tab) {
        g2.setPaint(SELECTED_TAB_COLOR);
        g2.fill(gp);
    } else {
        g2.setPaint(TAB_COLOR);
        g2.fill(gp);
        gp.closePath();
    }
    g2.setPaint(TAB_BORDER_COLOR);
    if (tab.getState().isFocused()) {
        Stroke s = g2.getStroke ();
        g2.setStroke (new BasicStroke(1.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, BasicStroke.JOIN_MITER, new float[] {2,2}, 0));
        g2.drawRect (rect.x+radius*3, rect.y+radius*2,rect.width-radius*6,rect.height-radius*4);
        g2.setStroke (s);
    }
    g2.draw(gp);
    
    g2.setPaint(oldPaint);
}
 
Example #10
Source File: StrokeMap.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Provides serialization support.
 *
 * @param stream  the output stream.
 *
 * @throws IOException  if there is an I/O error.
 */
private void writeObject(ObjectOutputStream stream) throws IOException {
    stream.defaultWriteObject();
    stream.writeInt(this.store.size());
    Set keys = this.store.keySet();
    Iterator iterator = keys.iterator();
    while (iterator.hasNext()) {
        Comparable key = (Comparable) iterator.next();
        stream.writeObject(key);
        Stroke stroke = getStroke(key);
        SerialUtilities.writeStroke(stroke, stream);
    }
}
 
Example #11
Source File: Marker.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a new marker.
 *
 * @param paint  the paint (<code>null</code> not permitted).
 * @param stroke  the stroke (<code>null</code> not permitted).
 * @param outlinePaint  the outline paint (<code>null</code> permitted).
 * @param outlineStroke  the outline stroke (<code>null</code> permitted).
 * @param alpha  the alpha transparency (must be in the range 0.0f to 
 *     1.0f).
 *     
 * @throws IllegalArgumentException if <code>paint</code> or 
 *     <code>stroke</code> is <code>null</code>, or <code>alpha</code> is 
 *     not in the specified range.
 */
protected Marker(Paint paint, Stroke stroke, 
                 Paint outlinePaint, Stroke outlineStroke, 
                 float alpha) {

    if (paint == null) {
        throw new IllegalArgumentException("Null 'paint' argument.");
    }
    if (stroke == null) {
        throw new IllegalArgumentException("Null 'stroke' argument.");
    }
    if (alpha < 0.0f || alpha > 1.0f)
        throw new IllegalArgumentException(
                "The 'alpha' value must be in the range 0.0f to 1.0f");
    
    this.paint = paint;
    this.stroke = stroke;
    this.outlinePaint = outlinePaint;
    this.outlineStroke = outlineStroke;
    this.alpha = alpha;
    
    this.labelFont = new Font("SansSerif", Font.PLAIN, 9);
    this.labelPaint = Color.black;
    this.labelAnchor = RectangleAnchor.TOP_LEFT;
    this.labelOffset = new RectangleInsets(3.0, 3.0, 3.0, 3.0);
    this.labelOffsetType = LengthAdjustmentType.CONTRACT;
    this.labelTextAnchor = TextAnchor.CENTER;
    
    this.listenerList = new EventListenerList();
}
 
Example #12
Source File: DiagramCanvas.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private void drawValueIndicator(Graphics2D g2d) {
    Diagram.RectTransform transform = diagram.getTransform();
    Point2D a = transform.transformB2A(dragPoint, null);
    double x = a.getX();
    if (x < selectedGraph.getXMin()) {
        x = selectedGraph.getXMin();
    }
    if (x > selectedGraph.getXMax()) {
        x = selectedGraph.getXMax();
    }
    final Stroke oldStroke = g2d.getStroke();
    final Color oldColor = g2d.getColor();

    double y = getY(selectedGraph, x);
    Point2D b = transform.transformA2B(new Point2D.Double(x, y), null);

    g2d.setStroke(new BasicStroke(1.0f));
    g2d.setColor(diagram.getForegroundColor());
    Ellipse2D.Double marker = new Ellipse2D.Double(b.getX() - 4.0, b.getY() - 4.0, 8.0, 8.0);
    g2d.draw(marker);

    g2d.setStroke(new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[]{6, 6}, 12));
    g2d.setColor(diagram.getForegroundColor());
    final Rectangle graphArea = diagram.getGraphArea();
    g2d.draw(new Line2D.Double(b.getX(), graphArea.y + graphArea.height, b.getX(), b.getY()));
    g2d.draw(new Line2D.Double(graphArea.x, b.getY(), b.getX(), b.getY()));

    DecimalFormat decimalFormat = new DecimalFormat("0.#####E0");
    String text = selectedGraph.getYName() + ": x = " + decimalFormat.format(x) + ", y = " + decimalFormat.format(y);

    g2d.setStroke(oldStroke);
    g2d.setColor(oldColor);

    drawTextBox(g2d, text, graphArea.x + 6, graphArea.y + 6 + 16, new Color(255, 255, 255, 128));
}
 
Example #13
Source File: PeriodAxisLabelInfo.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a new instance.
 *
 * @param periodClass  the subclass of {@link RegularTimePeriod} to use
 *                     (<code>null</code> not permitted).
 * @param dateFormat  the date format (<code>null</code> not permitted).
 * @param padding  controls the space around the band (<code>null</code>
 *                 not permitted).
 * @param labelFont  the label font (<code>null</code> not permitted).
 * @param labelPaint  the label paint (<code>null</code> not permitted).
 * @param drawDividers  a flag that controls whether dividers are drawn.
 * @param dividerStroke  the stroke used to draw the dividers
 *                       (<code>null</code> not permitted).
 * @param dividerPaint  the paint used to draw the dividers
 *                      (<code>null</code> not permitted).
 */
public PeriodAxisLabelInfo(Class periodClass, DateFormat dateFormat,
                           RectangleInsets padding,
                           Font labelFont, Paint labelPaint,
                           boolean drawDividers, Stroke dividerStroke,
                           Paint dividerPaint) {
    if (periodClass == null) {
        throw new IllegalArgumentException("Null 'periodClass' argument.");
    }
    if (dateFormat == null) {
        throw new IllegalArgumentException("Null 'dateFormat' argument.");
    }
    if (padding == null) {
        throw new IllegalArgumentException("Null 'padding' argument.");
    }
    if (labelFont == null) {
        throw new IllegalArgumentException("Null 'labelFont' argument.");
    }
    if (labelPaint == null) {
        throw new IllegalArgumentException("Null 'labelPaint' argument.");
    }
    if (dividerStroke == null) {
        throw new IllegalArgumentException(
                "Null 'dividerStroke' argument.");
    }
    if (dividerPaint == null) {
        throw new IllegalArgumentException("Null 'dividerPaint' argument.");
    }
    this.periodClass = periodClass;
    this.dateFormat = dateFormat;
    this.padding = padding;
    this.labelFont = labelFont;
    this.labelPaint = labelPaint;
    this.drawDividers = drawDividers;
    this.dividerStroke = dividerStroke;
    this.dividerPaint = dividerPaint;
}
 
Example #14
Source File: AbstractCategoryItemRenderer.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
/**
 * Draws a grid line against the domain axis.
 * <P>
 * Note that this default implementation assumes that the horizontal axis 
 * is the domain axis. If this is not the case, you will need to override 
 * this method.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param dataArea  the area for plotting data (not yet adjusted for any 
 *                  3D effect).
 * @param value  the Java2D value at which the grid line should be drawn.
 */
public void drawDomainGridline(Graphics2D g2,
                               CategoryPlot plot,
                               Rectangle2D dataArea,
                               double value) {

    Line2D line = null;
    PlotOrientation orientation = plot.getOrientation();

    if (orientation == PlotOrientation.HORIZONTAL) {
        line = new Line2D.Double(dataArea.getMinX(), value, 
                dataArea.getMaxX(), value);
    }
    else if (orientation == PlotOrientation.VERTICAL) {
        line = new Line2D.Double(value, dataArea.getMinY(), value, 
                dataArea.getMaxY());
    }

    Paint paint = plot.getDomainGridlinePaint();
    if (paint == null) {
        paint = CategoryPlot.DEFAULT_GRIDLINE_PAINT;
    }
    g2.setPaint(paint);

    Stroke stroke = plot.getDomainGridlineStroke();
    if (stroke == null) {
        stroke = CategoryPlot.DEFAULT_GRIDLINE_STROKE;
    }
    g2.setStroke(stroke);

    g2.draw(line);

}
 
Example #15
Source File: jMutRepair_001_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Draws the gridlines for the plot.
 *
 * @param g2  the graphics device.
 * @param dataArea  the area inside the axes.
 * 
 * @see #drawRangeGridlines(Graphics2D, Rectangle2D, List)
 */
protected void drawDomainGridlines(Graphics2D g2, Rectangle2D dataArea) {

    // draw the domain grid lines, if any...
    if (isDomainGridlinesVisible()) {
        CategoryAnchor anchor = getDomainGridlinePosition();
        RectangleEdge domainAxisEdge = getDomainAxisEdge();
        Stroke gridStroke = getDomainGridlineStroke();
        Paint gridPaint = getDomainGridlinePaint();
        if ((gridStroke != null) && (gridPaint != null)) {
            // iterate over the categories
            CategoryDataset data = getDataset();
            if (data != null) {
                CategoryAxis axis = getDomainAxis();
                if (axis != null) {
                    int columnCount = data.getColumnCount();
                    for (int c = 0; c < columnCount; c++) {
                        double xx = axis.getCategoryJava2DCoordinate(
                                anchor, c, columnCount, dataArea, 
                                domainAxisEdge);
                        CategoryItemRenderer renderer1 = getRenderer();
                        if (renderer1 != null) {
                            renderer1.drawDomainGridline(g2, this, 
                                    dataArea, xx);
                        }
                    }
                }
            }
        }
    }
}
 
Example #16
Source File: Underline.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
private Stroke getStroke(float thickness) {

            float lineThickness = getLineThickness(thickness);
            BasicStroke stroke = cachedStroke;
            if (stroke == null ||
                    stroke.getLineWidth() != lineThickness) {

                stroke = createStroke(lineThickness);
                cachedStroke = stroke;
            }

            return stroke;
        }
 
Example #17
Source File: jMutRepair_0020_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Draws a grid line against the domain axis.
 * <P>
 * Note that this default implementation assumes that the horizontal axis
 * is the domain axis. If this is not the case, you will need to override
 * this method.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param dataArea  the area for plotting data (not yet adjusted for any
 *                  3D effect).
 * @param value  the Java2D value at which the grid line should be drawn.
 * @param paint  the paint (<code>null</code> not permitted).
 * @param stroke  the stroke (<code>null</code> not permitted).
 *
 * @see #drawRangeGridline(Graphics2D, CategoryPlot, ValueAxis,
 *     Rectangle2D, double)
 *
 * @since 1.2.0
 */
public void drawDomainLine(Graphics2D g2, CategoryPlot plot,
        Rectangle2D dataArea, double value, Paint paint, Stroke stroke) {

    if (paint == null) {
        throw new IllegalArgumentException("Null 'paint' argument.");
    }
    if (stroke == null) {
        throw new IllegalArgumentException("Null 'stroke' argument.");
    }
    Line2D line = null;
    PlotOrientation orientation = plot.getOrientation();

    if (orientation == PlotOrientation.HORIZONTAL) {
        line = new Line2D.Double(dataArea.getMinX(), value,
                dataArea.getMaxX(), value);
    }
    else if (orientation == PlotOrientation.VERTICAL) {
        line = new Line2D.Double(value, dataArea.getMinY(), value,
                dataArea.getMaxY());
    }

    g2.setPaint(paint);
    g2.setStroke(stroke);
    g2.draw(line);

}
 
Example #18
Source File: DefaultDrawingSupplier.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a new supplier.
 *
 * @param paintSequence  the paint sequence.
 * @param fillPaintSequence  the fill paint sequence.
 * @param outlinePaintSequence  the outline paint sequence.
 * @param strokeSequence  the stroke sequence.
 * @param outlineStrokeSequence  the outline stroke sequence.
 * @param shapeSequence  the shape sequence.
 *
 * @since 1.0.6
 */
public DefaultDrawingSupplier(Paint[] paintSequence,
        Paint[] fillPaintSequence, Paint[] outlinePaintSequence,
        Stroke[] strokeSequence, Stroke[] outlineStrokeSequence,
        Shape[] shapeSequence) {

    this.paintSequence = paintSequence;
    this.fillPaintSequence = fillPaintSequence;
    this.outlinePaintSequence = outlinePaintSequence;
    this.strokeSequence = strokeSequence;
    this.outlineStrokeSequence = outlineStrokeSequence;
    this.shapeSequence = shapeSequence;
}
 
Example #19
Source File: AbstractCategoryItemRenderer.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
/**
 * Draws a grid line against the range axis.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param axis  the value axis.
 * @param dataArea  the area for plotting data (not yet adjusted for any 
 *                  3D effect).
 * @param value  the value at which the grid line should be drawn.
 *
 */
public void drawRangeGridline(Graphics2D g2,
                              CategoryPlot plot,
                              ValueAxis axis,
                              Rectangle2D dataArea,
                              double value) {

    Range range = axis.getRange();
    if (!range.contains(value)) {
        return;
    }

    PlotOrientation orientation = plot.getOrientation();
    double v = axis.valueToJava2D(value, dataArea, plot.getRangeAxisEdge());
    Line2D line = null;
    if (orientation == PlotOrientation.HORIZONTAL) {
        line = new Line2D.Double(v, dataArea.getMinY(), v, 
                dataArea.getMaxY());
    }
    else if (orientation == PlotOrientation.VERTICAL) {
        line = new Line2D.Double(dataArea.getMinX(), v, 
                dataArea.getMaxX(), v);
    }

    Paint paint = plot.getRangeGridlinePaint();
    if (paint == null) {
        paint = CategoryPlot.DEFAULT_GRIDLINE_PAINT;
    }
    g2.setPaint(paint);

    Stroke stroke = plot.getRangeGridlineStroke();
    if (stroke == null) {
        stroke = CategoryPlot.DEFAULT_GRIDLINE_STROKE;
    }
    g2.setStroke(stroke);

    g2.draw(line);

}
 
Example #20
Source File: LineBorder.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a new border with the specified color.
 *
 * @param paint  the color ({@code null} not permitted).
 * @param stroke  the border stroke ({@code null} not permitted).
 * @param insets  the insets ({@code null} not permitted).
 */
public LineBorder(Paint paint, Stroke stroke, RectangleInsets insets) {
    ParamChecks.nullNotPermitted(paint, "paint");
    ParamChecks.nullNotPermitted(stroke, "stroke");
    ParamChecks.nullNotPermitted(insets, "insets");
    this.paint = paint;
    this.stroke = stroke;
    this.insets = insets;
}
 
Example #21
Source File: DefaultDrawingSupplier.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a new supplier.
 *
 * @param paintSequence  the fill paint sequence.
 * @param outlinePaintSequence  the outline paint sequence.
 * @param strokeSequence  the stroke sequence.
 * @param outlineStrokeSequence  the outline stroke sequence.
 * @param shapeSequence  the shape sequence.
 */
public DefaultDrawingSupplier(Paint[] paintSequence,
                              Paint[] outlinePaintSequence,
                              Stroke[] strokeSequence,
                              Stroke[] outlineStrokeSequence,
                              Shape[] shapeSequence) {

    this.paintSequence = paintSequence;
    this.fillPaintSequence = DEFAULT_FILL_PAINT_SEQUENCE;
    this.outlinePaintSequence = outlinePaintSequence;
    this.strokeSequence = strokeSequence;
    this.outlineStrokeSequence = outlineStrokeSequence;
    this.shapeSequence = shapeSequence;

}
 
Example #22
Source File: ContourPlot.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Draws a horizontal line across the chart to represent a 'range marker'.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param rangeAxis  the range axis.
 * @param marker  the marker line.
 * @param dataArea  the axis data area.
 */
public void drawRangeMarker(Graphics2D g2,
                            ContourPlot plot,
                            ValueAxis rangeAxis,
                            Marker marker,
                            Rectangle2D dataArea) {

    if (marker instanceof ValueMarker) {
        ValueMarker vm = (ValueMarker) marker;
        double value = vm.getValue();
        Range range = rangeAxis.getRange();
        if (!range.contains(value)) {
            return;
        }

        double y = rangeAxis.valueToJava2D(value, dataArea,
                RectangleEdge.LEFT);
        Line2D line = new Line2D.Double(dataArea.getMinX(), y,
                dataArea.getMaxX(), y);
        Paint paint = marker.getOutlinePaint();
        Stroke stroke = marker.getOutlineStroke();
        g2.setPaint(paint != null ? paint : Plot.DEFAULT_OUTLINE_PAINT);
        g2.setStroke(stroke != null ? stroke : Plot.DEFAULT_OUTLINE_STROKE);
        g2.draw(line);
    }

}
 
Example #23
Source File: ContourPlot.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Utility method for drawing a crosshair on the chart (if required).
 *
 * @param g2  The graphics device.
 * @param dataArea  The data area.
 * @param value  The coordinate, where to draw the line.
 * @param stroke  The stroke to use.
 * @param paint  The paint to use.
 */
protected void drawHorizontalLine(Graphics2D g2, Rectangle2D dataArea,
                                  double value, Stroke stroke,
                                  Paint paint) {

    double yy = getRangeAxis().valueToJava2D(value, dataArea,
            RectangleEdge.LEFT);
    Line2D line = new Line2D.Double(dataArea.getMinX(), yy,
            dataArea.getMaxX(), yy);
    g2.setStroke(stroke);
    g2.setPaint(paint);
    g2.draw(line);

}
 
Example #24
Source File: Decoration.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private void drawTextAndEmbellishments(Label label,
                                       Graphics2D g2d,
                                       float x,
                                       float y) {

    label.handleDraw(g2d, x, y);

    if (!strikethrough && stdUnderline == null && imUnderline == null) {
        return;
    }

    float x1 = x;
    float x2 = x1 + (float)label.getLogicalBounds().getWidth();

    CoreMetrics cm = label.getCoreMetrics();
    if (strikethrough) {
        Stroke savedStroke = g2d.getStroke();
        g2d.setStroke(new BasicStroke(cm.strikethroughThickness,
                                      BasicStroke.CAP_BUTT,
                                      BasicStroke.JOIN_MITER));
        float strikeY = y + cm.strikethroughOffset;
        g2d.draw(new Line2D.Float(x1, strikeY, x2, strikeY));
        g2d.setStroke(savedStroke);
    }

    float ulOffset = cm.underlineOffset;
    float ulThickness = cm.underlineThickness;

    if (stdUnderline != null) {
        stdUnderline.drawUnderline(g2d, ulThickness, x1, x2, y + ulOffset);
    }

    if (imUnderline != null) {
        imUnderline.drawUnderline(g2d, ulThickness, x1, x2, y + ulOffset);
    }
}
 
Example #25
Source File: PlotSettings.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * @return the domainGridlineStroke
 */
public Stroke getDomainGridlineStroke()
{
	return domainGridlineStroke;
}
 
Example #26
Source File: StrategyMapUtils.java    From bamboobsc with Apache License 2.0 4 votes vote down vote up
public static byte[] getBackgroundImage(VisionVO vision, int width, int height) throws Exception {
	byte[] data = null;
	List<PerspectiveVO> perspectivesList = perspectiveService.findForListByVisionOid(vision.getOid());
	
	BufferedImage bi = new BufferedImage(getWidth(width), getHeight(height), BufferedImage.TYPE_INT_RGB);
	Graphics2D g2 = bi.createGraphics();	
	Font font = new Font("", Font.BOLD, 16);
	g2.setFont(font);		
	g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);		
	
	int fontLeft = 3;
	int fontAddY = ONE_HEIGHT; // 150
	int fontNowY = 80;
	int lineAddY = 60;
	
	// 填滿 grid 圖片的底
	BufferedImage bg = ImageIO.read( StrategyMapUtils.class.getClassLoader().getResource(SRC_IMG) );
	for (int y=0; y<height; y+=bg.getHeight()) {
		for (int x=0; x<width; x+=bg.getWidth()) {
			g2.drawImage(bg, x, y, null);
		}
	}
	
	Stroke dashed = new BasicStroke(2, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[]{9}, 0);
	
	for (int i=0; perspectivesList != null && i < perspectivesList.size(); i++) {
		
		PerspectiveVO perspective = perspectivesList.get(i);
		
		if (fontNowY > bi.getHeight()) {
			logger.warn("Perspective item over heigh, no paint it : " + perspective.getName());
			continue;
		}
		if (fontLeft > bi.getWidth()) {
			logger.warn("Perspective item over width, no paint it : " + perspective.getName());
			continue;				
		}
		
		g2.setPaint( new Color(64, 64, 64) );
		g2.drawString(perspective.getName(), fontLeft, fontNowY);
		
		g2.setStroke(dashed);
		g2.drawLine(0, fontNowY+lineAddY, width, fontNowY+lineAddY);
		
		fontNowY = fontNowY + fontAddY;
	}
	ByteArrayOutputStream baos = null;
	try {
		baos = new ByteArrayOutputStream();
		ImageIO.write(bi, "PNG", baos);
		data = baos.toByteArray();
		baos.flush();
	} catch (Exception e) {
		e.printStackTrace();
	} finally {
		baos = null;
	}
	return data;
}
 
Example #27
Source File: ShapeInfo.java    From mil-sym-java with Apache License 2.0 4 votes vote down vote up
public Stroke getStroke()
{
    return stroke;
}
 
Example #28
Source File: XYLineAndShapeRenderer.java    From openstock with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Returns a legend item for the specified series.
 *
 * @param datasetIndex  the dataset index (zero-based).
 * @param series  the series index (zero-based).
 *
 * @return A legend item for the series (possibly {@code null}).
 */
@Override
public LegendItem getLegendItem(int datasetIndex, int series) {
    XYPlot plot = getPlot();
    if (plot == null) {
        return null;
    }

    XYDataset dataset = plot.getDataset(datasetIndex);
    if (dataset == null) {
        return null;
    }

    if (!getItemVisible(series, 0)) {
        return null;
    }
    String label = getLegendItemLabelGenerator().generateLabel(dataset,
            series);
    String description = label;
    String toolTipText = null;
    if (getLegendItemToolTipGenerator() != null) {
        toolTipText = getLegendItemToolTipGenerator().generateLabel(
                dataset, series);
    }
    String urlText = null;
    if (getLegendItemURLGenerator() != null) {
        urlText = getLegendItemURLGenerator().generateLabel(dataset,
                series);
    }
    boolean shapeIsVisible = getItemShapeVisible(series, 0);
    Shape shape = lookupLegendShape(series);
    boolean shapeIsFilled = getItemShapeFilled(series, 0);
    Paint fillPaint = (this.useFillPaint ? lookupSeriesFillPaint(series)
            : lookupSeriesPaint(series));
    boolean shapeOutlineVisible = this.drawOutlines;
    Paint outlinePaint = (this.useOutlinePaint ? lookupSeriesOutlinePaint(
            series) : lookupSeriesPaint(series));
    Stroke outlineStroke = lookupSeriesOutlineStroke(series);
    boolean lineVisible = getItemLineVisible(series, 0);
    Stroke lineStroke = lookupSeriesStroke(series);
    Paint linePaint = lookupSeriesPaint(series);
    LegendItem result = new LegendItem(label, description, toolTipText,
            urlText, shapeIsVisible, shape, shapeIsFilled, fillPaint,
            shapeOutlineVisible, outlinePaint, outlineStroke, lineVisible,
            this.legendLine, lineStroke, linePaint);
    result.setLabelFont(lookupLegendTextFont(series));
    Paint labelPaint = lookupLegendTextPaint(series);
    if (labelPaint != null) {
        result.setLabelPaint(labelPaint);
    }
    result.setSeriesKey(dataset.getSeriesKey(series));
    result.setSeriesIndex(series);
    result.setDataset(dataset);
    result.setDatasetIndex(datasetIndex);

    return result;
}
 
Example #29
Source File: GroupGraphics.java    From sambox with Apache License 2.0 4 votes vote down vote up
@Override
public Stroke getStroke()
{
    return groupG2D.getStroke();
}
 
Example #30
Source File: PiePlot.java    From openstock with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Returns a collection of legend items for the pie chart.
 *
 * @return The legend items (never <code>null</code>).
 */
@Override
public LegendItemCollection getLegendItems() {

    LegendItemCollection result = new LegendItemCollection();
    if (this.dataset == null) {
        return result;
    }
    List keys = this.dataset.getKeys();
    int section = 0;
    Shape shape = getLegendItemShape();
    Iterator iterator = keys.iterator();
    while (iterator.hasNext()) {
        Comparable key = (Comparable) iterator.next();
        Number n = this.dataset.getValue(key);
        boolean include;
        if (n == null) {
            include = !this.ignoreNullValues;
        }
        else {
            double v = n.doubleValue();
            if (v == 0.0) {
                include = !this.ignoreZeroValues;
            }
            else {
                include = v > 0.0;
            }
        }
        if (include) {
            String label = this.legendLabelGenerator.generateSectionLabel(
                    this.dataset, key);
            if (label != null) {
                String description = label;
                String toolTipText = null;
                if (this.legendLabelToolTipGenerator != null) {
                    toolTipText = this.legendLabelToolTipGenerator
                            .generateSectionLabel(this.dataset, key);
                }
                String urlText = null;
                if (this.legendLabelURLGenerator != null) {
                    urlText = this.legendLabelURLGenerator.generateURL(
                            this.dataset, key, this.pieIndex);
                }
                Paint paint = lookupSectionPaint(key);
                Paint outlinePaint = lookupSectionOutlinePaint(key);
                Stroke outlineStroke = lookupSectionOutlineStroke(key);
                LegendItem item = new LegendItem(label, description,
                        toolTipText, urlText, true, shape, true, paint,
                        true, outlinePaint, outlineStroke,
                        false,          // line not visible
                        new Line2D.Float(), new BasicStroke(), Color.black);
                item.setDataset(getDataset());
                item.setSeriesIndex(this.dataset.getIndex(key));
                item.setSeriesKey(key);
                result.add(item);
            }
            section++;
        }
        else {
            section++;
        }
    }
    return result;
}