Java Code Examples for javax.swing.JComponent#addMouseMotionListener()

The following examples show how to use javax.swing.JComponent#addMouseMotionListener() . 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
Source File: ToolTipManagerEx.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
    * Registers a component for tooltip management.
    * <p>
    * This will register key bindings to show and hide the tooltip text
    * only if <code>component</code> has focus bindings. This is done
    * so that components that are not normally focus traversable, such
    * as <code>JLabel</code>, are not made focus traversable as a result
    * of invoking this method.
    *
    * @param component  a <code>JComponent</code> object to add
    * @see JComponent#isFocusTraversable
    */
   protected void registerComponent(JComponent component) {
       component.removeMouseListener(this);
       component.addMouseListener(this);
       component.removeMouseMotionListener(moveBeforeEnterListener);
component.addMouseMotionListener(moveBeforeEnterListener);

if (shouldRegisterBindings(component)) {
    // register our accessibility keybindings for this component
    // this will apply globally across L&F
    // Post Tip: Ctrl+F1
    // Unpost Tip: Esc and Ctrl+F1
    InputMap inputMap = component.getInputMap(JComponent.WHEN_FOCUSED);
    ActionMap actionMap = component.getActionMap();

    if (inputMap != null && actionMap != null) {
               //XXX remove
    }
}
   }
 
Example 2
Source File: Rubber.java    From libreveris with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Actually register the rubber as the mouse listener for the provided
 * component.
 *
 * @param component the related component
 */
public void connectComponent (JComponent component)
{
    // Clean up if needed
    disconnectComponent(this.component);

    // Remember the related component (to get visible rect, etc ...)
    this.component = component;

    // To be notified of mouse clicks
    component.removeMouseListener(this); // No multiple notifications
    component.addMouseListener(this);

    // To be notified of mouse mouvements
    component.removeMouseMotionListener(this); // No multiple notifs
    component.addMouseMotionListener(this);

    // To be notified of mouse  wheel mouvements
    component.removeMouseWheelListener(this); // No multiple notifs
    component.addMouseWheelListener(this);
}
 
Example 3
Source File: NavigationPanelUI.java    From pumpernickel with MIT License 6 votes vote down vote up
@Override
public void installUI(JComponent c) {
	super.installUI(c);

	spinner.addChangeListener(valueListener);
	label = createLabel();
	maybeAdd(label, "Label");
	UpdateLabelListener changeListener = new UpdateLabelListener(
			(JSpinner) c, label);
	changeListener.refreshLabel();
	c.putClientProperty(PROPERTY_LABEL_CHANGE_LISTENER, changeListener);
	((JSpinner) c).addChangeListener(changeListener);
	((JSpinner) c).addPropertyChangeListener(changeListener);
	c.addMouseListener(dragListener);
	c.addMouseMotionListener(dragListener);
	c.setBorder(null);
}
 
Example 4
Source File: Rubber.java    From audiveris with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Actually register the rubber as the mouse listener for the provided component.
 *
 * @param component the related component
 */
public final void connectComponent (JComponent component)
{
    // Clean up if needed
    disconnectComponent(this.component);

    // Remember the related component (to get visible rect, etc ...)
    this.component = component;

    if (component != null) {
        // To be notified of mouse clicks
        component.removeMouseListener(this); // No multiple notifications
        component.addMouseListener(this);

        // To be notified of mouse mouvements
        component.removeMouseMotionListener(this); // No multiple notifs
        component.addMouseMotionListener(this);

        // To be notified of mouse  wheel mouvements
        component.removeMouseWheelListener(this); // No multiple notifs
        component.addMouseWheelListener(this);
    }
}
 
Example 5
Source File: ColorWellUI.java    From pumpernickel with MIT License 6 votes vote down vote up
@Override
public void installUI(JComponent c) {
	c.addFocusListener(repaintFocusListener);
	c.addMouseListener(mouseListener);
	c.addMouseMotionListener(mouseListener);
	c.addKeyListener(keyListener);

	JColorWell well = (JColorWell) c;
	ColorChangeListener ccl = new ColorChangeListener(c);
	listenerMap.put(well, ccl);
	well.getColorSelectionModel().addChangeListener(ccl);

	ShowColorPaletteActionListener colorPaletteActionListener = new ShowColorPaletteActionListener();
	c.putClientProperty(DOUBLE_CLICK_ACTION_PROPERTY,
			colorPickerActionListener);
	c.putClientProperty(SPACE_KEY_ACTION_PROPERTY,
			colorPickerActionListener);
	c.putClientProperty(SINGLE_CLICK_ACTION_PROPERTY,
			colorPaletteActionListener);
	c.putClientProperty(DOWN_KEY_ACTION_PROPERTY,
			colorPaletteActionListener);
}
 
