Java Code Examples for java.awt.event.MouseMotionListener

The following examples show how to use java.awt.event.MouseMotionListener. 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
Source Project: ghidra   Source File: GraphViewerTest.java    License: Apache License 2.0 6 votes vote down vote up
private void hoverEdge(TestEdge edge) {

		// if the vertex is visible, then at least part of the edge will be
		ensureVertexVisible(edge.getStart());

		Point2D graphSpaceEdgePoint = findHoverPointInGraphSpace(edge);
		Point viewPoint =
			GraphViewerUtils.translatePointFromGraphSpaceToViewSpace(graphSpaceEdgePoint, viewer);

		int mods = 0;
		MouseEvent e = new MouseEvent(viewer, MouseEvent.MOUSE_MOVED, System.currentTimeMillis(),
			mods, viewPoint.x, viewPoint.y, 0, false);

		MouseMotionListener[] listeners = viewer.getMouseMotionListeners();
		swing(() -> {
			for (MouseMotionListener listener : listeners) {
				listener.mouseMoved(e);
			}
		});

		tooltipSpy.clearTooltipTriggered();
		AbstractGTest.waitForCondition(() -> tooltipSpy.isTooltipTriggered(),
			"Timed-out waiting for tooltip to appear");
		waitForSwing();
	}
 
Example 2
Source Project: freecol   Source File: Canvas.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Removes components that is only used when in game.
 */
public void removeInGameComponents() {
    // remove listeners, they will be added when launching the new game...
    KeyListener[] keyListeners = getKeyListeners();
    for (KeyListener keyListener : keyListeners) {
        removeKeyListener(keyListener);
    }

    MouseListener[] mouseListeners = getMouseListeners();
    for (MouseListener mouseListener : mouseListeners) {
        removeMouseListener(mouseListener);
    }

    MouseMotionListener[] mouseMotionListeners = getMouseMotionListeners();
    for (MouseMotionListener mouseMotionListener : mouseMotionListeners) {
        removeMouseMotionListener(mouseMotionListener);
    }

    for (Component c : getComponents()) {
        removeFromCanvas(c);
    }
}
 
Example 3
Source Project: freecol   Source File: InGameMenuBar.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a new {@code FreeColMenuBar}. This menu bar will include
 * all of the submenus and items.
 *
 * @param freeColClient The main controller.
 * @param listener An optional mouse motion listener.
 */
public InGameMenuBar(FreeColClient freeColClient, MouseMotionListener listener) {
    // FIXME: FreeColClient should not have to be passed in to
    // this class.  This is only a menu bar, it doesn't need a
    // reference to the main controller.  The only reason it has
    // one now is because DebugMenu needs it.  And DebugMenu needs
    // it because it is using inner classes for ActionListeners
    // and those inner classes use the reference.  If those inner
    // classes were in seperate classes, when they were created,
    // they could use the FreeColClient reference of the
    // ActionManger.  So DebugMenu needs to be refactored to remove
    // inner classes so that this MenuBar can lose its unnecessary
    // reference to the main controller.  See FreeColMenuTest.
    //
    // Okay, I lied.. the update() and paintComponent() methods in
    // this MenuBar use freeColClient, too. But so what.  Move
    // those to another class too. :)
    super(freeColClient);

    // Add a mouse listener so that autoscrolling can happen in
    // this menubar
    this.addMouseMotionListener(listener);
    
    reset();
}
 
Example 4
Source Project: FCMFrame   Source File: CCSystem.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Set whether the coordinate system is movable with the mouse, i.e.
 * the scope of the system changes as the the mouse is clicked, held
 * and dragged over the system.
 * 
 * @param movable
 *        If true, move is possible.
 */
public void setMovable(boolean movable) {
    if (this.movable && movable) return;
    if (!this.movable && !movable) return;
    
    if (movable) {
        addMouseListener(mouseListener);
        addMouseMotionListener((MouseMotionListener) mouseListener);
    }
    else {
        removeMouseListener(mouseListener);
        removeMouseMotionListener((MouseMotionListener) mouseListener);
    }
    
    movable = !movable;
}
 
