List of usage examples for java.awt Component addMouseListener
public synchronized void addMouseListener(MouseListener l)
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();//w w w. java2s. c om 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.iisigroup.ris.WebFileScanUtilBrowserUI.java
/** * Auto-generated method for setting the popup menu for a component */// w ww .ja v a 2 s . co m private void setComponentPopupMenu(final java.awt.Component parent, final javax.swing.JPopupMenu menu) { parent.addMouseListener(new java.awt.event.MouseAdapter() { public void mousePressed(java.awt.event.MouseEvent e) { if (e.isPopupTrigger()) menu.show(parent, e.getX(), e.getY()); } public void mouseReleased(java.awt.event.MouseEvent e) { if (e.isPopupTrigger()) menu.show(parent, e.getX(), e.getY()); } }); }
From source file:PopupDemo.java
void addPopup(Component c, String name) { PopupMenu pm = new PopupMenu(); MenuItem mi = new MenuItem(name + "-1"); mi.addActionListener(this); pm.add(mi);//from w w w. jav a 2s. c o m mi = new MenuItem(name + "-2"); pm.add(mi); setHash(c, pm); c.add(pm); c.addMouseListener(this); }
From source file:Main.java
private static void addComponentListeners(Component c, Object... objs) { if (c == null) return;/*from w w w .j av a 2 s . co m*/ ComponentListener componentListener = search(objs, ComponentListener.class); FocusListener focusListener = search(objs, FocusListener.class); HierarchyBoundsListener hierarchyBoundsListener = search(objs, HierarchyBoundsListener.class); HierarchyListener hierarchyListener = search(objs, HierarchyListener.class); InputMethodListener inputMethodListener = search(objs, InputMethodListener.class); KeyListener keyListener = search(objs, KeyListener.class); MouseListener mouseListener = search(objs, MouseListener.class); MouseMotionListener mouseMotionListener = search(objs, MouseMotionListener.class); MouseWheelListener mouseWheelListener = search(objs, MouseWheelListener.class); if (componentListener != null) c.addComponentListener(componentListener); if (focusListener != null) c.addFocusListener(focusListener); if (hierarchyBoundsListener != null) c.addHierarchyBoundsListener(hierarchyBoundsListener); if (hierarchyListener != null) c.addHierarchyListener(hierarchyListener); if (inputMethodListener != null) c.addInputMethodListener(inputMethodListener); if (keyListener != null) c.addKeyListener(keyListener); if (mouseListener != null) c.addMouseListener(mouseListener); if (mouseMotionListener != null) c.addMouseMotionListener(mouseMotionListener); if (mouseWheelListener != null) c.addMouseWheelListener(mouseWheelListener); }
From source file:org.fhaes.jsea.JSEAFrame.java
/** * Show popup menu//w ww . j a va2 s .co m * * @param component * @param popup */ private static void addPopup(Component component, final JPopupMenu popup) { component.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { if (e.isPopupTrigger()) { showMenu(e); } } @Override public void mouseReleased(MouseEvent e) { if (e.isPopupTrigger()) { showMenu(e); } } private void showMenu(MouseEvent e) { popup.show(e.getComponent(), e.getX(), e.getY()); } }); }
From source file:com.mac.tarchan.desktop.event.EventQuery.java
/** * ????????????????????//ww w . j av a2 s . c o m * * @param target ? * @param overAction ????????????????????? * @param outAction ???????????????????? * @param property ???????????? * @return ?? * @see MouseListener#mouseEntered(java.awt.event.MouseEvent) * @see MouseListener#mouseExited(java.awt.event.MouseEvent) */ public EventQuery hover(Object target, String overAction, String outAction, String property) { MouseListener mouseEntered = EventHandler.create(MouseListener.class, target, overAction, property, "mouseEntered"); MouseListener mouseExited = EventHandler.create(MouseListener.class, target, outAction, property, "mouseExited"); for (Component child : list) { child.addMouseListener(mouseEntered); child.addMouseListener(mouseExited); } return this; }
From source file:com.mac.tarchan.desktop.event.EventQuery.java
/** * ?????//from w ww. ja v a 2s. c o m * * @param mouseClicked ? * @return ?? * @see MouseListener#mouseClicked(java.awt.event.MouseEvent) */ public EventQuery dblclick(final MouseListener mouseClicked) { log.debug("dblclick=" + list); for (Component child : list) { child.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) mouseClicked.mouseClicked(e); } }); } return this; }
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;// ww w. ja va2s . 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:com.mac.tarchan.desktop.event.EventQuery.java
/** * ??????????/*from w w w . j a v a 2 s. c om*/ * * @param target ? * @param action ????????????? * @param property ???????????? * @return ?? * @see MouseListener#mousePressed(java.awt.event.MouseEvent) * @see MouseMotionListener#mouseDragged(java.awt.event.MouseEvent) */ public EventQuery swipe(Object target, String action, String property) { // MouseListener mousePressed = EventHandler.create(MouseListener.class, target, action, property, "mousePressed"); MouseMotionListener mouseDragged = EventHandler.create(MouseMotionListener.class, target, action, property, "mouseDragged"); MouseSwipeHandler swipeHandler = new MouseSwipeHandler(); for (Component child : list) { // child.addMouseListener(mousePressed); child.addMouseMotionListener(mouseDragged); child.addMouseListener(swipeHandler); child.addMouseMotionListener(swipeHandler); } return this; }
From source file:Filter3dTest.java
/** * Creates a new InputManager that listens to input from the specified * component.// ww w . jav a2 s . c o m */ public InputManager(Component comp) { this.comp = comp; mouseLocation = new Point(); centerLocation = new Point(); // register key and mouse listeners comp.addKeyListener(this); comp.addMouseListener(this); comp.addMouseMotionListener(this); comp.addMouseWheelListener(this); // allow input of the TAB key and other keys normally // used for focus traversal comp.setFocusTraversalKeysEnabled(false); }