Example usage for java.awt Point getX

List of usage examples for java.awt Point getX

Introduction

In this page you can find the example usage for java.awt Point getX.

Prototype

public double getX() 

Source Link

Usage

From source file:com.projity.pm.graphic.spreadsheet.SpreadSheet.java

public boolean isOnText(MouseEvent e) {
    Point p = e.getPoint();
    int row = rowAtPoint(p);
    int col = columnAtPoint(p);
    Rectangle bounds = getCellRect(row, col, false);
    SpreadSheetModel model = (SpreadSheetModel) getModel();
    GraphicNode node = model.getNode(row);
    return NameCellComponent.isOnText(
            new Point((int) (p.getX() - bounds.getX()), (int) (p.getY() - bounds.getY())), bounds.getSize(),
            model.getCache().getLevel(node));
}

From source file:org.processmining.analysis.performance.advanceddottedchartanalysis.ui.DottedChartPanel.java

/**
 * adjusts the viewable are of the log (zoom)
 * //from w w w  .  j  av a 2s  .  c om
 * @param aZoom
 *            fraction of the log to be viewable (within (0,1] !)
 */
public void setViewportZoomY(double aZoom) {
    if (aZoom > 1.0) { // ensure sane values
        viewportZoomY = 1.0;
    } else if (aZoom <= 0.0) {
        viewportZoomY = 0.00000000001;
    } else {
        viewportZoomY = aZoom;
    }
    double ratio = updHight;
    updHight = (int) (getParent().getHeight() * (1.0 / aZoom));
    ratio = updHight / ratio;
    Dimension dim = new Dimension(updWidth, updHight);
    Point d = dca.getScrollPane().getViewport().getViewPosition();
    Point p = new Point((int) d.getX(), (int) (d.getY() * ratio));
    this.setPreferredSize(dim);
    coUtil.updateMilli2pixelsRatio(this.getWidth(), BORDER);

    this.revalidate();
    dca.setScrollBarPosition(p);
}

From source file:org.processmining.analysis.performance.advanceddottedchartanalysis.ui.DottedChartPanel.java

/**
 * adjusts the viewable are of the log (zoom)
 * // www.  j  a  va2  s  .c  o m
 * @param aZoom
 *            fraction of the log to be viewable (within (0,1] !)
 */
public void setViewportZoomX(double aZoom) {
    if (aZoom > 1.0) { // ensure sane values
        viewportZoomX = 1.0;
    } else if (aZoom <= 0.0) {
        viewportZoomX = 0.00000000001;
    } else {
        viewportZoomX = aZoom;
    }
    double ratio = updWidth;
    updWidth = (int) (getParent().getWidth() * (1.0 / aZoom));
    ratio = updWidth / ratio;
    Dimension dim = new Dimension(updWidth, updHight);
    Point d = dca.getScrollPane().getViewport().getViewPosition();
    Point p = new Point((int) (d.getX() * ratio), (int) (d.getY()));

    this.setPreferredSize(dim);
    coUtil.updateMilli2pixelsRatio(this.getWidth(), BORDER);

    this.revalidate();
    dca.setScrollBarPosition(p);
}

From source file:msi.gama.outputs.layers.charts.StandardXYItemRenderer.java

/**
 * Draws the visual representation of a single data item.
 *
 * @param g2//from ww w.  j a v a2 s.c o  m
 *            the graphics device.
 * @param state
 *            the renderer state.
 * @param dataArea
 *            the area within which the data is being drawn.
 * @param info
 *            collects information about the drawing.
 * @param plot
 *            the plot (can be used to obtain standard color information etc).
 * @param domainAxis
 *            the domain axis.
 * @param rangeAxis
 *            the range axis.
 * @param dataset
 *            the dataset.
 * @param series
 *            the series index (zero-based).
 * @param item
 *            the item index (zero-based).
 * @param crosshairState
 *            crosshair information for the plot (<code>null</code> permitted).
 * @param pass
 *            the pass index.
 */
