Example usage for java.awt.geom Rectangle2D getHeight

List of usage examples for java.awt.geom Rectangle2D getHeight

Introduction

In this page you can find the example usage for java.awt.geom Rectangle2D getHeight.

Prototype

public abstract double getHeight();

Source Link

Document

Returns the height of the framing rectangle in double precision.

Usage

From source file:org.yccheok.jstock.gui.charting.InvestmentFlowLayerUI.java

private void drawInformationBox(Graphics2D g2, Activities activities, Rectangle2D rect, List<String> params,
        List<String> values, String totalParam, double totalValue, Color background_color, Color border_color) {
    final Font oldFont = g2.getFont();
    final Font paramFont = oldFont;
    final FontMetrics paramFontMetrics = g2.getFontMetrics(paramFont);
    final Font valueFont = oldFont.deriveFont(oldFont.getStyle() | Font.BOLD, (float) oldFont.getSize() + 1);
    final FontMetrics valueFontMetrics = g2.getFontMetrics(valueFont);
    final Font dateFont = oldFont.deriveFont((float) oldFont.getSize() - 1);
    final FontMetrics dateFontMetrics = g2.getFontMetrics(dateFont);

    final int x = (int) rect.getX();
    final int y = (int) rect.getY();
    final int width = (int) rect.getWidth();
    final int height = (int) rect.getHeight();

    final Object oldValueAntiAlias = g2.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
    final Composite oldComposite = g2.getComposite();
    final Color oldColor = g2.getColor();

    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setColor(border_color);//from  w  w  w  . j a  va 2  s .  c  o  m
    g2.drawRoundRect(x - 1, y - 1, width + 1, height + 1, 15, 15);
    g2.setColor(background_color);
    g2.setComposite(Utils.makeComposite(0.75f));
    g2.fillRoundRect(x, y, width, height, 15, 15);
    g2.setComposite(oldComposite);
    g2.setColor(oldColor);

    final Date date = activities.getDate().getTime();
    final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("EEEE, MMMM d, yyyy");
    final String dateString = simpleDateFormat.format(date);

    final int padding = 5;

    int yy = y + padding + dateFontMetrics.getAscent();
    g2.setFont(dateFont);
    g2.setColor(COLOR_BLUE);
    g2.drawString(dateString, ((width - dateFontMetrics.stringWidth(dateString)) >> 1) + x, yy);

    int index = 0;
    final int dateInfoHeightMargin = 5;
    final int infoTotalHeightMargin = 5;
    final int paramValueHeightMargin = 0;

    yy += dateFontMetrics.getDescent() + dateInfoHeightMargin
            + Math.max(paramFontMetrics.getAscent(), valueFontMetrics.getAscent());
    for (String param : params) {
        final String value = values.get(index++);
        g2.setColor(Color.BLACK);
        g2.setFont(paramFont);
        g2.drawString(param + ":", padding + x, yy);
        g2.setFont(valueFont);
        g2.drawString(value, width - padding - valueFontMetrics.stringWidth(value) + x, yy);
        // Same as yy += valueFontMetrics.getDescent() + paramValueHeightMargin + valueFontMetrics.getAscent()
        yy += paramValueHeightMargin + Math.max(paramFontMetrics.getHeight(), valueFontMetrics.getHeight());
    }

    if (values.size() > 1) {
        yy -= paramValueHeightMargin;
        yy += infoTotalHeightMargin;
        if (totalValue > 0.0) {
            g2.setColor(JStockOptions.DEFAULT_HIGHER_NUMERICAL_VALUE_FOREGROUND_COLOR);
        } else if (totalValue < 0.0) {
            g2.setColor(JStockOptions.DEFAULT_LOWER_NUMERICAL_VALUE_FOREGROUND_COLOR);
        }

        g2.setFont(paramFont);
        g2.drawString(totalParam + ":", padding + x, yy);
        g2.setFont(valueFont);
        final DecimalPlace decimalPlace = JStock.instance().getJStockOptions().getDecimalPlace();
        final String totalValueStr = org.yccheok.jstock.portfolio.Utils.toCurrencyWithSymbol(decimalPlace,
                totalValue);
        g2.drawString(totalValueStr, width - padding - valueFontMetrics.stringWidth(totalValueStr) + x, yy);
    }

    g2.setColor(oldColor);
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, oldValueAntiAlias);
    g2.setFont(oldFont);
}

From source file:org.gvsig.remotesensing.scatterplot.chart.ScatterPlotDiagram.java

/**
 * Handles a 'mouse released' event.  On Windows, we need to check if this 
 * is a popup trigger, but only if we haven't already been tracking a zoom
 * rectangle./*  ww w  . java  2  s .  co  m*/
 *
 * @param e  information about the event.
 */
