Example usage for java.awt.geom Rectangle2D getMaxX

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

Introduction

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

Prototype

public double getMaxX() 

Source Link

Document

Returns the largest X coordinate of the framing rectangle of the Shape in double precision.

Usage

From source file:figs.treeVisualization.gui.PhyloDateAxis.java

/**
 * Translates the data value to the display coordinates (Java 2D User Space)
 * of the chart.//from w  w w. jav a  2  s. c o  m
 *
 * @param value  the date to be plotted.
 * @param area  the rectangle (in Java2D space) where the data is to be 
 *              plotted.
 * @param edge  the axis location.
 *
 * @return The coordinate corresponding to the supplied data value.
 * 
 * Original method is in <code>org.jfree.chart.axis.DateAxis</code>
 */
@Override
public double valueToJava2D(double value, Rectangle2D area, RectangleEdge edge) {

    Timeline timeline = this.getTimeline();
    value = timeline.toTimelineValue((long) value);

    DateRange range = (DateRange) getRange();
    double axisMin = timeline.toTimelineValue(range.getLowerDate());
    double axisMax = timeline.toTimelineValue(range.getUpperDate());
    double result = 0.0;
    if (RectangleEdge.isTopOrBottom(edge)) {
        double minX = area.getX();
        double maxX = area.getMaxX();
        if (isInverted()) {
            result = maxX + ((value - axisMin) / (axisMax - axisMin)) * (minX - maxX);
        } else {
            result = minX + ((value - axisMin) / (axisMax - axisMin)) * (maxX - minX);
        }
    } else if (RectangleEdge.isLeftOrRight(edge)) {
        //double minY = area.getMinY();
        //double maxY = area.getMaxY();
        double minY = area.getY();
        double maxY = area.getHeight();
        if (isInverted()) {
            result = minY + (((value - axisMin) / (axisMax - axisMin)) * (maxY - minY));
        } else {
            result = maxY - (((value - axisMin) / (axisMax - axisMin)) * (maxY - minY));
        }
    }
    return result;

}

From source file:org.jfree.experimental.chart.axis.LogAxis.java

/**
 * Converts a Java2D coordinate to an axis value, assuming that the
 * axis covers the specified <code>edge</code> of the <code>area</code>.
 * /*from   w w  w  .  j av  a2 s.co  m*/
 * @param java2DValue  the Java2D coordinate.
 * @param area  the area.
 * @param edge  the edge that the axis belongs to.
 * 
 * @return A value along the axis scale.
 */
public double java2DToValue(double java2DValue, Rectangle2D area, RectangleEdge edge) {

    Range range = getRange();
    double axisMin = calculateLog(range.getLowerBound());
    double axisMax = calculateLog(range.getUpperBound());

    double min = 0.0;
    double max = 0.0;
    if (RectangleEdge.isTopOrBottom(edge)) {
        min = area.getX();
        max = area.getMaxX();
    } else if (RectangleEdge.isLeftOrRight(edge)) {
        min = area.getMaxY();
        max = area.getY();
    }
    double log = 0.0;
    if (isInverted()) {
        log = axisMax - (java2DValue - min) / (max - min) * (axisMax - axisMin);
    } else {
        log = axisMin + (java2DValue - min) / (max - min) * (axisMax - axisMin);
    }
    return calculateValue(log);
}

From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.link_and_brush.LinkAndBrushChartPanel.java