@Override
public void drawItem(final Graphics2D g2, final XYItemRendererState state, final Rectangle2D dataArea,
        final PlotRenderingInfo info, final XYPlot plot, final ValueAxis domainAxis, final ValueAxis rangeAxis,
        final XYDataset dataset, final int series, final int item, final CrosshairState crosshairState,
        final int pass) {

    boolean itemVisible = getItemVisible(series, item);

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

    final PlotOrientation orientation = plot.getOrientation();
    final Paint paint = getItemPaint(series, item);
    final Stroke seriesStroke = getItemStroke(series, item);
    g2.setPaint(paint);
    g2.setStroke(seriesStroke);

    // get the data point...
    final double x1 = dataset.getXValue(series, item);
    final double y1 = dataset.getYValue(series, item);
    if (Double.isNaN(x1) || Double.isNaN(y1)) {
        itemVisible = false;
    }

    final RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    final RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
    final double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation);
    final double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation);

    if (getPlotLines()) {
        if (this.drawSeriesLineAsPath) {
            final State s = (State) state;
            if (s.getSeriesIndex() != series) {
                // we are starting a new series path
                s.seriesPath.reset();
                s.lastPointGood = false;
                s.setSeriesIndex(series);
            }

            // update path to reflect latest point
            if (itemVisible && !Double.isNaN(transX1) && !Double.isNaN(transY1)) {
                float x = (float) transX1;
                float y = (float) transY1;
                if (orientation == PlotOrientation.HORIZONTAL) {
                    x = (float) transY1;
                    y = (float) transX1;
                }
                if (s.isLastPointGood()) {
                    // TODO: check threshold
                    s.seriesPath.lineTo(x, y);
                } else {
                    s.seriesPath.moveTo(x, y);
                }
                s.setLastPointGood(true);
            } else {
                s.setLastPointGood(false);
            }
            if (item == dataset.getItemCount(series) - 1) {
                if (s.seriesIndex == series) {
                    // draw path
                    g2.setStroke(lookupSeriesStroke(series));
                    g2.setPaint(lookupSeriesPaint(series));
                    g2.draw(s.seriesPath);
                }
            }
        }

        else if (item != 0 && itemVisible) {
            // get the previous data point...
            final double x0 = dataset.getXValue(series, item - 1);
            final double y0 = dataset.getYValue(series, item - 1);
            if (!Double.isNaN(x0) && !Double.isNaN(y0)) {
                boolean drawLine = true;
                if (getPlotDiscontinuous()) {
                    // only draw a line if the gap between the current and
                    // previous data point is within the threshold
                    final int numX = dataset.getItemCount(series);
                    final double minX = dataset.getXValue(series, 0);
                    final double maxX = dataset.getXValue(series, numX - 1);
                    if (this.gapThresholdType == UnitType.ABSOLUTE) {
                        drawLine = Math.abs(x1 - x0) <= this.gapThreshold;
                    } else {
                        drawLine = Math.abs(x1 - x0) <= (maxX - minX) / numX * getGapThreshold();
                    }
                }
                if (drawLine) {
                    final double transX0 = domainAxis.valueToJava2D(x0, dataArea, xAxisLocation);
                    final double transY0 = rangeAxis.valueToJava2D(y0, dataArea, yAxisLocation);

                    // only draw if we have good values
                    if (Double.isNaN(transX0) || Double.isNaN(transY0) || Double.isNaN(transX1)
                            || Double.isNaN(transY1)) {
                        return;
                    }

                    if (orientation == PlotOrientation.HORIZONTAL) {
                        state.workingLine.setLine(transY0, transX0, transY1, transX1);
                    } else if (orientation == PlotOrientation.VERTICAL) {
                        state.workingLine.setLine(transX0, transY0, transX1, transY1);
                    }

                    if (state.workingLine.intersects(dataArea)) {
                        g2.draw(state.workingLine);
                    }
                }
            }
        }
    }

    // we needed to get this far even for invisible items, to ensure that
    // seriesPath updates happened, but now there is nothing more we need
    // to do for non-visible items...
    if (!itemVisible) {
        return;
    }

    if (getBaseShapesVisible()) {

        Shape shape = getItemShape(series, item);
        if (orientation == PlotOrientation.HORIZONTAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, transY1, transX1);
        } else if (orientation == PlotOrientation.VERTICAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, transX1, transY1);
        }
        if (shape.intersects(dataArea)) {
            if (getItemShapeFilled(series, item)) {
                g2.fill(shape);
            } else {
                g2.draw(shape);
            }
        }
        entityArea = shape;

    }

    if (getPlotImages()) {
        final Image image = getImage(plot, series, item, transX1, transY1);
        if (image != null) {
            final Point hotspot = getImageHotspot(plot, series, item, transX1, transY1, image);
            g2.drawImage(image, (int) (transX1 - hotspot.getX()), (int) (transY1 - hotspot.getY()), null);
            entityArea = new Rectangle2D.Double(transX1 - hotspot.getX(), transY1 - hotspot.getY(),
                    image.getWidth(null), image.getHeight(null));
        }

    }

    double xx = transX1;
    double yy = transY1;
    if (orientation == PlotOrientation.HORIZONTAL) {
        xx = transY1;
        yy = transX1;
    }

    // draw the item label if there is one...
    if (isItemLabelVisible(series, item)) {
        drawItemLabel(g2, orientation, dataset, series, item, xx, yy, y1 < 0.0);
    }

    final int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
    final int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
    updateCrosshairValues(crosshairState, x1, y1, domainAxisIndex, rangeAxisIndex, transX1, transY1,
            orientation);

    // add an entity for the item...
    if (entities != null && isPointInRect(dataArea, xx, yy)) {
        addEntity(entities, entityArea, dataset, series, item, xx, yy);
    }

}