public void mouseReleased(MouseEvent e) {

    if (this.zoomRectangle != null) {
        boolean hZoom = false;
        boolean vZoom = false;
        if (this.orientation == PlotOrientation.HORIZONTAL) {
            hZoom = this.rangeZoomable;
            vZoom = this.domainZoomable;
        } else {
            hZoom = this.domainZoomable;
            vZoom = this.rangeZoomable;
        }

        boolean zoomTrigger1 = hZoom && Math.abs(e.getX() - this.zoomPoint.getX()) >= this.zoomTriggerDistance;
        boolean zoomTrigger2 = vZoom && Math.abs(e.getY() - this.zoomPoint.getY()) >= this.zoomTriggerDistance;
        if (zoomTrigger1 || zoomTrigger2) {
            if ((hZoom && (e.getX() < this.zoomPoint.getX()))
                    || (vZoom && (e.getY() < this.zoomPoint.getY()))) {
                // restoreAutoBounds();
            } else {
                double x, y, w, h;
                Rectangle2D screenDataArea = getScreenDataArea((int) this.zoomPoint.getX(),
                        (int) this.zoomPoint.getY());
                // for mouseReleased event, (horizontalZoom || verticalZoom)
                // will be true, so we can just test for either being false;
                // otherwise both are true
                if (!vZoom) {
                    x = this.zoomPoint.getX();
                    y = screenDataArea.getMinY();
                    w = Math.min(this.zoomRectangle.getWidth(),
                            screenDataArea.getMaxX() - this.zoomPoint.getX());
                    h = screenDataArea.getHeight();
                } else if (!hZoom) {
                    x = screenDataArea.getMinX();
                    y = this.zoomPoint.getY();
                    w = screenDataArea.getWidth();
                    h = Math.min(this.zoomRectangle.getHeight(),
                            screenDataArea.getMaxY() - this.zoomPoint.getY());
                } else {
                    x = this.zoomPoint.getX();
                    y = this.zoomPoint.getY();
                    w = Math.min(this.zoomRectangle.getWidth(),
                            screenDataArea.getMaxX() - this.zoomPoint.getX());
                    h = Math.min(this.zoomRectangle.getHeight(),
                            screenDataArea.getMaxY() - this.zoomPoint.getY());
                }
                if (activeROI != null) {
                    Rectangle2D rectangleArea = new Rectangle2D.Double(x, y, w, h);
                    g2 = (Graphics2D) getGraphics();
                    g2.setPaint(activeROI.getColor());
                    g2.draw(rectangleArea);
                    activeROI.add(rectangleArea, getRange(rectangleArea));
                    RoiFromChartProcess process = new RoiFromChartProcess();
                    process.addParam("roi", activeROI);
                    process.addParam("raster", (FLyrRasterSE) rasterSE);
                    process.setActions(this);
                    process.start();
                    if (gestorRois != null) {
                        // Cargar la nueva ROI en el destor
                        gestorRois.clearRoiGraphics();
                    }
                }

            }
            this.zoomPoint = null;
            this.zoomRectangle = null;
            updateUI();
        } else {
            // Erase the zoom rectangle
            Graphics2D g2 = (Graphics2D) getGraphics();
            drawRectangle(g2);
            g2.dispose();
            this.zoomPoint = null;
            this.zoomRectangle = null;
        }

    }

    else if (e.isPopupTrigger()) {
        if (this.popup != null) {
            displayPopupMenu(e.getX(), e.getY());
        }
    }
}

From source file:ucar.unidata.idv.control.chart.TimeSeriesChartWrapper.java

/**
 * Is mouse on bottom axis/* w  w  w. jav  a 2 s  .  c o  m*/
 *
 * @param mouseEvent the event
 *
 * @return on bottom axis
 */
private boolean isOnBottomDomainAxis(MouseEvent mouseEvent) {
    Rectangle2D dataArea = chartPanel.getScreenDataArea();
    if (mouseEvent.getX() < dataArea.getX()) {
        return false;
    }
    if (mouseEvent.getX() > dataArea.getX() + dataArea.getWidth()) {
        return false;
    }

    double bottom = dataArea.getY() + dataArea.getHeight();
    return mouseEvent.getY() >= bottom - 20;
}

From source file:de.laures.cewolf.jfree.ThermometerPlot.java

/**
 * Draws the plot on a Java 2D graphics device (such as the screen or a printer).
 *
 * @param g2  the graphics device.//from w ww.  j  a v  a2s.c o  m
 * @param area  the area within which the plot should be drawn.
 * @param anchor  the anchor point (<code>null</code> permitted).
 * @param parentState  the state from the parent plot, if there is one.
 * @param info  collects info about the drawing.
 */