@Override
public void mouseReleased(MouseEvent e) {

    // if we've been panning, we need to reset now that the mouse is
    // released...
    Rectangle2D zoomRectangle = (Rectangle2D) getChartFieldValueByName("zoomRectangle");
    Point2D zoomPoint = (Point2D) getChartFieldValueByName("zoomPoint");
    if (getChartFieldValueByName("panLast") != null) {
        setChartFieldValue((getChartFieldByName("panLast")), null);
        setCursor(Cursor.getDefaultCursor());
    } else if (zoomRectangle != null) {
        boolean hZoom = false;
        boolean vZoom = false;
        if ((PlotOrientation) getChartFieldValueByName("orientation") == PlotOrientation.HORIZONTAL) {
            hZoom = (Boolean) getChartFieldValueByName("rangeZoomable");
            vZoom = (Boolean) getChartFieldValueByName("domainZoomable");
        } else {//from w  w w .  ja  va2  s  .  c om
            hZoom = (Boolean) getChartFieldValueByName("domainZoomable");
            vZoom = (Boolean) getChartFieldValueByName("rangeZoomable");
        }

        boolean zoomTrigger1 = hZoom && Math
                .abs(e.getX() - zoomPoint.getX()) >= (Integer) getChartFieldValueByName("zoomTriggerDistance");
        boolean zoomTrigger2 = vZoom && Math
                .abs(e.getY() - zoomPoint.getY()) >= (Integer) getChartFieldValueByName("zoomTriggerDistance");
        if (zoomTrigger1 || zoomTrigger2) {
            if ((hZoom && (e.getX() < zoomPoint.getX())) || (vZoom && (e.getY() < zoomPoint.getY()))) {
                restoreAutoBounds();
            } else {
                double x, y, w, h;
                Rectangle2D screenDataArea = getScreenDataArea((int) zoomPoint.getX(), (int) zoomPoint.getY());
                double maxX = screenDataArea.getMaxX();
                double maxY = screenDataArea.getMaxY();
                // for mouseReleased event, (horizontalZoom || verticalZoom)
                // will be true, so we can just test for either being false;
                // otherwise both are true
                if (!vZoom) {
                    x = zoomPoint.getX();
                    y = screenDataArea.getMinY();
                    w = Math.min(zoomRectangle.getWidth(), maxX - zoomPoint.getX());
                    h = screenDataArea.getHeight();
                } else if (!hZoom) {
                    x = screenDataArea.getMinX();
                    y = zoomPoint.getY();
                    w = screenDataArea.getWidth();
                    h = Math.min(zoomRectangle.getHeight(), maxY - zoomPoint.getY());
                } else {
                    x = zoomPoint.getX();
                    y = zoomPoint.getY();
                    w = Math.min(zoomRectangle.getWidth(), maxX - zoomPoint.getX());
                    h = Math.min(zoomRectangle.getHeight(), maxY - zoomPoint.getY());
                }
                Rectangle2D zoomArea = new Rectangle2D.Double(x, y, w, h);
                zoom(zoomArea);
            }
            setChartFieldValue(getChartFieldByName("zoomPoint"), null);
            setChartFieldValue(getChartFieldByName("zoomRectangle"), null);
        } else {
            // erase the zoom rectangle
            Graphics2D g2 = (Graphics2D) getGraphics();
            if ((Boolean) getChartFieldValueByName("useBuffer")) {
                repaint();
            } else {
                drawZoomRectangle(g2, true);
            }
            g2.dispose();
            setChartFieldValue(getChartFieldByName("zoomPoint"), null);
            setChartFieldValue(getChartFieldByName("zoomRectangle"), null);
        }

    }

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

}

From source file:org.jfree.experimental.chart.axis.LogAxis.java

/**
 * Converts a value on the axis scale to a Java2D coordinate relative to 
 * the given <code>area</code>, based on the axis running along the 
 * specified <code>edge</code>.
 * //from   ww w . j a  v a2s .c o  m
 * @param value  the data value.
 * @param area  the area.
 * @param edge  the edge.
 * 
 * @return The Java2D coordinate corresponding to <code>value</code>.
 */
public double valueToJava2D(double value, Rectangle2D area, RectangleEdge edge) {

    Range range = getRange();
    double axisMin = calculateLog(range.getLowerBound());
    double axisMax = calculateLog(range.getUpperBound());
    value = calculateLog(value);

    double min = 0.0;
    double max = 0.0;
    if (RectangleEdge.isTopOrBottom(edge)) {
        min = area.getX();
        max = area.getMaxX();
    } else if (RectangleEdge.isLeftOrRight(edge)) {
        max = area.getMinY();
        min = area.getMaxY();
    }
    if (isInverted()) {
        return max - ((value - axisMin) / (axisMax - axisMin)) * (max - min);
    } else {
        return min + ((value - axisMin) / (axisMax - axisMin)) * (max - min);
    }
}