Example 6
Source File: Resizer.java    From jclic with GNU General Public License v2.0 5 votes vote down vote up
/** Creates a new instance of Resizer */
public Resizer(JComponent jc, Rectangle r, boolean editable, ResizerListener rl) {
  this.jc = jc;
  setRect(r);
  this.editable = editable;
  if (editable)
    defaultCursor = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR);
  this.rl = rl;
  jc.addMouseListener(this);
  jc.addMouseMotionListener(this);
  minSize = new Dimension(Constants.MIN_CELL_SIZE, Constants.MIN_CELL_SIZE);
  maxSize = new Dimension(jc.getPreferredSize());
  setEnabled(true);
}
 
Example 7
Source File: SwingRendererImpl.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void setProperty( String sProperty, Object oValue )
{
	// InteractiveRenderer(iv) is only for Swing
	if ( sProperty.equals( IDeviceRenderer.UPDATE_NOTIFIER ) && iv != null )
	{
		_iun = (IUpdateNotifier) oValue;
		iv.setUpdateNotifier( _iun );
		_lhmAllTriggers.clear( );
		Object obj = _iun.peerInstance( );

		if ( obj instanceof JComponent )
		{
			JComponent jc = (JComponent) obj;

			if ( _eh != null )
			{
				// We can't promise to remove all the old swtEventHandler
				// due to SWT limitation here, so be sure to just attach the
				// update_notifier only to one renderer.

				jc.removeMouseListener( _eh );
				jc.removeMouseMotionListener( _eh );
				jc.removeKeyListener( _eh );
				jc.removeFocusListener( _eh );
			}

			_eh = new SwingEventHandler( iv,
					_lhmAllTriggers,
					_iun,
					getULocale( ) );
			jc.addMouseListener( _eh );
			jc.addMouseMotionListener( _eh );
			jc.addKeyListener( _eh );
			jc.addFocusListener( _eh );
		}
	}
	
	super.setProperty( sProperty, oValue );
}
 
Example 8
Source File: MultiThumbSliderUI.java    From PyramidShader with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void installUI(JComponent slider) {
	slider.addMouseListener(this);
	slider.addMouseMotionListener(this);
	slider.addFocusListener(focusListener);
	slider.addKeyListener(keyListener);
	slider.addComponentListener(compListener);
	slider.addPropertyChangeListener(propertyListener);
	slider.addPropertyChangeListener(THUMB_SHAPE_PROPERTY, thumbShapeListener);
	calculateGeometry();
}
 
Example 9
Source File: ComponentToolTipManager.java    From mzmine2 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 
 * @param event
 */
private void initiateToolTip(MouseEvent event) {

  JComponent component = (JComponent) event.getSource();
  String newToolTipText = component.getToolTipText(event);
  newToolTipComponent = ((ComponentToolTipProvider) component).getCustomToolTipComponent(event);

  if (newToolTipComponent == null)
    return;

  component.removeMouseMotionListener(moveBeforeEnterListener);

  Point location = event.getPoint();
  // ensure tooltip shows only in proper place
  if (location.x < 0 || location.x >= component.getWidth() || location.y < 0
      || location.y >= component.getHeight()) {
    return;
  }

  component.removeMouseMotionListener(this);
  component.addMouseMotionListener(this);

  mouseEvent = event;
  toolTipText = newToolTipText;
  preferredLocation = component.getToolTipLocation(event);
  insideComponent = component;

  showTipWindow();
}
 
Example 10
Source File: MultiThumbSliderUI.java    From pumpernickel with MIT License 5 votes vote down vote up
@Override
public void installUI(JComponent slider) {
	slider.addMouseListener(this);
	slider.addMouseMotionListener(this);
	slider.addFocusListener(focusListener);
	slider.addKeyListener(keyListener);
	slider.addComponentListener(compListener);
	slider.addPropertyChangeListener(propertyListener);
	slider.addPropertyChangeListener(THUMB_SHAPE_PROPERTY,
			thumbShapeListener);
	calculateGeometry();
}
 