public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState,
        PlotRenderingInfo info) {

    RoundRectangle2D outerStem = new RoundRectangle2D.Double();
    RoundRectangle2D innerStem = new RoundRectangle2D.Double();
    RoundRectangle2D mercuryStem = new RoundRectangle2D.Double();
    Ellipse2D outerBulb = new Ellipse2D.Double();
    Ellipse2D innerBulb = new Ellipse2D.Double();
    String temp = null;
    FontMetrics metrics = null;
    if (info != null) {
        info.setPlotArea(area);
    }

    // adjust for insets...
    RectangleInsets insets = getInsets();
    insets.trim(area);
    drawBackground(g2, area);

    // adjust for padding...
    Rectangle2D interior = (Rectangle2D) area.clone();
    this.padding.trim(interior);
    int midX = (int) (interior.getX() + (interior.getWidth() / 2));
    int midY = (int) (interior.getY() + (interior.getHeight() / 2));
    int stemTop = (int) (interior.getMinY() + getBulbRadius());
    int stemBottom = (int) (interior.getMaxY() - getBulbDiameter());
    Rectangle2D dataArea = new Rectangle2D.Double(midX - getColumnRadius(), stemTop, getColumnRadius(),
            stemBottom - stemTop);

    outerBulb.setFrame(midX - getBulbRadius(), stemBottom, getBulbDiameter(), getBulbDiameter());

    outerStem.setRoundRect(midX - getColumnRadius(), interior.getMinY(), getColumnDiameter(),
            stemBottom + getBulbDiameter() - stemTop, getColumnDiameter(), getColumnDiameter());

    Area outerThermometer = new Area(outerBulb);
    Area tempArea = new Area(outerStem);
    outerThermometer.add(tempArea);

    innerBulb.setFrame(midX - getBulbRadius() + getGap(), stemBottom + getGap(),
            getBulbDiameter() - getGap() * 2, getBulbDiameter() - getGap() * 2);

    innerStem.setRoundRect(midX - getColumnRadius() + getGap(), interior.getMinY() + getGap(),
            getColumnDiameter() - getGap() * 2, stemBottom + getBulbDiameter() - getGap() * 2 - stemTop,
            getColumnDiameter() - getGap() * 2, getColumnDiameter() - getGap() * 2);

    Area innerThermometer = new Area(innerBulb);
    tempArea = new Area(innerStem);
    innerThermometer.add(tempArea);

    if ((this.dataset != null) && (this.dataset.getValue() != null)) {
        double current = this.dataset.getValue().doubleValue();
        double ds = this.rangeAxis.valueToJava2D(current, dataArea, RectangleEdge.LEFT);

        int i = getColumnDiameter() - getGap() * 2; // already calculated
        int j = getColumnRadius() - getGap(); // already calculated
        int l = (i / 2);
        int k = (int) Math.round(ds);
        if (k < (getGap() + interior.getMinY())) {
            k = (int) (getGap() + interior.getMinY());
            l = getBulbRadius();
        }

        Area mercury = new Area(innerBulb);

        if (k < (stemBottom + getBulbRadius())) {
            mercuryStem.setRoundRect(midX - j, k, i, (stemBottom + getBulbRadius()) - k, l, l);
            tempArea = new Area(mercuryStem);
            mercury.add(tempArea);
        }

        g2.setPaint(getCurrentPaint());
        g2.fill(mercury);

        // draw range indicators...
        if (this.subrangeIndicatorsVisible) {
            g2.setStroke(this.subrangeIndicatorStroke);
            Range range = this.rangeAxis.getRange();

            // draw start of normal range
            double value = this.subrangeInfo[NORMAL][RANGE_LOW];
            if (range.contains(value)) {
                double x = midX + getColumnRadius() + 2;
                double y = this.rangeAxis.valueToJava2D(value, dataArea, RectangleEdge.LEFT);
                Line2D line = new Line2D.Double(x, y, x + 10, y);
                g2.setPaint(this.subrangePaint[NORMAL]);
                g2.draw(line);
            }

            // draw start of warning range
            value = this.subrangeInfo[WARNING][RANGE_LOW];
            if (range.contains(value)) {
                double x = midX + getColumnRadius() + 2;
                double y = this.rangeAxis.valueToJava2D(value, dataArea, RectangleEdge.LEFT);
                Line2D line = new Line2D.Double(x, y, x + 10, y);
                g2.setPaint(this.subrangePaint[WARNING]);
                g2.draw(line);
            }

            // draw start of critical range
            value = this.subrangeInfo[CRITICAL][RANGE_LOW];
            if (range.contains(value)) {
                double x = midX + getColumnRadius() + 2;
                double y = this.rangeAxis.valueToJava2D(value, dataArea, RectangleEdge.LEFT);
                Line2D line = new Line2D.Double(x, y, x + 10, y);
                g2.setPaint(this.subrangePaint[CRITICAL]);
                g2.draw(line);
            }
        }

        // draw the axis...
        if ((this.rangeAxis != null) && (this.axisLocation != NONE)) {
            int drawWidth = AXIS_GAP;
            Rectangle2D drawArea;
            double cursor = 0;

            switch (this.axisLocation) {
            case RIGHT:
                cursor = midX + getColumnRadius();
                drawArea = new Rectangle2D.Double(cursor, stemTop, drawWidth, (stemBottom - stemTop + 1));
                this.rangeAxis.draw(g2, cursor, area, drawArea, RectangleEdge.RIGHT, null);
                break;

            case LEFT:
            default:
                //cursor = midX - COLUMN_RADIUS - AXIS_GAP;
                cursor = midX - getColumnRadius();
                drawArea = new Rectangle2D.Double(cursor, stemTop, drawWidth, (stemBottom - stemTop + 1));
                this.rangeAxis.draw(g2, cursor, area, drawArea, RectangleEdge.LEFT, null);
                break;
            }

        }

        // draw text value on screen
        g2.setFont(this.valueFont);
        g2.setPaint(this.valuePaint);
        metrics = g2.getFontMetrics();
        switch (this.valueLocation) {
        case RIGHT:
            g2.drawString(this.valueFormat.format(current), midX + getColumnRadius() + getGap(), midY);
            break;
        case LEFT:
            String valueString = this.valueFormat.format(current);
            int stringWidth = metrics.stringWidth(valueString);
            g2.drawString(valueString, midX - getColumnRadius() - getGap() - stringWidth, midY);
            break;
        case BULB:
            temp = this.valueFormat.format(current);
            i = metrics.stringWidth(temp) / 2;
            g2.drawString(temp, midX - i, stemBottom + getBulbRadius() + getGap());
            break;
        default:
        }
        /***/
    }

    g2.setPaint(this.thermometerPaint);
    g2.setFont(this.valueFont);

    //  draw units indicator
    metrics = g2.getFontMetrics();
    int tickX1 = midX - getColumnRadius() - getGap() * 2 - metrics.stringWidth(UNITS[this.units]);
    if (tickX1 > area.getMinX()) {
        g2.drawString(UNITS[this.units], tickX1, (int) (area.getMinY() + 20));
    }

    // draw thermometer outline
    g2.setStroke(this.thermometerStroke);
    g2.draw(outerThermometer);
    g2.draw(innerThermometer);

    drawOutline(g2, area);
}

