类java.awt.Shape源码实例Demo

下面列出了怎么用java.awt.Shape的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: jdk8u-jdk   文件: SunGraphics2D.java
protected static Shape transformShape(int tx, int ty, Shape s) {
    if (s == null) {
        return null;
    }

    if (s instanceof Rectangle) {
        Rectangle r = s.getBounds();
        r.translate(tx, ty);
        return r;
    }
    if (s instanceof Rectangle2D) {
        Rectangle2D rect = (Rectangle2D) s;
        return new Rectangle2D.Double(rect.getX() + tx,
                                      rect.getY() + ty,
                                      rect.getWidth(),
                                      rect.getHeight());
    }

    if (tx == 0 && ty == 0) {
        return cloneShape(s);
    }

    AffineTransform mat = AffineTransform.getTranslateInstance(tx, ty);
    return mat.createTransformedShape(s);
}
 
源代码2 项目: ccu-historian   文件: ShapeUtilities.java
/**
 * Translates a shape to a new location such that the anchor point
 * (relative to the rectangular bounds of the shape) aligns with the
 * specified (x, y) coordinate in Java2D space.
 *
 * @param shape  the shape (<code>null</code> not permitted).
 * @param anchor  the anchor (<code>null</code> not permitted).
 * @param locationX  the x-coordinate (in Java2D space).
 * @param locationY  the y-coordinate (in Java2D space).
 *
 * @return A new and translated shape.
 */
public static Shape createTranslatedShape(final Shape shape,
                                          final RectangleAnchor anchor,
                                          final double locationX,
                                          final double locationY) {
    if (shape == null) {
        throw new IllegalArgumentException("Null 'shape' argument.");
    }
    if (anchor == null) {
        throw new IllegalArgumentException("Null 'anchor' argument.");
    }
    Point2D anchorPoint = RectangleAnchor.coordinates(
            shape.getBounds2D(), anchor);
    final AffineTransform transform = AffineTransform.getTranslateInstance(
            locationX - anchorPoint.getX(), locationY - anchorPoint.getY());
    return transform.createTransformedShape(shape);
}
 
源代码3 项目: openjdk-jdk8u   文件: SpanShapeRenderer.java
public void fill(SunGraphics2D sg, Shape s) {
    if (s instanceof Rectangle2D &&
        (sg.transform.getType() & NON_RECTILINEAR_TRANSFORM_MASK) == 0)
    {
        renderRect(sg, (Rectangle2D) s);
        return;
    }

    Region clipRegion = sg.getCompClip();
    ShapeSpanIterator sr = LoopPipe.getFillSSI(sg);
    try {
        sr.setOutputArea(clipRegion);
        sr.appendPath(s.getPathIterator(sg.transform));
        renderSpans(sg, clipRegion, s, sr);
    } finally {
        sr.dispose();
    }
}
 
源代码4 项目: pumpernickel   文件: AddRulesTest.java
public BufferedImage render() {
	Rectangle2D bounds = getBounds();
	Rectangle r = bounds.getBounds();
	BufferedImage bi = new BufferedImage(r.width, r.height,
			BufferedImage.TYPE_INT_ARGB);
	Graphics2D g = bi.createGraphics();
	g.translate(-r.x, -r.y);
	g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
			RenderingHints.VALUE_ANTIALIAS_ON);
	for (int a = 0; a < shapes.size(); a++) {
		float hue = (a) / 11f;
		float bri = .75f + .25f * a / ((shapes.size()));
		Shape shape = shapes.get(a);
		g.setColor(new Color(Color.HSBtoRGB(hue, .75f, bri)));
		g.fill(shape);
	}
	g.dispose();
	return bi;
}
 
源代码5 项目: astor   文件: SymbolAxis.java
/**
 * Draws the grid bands.  Alternate bands are colored using 
 * <CODE>gridBandPaint<CODE> (<CODE>DEFAULT_GRID_BAND_PAINT</CODE> by 
 * default).
 *
 * @param g2  the graphics device.
 * @param plotArea  the area within which the chart should be drawn.
 * @param dataArea  the area within which the plot should be drawn (a 
 *                  subset of the drawArea).
 * @param edge  the axis location.
 * @param ticks  the ticks.
 */