Example 11
Source File: PanZoomListener.java    From rcrs-server with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
   Construct a PanZoomListener that listens for events on a JComponent.
   @param component The component to listen for mouse events on.
*/
public PanZoomListener(JComponent component) {
    this.component = component;
    component.addMouseListener(this);
    component.addMouseMotionListener(this);
    component.addMouseWheelListener(this);
    panTriggerModifiers = InputEvent.BUTTON1_DOWN_MASK;
    zoomTriggerModifiers = InputEvent.BUTTON2_DOWN_MASK;
    zoomThreshold = DEFAULT_MOUSE_ZOOM_THRESHOLD;
    enabled = true;
}
 
Example 12
Source File: DragManager.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Creates a new instance of SplashDnDSupport */
DragManager(JComponent component) {
    this.component = component;
    dSource =  new DragSource();
    dRecognizer = dSource.createDefaultDragGestureRecognizer(this.component,DnDConstants.ACTION_MOVE,this);
    dTarget = new DropTarget(this.component,DnDConstants.ACTION_MOVE,this);
    component.addMouseMotionListener(this);
    oCursor = component.getCursor();
}
 
Example 13
Source File: ComponentToolTipManager.java    From mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 
 * @param event
 */
private void initiateToolTip(MouseEvent event) {

  JComponent component = (JComponent) event.getSource();
  String newToolTipText = component.getToolTipText(event);
  newToolTipComponent = ((ComponentToolTipProvider) component).getCustomToolTipComponent(event);

  if (newToolTipComponent == null)
    return;

  component.removeMouseMotionListener(moveBeforeEnterListener);

  Point location = event.getPoint();
  // ensure tooltip shows only in proper place
  if (location.x < 0 || location.x >= component.getWidth() || location.y < 0
      || location.y >= component.getHeight()) {
    return;
  }

  component.removeMouseMotionListener(this);
  component.addMouseMotionListener(this);

  mouseEvent = event;
  toolTipText = newToolTipText;
  preferredLocation = component.getToolTipLocation(event);
  insideComponent = component;

  showTipWindow();
}
 
Example 14
Source File: Canvas.java    From freecol with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Adds a component on this Canvas inside a frame.
 *
 * @param comp The component to add to the canvas.
 * @param toolBox Should be set to true if the resulting frame is
 *     used as a toolbox (that is: it should not be counted as a
 *     frame).
 * @param popupPosition A preferred {@code PopupPosition}.
 * @param resizable Whether this component can be resized.
 * @return The {@code JInternalFrame} that was created and added.
 */
private JInternalFrame addAsFrame(JComponent comp, boolean toolBox,
                                  PopupPosition popupPosition,
                                  boolean resizable) {
    final int FRAME_EMPTY_SPACE = 60;

    final JInternalFrame f = (toolBox) ? new ToolBoxFrame()
        : new JInternalFrame();
    Container con = f.getContentPane();
    if (con instanceof JComponent) {
        JComponent c = (JComponent)con;
        c.setOpaque(false);
        c.setBorder(null);
    }

    if (comp.getBorder() != null) {
        if (comp.getBorder() instanceof EmptyBorder) {
            f.setBorder(Utility.blankBorder(10, 10, 10, 10));
        } else {
            f.setBorder(comp.getBorder());
            comp.setBorder(Utility.blankBorder(5, 5, 5, 5));
        }
    } else {
        f.setBorder(null);
    }

    final FrameMotionListener fml = new FrameMotionListener(f);
    comp.addMouseMotionListener(fml);
    comp.addMouseListener(fml);
    if (f.getUI() instanceof BasicInternalFrameUI) {
        BasicInternalFrameUI biu = (BasicInternalFrameUI) f.getUI();
        biu.setNorthPane(null);
        biu.setSouthPane(null);
        biu.setWestPane(null);
        biu.setEastPane(null);
    }

    f.getContentPane().add(comp);
    f.setOpaque(false);
    f.pack();
    int width = f.getWidth();
    int height = f.getHeight();
    if (width > getWidth() - FRAME_EMPTY_SPACE) {
        width = Math.min(width, getWidth());
    }
    if (height > getHeight() - FRAME_EMPTY_SPACE) {
        height = Math.min(height, getHeight());
    }
    f.setSize(width, height);
    Point p = chooseLocation(comp, width, height, popupPosition);
    f.setLocation(p);
    this.addToCanvas(f, MODAL_LAYER);
    f.setName(comp.getClass().getSimpleName());

    f.setFrameIcon(null);
    f.setVisible(true);
    f.setResizable(resizable);
    try {
        f.setSelected(true);
    } catch (java.beans.PropertyVetoException e) {}

    return f;
}
 
