java.awt.Graphics2D#setPaint ( )源码实例Demo

下面列出了java.awt.Graphics2D#setPaint ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: pumpernickel   文件: TextBlock.java
protected void paintBackground(Graphics2D g, GeneralPath bodyOutline) {
	Paint background = getBackground();
	if (background != null) {

		if (isShadowActive()) {
			Graphics2D g2 = (Graphics2D) g.create();
			double dy = 0;
			Stroke stroke = getStroke();
			if (stroke != null) {
				dy = (ShapeBounds.getBounds(
						stroke.createStrokedShape(bodyOutline)).getHeight() - ShapeBounds
						.getBounds(bodyOutline).getHeight()) / 2;
			}
			g2.translate(0, dy);
			g2.setColor(getBackgroundShadowColor());
			g2.translate(0, 1);
			g2.fill(bodyOutline);
			g2.translate(0, 1);
			g2.fill(bodyOutline);
			g2.dispose();
		}

		g.setPaint(background);
		g.fill(bodyOutline);
	}
}
 
/**
 * Draws a line perpendicular to 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.
 * @param paint  the paint (<code>null</code> not permitted).
 * @param stroke  the stroke (<code>null</code> not permitted).
 *
 * @see #drawRangeGridline
 *
 * @since 1.0.13
 */
public void drawRangeLine(Graphics2D g2, CategoryPlot plot, ValueAxis axis,
        Rectangle2D dataArea, double value, Paint paint, Stroke stroke) {

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

    PlotOrientation orientation = plot.getOrientation();
    Line2D line = null;
    double v = axis.valueToJava2D(value, dataArea, plot.getRangeAxisEdge());
    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);
    }

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

}
 
源代码3 项目: opensim-gui   文件: CategoryPlot.java
/**
 * 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.
 * @param paint  the line paint.
 */
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);

}
 
源代码4 项目: seaglass   文件: ComboBoxArrowButtonPainter.java
/**
 * Paint the arrows (both up and down, or left and right).
 *
 * @param g      the Graphics2D context to paint with.
 * @param c      the component to paint.
 * @param width  the width.
 * @param height the height.
 */
private void paintArrows(Graphics2D g, JComponent c, int width, int height) {
    int xOffset = width / 2 - 5;
    int yOffset = height / 2 - 3;

    g.translate(xOffset, yOffset);

    Shape s = shapeGenerator.createArrowLeft(0.5, 0.5, 3, 4);

    g.setPaint(getCommonArrowPaint(s, type));
    g.fill(s);

    s = shapeGenerator.createArrowRight(6.5, 0.5, 3, 4);
    g.setPaint(getCommonArrowPaint(s, type));
    g.fill(s);

    g.translate(-xOffset, -yOffset);
}
 
源代码5 项目: iBioSim   文件: SchemeChooserPanel.java
/**
 * draw the gradient for whichever item in the list
 */
@Override
public void paintComponent(Graphics g) {
	
	Color endColor;
	
	if (name.equals("none"))
		endColor = colorsArray[0];
	else 
		endColor = startColor;
	
	setOpaque(false);
       Graphics2D g2d = (Graphics2D) g;
       Paint oldPaint = g2d.getPaint();
       Paint newPaint = new GradientPaint(0, 0, gradientColor, getWidth(), 0, endColor, false);
       g2d.setPaint(newPaint);
       g2d.fillRect(0,0,getWidth(),getHeight());
       g2d.setPaint(oldPaint);
       super.paintComponent(g);
}
 
源代码6 项目: coming   文件: Arja_0062_t.java
/**
 * Draws an item label.
 *
 * @param g2  the graphics device.
 * @param orientation  the orientation.
 * @param dataset  the dataset.
 * @param row  the row.
 * @param column  the column.
 * @param selected  is the item selected?
 * @param x  the x coordinate (in Java2D space).
 * @param y  the y coordinate (in Java2D space).
 * @param negative  indicates a negative value (which affects the item
 *                  label position).
 *
 * @since 1.2.0
 */
