Example usage for java.awt Point Point

List of usage examples for java.awt Point Point

Introduction

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

Prototype

public Point(int x, int y) 

Source Link

Document

Constructs and initializes a point at the specified (x,y) location in the coordinate space.

Usage

From source file:it.unibas.spicygui.controllo.provider.MyPopupSceneMatcher.java

private void showSliderImpl(LayerWidget constraintslayer, Point point) {

    ComponentWidget componentWidget = new ComponentWidget(scene, slider);

    componentWidget.getActions().addAction(ActionFactory.createMoveAction());

    CaratteristicheBarra caratteristicheBarra = new CaratteristicheBarra(componentWidget,
            Costanti.INTERMEDIE_BARRA);//from  w w w . j a  v  a 2 s.  com
    IconNodeWidget barra = new IconNodeWidget(scene);
    barra.setLayout(LayoutFactory.createHorizontalFlowLayout());
    barra.setImage(ImageUtilities.loadImage(Costanti.ICONA_MOVE));
    ComponentWidget labelConfidence = new ComponentWidget(scene, jLabelConfidenceLevel);
    labelConfidence.setPreferredSize(new Dimension(100, 10));
    barra.addChild(labelConfidence);
    Point pointBarra = new Point(point.x - Costanti.OFF_SET_X_WIDGET_BARRA,
            point.y - Costanti.OFF_SET_Y_WIDGET_BARRA);
    barra.setPreferredLocation(pointBarra);
    MyMoveProviderGeneric moveProvider = new MyMoveProviderGeneric();
    barra.getActions().addAction(ActionFactory.createMoveAction(moveProvider, moveProvider));

    //        int x = myGraphScene.getBounds()
    componentWidget.setPreferredLocation(new Point(point.x, point.y));
    constraintslayer.addChild(componentWidget, barra);
    constraintslayer.addChild(barra, caratteristicheBarra);
    scene.validate();
    myGraphScene.updateUI();
}

From source file:com.sshtools.appframework.ui.SshToolsApplicationFrame.java

/**
 * @param application//from w w w  .j a  v a  2s  .  co m
 * @param panel
 * 
 * @throws SshToolsApplicationException
 */

public void init(final SshToolsApplication application, SshToolsApplicationPanel panel)
        throws SshToolsApplicationException {
    log.debug("Initialising frame");
    this.panel = panel;
    this.application = application;
    if (application != null) {
        setTitle(application.getApplicationName() + " - " + application.getApplicationVersion());
    }
    setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    // Register the File menu
    panel.registerActionMenu(new ActionMenu("File", "File", 'f', 0));
    // Register the Exit action
    if (showExitAction && application != null) {
        panel.registerAction(exitAction = new ExitAction(application, this));
        // Register the New Window Action
    }
    if (showNewWindowAction && application != null) {
        panel.registerAction(newWindowAction = new NewWindowAction(application));
        // Register the Help menu
    }
    panel.registerActionMenu(new ActionMenu("Help", "Help", 'h', 99));
    // Register the About box action
    if (showAboutBox && application != null) {
        panel.registerAction(aboutAction = new AboutAction(this, application));
    }

    getApplicationPanel().rebuildActionComponents();
    // JPanel p = new JPanel(new ToolBarLayout());
    JPanel p = new JPanel(new BorderLayout(0, 0));
    JPanel center = new JPanel(new BorderLayout(0, 0));
    if (panel.getJMenuBar() != null) {
        setJMenuBar(panel.getJMenuBar());
    }

    if (panel.getToolBar() != null) {
        // center.add(toolSeparator = new JSeparator(JSeparator.HORIZONTAL),
        // BorderLayout.NORTH);
        // toolSeparator.setVisible(panel.getToolBar().isVisible());
        // panel.getToolBar().addComponentListener(new ComponentAdapter() {
        // public void componentShown(ComponentEvent e) {
        // toolSeparator.setVisible(SshToolsApplicationFrame.this.panel.getToolBar().isVisible());
        // }
        //
        // public void componentHidden(ComponentEvent e) {
        // toolSeparator.setVisible(SshToolsApplicationFrame.this.panel.getToolBar().isVisible());
        // }
        //
        // });
        final SshToolsApplicationPanel pnl = panel;
        panel.getToolBar().addComponentListener(new ComponentAdapter() {

            public void componentHidden(ComponentEvent evt) {
                // toolSeparator.setVisible(pnl.getToolBar().isVisible());

            }

        });
        p.add(panel.getToolBar(), BorderLayout.NORTH);
    }
    center.add(panel, BorderLayout.CENTER);
    p.add(center, BorderLayout.CENTER);
    getContentPane().setLayout(new GridLayout(1, 1, 0, 0));
    getContentPane().add(p);
    // Watch for the frame closing
    setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    addWindowListener(new WindowAdapter() {

        public void windowClosing(WindowEvent evt) {
            if (application != null) {
                application.closeContainer(SshToolsApplicationFrame.this);
            } else {
                int confirm = JOptionPane.showOptionDialog(SshToolsApplicationFrame.this,
                        "Close " + getTitle() + "?", "Close Operation", JOptionPane.YES_NO_OPTION,
                        JOptionPane.QUESTION_MESSAGE, null, null, null);
                if (confirm == 0) {
                    hide();
                }
            }

        }

    });
    // If this is the first frame, center the window on the screen
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    boolean found = false;
    if (application != null && application.getContainerCount() != 0) {
        for (int i = 0; (i < application.getContainerCount()) && !found; i++) {
            SshToolsApplicationContainer c = application.getContainerAt(i);
            if (c instanceof SshToolsApplicationFrame) {
                SshToolsApplicationFrame f = (SshToolsApplicationFrame) c;
                setSize(f.getSize());
                Point newLocation = new Point(f.getX(), f.getY());
                newLocation.x += 48;
                newLocation.y += 48;
                if (newLocation.x > (screenSize.getWidth() - 64)) {
                    newLocation.x = 0;
                }
                if (newLocation.y > (screenSize.getHeight() - 64)) {
                    newLocation.y = 0;
                }
                setLocation(newLocation);
                found = true;
            }
        }
    }
    if (!found) {
        // Is there a previous stored geometry we can use?
        if (PreferencesStore.preferenceExists(PREF_LAST_FRAME_GEOMETRY)) {
            setBounds(PreferencesStore.getRectangle(PREF_LAST_FRAME_GEOMETRY, getBounds()));
        } else {
            pack();
            setSize(800, 600);
            UIUtil.positionComponent(SwingConstants.CENTER, this);
        }
    }
    log.debug("Initialisation of frame complete");
}