protected void drawGridBands(Graphics2D g2,
                             Rectangle2D plotArea, 
                             Rectangle2D dataArea,
                             RectangleEdge edge, 
                             List ticks) {

    Shape savedClip = g2.getClip();
    g2.clip(dataArea);
    if (RectangleEdge.isTopOrBottom(edge)) {
        drawGridBandsHorizontal(g2, plotArea, dataArea, true, ticks);
    }
    else if (RectangleEdge.isLeftOrRight(edge)) {
        drawGridBandsVertical(g2, plotArea, dataArea, true, ticks);
    }
    g2.setClip(savedClip);

}
 
源代码6 项目: osp   文件: DrawableShapeLoader.java
/**
 * Saves a DrawableShape by saving the general path.
 * @param control XMLControl
 * @param obj Object
 */
public void saveObject(XMLControl control, Object obj) {
  DrawableShape drawableShape = (DrawableShape) obj;
  control.setValue("geometry", drawableShape.shapeClass);  //$NON-NLS-1$
  control.setValue("x", drawableShape.x);                  //$NON-NLS-1$
  control.setValue("y", drawableShape.y);                  //$NON-NLS-1$
  control.setValue("theta", drawableShape.theta);          //$NON-NLS-1$
  control.setValue("fill color", drawableShape.color);     //$NON-NLS-1$
  control.setValue("edge color", drawableShape.edgeColor); //$NON-NLS-1$
  Shape shape = AffineTransform.getRotateInstance(-drawableShape.theta, drawableShape.x, drawableShape.y).createTransformedShape(drawableShape.shape);
  control.setValue("general path", shape); //$NON-NLS-1$
}
 
源代码7 项目: mars-sim   文件: ZoomSliderPanel.java
private void initShapes() {
    shapes = new Shape[3];
    int w = getWidth();
    int h = getHeight();
    shapes[0] = new Rectangle2D.Double(w/16, h/16, w*7/8, h*7/8);
    shapes[1] = new Line2D.Double(w/16, h*15/16, w*15/16, h/16);
    shapes[2] = new Ellipse2D.Double(w/4, h/4, w/2, h/2);
    size.width = w;
    size.height = h;
}
 
源代码8 项目: plugins   文件: NpcHighlightOverlay.java
private void renderHullOverlay(Graphics2D graphics, NPC npc, Color color)
{
	Shape objectClickbox = npc.getConvexHull();
	if (objectClickbox != null)
	{
		graphics.setColor(color);
		graphics.setStroke(new BasicStroke(2));
		graphics.draw(objectClickbox);
		graphics.setColor(new Color(color.getRed(), color.getGreen(), color.getBlue(), 20));
		graphics.fill(objectClickbox);
	}
}
 
源代码9 项目: jdk8u-dev-jdk   文件: TextMeasureTests.java
public void runTest(Object ctx, int numReps) {
    GVContext gvctx = (GVContext)ctx;
    GlyphVector gv = gvctx.gv;
    Shape s;
    do {
        for (int i = 0, e = gv.getNumGlyphs(); i < e; ++i) {
            s = gv.getGlyphOutline(i);
        }
    } while (--numReps >= 0);
}
 
源代码10 项目: jdk8u-dev-jdk   文件: TextMeasureTests.java
public void runTest(Object ctx, int numReps) {
    GVContext gvctx = (GVContext)ctx;
    GlyphVector gv = gvctx.gv;
    Shape s;
    do {
        for (int i = 0, e = gv.getNumGlyphs(); i < e; ++i) {
            s = gv.getGlyphLogicalBounds(i);
        }
    } while (--numReps >= 0);
}
 
源代码11 项目: buffer_bci   文件: LegendGraphic.java
/**
 * Creates a new legend graphic.
 *
 * @param shape  the shape (<code>null</code> not permitted).
 * @param fillPaint  the fill paint (<code>null</code> not permitted).
 */
public LegendGraphic(Shape shape, Paint fillPaint) {
    ParamChecks.nullNotPermitted(shape, "shape");
    ParamChecks.nullNotPermitted(fillPaint, "fillPaint");
    this.shapeVisible = true;
    this.shape = shape;
    this.shapeAnchor = RectangleAnchor.CENTER;
    this.shapeLocation = RectangleAnchor.CENTER;
    this.shapeFilled = true;
    this.fillPaint = fillPaint;
    this.fillPaintTransformer = new StandardGradientPaintTransformer();
    setPadding(2.0, 2.0, 2.0, 2.0);
}
 
