Search in sources :

Example 6 with RectangularShape

use of java.awt.geom.RectangularShape in project sis by apache.

the class AffineTransforms2D method transform.

/**
 * Transforms the given shape.
 * This method is similar to {@link AffineTransform#createTransformedShape(Shape)} except that:
 *
 * <ul>
 *   <li>It tries to preserve the shape kind when possible. For example if the given shape
 *       is an instance of {@link RectangularShape} and the given transform does not involve
 *       rotation, then the returned shape may be some instance of the same class.</li>
 *   <li>It tries to recycle the given object if {@code overwrite} is {@code true}.</li>
 * </ul>
 *
 * @param  transform       the affine transform to use.
 * @param  shape           the shape to transform, or {@code null}.
 * @param  allowOverwrite  if {@code true}, this method is allowed to overwrite {@code shape} with the
 *                         transform result. If {@code false}, then {@code shape} is never modified.
 * @return the transform of the given shape, or {@code null} if the given shape was null.
 *         May or may not be the same instance than the given shape.
 *
 * @see AffineTransform#createTransformedShape(Shape)
 */
public static Shape transform(final AffineTransform transform, Shape shape, boolean allowOverwrite) {
    ArgumentChecks.ensureNonNull("transform", transform);
    if (shape == null) {
        return null;
    }
    final int type = transform.getType();
    if (type == TYPE_IDENTITY) {
        return shape;
    }
    /*
         * If there is only scale, flip, quadrant rotation or translation,
         * then we can optimize the transformation of rectangular shapes.
         */
    if ((type & (TYPE_GENERAL_ROTATION | TYPE_GENERAL_TRANSFORM)) == 0) {
        // For a Rectangle input, the output should be a rectangle as well.
        if (shape instanceof Rectangle2D) {
            final Rectangle2D rect = (Rectangle2D) shape;
            return transform(transform, rect, allowOverwrite ? rect : null);
        }
        /*
             * For other rectangular shapes, we restrict to cases without
             * rotation or flip because we don't know if the shape is symmetric.
             */
        if ((type & (TYPE_FLIP | TYPE_MASK_ROTATION)) == 0) {
            if (shape instanceof RectangularShape) {
                RectangularShape rect = (RectangularShape) shape;
                if (!allowOverwrite) {
                    rect = (RectangularShape) rect.clone();
                }
                final Rectangle2D frame = rect.getFrame();
                rect.setFrame(transform(transform, frame, frame));
                return rect;
            }
        }
    }
    if (shape instanceof Path2D) {
        final Path2D path = (Path2D) shape;
        if (allowOverwrite) {
            path.transform(transform);
        } else {
            shape = path.createTransformedShape(transform);
        }
    } else if (shape instanceof Area) {
        final Area area = (Area) shape;
        if (allowOverwrite) {
            area.transform(transform);
        } else {
            shape = area.createTransformedArea(transform);
        }
    } else {
        shape = new Path2D.Double(shape, transform);
    }
    return shape;
}
Also used : Area(java.awt.geom.Area) Path2D(java.awt.geom.Path2D) Rectangle2D(java.awt.geom.Rectangle2D) RectangularShape(java.awt.geom.RectangularShape)

Example 7 with RectangularShape

use of java.awt.geom.RectangularShape in project cubrid-manager by CUBRID.

the class CombinedBarTimeSeriesChart method createBarChart.

/**
	 * Create a bar chart instance.
	 * 
	 * @return a bar chart instance
	 */