From source file:org.talend.dataprofiler.chart.util.ToolTipChartComposite.java

/**
 * This method attempts to get a tooltip by converting the screen X,Y into Chart Area X,Y and then looking for a
 * data point in a data set that lies inside a hotspot around that value.
 * //from   w  w  w.  j a va  2 s. c  om
 * @param point The Java 2D point
 * @return A string for the data at the point or null if no data is found.
 */
protected String getTooltipAtPoint(Point point) {
    String result = null;

    Point2D translatedPoint = this.translateScreenToJava2D(point);
    Plot plot = this.getChart().getPlot();
    PlotRenderingInfo info = this.getChartRenderingInfo().getPlotInfo();
    if (plot instanceof CombinedDomainXYPlot) {
        int index = info.getSubplotIndex(translatedPoint);
        if (index < 0) {
            index = 0;
        }
        plot = (Plot) ((CombinedDomainXYPlot) plot).getSubplots().get(index);
        info = this.getChartRenderingInfo().getPlotInfo().getSubplotInfo(index);
    }
    if (plot != null && plot instanceof XYPlot) {
        XYPlot xyPlot = (XYPlot) plot;
        ValueAxis domainAxis = xyPlot.getDomainAxis();
        ValueAxis rangeAxis = xyPlot.getRangeAxis();
        // had to switch to SWT's rectangle here.
        Rectangle screenArea = this.scale(info.getDataArea());

        double hotspotSizeX = hotspontsize * this.getScaleX();
        double hotspotSizeY = hotspontsize * this.getScaleY();
        double x0 = point.getX();
        double y0 = point.getY();
        double x1 = x0 - hotspotSizeX;
        double y1 = y0 + hotspotSizeY;
        double x2 = x0 + hotspotSizeX;
        double y2 = y0 - hotspotSizeY;
        RectangleEdge xEdge = RectangleEdge.BOTTOM;
        RectangleEdge yEdge = RectangleEdge.LEFT;
        // Switch everything for horizontal charts
        if (xyPlot.getOrientation() == PlotOrientation.HORIZONTAL) {
            hotspotSizeX = hotspontsize * this.getScaleY();
            hotspotSizeY = hotspontsize * this.getScaleX();
            x0 = point.getY();
            y0 = point.getX();
            x1 = x0 + hotspotSizeX;
            y1 = y0 - hotspotSizeY;
            x2 = x0 - hotspotSizeX;
            y2 = y0 + hotspotSizeY;
            xEdge = RectangleEdge.LEFT;
            yEdge = RectangleEdge.BOTTOM;
        }

        // OK, here we have to get ourselves back into AWT land...
        Rectangle2D r2d = new Rectangle2D.Double();
        r2d.setRect(screenArea.x, screenArea.y, screenArea.width, screenArea.height);

        double ty0 = rangeAxis.java2DToValue(y0, r2d, yEdge);
        double tx1 = domainAxis.java2DToValue(x1, r2d, xEdge);
        double ty1 = rangeAxis.java2DToValue(y1, r2d, yEdge);
        double tx2 = domainAxis.java2DToValue(x2, r2d, xEdge);
        double ty2 = rangeAxis.java2DToValue(y2, r2d, yEdge);

        int datasetCount = xyPlot.getDatasetCount();
        for (int datasetIndex = 0; datasetIndex < datasetCount; datasetIndex++) {
            XYDataset dataset = xyPlot.getDataset(datasetIndex);
            int seriesCount = dataset.getSeriesCount();
            for (int series = 0; series < seriesCount; series++) {
                int itemCount = dataset.getItemCount(series);
                if (dataset instanceof OHLCDataset) {
                    // This could be optimized to use a binary search for x first
                    for (int item = 0; item < itemCount; item++) {
                        double xValue = dataset.getXValue(series, item);
                        double yValueHi = ((OHLCDataset) dataset).getHighValue(series, item);
                        double yValueLo = ((OHLCDataset) dataset).getLowValue(series, item);
                        // Check hi lo and swap if needed
                        if (yValueHi < yValueLo) {
                            double temp = yValueHi;
                            yValueHi = yValueLo;
                            yValueLo = temp;
                        }
                        // Check if the dataset 'X' value lies between the hotspot (tx1 < xValue < tx2)
                        if (tx1 < xValue && xValue < tx2) {
                            // Check if the cursor 'y' value lies between the high and low (low < ty0 < high)
                            if (yValueLo < ty0 && ty0 < yValueHi) {
                                return hiLoTips.generateToolTip(dataset, series, item);
                            }
                        }
                    }
                } else {
                    // This could be optimized to use a binary search for x first
                    for (int item = 0; item < itemCount; item++) {
                        double xValue = dataset.getXValue(series, item);
                        double yValue = dataset.getYValue(series, item);
                        // Check if the dataset 'X' value lies between the hotspot (tx1< xValue < tx2)
                        if (tx1 < xValue && xValue < tx2) {
                            // Check if the dataset 'Y' value lies between the hotspot (ty1 < yValue < ty2)
                            if (ty1 < yValue && yValue < ty2) {
                                return xyTips.generateToolTip(dataset, series, item);
                            }
                        }
                    }
                }
            }
        }
    }

    return result;
}