源代码12 项目: ET_Redux   文件: SessionOfStandardView.java
private void paintFractionVerticalTicRed(Graphics2D g2d, int chosenDatumIndex) {
    Shape redDatumLine = new Line2D.Double(//
            mapX(zeroBasedFractionAquireTimes.get(chosenDatumIndex)),// 
            mapY(minY),//
            mapX(zeroBasedFractionAquireTimes.get(chosenDatumIndex)),// 
            mapY(maxY));

    Paint savedPaint = g2d.getPaint();
    Stroke savedStroke = g2d.getStroke();
    g2d.setPaint(EXCLUDED_COLOR);
    g2d.setStroke(new BasicStroke(0.5f));
    g2d.draw(redDatumLine);
    g2d.setPaint(savedPaint);
    g2d.setStroke(savedStroke);
}
 
源代码13 项目: hottub   文件: PathGraphics.java
/**
  * Redraw a rectanglular area using a proxy graphics
  */
public abstract void redrawRegion(Rectangle2D region,
                                  double scaleX, double scaleY,
                                  Shape clip,
                                  AffineTransform devTransform)

                throws PrinterException ;
 
源代码14 项目: jdk8u-dev-jdk   文件: Underline.java
Shape getUnderlineShape(float thickness,
                        float x1,
                        float x2,
                        float y) {

    Stroke ulStroke = getStroke(thickness);
    Line2D line = new Line2D.Float(x1, y + shift, x2, y + shift);
    return ulStroke.createStrokedShape(line);
}
 
源代码15 项目: ECG-Viewer   文件: FXGraphics2D.java
/**
 * Returns the user clipping region.  The initial default value is 
 * {@code null}.
 * 
 * @return The user clipping region (possibly {@code null}).
 * 
 * @see #setClip(java.awt.Shape)
 */
@Override
public Shape getClip() {
    if (this.clip == null) {
        return null;
    }
    AffineTransform inv;
    try {
        inv = this.transform.createInverse();
        return inv.createTransformedShape(this.clip);
    } catch (NoninvertibleTransformException ex) {
        return null;
    }
}
 
源代码16 项目: openjdk-8-source   文件: BufferedRenderPipe.java
public void draw(SunGraphics2D sg2d, Shape s) {
    if (sg2d.strokeState == SunGraphics2D.STROKE_THIN) {
        if (s instanceof Polygon) {
            if (sg2d.transformState < SunGraphics2D.TRANSFORM_TRANSLATESCALE) {
                Polygon p = (Polygon)s;
                drawPolygon(sg2d, p.xpoints, p.ypoints, p.npoints);
                return;
            }
        }
        Path2D.Float p2df;
        int transx, transy;
        if (sg2d.transformState <= SunGraphics2D.TRANSFORM_INT_TRANSLATE) {
            if (s instanceof Path2D.Float) {
                p2df = (Path2D.Float)s;
            } else {
                p2df = new Path2D.Float(s);
            }
            transx = sg2d.transX;
            transy = sg2d.transY;
        } else {
            p2df = new Path2D.Float(s, sg2d.transform);
            transx = 0;
            transy = 0;
        }
        drawPath(sg2d, p2df, transx, transy);
    } else if (sg2d.strokeState < SunGraphics2D.STROKE_CUSTOM) {
        ShapeSpanIterator si = LoopPipe.getStrokeSpans(sg2d, s);
        try {
            fillSpans(sg2d, si, 0, 0);
        } finally {
            si.dispose();
        }
    } else {
        fill(sg2d, sg2d.stroke.createStrokedShape(s));
    }
}
 
源代码17 项目: jdk8u-jdk   文件: TranslucentShapedFrameTest.java
private void shapedCbActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_shapedCbActionPerformed
    if (testFrame != null) {
        Shape s = null;
        if (shapedCb.isSelected()) {
            s = new Ellipse2D.Double(0, 0,
                                     testFrame.getWidth(),
                                     testFrame.getHeight());
        }
        testFrame.setShape(s);
    }
}
 