From source file:com.kbot2.scriptable.methods.wrappers.Interface.java

public void doClick() {

    Rectangle rect = getArea();//from   w ww  . j a v  a2 s  .co  m
    final Point mousePos = getMethods().getMousePos();
    if (rect.contains(mousePos)) {
        int random = random(0, 5);
        if (random < 4) {
            botEnv.mouse.clickMouse(true);
            return;
        } else if (random == 4) {
            Point ranPoint = new Point(mousePos.x + random(-5, 5), mousePos.y + random(-5, 5));
            if (rect.contains(ranPoint)) {
                botEnv.methods.clickMouse(ranPoint, true);
                return;
            }
        }
    }
    int randomX = random(rect.x, rect.x + rect.width);
    int randomY = random(rect.y, rect.y + rect.height);
    botEnv.methods.clickMouse(new Point(randomX, randomY), true);
}

From source file:de.fhg.igd.mapviewer.server.wms.overlay.WMSTileOverlay.java

/**
 * @see AbstractTileOverlayPainter#repaintTile(int, int, int, int,
 *      PixelConverter, int)/*from www.ja  v a  2 s .c om*/
 */
@Override
public BufferedImage repaintTile(int posX, int posY, int width, int height, PixelConverter converter,
        int zoom) {
    // the first converter isn't regarded as a new converter because it's
    // always the empty map
    boolean isNewConverter = lastConverter != null && !converter.equals(lastConverter);
    lastConverter = converter;

    if (!converter.supportsBoundingBoxes()) {
        if (isNewConverter) {
            handleError(Messages.WMSTileOverlay_0 + configuration.getName() + Messages.WMSTileOverlay_1);
        }
        return null;
    }

    synchronized (this) {
        if (capabilities == null) {
            try {
                capabilities = WMSUtil.getCapabilities(configuration.getBaseUrl());
            } catch (WMSCapabilitiesException e) {
                log.error("Error getting WMS capabilities"); //$NON-NLS-1$
            }
        }
    }

    if (capabilities != null) {
        int mapEpsg = converter.getMapEpsg();

        WMSBounds box;
        synchronized (this) {
            if (capabilities.getSupportedSRS().contains("EPSG:" + mapEpsg)) { //$NON-NLS-1$
                // same SRS supported
            } else {
                // SRS not supported
                if (isNewConverter) {
                    StringBuilder message = new StringBuilder();
                    message.append(Messages.WMSTileOverlay_2);
                    message.append(configuration.getName());
                    message.append(Messages.WMSTileOverlay_3);
                    boolean init = true;
                    for (String srs : capabilities.getSupportedSRS()) {
                        if (init) {
                            init = false;
                        } else {
                            message.append(", "); //$NON-NLS-1$
                        }
                        message.append(srs);
                    }
                    handleError(message.toString());
                }
                return null;
            }

            box = WMSUtil.getBoundingBox(capabilities, mapEpsg);
        }

        String srs = box.getSRS();

        if (srs.startsWith("EPSG:")) { //$NON-NLS-1$
            // determine format
            String format = null;
            Iterator<String> itFormat = supportedFormats.iterator();
            synchronized (this) {
                while (format == null && itFormat.hasNext()) {
                    String supp = itFormat.next();
                    if (capabilities.getFormats().contains(supp)) {
                        format = supp;
                    }
                }
            }
            if (format == null) {
                // no compatible format
                return null;
            }

            try {
                // check if tile lies within the bounding box
                int epsg = Integer.parseInt(srs.substring(5));

                GeoPosition topLeft = converter.pixelToGeo(new Point(posX, posY), zoom);
                GeoPosition bottomRight = converter.pixelToGeo(new Point(posX + width, posY + height), zoom);

                // WMS bounding box
                BoundingBox wms = new BoundingBox(box.getMinX(), box.getMinY(), -1, box.getMaxX(),
                        box.getMaxY(), 1);

                GeoConverter geotools = GeotoolsConverter.getInstance();
                GeoPosition bbTopLeft = geotools.convert(topLeft, epsg);
                GeoPosition bbBottomRight = geotools.convert(bottomRight, epsg);

                double minX = Math.min(bbTopLeft.getX(), bbBottomRight.getX());
                double minY = Math.min(bbTopLeft.getY(), bbBottomRight.getY());
                double maxX = Math.max(bbTopLeft.getX(), bbBottomRight.getX());
                double maxY = Math.max(bbTopLeft.getY(), bbBottomRight.getY());

                BoundingBox tile = new BoundingBox(minX, minY, -1, maxX, maxY, 1);

                // check if bounding box and tile overlap
                if (wms.intersectsOrCovers(tile) || tile.covers(wms)) {
                    WMSBounds bounds;
                    if (epsg == mapEpsg) {
                        bounds = new WMSBounds(srs, minX, minY, maxX, maxY);
                    } else {
                        // determine bounds for request
                        minX = Math.min(topLeft.getX(), bottomRight.getX());
                        minY = Math.min(topLeft.getY(), bottomRight.getY());
                        maxX = Math.max(topLeft.getX(), bottomRight.getX());
                        maxY = Math.max(topLeft.getY(), bottomRight.getY());
                        bounds = new WMSBounds("EPSG:" + mapEpsg, minX, minY, maxX, maxY); //$NON-NLS-1$
                    }

                    URI uri;
                    synchronized (this) {
                        uri = WMSUtil.getMapURI(capabilities, configuration, width, height, bounds, null,
                                format, true);
                    }

                    Proxy proxy = ProxyUtil.findProxy(uri);

                    InputStream in = uri.toURL().openConnection(proxy).getInputStream();

                    BufferedImage image = GraphicsUtilities.loadCompatibleImage(in);

                    // apply transparency to the image
                    BufferedImage result = GraphicsUtilities.createCompatibleTranslucentImage(image.getWidth(),
                            image.getHeight());
                    Graphics2D g = result.createGraphics();
                    try {
                        AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC, 0.5f);
                        g.setComposite(ac);
                        g.drawImage(image, 0, 0, null);
                    } finally {
                        g.dispose();
                    }

                    return result;
                }
            } catch (Throwable e) {
                log.warn("Error painting WMS overlay", e); //$NON-NLS-1$
            }
        }
    }

    return null;
}