From source file:org.gumtree.vis.plot1d.Plot1DPanel.java

private void drawInternalLegend(Graphics2D g2) {
    //      XYDataset dataset = getXYPlot().getDataset();
    //      int numSeries = dataset.getSeriesCount();
    Rectangle2D screenArea = getScreenDataArea();
    Rectangle2D lengendArea = new Rectangle2D.Double(screenArea.getMaxX() - internalLegendSetup.getMinX(),
            screenArea.getMinY() + internalLegendSetup.getMinY(), internalLegendSetup.getWidth(),
            internalLegendSetup.getHeight());
    LegendTitle legend = new LegendTitle(getXYPlot());
    RectangleConstraint rc = new RectangleConstraint(new Range(0, internalLegendSetup.getWidth()),
            new Range(0, internalLegendSetup.getHeight()));
    Size2D size = legend.arrange(g2, rc);
    getXYPlot().getLegendItems();//  w  ww  . jav a2  s . co  m
    legend.draw(g2, lengendArea);
    Rectangle2D titleRect = new Rectangle2D.Double(lengendArea.getMinX(), lengendArea.getMinY(), size.width,
            size.height);
    internalLegendSetup.setRect(internalLegendSetup.getX(), internalLegendSetup.getY(), titleRect.getWidth(),
            titleRect.getHeight());
    if (isInternalLegendSelected) {
        ChartMaskingUtilities.drawMaskBoarder(g2, titleRect);
    } else {
        g2.setColor(Color.GRAY);
        g2.draw(titleRect);
    }
}

From source file:org.jfree.experimental.chart.annotations.XYTitleAnnotation.java

