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

public KeyTextComponent2() {
    setBackground(Color.cyan);/* www .  ja va  2s.  co m*/
    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);
                fireActionPerformed(actionEvent);
            }
        }
    };

    MouseListener internalMouseListener = new MouseAdapter() {
        public void mousePressed(MouseEvent mouseEvent) {
            requestFocus();
        }
    };

    addKeyListener(internalKeyListener);
    addMouseListener(internalMouseListener);
}

From source file:Simulator.java

private void AddMouseListeners() {
    map().addMouseListener(new MouseAdapter() {
        @Override/*from  w w w .j a v a  2s.  c  o m*/
        public void mouseClicked(MouseEvent e) {
            if (e.getButton() == MouseEvent.BUTTON1) {
                map().getAttribution().handleAttribution(e.getPoint(), true);
            }
        }
    });

    map().addMouseMotionListener(new MouseAdapter() {
        @Override
        public void mouseMoved(MouseEvent e) {
            Point p = e.getPoint();
            boolean cursorHand = map().getAttribution().handleAttributionCursor(p);
            if (cursorHand) {
                map().setCursor(new Cursor(Cursor.HAND_CURSOR));
            } else {
                map().setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
            }
        }
    });
}

From source file:Main.java

public KeyTextComponent() {
    setBackground(Color.CYAN);//from  w  w w. jav 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_FIRST, keyText,
                        ActionEvent.ALT_MASK);
                fireActionPerformed(actionEvent);
            }
        }
    };

    MouseListener internalMouseListener = new MouseAdapter() {
        public void mousePressed(MouseEvent mouseEvent) {
            requestFocusInWindow();
        }
    };

    addKeyListener(internalKeyListener);
    addMouseListener(internalMouseListener);
}

From source file:Main.java

public KeyTextComponent() {
    setBackground(Color.CYAN);/*from  w w  w. j  a  va  2  s .c  o  m*/
    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_FIRST, keyText,
                        System.currentTimeMillis() - 10, ActionEvent.ALT_MASK);
                fireActionPerformed(actionEvent);
            }
        }
    };

    MouseListener internalMouseListener = new MouseAdapter() {
        public void mousePressed(MouseEvent mouseEvent) {
            requestFocusInWindow();
        }
    };

    addKeyListener(internalKeyListener);
    addMouseListener(internalMouseListener);
}

From source file:Main.java

MyJTree(DefaultMutableTreeNode dmtn) {
    super(dmtn);/*from  w  w  w.jav  a  2  s. co m*/
    mi.addActionListener(this);
    mi.setActionCommand("insert");
    popup.add(mi);
    mi = new JMenuItem("Remove this node");
    mi.addActionListener(this);
    mi.setActionCommand("remove");
    popup.add(mi);
    addMouseListener(new MouseAdapter() {
        public void mouseReleased(MouseEvent e) {
            if (e.isPopupTrigger()) {
                popup.show((JComponent) e.getSource(), e.getX(), e.getY());
            }
        }
    });

}

From source file:br.univali.ps.ui.telas.TelaPrincipal.java

/**
/**//from w  w  w . ja va 2 s . c o  m
 * Creates new form TelaInicial
 */
public TelaPrincipal() {
    initComponents();
    criaAbas();
    configurarCores();
    instalarObservadores();
    addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent me) {
            // Get x,y and store them
            pX = me.getX();
            pY = me.getY();

        }

        public void mouseDragged(MouseEvent me) {

            Lancador.getJFrame().setLocation(Lancador.getJFrame().getLocation().x + me.getX() - pX,
                    Lancador.getJFrame().getLocation().y + me.getY() - pY);
        }
    });

    addMouseMotionListener(new MouseMotionAdapter() {
        public void mouseDragged(MouseEvent me) {

            Lancador.getJFrame().setLocation(Lancador.getJFrame().getLocation().x + me.getX() - pX,
                    Lancador.getJFrame().getLocation().y + me.getY() - pY);
        }
    });
}

From source file:MainClass.java

public MainClass() {
    Container cp = new Box(BoxLayout.X_AXIS);
    setContentPane(cp);//from  w ww . ja  va2s .  c om
    JPanel firstPanel = new JPanel();
    propertyComboBox = new JComboBox();
    propertyComboBox.addItem("text");
    propertyComboBox.addItem("font");
    propertyComboBox.addItem("background");
    propertyComboBox.addItem("foreground");
    firstPanel.add(propertyComboBox);
    cp.add(firstPanel);
    cp.add(Box.createGlue());

    tf = new JTextField("Hello");
    tf.setForeground(Color.RED);
    tf.setDragEnabled(true);
    cp.add(tf);

    cp.add(Box.createGlue());

    l = new JLabel("Hello");
    l.setBackground(Color.YELLOW);
    cp.add(l);

    cp.add(Box.createGlue());

    JSlider stryder = new JSlider(SwingConstants.VERTICAL);
    stryder.setMinimum(10);
    stryder.setValue(14);
    stryder.setMaximum(72);
    stryder.setMajorTickSpacing(10);
    stryder.setPaintTicks(true);

    cp.add(stryder);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setSize(500, 300);

    setMyTransferHandlers((String) propertyComboBox.getSelectedItem());

    MouseListener myDragListener = new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            JComponent c = (JComponent) e.getSource();
            TransferHandler handler = c.getTransferHandler();
            handler.exportAsDrag(c, e, TransferHandler.COPY);
        }
    };
    l.addMouseListener(myDragListener);

    propertyComboBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ce) {
            JComboBox bx = (JComboBox) ce.getSource();
            String prop = (String) bx.getSelectedItem();
            setMyTransferHandlers(prop);
        }
    });

    tf.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            JTextField jtf = (JTextField) evt.getSource();
            String fontName = jtf.getText();
            Font font = new Font(fontName, Font.BOLD, 18);
            tf.setFont(font);
        }
    });

    stryder.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent evt) {
            JSlider sl = (JSlider) evt.getSource();
            Font oldf = tf.getFont();
            Font newf = oldf.deriveFont((float) sl.getValue());
            tf.setFont(newf);
        }
    });
}