protected void drawItemLabel(Graphics2D g2, PlotOrientation orientation,
        CategoryDataset dataset, int row, int column, boolean selected,
        double x, double y, boolean negative) {

    CategoryItemLabelGenerator generator = getItemLabelGenerator(row,
            column, selected);
    if (generator != null) {
        Font labelFont = getItemLabelFont(row, column, selected);
        Paint paint = getItemLabelPaint(row, column, selected);
        g2.setFont(labelFont);
        g2.setPaint(paint);
        String label = generator.generateLabel(dataset, row, column);
        ItemLabelPosition position = null;
        if (!negative) {
            position = getPositiveItemLabelPosition(row, column, selected);
        }
        else {
            position = getNegativeItemLabelPosition(row, column, selected);
        }
        Point2D anchorPoint = calculateLabelAnchorPoint(
                position.getItemLabelAnchor(), x, y, orientation);
        TextUtilities.drawRotatedString(label, g2,
                (float) anchorPoint.getX(), (float) anchorPoint.getY(),
                position.getTextAnchor(),
                position.getAngle(), position.getRotationAnchor());
    }

}
 
源代码7 项目: coming   文件: Arja_0062_s.java
/**
 * 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);

}
 
源代码8 项目: seaglass   文件: ScrollPanePainter.java
private void paintBackground(Graphics2D g, JComponent c, int width, int height) {
    JViewport viewport = ((JScrollPane)c).getViewport();
    if (viewport.isOpaque()) {
        Shape s = shapeGenerator.createRoundRectangle(0, 0, width - 1, height - 1, CornerSize.BORDER);
        g.setPaint(viewport.getBackground());
        g.fill(s);
    }
}
 
源代码9 项目: buffer_bci   文件: SymbolAxis.java
/**
 * Draws the grid bands for an axis that is aligned to the left or
 * right of the data area (that is, a vertical axis).
 *
 * @param g2  the graphics target (<code>null</code> not permitted).
 * @param plotArea  the area within which the plot is drawn (not used here).
 * @param dataArea  the area for the data (to which the axes are aligned,
 *     <code>null</code> not permitted).
 * @param firstGridBandIsDark  True: the first grid band takes the
 *                             color of <CODE>gridBandPaint</CODE>.
 *                             False: the second grid band takes the
 *                             color of <CODE>gridBandPaint</CODE>.
 * @param ticks  a list of ticks (<code>null</code> not permitted).
 */
protected void drawGridBandsVertical(Graphics2D g2, Rectangle2D plotArea,
        Rectangle2D dataArea, boolean firstGridBandIsDark, 
        List ticks) {

    boolean currentGridBandIsDark = firstGridBandIsDark;
    double xx = dataArea.getX();
    double yy1, yy2;

    //gets the outline stroke width of the plot
    double outlineStrokeWidth = 1.0;
    Stroke outlineStroke = getPlot().getOutlineStroke();
    if (outlineStroke != null && outlineStroke instanceof BasicStroke) {
        outlineStrokeWidth = ((BasicStroke) outlineStroke).getLineWidth();
    }

    Iterator iterator = ticks.iterator();
    ValueTick tick;
    Rectangle2D band;
    while (iterator.hasNext()) {
        tick = (ValueTick) iterator.next();
        yy1 = valueToJava2D(tick.getValue() + 0.5d, dataArea,
                RectangleEdge.LEFT);
        yy2 = valueToJava2D(tick.getValue() - 0.5d, dataArea,
                RectangleEdge.LEFT);
        if (currentGridBandIsDark) {
            g2.setPaint(this.gridBandPaint);
        }
        else {
            g2.setPaint(this.gridBandAlternatePaint);
        }
        band = new Rectangle2D.Double(xx + outlineStrokeWidth, 
                Math.min(yy1, yy2), dataArea.getMaxX() - xx 
                - outlineStrokeWidth, Math.abs(yy2 - yy1));
        g2.fill(band);
        currentGridBandIsDark = !currentGridBandIsDark;
    }
}
 
源代码10 项目: SIMVA-SoS   文件: AbstractXYItemRenderer.java
/**
 * 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.
 */