From source file:ec.ui.view.RevisionSaSeriesView.java

private void showSelectionPopup(Rectangle2D rectangle) {
    XYPlot plot = chartpanel_.getChart().getXYPlot();
    Rectangle2D dataArea = chartpanel_.getScreenDataArea();
    DateAxis domainAxis = (DateAxis) plot.getDomainAxis();
    double minX = domainAxis.java2DToValue(rectangle.getMinX(), dataArea, plot.getDomainAxisEdge());
    double maxX = domainAxis.java2DToValue(rectangle.getMaxX(), dataArea, plot.getDomainAxisEdge());

    Date startDate = new Date((long) minX);
    Date endDate = new Date((long) maxX);
    TsPeriod start = new TsPeriod(firstPeriod.getFrequency(), startDate);
    TsPeriod end = new TsPeriod(firstPeriod.getFrequency(), endDate);

    if (end.minus(start) == 0) {
        return;//from  w  ww.ja v a2s .  c o  m
    }

    TsPeriodSelector sel = new TsPeriodSelector();
    sel.between(start.firstday(), end.lastday());
    List<TsData> listSeries = history_.Select(info_, startDate, endDate);
    List<TsData> revSeries = new ArrayList<>();

    for (TsData t : listSeries) {
        revSeries.add(t.select(sel));
    }

    Point pt = new Point((int) rectangle.getX(), (int) rectangle.getY());
    pt.translate(3, 3);
    SwingUtilities.convertPointToScreen(pt, chartpanel_);
    popup.setLocation(pt);
    popup.setChartTitle(info_.toUpperCase() + " First estimations");
    popup.setTsData(sRef.select(sel), revSeries);
    popup.setVisible(true);
    chartpanel_.repaint();
}

