Java Code Examples for java.awt.Component#addMouseListener()

The following examples show how to use java.awt.Component#addMouseListener() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
public static void registerForMouseEvent(Component comp,
                                         MouseListener mouseListener) {
    if(comp instanceof JScrollPane) {
        JScrollPane pane = (JScrollPane) comp;
        comp = pane.getViewport().getView();
    }
    if(comp instanceof Container) {
        Container container = (Container) comp;
        Component[] components = container.getComponents();
        for(int i = 0; i < components.length; i++) {
            registerForMouseEvent(components[i], mouseListener);
        }
    }

    //No registration for XOpenTypedata that are themselves clickable.
    //No registration for JButton that are themselves clickable.
    if(comp != null &&
       (!(comp instanceof XOpenTypeViewer.XOpenTypeData) &&
        !(comp instanceof JButton)) )
        comp.addMouseListener(mouseListener);
}
 
Example 2
public static void registerForMouseEvent(Component comp,
                                         MouseListener mouseListener) {
    if(comp instanceof JScrollPane) {
        JScrollPane pane = (JScrollPane) comp;
        comp = pane.getViewport().getView();
    }
    if(comp instanceof Container) {
        Container container = (Container) comp;
        Component[] components = container.getComponents();
        for(int i = 0; i < components.length; i++) {
            registerForMouseEvent(components[i], mouseListener);
        }
    }

    //No registration for XOpenTypedata that are themselves clickable.
    //No registration for JButton that are themselves clickable.
    if(comp != null &&
       (!(comp instanceof XOpenTypeViewer.XOpenTypeData) &&
        !(comp instanceof JButton)) )
        comp.addMouseListener(mouseListener);
}
 
Example 3
Source Project: pdfxtk   File: ContextMenuManager.java    License: Apache License 2.0 6 votes vote down vote up
private void setupML(Component cmp, boolean add) {
   if(cmp instanceof Container) { 
     Component[] cmps = ((Container)cmp).getComponents();
     for(int i = 0; i < cmps.length; i++)
if(cmps[i] instanceof Component) 
  setupML(cmps[i], add);
     
   } else if(cmp instanceof JScrollPane) {
     if(((JScrollPane)cmp).getViewport().getView() instanceof Component)
setupML(((JScrollPane)cmp).getViewport().getView(), add);
     return;
   }
   if(add)
     cmp.addMouseListener(this);
   else
     cmp.removeMouseListener(this);
 }
 
Example 4
public static void registerForMouseEvent(Component comp,
                                         MouseListener mouseListener) {
    if(comp instanceof JScrollPane) {
        JScrollPane pane = (JScrollPane) comp;
        comp = pane.getViewport().getView();
    }
    if(comp instanceof Container) {
        Container container = (Container) comp;
        Component[] components = container.getComponents();
        for(int i = 0; i < components.length; i++) {
            registerForMouseEvent(components[i], mouseListener);
        }
    }

    //No registration for XOpenTypedata that are themselves clickable.
    //No registration for JButton that are themselves clickable.
    if(comp != null &&
       (!(comp instanceof XOpenTypeViewer.XOpenTypeData) &&
        !(comp instanceof JButton)) )
        comp.addMouseListener(mouseListener);
}
 
Example 5
public static void registerForMouseEvent(Component comp,
                                         MouseListener mouseListener) {
    if(comp instanceof JScrollPane) {
        JScrollPane pane = (JScrollPane) comp;
        comp = pane.getViewport().getView();
    }
    if(comp instanceof Container) {
        Container container = (Container) comp;
        Component[] components = container.getComponents();
        for(int i = 0; i < components.length; i++) {
            registerForMouseEvent(components[i], mouseListener);
        }
    }

    //No registration for XOpenTypedata that are themselves clickable.
    //No registration for JButton that are themselves clickable.
    if(comp != null &&
       (!(comp instanceof XOpenTypeViewer.XOpenTypeData) &&
        !(comp instanceof JButton)) )
        comp.addMouseListener(mouseListener);
}
 