源代码18 项目: opensim-gui   文件: BoxAndWhiskerRenderer.java
/**
 * Returns a legend item for a series.
 *
 * @param datasetIndex  the dataset index (zero-based).
 * @param series  the series index (zero-based).
 *
 * @return The legend item.
 */
public LegendItem getLegendItem(int datasetIndex, int series) {

    CategoryPlot cp = getPlot();
    if (cp == null) {
        return null;
    }

    CategoryDataset dataset;
    dataset = cp.getDataset(datasetIndex);
    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);   
    }
    Shape shape = new Rectangle2D.Double(-4.0, -4.0, 8.0, 8.0);
    Paint paint = getSeriesPaint(series);
    Paint outlinePaint = getSeriesOutlinePaint(series);
    Stroke outlineStroke = getSeriesOutlineStroke(series);

    return new LegendItem(label, description, toolTipText, urlText, 
            shape, paint, outlineStroke, outlinePaint);

}
 
源代码19 项目: brModelo   文件: LivreBase.java
public Shape getRegiaoRecArred() {
    if (Regiao == null) {
        Regiao = new RoundRectangle2D.Float(getLeft(), getTop(), getWidth(), getHeight(), getWidth() / 3, getHeight());
    }
    return Regiao;
}
 
源代码20 项目: openstock   文件: ScatterRenderer.java
/**
 * Returns a legend item for a series.
 *
 * @param datasetIndex  the dataset index (zero-based).
 * @param series  the series index (zero-based).
 *
 * @return The legend item.
 */
@Override
public LegendItem getLegendItem(int datasetIndex, int series) {

    CategoryPlot cp = getPlot();
    if (cp == null) {
        return null;
    }

    if (isSeriesVisible(series) && isSeriesVisibleInLegend(series)) {
        CategoryDataset dataset = cp.getDataset(datasetIndex);
        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);
        }
        Shape shape = lookupLegendShape(series);
        Paint paint = lookupSeriesPaint(series);
        Paint fillPaint = (this.useFillPaint
                ? getItemFillPaint(series, 0) : paint);
        boolean shapeOutlineVisible = this.drawOutlines;
        Paint outlinePaint = (this.useOutlinePaint
                ? getItemOutlinePaint(series, 0) : paint);
        Stroke outlineStroke = lookupSeriesOutlineStroke(series);
        LegendItem result = new LegendItem(label, description, toolTipText,
                urlText, true, shape, getItemShapeFilled(series, 0),
                fillPaint, shapeOutlineVisible, outlinePaint, outlineStroke,
                false, new Line2D.Double(-7.0, 0.0, 7.0, 0.0),
                getItemStroke(series, 0), getItemPaint(series, 0));
        result.setLabelFont(lookupLegendTextFont(series));
        Paint labelPaint = lookupLegendTextPaint(series);
        if (labelPaint != null) {
            result.setLabelPaint(labelPaint);
        }
        result.setDataset(dataset);
        result.setDatasetIndex(datasetIndex);
        result.setSeriesKey(dataset.getRowKey(series));
        result.setSeriesIndex(series);
        return result;
    }
    return null;

}
 
源代码21 项目: dragonwell8_jdk   文件: X11Renderer.java
public void fill(SunGraphics2D sg2d, Shape s) {
    if (sg2d.strokeState == SunGraphics2D.STROKE_THIN) {
        // Delegate to fillPolygon() if possible...
        if (s instanceof Polygon &&
            sg2d.transformState < SunGraphics2D.TRANSFORM_TRANSLATESCALE)
        {
            Polygon p = (Polygon) s;
            fillPolygon(sg2d, p.xpoints, p.ypoints, p.npoints);
            return;
        }

        // Otherwise we will use fillPath() for
        // high-quality fills.
        doPath(sg2d, s, true);
        return;
    }

    AffineTransform at;
    int transx, transy;
    if (sg2d.transformState < SunGraphics2D.TRANSFORM_TRANSLATESCALE) {
        // Transform (translation) will be done by XFillSpans
        at = null;
        transx = sg2d.transX;
        transy = sg2d.transY;
    } else {
        // Transform will be done by the PathIterator
        at = sg2d.transform;
        transx = transy = 0;
    }

    ShapeSpanIterator ssi = LoopPipe.getFillSSI(sg2d);
    try {
        // Subtract transx/y from the SSI clip to match the
        // (potentially untranslated) geometry fed to it
        Region clip = sg2d.getCompClip();
        ssi.setOutputAreaXYXY(clip.getLoX() - transx,
                              clip.getLoY() - transy,
                              clip.getHiX() - transx,
                              clip.getHiY() - transy);
        ssi.appendPath(s.getPathIterator(at));
        SunToolkit.awtLock();
        try {
            long xgc = validate(sg2d);
            XFillSpans(sg2d.surfaceData.getNativeOps(), xgc,
                       ssi, ssi.getNativeIterator(),
                       transx, transy);
        } finally {
            SunToolkit.awtUnlock();
        }
    } finally {
        ssi.dispose();
    }
}
 