From source file:org.openmicroscopy.shoola.agents.measurement.view.IntensityView.java

/**
 * Populates the pixels value per channel.
 * /*from   w w  w  .  j  av a2 s  . c  o m*/
 * @param channel The selected channel.
 */
private void populateChannel() {
    Object[] nameColour = (Object[]) channelSelection.getSelectedItem();
    String string = (String) nameColour[1];
    if (!nameMap.containsKey(string))
        return;
    selectedChannelName = string;
    int channel = nameMap.get(string);
    if (channel < 0)
        return;
    Map<Point, Double> pixels = pixelStats.get(coord).get(channel);
    if (pixels == null)
        return;
    Iterator<Point> pixelIterator = pixels.keySet().iterator();
    double minX, maxX, minY, maxY;
    if (!pixelIterator.hasNext())
        return;
    Point point = pixelIterator.next();
    minX = (point.getX());
    maxX = (point.getX());
    minY = (point.getY());
    maxY = (point.getY());
    while (pixelIterator.hasNext()) {
        point = pixelIterator.next();
        minX = Math.min(minX, point.getX());
        maxX = Math.max(maxX, point.getX());
        minY = Math.min(minY, point.getY());
        maxY = Math.max(maxY, point.getY());
    }
    int sizeX, sizeY;
    sizeX = (int) (maxX - minX) + 1;
    sizeY = (int) ((maxY - minY) + 1);
    Double[][] data = new Double[sizeX][sizeY];
    Iterator<Entry<Point, Double>> i = pixels.entrySet().iterator();
    int x, y;
    Double value;
    Entry<Point, Double> entry;
    while (i.hasNext()) {
        entry = i.next();
        point = entry.getKey();
        x = (int) (point.getX() - minX);
        y = (int) (point.getY() - minY);
        if (x >= sizeX || y >= sizeY)
            continue;

        if (pixels.containsKey(point))
            value = entry.getValue();
        else
            value = new Double(0);
        data[x][y] = value;
    }
    tableModel = new IntensityModel(data);
    intensityDialog.setModel(tableModel);
}