Example 15
Source File: HexMap.java    From Rails with GNU General Public License v2.0 4 votes vote down vote up
private void addMouseMotionListener(MouseMotionListener ml) {
    for (JComponent l : layers) {
        l.addMouseMotionListener(ml);
    }
}
 
Example 16
Source File: PointerEventHandler.java    From jfxvnc with Apache License 2.0 4 votes vote down vote up
public void register(JComponent node) {
  node.addMouseMotionListener(mouseMotionEventHandler);
  node.addMouseListener(mouseEventHandler);
  node.addMouseWheelListener(mouseWheelEventHandler);
}
 
Example 17
Source File: ToolTipManagerEx.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void initiateToolTip(MouseEvent event) {
       if (event.getSource() == window) {
           return;
       }
       JComponent component = (JComponent)event.getSource();
component.removeMouseMotionListener(moveBeforeEnterListener);

       exitTimer.stop();

Point location = event.getPoint();
// ensure tooltip shows only in proper place
if (location.x < 0 || 
    location.x >=component.getWidth() ||
    location.y < 0 ||
    location.y >= component.getHeight()) {
    return;
}

       if (insideComponent != null) {
           enterTimer.stop();
       }
// A component in an unactive internal frame is sent two
// mouseEntered events, make sure we don't end up adding
// ourselves an extra time.
       component.removeMouseMotionListener(this);
       component.addMouseMotionListener(this);

       boolean sameComponent = (insideComponent == component);

       insideComponent = component;
if (tipWindow != null){
           mouseEvent = event;
           if (showImmediately) {
               Rectangle rect = provider.getToolTipSourceBounds( event.getPoint() );
               if( null != rect ) {
                   String newToolTipText = startToolTipCalculation( rect, event.getPoint() );

                   if (!sameComponent || !toolTipText.equals(newToolTipText) /*|| 
                            !sameLoc*/) {
                       toolTipText = newToolTipText;
                       showTipWindow();
                   }
               }
           } else {
               enterTimer.start();
           }
       }
   }
 
Example 18
Source File: ComponentToolTipManager.java    From mzmine2 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Registers a component for tooltip management.
 * <p>
 * This will register key bindings to show and hide the tooltip text only if
 * <code>component</code> has focus bindings. This is done so that components that are not
 * normally focus traversable, such as <code>JLabel</code>, are not made focus traversable as a
 * result of invoking this method.
 * 
 * @param component a <code>JComponent</code> object to add
 * @see JComponent#isFocusTraversable
 */
public void registerComponent(JComponent component) {

  if (!(component instanceof ComponentToolTipProvider))
    return;

  component.addMouseListener(this);
  component.addMouseMotionListener(moveBeforeEnterListener);

  ToolTipManager.sharedInstance().unregisterComponent(component);

}
 
Example 19
Source File: ComponentToolTipManager.java    From mzmine3 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Registers a component for tooltip management.
 * <p>
 * This will register key bindings to show and hide the tooltip text only if
 * <code>component</code> has focus bindings. This is done so that components that are not
 * normally focus traversable, such as <code>JLabel</code>, are not made focus traversable as a
 * result of invoking this method.
 * 
 * @param component a <code>JComponent</code> object to add
 * @see JComponent#isFocusTraversable
 */
public void registerComponent(JComponent component) {

  if (!(component instanceof ComponentToolTipProvider))
    return;

  component.addMouseListener(this);
  component.addMouseMotionListener(moveBeforeEnterListener);

  ToolTipManager.sharedInstance().unregisterComponent(component);

}