Example 5
Source Project: java-swing-tips   Source File: MainPanel.java    License: MIT License 6 votes vote down vote up
private MainPanel() {
  super(new BorderLayout());

  // title, resizable, closable, maximizable, iconifiable
  JInternalFrame immovableFrame = new JInternalFrame("immovable", false, false, true, true);
  Component north = ((BasicInternalFrameUI) immovableFrame.getUI()).getNorthPane();
  MouseMotionListener[] actions = north.getListeners(MouseMotionListener.class);
  for (MouseMotionListener l: actions) {
    north.removeMouseMotionListener(l);
  }
  // immovableFrame.setLocation(0, 0);
  immovableFrame.setSize(160, 0);
  desktop.add(immovableFrame);
  immovableFrame.setVisible(true);

  desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
  desktop.addComponentListener(new ComponentAdapter() {
    @Override public void componentResized(ComponentEvent e) {
      immovableFrame.setSize(immovableFrame.getSize().width, e.getComponent().getSize().height);
    }
  });

  add(desktop);
  add(createMenuBar(), BorderLayout.NORTH);
  setPreferredSize(new Dimension(320, 240));
}
 
Example 6
@Override
public void mouseDragged(MouseEvent e) {
    SwingGraphicsBridge.component.mouseDragged(e);
    if (active)
        for (MouseMotionListener mouseMotion1 : mouseMotion)
            mouseMotion1.mouseDragged(e);
}
 
Example 7
@Override
public void mouseMoved(MouseEvent e) {
    SwingGraphicsBridge.component.mouseMoved(e);
    if (active)
        for (MouseMotionListener mouseMotion1 : mouseMotion)
            mouseMotion1.mouseMoved(e);
}
 
Example 8
Source Project: amodeus   Source File: JMapController.java    License: GNU General Public License v2.0 5 votes vote down vote up
public JMapController(JMapViewer map) {
    this.map = map;
    if (this instanceof MouseListener)
        map.addMouseListener((MouseListener) this);
    if (this instanceof MouseWheelListener)
        map.addMouseWheelListener((MouseWheelListener) this);
    if (this instanceof MouseMotionListener)
        map.addMouseMotionListener((MouseMotionListener) this);
}
 
Example 9
Source Project: ramus   Source File: Handler.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Strips off the UI's mouse listeners attached to the associated toolbar
 * and replaces them with this handler's listeners.
 */
private void installListeners() {
    if (!ourVersionIsCompatible)
        return;

    ourToolBar.removePropertyChangeListener("UI", ourUIListener);

    // Uninstall the current ui, collect the remaining listeners
    // on the toolbar, and reinstall the ui...
    final ComponentUI ui = ourToolBar.getUI();
    ui.uninstallUI(ourToolBar);
    final java.util.List mList = Arrays.asList(ourToolBar
            .getListeners(MouseListener.class));

    final java.util.List mmList = Arrays.asList(ourToolBar
            .getListeners(MouseMotionListener.class));
    ui.installUI(ourToolBar);

    // ...then remove the listeners that were added by the ui...
    final MouseListener[] ml = ourToolBar
            .getListeners(MouseListener.class);
    final MouseMotionListener[] mml = ourToolBar
            .getListeners(MouseMotionListener.class);

    for (int i = 0; i < ml.length; i++) {
        if (!mList.contains(ml[i]))
            ourToolBar.removeMouseListener(ml[i]);
    }

    for (int i = 0; i < mml.length; i++) {
        if (!mmList.contains(mml[i]))
            ourToolBar.removeMouseMotionListener(mml[i]);
    }

    // ...and add our listeners to the toolbar.
    ourToolBar.addMouseListener(ourDragListener);
    ourToolBar.addMouseMotionListener(ourDragListener);
    ourToolBar.addPropertyChangeListener("UI", ourUIListener);
}
 
