Example usage for java.awt Point getY

List of usage examples for java.awt Point getY

Introduction

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

Prototype

public double getY() 

Source Link

Usage

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

/**
 * adjusts the viewable are of the log (zoom)
 * //from  ww w. j a  v a  2 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/* w  w  w .ja  va2 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  www  . j  av a 2  s . c  o  m*/
 * @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.
 * //  w w w . ja v  a 2 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();// ww w  .  j  a  v a2 s  .  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 www .  j ava2 s. co m
    }

    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. java  2 s .c  o  m*/
 */
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)
 * //from  w w  w. j  a v  a2  s . com
 * @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);
}

From source file:de.tor.tribes.ui.panels.MinimapPanel.java

/**
 * Creates new form MinimapPanel//w ww .  j  a  v  a  2s  .com
 */
MinimapPanel() {
    initComponents();
    setSize(300, 300);
    mMinimapListeners = new LinkedList<>();
    mToolChangeListeners = new LinkedList<>();
    setCursor(ImageManager.getCursor(iCurrentCursor));
    mScreenshotPanel = new ScreenshotPanel();
    minimapButtons.put(ID_MINIMAP, new Rectangle(2, 2, 26, 26));
    minimapButtons.put(ID_ALLY_CHART, new Rectangle(30, 2, 26, 26));
    minimapButtons.put(ID_TRIBE_CHART, new Rectangle(60, 2, 26, 26));
    try {
        minimapIcons.put(ID_MINIMAP, ImageIO.read(new File("./graphics/icons/minimap.png")));
        minimapIcons.put(ID_ALLY_CHART, ImageIO.read(new File("./graphics/icons/ally_chart.png")));
        minimapIcons.put(ID_TRIBE_CHART, ImageIO.read(new File("./graphics/icons/tribe_chart.png")));
    } catch (Exception ignored) {
    }
    jPanel1.add(mScreenshotPanel);
    rVisiblePart = new Rectangle(ServerSettings.getSingleton().getMapDimension());
    zoomed = false;
    MarkerManager.getSingleton().addManagerListener(this);
    TagManager.getSingleton().addManagerListener(this);
    MinimapRepaintThread.getSingleton().setVisiblePart(rVisiblePart);
    if (!GlobalOptions.isMinimal()) {
        MinimapRepaintThread.getSingleton().start();
    }
    addMouseListener(new MouseListener() {
        @Override
        public void mouseClicked(MouseEvent e) {
            if (!showControls && e.getButton() != MouseEvent.BUTTON1) {
                //show controls
                Point p = e.getPoint();
                p.translate(-5, -5);
                showControls(p);
                return;
            }
            if (!showControls && iCurrentView == ID_MINIMAP) {
                Point p = mousePosToMapPosition(e.getX(), e.getY());
                DSWorkbenchMainFrame.getSingleton().centerPosition(p.getX(), p.getY());
                MapPanel.getSingleton().getMapRenderer().initiateRedraw(MapRenderer.ALL_LAYERS);
                if (MinimapZoomFrame.getSingleton().isVisible()) {
                    MinimapZoomFrame.getSingleton().toFront();
                }
            } else {
                if (minimapButtons.get(ID_MINIMAP).contains(e.getPoint())) {
                    iCurrentView = ID_MINIMAP;
                    mBuffer = null;
                    showControls = false;
                    MinimapRepaintThread.getSingleton().update();
                } else if (minimapButtons.get(ID_ALLY_CHART).contains(e.getPoint())) {
                    iCurrentView = ID_ALLY_CHART;
                    lastHash = 0;
                    showControls = false;
                    updateComplete();
                } else if (minimapButtons.get(ID_TRIBE_CHART).contains(e.getPoint())) {
                    iCurrentView = ID_TRIBE_CHART;
                    lastHash = 0;
                    showControls = false;
                    updateComplete();
                }
            }
        }

        @Override
        public void mousePressed(MouseEvent e) {
            if (iCurrentView != ID_MINIMAP) {
                return;
            }
            if (iCurrentCursor == ImageManager.CURSOR_SHOT || iCurrentCursor == ImageManager.CURSOR_ZOOM) {
                iXDown = e.getX();
                iYDown = e.getY();
            }
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            if (iCurrentView != ID_MINIMAP) {
                return;
            }
            if (rDrag == null) {
                return;
            }
            if (iCurrentCursor == ImageManager.CURSOR_SHOT) {
                try {
                    BufferedImage i = MinimapRepaintThread.getSingleton().getImage();
                    double widthFactor = ((double) ServerSettings.getSingleton().getMapDimension().width)
                            / getWidth();
                    double heightFactor = ((double) ServerSettings.getSingleton().getMapDimension().height)
                            / getHeight();

                    int x = (int) Math.rint(widthFactor * rDrag.getX());
                    int y = (int) Math.rint(heightFactor * rDrag.getY());
                    int w = (int) Math.rint(widthFactor * (rDrag.getWidth() - rDrag.getX()));
                    int h = (int) Math.rint(heightFactor * (rDrag.getHeight() - rDrag.getY()));
                    BufferedImage sub = i.getSubimage(x, y, w, h);
                    mScreenshotPanel.setBuffer(sub);
                    jPanel1.setSize(mScreenshotPanel.getSize());
                    jPanel1.setPreferredSize(mScreenshotPanel.getSize());
                    jPanel1.setMinimumSize(mScreenshotPanel.getSize());
                    jPanel1.setMaximumSize(mScreenshotPanel.getSize());
                    jScreenshotPreview.pack();
                    jScreenshotControl.pack();
                    jScreenshotPreview.setVisible(true);
                    jScreenshotControl.setVisible(true);
                } catch (Exception ie) {
                    logger.error("Failed to initialize mapshot", ie);
                }
            } else if (iCurrentCursor == ImageManager.CURSOR_ZOOM) {
                if (!zoomed) {
                    Rectangle mapDim = ServerSettings.getSingleton().getMapDimension();
                    double widthFactor = ((double) mapDim.width) / getWidth();
                    double heightFactor = ((double) mapDim.height) / getHeight();

                    int x = (int) Math.rint(widthFactor * rDrag.getX() + mapDim.getMinX());
                    int y = (int) Math.rint(heightFactor * rDrag.getY() + mapDim.getMinY());
                    int w = (int) Math.rint(widthFactor * (rDrag.getWidth() - rDrag.getX()));

                    if (w >= 10) {
                        rVisiblePart = new Rectangle(x, y, w, w);
                        MinimapRepaintThread.getSingleton().setVisiblePart(rVisiblePart);
                        redraw();
                        zoomed = true;
                    }
                } else {
                    rVisiblePart = new Rectangle(ServerSettings.getSingleton().getMapDimension());
                    MinimapRepaintThread.getSingleton().setVisiblePart(rVisiblePart);
                    redraw();
                    zoomed = false;
                }
                MinimapZoomFrame.getSingleton().setVisible(false);
            }
            iXDown = 0;
            iYDown = 0;
            rDrag = null;
        }

        @Override
        public void mouseEntered(MouseEvent e) {
            if (iCurrentView != ID_MINIMAP) {
                return;
            }
            switch (iCurrentCursor) {
            case ImageManager.CURSOR_ZOOM: {
                MinimapZoomFrame.getSingleton().setVisible(true);
            }
            }
        }

        @Override
        public void mouseExited(MouseEvent e) {
            if (MinimapZoomFrame.getSingleton().isVisible()) {
                MinimapZoomFrame.getSingleton().setVisible(false);
            }
            iXDown = 0;
            iYDown = 0;
            rDrag = null;
        }
    });

    addMouseMotionListener(new MouseMotionListener() {

        @Override
        public void mouseDragged(MouseEvent e) {
            if (iCurrentView != ID_MINIMAP) {
                return;
            }
            switch (iCurrentCursor) {
            case ImageManager.CURSOR_MOVE: {
                Point p = mousePosToMapPosition(e.getX(), e.getY());
                DSWorkbenchMainFrame.getSingleton().centerPosition(p.x, p.y);
                rDrag = null;
                break;
            }
            case ImageManager.CURSOR_SHOT: {
                rDrag = new Rectangle2D.Double(iXDown, iYDown, e.getX(), e.getY());
                break;
            }
            case ImageManager.CURSOR_ZOOM: {
                rDrag = new Rectangle2D.Double(iXDown, iYDown, e.getX(), e.getY());
                break;
            }
            }
        }

        @Override
        public void mouseMoved(MouseEvent e) {
            if (iCurrentView == ID_MINIMAP) {
                switch (iCurrentCursor) {
                case ImageManager.CURSOR_ZOOM: {
                    if (!MinimapZoomFrame.getSingleton().isVisible()) {
                        MinimapZoomFrame.getSingleton().setVisible(true);
                    }
                    int mapWidth = (int) ServerSettings.getSingleton().getMapDimension().getWidth();
                    int mapHeight = (int) ServerSettings.getSingleton().getMapDimension().getHeight();

                    int x = (int) Math.rint((double) mapWidth / (double) getWidth() * (double) e.getX());
                    int y = (int) Math.rint((double) mapHeight / (double) getHeight() * (double) e.getY());
                    MinimapZoomFrame.getSingleton().updatePosition(x, y);
                    break;
                }
                default: {
                    if (MinimapZoomFrame.getSingleton().isVisible()) {
                        MinimapZoomFrame.getSingleton().setVisible(false);
                    }
                }
                }
            }
            Point location = minimapButtons.get(ID_MINIMAP).getLocation();
            location.translate(-2, -2);
            if (!new Rectangle(location.x, location.y, 88, 30).contains(e.getPoint())) {
                //hide controls
                showControls = false;
                repaint();
            }
        }
    });

    addMouseWheelListener(new MouseWheelListener() {

        @Override
        public void mouseWheelMoved(MouseWheelEvent e) {

            if (iCurrentView != ID_MINIMAP) {
                return;
            }
            iCurrentCursor += e.getWheelRotation();
            if (iCurrentCursor == ImageManager.CURSOR_DEFAULT + e.getWheelRotation()) {
                if (e.getWheelRotation() < 0) {
                    iCurrentCursor = ImageManager.CURSOR_SHOT;
                } else {
                    iCurrentCursor = ImageManager.CURSOR_MOVE;
                }
            } else if (iCurrentCursor < ImageManager.CURSOR_MOVE) {
                iCurrentCursor = ImageManager.CURSOR_DEFAULT;
            } else if (iCurrentCursor > ImageManager.CURSOR_SHOT) {
                iCurrentCursor = ImageManager.CURSOR_DEFAULT;
            }
            if (iCurrentCursor != ImageManager.CURSOR_ZOOM) {
                if (MinimapZoomFrame.getSingleton().isVisible()) {
                    MinimapZoomFrame.getSingleton().setVisible(false);
                }
            } else {
                MinimapZoomFrame.getSingleton().setVisible(true);
            }
            setCurrentCursor(iCurrentCursor);
        }
    });

}

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

/**
 * adjusts the viewable are of the log (zoom)
 * /* www .j  a  va  2 s. c om*/
 * @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) ((double) 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) ((double) d.getX() * ratio), (int) ((double) d.getY()));

    this.setPreferredSize(dim);
    updateMilli2pixelsRatio();

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