源代码22 项目: ECG-Viewer   文件: ScatterRenderer.java
/**
 * Returns a legend item for a series.
 *
 * @param datasetIndex  the dataset index (zero-based).
 * @param series  the series index (zero-based).
 *
 * @return The legend item.
 */
@Override
public LegendItem getLegendItem(int datasetIndex, int series) {

    CategoryPlot cp = getPlot();
    if (cp == null) {
        return null;
    }

    if (isSeriesVisible(series) && isSeriesVisibleInLegend(series)) {
        CategoryDataset dataset = cp.getDataset(datasetIndex);
        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);
        }
        Shape shape = lookupLegendShape(series);
        Paint paint = lookupSeriesPaint(series);
        Paint fillPaint = (this.useFillPaint
                ? getItemFillPaint(series, 0) : paint);
        boolean shapeOutlineVisible = this.drawOutlines;
        Paint outlinePaint = (this.useOutlinePaint
                ? getItemOutlinePaint(series, 0) : paint);
        Stroke outlineStroke = lookupSeriesOutlineStroke(series);
        LegendItem result = new LegendItem(label, description, toolTipText,
                urlText, true, shape, getItemShapeFilled(series, 0),
                fillPaint, shapeOutlineVisible, outlinePaint, outlineStroke,
                false, new Line2D.Double(-7.0, 0.0, 7.0, 0.0),
                getItemStroke(series, 0), getItemPaint(series, 0));
        result.setLabelFont(lookupLegendTextFont(series));
        Paint labelPaint = lookupLegendTextPaint(series);
        if (labelPaint != null) {
            result.setLabelPaint(labelPaint);
        }
        result.setDataset(dataset);
        result.setDatasetIndex(datasetIndex);
        result.setSeriesKey(dataset.getRowKey(series));
        result.setSeriesIndex(series);
        return result;
    }
    return null;

}
 
源代码23 项目: netcdf-java   文件: GisFeatureRendererMulti.java
private ArrayList makeShapes(Iterator featList) {
  Shape shape;
  ArrayList shapeList = new ArrayList();
  ProjectionImpl dataProject = getDataProjection();

  if (Debug.isSet("GisFeature/MapDraw")) {
    System.out.println("GisFeature/MapDraw: makeShapes with " + displayProject);
  }

  /*
   * if (Debug.isSet("bug.drawShapes")) {
   * int count =0;
   * // make each GisPart a seperate shape for debugging
   * feats:while (featList.hasNext()) {
   * AbstractGisFeature feature = (AbstractGisFeature) featList.next();
   * java.util.Iterator pi = feature.getGisParts();
   * while (pi.hasNext()) {
   * GisPart gp = (GisPart) pi.next();
   * int np = gp.getNumPoints();
   * GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD, np);
   * double[] xx = gp.getX();
   * double[] yy = gp.getY();
   * path.moveTo((float) xx[0], (float) yy[0]);
   * if (count == 63)
   * System.out.println("moveTo x ="+xx[0]+" y= "+yy[0]);
   * for(int i = 1; i < np; i++) {
   * path.lineTo((float) xx[i], (float) yy[i]);
   * if (count == 63)
   * System.out.println("lineTo x ="+xx[i]+" y= "+yy[i]);
   * }
   * shapeList.add(path);
   * if (count == 63)
   * break feats;
   * count++;
   * }
   * }
   * System.out.println("bug.drawShapes: #shapes =" +shapeList.size());
   * return shapeList;
   * }
   */

  while (featList.hasNext()) {
    AbstractGisFeature feature = (AbstractGisFeature) featList.next();
    if (dataProject.isLatLon()) // always got to run it through if its lat/lon
      shape = feature.getProjectedShape(displayProject);
    else if (dataProject == displayProject)
      shape = feature.getShape();
    else
      shape = feature.getProjectedShape(dataProject, displayProject);

    shapeList.add(shape);
  }

  return shapeList;
}
 