Example 10
Source Project: freecol   Source File: MapEditorMenuBar.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a new {@code MapEditorMenuBar}. This menu bar will include
 * all of the submenus and items.
 *
 * @param freeColClient The {@code FreeColClient} for the game.
 * @param listener An optional mouse motion listener.
 */
public MapEditorMenuBar(final FreeColClient freeColClient, MouseMotionListener listener) {
    super(freeColClient);

    // Add a mouse listener so that autoscrolling can happen in this menubar
    this.addMouseMotionListener(listener);
    reset();
}
 
Example 11
/**
 * Maps {@code Component.addMouseMotionListener(MouseMotionListener)}
 * through queue
 */
public void addMouseMotionListener(final MouseMotionListener mouseMotionListener) {
    runMapping(new MapVoidAction("addMouseMotionListener") {
        @Override
        public void map() {
            getSource().addMouseMotionListener(mouseMotionListener);
        }
    });
}
 
Example 12
/**
 * Maps
 * {@code Component.removeMouseMotionListener(MouseMotionListener)}
 * through queue
 */
public void removeMouseMotionListener(final MouseMotionListener mouseMotionListener) {
    runMapping(new MapVoidAction("removeMouseMotionListener") {
        @Override
        public void map() {
            getSource().removeMouseMotionListener(mouseMotionListener);
        }
    });
}
 
Example 13
public void removeListener() {
    for (MouseListener ml : com.getMouseListeners()) {
        com.removeMouseListener(ml);
    }
    for (MouseMotionListener mml : com.getMouseMotionListeners()) {
        com.removeMouseMotionListener(mml);
    }
    for (KeyListener kl : com.getKeyListeners()) {
        com.removeKeyListener(kl);
    }
    reset();
    com.repaint();
}
 
Example 14
Source Project: pumpernickel   Source File: DecoratedTreeUI.java    License: MIT License 5 votes vote down vote up
@Override
public void mouseDragged(MouseEvent e) {
	mouseX = e.getX();
	mouseY = e.getY();
	repaintDecorations(false);
	if (mouseListener instanceof MouseMotionListener)
		((MouseMotionListener) mouseListener).mouseDragged(e);
}
 
Example 15
Source Project: pumpernickel   Source File: DecoratedTreeUI.java    License: MIT License 5 votes vote down vote up
@Override
public void mouseMoved(MouseEvent e) {
	mouseX = e.getX();
	mouseY = e.getY();
	repaintDecorations(false);
	if (mouseListener instanceof MouseMotionListener)
		((MouseMotionListener) mouseListener).mouseMoved(e);
}
 
Example 16
Source Project: sldeditor   Source File: CharMap4Grid.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Instantiates a new char map4 grid.
 *
 * @param charMap4
 */
public CharMap4Grid(CharMap4 charMap4) {
    super(); // initialize our superclass first (JPanel)

    this.charMap4 = charMap4;
    // Set class instance variables to undefined values that we will recognise
    // if we are called before the layout and first "paint" is complete. */

    cellCount = charCount = glyphCount = 0; // no chars or glyphs to display
    clickIndex = NO_MOUSE; // cell index of clicked character
    clickStartX = clickStartY = NO_MOUSE; // no starting coordinates for click
    cornerIndex = 0; // cell index of top-left corner
    fontData = null; // information about current display font
    horizStep = 100; // horizontal offset from one cell to next
    hoverIndex = NO_MOUSE; // cell index of mouse over character
    lineAscent = 100; // number of pixels above baseline
    lineHeight = 100; // height of each display line in pixels
    maxWidth = 100; // maximum pixel width of all characters
    panelColumns = 10; // number of complete text columns displayed
    panelCount = -1; // saved value of <cellCount> used previously
    panelFont = null; // saved font for drawing text on this panel
    panelHeight = panelWidth = -1; // saved panel height and width in pixels
    panelRows = 10; // number of complete lines (rows) displayed
    vertiStep = 100; // vertical offset from one cell to next

    /* Install our mouse and scroll listeners. */

    this.addMouseListener((MouseListener) this);
    this.addMouseMotionListener((MouseMotionListener) this);
    this.addMouseWheelListener((MouseWheelListener) this);
    // this.setFocusable(false); // we don't handle keyboard input, owner does

}
 