/**
 * Draws the annotation.  This method is called by the drawing code in the 
 * {@link XYPlot} class, you don't normally need to call this method 
 * directly.//from   w w w.  ja  va  2 s  .  co  m
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param dataArea  the data area.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param rendererIndex  the renderer index.
 * @param info  if supplied, this info object will be populated with
 *              entity information.
 */
public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis,
        int rendererIndex, PlotRenderingInfo info) {

    PlotOrientation orientation = plot.getOrientation();
    AxisLocation domainAxisLocation = plot.getDomainAxisLocation();
    AxisLocation rangeAxisLocation = plot.getRangeAxisLocation();
    RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(domainAxisLocation, orientation);
    RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(rangeAxisLocation, orientation);
    Range xRange = domainAxis.getRange();
    Range yRange = rangeAxis.getRange();
    double anchorX = 0.0;
    double anchorY = 0.0;
    if (this.coordinateType == XYCoordinateType.RELATIVE) {
        anchorX = xRange.getLowerBound() + (this.x * xRange.getLength());
        anchorY = yRange.getLowerBound() + (this.y * yRange.getLength());
    } else {
        anchorX = domainAxis.valueToJava2D(this.x, dataArea, domainEdge);
        anchorY = rangeAxis.valueToJava2D(this.y, dataArea, rangeEdge);
    }

    float j2DX = (float) domainAxis.valueToJava2D(anchorX, dataArea, domainEdge);
    float j2DY = (float) rangeAxis.valueToJava2D(anchorY, dataArea, rangeEdge);
    float xx = 0.0f;
    float yy = 0.0f;
    if (orientation == PlotOrientation.HORIZONTAL) {
        xx = j2DY;
        yy = j2DX;
    } else if (orientation == PlotOrientation.VERTICAL) {
        xx = j2DX;
        yy = j2DY;
    }

    double maxW = dataArea.getWidth();
    double maxH = dataArea.getHeight();
    if (this.coordinateType == XYCoordinateType.RELATIVE) {
        if (this.maxWidth > 0.0) {
            maxW = maxW * this.maxWidth;
        }
        if (this.maxHeight > 0.0) {
            maxH = maxH * this.maxHeight;
        }
    }
    if (this.coordinateType == XYCoordinateType.DATA) {
        maxW = this.maxWidth;
        maxH = this.maxHeight;
    }
    RectangleConstraint rc = new RectangleConstraint(new Range(0, maxW), new Range(0, maxH));

    Size2D size = this.title.arrange(g2, rc);
    Rectangle2D titleRect = new Rectangle2D.Double(0, 0, size.width, size.height);
    Point2D anchorPoint = RectangleAnchor.coordinates(titleRect, this.anchor);
    xx = xx - (float) anchorPoint.getX();
    yy = yy - (float) anchorPoint.getY();
    titleRect.setRect(xx, yy, titleRect.getWidth(), titleRect.getHeight());
    BlockParams p = new BlockParams();
    if (info != null) {
        if (info.getOwner().getEntityCollection() != null) {
            p.setGenerateEntities(true);
        }
    }
    Object result = this.title.draw(g2, titleRect, p);
    if (result instanceof EntityBlockResult) {
        EntityBlockResult ebr = (EntityBlockResult) result;
        info.getOwner().getEntityCollection().addAll(ebr.getEntityCollection());
    }
    String toolTip = getToolTipText();
    String url = getURL();
    if (toolTip != null || url != null) {
        addEntity(info, new Rectangle2D.Float(xx, yy, (float) size.width, (float) size.height), rendererIndex,
                toolTip, url);
    }
}

From source file:com.controlj.addon.gwttree.server.OpaqueBarRenderer3D.java

@Override
public void drawBackground(Graphics2D g2, CategoryPlot plot, Rectangle2D dataArea) {

    float x0 = (float) dataArea.getX();
    float x1 = x0 + (float) Math.abs(getXOffset());
    float x3 = (float) dataArea.getMaxX();
    float x2 = x3 - (float) Math.abs(getXOffset());

    float y0 = (float) dataArea.getMaxY();
    float y1 = y0 - (float) Math.abs(getYOffset());
    float y3 = (float) dataArea.getMinY();
    float y2 = y3 + (float) Math.abs(getYOffset());

    GeneralPath clip = new GeneralPath();
    clip.moveTo(x0, y0);//  w w w .j  a va 2  s  .c o  m
    clip.lineTo(x0, y2);
    clip.lineTo(x1, y3);
    clip.lineTo(x3, y3);
    clip.lineTo(x3, y1);
    clip.lineTo(x2, y0);
    clip.closePath();

    Composite originalComposite = g2.getComposite();
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, plot.getBackgroundAlpha()));

    // fill background...
    Paint backgroundPaint = plot.getBackgroundPaint();
    if (backgroundPaint != null) {
        g2.setPaint(backgroundPaint);
        g2.fill(clip);
    }

    GeneralPath bottomWall = new GeneralPath();
    bottomWall.moveTo(x0, y0);
    bottomWall.lineTo(x1, y1);
    bottomWall.lineTo(x3, y1);
    bottomWall.lineTo(x2, y0);
    bottomWall.closePath();
    g2.setPaint(getWallPaint());
    g2.fill(bottomWall);

    // draw background image, if there is one...
    Image backgroundImage = plot.getBackgroundImage();
    if (backgroundImage != null) {
        Rectangle2D adjusted = new Rectangle2D.Double(dataArea.getX() + getXOffset(), dataArea.getY(),
                dataArea.getWidth() - getXOffset(), dataArea.getHeight() - getYOffset());
        plot.drawBackgroundImage(g2, adjusted);
    }

    g2.setComposite(originalComposite);

}