源代码24 项目: openjdk-jdk8u   文件: TextRenderer.java
protected void drawGlyphList(SunGraphics2D sg2d, GlyphList gl) {
    int num = gl.getNumGlyphs();
    Region clipRegion = sg2d.getCompClip();
    int cx1 = clipRegion.getLoX();
    int cy1 = clipRegion.getLoY();
    int cx2 = clipRegion.getHiX();
    int cy2 = clipRegion.getHiY();
    Object ctx = null;
    try {
        int[] bounds = gl.getBounds();
        Rectangle r = new Rectangle(bounds[0], bounds[1],
                                    bounds[2] - bounds[0],
                                    bounds[3] - bounds[1]);
        Shape s = sg2d.untransformShape(r);
        ctx = outpipe.startSequence(sg2d, s, r, bounds);
        for (int i = 0; i < num; i++) {
            gl.setGlyphIndex(i);
            int metrics[] = gl.getMetrics();
            int gx1 = metrics[0];
            int gy1 = metrics[1];
            int w = metrics[2];
            int gx2 = gx1 + w;
            int gy2 = gy1 + metrics[3];
            int off = 0;
            if (gx1 < cx1) {
                off = cx1 - gx1;
                gx1 = cx1;
            }
            if (gy1 < cy1) {
                off += (cy1 - gy1) * w;
                gy1 = cy1;
            }
            if (gx2 > cx2) gx2 = cx2;
            if (gy2 > cy2) gy2 = cy2;
            if (gx2 > gx1 && gy2 > gy1 &&
                outpipe.needTile(ctx, gx1, gy1, gx2 - gx1, gy2 - gy1))
            {
                byte alpha[] = gl.getGrayBits();
                outpipe.renderPathTile(ctx, alpha, off, w,
                                       gx1, gy1, gx2 - gx1, gy2 - gy1);
            } else {
                outpipe.skipTile(ctx, gx1, gy1);
            }
        }
    } finally {
        if (ctx != null) {
            outpipe.endSequence(ctx);
        }
    }
}
 
源代码25 项目: megamek   文件: HexDrawUtilities.java
private static Shape getHBLU() {
    Path2D.Double border = new Path2D.Double();
    border.moveTo(HEX_UL.x, HEX_UL.y);
    border.lineTo(HEX_UR.x, HEX_UR.y);
    return border;
}
 
源代码26 项目: buffer_bci   文件: AbstractXYItemRenderer.java
/**
 * Returns a default legend item for the specified series.  Subclasses
 * should override this method to generate customised items.
 *
 * @param datasetIndex  the dataset index (zero-based).
 * @param series  the series index (zero-based).
 *
 * @return A legend item for the series.
 */
@Override
public LegendItem getLegendItem(int datasetIndex, int series) {
    XYPlot xyplot = getPlot();
    if (xyplot == null) {
        return null;
    }
    XYDataset dataset = xyplot.getDataset(datasetIndex);
    if (dataset == null) {
        return null;
    }
    String label = this.legendItemLabelGenerator.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);
    }
    Shape shape = lookupLegendShape(series);
    Paint paint = lookupSeriesPaint(series);
    LegendItem item = new LegendItem(label, paint);
    item.setToolTipText(toolTipText);
    item.setURLText(urlText);
    item.setLabelFont(lookupLegendTextFont(series));
    Paint labelPaint = lookupLegendTextPaint(series);
    if (labelPaint != null) {
        item.setLabelPaint(labelPaint);
    }
    item.setSeriesKey(dataset.getSeriesKey(series));
    item.setSeriesIndex(series);
    item.setDataset(dataset);
    item.setDatasetIndex(datasetIndex);

    if (getTreatLegendShapeAsLine()) {
        item.setLineVisible(true);
        item.setLine(shape);
        item.setLinePaint(paint);
        item.setShapeVisible(false);
    }
    else {
        Paint outlinePaint = lookupSeriesOutlinePaint(series);
        Stroke outlineStroke = lookupSeriesOutlineStroke(series);
        item.setOutlinePaint(outlinePaint);
        item.setOutlineStroke(outlineStroke);
    }
    return item;
}
 
