Package java.awt.geom

Examples of java.awt.geom.RectangularShape


    String getShapeDesc(Shape shape) {
        String shapeDesc = null;

        if (shape instanceof RectangularShape) {
            RectangularShape rshape = (RectangularShape)shape;
            shapeDesc =
                doubleToStr(rshape.getX()) + "," +
                doubleToStr(rshape.getY()) + "," +
                doubleToStr(rshape.getWidth()) + "," +
                doubleToStr(rshape.getHeight());

            if (shape instanceof Ellipse2D) {
                shapeDesc = "ellipse(" + shapeDesc + ")";
            } else
            if (shape instanceof Rectangle2D) {
View Full Code Here


            }
            // 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) {
View Full Code Here

                              ColorBar colorBar,
                              ContourDataset data,
                              CrosshairState crosshairState) {

        // setup for collecting optional entity info...
        RectangularShape entityArea = null;
        EntityCollection entities = null;
        if (info != null) {
            entities = info.getOwner().getEntityCollection();
        }

//      Rectangle2D.Double rect = null;
//      rect = new Rectangle2D.Double();
        RectangularShape rect = new Ellipse2D.Double();


        //turn off anti-aliasing when filling rectangles
        Object antiAlias = g2.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                RenderingHints.VALUE_ANTIALIAS_OFF);

        // if (tooltips!=null) tooltips.clearToolTips(); // reset collection
        // get the data points
        Number[] xNumber = data.getXValues();
        Number[] yNumber = data.getYValues();
        Number[] zNumber = data.getZValues();

        double[] x = new double[xNumber.length];
        double[] y = new double[yNumber.length];

        for (int i = 0; i < x.length; i++) {
            x[i] = xNumber[i].doubleValue();
            y[i] = yNumber[i].doubleValue();
        }

        double transX = 0.0;
        double transDX = 0.0;
        double transY = 0.0;
        double transDY = 0.0;
        double size = dataArea.getWidth() * this.ptSizePct;
        for (int k = 0; k < x.length; k++) {

            transX = domainAxis.valueToJava2D(x[k], dataArea,
                    RectangleEdge.BOTTOM) - 0.5 * size;
            transY = rangeAxis.valueToJava2D(y[k], dataArea, RectangleEdge.LEFT)
                     - 0.5 * size;
            transDX = size;
            transDY = size;

            rect.setFrame(transX, transY, transDX, transDY);

            if (zNumber[k] != null) {
                g2.setPaint(colorBar.getPaint(zNumber[k].doubleValue()));
                g2.fill(rect);
            }
View Full Code Here

            }
            // For other rectangular shapes, we restrict to cases whithout
            // rotation or flip because we don't know if the shape is symetric.
            if ((type & (TYPE_FLIP & TYPE_MASK_ROTATION)) == 0) {
                if (shape instanceof RectangularShape) {
                    RectangularShape rect = (RectangularShape) shape;
                    if (!overwrite) {
                        rect = (RectangularShape) rect.clone();
                    }
                    final Rectangle2D frame = rect.getFrame();
                    rect.setFrame(transform(transform, frame, frame));
                    return rect;
                }
            }
        }
        // TODO: Check for Path2D instance instead of GeneralPath
