Example usage for java.awt.geom Rectangle2D getMinX

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

Introduction

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

Prototype

public double getMinX() 

Source Link

Document

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

Usage

From source file:de.hs.mannheim.modUro.controller.diagram.fx.interaction.ZoomHandlerFX.java

@Override
public void handleMouseReleased(ChartCanvas canvas, MouseEvent e) {
    Plot p = canvas.getChart().getPlot();
    if (!(p instanceof Zoomable)) {
        return;//from  w ww  .  ja  v  a2 s.com
    }
    boolean hZoom, vZoom;
    Zoomable z = (Zoomable) p;
    if (z.getOrientation().isHorizontal()) {
        hZoom = z.isRangeZoomable();
        vZoom = z.isDomainZoomable();
    } else {
        hZoom = z.isDomainZoomable();
        vZoom = z.isRangeZoomable();
    }

    boolean zoomTrigger1 = hZoom && Math.abs(e.getX() - this.startPoint.getX()) >= 10;
    boolean zoomTrigger2 = vZoom && Math.abs(e.getY() - this.startPoint.getY()) >= 10;
    if (zoomTrigger1 || zoomTrigger2) {
        Point2D endPoint = new Point2D.Double(e.getX(), e.getY());
        PlotRenderingInfo pri = canvas.getRenderingInfo().getPlotInfo();
        if ((hZoom && (e.getX() < this.startPoint.getX())) || (vZoom && (e.getY() < this.startPoint.getY()))) {
            boolean saved = p.isNotify();
            p.setNotify(false);
            z.zoomDomainAxes(0, pri, endPoint);
            z.zoomRangeAxes(0, pri, endPoint);
            p.setNotify(saved);
        } else {
            double x = this.startPoint.getX();
            double y = this.startPoint.getY();
            double w = e.getX() - x;
            double h = e.getY() - y;
            Rectangle2D dataArea = canvas.findDataArea(this.startPoint);
            double maxX = dataArea.getMaxX();
            double maxY = dataArea.getMaxY();
            // for mouseReleased event, (horizontalZoom || verticalZoom)
            // will be true, so we can just test for either being false;
            // otherwise both are true
            if (!vZoom) {
                y = dataArea.getMinY();
                w = Math.min(w, maxX - this.startPoint.getX());
                h = dataArea.getHeight();
            } else if (!hZoom) {
                x = dataArea.getMinX();
                w = dataArea.getWidth();
                h = Math.min(h, maxY - this.startPoint.getY());
            } else {
                w = Math.min(w, maxX - this.startPoint.getX());
                h = Math.min(h, maxY - this.startPoint.getY());
            }
            Rectangle2D zoomArea = new Rectangle2D.Double(x, y, w, h);

            boolean saved = p.isNotify();
            p.setNotify(false);
            double pw0 = percentW(x, dataArea);
            double pw1 = percentW(x + w, dataArea);
            double ph0 = percentH(y, dataArea);
            double ph1 = percentH(y + h, dataArea);
            PlotRenderingInfo info = this.viewer.getRenderingInfo().getPlotInfo();
            if (z.getOrientation().isVertical()) {
                z.zoomDomainAxes(pw0, pw1, info, endPoint);
                z.zoomRangeAxes(1 - ph1, 1 - ph0, info, endPoint);
            } else {
                z.zoomRangeAxes(pw0, pw1, info, endPoint);
                z.zoomDomainAxes(1 - ph1, 1 - ph0, info, endPoint);
            }
            p.setNotify(saved);

        }
    }
    viewer.hideZoomRectangle();
    this.startPoint = null;
    canvas.clearLiveHandler();
}

From source file:com.zilbo.flamingSailor.TE.model.Component.java

