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:Main.java

Point getScreenLocation(MouseEvent e) {
    Point cursor = e.getPoint();/*from  www .j a v a 2 s  .c om*/
    Point target_location = this.target.getLocationOnScreen();
    return new Point((int) (target_location.getX() + cursor.getX()),
            (int) (target_location.getY() + cursor.getY()));
}

From source file:net.sf.maltcms.chromaui.charts.tools.ChartTools.java

/**
 *
 * @param plot/*from   w  ww  . j  av  a2 s  .co m*/
 * @param screenPoint
 * @param screenDataArea
 * @return
 */
public static Point translatePointToImageCoord(XYPlot plot, final Point screenPoint,
        final Rectangle2D screenDataArea) {
    final ValueAxis da = plot.getDomainAxis();
    final ValueAxis ra = plot.getRangeAxis();

    final double x = da.java2DToValue(screenPoint.getX(), screenDataArea, plot.getDomainAxisEdge());
    final double y = ra.java2DToValue(screenPoint.getY(), screenDataArea, plot.getRangeAxisEdge());

    Logger.getLogger(ChartTools.class.getName()).log(Level.INFO, "{0} - {1}", new Object[] { x, y });

    if (x > 0 && y > 0) {
        return new Point((int) x, (int) y);
    }

    //        final double axisXperc = (x - plot.getDomainAxis().getLowerBound())
    //                / (plot.getDomainAxis().getUpperBound() - plot.getDomainAxis().getLowerBound());
    //        final double axisYperc = (y - plot.getRangeAxis().getLowerBound())
    //                / (plot.getRangeAxis().getUpperBound() - plot.getRangeAxis().getLowerBound());
    //
    //        System.out.println(axisXperc + " - " + axisYperc);
    //        final int newX = (int) (axisXperc * this.imageWidth);
    //        final int newY = (int) (axisYperc * this.imageHeight);
    return null;
}

From source file:UndoManagerDemo.java

public UndoManagerDemo() {
    super("Undo/Redo Demo");

    undoButton.setEnabled(false);//from  ww  w. ja v a  2s .c o m
    redoButton.setEnabled(false);

    JPanel buttonPanel = new JPanel(new GridLayout());
    buttonPanel.add(undoButton);
    buttonPanel.add(redoButton);

    getContentPane().add(buttonPanel, BorderLayout.NORTH);
    getContentPane().add(canvas, BorderLayout.CENTER);

    canvas.addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            Point point = new Point(e.getX(), e.getY());
            pointVector.addElement(point);

            undoManager.undoableEditHappened(
                    new UndoableEditEvent(canvas, new UndoablePaintSquare(point, pointVector)));

            undoButton.setText(undoManager.getUndoPresentationName());
            redoButton.setText(undoManager.getRedoPresentationName());
            undoButton.setEnabled(undoManager.canUndo());
            redoButton.setEnabled(undoManager.canRedo());
            canvas.repaint();
        }
    });

    undoButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                undoManager.undo();
            } catch (CannotRedoException cre) {
                cre.printStackTrace();
            }
            canvas.repaint();
            undoButton.setEnabled(undoManager.canUndo());
            redoButton.setEnabled(undoManager.canRedo());
        }
    });

    redoButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                undoManager.redo();
            } catch (CannotRedoException cre) {
                cre.printStackTrace();
            }
            canvas.repaint();
            undoButton.setEnabled(undoManager.canUndo());
            redoButton.setEnabled(undoManager.canRedo());
        }
    });

    setSize(400, 300);
    setVisible(true);
}

From source file:net.bioclipse.chart.ScatterPlotRenderer.java

/**
 * Marks a point for highlighting//w ww . j  av  a2s.c  o m
 * @param series series in the dataset
 * @param index index of the selected point
 * @return <code>true</code> if the point was marked, <code>false</code> otherwise, for example if the point was marked already.
 * @see XYDataSet
 */
public boolean addMarkedPoint(int index, int series) {
    Point p = new Point(index, series);
    if (!markedPoints.contains(p)) {
        markedPoints.add(p);
        return true;
    }
    return false;
}

From source file:com.db2eshop.gui.dialog.BaseDialog.java

/**
 * <p>relocate.</p>/*from  w ww.j  av a2  s.co  m*/
 */