private JFreeChart createBarChart() {
    bardataset = new DefaultCategoryDataset();
    if (valueMap != null) {
        for (String key : valueMap.keySet()) {
            bardataset.addValue(0D, key, "");
        }
    }
    bardataset.addValue(barMax, "100", "");
    JFreeChart chart = ChartFactory.createStackedBarChart("", "", "", bardataset, PlotOrientation.VERTICAL, false, false, false);
    chart.setBorderVisible(false);
    chart.setBorderStroke(new BasicStroke(0.0f));
    chart.setBackgroundPaint(Color.BLACK);
    //plot
    CategoryPlot categoryplot = (CategoryPlot) chart.getPlot();
    categoryplot.setOutlineVisible(false);
    RectangleInsets rectangleInsets = new RectangleInsets();
    categoryplot.setAxisOffset(rectangleInsets);
    categoryplot.setBackgroundPaint(Color.BLACK);
    categoryplot.setDomainGridlinesVisible(false);
    categoryplot.setRangeGridlinesVisible(false);
    //renderer
    StackedBarRenderer stackedbarrenderer = (StackedBarRenderer) categoryplot.getRenderer(0);
    stackedbarrenderer.setDrawBarOutline(false);
    stackedbarrenderer.setMaximumBarWidth(0.6);
    stackedbarrenderer.setItemMargin(0);
    //painter
    StandardBarPainter painter = new StandardBarPainter() {

        private static final long serialVersionUID = -3124115075260902181L;

        public void paintBar(Graphics2D g2, BarRenderer renderer, int row, int column, RectangularShape bar, RectangleEdge base) {
            Paint itemPaint = renderer.getItemPaint(row, column);
            GradientPaintTransformer t = renderer.getGradientPaintTransformer();
            if (t != null && itemPaint instanceof GradientPaint) {
                itemPaint = t.transform((GradientPaint) itemPaint, bar);
            }
            g2.setPaint(itemPaint);
            double height = bar.getHeight();
            double width = bar.getWidth();
            double x = bar.getBounds2D().getX();
            double y = bar.getBounds2D().getY();
            int barNumber = (int) (height / 2 + 0.5);
            if (height < 1 && height > 0.5) {
                barNumber = 1;
            }
            for (int i = 0; i < barNumber; i++) {
                RectangularShape subBarLeft = new Rectangle2D.Double(x, y, width / 2, 0.8);
                g2.fill(subBarLeft);
                RectangularShape subBarRight = new Rectangle2D.Double(x + width / 2 + 1, y, width / 2, 0.8);
                g2.fill(subBarRight);
                y += 2;
            }
            if (renderer.isDrawBarOutline()) {
                Stroke stroke = renderer.getItemOutlineStroke(row, column);
                Paint paint = renderer.getItemOutlinePaint(row, column);
                if (stroke != null && paint != null) {
                    g2.setStroke(stroke);
                    g2.setPaint(paint);
                    g2.draw(bar);
                }
            }
        }
    };
    stackedbarrenderer.setBarPainter(painter);
    stackedbarrenderer.setSeriesPaint(0, Color.GREEN);
    stackedbarrenderer.setSeriesPaint(1, Color.RED);
    int backPaintOrder = 1;
    if (valueMap != null) {
        backPaintOrder = valueMap.size();
    }
    stackedbarrenderer.setSeriesPaint(backPaintOrder, new Color(136, 200, 135));
    stackedbarrenderer.setShadowVisible(false);
    stackedbarrenderer.setDrawBarOutline(false);
    //categoryAxis
    categoryAxis = categoryplot.getDomainAxis();
    categoryAxis.setAxisLineVisible(false);
    //	categoryAxis.setCategoryMargin(0);
    categoryAxis.setMinorTickMarksVisible(false);
    categoryAxis.setTickLabelsVisible(false);
    categoryAxis.setTickMarksVisible(false);
    categoryAxis.setLabelPaint(Color.GREEN);
    categoryAxis.setLabelFont(new Font("", 0, 10));
    //valueAxis
    ValueAxis valueAxis = categoryplot.getRangeAxis();
    valueAxis.setVisible(false);
    return chart;
}
Also used : BasicStroke(java.awt.BasicStroke) BasicStroke(java.awt.BasicStroke) Stroke(java.awt.Stroke) StackedBarRenderer(org.jfree.chart.renderer.category.StackedBarRenderer) GradientPaintTransformer(org.jfree.ui.GradientPaintTransformer) Color(java.awt.Color) BarRenderer(org.jfree.chart.renderer.category.BarRenderer) StackedBarRenderer(org.jfree.chart.renderer.category.StackedBarRenderer) GradientPaint(java.awt.GradientPaint) Paint(java.awt.Paint) GradientPaint(java.awt.GradientPaint) JFreeChart(org.jfree.chart.JFreeChart) CategoryPlot(org.jfree.chart.plot.CategoryPlot) Paint(java.awt.Paint) GradientPaint(java.awt.GradientPaint) Font(java.awt.Font) Graphics2D(java.awt.Graphics2D) StandardBarPainter(org.jfree.chart.renderer.category.StandardBarPainter) ValueAxis(org.jfree.chart.axis.ValueAxis) RectangularShape(java.awt.geom.RectangularShape) RectangleInsets(org.jfree.ui.RectangleInsets) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) RectangleEdge(org.jfree.ui.RectangleEdge)

Aggregations

RectangularShape (java.awt.geom.RectangularShape)7 GradientPaint (java.awt.GradientPaint)5 Rectangle (java.awt.Rectangle)3 BasicStroke (java.awt.BasicStroke)2 Paint (java.awt.Paint)2 Color (java.awt.Color)1 Font (java.awt.Font)1 FontMetrics (java.awt.FontMetrics)1 Graphics (java.awt.Graphics)1 Graphics2D (java.awt.Graphics2D)1 Image (java.awt.Image)1 Stroke (java.awt.Stroke)1 AffineTransform (java.awt.geom.AffineTransform)1 Area (java.awt.geom.Area)1 Path2D (java.awt.geom.Path2D)1 Rectangle2D (java.awt.geom.Rectangle2D)1 AffineTransformOp (java.awt.image.AffineTransformOp)1 BufferedImage (java.awt.image.BufferedImage)1 BufferedImageOp (java.awt.image.BufferedImageOp)1 IOException (java.io.IOException)1