View Full Code Here

                              ColorBar colorBar,
                              ContourDataset data,
                              CrosshairState crosshairState) {

        // setup for collecting optional entity info...
        RectangularShape entityArea = null;
        EntityCollection entities = null;
        if (info != null) {
            entities = info.getOwner().getEntityCollection();
        }

//      Rectangle2D.Double rect = null;
//      rect = new Rectangle2D.Double();
        RectangularShape rect = new Ellipse2D.Double();


        //turn off anti-aliasing when filling rectangles
        Object antiAlias = g2.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);

        //      if (tooltips!=null) tooltips.clearToolTips(); // reset collection
        // get the data points
        Number[] xNumber = data.getXValues();
        Number[] yNumber = data.getYValues();
        Number[] zNumber = data.getZValues();

        double[] x = new double[xNumber.length];
        double[] y = new double[yNumber.length];

        for (int i = 0; i < x.length; i++) {
            x[i] = xNumber[i].doubleValue();
            y[i] = yNumber[i].doubleValue();
        }

        double transX = 0.0;
        double transDX = 0.0;
        double transY = 0.0;
        double transDY = 0.0;
        double size = dataArea.getWidth() * this.ptSizePct;
        for (int k = 0; k < x.length; k++) {

            transX = domainAxis.valueToJava2D(x[k], dataArea, RectangleEdge.BOTTOM)
                     - 0.5 * size;
            transY = rangeAxis.valueToJava2D(y[k], dataArea, RectangleEdge.LEFT)
                     - 0.5 * size;
            transDX = size;
            transDY = size;

            rect.setFrame(transX, transY, transDX, transDY);

            if (zNumber[k] != null) {
                g2.setPaint(colorBar.getPaint(zNumber[k].doubleValue()));
                g2.fill(rect);
            }
View Full Code Here

                this.title, this.title, null, true, Color.black,
                new BasicStroke(1.0f), Color.black, new BasicStroke(1.0f)
            );
        }

        RectangularShape legendArea;
        double availableWidth = available.getWidth();
        // the translation point for the origin of the drawing system
        Point2D translation;

        // Create buffer for individual items within the legend
        List items = new ArrayList();

        // Compute individual rectangles in the legend, translation point as well
        // as the bounding box for the legend.
        if (horizontal) {
            double xstart = available.getX() + getOuterGap().getLeftSpace(availableWidth);
            double xlimit = available.getMaxX() - getOuterGap().getRightSpace(availableWidth);
            double maxRowWidth = 0;
            double xoffset = 0;
            double rowHeight = 0;
            double totalHeight = 0;
            boolean wrappingAllowed = true;

            if (titleItem != null) {
                g2.setFont(getTitleFont());

                legendTitle = createDrawableLegendItem(
                    g2, titleItem, xoffset, totalHeight
                );

                rowHeight = Math.max(0, legendTitle.getHeight());
                xoffset += legendTitle.getWidth();
            }

            g2.setFont(this.itemFont);
            for (int i = 0; i < legendItems.getItemCount(); i++) {
                DrawableLegendItem item;
               
                if (this.renderingOrder == LegendRenderingOrder.STANDARD) {
                    item = createDrawableLegendItem(
                        g2, legendItems.get(i), xoffset, totalHeight
                    );
                }
                else if (this.renderingOrder == LegendRenderingOrder.REVERSE) {
                    item = createDrawableLegendItem(
                        g2, legendItems.get(legendItems.getItemCount() - i - 1), xoffset,
                        totalHeight
                    );                       
                }
                else {
                    // we're not supposed to get here, will cause NullPointerException
                    item = null;
                }

                if (item.getMaxX() + xstart > xlimit && wrappingAllowed) {
                    // start a new row
                    maxRowWidth = Math.max(maxRowWidth, xoffset);
                    xoffset = 0;
                    totalHeight += rowHeight;
                    i--; // redo this item in the next row
                    // if item to big to fit, we dont want to attempt wrapping endlessly.
                    // we therefore disable wrapping for at least one item.
                    wrappingAllowed = false
                }
                else {
                    // continue current row
                    rowHeight = Math.max(rowHeight, item.getHeight());
                    xoffset += item.getWidth();
                    // we placed an item in this row, re-allow wrapping for next item.
                    wrappingAllowed = true;
                    items.add(item);
                }
            }

            maxRowWidth = Math.max(maxRowWidth, xoffset);
            totalHeight += rowHeight;

            // Create the bounding box
            legendArea = new RoundRectangle2D.Double(
                0, 0, maxRowWidth, totalHeight, this.boundingBoxArcWidth, this.boundingBoxArcHeight
            );

            translation = createTranslationPointForHorizontalDraw(
                available, inverted, maxRowWidth, totalHeight
            );
        }
        else // vertical...
            double totalHeight = 0;
            double maxWidth = (this.preferredWidth == NO_PREFERRED_WIDTH) ? 0 : this.preferredWidth;
           
            if (titleItem != null) {
                g2.setFont(getTitleFont());

                legendTitle = createDrawableLegendItem(g2, titleItem, 0, totalHeight);

                totalHeight += legendTitle.getHeight();
                maxWidth = Math.max(maxWidth, legendTitle.getWidth());
            }

            g2.setFont(this.itemFont);
           
            int legendItemsLength = legendItems.getItemCount();
            for (int i = 0; i < legendItemsLength; i++) {
                List drawableParts;
               
                if (this.renderingOrder == LegendRenderingOrder.STANDARD) {
                    drawableParts = createAllDrawableLinesForItem(g2,
                            legendItems.get(i), 0, totalHeight, maxWidth);
                }
                else if (this.renderingOrder == LegendRenderingOrder.REVERSE) {
                    drawableParts = createAllDrawableLinesForItem(
                        g2, legendItems.get(legendItemsLength - i - 1), 0, totalHeight, maxWidth
                    );
                }
                else {
                    // we're not supposed to get here, will cause NullPointerException
                    drawableParts = null;
                }
               
                for (Iterator j = drawableParts.iterator(); j.hasNext();) {
                    DrawableLegendItem item = (DrawableLegendItem) j.next();
                   
                    totalHeight += item.getHeight();
                    maxWidth = Math.max(maxWidth, item.getWidth());
                   
                    items.add(item);
                }
            }

            // Create the bounding box
            legendArea = new RoundRectangle2D.Float(
                0, 0, (float) maxWidth, (float) totalHeight,
                this.boundingBoxArcWidth, this.boundingBoxArcHeight
            );

            translation = createTranslationPointForVerticalDraw(
                available, inverted, totalHeight, maxWidth
            );
        }

        // Move the origin of the drawing to the appropriate location
        g2.translate(translation.getX(), translation.getY());

        LOGGER.debug("legendArea = " + legendArea.getWidth() + ", " + legendArea.getHeight());
        drawLegendBox(g2, legendArea);
        drawLegendTitle(g2, legendTitle);
        drawSeriesElements(g2, items, translation, info);

        // translate the origin back to what it was prior to drawing the legend