From source file:com.vgi.mafscaling.LogPlay.java

private void createPlayer(JPanel panel) {
    playerPanel = new JPanel();
    GridBagLayout gbl_playerPanel = new GridBagLayout();
    gbl_playerPanel.columnWidths = new int[] { 0, 0, 0, 0, 0, 0, 0, 0 };
    gbl_playerPanel.rowHeights = new int[] { 0, 0, 0, 0 };
    gbl_playerPanel.columnWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0 };
    gbl_playerPanel.rowWeights = new double[] { 0.0, 0.0 };
    playerPanel.setLayout(gbl_playerPanel);

    GridBagConstraints gbc = new GridBagConstraints();
    gbc.insets = insets0;// ww w  .j ava 2  s.  co m
    gbc.anchor = GridBagConstraints.PAGE_START;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.gridx = 0;
    gbc.gridy = 0;

    progressBar = new JSlider(0, 0, 0);
    progressBar.setMinimum(0);
    progressBar.setMaximum(lastRow);
    setProgressBar(logDataTable.getSelectedRow());
    progressBar.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            int row = progressBar.getValue();
            if (playing) {
                if (row == lastRow || (endPlay >= 0 && endPlay < row)) {
                    stop();
                    return;
                }
                if (showMarker) {
                    Rectangle2D dataArea = logView.getChartPanel().getChartRenderingInfo().getPlotInfo()
                            .getDataArea();
                    XYPlot plot = (XYPlot) logView.getChartPanel().getChart().getPlot();
                    double x = plot.getDomainAxis().valueToJava2D(row, dataArea, plot.getDomainAxisEdge());
                    boolean isLeft = (x < (dataArea.getMaxX() - dataArea.getMinX()) / 2) ? true : false;
                    logView.setMarkers(row, isLeft);
                }
            }
            logDataTable.getTable().setRowSelectionInterval(row, row);
            logDataTable.getTable().changeSelection(row, logDataTable.getSelectedColumn(), false, false);
            double x, y, z;
            int origXCol, origYCol, origZCol;
            synchronized (lock) {
                for (TableHolder tableHolder : tables) {
                    try {
                        origXCol = logDataTable.getCurrentIndexForOriginalColumn(tableHolder.xColIdx);
                        origYCol = logDataTable.getCurrentIndexForOriginalColumn(tableHolder.yColIdx);
                        origZCol = logDataTable.getCurrentIndexForOriginalColumn(tableHolder.zColIdx);
                        x = Double.valueOf(logDataTable.getValueAt(row, origXCol).toString());
                        y = Double.valueOf(logDataTable.getValueAt(row, origYCol).toString());
                        if (origZCol > 0)
                            z = Double.valueOf(logDataTable.getValueAt(row, origZCol).toString());
                        else
                            z = Double.NaN;
                        tableHolder.table.setCurrentPoint(x, y, z);
                    } catch (Exception ex) {
                        JOptionPane
                                .showMessageDialog(null,
                                        "Invalid numeric value in column " + (tableHolder.xColIdx + 1)
                                                + ", row " + (row + 1),
                                        "Invalid value", JOptionPane.ERROR_MESSAGE);
                        return;
                    }
                }
            }
        }
    });
    gbc.weightx = 1.0;
    gbc.gridwidth = gbl_playerPanel.columnWidths.length;
    playerPanel.add(progressBar, gbc);

    stopButton = addPlayerButton(0, new ImageIcon(getClass().getResource("/stop.png")));
    rewButton = addPlayerButton(1, new ImageIcon(getClass().getResource("/rew.png")));
    playButton = addPlayerButton(2, playIcon);
    ffwButton = addPlayerButton(3, new ImageIcon(getClass().getResource("/ffw.png")));
    showIntepCells = addCheckBox(4, "Show interpolation cells");
    showSignifCells = addCheckBox(5, "Show significant cell");
    showTraceLine = addCheckBox(6, "Show trace line");
    showTraceMarker = addCheckBox(7, "Show plot trace marker");

    gbc.weightx = 0.0;
    gbc.gridwidth = 0;
    gbc.gridy = 1;
    panel.add(playerPanel, gbc);
}