Example 6
public static void registerForMouseEvent(Component comp,
                                         MouseListener mouseListener) {
    if(comp instanceof JScrollPane) {
        JScrollPane pane = (JScrollPane) comp;
        comp = pane.getViewport().getView();
    }
    if(comp instanceof Container) {
        Container container = (Container) comp;
        Component[] components = container.getComponents();
        for(int i = 0; i < components.length; i++) {
            registerForMouseEvent(components[i], mouseListener);
        }
    }

    //No registration for XOpenTypedata that are themselves clickable.
    //No registration for JButton that are themselves clickable.
    if(comp != null &&
       (!(comp instanceof XOpenTypeViewer.XOpenTypeData) &&
        !(comp instanceof JButton)) )
        comp.addMouseListener(mouseListener);
}
 
Example 7
public static void registerForMouseEvent(Component comp,
                                         MouseListener mouseListener) {
    if(comp instanceof JScrollPane) {
        JScrollPane pane = (JScrollPane) comp;
        comp = pane.getViewport().getView();
    }
    if(comp instanceof Container) {
        Container container = (Container) comp;
        Component[] components = container.getComponents();
        for(int i = 0; i < components.length; i++) {
            registerForMouseEvent(components[i], mouseListener);
        }
    }

    //No registration for XOpenTypedata that are themselves clickable.
    //No registration for JButton that are themselves clickable.
    if(comp != null &&
       (!(comp instanceof XOpenTypeViewer.XOpenTypeData) &&
        !(comp instanceof JButton)) )
        comp.addMouseListener(mouseListener);
}
 
Example 8
public static void registerForMouseEvent(Component comp,
                                         MouseListener mouseListener) {
    if(comp instanceof JScrollPane) {
        JScrollPane pane = (JScrollPane) comp;
        comp = pane.getViewport().getView();
    }
    if(comp instanceof Container) {
        Container container = (Container) comp;
        Component[] components = container.getComponents();
        for(int i = 0; i < components.length; i++) {
            registerForMouseEvent(components[i], mouseListener);
        }
    }

    //No registration for XOpenTypedata that are themselves clickable.
    //No registration for JButton that are themselves clickable.
    if(comp != null &&
       (!(comp instanceof XOpenTypeViewer.XOpenTypeData) &&
        !(comp instanceof JButton)) )
        comp.addMouseListener(mouseListener);
}
 
Example 9
public static void registerForMouseEvent(Component comp,
                                         MouseListener mouseListener) {
    if(comp instanceof JScrollPane) {
        JScrollPane pane = (JScrollPane) comp;
        comp = pane.getViewport().getView();
    }
    if(comp instanceof Container) {
        Container container = (Container) comp;
        Component[] components = container.getComponents();
        for(int i = 0; i < components.length; i++) {
            registerForMouseEvent(components[i], mouseListener);
        }
    }

    //No registration for XOpenTypedata that are themselves clickable.
    //No registration for JButton that are themselves clickable.
    if(comp != null &&
       (!(comp instanceof XOpenTypeViewer.XOpenTypeData) &&
        !(comp instanceof JButton)) )
        comp.addMouseListener(mouseListener);
}
 
Example 10
public static void registerForMouseEvent(Component comp,
                                         MouseListener mouseListener) {
    if(comp instanceof JScrollPane) {
        JScrollPane pane = (JScrollPane) comp;
        comp = pane.getViewport().getView();
    }
    if(comp instanceof Container) {
        Container container = (Container) comp;
        Component[] components = container.getComponents();
        for(int i = 0; i < components.length; i++) {
            registerForMouseEvent(components[i], mouseListener);
        }
    }

    //No registration for XOpenTypedata that are themselves clickable.
    //No registration for JButton that are themselves clickable.
    if(comp != null &&
       (!(comp instanceof XOpenTypeViewer.XOpenTypeData) &&
        !(comp instanceof JButton)) )
        comp.addMouseListener(mouseListener);
}
 
Example 11
Source Project: netbeans   File: BalloonManager.java    License: Apache License 2.0 5 votes vote down vote up
private void handleMouseOver( Container c, MouseListener ml ) {
    c.addMouseListener(ml);
    for( Component child : c.getComponents() ) {
        child.addMouseListener(ml);
        if( child instanceof Container )
            handleMouseOver((Container)child, ml);
    }
}
 
Example 12
Source Project: netbeans   File: BalloonManager.java    License: Apache License 2.0 5 votes vote down vote up
private void handleMouseOver( Container c, MouseListener ml ) {
    c.addMouseListener(ml);
    for( Component child : c.getComponents() ) {
        child.addMouseListener(ml);
        if( child instanceof Container )
            handleMouseOver((Container)child, ml);
    }
}
 