@Override
public void drawDomainGridLine(Graphics2D g2, XYPlot 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.getDomainAxisEdge());
    Line2D line = null;
    if (orientation == PlotOrientation.HORIZONTAL) {
        line = new Line2D.Double(dataArea.getMinX(), v,
                dataArea.getMaxX(), v);
    }
    else if (orientation == PlotOrientation.VERTICAL) {
        line = new Line2D.Double(v, dataArea.getMinY(), v,
                dataArea.getMaxY());
    }

    Paint paint = plot.getDomainGridlinePaint();
    Stroke stroke = plot.getDomainGridlineStroke();
    g2.setPaint(paint != null ? paint : Plot.DEFAULT_OUTLINE_PAINT);
    g2.setStroke(stroke != null ? stroke : Plot.DEFAULT_OUTLINE_STROKE);
    Object saved = g2.getRenderingHint(RenderingHints.KEY_STROKE_CONTROL);
    g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, 
            RenderingHints.VALUE_STROKE_NORMALIZE);
    g2.draw(line);
    g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, saved);
}
 
源代码11 项目: ECG-Viewer   文件: Plot.java
/**
 * Draws the plot outline.  This method will be called during the chart
 * drawing process and is declared public so that it can be accessed by the
 * renderers used by certain subclasses. You shouldn't need to call this
 * method directly.
 *
 * @param g2  the graphics device.
 * @param area  the area within which the plot should be drawn.
 */
public void drawOutline(Graphics2D g2, Rectangle2D area) {
    if (!this.outlineVisible) {
        return;
    }
    if ((this.outlineStroke != null) && (this.outlinePaint != null)) {
        g2.setStroke(this.outlineStroke);
        g2.setPaint(this.outlinePaint);
        Object saved = g2.getRenderingHint(RenderingHints.KEY_STROKE_CONTROL);
        g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);
        g2.draw(area);
        g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, saved);
    }
}
 
源代码12 项目: ccu-historian   文件: PiePlot.java
/**
 * Draws a section label on the right side of the pie chart.
 *
 * @param g2  the graphics device.
 * @param state  the state.
 * @param record  the label record.
 */
protected void drawRightLabel(Graphics2D g2, PiePlotState state,
                              PieLabelRecord record) {

    double anchorX = state.getLinkArea().getMaxX();
    double targetX = anchorX + record.getGap();
    double targetY = record.getAllocatedY();

    if (this.labelLinksVisible) {
        double theta = record.getAngle();
        double linkX = state.getPieCenterX() + Math.cos(theta)
                * state.getPieWRadius() * record.getLinkPercent();
        double linkY = state.getPieCenterY() - Math.sin(theta)
                * state.getPieHRadius() * record.getLinkPercent();
        double elbowX = state.getPieCenterX() + Math.cos(theta)
                * state.getLinkArea().getWidth() / 2.0;
        double elbowY = state.getPieCenterY() - Math.sin(theta)
                * state.getLinkArea().getHeight() / 2.0;
        double anchorY = elbowY;
        g2.setPaint(this.labelLinkPaint);
        g2.setStroke(this.labelLinkStroke);
        PieLabelLinkStyle style = getLabelLinkStyle();
        if (style.equals(PieLabelLinkStyle.STANDARD)) {
            g2.draw(new Line2D.Double(linkX, linkY, elbowX, elbowY));
            g2.draw(new Line2D.Double(anchorX, anchorY, elbowX, elbowY));
            g2.draw(new Line2D.Double(anchorX, anchorY, targetX, targetY));
        }
        else if (style.equals(PieLabelLinkStyle.QUAD_CURVE)) {
            QuadCurve2D q = new QuadCurve2D.Float();
            q.setCurve(targetX, targetY, anchorX, anchorY, elbowX, elbowY);
            g2.draw(q);
            g2.draw(new Line2D.Double(elbowX, elbowY, linkX, linkY));
        }
        else if (style.equals(PieLabelLinkStyle.CUBIC_CURVE)) {
            CubicCurve2D c = new CubicCurve2D .Float();
            c.setCurve(targetX, targetY, anchorX, anchorY, elbowX, elbowY,
                    linkX, linkY);
            g2.draw(c);
        }
    }

    TextBox tb = record.getLabel();
    tb.draw(g2, (float) targetX, (float) targetY, RectangleAnchor.LEFT);

}
 
/**
 * Draws a marker for the domain axis.
 *
 * @param g2  the graphics device (not <code>null</code>).
 * @param plot  the plot (not <code>null</code>).
 * @param axis  the range axis (not <code>null</code>).
 * @param marker  the marker to be drawn (not <code>null</code>).
 * @param dataArea  the area inside the axes (not <code>null</code>).
 *
 * @see #drawRangeMarker(Graphics2D, CategoryPlot, ValueAxis, Marker,
 *     Rectangle2D)
 */