From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.link_and_brush.LinkAndBrushChartPanel.java

@Override
public void mouseDragged(MouseEvent e) {
    // when not allowed to zoom / select, return
    if (blockSelectionOrZoom) {
        return;/*from ww  w . j av  a2 s.  co m*/
    }
    // if the popup menu has already been triggered, then ignore dragging...
    if (getChartFieldValueByName("popup") != null
            && ((JPopupMenu) getChartFieldValueByName("popup")).isShowing()) {
        return;
    }

    // handle panning if we have a start point
    if (getChartFieldValueByName("panLast") != null) {
        double dx = e.getX() - ((Point) getChartFieldValueByName("panLast")).getX();
        double dy = e.getY() - ((Point) getChartFieldValueByName("panLast")).getY();
        if (dx == 0.0 && dy == 0.0) {
            return;
        }
        double wPercent = -dx / ((Double) getChartFieldValueByName("panW"));
        double hPercent = dy / ((Double) getChartFieldValueByName("panH"));
        boolean old = getChart().getPlot().isNotify();
        getChart().getPlot().setNotify(false);
        Pannable p = (Pannable) getChart().getPlot();
        if (p.getOrientation() == PlotOrientation.VERTICAL) {
            p.panDomainAxes(wPercent, getChartRenderingInfo().getPlotInfo(),
                    (Point) getChartFieldValueByName("panLast"));
            p.panRangeAxes(hPercent, getChartRenderingInfo().getPlotInfo(),
                    (Point) getChartFieldValueByName("panLast"));
        } else {
            p.panDomainAxes(hPercent, getChartRenderingInfo().getPlotInfo(),
                    (Point) getChartFieldValueByName("panLast"));
            p.panRangeAxes(wPercent, getChartRenderingInfo().getPlotInfo(),
                    (Point) getChartFieldValueByName("panLast"));
        }
        setChartFieldValue((getChartFieldByName("panLast")), e.getPoint());
        getChart().getPlot().setNotify(old);
        return;
    }

    // if no initial zoom point was set, ignore dragging...
    if (getChartFieldValueByName("zoomPoint") == null) {
        return;
    }
    Graphics2D g2 = (Graphics2D) getGraphics();

    // erase the previous zoom rectangle (if any). We only need to do
    // this is we are using XOR mode, which we do when we're not using
    // the buffer (if there is a buffer, then at the end of this method we
    // just trigger a repaint)
    if (!(Boolean) getChartFieldValueByName("useBuffer")) {
        drawZoomRectangle(g2, true);
    }

    boolean hZoom = false;
    boolean vZoom = false;
    if ((PlotOrientation) getChartFieldValueByName("orientation") == PlotOrientation.HORIZONTAL) {
        hZoom = (Boolean) getChartFieldValueByName("rangeZoomable");
        vZoom = (Boolean) getChartFieldValueByName("domainZoomable");
    } else {
        hZoom = (Boolean) getChartFieldValueByName("domainZoomable");
        vZoom = (Boolean) getChartFieldValueByName("rangeZoomable");
    }
    Point2D zoomPoint = (Point2D) getChartFieldValueByName("zoomPoint");
    Rectangle2D scaledDataArea = getScreenDataArea((int) zoomPoint.getX(), (int) 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());
        setChartFieldValue(getChartFieldByName("zoomRectangle"), new Rectangle2D.Double(zoomPoint.getX(),
                zoomPoint.getY(), xmax - zoomPoint.getX(), ymax - zoomPoint.getY()));
    } else if (hZoom) {
        double xmax = Math.min(e.getX(), scaledDataArea.getMaxX());
        setChartFieldValue(getChartFieldByName("zoomRectangle"), new Rectangle2D.Double(zoomPoint.getX(),
                scaledDataArea.getMinY(), xmax - zoomPoint.getX(), scaledDataArea.getHeight()));
    } else if (vZoom) {
        double ymax = Math.min(e.getY(), scaledDataArea.getMaxY());
        setChartFieldValue(getChartFieldByName("zoomRectangle"),
                new Rectangle2D.Double(scaledDataArea.getMinX(), zoomPoint.getY(), scaledDataArea.getWidth(),
                        ymax - zoomPoint.getY()));
    }

    // Draw the new zoom rectangle...
    if ((Boolean) getChartFieldValueByName("useBuffer")) {
        repaint();
    } else {
        // with no buffer, we use XOR to draw the rectangle "over" the
        // chart...
        drawZoomRectangle(g2, true);
    }
    g2.dispose();

}