Example 17
public JMapController(JMapViewer map) {
	this.map = map;
	if (this instanceof MouseListener)
		map.addMouseListener((MouseListener) this);
	if (this instanceof MouseWheelListener)
		map.addMouseWheelListener((MouseWheelListener) this);
	if (this instanceof MouseMotionListener)
		map.addMouseMotionListener((MouseMotionListener) this);
}
 
Example 18
Source Project: jexer   Source File: SwingComponent.java    License: MIT License 5 votes vote down vote up
/**
 * Adds the specified mouse motion listener to receive mouse motion
 * events from this component. If listener l is null, no exception is
 * thrown and no action is performed.
 *
 * @param l the mouse motion listener
 */
public void addMouseMotionListener(MouseMotionListener l) {
    if (frame != null) {
        frame.addMouseMotionListener(l);
    } else {
        component.addMouseMotionListener(l);
    }
}
 
Example 19
Source Project: seaglass   Source File: SeaGlassTabbedPaneUI.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new SeaGlassTabbedPaneMouseHandler object.
 *
 * @param originalMouseListener the original mouse handler.
 */
public SeaGlassTabbedPaneMouseHandler(MouseListener originalMouseListener) {
    delegate  = originalMouseListener;
    delegate2 = (MouseMotionListener) originalMouseListener;

    closeButtonHoverIndex = -1;
    closeButtonArmedIndex = -1;
}
 
Example 20
@Override
protected MouseMotionListener getMouseMotionListener() {
  if (myMouseMotionListener == null) {
    myMouseMotionListener = new MouseMotionListenerBase(getUIFacade(), getImplementation());
  }
  return myMouseMotionListener;
}
 
Example 21
Source Project: java-swing-tips   Source File: MainPanel.java    License: MIT License 5 votes vote down vote up
@Override public void updateUI() {
  super.updateUI();
  BasicInternalFrameUI ui = (BasicInternalFrameUI) getUI();
  Component titleBar = ui.getNorthPane();
  for (MouseMotionListener l: titleBar.getListeners(MouseMotionListener.class)) {
    titleBar.removeMouseMotionListener(l);
  }
  DragWindowListener dwl = new DragWindowListener();
  titleBar.addMouseListener(dwl);
  titleBar.addMouseMotionListener(dwl);
}
 
Example 22
Source Project: java-swing-tips   Source File: MainPanel.java    License: MIT License 5 votes vote down vote up
private MainPanel() {
  super(new BorderLayout());
  JTabbedPane tabbedPane = new JTabbedPane() {
    private transient MouseMotionListener hoverHandler;
    @Override public void updateUI() {
      removeMouseMotionListener(hoverHandler);
      super.updateUI();
      hoverHandler = new MouseAdapter() {
        @Override public void mouseMoved(MouseEvent e) {
          JTabbedPane source = (JTabbedPane) e.getComponent();
          int num = source.indexAtLocation(e.getX(), e.getY());
          for (int i = 0; i < source.getTabCount(); i++) {
            source.setForegroundAt(i, i == num ? Color.GREEN : Color.BLACK);
          }
        }
      };
      addMouseMotionListener(hoverHandler);
    }
  };
  tabbedPane.addTab("11111", new JScrollPane(new JTree()));
  tabbedPane.addTab("22222", new JScrollPane(new JLabel("asdfasdfsadf")));
  tabbedPane.addTab("33333", new JScrollPane(new JTree()));
  tabbedPane.addTab("44444", new JScrollPane(new JLabel("qerwqerqwerqwe")));
  tabbedPane.addTab("55555", new JScrollPane(new JTree()));

  add(tabbedPane);
  setPreferredSize(new Dimension(320, 240));
}
 