public void drawDomainMarker(Graphics2D g2,
                             CategoryPlot plot,
                             CategoryAxis axis,
                             CategoryMarker marker,
                             Rectangle2D dataArea) {

    Comparable category = marker.getKey();
    CategoryDataset dataset = plot.getDataset(plot.getIndexOf(this));
    int columnIndex = dataset.getColumnIndex(category);
    if (columnIndex < 0) {
        return;
    }

    final Composite savedComposite = g2.getComposite();
    g2.setComposite(AlphaComposite.getInstance(
            AlphaComposite.SRC_OVER, marker.getAlpha()));

    PlotOrientation orientation = plot.getOrientation();
    Rectangle2D bounds = null;
    if (marker.getDrawAsLine()) {
        double v = axis.getCategoryMiddle(columnIndex,
                dataset.getColumnCount(), dataArea,
                plot.getDomainAxisEdge());
        Line2D line = null;
        if (orientation == PlotOrientation.HORIZONTAL) {
            line = new Line2D.Double(dataArea.getMinX(), v,
                    dataArea.getMaxX(), v);
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            line = new Line2D.Double(v, dataArea.getMinY(), v,
                    dataArea.getMaxY());
        }
        g2.setPaint(marker.getPaint());
        g2.setStroke(marker.getStroke());
        g2.draw(line);
        bounds = line.getBounds2D();
    }
    else {
        double v0 = axis.getCategoryStart(columnIndex,
                dataset.getColumnCount(), dataArea,
                plot.getDomainAxisEdge());
        double v1 = axis.getCategoryEnd(columnIndex,
                dataset.getColumnCount(), dataArea,
                plot.getDomainAxisEdge());
        Rectangle2D area = null;
        if (orientation == PlotOrientation.HORIZONTAL) {
            area = new Rectangle2D.Double(dataArea.getMinX(), v0,
                    dataArea.getWidth(), (v1 - v0));
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            area = new Rectangle2D.Double(v0, dataArea.getMinY(),
                    (v1 - v0), dataArea.getHeight());
        }
        g2.setPaint(marker.getPaint());
        g2.fill(area);
        bounds = area;
    }

    String label = marker.getLabel();
    RectangleAnchor anchor = marker.getLabelAnchor();
    if (label != null) {
        Font labelFont = marker.getLabelFont();
        g2.setFont(labelFont);
        g2.setPaint(marker.getLabelPaint());
        Point2D coordinates = calculateDomainMarkerTextAnchorPoint(
                g2, orientation, dataArea, bounds, marker.getLabelOffset(),
                marker.getLabelOffsetType(), anchor);
        TextUtilities.drawAlignedString(label, g2,
                (float) coordinates.getX(), (float) coordinates.getY(),
                marker.getLabelTextAnchor());
    }
    g2.setComposite(savedComposite);
}
 
源代码14 项目: ECG-Viewer   文件: XYBlockRenderer.java
/**
 * Draws the block representing the specified item.
 *
 * @param g2  the graphics device.
 * @param state  the state.
 * @param dataArea  the data area.
 * @param info  the plot rendering info.
 * @param plot  the plot.
 * @param domainAxis  the x-axis.
 * @param rangeAxis  the y-axis.
 * @param dataset  the dataset.
 * @param series  the series index.
 * @param item  the item index.
 * @param crosshairState  the crosshair state.
 * @param pass  the pass index.
 */
