java.awt.event.MouseMotionListener Java Examples

The following examples show how to use java.awt.event.MouseMotionListener. 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: CCSystem.java    From FCMFrame with 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 #2
Source File: Canvas.java    From freecol with 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 File: InGameMenuBar.java    From freecol with 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 File: GraphViewerTest.java    From ghidra with 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 #5
Source File: MainPanel.java    From java-swing-tips with 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
Source File: JMapController.java    From Course_Generator with GNU General Public License v3.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 #7
Source File: Handler.java    From ramus with 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 #8
Source File: SwingComponent.java    From jexer with 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 #9
Source File: SeaGlassTabbedPaneUI.java    From seaglass with 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 #10
Source File: MapEditorMenuBar.java    From freecol with 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
Source File: ResourceLoadGraphicArea.java    From ganttproject with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected MouseMotionListener getMouseMotionListener() {
  if (myMouseMotionListener == null) {
    myMouseMotionListener = new MouseMotionListenerBase(getUIFacade(), getImplementation());
  }
  return myMouseMotionListener;
}
 
Example #12
Source File: JMapController.java    From amodeus with 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 #13
Source File: MainPanel.java    From java-swing-tips with 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 #14
Source File: MainPanel.java    From java-swing-tips with 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 #15
Source File: SwingWrapperClickConsumer.java    From CrossMobile with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void mouseMoved(MouseEvent e) {
    SwingGraphicsBridge.component.mouseMoved(e);
    if (active)
        for (MouseMotionListener mouseMotion1 : mouseMotion)
            mouseMotion1.mouseMoved(e);
}
 
Example #16
Source File: SwingWrapperClickConsumer.java    From CrossMobile with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void mouseDragged(MouseEvent e) {
    SwingGraphicsBridge.component.mouseDragged(e);
    if (active)
        for (MouseMotionListener mouseMotion1 : mouseMotion)
            mouseMotion1.mouseDragged(e);
}
 
Example #17
Source File: ComponentOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 #18
Source File: BasicMarkerBarUI.java    From microba with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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 #19
Source File: ComponentOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 #20
Source File: Menu.java    From JavaGame with 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 #21
Source File: SelectionManager.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 5 votes vote down vote up
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 #22
Source File: IdeGlassPaneImpl.java    From consulo with 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 #23
Source File: CharMap4Grid.java    From sldeditor with 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 #24
Source File: DecoratedTreeUI.java    From pumpernickel with 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 #25
Source File: DecoratedTreeUI.java    From pumpernickel with 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 #26
Source File: ListenerUtil.java    From consulo with 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 File: ListenerUtil.java    From consulo with 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 File: MainPanel.java    From java-swing-tips with MIT License 4 votes vote down vote up
private static JInternalFrame makeInternalFrame() {
  JInternalFrame internal = new JInternalFrame("@title@");
  BasicInternalFrameUI ui = (BasicInternalFrameUI) internal.getUI();
  Component title = ui.getNorthPane();
  for (MouseMotionListener l: title.getListeners(MouseMotionListener.class)) {
    title.removeMouseMotionListener(l);
  }
  DragWindowListener dwl = new DragWindowListener();
  title.addMouseListener(dwl);
  title.addMouseMotionListener(dwl);

  KeyboardFocusManager focusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
  focusManager.addPropertyChangeListener(e -> {
    String prop = e.getPropertyName();
    // System.out.println(prop);
    if ("activeWindow".equals(prop)) {
      try {
        internal.setSelected(Objects.nonNull(e.getNewValue()));
      } catch (PropertyVetoException ex) {
        throw new IllegalStateException(ex);
      }
      // System.out.println("---------------------");
    }
  });

  // frame.addWindowListener(new WindowAdapter() {
  //   @Override public void windowLostFocus(FocusEvent e) {
  //     System.out.println("222222222");
  //     try {
  //       internal.setSelected(false);
  //     } catch (PropertyVetoException ex) {
  //       throw new IllegalStateException(ex);
  //     }
  //   }
  //   @Override public void windowGainedFocus(FocusEvent e) {
  //     System.out.println("111111111");
  //     try {
  //       internal.setSelected(true);
  //     } catch (PropertyVetoException ex) {
  //       throw new IllegalStateException(ex);
  //     }
  //   }
  // });
  // EventQueue.invokeLater(() -> {
  //   try {
  //     internal.setSelected(true);
  //   } catch (PropertyVetoException ex) {
  //     throw new IllegalStateException(ex);
  //   }
  //   // internal.requestFocusInWindow();
  // });
  return internal;
}
 
Example #29
Source File: Plotter.java    From rapidminer-studio with GNU Affero General Public License v3.0 4 votes vote down vote up
/** Adds a mouse motion listener to the plotter component. */
public void addMouseMotionListener(MouseMotionListener listener);
 
Example #30
Source File: IdeGlassPaneImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void removeMouseMotionPreprocessor(final MouseMotionListener listener) {
  removeListener(listener);
}