Example usage for java.awt.event MouseAdapter MouseAdapter

List of usage examples for java.awt.event MouseAdapter MouseAdapter

Introduction

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

Prototype

MouseAdapter

Source Link

Usage

From source file:com.mirth.connect.client.ui.components.MirthIconTextField.java

public MirthIconTextField(ImageIcon icon) {
    setIcon(icon);/*from   w  ww  .  j a  va2 s .  c om*/

    addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent evt) {
            if (isIconActive(evt) && iconPopupMenuComponent != null) {
                JPopupMenu iconPopupMenu = new JPopupMenu();
                iconPopupMenu.insert(iconPopupMenuComponent, 0);
                iconPopupMenu.show(evt.getComponent(), evt.getX(), evt.getY());
            }
        }
    });

    addMouseMotionListener(new MouseMotionAdapter() {
        @Override
        public void mouseMoved(MouseEvent evt) {
            int cursorType = getCursor().getType();

            if (isIconActive(evt)) {
                if (StringUtils.isNotBlank(alternateToolTipText)) {
                    MirthIconTextField.super.setToolTipText(alternateToolTipText);
                }

                if (iconPopupMenuComponent != null) {
                    if (cursorType != Cursor.HAND_CURSOR) {
                        setCursor(new Cursor(Cursor.HAND_CURSOR));
                    }
                } else {
                    if (cursorType != Cursor.DEFAULT_CURSOR) {
                        setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
                    }
                }
            } else {
                if (StringUtils.isNotBlank(alternateToolTipText)) {
                    MirthIconTextField.super.setToolTipText(originalToolTipText);
                }

                if (cursorType != Cursor.TEXT_CURSOR) {
                    setCursor(new Cursor(Cursor.TEXT_CURSOR));
                }
            }
        }
    });
}

From source file:KeyTextComponent.java

public KeyTextComponent() {
    setBackground(Color.CYAN);/*www .j a  v  a 2  s .c  om*/
    KeyListener internalKeyListener = new KeyAdapter() {
        public void keyPressed(KeyEvent keyEvent) {
            if (actionListenerList != null) {
                int keyCode = keyEvent.getKeyCode();
                String keyText = KeyEvent.getKeyText(keyCode);
                ActionEvent actionEvent = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, keyText);
                actionListenerList.actionPerformed(actionEvent);
            }
        }
    };
    MouseListener internalMouseListener = new MouseAdapter() {
        public void mousePressed(MouseEvent mouseEvent) {
            requestFocusInWindow();
        }
    };
    addKeyListener(internalKeyListener);
    addMouseListener(internalMouseListener);
}

From source file:UndoableDrawingPanel.java

public UndoableDrawingPanel() {
    MouseListener mouseListener = new MouseAdapter() {
        public void mouseReleased(MouseEvent mouseEvent) {
            StateEdit stateEdit = new StateEdit(UndoableDrawingPanel.this);
            polygon.addPoint(mouseEvent.getX(), mouseEvent.getY());
            stateEdit.end();//  w  ww.  j  a va2 s  .  c  om
            undoableEditSupport.postEdit(stateEdit);
            repaint();
        }
    };
    addMouseListener(mouseListener);
}

From source file:Main.java

public DrawPad() {
    setDoubleBuffered(false);/*from  w ww. j  a v  a  2 s  .  com*/
    addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            oldX = e.getX();
            oldY = e.getY();
        }
    });
    addMouseMotionListener(new MouseMotionAdapter() {
        public void mouseDragged(MouseEvent e) {
            currentX = e.getX();
            currentY = e.getY();
            if (graphics2D != null)
                graphics2D.drawLine(oldX, oldY, currentX, currentY);
            repaint();
            oldX = currentX;
            oldY = currentY;
        }
    });
}

From source file:Main.java

public Main(JFrame frame) {
    this.frame = frame;
    cursor = new Point();
    this.addMouseMotionListener(new MouseMotionAdapter() {
        public void mouseMoved(MouseEvent evt) {
            cursor = new Point(evt.getPoint());
            Main.this.repaint();
        }//from  w  w  w.  j  a v a 2s.co m
    });
    this.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent evt) {
            Main.this.setVisible(false);
        }
    });
}

From source file:hwcdhackwaterloo.GUIMain.java

/**
 * Creates new form NewJFrame/*from  w  w  w.j a v  a  2s.  c  om*/
 */