源代码27 项目: SIMVA-SoS   文件: AbstractCategoryItemRenderer.java
/**
 * Returns a legend item for a series.  This default implementation will
 * return <code>null</code> if {@link #isSeriesVisible(int)} or
 * {@link #isSeriesVisibleInLegend(int)} returns <code>false</code>.
 *
 * @param datasetIndex  the dataset index (zero-based).
 * @param series  the series index (zero-based).
 *
 * @return The legend item (possibly <code>null</code>).
 *
 * @see #getLegendItems()
 */
@Override
public LegendItem getLegendItem(int datasetIndex, int series) {

    CategoryPlot p = getPlot();
    if (p == null) {
        return null;
    }

    // check that a legend item needs to be displayed...
    if (!isSeriesVisible(series) || !isSeriesVisibleInLegend(series)) {
        return null;
    }

    CategoryDataset dataset = p.getDataset(datasetIndex);
    String label = this.legendItemLabelGenerator.generateLabel(dataset,
            series);
    String description = label;
    String toolTipText = null;
    if (this.legendItemToolTipGenerator != null) {
        toolTipText = this.legendItemToolTipGenerator.generateLabel(
                dataset, series);
    }
    String urlText = null;
    if (this.legendItemURLGenerator != null) {
        urlText = this.legendItemURLGenerator.generateLabel(dataset,
                series);
    }
    Shape shape = lookupLegendShape(series);
    Paint paint = lookupSeriesPaint(series);
    Paint outlinePaint = lookupSeriesOutlinePaint(series);
    Stroke outlineStroke = lookupSeriesOutlineStroke(series);

    LegendItem item = new LegendItem(label, description, toolTipText,
            urlText, shape, paint, outlineStroke, outlinePaint);
    item.setLabelFont(lookupLegendTextFont(series));
    Paint labelPaint = lookupLegendTextPaint(series);
    if (labelPaint != null) {
        item.setLabelPaint(labelPaint);
    }
    item.setSeriesKey(dataset.getRowKey(series));
    item.setSeriesIndex(series);
    item.setDataset(dataset);
    item.setDatasetIndex(datasetIndex);
    return item;
}
 
源代码28 项目: jdk8u60   文件: PSPathGraphics.java
/** Redraw a rectanglular area using a proxy graphics
  * To do this we need to know the rectangular area to redraw and
  * the transform & clip in effect at the time of the original drawImage
  *
  */