From source file:org.gvsig.remotesensing.scatterplot.chart.ScatterPlotDiagram.java

/**
 * Handles a 'mouse dragged' event.// w w w.  j ava  2 s  .c o  m
 *
 * @param e  the mouse event.
 */
public void mouseDragged(MouseEvent e) {

    // if the popup menu has already been triggered, then ignore dragging...
    if (this.popup != null && this.popup.isShowing()) {
        return;
    }
    // if no initial zoom point was set, ignore dragging...
    if (this.zoomPoint == null) {
        return;
    }
    Graphics2D g2 = (Graphics2D) getGraphics();

    // Erase the previous zoom rectangle (if any)...
    drawRectangle(g2);

    boolean hZoom = false;
    boolean vZoom = false;
    if (this.orientation == PlotOrientation.HORIZONTAL) {
        hZoom = this.rangeZoomable;
        vZoom = this.domainZoomable;
    } else {
        hZoom = this.domainZoomable;
        vZoom = this.rangeZoomable;
    }
    Rectangle2D scaledDataArea = getScreenDataArea((int) this.zoomPoint.getX(), (int) this.zoomPoint.getY());
    if (hZoom && vZoom) {
        // selected rectangle shouldn't extend outside the data area...
        double xmax = Math.min(e.getX(), scaledDataArea.getMaxX());
        double ymax = Math.min(e.getY(), scaledDataArea.getMaxY());
        this.zoomRectangle = new Rectangle2D.Double(this.zoomPoint.getX(), this.zoomPoint.getY(),
                xmax - this.zoomPoint.getX(), ymax - this.zoomPoint.getY());
    } else if (hZoom) {
        double xmax = Math.min(e.getX(), scaledDataArea.getMaxX());
        this.zoomRectangle = new Rectangle2D.Double(this.zoomPoint.getX(), scaledDataArea.getMinY(),
                xmax - this.zoomPoint.getX(), scaledDataArea.getHeight());
    } else if (vZoom) {
        double ymax = Math.min(e.getY(), scaledDataArea.getMaxY());
        this.zoomRectangle = new Rectangle2D.Double(scaledDataArea.getMinX(), this.zoomPoint.getY(),
                scaledDataArea.getWidth(), ymax - this.zoomPoint.getY());
    }

    // Draw the new zoom rectangle...
    drawRectangle(g2);
    g2.dispose();
}

From source file:org.squidy.designer.shape.ZoomShape.java

/**
 * @param goalDirectedZoom/*from   www  .  j  av a 2s. c  o  m*/
 */