From source file:de.tntinteractive.portalsammler.gui.DocumentTable.java

public DocumentTable(final Gui gui, final SecureStore store) {
    this.gui = gui;
    this.store = store;

    this.table = new JTable();
    this.table.setRowSelectionAllowed(true);
    this.refreshContents();
    this.table.addMouseListener(new MouseAdapter() {
        @Override/*from  w w  w  .  jav a 2 s . c  o m*/
        public void mousePressed(final MouseEvent me) {
            final int r = DocumentTable.this.table.rowAtPoint(me.getPoint());
            if (!DocumentTable.this.table.getSelectionModel().isSelectedIndex(r)) {
                if (r >= 0 && r < DocumentTable.this.table.getRowCount()) {
                    DocumentTable.this.table.setRowSelectionInterval(r, r);
                } else {
                    DocumentTable.this.table.clearSelection();
                }
            }

            if (me.isPopupTrigger()) {
                DocumentTable.this.showPopup(me);
            } else if (me.getClickCount() == 2) {
                DocumentTable.this.openSelectedRows();
            }
        }

        @Override
        public void mouseReleased(final MouseEvent me) {
            if (me.isPopupTrigger()) {
                DocumentTable.this.showPopup(me);
            }
        }
    });
    this.table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
    this.table.getColumnModel().getColumn(0).setPreferredWidth(120);
    this.table.getColumnModel().getColumn(1).setPreferredWidth(80);
    this.table.getColumnModel().getColumn(2).setPreferredWidth(100);
    this.table.getColumnModel().getColumn(3).setPreferredWidth(500);
}

From source file:com.limegroup.gnutella.gui.tables.ActionIconAndNameEditor.java

public Component getTableCellEditorComponent(final JTable table, Object value, boolean isSelected, int row,
        int column) {
    ActionIconAndNameHolder in = (ActionIconAndNameHolder) value;
    action = in.getAction();//from   w  w  w .j ava  2s  . c o  m

    final Component component = new ActionIconAndNameRenderer().getTableCellRendererComponent(table, value,
            isSelected, true, row, column);
    component.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent e) {
            if (e.getButton() == MouseEvent.BUTTON1) {
                if (actionRegion == null) {
                    component_mousePressed(e);
                } else {
                    if (actionRegion.contains(e.getPoint())) {
                        component_mousePressed(e);
                    } else {
                        if (e.getClickCount() >= 2) {
                            Toolkit.getDefaultToolkit().getSystemEventQueue()
                                    .postEvent(new MouseEvent(table, MouseEvent.MOUSE_CLICKED, e.getWhen(),
                                            e.getModifiers(), component.getX() + e.getX(),
                                            component.getY() + e.getY(), e.getClickCount(), false));
                        }
                    }
                }
            } else if (e.getButton() == MouseEvent.BUTTON3) {
                Toolkit.getDefaultToolkit().getSystemEventQueue()
                        .postEvent(new MouseEvent(table, e.getID(), e.getWhen(), e.getModifiers(),
                                component.getX() + e.getX(), component.getY() + e.getY(), e.getClickCount(),
                                true));
            }
        }
    });

    return component;
}

From source file:com.sec.ose.osi.ui.frm.main.report.project.JListProjectWithPopup.java

private void initialize() {
    this.addListSelectionListener(new FileSelectionListener());
    this.addMouseListener(new MouseAdapter() {
        @SuppressWarnings("deprecation")
        public void mouseClicked(MouseEvent e) {
            if (e.getButton() == MouseEvent.BUTTON3) {
                log.debug("JLIstProjectWithPop.mouseClicked() : MouseEvent.BUTTON3");
                /// clicked right button
                mEventHandler.handle(EventHandler.RIGHT_BTN_CLICKED);

                if (JListProjectWithPopup.this.getSelectedValues() != null // existed selected item
                        && JListProjectWithPopup.this.getSelectedValues().length > 0) {
                    log.debug("button3");
                    mPopup.show(e.getComponent(), e.getX(), e.getY());
                }/*from  www.  j av a 2 s.c o  m*/
            }
        }
    });
}