public GUIMain() {
    initComponents();
    menuPanel.addMouseListener(new MouseAdapter() {

        public void mousePressed(MouseEvent e) {
            posX = e.getX();
            posY = e.getY();
        }
    });
    menuPanel.addMouseMotionListener(new MouseAdapter() {
        public void mouseDragged(MouseEvent evt) {
            //sets frame position when mouse dragged         
            setLocation(evt.getXOnScreen() - posX, evt.getYOnScreen() - posY);

        }
    });
}

From source file:UndoableDrawingPanel2.java

public UndoableDrawingPanel2() {
    MouseListener mouseListener = new MouseAdapter() {
        public void mouseReleased(MouseEvent mouseEvent) {
            StateEdit stateEdit = new StateEdit(UndoableDrawingPanel2.this);
            polygon.addPoint(mouseEvent.getX(), mouseEvent.getY());
            stateEdit.end();//from   ww  w . j  a  v  a2  s.  c om
            undoableEditSupport.postEdit(stateEdit);
            repaint();
        }
    };
    addMouseListener(mouseListener);
}

From source file:Main.java

public Main() {
    Icon icon = UIManager.getIcon("html.pendingImage");
    JTabbedPane jtb = new JTabbedPane();

    JPanel jplInnerPanel1 = createInnerPanel("Tab 1: Tooltip and Icon");
    jtb.addTab("One", icon, jplInnerPanel1, "Tab 1");
    jtb.setSelectedIndex(0);//from   w w w.ja  v  a 2 s.  com

    JPanel jplInnerPanel2 = createInnerPanel("Tab 2: Icon only");
    jtb.addTab("Two", icon, jplInnerPanel2);

    JPanel jplInnerPanel3 = createInnerPanel("Tab 3: Tooltip and Icon");
    jtb.addTab("Three", icon, jplInnerPanel3, "Tab 3");

    JPanel jplInnerPanel4 = createInnerPanel("Tab 4: Text only");
    jtb.addTab("Four", jplInnerPanel4);

    menu.add(new JMenuItem("Item 1"));
    menu.add(new JMenuItem("Item 2"));

    JLabel tab4Label = new JLabel();
    tab4Label.setText("Four");
    jtb.setTabComponentAt(3, tab4Label);
    tab4Label.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent e) {
            maybeShowPopup(e);
        }

        @Override
        public void mousePressed(MouseEvent e) {
            maybeShowPopup(e);
        }

        private void maybeShowPopup(MouseEvent e) {
            jtb.getModel().setSelectedIndex(3);
            if (e.isPopupTrigger()) {
                menu.show(e.getComponent(), e.getX(), e.getY());
            }
        }
    });
    setLayout(new GridLayout());
    add(jtb);
}

From source file:MainClass.java

public MainClass() {
    final JTree tree;
    final JTextField jtf;

    DefaultMutableTreeNode top = new DefaultMutableTreeNode("Options");

    DefaultMutableTreeNode a = new DefaultMutableTreeNode("A");
    top.add(a);//from   ww w  . j ava 2s  .c o  m
    DefaultMutableTreeNode a1 = new DefaultMutableTreeNode("A1");
    a.add(a1);
    DefaultMutableTreeNode a2 = new DefaultMutableTreeNode("A2");
    a.add(a2);

    DefaultMutableTreeNode b = new DefaultMutableTreeNode("B");
    top.add(b);
    DefaultMutableTreeNode b1 = new DefaultMutableTreeNode("B1");
    b.add(b1);
    DefaultMutableTreeNode b2 = new DefaultMutableTreeNode("B2");
    b.add(b2);
    DefaultMutableTreeNode b3 = new DefaultMutableTreeNode("B3");
    b.add(b3);

    tree = new JTree(top);

    JScrollPane jsp = new JScrollPane(tree);

    add(jsp, BorderLayout.CENTER);

    jtf = new JTextField("", 20);
    add(jtf, BorderLayout.SOUTH);

    tree.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent me) {
            TreePath tp = tree.getPathForLocation(me.getX(), me.getY());
            if (tp != null)
                jtf.setText(tp.toString());
            else
                jtf.setText("");
        }
    });

}

From source file:UndoManagerDemo.java

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

    undoButton.setEnabled(false);//from   ww w . j  a  va 2  s . 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);
}