public ZoomShape(boolean goalDirectedZoom) {
    setBounds(Constants.DEFAULT_NODE_BOUNDS);

    if (goalDirectedZoom) {
        addInputEventListener(new PBasicInputEventHandler() {

            @Override
            public void mouseClicked(PInputEvent event) {
                if (!event.isHandled() && event.isLeftMouseButton() && event.getClickCount() == 2) {

                    PNode store = event.getPickedNode();
                    while (store != null && !(store instanceof IModelStore)) {
                        store = store.getParent();
                    }

                    PNode node = event.getPickedNode();
                    while (node != null && !(node instanceof ZoomShape<?>)) {
                        node = node.getParent();
                    }

                    if (node instanceof ZoomShape<?>) {

                        //                     if (LOG.isDebugEnabled()) {
                        //                         LOG.debug("Selected node to zoom is " + node + " and this is " + ZoomShape.this);
                        //                     }

                        node.moveToFront();

                        //                     PBounds boundsView = event.getCamera()
                        //                           .getViewBounds();
                        //                     PBounds boundsNode = ((ZoomShape<?>) node)
                        //                           .getGlobalBoundsZoomedIn();
                        //                     boolean sameNode = (Math.abs(boundsView.x
                        //                           - boundsNode.x) < 0.1 && Math
                        //                           .abs(boundsView.width - boundsNode.width) < 0.1)
                        //                           || (Math.abs(boundsView.y - boundsNode.y) < 0.1 && Math
                        //                                 .abs(boundsView.height
                        //                                       - boundsNode.height) < 0.1);
                        //
                        //                     if (!sameNode) {
                        if (store != null) {
                            ((IModelStore) store).getModel().setZoomedShape((ZoomShape<?>) node);
                            ((IModelStore) store).getModel().setZoomedBounds(getGlobalBoundsZoomedIn());
                        }
                        animateToCenterView(event.getCamera());
                        //                     }

                        event.setHandled(true);
                    }
                }
            }
        });
    }

    if (this instanceof Draggable) {
        addInputEventListener(new PDragEventHandler() {

            private PNode draggable;

            /*
             * (non-Javadoc)
             * 
             * @seeedu.umd.cs.piccolo.event.PDragEventHandler#
             * shouldStartDragInteraction
             * (edu.umd.cs.piccolo.event.PInputEvent)
             */
            @Override
            protected boolean shouldStartDragInteraction(PInputEvent event) {
                if (!event.isHandled()) {
                    PNode node = event.getPickedNode();
                    while (node != null && !(node instanceof Draggable)) {
                        node = node.getParent();
                    }
                    // Set dragged node to allow drag transformation.
                    draggable = node;
                    if (node instanceof Draggable) {
                        if (((Draggable) node).isDraggable() && super.shouldStartDragInteraction(event)) {
                            return true;
                        }
                    }
                    return false;
                }
                return false;
            }

            /*
             * (non-Javadoc)
             * 
             * @see
             * edu.umd.cs.piccolo.event.PDragEventHandler#drag(edu.umd.cs
             * .piccolo .event.PInputEvent)
             */
            @Override
            protected void drag(PInputEvent event) {
                if (!event.isHandled()) {
                    if (!event.getPath().acceptsNode(draggable)) {
                        if (LOG.isDebugEnabled()) {
                            LOG.debug("Pick path doesn't accept node " + draggable.getClass().getName() + ".");
                        }
                        return;
                    }

                    PNode parent = draggable.getParent();

                    PDimension d = event.getDeltaRelativeTo(draggable);
                    draggable.localToParent(d);

                    PBounds parentBounds = parent.getBoundsReference();
                    Rectangle2D draggableBounds = draggable
                            .localToParent(draggable.getBounds().moveBy(d.getWidth(), d.getHeight()));

                    if (parentBounds.contains(draggableBounds)) {
                        draggable.offset(d.getWidth(), d.getHeight());
                    }

                    Point2D offset = draggable.getOffset();
                    if (offset.getX() < 0) {
                        draggable.setOffset(0, offset.getY());
                    }
                    if (offset.getY() < 0) {
                        draggable.setOffset(offset.getX(), 0);
                    }
                    if (offset.getX() > parentBounds.getWidth() - draggableBounds.getWidth()) {
                        draggable.setOffset(parentBounds.getWidth() - draggableBounds.getWidth(),
                                offset.getY());
                    }
                    if (offset.getY() > parentBounds.getHeight() - draggableBounds.getHeight()) {
                        draggable.setOffset(offset.getX(),
                                parentBounds.getHeight() - draggableBounds.getHeight());
                    }

                    event.setHandled(true);
                }

                // if (!event.isHandled()) {
                // if (!event.getPath().acceptsNode(draggable)) {
                // if (LOG.isDebugEnabled()) {
                // LOG.debug("Pick path doesn't accept node " +
                // draggable.getClass().getName() + ".");
                // }
                // return;
                // }
                //
                // Point2D current =
                // event.getPositionRelativeTo(ZoomShape.this);
                // draggable.localToParent(current);
                //                  
                // Point2D dest = new Point2D.Double();
                //                  
                // dest.setLocation((current.getX()), (current.getY()));
                //            
                // dest.setLocation(dest.getX() - (dest.getX() % 20),
                // dest.getY() - (dest.getY() % 20));
                //                  
                // // dest.setLocation(nodeStartPosition.getX() - (d.getX()
                // % 20), nodeStartPosition.getY() - (d.getY() % 20));
                //                  
                // System.out.println("OFFSET: " + dest);
                //                  
                // draggable.setOffset(dest.getX(), dest.getY());
                //
                // // }
                // event.setHandled(true);
                // }
            }
        });
    }

    MultiSelectionHandler multiSelectionHandler = new MultiSelectionHandler() {

        /* (non-Javadoc)
         * @see org.squidy.designer.event.MultiSelectionHandler#selectionAllowed(edu.umd.cs.piccolo.event.PInputEvent)
         */
        @Override
        protected boolean selectionAllowed(PInputEvent event) {
            PNode node = event.getPickedNode();
            return node instanceof Draggable && !((Draggable) node).isDraggable();
        }

        /*
         * (non-Javadoc)
         * 
         * @see
         * org.squidy.designer.event.MultiSelectionHandler#startSelection
         * (edu.umd.cs.piccolo.event.PInputEvent, java.awt.Shape)
         */
        @Override
        public void startSelection(PInputEvent event, Shape selectionShape) {
            if (!event.isHandled()) {
                multiSelection = selectionShape;

                event.setHandled(true);
                invalidatePaint();
            }
        }

        /*
         * (non-Javadoc)
         * 
         * @see
         * org.squidy.designer.event.MultiSelectionHandler#selection
         * (edu.umd.cs.piccolo.event.PInputEvent, java.awt.Shape)
         */
        @Override
        public void selection(PInputEvent event, Shape selectionShape) {
            if (!event.isHandled()) {
                multiSelection = selectionShape;

                event.setHandled(true);
                invalidatePaint();
            }
        }

        /*
         * (non-Javadoc)
         * 
         * @see
         * org.squidy.designer.event.MultiSelectionHandler#endSelection
         * (edu.umd.cs.piccolo.event.PInputEvent, java.awt.Shape)
         */
        @Override
        public void endSelection(PInputEvent event, Shape selectionShape) {
            if (!event.isHandled()) {
                multiSelection = null;

                for (Object o : getChildrenReference()) {
                    if (o instanceof VisualShape<?>) {
                        VisualShape<?> shape = (VisualShape<?>) o;

                        PBounds bounds = shape.getGlobalFullBounds();
                        if (selectionShape.contains(bounds)) {
                            System.out.println("containing: " + shape);
                        }
                    }
                }

                event.setHandled(true);
                invalidatePaint();
            }
        }
    };

    //       addInputEventListener(multiSelectionHandler);

    // Add knowledge base to zoom object if class is of type
    // <code>KnowledgeBased</code>.
    if (this instanceof NodeBased<?>) {
        boolean isWorkspace = this instanceof WorkspaceShape;

        knowledgeBase = new AdvancedKnowledgeBase<ZoomShape<VisualShape<?>>>(isWorkspace);

        addChild(knowledgeBase);
        knowledgeBase.setOffset(0, 895);
    }
}

