Example usage for java.awt.event MouseEvent getComponent

List of usage examples for java.awt.event MouseEvent getComponent

Introduction

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

Prototype

public Component getComponent() 

Source Link

Document

Returns the originator of the event.

Usage

From source file:SwingMouseMotionEventDemo.java

void saySomething(String eventDescription, MouseEvent e) {
    textArea.append(eventDescription + " (" + e.getX() + "," + e.getY() + ")" + " detected on "
            + e.getComponent().getClass().getName() + newline);
    textArea.setCaretPosition(textArea.getDocument().getLength());
}

From source file:org.zest_owtf.mainclass.ZestZapUtils.java

public static MouseAdapter stdMenuAdapter() {
    return new java.awt.event.MouseAdapter() {
        @Override/*from   w  w  w . j a  v a 2  s  .c o  m*/
        public void mousePressed(java.awt.event.MouseEvent e) {
            mouseAction(e);
        }

        @Override
        public void mouseReleased(java.awt.event.MouseEvent e) {
            mouseAction(e);
        }

        public void mouseAction(java.awt.event.MouseEvent e) {
            // right mouse button action
            if ((e.getModifiers() & InputEvent.BUTTON3_MASK) != 0 || e.isPopupTrigger()) {
                View.getSingleton().getPopupMenu().show(e.getComponent(), e.getX(), e.getY());
            }
        }
    };
}

From source file:burlov.ultracipher.swing.MainPanel.java

private void showTextPopup(MouseEvent e) {
    if (e.isPopupTrigger()) {
        e.getComponent().requestFocusInWindow();
        textPopup.show(e.getComponent(), e.getX(), e.getY());
    }/*from   w w w  .j  av  a  2 s  .c om*/
}

From source file:de.codesourcery.eve.skills.ui.utils.PopupMenuBuilder.java

/**
 * Checks whether a mouse-click event//w  ww  . j  a v a 2  s .  c o m
 * should trigger a context-sensitive popup menu
 * and renders the menu if so.
 * 
 * @param e
 */
protected void maybeShowPopup(MouseEvent e) {

    if (!e.isPopupTrigger()) {
        return;
    }

    popupMenu.removeAll();

    if (populateMenu() > 0) {
        popupMenu.show(e.getComponent(), e.getX(), e.getY());
    }
}

From source file:plugin.notes.gui.JIcon.java

private void buttonMouseReleased(MouseEvent evt) {
    //GEN-FIRST:event_buttonMouseReleased
    if (evt.isPopupTrigger()) {
        contextMenu.show(evt.getComponent(), evt.getX(), evt.getY());
    }//from  w  w  w .  j ava2s  .  co  m
}

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

public MirthIconTextField(ImageIcon icon) {
    setIcon(icon);/*from   w w  w  .  j a  v a2s. co  m*/

    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: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 ww .j av a2s .  c om*/

    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:org.gitools.ui.app.heatmap.panel.details.boxes.DimensionBox.java

@Override
protected void onMouseRightClick(DetailsDecoration propertyItem, MouseEvent e) {
    if (propertyItem.getReference() instanceof HeatmapHeader) {
        DynamicActionsManager.updatePopupMenu(popupMenu, IHeatmapHeaderAction.class,
                (HeatmapHeader) propertyItem.getReference(), null);
        popupMenu.show(e.getComponent(), e.getX(), e.getY());
    }// w w w  .  j av a 2s .c  o m
}

From source file:PopUpColorMenu.java

public PopUpColorMenu() {
    JFrame frame = new JFrame();

    final JPopupMenu colorMenu = new JPopupMenu("Color");
    colorMenu.add(makeMenuItem("Red"));
    colorMenu.add(makeMenuItem("Green"));
    colorMenu.add(makeMenuItem("Blue"));

    MouseListener mouseListener = new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            checkPopup(e);/* ww w .j ava  2  s  . c o  m*/
        }

        public void mouseClicked(MouseEvent e) {
            checkPopup(e);
        }

        public void mouseReleased(MouseEvent e) {
            checkPopup(e);
        }

        private void checkPopup(MouseEvent e) {
            if (e.isPopupTrigger()) {
                selectedComponent = e.getComponent();
                colorMenu.show(e.getComponent(), e.getX(), e.getY());
            }
        }
    };

    frame.setLayout(new FlowLayout());
    JButton button = new JButton("Uno");
    button.addMouseListener(mouseListener);
    frame.add(button);
    button = new JButton("Due");
    button.addMouseListener(mouseListener);
    frame.add(button);
    button = new JButton("Tre");
    button.addMouseListener(mouseListener);
    frame.add(button);

    frame.getContentPane().addMouseListener(mouseListener);

    frame.setSize(200, 50);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
}

From source file:hermes.browser.dialog.HermesAdminFactoryConfigPanel.java

public void init() {
    final Border border = BorderFactory.createBevelBorder(BevelBorder.RAISED);
    setLayout(new BorderLayout());
    setBorder(BorderFactory.createTitledBorder(border, ADMIN_FACTORY));

    afCombo.setModel(cfComboModel);//ww  w. ja v a2  s  .com

    propertyTableSP.setViewportView(propertyTable);
    propertyTable.setSortable(true);
    add(afCombo, BorderLayout.NORTH);
    add(propertyTableSP, BorderLayout.CENTER);

    popupMenu.add(addItem);
    popupMenu.add(removeItem);

    addItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            try {
                propertyTableModel.insertRow();
            } catch (Exception ex) {
                cat.error(ex.getMessage(), ex);
            }
        }
    });

    removeItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            if (propertyTable.getSelectedRow() != -1) {
                propertyTableModel.removeRow(propertyTable.getSelectedRow());
            }
        }
    });

    final MouseAdapter m = new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            if (SwingUtilities.isRightMouseButton(e)) {
                if (e.getComponent() == propertyTableSP) {
                    removeItem.setEnabled(false);
                } else {
                    removeItem.setEnabled(true);
                }

                if (propertySelectionComboBox.getModel().getSize() == 0) {
                    addItem.setEnabled(false);
                } else {
                    addItem.setEnabled(true);
                }

                popupMenu.show(e.getComponent(), e.getX(), e.getY());
            }
        }
    };

    propertyTableSP.addMouseListener(m);
    propertyTable.addMouseListener(m);
    propertyTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);

    cfComboModel.addListDataListener(new ListDataListener() {
        public void contentsChanged(ListDataEvent arg0) {
            final String className = HermesBrowser.getConfigDAO()
                    .getAdminClassForPlugIn((String) cfComboModel.getSelectedItem());
            final ClassLoaderManager classLoaderManager = (ClassLoaderManager) SingletonManager
                    .get(ClassLoaderManager.class);

            try {
                if (propertyTableModel != null) {
                    final ClassLoader classLoader = classLoaderManager
                            .getClassLoader(dialog.getSelectedLoader());
                    Thread.currentThread().setContextClassLoader(classLoader);

                    bean = (HermesAdminFactory) classLoader.loadClass(className).newInstance();
                    propertyTableModel.setBean(bean);
                    updateCellEditor();
                    dialog.setDirty();
                }
            } catch (Throwable e) {
                HermesBrowser.getBrowser().showErrorDialog(
                        "Unable to locate this plugin.\nSelect the loader the JMS provider classes are in before choosing the plugin.");
                cfComboModel.setSelectedItem(ConfigDAO.DEFAULT_PLUGIN);
            }
        }

        public void intervalAdded(ListDataEvent arg0) {
            // NOP
        }

        public void intervalRemoved(ListDataEvent arg0) {
            // NOP
        }
    });

}