Example usage for java.awt Cursor MOVE_CURSOR

List of usage examples for java.awt Cursor MOVE_CURSOR

Introduction

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

Prototype

int MOVE_CURSOR

To view the source code for java.awt Cursor MOVE_CURSOR.

Click Source Link

Document

The move cursor type.

Usage

From source file:Main.java

public static void main(String[] args) {
    JFrame aWindow = new JFrame();
    aWindow.setBounds(200, 200, 200, 200);
    aWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    aWindow.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
    aWindow.setVisible(true);/*from   w  w w  .j a  v  a 2 s  .  com*/
}

From source file:Main.java

public GrabAndScrollLabel(ImageIcon i) {
    super(i);/*from   w w w. j a  v a2  s. c  o m*/

    MouseInputAdapter mia = new MouseInputAdapter() {
        int xDiff, yDiff;
        Container c;

        public void mouseDragged(MouseEvent e) {
            c = GrabAndScrollLabel.this.getParent();
            if (c instanceof JViewport) {
                JViewport jv = (JViewport) c;
                Point p = jv.getViewPosition();
                int newX = p.x - (e.getX() - xDiff);
                int newY = p.y - (e.getY() - yDiff);

                int maxX = GrabAndScrollLabel.this.getWidth() - jv.getWidth();
                int maxY = GrabAndScrollLabel.this.getHeight() - jv.getHeight();
                if (newX < 0)
                    newX = 0;
                if (newX > maxX)
                    newX = maxX;
                if (newY < 0)
                    newY = 0;
                if (newY > maxY)
                    newY = maxY;

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

        public void mousePressed(MouseEvent e) {
            setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
            xDiff = e.getX();
            yDiff = e.getY();
        }

        public void mouseReleased(MouseEvent e) {
            setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
        }
    };
    addMouseMotionListener(mia);
    addMouseListener(mia);
}

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  ww  w .  j  a v  a 2  s.c o  m*/
                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:GrabAndDragDemo.java

public GrabAndScrollLabel(ImageIcon i) {
    super(i);/*w w  w.j a v  a2s  . co m*/

    MouseInputAdapter mia = new MouseInputAdapter() {
        int xDiff, yDiff;

        boolean isDragging;

        Container c;

        public void mouseDragged(MouseEvent e) {
            c = GrabAndScrollLabel.this.getParent();
            if (c instanceof JViewport) {
                JViewport jv = (JViewport) c;
                Point p = jv.getViewPosition();
                int newX = p.x - (e.getX() - xDiff);
                int newY = p.y - (e.getY() - yDiff);

                int maxX = GrabAndScrollLabel.this.getWidth() - jv.getWidth();
                int maxY = GrabAndScrollLabel.this.getHeight() - jv.getHeight();
                if (newX < 0)
                    newX = 0;
                if (newX > maxX)
                    newX = maxX;
                if (newY < 0)
                    newY = 0;
                if (newY > maxY)
                    newY = maxY;

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

        public void mousePressed(MouseEvent e) {
            setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
            xDiff = e.getX();
            yDiff = e.getY();
        }

        public void mouseReleased(MouseEvent e) {
            setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
        }
    };
    addMouseMotionListener(mia);
    addMouseListener(mia);
}

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

public Cursor selectCursor() {
    Cursor cursor = defaultCursor;
    switch (state) {
    case BAR_MOVE:
        cursor = new Cursor(Cursor.MOVE_CURSOR);
        break;/* ww w  .  j av a  2 s .  co  m*/
    case LINK_CREATION:
        cursor = getLinkCursor();
        break;
    case LINK_SELECTION:
        cursor = new Cursor(Cursor.CROSSHAIR_CURSOR);
        break;
    }
    getGraph().setCursor(cursor);
    return cursor;
}

From source file:pl.edu.icm.visnow.lib.basic.viewers.Viewer2D.Display2DPanel.java

private void formMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMousePressed
    if (evt.getButton() == MouseEvent.BUTTON1) {
        oldX = evt.getX();/*w  w  w .  j  a va  2s.  c  om*/
        oldY = evt.getY();
        if (!noObjects) {
            move = true;
            this.setCursor(new Cursor(Cursor.MOVE_CURSOR));
        }
    }
}

From source file:JavaXWin.java

public WindowWatcher(JDesktopPane desktop) {
    m_desktop = desktop;//ww w .  jav a 2s.  c om
    setOpaque(true);

    m_northResizer = new NorthResizeEdge(this);
    m_southResizer = new SouthResizeEdge(this);
    m_eastResizer = new EastResizeEdge(this);
    m_westResizer = new WestResizeEdge(this);

    setLayout(new BorderLayout());
    add(m_northResizer, BorderLayout.NORTH);
    add(m_southResizer, BorderLayout.SOUTH);
    add(m_eastResizer, BorderLayout.EAST);
    add(m_westResizer, BorderLayout.WEST);

    MouseInputAdapter ma = new MouseInputAdapter() {
        public void mousePressed(MouseEvent e) {
            m_XDifference = e.getX();
            m_YDifference = e.getY();
        }

        public void mouseDragged(MouseEvent e) {
            int vx = 0;
            int vy = 0;
            if (m_desktop.getParent() instanceof JViewport) {
                vx = ((JViewport) m_desktop.getParent()).getViewPosition().x;
                vy = ((JViewport) m_desktop.getParent()).getViewPosition().y;
            }
            int w = m_desktop.getParent().getWidth();
            int h = m_desktop.getParent().getHeight();
            int x = getX();
            int y = getY();
            int ex = e.getX();
            int ey = e.getY();
            if ((ey + y > vy && ey + y < h + vy) && (ex + x > vx && ex + x < w + vx)) {
                setLocation(ex - m_XDifference + x, ey - m_YDifference + y);
            } else if (!(ey + y > vy && ey + y < h + vy) && (ex + x > vx && ex + x < w + vx)) {
                if (!(ey + y > vy) && ey + y < h + vy)
                    setLocation(ex - m_XDifference + x, vy - m_YDifference);
                else if (ey + y > vy && !(ey + y < h + vy))
                    setLocation(ex - m_XDifference + x, (h + vy) - m_YDifference);
            } else if ((ey + y > vy && ey + y < h + vy) && !(ex + x > vx && ex + x < w + vx)) {
                if (!(ex + x > vx) && ex + x < w + vx)
                    setLocation(vx - m_XDifference, ey - m_YDifference + y);
                else if (ex + x > vx && !(ex + x < w))
                    setLocation((w + vx) - m_XDifference, ey - m_YDifference + y);
            } else if (!(ey + y > vy) && ey + y < h + vy && !(ex + x > vx) && ex + x < w + vx)
                setLocation(vx - m_XDifference, vy - m_YDifference);
            else if (!(ey + y > vy) && ey + y < h + vy && ex + x > vx && !(ex + x < w + vx))
                setLocation((w + vx) - m_XDifference, vy - m_YDifference);
            else if (ey + y > vy && !(ey + y < h + vy) && !(ex + x > vx) && ex + x < w + vx)
                setLocation(vx - m_XDifference, (h + vy) - m_YDifference);
            else if (ey + y > vy && !(ey + y < h + vy) && ex + x > vx && !(ex + x < w + vx))
                setLocation((w + vx) - m_XDifference, (h + vy) - m_YDifference);
        }

        public void mouseEntered(MouseEvent e) {
            setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
        }

        public void mouseExited(MouseEvent e) {
            setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
        }
    };
    addMouseListener(ma);
    addMouseMotionListener(ma);
}

From source file:org.gumtree.vis.hist2d.Hist2DPanel.java

private void changeSelectedMask(Point2D point) {
    switch (getMaskDragIndicator()) {
    case Cursor.MOVE_CURSOR:
        moveMask(point);// w  ww  .j av  a  2s .co m
        break;
    case Cursor.W_RESIZE_CURSOR:
        if (((XYPlot) getChart().getPlot()).getDomainAxis().isInverted()) {
            changeMaskXMax(point.getX());
        } else {
            changeMaskXMin(point.getX());
        }
        break;
    case Cursor.E_RESIZE_CURSOR:
        if (((XYPlot) getChart().getPlot()).getDomainAxis().isInverted()) {
            changeMaskXMin(point.getX());
        } else {
            changeMaskXMax(point.getX());
        }
        break;
    case Cursor.N_RESIZE_CURSOR:
        if (((XYPlot) getChart().getPlot()).getRangeAxis().isInverted()) {
            changeMaskYMin(point.getY());
        } else {
            changeMaskYMax(point.getY());
        }
        break;
    case Cursor.S_RESIZE_CURSOR:
        if (((XYPlot) getChart().getPlot()).getRangeAxis().isInverted()) {
            changeMaskYMax(point.getY());
        } else {
            changeMaskYMin(point.getY());
        }
        break;
    case Cursor.NW_RESIZE_CURSOR:
        if (((XYPlot) getChart().getPlot()).getDomainAxis().isInverted()) {
            changeMaskXMax(point.getX());
        } else {
            changeMaskXMin(point.getX());
        }
        if (((XYPlot) getChart().getPlot()).getRangeAxis().isInverted()) {
            changeMaskYMin(point.getY());
        } else {
            changeMaskYMax(point.getY());
        }
        break;
    case Cursor.NE_RESIZE_CURSOR:
        if (((XYPlot) getChart().getPlot()).getDomainAxis().isInverted()) {
            changeMaskXMin(point.getX());
        } else {
            changeMaskXMax(point.getX());
        }
        if (((XYPlot) getChart().getPlot()).getRangeAxis().isInverted()) {
            changeMaskYMin(point.getY());
        } else {
            changeMaskYMax(point.getY());
        }
        break;
    case Cursor.SW_RESIZE_CURSOR:
        if (((XYPlot) getChart().getPlot()).getDomainAxis().isInverted()) {
            changeMaskXMax(point.getX());
        } else {
            changeMaskXMin(point.getX());
        }
        if (((XYPlot) getChart().getPlot()).getRangeAxis().isInverted()) {
            changeMaskYMax(point.getY());
        } else {
            changeMaskYMin(point.getY());
        }
        break;
    case Cursor.SE_RESIZE_CURSOR:
        if (((XYPlot) getChart().getPlot()).getDomainAxis().isInverted()) {
            changeMaskXMin(point.getX());
        } else {
            changeMaskXMax(point.getX());
        }
        if (((XYPlot) getChart().getPlot()).getRangeAxis().isInverted()) {
            changeMaskYMax(point.getY());
        } else {
            changeMaskYMin(point.getY());
        }
        break;
    default:
        break;
    }
    fireMaskUpdateEvent(getSelectedMask());
}

From source file:com.cmsoftware.keyron.vista.Login.java

private void panelContenidoMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_panelContenidoMousePressed
    yAnterior = evt.getY();/*from   ww  w .  j a va2  s.co  m*/
    xAnterior = evt.getX();
    this.setCursor(new Cursor(Cursor.MOVE_CURSOR));
}

From source file:com.floreantpos.jasperreport.swing.JRViewerPanel.java

void pnlLinksMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_pnlLinksMousePressed
    // Add your handling code here:
    pnlLinks.setCursor(new Cursor(Cursor.MOVE_CURSOR));

    downX = evt.getX();/* w  w w .j a v a 2 s.  com*/
    downY = evt.getY();
}