public boolean onSameLine(Rectangle2D otherGeom) {

    Double y1 = this.geom.getMinY();
    Double y3 = this.geom.getMaxY();
    Double y2 = otherGeom.getMinY();
    Double y4 = otherGeom.getMaxY();

    // we have some kind of crossover.
    if (y1 <= y4 && y1 >= y2) {
        // AND the boxes are touching
        if (Math.abs(this.geom.getMinX() - otherGeom.getMaxX()) < 0.5
                || (this.geom.getMaxX() - otherGeom.getMinX()) < 0.5) {
            // assume it's a super/subscript letter and call it the same line.
            return true;
        }/*from  w w  w .jav  a  2s  .  co m*/

    }
    // we have some kind of crossover.
    if (y2 <= y3 && y2 >= y1) {
        // AND the boxes are touching
        //   logger.info(this.geom.getMinX() - otherGeom.getMaxX());
        if (Math.abs(this.geom.getMinX() - otherGeom.getMaxX()) < 0.5
                || (this.geom.getMaxX() - otherGeom.getMinX()) < 0.5) {
            // assume it's a super/subscript letter and call it the same line.
            return true;
        }

    }
    double yAveT = (y2 + y4) / 2;
    //   double diff = (y4-y2)/4;
    if ((y1 <= (yAveT)) && ((yAveT) < y3)) {
        return true;
    }
    yAveT = (y1 + y3) / 2;
    return (y2 <= yAveT) && (yAveT < y4);

}

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;/*from ww w  .  ja  v a 2s  . 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: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();//from w  w w  .  j  av a  2 s.co  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:ucar.unidata.idv.control.chart.MyScatterPlot.java

/**
 * Draws the fast scatter plot on a Java 2D graphics device (such as the
 * screen or a printer).//from w  w w . j  a  va  2  s .  co m
 * a
 * @param g2  the graphics device.
 * @param dataArea the data area
 * @param index which data set
 * @param info  collects chart drawing information (<code>null</code>
 *              permitted).
 * @param crosshairState crosshairState
 *
 * @return did something
 */
public boolean render(Graphics2D g2, Rectangle2D dataArea, int index, PlotRenderingInfo info,
        CrosshairState crosshairState) {

    if (index >= series.size()) {
        return false;
    }
    XYDataset dataset = getDataset(index);
    g2.setStroke(new BasicStroke());
    //                   getRendererForDataset(dataset).getSeriesStroke(0));
    ScatterPlotChartWrapper.MyRenderer renderer = (ScatterPlotChartWrapper.MyRenderer) getRendererForDataset(
            dataset);
    g2.setPaint(renderer.getSeriesPaint(0));
    int shape = renderer.shape;

    PlotOrientation orientation = getOrientation();
    int seenCnt = 0;

    int xx = (int) dataArea.getMinX();
    int ww = (int) dataArea.getWidth();
    int yy = (int) dataArea.getMaxY();
    int hh = (int) dataArea.getHeight();
    ValueAxis rangeAxis = getRangeAxisForDataset(index);
    ValueAxis domainAxis = getDomainAxisForDataset(index);
    double domainMin = domainAxis.getLowerBound();
    double domainLength = domainAxis.getUpperBound() - domainMin;
    double rangeMin = rangeAxis.getLowerBound();
    double rangeLength = rangeAxis.getUpperBound() - rangeMin;
    int boxWidth = 6;

    double[][] data = (double[][]) series.get(index);

    double[] d1 = data[0];
    double[] d2 = data[1];
    int size = d1.length;

    Hashtable seen = new Hashtable();
    int lastX = 0;
    int lastY = 0;
    //TODO: Check for clipping
    //TODO: Try to create a GeneralPath with the points
    //and cal g2.draw just once
    GeneralPath path = new GeneralPath();
    long t1 = System.currentTimeMillis();

    for (int i = 0; i < size; i++) {
        int transX = (int) (xx + ww * (d1[i] - domainMin) / domainLength);
        int transY = (int) (yy - hh * (d2[i] - rangeMin) / rangeLength);
        Object key = transX + "_" + transY;
        if (seen.get(key) != null) {
            seenCnt++;
            continue;
        }
        seen.put(key, key);
        if (crosshairState != null) {
            crosshairState.updateCrosshairPoint(d1[i], d2[i], transX, transY, orientation);
        }

        switch (shape) {

        case LineState.SHAPE_VLINE:
            if (i > 1) {
                g2.drawLine(lastX, lastY, transX, transY);
            }
            lastX = transX;
            lastY = transY;

        case LineState.SHAPE_POINT:
            path.append(new Rectangle((int) transX, (int) transY, 1, 1), false);
            break;

        case LineState.SHAPE_LARGEPOINT:
            path.append(new Rectangle((int) transX, (int) transY, 2, 2), false);
            break;

        case LineState.SHAPE_RECTANGLE:
            path.append(
                    new Rectangle((int) transX - boxWidth / 2, (int) transY - boxWidth / 2, boxWidth, boxWidth),
                    false);
            break;

        case LineState.SHAPE_X:
            g2.drawLine(transX - boxWidth / 2, transY - boxWidth / 2, transX + boxWidth - boxWidth / 2,
                    transY + boxWidth - boxWidth / 2);
            g2.drawLine(transX + boxWidth - boxWidth / 2, transY - boxWidth / 2, transX - boxWidth / 2,
                    transY + boxWidth - boxWidth / 2);
            break;

        case LineState.SHAPE_PLUS:
            g2.drawLine(transX + boxWidth / 2, transY, transX + boxWidth / 2, transY + boxWidth);
            g2.drawLine(transX, transY + boxWidth / 2, transX + boxWidth, transY + boxWidth / 2);
            break;

        }
    }
    g2.fill(path);
    long t2 = System.currentTimeMillis();
    //        System.out.println ("time:" + (t2-t1));
    return true;
}