From source file:org.eurocarbdb.application.glycoworkbench.plugin.reporting.AnnotationReportCanvas.java

private void xorConnection(AnnotationObject selection, Point start_point, Point end_point) {

    Graphics g = getGraphics();/*from   ww w  .j  a v a 2s  .  c  om*/
    g.setXORMode(Color.white);
    g.setColor(Color.gray);

    Rectangle rect = rectangles_complete.get(selection);
    Point2D peak = dataToScreenCoords(selection.getPeakPoint());

    // select anchor
    Point2D anchor = computeAnchor(rect, end_point, peak);

    // draw connection
    g.drawLine((int) anchor.getX(), (int) anchor.getY(), (int) end_point.getX(), (int) end_point.getY());
    g.drawLine((int) end_point.getX(), (int) end_point.getY(), (int) peak.getX(), (int) peak.getY());
}

From source file:es.darkhogg.hazelnutt.EditorFrame.java

private void actionExit() {
    logger.trace("Program exit requested...");

    boolean close = true;
    if (!checkRomModified()) {
        close = false;/*from  w  w w. j  a v  a  2  s .  com*/
    }

    if (close && config.getBoolean("Hazelnutt.gui.confirmExit", true)) {
        int res = JOptionPane.showConfirmDialog(this, "Do you really want to close Hazelnutt?", "Confirm",
                JOptionPane.YES_NO_OPTION);
        close = (res == JOptionPane.OK_OPTION);
    }

    if (close) {
        logger.info("Saving configuration values...");

        boolean maximum = (getExtendedState() & JFrame.MAXIMIZED_BOTH) != 0;
        config.setProperty("Hazelnutt.gui.maximum", maximum);

        Point loc = getLocation();
        Dimension size = getSize();
        config.setProperty("Hazelnutt.gui.location.x", (int) loc.getX());
        config.setProperty("Hazelnutt.gui.location.y", (int) loc.getY());
        config.setProperty("Hazelnutt.gui.size.width", (int) size.getWidth());
        config.setProperty("Hazelnutt.gui.size.height", (int) size.getHeight());

        logger.debug("Saving the last opened directory: '" + fileChooser.getCurrentDirectory() + "'");
        config.setProperty("Hazelnutt.gui.lastDirectory", fileChooser.getCurrentDirectory());

        logger.debug("Saving the recently opened files");
        config.clearProperty("Hazelnutt.gui.recentFiles");
        for (String str : recentFiles) {
            config.addProperty("Hazelnutt.gui.recentFiles", str);
        }

        logger.trace("Closing program...");
        dispose();

        //memoryMonitor.cancel( true );
    }
}

From source file:org.tsho.dmc2.core.chart.jfree.DmcChartPanel.java

/**
 * Translates a screen location to a Java2D point.
 *
 * @param screenPoint  the screen location.
 *
 * @return the Java2D coordinates.//w w  w .j a  va 2s.c om
 */
public Point2D translateScreenToJava2D(Point screenPoint) {
    Insets insets = getInsets();
    double x = (screenPoint.getX() - insets.left);
    double y = (screenPoint.getY() - insets.top);
    return new Point2D.Double(x, y);
}

From source file:org.processmining.analysis.performance.dottedchart.ui.DottedChartPanel.java

/**
 * adjusts the viewable are of the log (zoom)
 * // w  w w . j a  v a 2 s  .  c o m
 * @param aZoom
 *            fraction of the log to be viewable (within (0,1] !)
 */
public void setViewportZoomY(double aZoom) {
    if (aZoom > 1.0) { // ensure sane values
        viewportZoomY = 1.0;
    } else if (aZoom <= 0.0) {
        viewportZoomY = 0.00000000001;
    } else {
        viewportZoomY = aZoom;
    }
    double ratio = updHight;
    updHight = (int) ((double) getParent().getHeight() * (1.0 / aZoom));
    ratio = updHight / ratio;
    Dimension dim = new Dimension(updWidth, updHight);
    Point d = dca.getScrollPane().getViewport().getViewPosition();
    Point p = new Point((int) d.getX(), (int) ((double) d.getY() * (ratio)));
    this.setPreferredSize(dim);
    updateMilli2pixelsRatio();

    this.revalidate();
    dca.setScrollBarPosition(p);
}