public void relocate() {
    log.debug("Relocation.");

    Point location = mainFrame.getLocation();
    Point newLocation = new Point((int) location.getX() + 40, (int) location.getY() + 40);
    this.setLocation(newLocation);
}

From source file:fr.lig.sigma.astral.gui.graph.sugiyama.Node.java

public Node(E e, Layout<E, ?> layout, Transformer<E, String> labelTransformer) {
    this.e = e;/*www . j  av  a  2  s .c o  m*/
    this.layout = layout;
    lbl.setText(labelTransformer.transform(e));

    Dimension size = lbl.getPreferredSize();
    //if(size.getWidth() == 0)
    //    nodeSize = new Point(100, 25);
    nodeSize = new Point(size.getWidth(), size.getHeight());

}

From source file:com.offbynull.peernetic.debug.visualizer.VisualizerUtils.java

/**
 * Creates point on a circle.//from  w w  w .ja  v  a 2  s .co  m
 * @param radius radius of circle
 * @param percentage 0 to 1 percentage of where point is on circle -- 0.0 indicates that the point is at the top middle
 * @return new point on circle specified by {@code radius} and {@code percentage}
 * @throws IllegalArgumentException if {@code radius} is negative or a special double value (e.g. NaN/infinite/etc..), or if
 * {@code percentage} isn't between {@code 0.0 - 1.0}
 */
public static Point pointOnCircle(double radius, double percentage) {
    Validate.inclusiveBetween(0.0, Double.MAX_VALUE, radius);
    Validate.inclusiveBetween(0.0, 1.0, percentage);
    double angle = percentage * Math.PI * 2.0;
    angle -= Math.PI / 2.0; // adjust so that percentage 0.0 is at top middle, if not it'ld be at middle right

    double y = (Math.sin(angle) * radius) + radius; // NOPMD
    double x = (Math.cos(angle) * radius) + radius; // NOPMD

    return new Point((int) x, (int) y);
}

From source file:de.tud.kom.p2psim.impl.application.ido.moveModels.RandomPositionDistribution.java

@Override
public Point getNextPosition() {

    RandomGenerator r = Simulator.getRandom();

    Point p = new Point(r.nextInt(worldDimensionX), r.nextInt(worldDimensionY));

    return p;//  w  ww.  jav a  2s .c om
}

From source file:Main.java

public static void addMiddleButtonDragSupport(Component targetComponent) {
    MouseInputAdapter mia = new MouseInputAdapter() {
        int m_XDifference, m_YDifference;
        boolean m_dragging = false;

        public void mouseDragged(MouseEvent e) {
            if (!m_dragging)
                return;

            Component target = e.getComponent();
            Container c = target.getParent();
            if (c instanceof JViewport) {
                JViewport jv = (JViewport) c;
                Point p = jv.getViewPosition();
                int newX = p.x - (e.getX() - m_XDifference);
                int newY = p.y - (e.getY() - m_YDifference);

                int maxX = target.getWidth() - jv.getWidth();
                int maxY = target.getHeight() - jv.getHeight();
                if (newX < 0)
                    newX = 0;//from  w w w . j a  va  2  s.  c om
                if (newX > maxX)
                    newX = maxX;
                if (newY < 0)
                    newY = 0;
                if (newY > maxY)
                    newY = maxY;

                jv.setViewPosition(new Point(newX, newY));
            }
        }

        Cursor oldCursor;

        public void mousePressed(MouseEvent e) {
            if (SwingUtilities.isMiddleMouseButton(e)) {
                m_dragging = true;
                oldCursor = e.getComponent().getCursor();
                e.getComponent().setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
                m_XDifference = e.getX();
                m_YDifference = e.getY();
            }
        }

        public void mouseReleased(MouseEvent e) {
            if (m_dragging) {
                e.getComponent().setCursor(oldCursor);
                m_dragging = false;
            }
        }
    };
    targetComponent.addMouseMotionListener(mia);
    targetComponent.addMouseListener(mia);
}

From source file:fr.lig.sigma.astral.gui.graph.sugiyama.Node.java

Point getCtrPos() {
    return new Point(p.x + nodeSize.x / 2, p.y + nodeSize.y / 2);
}