From source file:Polygon2D.java

/**
 * Constructs and initializes a <code>Polygon2D</code> from the specified
 * Rectangle2D.//  w w  w  .  j  av a 2 s. c  o m
 * @param rec the Rectangle2D
 * @exception  NullPointerException rec is <code>null</code>.
 */
public Polygon2D(Rectangle2D rec) {
    if (rec == null) {
        throw new IndexOutOfBoundsException("null Rectangle");
    }
    npoints = 4;
    xpoints = new float[4];
    ypoints = new float[4];
    xpoints[0] = (float) rec.getMinX();
    ypoints[0] = (float) rec.getMinY();
    xpoints[1] = (float) rec.getMaxX();
    ypoints[1] = (float) rec.getMinY();
    xpoints[2] = (float) rec.getMaxX();
    ypoints[2] = (float) rec.getMaxY();
    xpoints[3] = (float) rec.getMinX();
    ypoints[3] = (float) rec.getMaxY();
    calculatePath();
}

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 {//w w w  . j  a  va 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:de.hs.mannheim.modUro.controller.diagram.fx.interaction.ZoomHandlerFX.java

/**
 * Handles a mouse dragged event by updating the zoom rectangle displayed
 * in the ChartViewer.//w ww.  j  a v a  2  s  .c o m
 * 
 * @param canvas  the JavaFX canvas (<code>null</code> not permitted).
 * @param e  the mouse event (<code>null</code> not permitted).
 */
@Override
public void handleMouseDragged(ChartCanvas canvas, MouseEvent e) {
    if (this.startPoint == null) {
        //no initial zoom rectangle exists but the handler is set
        //as life handler unregister
        canvas.clearLiveHandler();
        return;
    }

    boolean hZoom, vZoom;
    Plot p = canvas.getChart().getPlot();
    if (!(p instanceof Zoomable)) {
        return;
    }
    Zoomable z = (Zoomable) p;
    if (z.getOrientation().isHorizontal()) {
        hZoom = z.isRangeZoomable();
        vZoom = z.isDomainZoomable();
    } else {
        hZoom = z.isDomainZoomable();
        vZoom = z.isRangeZoomable();
    }
    Rectangle2D dataArea = canvas.findDataArea(this.startPoint);

    double x = this.startPoint.getX();
    double y = this.startPoint.getY();
    double w = 0;
    double h = 0;
    if (hZoom && vZoom) {
        // selected rectangle shouldn't extend outside the data area...
        double xmax = Math.min(e.getX(), dataArea.getMaxX());
        double ymax = Math.min(e.getY(), dataArea.getMaxY());
        w = xmax - this.startPoint.getX();
        h = ymax - this.startPoint.getY();
    } else if (hZoom) {
        double xmax = Math.min(e.getX(), dataArea.getMaxX());
        y = dataArea.getMinY();
        w = xmax - this.startPoint.getX();
        h = dataArea.getHeight();
    } else if (vZoom) {
        double ymax = Math.min(e.getY(), dataArea.getMaxY());
        x = dataArea.getMinX();
        w = dataArea.getWidth();
        h = ymax - this.startPoint.getY();
    }
    viewer.showZoomRectangle(x, y, w, h);
}

From source file:org.csa.rstb.dat.toolviews.HaAlphaPlotPanel.java

@Override
protected String getDataAsText() {
    final BufferedImage image = plot.getImage();
    final Rectangle2D bounds = plot.getImageDataBounds();

    final byte[] data = getValidData(image);
    if (data == null) {
        return null;
    }//from  w  w w.  jav a  2  s  .  co m

    final StringBuilder sb = new StringBuilder(64000);
    final int w = image.getWidth();
    final int h = image.getHeight();

    final RasterDataNode rasterX = getRaster(X_VAR);
    final String nameX = rasterX.getName();
    final double sampleMinX = bounds.getMinX();
    final double sampleMaxX = bounds.getMaxX();

    final RasterDataNode rasterY = getRaster(Y_VAR);
    final String nameY = rasterY.getName();
    final double sampleMinY = bounds.getMinY();
    final double sampleMaxY = bounds.getMaxY();

    sb.append("Product name:\t").append(rasterX.getProduct().getName()).append("\n");
    sb.append("Dataset X name:\t").append(nameX).append("\n");
    sb.append("Dataset Y name:\t").append(nameY).append("\n");
    sb.append('\n');
    sb.append(nameX).append(" minimum:\t").append(sampleMinX).append("\t").append(rasterX.getUnit())
            .append("\n");
    sb.append(nameX).append(" maximum:\t").append(sampleMaxX).append("\t").append(rasterX.getUnit())
            .append("\n");
    sb.append(nameX).append(" bin size:\t").append((sampleMaxX - sampleMinX) / w).append("\t")
            .append(rasterX.getUnit()).append("\n");
    sb.append(nameX).append(" #bins:\t").append(w).append("\n");
    sb.append('\n');
    sb.append(nameY).append(" minimum:\t").append(sampleMinY).append("\t").append(rasterY.getUnit())
            .append("\n");
    sb.append(nameY).append(" maximum:\t").append(sampleMaxY).append("\t").append(rasterY.getUnit())
            .append("\n");
    sb.append(nameY).append(" bin size:\t").append((sampleMaxY - sampleMinY) / h).append("\t")
            .append(rasterY.getUnit()).append("\n");
    sb.append(nameY).append(" #bins:\t").append(h).append("\n");
    sb.append('\n');

    sb.append(nameX);
    sb.append('\t');
    sb.append(nameY);
    sb.append('\t');
    sb.append("Bin counts\t(cropped at 255)");
    sb.append('\n');

    int x, y, z;
    double v1, v2;
    for (int i = 0; i < data.length; i++) {
        z = data[i] & 0xff;
        if (z != 0) {

            x = i % w;
            y = h - i / w - 1;

            v1 = sampleMinX + ((x + 0.5) * (sampleMaxX - sampleMinX)) / w;
            v2 = sampleMinY + ((y + 0.5) * (sampleMaxY - sampleMinY)) / h;

            sb.append(v1);
            sb.append('\t');
            sb.append(v2);
            sb.append('\t');
            sb.append(z);
            sb.append('\n');
        }
    }

    return sb.toString();
}

From source file:com.lfx.web.WebChartXYPlot.java

/**
  * Draws the gridlines for the plot, if they are visible.
  *//w  w w.  ja va  2  s. com
  * @param g2  the graphics device.
  * @param dataArea  the data area.
  * @param ticks  the ticks.
  *
  * @see #drawRangeGridlines(Graphics2D, Rectangle2D, List)
  */

protected void drawRangeGridlines(Graphics2D g2, Rectangle2D dataArea, List ticks) {
    Composite oldcomp = g2.getComposite();
    Paint bandPaint = getBackgroundPaint();
    if (bandPaint != null && bandPaint instanceof java.awt.Color) {
        // g2.setComposite(AlphaComposite.SrcO);
        java.awt.Color bandcolor = (java.awt.Color) (bandPaint);
        boolean fillBand = false;
        ValueAxis axis = getRangeAxis();
        double previous = axis.getLowerBound();
        Iterator iterator = ticks.iterator();
        while (iterator.hasNext()) {
            ValueTick tick = (ValueTick) iterator.next();
            if (!tick.getTickType().equals(TickType.MAJOR))
                continue;
            double current = tick.getValue();
            double y1 = axis.valueToJava2D(previous, dataArea, getRangeAxisEdge());
            double y2 = axis.valueToJava2D(current, dataArea, getRangeAxisEdge());
            Rectangle2D band = new Rectangle2D.Double(dataArea.getMinX(), y2, dataArea.getWidth(), y1 - y2);
            if (fillBand)
                g2.setPaint(bandcolor);
            else
                g2.setPaint(bandcolor.darker());
            g2.fill(band);
            previous = current;
            fillBand = !fillBand;
        }
        double end = axis.getUpperBound();
        double y1 = axis.valueToJava2D(previous, dataArea, getRangeAxisEdge());
        double y2 = axis.valueToJava2D(end, dataArea, getRangeAxisEdge());
        Rectangle2D band = new Rectangle2D.Double(dataArea.getMinX(), y2, dataArea.getWidth(), y1 - y2);
        if (fillBand)
            g2.setPaint(bandcolor);
        else
            g2.setPaint(bandcolor.darker());
        g2.fill(band);
    } else {
        super.drawRangeGridlines(g2, dataArea, ticks);
    }
    g2.setComposite(oldcomp);
}