@Override
public void drawItem(Graphics2D g2, XYItemRendererState state,
        Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot,
        ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset,
        int series, int item, CrosshairState crosshairState, int pass) {

    double x = dataset.getXValue(series, item);
    double y = dataset.getYValue(series, item);
    double z = 0.0;
    if (dataset instanceof XYZDataset) {
        z = ((XYZDataset) dataset).getZValue(series, item);
    }
    Paint p = this.paintScale.getPaint(z);
    double xx0 = domainAxis.valueToJava2D(x + this.xOffset, dataArea,
            plot.getDomainAxisEdge());
    double yy0 = rangeAxis.valueToJava2D(y + this.yOffset, dataArea,
            plot.getRangeAxisEdge());
    double xx1 = domainAxis.valueToJava2D(x + this.blockWidth
            + this.xOffset, dataArea, plot.getDomainAxisEdge());
    double yy1 = rangeAxis.valueToJava2D(y + this.blockHeight
            + this.yOffset, dataArea, plot.getRangeAxisEdge());
    Rectangle2D block;
    PlotOrientation orientation = plot.getOrientation();
    if (orientation.equals(PlotOrientation.HORIZONTAL)) {
        block = new Rectangle2D.Double(Math.min(yy0, yy1),
                Math.min(xx0, xx1), Math.abs(yy1 - yy0),
                Math.abs(xx0 - xx1));
    }
    else {
        block = new Rectangle2D.Double(Math.min(xx0, xx1),
                Math.min(yy0, yy1), Math.abs(xx1 - xx0),
                Math.abs(yy1 - yy0));
    }
    g2.setPaint(p);
    g2.fill(block);
    g2.setStroke(new BasicStroke(1.0f));
    g2.draw(block);

    EntityCollection entities = state.getEntityCollection();
    if (entities != null) {
        addEntity(entities, block, dataset, series, item, 0.0, 0.0);
    }

}
 
源代码15 项目: astor   文件: BarRenderer.java
/**
 * Draws an item label.  This method is used for bars instead of
 * {@link #drawItemLabel()} so that the bar can be used to calculate the
 * label anchor point.
 *
 * @param g2  the graphics device.
 * @param dataset  the dataset.
 * @param row  the row.
 * @param column  the column.
 * @param selected  is the item selected?
 * @param plot  the plot.
 * @param generator  the label generator.
 * @param bar  the bar.
 * @param negative  a flag indicating a negative value.
 *
 * @since 1.2.0
 */
protected void drawItemLabelForBar(Graphics2D g2, CategoryPlot plot,
        CategoryDataset dataset, int row, int column, boolean selected,
        CategoryItemLabelGenerator generator, Rectangle2D bar,
        boolean negative) {

    String label = generator.generateLabel(dataset, row, column);
    if (label == null) {
        return;  // nothing to do
    }

    Font labelFont = getItemLabelFont(row, column, selected);
    g2.setFont(labelFont);
    Paint paint = getItemLabelPaint(row, column, selected);
    g2.setPaint(paint);

    // find out where to place the label...
    ItemLabelPosition position = null;
    if (!negative) {
        position = getPositiveItemLabelPosition(row, column, selected);
    }
    else {
        position = getNegativeItemLabelPosition(row, column, selected);
    }

    // work out the label anchor point...
    Point2D anchorPoint = calculateLabelAnchorPoint(
            position.getItemLabelAnchor(), bar, plot.getOrientation());

    if (isInternalAnchor(position.getItemLabelAnchor())) {
        Shape bounds = TextUtilities.calculateRotatedStringBounds(label,
                g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(),
                position.getTextAnchor(), position.getAngle(),
                position.getRotationAnchor());

        if (bounds != null) {
            if (!bar.contains(bounds.getBounds2D())) {
                if (!negative) {
                    position = getPositiveItemLabelPositionFallback();
                }
                else {
                    position = getNegativeItemLabelPositionFallback();
                }
                if (position != null) {
                    anchorPoint = calculateLabelAnchorPoint(
                            position.getItemLabelAnchor(), bar,
                            plot.getOrientation());
                }
            }
        }

    }

    if (position != null) {
        TextUtilities.drawRotatedString(label, g2,
                (float) anchorPoint.getX(), (float) anchorPoint.getY(),
                position.getTextAnchor(), position.getAngle(),
                position.getRotationAnchor());
    }
}
 
源代码16 项目: astor   文件: PeriodAxis.java
/**
 * Draws the major and minor tick marks for an axis that lies at the top or 
 * bottom of the plot.
 * 
 * @param g2  the graphics device.
 * @param state  the axis state.
 * @param dataArea  the data area.
 * @param edge  the edge.
 */