View Full Code Here

    {
        double x, y, w, h, lw, lw2;
       
        if ( shape instanceof RectangularShape ) {
            // this covers rectangle, rounded rectangle, ellipse, and arcs
            RectangularShape r = (RectangularShape)shape;
            x = r.getX();
            y = r.getY();
            w = r.getWidth();
            h = r.getHeight();
        } else if ( shape instanceof Line2D ) {
            // this covers straight lines
            Line2D l = (Line2D)shape;
            x = l.getX1();
            y = l.getY1();
            w = l.getX2();
            h = l.getY2();
            if ( w < x ) {
                lw = x;
                x = w;
                w = lw-x;
            } else {
                w = w-x;
            }
            if ( h < y ) {
                lw = y;
                y = h;
                h = lw-y;
            } else {
                h = h-y;
            }
        } else {
            // this covers any other arbitrary shapes, but
            // takes a small object allocation / garbage collection hit
            Rectangle2D r = shape.getBounds2D();
            x = r.getX();
            y = r.getY();
            w = r.getWidth();
            h = r.getHeight();
        }
       
        // adjust boundary for stoke length as necessary
        if ( stroke != null && (lw=stroke.getLineWidth()) > 1 ) {
            lw2 = lw/2.0;
View Full Code Here

            if (fdraw) { g.setPaint(fillColor);   g.fill(shape); }
            if (sdraw) { g.setPaint(strokeColor); g.draw(shape); }
        }
        else if ( shape instanceof RectangularShape )
        {
            RectangularShape r = (RectangularShape)shape;
            xx = r.getX(); ww = r.getWidth();
            yy = r.getY(); hh = r.getHeight();
           
            x = (int)xx;
            y = (int)yy;
            w = (int)(ww+xx-x);
            h = (int)(hh+yy-y);
View Full Code Here

   
    /**
     * @see prefuse.render.Renderer#render(java.awt.Graphics2D, prefuse.visual.VisualItem)
     */
    public void render(Graphics2D g, VisualItem item) {
        RectangularShape shape = (RectangularShape)getShape(item);
        if ( shape == null ) return;
       
        // fill the shape, if requested
        int type = getRenderType(item);
        if ( type==RENDER_TYPE_FILL || type==RENDER_TYPE_DRAW_AND_FILL )
            GraphicsLib.paint(g, item, shape, getStroke(item), RENDER_TYPE_FILL);

        // now render the image and text
        String text = m_text;
        Image  img  = getImage(item);
       
        if ( text == null && img == null )
            return;
                       
        double size = item.getSize();
        boolean useInt = 1.5 > Math.max(g.getTransform().getScaleX(),
                                        g.getTransform().getScaleY());
        double x = shape.getMinX() + size*m_horizBorder;
        double y = shape.getMinY() + size*m_vertBorder;
       
        // render image
        if ( img != null ) {           
            double w = size * img.getWidth(null);
            double h = size * img.getHeight(null);
            double ix=x, iy=y;
           
            // determine one co-ordinate based on the image position
            switch ( m_imagePos ) {
            case Constants.LEFT:
                x += w + size*m_imageMargin;
                break;
            case Constants.RIGHT:
                ix = shape.getMaxX() - size*m_horizBorder - w;
                break;
            case Constants.TOP:
                y += h + size*m_imageMargin;
                break;
            case Constants.BOTTOM:
                iy = shape.getMaxY() - size*m_vertBorder - h;
                break;
            default:
                throw new IllegalStateException(
                        "Unrecognized image alignment setting.");
            }
           
            // determine the other coordinate based on image alignment
            switch ( m_imagePos ) {
            case Constants.LEFT:
            case Constants.RIGHT:
                // need to set image y-coordinate
                switch ( m_vImageAlign ) {
                case Constants.TOP:
                    break;
                case Constants.BOTTOM:
                    iy = shape.getMaxY() - size*m_vertBorder - h;
                    break;
                case Constants.CENTER:
                    iy = shape.getCenterY() - h/2;
                    break;
                }
                break;
            case Constants.TOP:
            case Constants.BOTTOM:
                // need to set image x-coordinate
                switch ( m_hImageAlign ) {
                case Constants.LEFT:
                    break;
                case Constants.RIGHT:
                    ix = shape.getMaxX() - size*m_horizBorder - w;
                    break;
                case Constants.CENTER:
                    ix = shape.getCenterX() - w/2;
                    break;
                }
                break;
            }
           
            if ( useInt && size == 1.0 ) {
                // if possible, use integer precision
                // results in faster, flicker-free image rendering
                g.drawImage(img, (int)ix, (int)iy, null);
            } else {
                m_transform.setTransform(size,0,0,size,ix,iy);
                g.drawImage(img, m_transform, null);
            }
        }
       
        // render text
        int textColor = item.getTextColor();
        if ( text != null && ColorLib.alpha(textColor) > 0 ) {
            g.setPaint(ColorLib.getColor(textColor));
            g.setFont(m_font);
            FontMetrics fm = DEFAULT_GRAPHICS.getFontMetrics(m_font);

            // compute available width
            double tw;
            switch ( m_imagePos ) {
            case Constants.TOP:
            case Constants.BOTTOM:
                tw = shape.getWidth() - 2*size*m_horizBorder;
                break;
            default:
                tw = m_textDim.width;
            }
           
            // compute available height
            double th;
            switch ( m_imagePos ) {
            case Constants.LEFT:
            case Constants.RIGHT:
                th = shape.getHeight() - 2*size*m_vertBorder;
                break;
            default:
                th = m_textDim.height;
            }
           
View Full Code Here

                              ColorBar colorBar,
                              ContourDataset data,
                              CrosshairState crosshairState) {

        // setup for collecting optional entity info...
        RectangularShape entityArea = null;
        EntityCollection entities = null;
        if (info != null) {
            entities = info.getOwner().getEntityCollection();
        }

//      Rectangle2D.Double rect = null;
//      rect = new Rectangle2D.Double();
        RectangularShape rect = new Ellipse2D.Double();


        //turn off anti-aliasing when filling rectangles
        Object antiAlias = g2.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                RenderingHints.VALUE_ANTIALIAS_OFF);

        // if (tooltips!=null) tooltips.clearToolTips(); // reset collection
        // get the data points
        Number[] xNumber = data.getXValues();
        Number[] yNumber = data.getYValues();
        Number[] zNumber = data.getZValues();

        double[] x = new double[xNumber.length];
        double[] y = new double[yNumber.length];

        for (int i = 0; i < x.length; i++) {
            x[i] = xNumber[i].doubleValue();
            y[i] = yNumber[i].doubleValue();
        }

        double transX = 0.0;
        double transDX = 0.0;
        double transY = 0.0;
        double transDY = 0.0;
        double size = dataArea.getWidth() * this.ptSizePct;
        for (int k = 0; k < x.length; k++) {

            transX = domainAxis.valueToJava2D(x[k], dataArea,
                    RectangleEdge.BOTTOM) - 0.5 * size;
            transY = rangeAxis.valueToJava2D(y[k], dataArea, RectangleEdge.LEFT)
                     - 0.5 * size;
            transDX = size;
            transDY = size;

            rect.setFrame(transX, transY, transDX, transDY);

            if (zNumber[k] != null) {
                g2.setPaint(colorBar.getPaint(zNumber[k].doubleValue()));
                g2.fill(rect);
            }
View Full Code Here

TOP

Related Classes of java.awt.geom.RectangularShape

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.