public void redrawRegion(Rectangle2D region, double scaleX, double scaleY,
                         Shape savedClip, AffineTransform savedTransform)

        throws PrinterException {

    PSPrinterJob psPrinterJob = (PSPrinterJob)getPrinterJob();
    Printable painter = getPrintable();
    PageFormat pageFormat = getPageFormat();
    int pageIndex = getPageIndex();

    /* Create a buffered image big enough to hold the portion
     * of the source image being printed.
     */
    BufferedImage deepImage = new BufferedImage(
                                    (int) region.getWidth(),
                                    (int) region.getHeight(),
                                    BufferedImage.TYPE_3BYTE_BGR);

    /* Get a graphics for the application to render into.
     * We initialize the buffer to white in order to
     * match the paper and then we shift the BufferedImage
     * so that it covers the area on the page where the
     * caller's Image will be drawn.
     */
    Graphics2D g = deepImage.createGraphics();
    ProxyGraphics2D proxy = new ProxyGraphics2D(g, psPrinterJob);
    proxy.setColor(Color.white);
    proxy.fillRect(0, 0, deepImage.getWidth(), deepImage.getHeight());
    proxy.clipRect(0, 0, deepImage.getWidth(), deepImage.getHeight());

    proxy.translate(-region.getX(), -region.getY());

    /* Calculate the resolution of the source image.
     */
    float sourceResX = (float)(psPrinterJob.getXRes() / scaleX);
    float sourceResY = (float)(psPrinterJob.getYRes() / scaleY);

    /* The application expects to see user space at 72 dpi.
     * so change user space from image source resolution to
     *  72 dpi.
     */
    proxy.scale(sourceResX / DEFAULT_USER_RES,
                sourceResY / DEFAULT_USER_RES);
   proxy.translate(
        -psPrinterJob.getPhysicalPrintableX(pageFormat.getPaper())
           / psPrinterJob.getXRes() * DEFAULT_USER_RES,
        -psPrinterJob.getPhysicalPrintableY(pageFormat.getPaper())
           / psPrinterJob.getYRes() * DEFAULT_USER_RES);
   /* NB User space now has to be at 72 dpi for this calc to be correct */
    proxy.transform(new AffineTransform(getPageFormat().getMatrix()));

    proxy.setPaint(Color.black);

    painter.print(proxy, pageFormat, pageIndex);

    g.dispose();

    /* In PSPrinterJob images are printed in device space
     * and therefore we need to set a device space clip.
     */
    psPrinterJob.setClip(savedTransform.createTransformedShape(savedClip));


    /* Scale the bounding rectangle by the scale transform.
     * Because the scaling transform has only x and y
     * scaling components it is equivalent to multiply
     * the x components of the bounding rectangle by
     * the x scaling factor and to multiply the y components
     * by the y scaling factor.
     */
    Rectangle2D.Float scaledBounds
            = new Rectangle2D.Float(
                    (float) (region.getX() * scaleX),
                    (float) (region.getY() * scaleY),
                    (float) (region.getWidth() * scaleX),
                    (float) (region.getHeight() * scaleY));


    /* Pull the raster data from the buffered image
     * and pass it along to PS.
     */
    ByteComponentRaster tile = (ByteComponentRaster)deepImage.getRaster();

    psPrinterJob.drawImageBGR(tile.getDataStorage(),
                        scaledBounds.x, scaledBounds.y,
                        scaledBounds.width,
                        scaledBounds.height,
                        0f, 0f,
                        deepImage.getWidth(), deepImage.getHeight(),
                        deepImage.getWidth(), deepImage.getHeight());


}
 
源代码29 项目: TencentKona-8   文件: BufferedRenderPipe.java
public void fill(SunGraphics2D sg2d, Shape s) {
    int transx, transy;

    if (sg2d.strokeState == SunGraphics2D.STROKE_THIN) {
        // Here we are able to use fillPath() for
        // high-quality fills.
        Path2D.Float p2df;
        if (sg2d.transformState <= SunGraphics2D.TRANSFORM_INT_TRANSLATE) {
            if (s instanceof Path2D.Float) {
                p2df = (Path2D.Float)s;
            } else {
                p2df = new Path2D.Float(s);
            }
            transx = sg2d.transX;
            transy = sg2d.transY;
        } else {
            p2df = new Path2D.Float(s, sg2d.transform);
            transx = 0;
            transy = 0;
        }
        fillPath(sg2d, p2df, transx, transy);
        return;
    }

    AffineTransform at;
    if (sg2d.transformState <= SunGraphics2D.TRANSFORM_INT_TRANSLATE) {
        // Transform (translation) will be done by FillSpans (we could
        // delegate to fillPolygon() here, but most hardware accelerated
        // libraries cannot handle non-convex polygons, so we will use
        // the FillSpans approach by default)
        at = null;
        transx = sg2d.transX;
        transy = sg2d.transY;
    } else {
        // Transform will be done by the PathIterator
        at = sg2d.transform;
        transx = transy = 0;
    }

    ShapeSpanIterator ssi = LoopPipe.getFillSSI(sg2d);
    try {
        // Subtract transx/y from the SSI clip to match the
        // (potentially untranslated) geometry fed to it
        Region clip = sg2d.getCompClip();
        ssi.setOutputAreaXYXY(clip.getLoX() - transx,
                              clip.getLoY() - transy,
                              clip.getHiX() - transx,
                              clip.getHiY() - transy);
        ssi.appendPath(s.getPathIterator(at));
        fillSpans(sg2d, ssi, transx, transy);
    } finally {
        ssi.dispose();
    }
}
 
源代码30 项目: megamek   文件: HexDrawUtilities.java
private static Shape getHBLU(int hexFace) {
    return getHRU(hexFace).createTransformedShape(getHBLU());
}
 
 类所在包
 同包方法