From source file:Hexagon.java

public void align(Rectangle2D bounds, Direction direction) {
    // these are defined here INSTEAD of in the switch, or it won't compile
    Point2D newTopRight, newTopLeft, newBottomRight, newBottomLeft;
    Point2D oldTopRight, oldTopLeft, oldBottomRight, oldBottomLeft;

    switch (direction) {
    case NorthEast:
        newTopRight = new Point2D.Double(bounds.getMaxX(), bounds.getMinY());
        oldTopRight = boundingCorners.get(BoundingCorner.TopRight);
        translate(newTopRight.getX() - oldTopRight.getX(), // deltaX
                newTopRight.getY() - oldTopRight.getY() // deltaY
        );//from  w  w w.j  a v  a  2  s  .  co  m
        break;
    case East:
        newTopRight = new Point2D.Double(bounds.getMaxX(), bounds.getMinY());
        oldTopRight = boundingCorners.get(BoundingCorner.TopRight);
        translate(newTopRight.getX() - oldTopRight.getX(), // deltaX
                0 // deltaY
        );
        break;
    case SouthEast:
        newBottomRight = new Point2D.Double(bounds.getMaxX(), bounds.getMaxY());
        oldBottomRight = boundingCorners.get(BoundingCorner.BottomRight);
        translate(newBottomRight.getX() - oldBottomRight.getX(), // deltaX
                newBottomRight.getY() - oldBottomRight.getY() // deltaY
        );
        break;
    case SouthWest:
        newBottomLeft = new Point2D.Double(bounds.getMinX(), bounds.getMaxY());
        oldBottomLeft = boundingCorners.get(BoundingCorner.BottomLeft);
        translate(newBottomLeft.getX() - oldBottomLeft.getX(), // deltaX
                newBottomLeft.getY() - oldBottomLeft.getY() // deltaY
        );
        break;
    case West:
        newTopLeft = new Point2D.Double(bounds.getMinX(), bounds.getMinY());
        oldTopLeft = boundingCorners.get(BoundingCorner.TopLeft);
        translate(newTopLeft.getX() - oldTopLeft.getX(), // deltaX
                0 // deltaY
        );
        break;
    case NorthWest:
        newTopLeft = new Point2D.Double(bounds.getMinX(), bounds.getMinY());
        oldTopLeft = boundingCorners.get(BoundingCorner.TopLeft);
        translate(newTopLeft.getX() - oldTopLeft.getX(), // deltaX
                newTopLeft.getY() - oldTopLeft.getY() // deltaY
        );
        break;
    }
}

From source file:org.gumtree.vis.awt.time.TimePlotPanel.java

@Override
protected void drawToolTipFollower(Graphics2D g2, int x, int y) {
    Rectangle2D dataArea = getScreenDataArea();
    if (((int) dataArea.getMinX() <= x) && (x <= (int) dataArea.getMaxX()) && ((int) dataArea.getMinY() <= y)
            && (y <= (int) dataArea.getMaxY())) {
        Date date = new Date((long) getChartX());
        String text = "";
        SimpleDateFormat format = new SimpleDateFormat("EEE d MMM HH:mm:ss");
        StringBuffer buffer = new StringBuffer();
        format.format(date, buffer, new FieldPosition(0));
        text = buffer.toString();//w w  w .  j  a  v a2 s  . c o  m
        text = "(" + text + String.format(", %.2f)", getChartY());
        int xLoc = x + 10;
        int yLoc = y + 20;
        double width = text.length() * 5.5;
        double height = 15;
        if (xLoc + width > dataArea.getMaxX()) {
            xLoc = (int) (x - width);
        }
        if (yLoc + height > dataArea.getMaxY()) {
            yLoc = (int) (y - height);
        }

        Rectangle2D toolTipArea = new Rectangle2D.Double(xLoc, yLoc, width, height);

        g2.setColor(Color.white);
        g2.fill(toolTipArea);
        g2.setColor(Color.black);
        g2.drawString(text, xLoc + 3, yLoc + 11);
    }
}