protected void drawTickMarksHorizontal(Graphics2D g2, AxisState state, 
                                       Rectangle2D dataArea, 
                                       RectangleEdge edge) {
    List ticks = new ArrayList();
    double x0 = dataArea.getX();
    double y0 = state.getCursor();
    double insideLength = getTickMarkInsideLength();
    double outsideLength = getTickMarkOutsideLength();
    RegularTimePeriod t = RegularTimePeriod.createInstance(
            this.majorTickTimePeriodClass, this.first.getStart(), 
            getTimeZone());
    long t0 = t.getFirstMillisecond(this.calendar);
    Line2D inside = null;
    Line2D outside = null;
    long firstOnAxis = getFirst().getFirstMillisecond(this.calendar);
    long lastOnAxis = getLast().getLastMillisecond(this.calendar);
    while (t0 <= lastOnAxis) {
        ticks.add(new NumberTick(new Double(t0), "", TextAnchor.CENTER, 
                TextAnchor.CENTER, 0.0));
        x0 = valueToJava2D(t0, dataArea, edge);
        if (edge == RectangleEdge.TOP) {
            inside = new Line2D.Double(x0, y0, x0, y0 + insideLength);  
            outside = new Line2D.Double(x0, y0, x0, y0 - outsideLength);
        }
        else if (edge == RectangleEdge.BOTTOM) {
            inside = new Line2D.Double(x0, y0, x0, y0 - insideLength);
            outside = new Line2D.Double(x0, y0, x0, y0 + outsideLength);
        }
        if (t0 > firstOnAxis) {
            g2.setPaint(getTickMarkPaint());
            g2.setStroke(getTickMarkStroke());
            g2.draw(inside);
            g2.draw(outside);
        }
        // draw minor tick marks
        if (this.minorTickMarksVisible) {
            RegularTimePeriod tminor = RegularTimePeriod.createInstance(
                    this.minorTickTimePeriodClass, new Date(t0), 
                    getTimeZone());
            long tt0 = tminor.getFirstMillisecond(this.calendar);
            while (tt0 < t.getLastMillisecond(this.calendar) 
                    && tt0 < lastOnAxis) {
                double xx0 = valueToJava2D(tt0, dataArea, edge);
                if (edge == RectangleEdge.TOP) {
                    inside = new Line2D.Double(xx0, y0, xx0, 
                            y0 + this.minorTickMarkInsideLength);
                    outside = new Line2D.Double(xx0, y0, xx0, 
                            y0 - this.minorTickMarkOutsideLength);
                }
                else if (edge == RectangleEdge.BOTTOM) {
                    inside = new Line2D.Double(xx0, y0, xx0, 
                            y0 - this.minorTickMarkInsideLength);
                    outside = new Line2D.Double(xx0, y0, xx0, 
                            y0 + this.minorTickMarkOutsideLength);
                }
                if (tt0 >= firstOnAxis) {
                    g2.setPaint(this.minorTickMarkPaint);
                    g2.setStroke(this.minorTickMarkStroke);
                    g2.draw(inside);
                    g2.draw(outside);
                }
                tminor = tminor.next();
                tt0 = tminor.getFirstMillisecond(this.calendar);
            }
        }            
        t = t.next();
        t0 = t.getFirstMillisecond(this.calendar);
    }
    if (edge == RectangleEdge.TOP) {
        state.cursorUp(Math.max(outsideLength, 
                this.minorTickMarkOutsideLength));
    }
    else if (edge == RectangleEdge.BOTTOM) {
        state.cursorDown(Math.max(outsideLength, 
                this.minorTickMarkOutsideLength));
    }
    state.setTicks(ticks);
}
 
源代码17 项目: openstock   文件: VectorRenderer.java
/**
 * Draws the block representing the specified item.
 *
 * @param g2  the graphics device.
 * @param state  the state.
 * @param dataArea  the data area.
 * @param info  the plot rendering info.
 * @param plot  the plot.
 * @param domainAxis  the x-axis.
 * @param rangeAxis  the y-axis.
 * @param dataset  the dataset.
 * @param series  the series index.
 * @param item  the item index.
 * @param crosshairState  the crosshair state.
 * @param pass  the pass index.
 */
