当前位置: 首页>>代码示例>>Java>>正文


Java Graphics2D.setPaint方法代码示例

本文整理汇总了Java中java.awt.Graphics2D.setPaint方法的典型用法代码示例。如果您正苦于以下问题:Java Graphics2D.setPaint方法的具体用法?Java Graphics2D.setPaint怎么用?Java Graphics2D.setPaint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.awt.Graphics2D的用法示例。


在下文中一共展示了Graphics2D.setPaint方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createTestImage

import java.awt.Graphics2D; //导入方法依赖的package包/类
private static BufferedImage createTestImage() {
    int w = 1024;
    int h = 768;

    BufferedImage img = new
        BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
    Graphics2D g = img.createGraphics();
    Color[] colors = { Color.red, Color.green, Color.blue };
    float[] dist = {0.0f, 0.5f, 1.0f };
    Point2D center = new Point2D.Float(0.5f * w, 0.5f * h);

    RadialGradientPaint p =
        new RadialGradientPaint(center, 0.5f * w, dist, colors);
    g.setPaint(p);
    g.fillRect(0, 0, w, h);
    g.dispose();

    return img;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:20,代码来源:WritingInterruptionTest.java

示例2: createSrcImage

import java.awt.Graphics2D; //导入方法依赖的package包/类
private static BufferedImage createSrcImage() {
    BufferedImage img = createImage();

    Graphics2D g = img.createGraphics();
    Color[] colors = { Color.red, Color.green, Color.blue };
    float[] dist = {0.0f, 0.5f, 1.0f };
    Point2D center = new Point2D.Float(0.5f * w, 0.5f * h);

    RadialGradientPaint p =
            new RadialGradientPaint(center, 0.5f * w, dist, colors);
    g.setPaint(p);
    g.fillRect(0, 0, w, h);
    g.dispose();

    return img;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:17,代码来源:MlibOpsTest.java

示例3: paint

import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
public void paint(Graphics g) {
    super.paint(g);
    RenderingHints renderHints
            = new RenderingHints(RenderingHints.KEY_ANTIALIASING,
                    RenderingHints.VALUE_ANTIALIAS_ON);
    renderHints.put(RenderingHints.KEY_RENDERING,
            RenderingHints.VALUE_RENDER_QUALITY);

    renderHints.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

    Graphics2D Canvas = (Graphics2D) g;

    Canvas.addRenderingHints(renderHints);

    Canvas.setStroke(new BasicStroke(
            1f,
            BasicStroke.CAP_ROUND,
            BasicStroke.JOIN_ROUND));

    Canvas.setPaint(Color.BLACK);

    paint2D(Canvas);
}
 
开发者ID:chcandido,项目名称:brModelo,代码行数:25,代码来源:InspectorItemBase.java

示例4: draw

import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
 * Draws the frame.
 * 
 * @param g2  the graphics target.
 * @param plot  the plot.
 * @param frame  the dial's reference frame.
 * @param view  the dial's view rectangle.
 */
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, 
        Rectangle2D view) {
    
    Shape window = getWindow(frame);
    Shape outerWindow = getOuterWindow(frame);

    Area area1 = new Area(outerWindow);
    Area area2 = new Area(window);
    area1.subtract(area2);
    g2.setPaint(Color.lightGray);
    g2.fill(area1);
    
    g2.setStroke(this.stroke);
    g2.setPaint(this.foregroundPaint);
    g2.draw(window);
    g2.draw(outerWindow);
    
    
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:28,代码来源:StandardDialFrame.java

示例5: drawRangeCrosshair

import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
 * Draws a range crosshair.
 * 
 * @param g2  the graphics target.
 * @param dataArea  the data area.
 * @param orientation  the plot orientation.
 * @param value  the crosshair value.
 * @param axis  the axis against which the value is measured.
 * @param stroke  the stroke used to draw the crosshair line.
 * @param paint  the paint used to draw the crosshair line.
 * 
 * @since 1.0.5
 */
protected void drawRangeCrosshair(Graphics2D g2, Rectangle2D dataArea, 
        PlotOrientation orientation, double value, ValueAxis axis, 
        Stroke stroke, Paint paint) {
    
    if (!axis.getRange().contains(value)) {
        return;
    }
    Line2D line = null;
    if (orientation == PlotOrientation.HORIZONTAL) {
        double xx = axis.valueToJava2D(value, dataArea, 
                RectangleEdge.BOTTOM);
        line = new Line2D.Double(xx, dataArea.getMinY(), xx, 
                dataArea.getMaxY());
    }
    else {
        double yy = axis.valueToJava2D(value, dataArea, 
                RectangleEdge.LEFT);
        line = new Line2D.Double(dataArea.getMinX(), yy, 
                dataArea.getMaxX(), yy);
    }
    g2.setStroke(stroke);
    g2.setPaint(paint);
    g2.draw(line);
   
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:39,代码来源:CategoryPlot.java

示例6: drawRangeGridlines

import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
 * Draws the gridlines for the plot, if they are visible.
 *
 * @param g2  the graphics device.
 * @param dataArea  the data area.
 * @param ticks  the ticks.
 */
protected void drawRangeGridlines(Graphics2D g2, Rectangle2D dataArea, List ticks) {

    // draw the range grid lines, if any...
    if (isRangeGridlinesVisible()) {
        Stroke gridStroke = getRangeGridlineStroke();
        Paint gridPaint = getRangeGridlinePaint();
        if ((gridStroke != null) && (gridPaint != null)) {
            Iterator iterator = ticks.iterator();
            while (iterator.hasNext()) {
                ValueTick tick = (ValueTick) iterator.next();
                double v = this.rangeAxis.valueToJava2D(
                    tick.getValue(), dataArea, RectangleEdge.LEFT
                );
                Line2D line = new Line2D.Double(dataArea.getMinX(), v, dataArea.getMaxX(), v);
                g2.setPaint(gridPaint);
                g2.setStroke(gridStroke);
                g2.draw(line);                
            }
        }
    }

}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:30,代码来源:FastScatterPlot.java

示例7: paintComponent

import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
public void paintComponent(Graphics g) {
    super.paintComponent(g); //paint background

    if (diagramaAtual == null) {
        return;
    }

    RenderingHints renderHints
            = new RenderingHints(RenderingHints.KEY_ANTIALIASING,
                    RenderingHints.VALUE_ANTIALIAS_ON);
    renderHints.put(RenderingHints.KEY_RENDERING,
            RenderingHints.VALUE_RENDER_QUALITY);

    Graphics2D Canvas = (Graphics2D) g;
    Canvas.addRenderingHints(renderHints);

    Canvas.setPaint(Color.BLACK);
    Stroke stroke = new BasicStroke(2.f,
            BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER);
    Canvas.setStroke(stroke);

    Canvas.drawRect(box.getLocation().x, box.getLocation().y, box.getWidth(), box.getHeight());
    Canvas.setPaint(Color.GRAY);
    Canvas.drawRect(box.getLocation().x + 1, box.getLocation().y + 1, box.getWidth(), box.getHeight());
    //Canvas.setPaint(Color.BLACK);
}
 
开发者ID:chcandido,项目名称:brModelo,代码行数:28,代码来源:Editor.java

示例8: paint

import java.awt.Graphics2D; //导入方法依赖的package包/类
protected void paint(XYItem item, List<ItemSelection> highlighted,
                     List<ItemSelection> selected, Graphics2D g,
                     Rectangle dirtyArea, SynchronousXYChartContext context) {

    int valuesCount = item.getValuesCount();
    int extraTrailing = fillColor != null ? 2 : 0;

    Rectangle dirtyExtended = new Rectangle(dirtyArea);
    dirtyExtended.x -= lineWidth;
    dirtyExtended.width += lineWidth * 2;
    int[][] idxs = computer.getVisible(dirtyExtended, valuesCount, context, 1,
                                       extraTrailing);
    if (idxs == null) return;
    int[] visibleIndexes = idxs[0];
    int npoints = idxs[1][0];
    int[][] points = computer.createPoints(visibleIndexes, npoints, item,
                                           dataFactor, context);

    if (fillColor != null) {
        points[0][npoints - 2] = points[0][npoints - 3];
        points[1][npoints - 2] = computer.getZeroY(context);
        points[0][npoints - 1] = points[0][0];
        points[1][npoints - 1] = points[1][npoints - 2];

        POLYGON.xpoints = points[0];
        POLYGON.ypoints = points[1];
        POLYGON.npoints = npoints;

        g.setPaint(fillColor);
        g.fill(POLYGON);
    }

    if (lineColor != null) {
        g.setPaint(lineColor);
        g.setStroke(lineStroke);
        g.drawPolyline(points[0], points[1], npoints - extraTrailing);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:39,代码来源:ContinuousXYPainter.java

示例9: drawProcessor2

import java.awt.Graphics2D; //导入方法依赖的package包/类
private void drawProcessor2(Color startC, Color border, boolean gradientFill, Graphics2D g2d, int cpu) {
	double x = getProcessorXY().x, y = getProcessorXY().y;
	processor.setFrame(x + PROC_RAD / 2, y + cpu * PROC_RAD + ELEMS_GAP * cpu - ELEMS_GAP / 2, PROC_RAD, PROC_RAD);
	if (gradientFill) {
		GradientPaint gp = new GradientPaint((float) x, (float) y, startC.brighter(), (float) x, (float) (y + PROC_RAD * 2), startC.darker(),
				false);
		g2d.setPaint(gp);
	} else {
		g2d.setPaint(startC);
	}
	g2d.fill(processor);
	g2d.setPaint(border);
	g2d.draw(processor);
}
 
开发者ID:max6cn,项目名称:jmt,代码行数:15,代码来源:QueueDrawer.java

示例10: drawProcessorMulti

import java.awt.Graphics2D; //导入方法依赖的package包/类
private void drawProcessorMulti(Color startC, Color border, boolean gradientFill, Graphics2D g2d, int cpu) {
	double x = getProcessorXY().x, y = getProcessorXY().y;
	processor.setFrame(x + PROC_RAD / 2 + ELEMS_GAP / 2, y + cpu * (PROC_RAD - ELEMS_GAP) + ELEMS_GAP * cpu * 3 - ELEMS_GAP / 2, PROC_RAD
			- ELEMS_GAP, PROC_RAD - ELEMS_GAP);
	if (gradientFill) {
		GradientPaint gp = new GradientPaint((float) x, (float) y, startC.brighter(), (float) x, (float) (y + PROC_RAD * 2), startC.darker(),
				false);
		g2d.setPaint(gp);
	} else {
		g2d.setPaint(startC);
	}
	g2d.fill(processor);
	g2d.setPaint(border);
	g2d.draw(processor);
}
 
开发者ID:HOMlab,项目名称:QN-ACTR-Release,代码行数:16,代码来源:QueueDrawer.java

示例11: drawDomainGridline

import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
 * 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.
 *
 * @see #drawRangeGridline(Graphics2D, CategoryPlot, ValueAxis,
 *     Rectangle2D, double)
 */
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);

}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:49,代码来源:AbstractCategoryItemRenderer.java

示例12: drawItem

import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
 * 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.
 */
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);
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:54,代码来源:XYBlockRenderer.java

示例13: drawSlider

import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
protected void drawSlider(final Graphics2D g2) {
    GradientPaint gradient = new GradientPaint(0, 0, colorLimitMin, sliderWidth(), 0, colorLimitMax, true);
    g2.setPaint(gradient);
    fillSlider(g2);
    g2.setColor(Color.black);
    super.drawSlider(g2);
}
 
开发者ID:iapafoto,项目名称:DicomViewer,代码行数:9,代码来源:SliderComponentForTimeSlider.java

示例14: createPaint

import java.awt.Graphics2D; //导入方法依赖的package包/类
private Paint createPaint(PaintType type, int startx, int starty,
                          int w, int h)
{
    // make sure that the blue color doesn't show up when filling a
    // w by h rect
    w++; h++;

    int endx = startx + w;
    int endy = starty + h;
    Rectangle2D.Float r = new Rectangle2D.Float(startx, starty, w, h);
    switch (type) {
        case COLOR: return Color.red;
        case GRADIENT: return
            new GradientPaint(startx, starty, Color.red,
                              endx, endy, Color.green);
        case LINEAR_GRADIENT: return
            new LinearGradientPaint(startx, starty, endx, endy,
                new float[] { 0.0f, 0.999f, 1.0f },
                new Color[] { Color.red, Color.green, Color.blue });
        case RADIAL_GRADIENT: return
            new RadialGradientPaint(startx, starty,
                (float)Math.sqrt(w * w + h * h),
                new float[] { 0.0f, 0.999f, 1.0f },
                new Color[] { Color.red, Color.green, Color.blue },
                CycleMethod.NO_CYCLE);
        case TEXTURE: {
            BufferedImage bi =
                new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
            Graphics2D g = (Graphics2D) bi.getGraphics();
            g.setPaint(createPaint(PaintType.LINEAR_GRADIENT, 0, 0, w, h));
            g.fillRect(0, 0, w, h);
            return new TexturePaint(bi, r);
        }
    }
    return Color.green;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:37,代码来源:TransformedPaintTest.java

示例15: doDrawColoredBorder

import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
 * Method description
 * 
 * @see
 * @param objPgraphics2D
 */
final private void doDrawColoredBorder(Graphics2D objPgraphics2D) {

	final Insets objLinsets = this.getInsets();

	final byte bytLthickness = 4;
	final int intLx0 = objLinsets.left;
	final int intLy0 = objLinsets.top;
	final int intLx1 = objLinsets.left + this.intGbackgroundWidth;
	final int intLy1 = objLinsets.top + this.intGbackgroundHeight;

	// North border :
	objPgraphics2D.setStroke(new BasicStroke(0.5F, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
	objPgraphics2D.setPaint(new GradientPaint(intLx0, intLy0, Color.WHITE, intLx1, intLy0, Color.ORANGE, false));
	objPgraphics2D.fillRect(intLx0, intLy0, intLx1 - intLx0, bytLthickness);

	// West border :
	objPgraphics2D.setPaint(new GradientPaint(intLx0, intLy0, Color.WHITE, intLx0, intLy1, Color.ORANGE, false));
	objPgraphics2D.fillRect(intLx0, intLy0, bytLthickness, intLy1 - intLy0);

	// East border :
	objPgraphics2D.setPaint(new GradientPaint(intLx1, intLy0, Color.ORANGE, intLx1, intLy1, Color.RED, false));
	objPgraphics2D.fillRect(intLx1 - bytLthickness, intLy0, bytLthickness, intLy1 - intLy0);

	// South border :
	objPgraphics2D.setPaint(new GradientPaint(intLx0, intLy1, Color.ORANGE, intLx1, intLy1, Color.RED, false));
	objPgraphics2D.fillRect(intLx0, intLy1 - bytLthickness, intLx1 - intLx0, bytLthickness);
}
 
开发者ID:jugglemaster,项目名称:JuggleMasterPro,代码行数:34,代码来源:AnimationJFrame.java


注:本文中的java.awt.Graphics2D.setPaint方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。