Java Code Examples for java.awt.Shape

The following examples show how to use java.awt.Shape. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: jdk8u-jdk   Source File: SunGraphics2D.java    License: GNU General Public License v2.0 7 votes vote down vote up
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);
}
 
Example 2
Source Project: ccu-historian   Source File: ShapeUtilities.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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);
}
 
Example 3
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();
    }
}
 
Example 4
Source Project: pumpernickel   Source File: AddRulesTest.java    License: MIT License 6 votes vote down vote up
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;
}
 
Example 5
Source Project: astor   Source File: SymbolAxis.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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);

}
 
Example 6
Source Project: osp   Source File: DrawableShapeLoader.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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$
}
 
Example 7
Source Project: mars-sim   Source File: ZoomSliderPanel.java    License: GNU General Public License v3.0 5 votes vote down vote up
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;
}
 
Example 8
Source Project: plugins   Source File: NpcHighlightOverlay.java    License: GNU General Public License v3.0 5 votes vote down vote up
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);
	}
}
 
Example 9
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);
}
 
Example 10
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);
}
 
Example 11
Source Project: buffer_bci   Source File: LegendGraphic.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 12
Source Project: ET_Redux   Source File: SessionOfStandardView.java    License: Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 13
Source Project: hottub   Source File: PathGraphics.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
  * Redraw a rectanglular area using a proxy graphics
  */
public abstract void redrawRegion(Rectangle2D region,
                                  double scaleX, double scaleY,
                                  Shape clip,
                                  AffineTransform devTransform)

                throws PrinterException ;
 
Example 14
Source Project: jdk8u-dev-jdk   Source File: Underline.java    License: GNU General Public License v2.0 5 votes vote down vote up
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);
}
 
Example 15
Source Project: ECG-Viewer   Source File: FXGraphics2D.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
    }
}
 
Example 16
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));
    }
}
 
Example 17
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);
    }
}
 
Example 18
Source Project: opensim-gui   Source File: BoxAndWhiskerRenderer.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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);

}
 
Example 19
Source Project: brModelo   Source File: LivreBase.java    License: GNU General Public License v3.0 4 votes vote down vote up
public Shape getRegiaoRecArred() {
    if (Regiao == null) {
        Regiao = new RoundRectangle2D.Float(getLeft(), getTop(), getWidth(), getHeight(), getWidth() / 3, getHeight());
    }
    return Regiao;
}
 
Example 20
Source Project: openstock   Source File: ScatterRenderer.java    License: GNU General Public License v3.0 4 votes vote down vote up
/**
 * 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;

}
 
Example 21
Source Project: dragonwell8_jdk   Source File: X11Renderer.java    License: GNU General Public License v2.0 4 votes vote down vote up
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();
    }
}
 
Example 22
Source Project: ECG-Viewer   Source File: ScatterRenderer.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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;

}
 
Example 23
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;
}
 
Example 24
Source Project: openjdk-jdk8u   Source File: TextRenderer.java    License: GNU General Public License v2.0 4 votes vote down vote up
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);
        }
    }
}
 
Example 25
Source Project: megamek   Source File: HexDrawUtilities.java    License: GNU General Public License v2.0 4 votes vote down vote up
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;
}
 
Example 26
/**
 * 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;
}
 
Example 27
Source Project: SIMVA-SoS   Source File: AbstractCategoryItemRenderer.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example 28
Source Project: jdk8u60   Source File: PSPathGraphics.java    License: GNU General Public License v2.0 4 votes vote down vote up
/** 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());


}
 
Example 29
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();
    }
}
 
Example 30
Source Project: megamek   Source File: HexDrawUtilities.java    License: GNU General Public License v2.0 4 votes vote down vote up
private static Shape getHBLU(int hexFace) {
    return getHRU(hexFace).createTransformedShape(getHBLU());
}