@Override
public void drawItem(Graphics2D g2, XYItemRendererState state,
        Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot,
        ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset,
        int series, int item, CrosshairState crosshairState, int pass) {

    double x = dataset.getXValue(series, item);
    double y = dataset.getYValue(series, item);
    double dx = 0.0;
    double dy = 0.0;
    if (dataset instanceof VectorXYDataset) {
        dx = ((VectorXYDataset) dataset).getVectorXValue(series, item);
        dy = ((VectorXYDataset) dataset).getVectorYValue(series, item);
    }
    double xx0 = domainAxis.valueToJava2D(x, dataArea,
            plot.getDomainAxisEdge());
    double yy0 = rangeAxis.valueToJava2D(y, dataArea,
            plot.getRangeAxisEdge());
    double xx1 = domainAxis.valueToJava2D(x + dx, dataArea,
            plot.getDomainAxisEdge());
    double yy1 = rangeAxis.valueToJava2D(y + dy, dataArea,
            plot.getRangeAxisEdge());
    Line2D line;
    PlotOrientation orientation = plot.getOrientation();
    if (orientation.equals(PlotOrientation.HORIZONTAL)) {
        line = new Line2D.Double(yy0, xx0, yy1, xx1);
    }
    else {
        line = new Line2D.Double(xx0, yy0, xx1, yy1);
    }
    g2.setPaint(getItemPaint(series, item));
    g2.setStroke(getItemStroke(series, item));
    g2.draw(line);

    // calculate the arrow head and draw it...
    double dxx = (xx1 - xx0);
    double dyy = (yy1 - yy0);
    double bx = xx0 + (1.0 - this.baseLength) * dxx;
    double by = yy0 + (1.0 - this.baseLength) * dyy;

    double cx = xx0 + (1.0 - this.headLength) * dxx;
    double cy = yy0 + (1.0 - this.headLength) * dyy;

    double angle = 0.0;
    if (dxx != 0.0) {
        angle = Math.PI / 2.0 - Math.atan(dyy / dxx);
    }
    double deltaX = 2.0 * Math.cos(angle);
    double deltaY = 2.0 * Math.sin(angle);

    double leftx = cx + deltaX;
    double lefty = cy - deltaY;
    double rightx = cx - deltaX;
    double righty = cy + deltaY;

    GeneralPath p = new GeneralPath();
    if (orientation == PlotOrientation.VERTICAL) {
        p.moveTo((float) xx1, (float) yy1);
        p.lineTo((float) rightx, (float) righty);
        p.lineTo((float) bx, (float) by);
        p.lineTo((float) leftx, (float) lefty);
    }
    else {  // orientation is HORIZONTAL
        p.moveTo((float) yy1, (float) xx1);
        p.lineTo((float) righty, (float) rightx);
        p.lineTo((float) by, (float) bx);
        p.lineTo((float) lefty, (float) leftx);
    }
    p.closePath();
    g2.draw(p);

    // setup for collecting optional entity info...
    EntityCollection entities;
    if (info != null) {
        entities = info.getOwner().getEntityCollection();
        if (entities != null) {
            addEntity(entities, line.getBounds(), dataset, series, item,
                    0.0, 0.0);
        }
    }

}
 
源代码18 项目: ECG-Viewer   文件: CategoryStepRenderer.java
/**
 * Draw a single data item.
 *
 * @param g2  the graphics device.
 * @param state  the renderer state.
 * @param dataArea  the area in which the data is drawn.
 * @param plot  the plot.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param dataset  the dataset.
 * @param row  the row index (zero-based).
 * @param column  the column index (zero-based).
 * @param pass  the pass index.
 */