From source file:net.sf.maltcms.chromaui.chromatogram1Dviewer.ui.panel.Chromatogram1DViewPanel.java

public void setViewport(Rectangle2D viewport) {
    //ignore viewport changes if we have the focus
    if (hasFocus()) {
        Logger.getLogger(Chromatogram1DViewPanel.class.getName()).log(Level.FINE,
                "Ignoring viewport update since we have the focus!");
    } else {/*from w ww.  j  a  v a  2  s  . c om*/
        //otherwise, clear our own viewport and set to new value
        if (this.viewport != null) {
            this.content.remove(this.viewport);
        }
        this.viewport = new ChromatogramViewViewport(viewport);
        Logger.getLogger(Chromatogram1DViewPanel.class.getName()).log(Level.FINE, "Setting viewport to: {0}",
                viewport);
        removeAxisListener();
        this.plot.getDomainAxis().setLowerBound(viewport.getMinX());
        this.plot.getDomainAxis().setUpperBound(viewport.getMaxX());
        //         this.ticplot.getRangeAxis().setLowerBound(viewport.getMinY());
        //         this.ticplot.getRangeAxis().setUpperBound(viewport.getMaxY());
        addAxisListener();
    }
}

From source file:org.eurocarbdb.application.glycoworkbench.plugin.PeakListChartPanel.java

public void mouseDragged(MouseEvent e) {
    if (mouse_start_point != null && theDocument.size() > 0) {
        if (is_moving) {
            // moving
            double mz_delta = screenToDataX(mouse_start_point.getX() - e.getPoint().getX());
            if (mz_delta > 0.) {
                double old_upper_bound = thePlot.getDomainAxis().getUpperBound();
                double old_lower_bound = thePlot.getDomainAxis().getLowerBound();
                double new_upper_bound = Math.min(old_upper_bound + mz_delta, theDocument.getMaxMZ());
                double new_lower_bound = old_lower_bound + new_upper_bound - old_upper_bound;

                thePlot.getDomainAxis().setRange(new Range(new_lower_bound, new_upper_bound));
            } else {
                double old_upper_bound = thePlot.getDomainAxis().getUpperBound();
                double old_lower_bound = thePlot.getDomainAxis().getLowerBound();
                double new_lower_bound = Math.max(old_lower_bound + mz_delta, theDocument.getMinMZ());
                double new_upper_bound = old_upper_bound + new_lower_bound - old_lower_bound;

                thePlot.getDomainAxis().setRange(new Range(new_lower_bound, new_upper_bound));
            }// w ww. j av a  2  s  .  c  o m

            mouse_start_point = e.getPoint();
        } else {
            // zooming                
            Graphics2D g2 = (Graphics2D) theChartPanel.getGraphics();
            g2.setXORMode(java.awt.Color.gray);

            // delete old rectangle
            if (zoom_rectangle != null)
                g2.draw(zoom_rectangle);

            // create new rectangle
            double start_x = Math.min(e.getX(), mouse_start_point.getX());
            double end_x = Math.max(e.getX(), mouse_start_point.getX());

            Rectangle2D data_area = theChartPanel.getScreenDataArea((int) start_x,
                    (int) mouse_start_point.getY());
            double xmax = Math.min(end_x, data_area.getMaxX());
            zoom_rectangle = new Rectangle2D.Double(start_x, data_area.getMinY(), xmax - start_x,
                    data_area.getHeight());

            // draw new rectangle
            g2.draw(zoom_rectangle);
            g2.dispose();
        }
    }
}