From source file:fr.landel.utils.commons.CollectionUtils2Test.java

/**
 * Test method for {@link CollectionUtils2#toArray(java.util.Collection)}.
 *//*  www .j  a v  a  2  s  . com*/
@Test
public void testToArray() {
    try {
        List<Point> points = new ArrayList<>();
        points.add(new Point(1, 2));
        points.add(new Point(2, 0));
        points.add(null);

        Point[] pointsArray = CollectionUtils2.toArray(points);

        assertNotNull(pointsArray);
        assertTrue(pointsArray.length > 0);
        assertThat(pointsArray, Matchers.arrayContaining(points.get(0), points.get(1), null));

        pointsArray = CollectionUtils2.toArray(points, Point.class);
        assertNotNull(pointsArray);
        assertTrue(pointsArray.length > 0);
        assertThat(pointsArray, Matchers.arrayContaining(points.get(0), points.get(1), null));

        assertNull(CollectionUtils2.toArray(null));

        points.clear();

        assertNull(CollectionUtils2.toArray(points));

        List<Object> objects = new ArrayList<>();
        objects.add(12);
        objects.add("text");
        assertThat(CollectionUtils2.toArray(objects), Matchers.arrayContaining(objects.get(0), objects.get(1)));

        String[] emptyArray = CollectionUtils2.toArray(Collections.<String>emptyList());
        assertNull(emptyArray);

        emptyArray = CollectionUtils2.toArray(Collections.<String>emptyList(), String.class);
        assertNotNull(emptyArray);
        assertTrue(ArrayUtils.isEmpty(emptyArray));
        assertTrue(emptyArray.getClass().isArray());

    } catch (IllegalArgumentException e) {
        fail("The test isn't correct");
    }
}

From source file:com.projity.pm.graphic.graph.GraphInteractor.java

protected Cursor getLinkCursor() {
    if (linkCursor == null) {
        try {//from  ww w . j  a v  a  2 s  .  com
            linkCursor = Toolkit.getDefaultToolkit().createCustomCursor(
                    IconManager.getImage("gantt.link.cursor"), new Point(7, 3), "linkCursor");
        } catch (Exception e) {
            linkCursor = new Cursor(Cursor.HAND_CURSOR);
        }
    }
    return linkCursor;
}

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

/**
 * Distance to the x/y. If the mouse is left of the left
 * waypoint then use the distance to the left point. Same with
 * the right waypoint. If is is between the end points then
 * use the y distance.//w w  w  .  ja v a 2  s .  c  om
 *
 * @param x mouse x
 * @param y mouse y
 *
 * @return distance
 */
public double distance(int x, int y) {
    lastDistanceCheckToRight = false;
    lastDistanceCheckToLeft = false;
    Point leftP = (Point) transform.transform(new Point(getLeft().getX(), this.y), new Point());

    Point rightP = (Point) transform.transform(new Point(getRight().getX(), this.y), new Point());

    if (x <= leftP.x) {
        lastDistanceCheckToLeft = true;
        return distance(x, y, leftP.x, leftP.y);
    } else if (x >= rightP.x) {
        lastDistanceCheckToRight = true;
        return distance(x, y, rightP.x, rightP.y);
    }
    return Math.abs(leftP.y - y);
}

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