From source file:ucar.unidata.idv.control.chart.TimeSeriesChart.java

/**
 * draw the time line/*  w  w w .jav a2 s .  c o  m*/
 *
 * @param g2 param
 * @param plot param
 * @param dataArea param
 * @param domainAxis param
 * @param rangeAxis param
 * @param rendererIndex param
 * @param info param
 */
private void drawTime(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis,
        ValueAxis rangeAxis, int rendererIndex, PlotRenderingInfo info) {
    try {
        Animation animation = control.getSomeAnimation();
        if (animation == null) {
            return;
        }
        Real dttm = animation.getAniValue();
        if (dttm == null) {
            return;
        }
        g2.setStroke(new BasicStroke());
        g2.setColor(Color.black);
        double timeValue = dttm.getValue(CommonUnit.secondsSinceTheEpoch);
        int x = (int) domainAxis.valueToJava2D(timeValue * 1000, dataArea, RectangleEdge.BOTTOM);
        if ((x < dataArea.getX()) || (x > dataArea.getX() + dataArea.getWidth())) {
            return;
        }

        int bottom = (int) (dataArea.getY() + dataArea.getHeight());
        int top = (int) (dataArea.getY());
        int offset = 0;
        if (false && (clockImage == null)) {
            clockImage = GuiUtils.getImage("/auxdata/ui/icons/clock.gif");
            clockImage.getHeight(this);
            offset = clockImage.getHeight(null);
        }

        //            g2.drawLine(x, (int) dataArea.getY(), x, bottom - offset);
        int w = 8;
        int w2 = w / 2;
        int[] xs = { x - w2, x, x + w2, x };
        int[] ys = { top, top + w, top, top };
        //            g2.drawLine(x, top, x, top+10);
        g2.fillPolygon(xs, ys, xs.length);
        if (clockImage != null) {
            g2.drawImage(clockImage, x - clockImage.getWidth(null) / 2, bottom - clockImage.getHeight(null),
                    null);
        }
    } catch (VisADException exc) {
    } catch (RemoteException exc) {
    }
}