Example 13
Source Project: pumpernickel   File: SplayedLayout.java    License: MIT License 5 votes vote down vote up
private void addListeners(Component c) {
	if (!Arrays.asList(c.getMouseListeners()).contains(mouseListener))
		c.addMouseListener(mouseListener);
	if (!Arrays.asList(c.getFocusListeners()).contains(focusListener))
		c.addFocusListener(focusListener);

	if (c instanceof Container) {
		Container c2 = (Container) c;
		for (int a = 0; a < c2.getComponentCount(); a++) {
			addListeners(c2.getComponent(a));
		}
	}
}
 
Example 14
Source Project: settlers-remake   File: GOSwingEventConverter.java    License: MIT License 5 votes vote down vote up
/**
 * Creates a new event converter, that converts swing events to go events.
 * 
 * @param component
 *            The component.
 * @param provider
 *            THe provider to which to send the events.
 */
public GOSwingEventConverter(Component component, GOEventHandlerProvider provider) {
	super(provider);

	component.setFocusTraversalKeysEnabled(false);

	component.addKeyListener(this);
	component.addMouseListener(this);
	component.addMouseMotionListener(this);
	component.addMouseWheelListener(this);
	component.addHierarchyListener(this);

	addReplaceRule(new EventReplacementRule(ReplacableEvent.DRAW, Replacement.COMMAND_SELECT, MOUSE_TIME_TRSHOLD, MOUSE_MOVE_TRESHOLD));
	addReplaceRule(new EventReplacementRule(ReplacableEvent.PAN, Replacement.COMMAND_ACTION, MOUSE_TIME_TRSHOLD, MOUSE_MOVE_TRESHOLD));
}
 
Example 15
Source Project: pumpernickel   File: DescendantMouseListener.java    License: MIT License 5 votes vote down vote up
/**
 * Add all our internal listeners from a component and its descendants.
 */
private void addListeners(DefaultMutableTreeNode componentNode) {
	Component c = (Component) componentNode.getUserObject();
	c.addHierarchyListener(hierarchyListener);
	c.addMouseListener(mouseListener);
	c.addMouseMotionListener(mouseListener);
	for (int a = 0; a < componentNode.getChildCount(); a++) {
		addListeners((DefaultMutableTreeNode) componentNode.getChildAt(a));
	}
	if (c instanceof Container)
		((Container) c).addContainerListener(containerListener);
}
 
Example 16
public void attachTo(Component cmp, boolean catchMotion) {
  cmp.addMouseListener(this);
  if (catchMotion)
    cmp.addMouseMotionListener(this);
}
 
Example 17
/**
 *  Add the required listeners to the specified component
 *
 *  @param component  the component the listeners are added to
 */
public void registerComponent(Component... components)
{
	for (Component component : components)
		component.addMouseListener(this);
}
 
Example 18
private static void showRes(String desc, final BufferedImage src) {
    final int w = src.getWidth();
    final int h = src.getHeight();

    Frame f = new Frame(desc+": dbl-click to exit");
    Component c;
    f.add(c = new Component() {
        public Dimension getPreferredSize() {
            return new Dimension(w,h);
        }

        public void paint(Graphics g) {
            g.clearRect(0, 0, getWidth(), getHeight());
            g.drawImage(src, 0,0, null);
        }
    });
    c.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() > 1) {
                System.exit(0);
            }
        }
    });
    f.pack();
    synchronized (JPEGsNotAcceleratedTest.class) {
        f.setLocation(frameX, frameY);
        frameX += f.getWidth();
        if ((frameX + f.getWidth()) >
            f.getGraphicsConfiguration().getBounds().width)
        {
            frameY += TEST_H;
            if ((frameY + f.getHeight()) >
                f.getGraphicsConfiguration().getBounds().height)
            {
                startY += 30;
                startX += 30;
                frameY = startY;
            }
            frameX = startX;
        }
    };
    f.setVisible(true);
}
 
Example 19
@Override
public Component add(Component c) {
	Component result = super.add(c);
	c.addMouseListener(borderListener);
	return result;
}
 
Example 20
Source Project: SikuliX1   File: ComponentMover.java    License: MIT License 3 votes vote down vote up
/**

    *  Add the required listeners to the specified component

    *

    *  @param components  components the listeners are added to

    */

   public void registerComponent(Component... components)

   {

      for (Component component : components)

         component.addMouseListener( this );

   }