@Override
public void zoom(Rectangle2D selection) {
    // get the origin of the zoom selection in the Java2D space used for
    // drawing the chart (that is, before any scaling to fit the panel)
    Point2D selectOrigin = translateScreenToJava2D(
            new Point((int) Math.ceil(selection.getX()), (int) Math.ceil(selection.getY())));
    PlotRenderingInfo plotInfo = getChartRenderingInfo().getPlotInfo();
    Rectangle2D scaledDataArea = getScreenDataArea((int) selection.getCenterX(), (int) selection.getCenterY());
    if ((selection.getHeight() > 0) && (selection.getWidth() > 0)) {

        double hLower = (selection.getMinX() - scaledDataArea.getMinX()) / scaledDataArea.getWidth();
        double hUpper = (selection.getMaxX() - scaledDataArea.getMinX()) / scaledDataArea.getWidth();
        double vLower = (scaledDataArea.getMaxY() - selection.getMaxY()) / scaledDataArea.getHeight();
        double vUpper = (scaledDataArea.getMaxY() - selection.getMinY()) / scaledDataArea.getHeight();

        Plot p = getChart().getPlot();//ww w.ja va  2  s . c o m
        if (p instanceof LinkAndBrushPlot) {

            PlotOrientation orientation = null;
            if (p instanceof XYPlot) {
                XYPlot xyPlot = (XYPlot) p;
                orientation = xyPlot.getOrientation();
            }
            if (p instanceof CategoryPlot) {
                CategoryPlot categoryPlot = (CategoryPlot) p;
                orientation = categoryPlot.getOrientation();
            }

            // here we tweak the notify flag on the plot so that only
            // one notification happens even though we update multiple
            // axes...

            boolean savedNotify = p.isNotify();
            p.setNotify(false);
            LinkAndBrushPlot LABPlot = (LinkAndBrushPlot) p;

            List<Pair<Integer, Range>> zoomedDomainAxisRanges = new LinkedList<Pair<Integer, Range>>();
            List<Pair<Integer, Range>> zoomedRangeAxisRanges = new LinkedList<Pair<Integer, Range>>();

            if (orientation == PlotOrientation.HORIZONTAL) {
                zoomedDomainAxisRanges
                        .addAll(LABPlot.calculateDomainAxesZoom(vLower, vUpper, zoomOnLinkAndBrushSelection));
                zoomedRangeAxisRanges.addAll(LABPlot.calculateRangeAxesZoom(hLower, hUpper, plotInfo,
                        selectOrigin, zoomOnLinkAndBrushSelection));
            } else {
                zoomedDomainAxisRanges
                        .addAll(LABPlot.calculateDomainAxesZoom(hLower, hUpper, zoomOnLinkAndBrushSelection));
                zoomedRangeAxisRanges.addAll(LABPlot.calculateRangeAxesZoom(vLower, vUpper, plotInfo,
                        selectOrigin, zoomOnLinkAndBrushSelection));
            }
            p.setNotify(savedNotify);

            if (zoomOnLinkAndBrushSelection) {
                informLinkAndBrushSelectionListeners(new LinkAndBrushSelection(SelectionType.ZOOM_IN,
                        zoomedDomainAxisRanges, zoomedRangeAxisRanges));
            } else {
                informLinkAndBrushSelectionListeners(new LinkAndBrushSelection(SelectionType.SELECTION,
                        zoomedDomainAxisRanges, zoomedRangeAxisRanges));
            }

        } else {
            super.zoom(selection);
        }
    }
}

From source file:de.codesourcery.jasm16.ide.ApplicationConfig.java

@Override
public SizeAndLocation getViewCoordinates(String viewId) {
    final String posKey = KEY_VIEW_COORDINATES_PREFIX + viewId + ".position";
    final String sizeKey = KEY_VIEW_COORDINATES_PREFIX + viewId + ".size";

    final String posValue = this.configProperties.get(posKey);
    final String sizeValue = this.configProperties.get(sizeKey);

    if (StringUtils.isBlank(posValue) || StringUtils.isBlank(sizeValue)) {
        return null;
    }//  ww w  . j a v  a 2  s  .com

    String[] parts = posValue.split(",");
    final int x = Integer.parseInt(parts[0]);
    final int y = Integer.parseInt(parts[1]);

    parts = sizeValue.split(",");
    final int width = Integer.parseInt(parts[0]);
    final int height = Integer.parseInt(parts[1]);

    return new SizeAndLocation(new Point(x, y), new Dimension(width, height));
}