Example 23
protected MarkerBarListener lookupListsner(MarkerBar markerBar) {
	MouseMotionListener[] listeners = markerBar.getMouseMotionListeners();

	if (listeners != null) {
		for (int counter = 0; counter < listeners.length; counter++) {
			if (listeners[counter] instanceof MarkerBarListener) {
				return (MarkerBarListener) listeners[counter];
			}
		}
	}
	return null;
}
 
Example 24
Source Project: JavaGame   Source File: Menu.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
private void render() {
	// frame.getFrame().getContentPane().setBackground(Color.GREEN);
	frame.addMouseMotionListener((MouseMotionListener) Mouse);
	frame.addMouseListener(Mouse);
	frame.addKeyListener(Key);
	BufferStrategy bs = frame.getBufferStrategy();
	if (bs == null) {
		frame.createBufferStrategy(3);
		return;
	}
	Graphics g = bs.getDrawGraphics();
	g.setColor(Color.BLACK);
	g.fillRect(0, 0, frame.getWidth(), frame.getHeight());
	g.setColor(new Color(0xFF660000));
	g.fillRect(0, 0, WIDTH * 3, HEIGHT * 3);
	g.setColor(new Color(0xFFFF9900));
	g.setFont(font.getArial());
	if (isGameOver()) {
		g.drawString("GAME OVER... What will you do now?", 35, 30);
	} else {
		String name = (Game.getJdata_UserName().length() >= 1) ? WordUtils
				.capitalizeFully(Game.getJdata_UserName()).toString()
				: "Player";
		g.drawString("Welcome to JavaGame " + name, 35, 30);
	}
	g.drawLine(0, HEIGHT * 3, 0, 0);
	g.drawLine(0, 0, (WIDTH * 3), 0);
	g.drawLine((WIDTH * 3), 0, (WIDTH * 3), (HEIGHT * 3));
	g.drawLine(0, (HEIGHT * 3), (WIDTH * 3), (HEIGHT * 3));
	// (LEFT,DOWN,WIDTH,HEIGHT)
	paintButtons(isSelectedStart(), isSelectedExit(), g);
	bs.show();
	g.dispose();

}
 
Example 25
Source Project: consulo   Source File: IdeGlassPaneImpl.java    License: Apache License 2.0 5 votes vote down vote up
private static void fireMouseMotion(MouseMotionListener listener, final MouseEvent event) {
  switch (event.getID()) {
    case MouseEvent.MOUSE_DRAGGED:
      listener.mouseDragged(event);
    case MouseEvent.MOUSE_MOVED:
      listener.mouseMoved(event);
  }
}
 
Example 26
Source Project: consulo   Source File: ListenerUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static void addMouseMotionListener(Component c, MouseMotionListener l) {
  c.addMouseMotionListener(l);
  if (c instanceof Container) {
    final Container container = (Container)c;
    Component[] children = container.getComponents();
    for (Component child : children) {
      addMouseMotionListener(child, l);
    }
  }
}
 
Example 27
Source Project: consulo   Source File: ListenerUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static void removeMouseMotionListener(final Component component, final MouseMotionListener motionListener) {
  component.removeMouseMotionListener(motionListener);
  if (component instanceof Container) {
    Container container = (Container)component;
    for (int i = 0; i < container.getComponentCount(); i++) {
      removeMouseMotionListener(container.getComponent(i), motionListener);
    }
  }
}
 
Example 28
Source Project: darklaf   Source File: DarkNumberingPaneUI.java    License: MIT License 4 votes vote down vote up
protected MouseMotionListener getMouseMotionListener() {
    return getHandler();
}
 
Example 29
Source Project: darklaf   Source File: DummyEditorPane.java    License: MIT License 4 votes vote down vote up
@Override
public synchronized void addMouseMotionListener(final MouseMotionListener l) {}
 
Example 30
Source Project: darklaf   Source File: DummyTextArea.java    License: MIT License 4 votes vote down vote up
@Override
public synchronized void addMouseMotionListener(final MouseMotionListener l) {}