@Override
public void drawItem(Graphics2D g2, CategoryItemRendererState state,
        Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis,
        ValueAxis rangeAxis, CategoryDataset dataset, int row,
        int column, int pass) {

    // do nothing if item is not visible
    if (!getItemVisible(row, column)) {
        return;
    }

    Number value = dataset.getValue(row, column);
    if (value == null) {
        return;
    }
    PlotOrientation orientation = plot.getOrientation();

    // current data point...
    double x1s = domainAxis.getCategoryStart(column, getColumnCount(),
            dataArea, plot.getDomainAxisEdge());
    double x1 = domainAxis.getCategoryMiddle(column, getColumnCount(),
            dataArea, plot.getDomainAxisEdge());
    double x1e = 2 * x1 - x1s; // or: x1s + 2*(x1-x1s)
    double y1 = rangeAxis.valueToJava2D(value.doubleValue(), dataArea,
            plot.getRangeAxisEdge());
    g2.setPaint(getItemPaint(row, column));
    g2.setStroke(getItemStroke(row, column));

    if (column != 0) {
        Number previousValue = dataset.getValue(row, column - 1);
        if (previousValue != null) {
            // previous data point...
            double previous = previousValue.doubleValue();
            double x0s = domainAxis.getCategoryStart(column - 1,
                    getColumnCount(), dataArea, plot.getDomainAxisEdge());
            double x0 = domainAxis.getCategoryMiddle(column - 1,
                    getColumnCount(), dataArea, plot.getDomainAxisEdge());
            double x0e = 2 * x0 - x0s; // or: x0s + 2*(x0-x0s)
            double y0 = rangeAxis.valueToJava2D(previous, dataArea,
                    plot.getRangeAxisEdge());
            if (getStagger()) {
                int xStagger = row * STAGGER_WIDTH;
                if (xStagger > (x1s - x0e)) {
                    xStagger = (int) (x1s - x0e);
                }
                x1s = x0e + xStagger;
            }
            drawLine(g2, (State) state, orientation, x0e, y0, x1s, y0);
            // extend x0's flat bar

            drawLine(g2, (State) state, orientation, x1s, y0, x1s, y1);
            // upright bar
       }
   }
   drawLine(g2, (State) state, orientation, x1s, y1, x1e, y1);
   // x1's flat bar

   // draw the item labels if there are any...
   if (isItemLabelVisible(row, column)) {
        drawItemLabel(g2, orientation, dataset, row, column, x1, y1,
                (value.doubleValue() < 0.0));
   }

   // add an item entity, if this information is being collected
   EntityCollection entities = state.getEntityCollection();
   if (entities != null) {
       Rectangle2D hotspot = new Rectangle2D.Double();
       if (orientation == PlotOrientation.VERTICAL) {
           hotspot.setRect(x1s, y1, x1e - x1s, 4.0);
       }
       else {
           hotspot.setRect(y1 - 2.0, x1s, 4.0, x1e - x1s);
       }
       addItemEntity(entities, dataset, row, column, hotspot);
   }

}
 
源代码19 项目: ccu-historian   文件: LineBorder.java
/**
 * Draws the border by filling in the reserved space (in black).
 *
 * @param g2  the graphics device.
 * @param area  the area.
 */
@Override
public void draw(Graphics2D g2, Rectangle2D area) {
    double w = area.getWidth();
    double h = area.getHeight();
    // if the area has zero height or width, we shouldn't draw anything
    if (w <= 0.0 || h <= 0.0) {
        return;
    }
    double t = this.insets.calculateTopInset(h);
    double b = this.insets.calculateBottomInset(h);
    double l = this.insets.calculateLeftInset(w);
    double r = this.insets.calculateRightInset(w);
    double x = area.getX();
    double y = area.getY();
    double x0 = x + l / 2.0;
    double x1 = x + w - r / 2.0;
    double y0 = y + h - b / 2.0;
    double y1 = y + t / 2.0;
    g2.setPaint(getPaint());
    g2.setStroke(getStroke());
    Object saved = g2.getRenderingHint(RenderingHints.KEY_STROKE_CONTROL);
    g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, 
            RenderingHints.VALUE_STROKE_NORMALIZE);
    Line2D line = new Line2D.Double();
    if (t > 0.0) {
        line.setLine(x0, y1, x1, y1);
        g2.draw(line);
    }
    if (b > 0.0) {
        line.setLine(x0, y0, x1, y0);
        g2.draw(line);
    }
    if (l > 0.0) {
        line.setLine(x0, y0, x0, y1);
        g2.draw(line);
    }
    if (r > 0.0) {
        line.setLine(x1, y0, x1, y1);
        g2.draw(line);
    }
    g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, saved);
}
 
源代码20 项目: freecol   文件: ImageLibrary.java
/**
 * Fills a certain rectangle with the image texture.
 * 
 * @param g2 The {@code Graphics} used for painting the border.
 * @param img The {@code BufferedImage} to fill the texture.
 * @param x The x-component of the offset.
 * @param y The y-component of the offset.
 * @param width The width of the rectangle.
 * @param height The height of the rectangle.
 */
public static void fillTexture(Graphics2D g2, BufferedImage img,
                               int x, int y, int width, int height) {
    Rectangle anchor = new Rectangle(
        x, y, img.getWidth(), img.getHeight());
    TexturePaint paint = new TexturePaint(img, anchor);
    g2.setPaint(paint);
    g2.fillRect(x, y, width, height);
}