public static void issue163946Hack(final JScrollPane scrollPane) { MouseWheelListener listener = new MouseWheelListener() { @Override public void mouseWheelMoved(MouseWheelEvent e) { if (scrollPane.getVerticalScrollBar().isShowing()) { if (e.getSource() != scrollPane) { e.setSource(scrollPane); scrollPane.dispatchEvent(e); } } else { scrollPane.getParent().dispatchEvent(e); } } }; scrollPane.addMouseWheelListener(listener); scrollPane.getViewport().getView().addMouseWheelListener(listener); }
public MorphPanel(String morphName, final MorphView morphView) { this.morphName = morphName; this.morphView = morphView; this.mouseWheelListener = new MouseWheelListener() { @Override public void mouseWheelMoved(MouseWheelEvent arg0) { if (arg0.getSource() instanceof JSlider) { // JSlider slider = (JSlider) arg0.getSource(); // slider.setValue(slider.getValue() + arg0.getUnitsToScroll()); } } }; panel.setLayout(new BoxLayout(panel,BoxLayout.LINE_AXIS)); undoButton = new JButton(); panelState = new State(); morphSlider = new JSlider(JSlider.HORIZONTAL, -100, 100, 0); setupLabel(morphName); setupSlider(); useInKeyFrameCheckBox = new JCheckBox(); setupCheckbox(useInKeyFrameCheckBox); setupUndoButton(); }
/** * Creates a new {@link MapCanvas}. * * @param repProc replay processor * @param zoomComboBox combo box which tells how to zoom the map image */ public MapCanvas( final RepProcessor repProc, final XComboBox< Zoom > zoomComboBox ) { this.repProc = repProc; this.zoomComboBox = zoomComboBox; ricon = MapImageCache.getMapImage( repProc ); GuiUtils.makeComponentDragScrollable( this ); // Zoom in and out with CTRL+wheel scroll: addMouseWheelListener( new MouseWheelListener() { @Override public void mouseWheelMoved( final MouseWheelEvent event ) { if ( event.isControlDown() ) { final int newZoomIdx = zoomComboBox.getSelectedIndex() - event.getWheelRotation(); zoomComboBox.setSelectedIndex( Math.max( 0, Math.min( zoomComboBox.getItemCount() - 1, newZoomIdx ) ) ); // An event will be fired which will cause reconfigureZoom() to be called... } } } ); }
/** * 初始化语法错误面板 */ private void initGrammarErrorPane() { grammarErrorPanel = new GrammarErrorPanel(sourceCodeEditorPane); grammarErrorPanel.setBackground(LIGHT_GRAY_COLOR); grammarErrorScroll = new JScrollPane(grammarErrorPanel); grammarErrorScroll.setLocation(GRAMMAR_START_X, GRAMMAR_START_Y); grammarErrorScroll.setSize(GRAMMAR_WIDTH, GRAMMAR_HEIGHT); this.add(grammarErrorScroll); final JScrollBar vBar = grammarErrorScroll.getVerticalScrollBar(); vBar.setUI(null); grammarErrorScroll.setHorizontalScrollBar(null); grammarErrorScroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); MouseWheelListener[] listeners = grammarErrorScroll.getMouseWheelListeners(); for (MouseWheelListener l : listeners) { grammarErrorScroll.removeMouseWheelListener(l); } grammarErrorScroll.setBorder(null); }
public JScrollPopupMenu(String label) { super(label); setLayout(new ScrollPopupMenuLayout()); super.add(getScrollBar()); addMouseWheelListener(new MouseWheelListener() { @Override public void mouseWheelMoved(MouseWheelEvent event) { JScrollBar scrollBar = getScrollBar(); int amount = (event.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) ? event.getUnitsToScroll() * scrollBar.getUnitIncrement() : (event.getWheelRotation() < 0 ? -1 : 1) * scrollBar.getBlockIncrement(); scrollBar.setValue(scrollBar.getValue() + amount); event.consume(); } }); }
public JScrollC2PopupMenu(String label) { super(label); setLayout(new ScrollPopupMenuLayout()); super.add(getScrollBar()); addMouseWheelListener(new MouseWheelListener() { @Override public void mouseWheelMoved(MouseWheelEvent event) { JScrollBar scrollBar = getScrollBar(); int amount = (event.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) ? event .getUnitsToScroll() * scrollBar.getUnitIncrement() : (event.getWheelRotation() < 0 ? -1 : 1) * scrollBar.getBlockIncrement(); scrollBar.setValue(scrollBar.getValue() + amount); event.consume(); } }); }
public JScrollPopupMenu(String label) { super(label); setLayout(new ScrollPopupMenuLayout()); super.add(getScrollBar()); addMouseWheelListener(new MouseWheelListener() { @Override public void mouseWheelMoved(MouseWheelEvent event) { JScrollBar scrollBar = getScrollBar(); int amount = (event.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) ? event .getUnitsToScroll() * scrollBar.getUnitIncrement() : (event.getWheelRotation() < 0 ? -1 : 1) * scrollBar.getBlockIncrement(); scrollBar.setValue(scrollBar.getValue() + amount); event.consume(); } }); }
/** * Remove a listener for mouse wheel events. * * @param listener The mouse wheel listener to remove. */ public void removeMouseWheelListener(MouseWheelListener listener) { if (app == null) { return; } synchronized (app.getAppCleanupLock()) { synchronized (this) { if (mouseWheelListeners == null) { return; } mouseWheelListeners.remove(listener); if (mouseWheelListeners.size() == 0) { mouseWheelListeners = null; } } } }
public void setModel(ImagePanelModel model) { this.model = model; revalidate(); final JScrollPane scrollPane = (JScrollPane) SwingUtilities.getAncestorOfClass(JScrollPane.class, this); if (scrollPane != null) { scrollPane.addMouseWheelListener(new MouseWheelListener() { public void mouseWheelMoved(MouseWheelEvent e) { if (SwingUtil.isControlDown(e) || e.isMetaDown()) { e.consume(); int steps = e.getWheelRotation(); setGridSize(gridSize + steps); scrollPane.setWheelScrollingEnabled(false); } else { scrollPane.setWheelScrollingEnabled(true); } } }); scrollPane.revalidate(); scrollPane.repaint(); } }
@SuppressWarnings("unchecked") public <T extends EventListener> T[] getListeners(Class<T> listenerType) { if (ComponentListener.class.isAssignableFrom(listenerType)) { return (T[]) getComponentListeners(); } else if (FocusListener.class.isAssignableFrom(listenerType)) { return (T[]) getFocusListeners(); } else if (HierarchyBoundsListener.class.isAssignableFrom(listenerType)) { return (T[]) getHierarchyBoundsListeners(); } else if (HierarchyListener.class.isAssignableFrom(listenerType)) { return (T[]) getHierarchyListeners(); } else if (InputMethodListener.class.isAssignableFrom(listenerType)) { return (T[]) getInputMethodListeners(); } else if (KeyListener.class.isAssignableFrom(listenerType)) { return (T[]) getKeyListeners(); } else if (MouseWheelListener.class.isAssignableFrom(listenerType)) { return (T[]) getMouseWheelListeners(); } else if (MouseMotionListener.class.isAssignableFrom(listenerType)) { return (T[]) getMouseMotionListeners(); } else if (MouseListener.class.isAssignableFrom(listenerType)) { return (T[]) getMouseListeners(); } else if (PropertyChangeListener.class.isAssignableFrom(listenerType)) { return (T[]) getPropertyChangeListeners(); } return (T[]) Array.newInstance(listenerType, 0); }
public final void testProcessMouseWheelEvent() { eventProcessed = false; scrollPane.addMouseWheelListener(new MouseWheelListener() { public void mouseWheelMoved(MouseWheelEvent arg0) { eventProcessed = true; } }); scrollPane.processEvent(new MouseWheelEvent(scrollPane, MouseEvent.MOUSE_WHEEL, 0l, 0, 100, 200, 0, false, MouseWheelEvent.WHEEL_BLOCK_SCROLL, 10, 10)); assertTrue(eventProcessed); }
private void setMouseWheelListener() { addMouseWheelListener(new MouseWheelListener() { @Override public void mouseWheelMoved(MouseWheelEvent event) { final int cardIndex = getCardIndexAt(event.getX(), event.getY()); if (event.getWheelRotation() < 0) { // rotate mousewheel forward if (cardIndex >= 0) { showCardPopup(cardIndex); } } else if (event.getWheelRotation() > 0) { // rotate mousewheel back if (cardIndex >= 0) { controller.hideInfo(); } } } }); }
private void registerScrollWheelListener(){ this.addMouseWheelListener(new MouseWheelListener(){ @Override public void mouseWheelMoved(MouseWheelEvent e) { if(e.getModifiers() == InputEvent.CTRL_MASK){ long centerTime = ABar.this.timeByXinView(e.getPoint().x); long newVisibleTime = navbar.getVisibleTime() + navbar.getVisibleTime() / 10 * e.getWheelRotation(); if(newVisibleTime <= player.getMediaDuration() && newVisibleTime > 100) navbar.setVisibleTime(newVisibleTime, centerTime); else if(newVisibleTime > player.getMediaDuration()){ navbar.setVisibleTime(player.getMediaDuration(), centerTime); } } else { long scrollSpeed = navbar.getVisibleTime() / 10; long newTime = navbar.getCurrentStartVisibleTime() + (scrollSpeed * e.getWheelRotation()); navbar.setCurrentStartVisibleTime(newTime); } } }); }
public void addZoomMouseListeners() { MouseWheelListener zoomer = new java.awt.event.MouseWheelListener() { public void mouseWheelMoved(java.awt.event.MouseWheelEvent evt) { onZoom(evt); } }; for (JTextArea ta : textAreas) { // Note: We cannot add a MouseWheelListener to the JTextArea; the // JScrollPane // will disable it's scrolling handler of the child has a mouse // listener. // So walk from the JtextArea to JViewPort to JScrollPane and add // the listeners there. if (ta.getParent().getParent() instanceof JScrollPane) { JScrollPane parent = (JScrollPane) ta.getParent().getParent(); parent.addMouseWheelListener(zoomer); } } }
/** * a setter for the GraphMouse. This will remove any * previous GraphMouse (including the one that * is added in the initMouseClicker method. * @param graphMouse new value */ public void setGraphMouse(GraphMouse graphMouse) { this.graphMouse = graphMouse; MouseListener[] ml = getMouseListeners(); for(int i=0; i<ml.length; i++) { if(ml[i] instanceof GraphMouse) { removeMouseListener(ml[i]); } } MouseMotionListener[] mml = getMouseMotionListeners(); for(int i=0; i<mml.length; i++) { if(mml[i] instanceof GraphMouse) { removeMouseMotionListener(mml[i]); } } MouseWheelListener[] mwl = getMouseWheelListeners(); for(int i=0; i<mwl.length; i++) { if(mwl[i] instanceof GraphMouse) { removeMouseWheelListener(mwl[i]); } } addMouseListener(graphMouse); addMouseMotionListener(graphMouse); addMouseWheelListener(graphMouse); }
TabbedPane(MainWindow window) { mainWindow = window; setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT); addMouseWheelListener(new MouseWheelListener() { public void mouseWheelMoved(MouseWheelEvent e) { int direction = e.getWheelRotation(); int index = getSelectedIndex(); int maxIndex = getTabCount() - 1; if ((index == 0 && direction < 0) || (index == maxIndex && direction > 0)) { index = maxIndex - index; } else { index += direction; } setSelectedIndex(index); } }); }
/** * Add new event handler. Depending on the interfaces implemented by * <code>handler</code> calls {@link Component#addKeyListener(KeyListener)}, * {@link Component#addMouseListener(MouseListener)}, * {@link Component#addMouseMotionListener(MouseMotionListener)}, * {@link Component#addMouseWheelListener(MouseWheelListener)}. */ @Override public void addHandler( final Object handler ) { if ( KeyListener.class.isInstance( handler ) ) addKeyListener( ( KeyListener ) handler ); if ( MouseMotionListener.class.isInstance( handler ) ) addMouseMotionListener( ( MouseMotionListener ) handler ); if ( MouseListener.class.isInstance( handler ) ) addMouseListener( ( MouseListener ) handler ); if ( MouseWheelListener.class.isInstance( handler ) ) addMouseWheelListener( ( MouseWheelListener ) handler ); }
/** * Remove an event handler. * Add new event handler. Depending on the interfaces implemented by * <code>handler</code> calls {@link Component#removeKeyListener(KeyListener)}, * {@link Component#removeMouseListener(MouseListener)}, * {@link Component#removeMouseMotionListener(MouseMotionListener)}, * {@link Component#removeMouseWheelListener(MouseWheelListener)}. */ @Override public void removeHandler( final Object handler ) { if ( KeyListener.class.isInstance( handler ) ) removeKeyListener( ( KeyListener ) handler ); if ( MouseMotionListener.class.isInstance( handler ) ) removeMouseMotionListener( ( MouseMotionListener ) handler ); if ( MouseListener.class.isInstance( handler ) ) removeMouseListener( ( MouseListener ) handler ); if ( MouseWheelListener.class.isInstance( handler ) ) removeMouseWheelListener( ( MouseWheelListener ) handler ); }
@Override public void mouseWheelMoved(MouseWheelEvent originalEvent) { MouseWheelEvent event = new MouseWheelEvent( originalEvent.getComponent(), originalEvent.getID(), originalEvent.getWhen(), originalEvent.getModifiers(), originalEvent.getX(), originalEvent.getY(), originalEvent.getXOnScreen(), originalEvent.getYOnScreen(), originalEvent.getClickCount(), originalEvent.isPopupTrigger(), originalEvent.getScrollType(), scrollAmount, originalEvent.getWheelRotation()); for (MouseWheelListener listener : originalListeners) listener.mouseWheelMoved(event); }
/** * Return the array of DeviceManagers that are available per the * constructor parameters. The InputDevices instantiated will be * initialized with the AWT ui toolkit event listeners. * * @return the array of DeviceManagers. If no DeviceManagers are * available, an empty (size 0) array is returned. */ public DeviceManager[] getDeviceManagers( ) { List managerList = createDevices( ); DeviceManager[] manager = (DeviceManager[])managerList.toArray( new DeviceManager[managerList.size( )] ); Component cmp = (Component)canvas; for( int i = 0; i < manager.length; i++ ) { InputDevice[] device = manager[i].getDevices( ); for( int j = 0; j < device.length; j++ ) { InputDevice dev = device[j]; if( dev instanceof MouseListener ) { cmp.addMouseListener( (MouseListener)dev ); } if( dev instanceof MouseMotionListener ) { cmp.addMouseMotionListener( (MouseMotionListener)dev ); } if( dev instanceof MouseWheelListener ) { cmp.addMouseWheelListener( (MouseWheelListener)dev ); } if( dev instanceof KeyListener ) { cmp.addKeyListener( (KeyListener)dev ); } } } return( manager ); }
@Override public void registerMouseWheelListener(final MouseWheelListener listener) { if (this.mouseWheelListeners.contains(listener)) { return; } this.mouseWheelListeners.add(listener); }
@Override public void unregisterMouseWheelListener(final MouseWheelListener listener) { if (!this.mouseWheelListeners.contains(listener)) { return; } this.mouseWheelListeners.remove(listener); }
private void updateListeners() { ScrollPaneUI ui = scrollPane.getUI(); if (ui != lastUI) { // Update "ui" property listener if (ui != null) { // Check mouse wheel listeners on scroll pane. // Pair first non-MWDelegator listener with // Remove any other delegators than this one. MouseWheelListener[] mwls = scrollPane.getListeners(MouseWheelListener.class); if (LOG.isLoggable(Level.FINE)) { LOG.log(Level.FINE, "MouseWheelDelegator.updateListeners(): scrollPane change scrollPane={0}, MouseWheelListeners:{1}\n", new Object[]{obj2String(scrollPane), Arrays.asList(mwls)}); } delegateListener = null; for (MouseWheelListener listener : mwls) { if (listener instanceof MouseWheelDelegator) { scrollPane.removeMouseWheelListener(listener); if (delegateListener == null) { delegateListener = ((MouseWheelDelegator) listener).delegateListener; scrollPane.addMouseWheelListener(this); } } else { // Regular listener // Current patch only assumes one MW listener attached by the UI impl. if (delegateListener == null) { delegateListener = listener; scrollPane.removeMouseWheelListener(listener); scrollPane.addMouseWheelListener(this); } } } } lastUI = ui; } }
void delegateToOriginalListener(MouseWheelEvent e, JScrollPane activeScrollPane) { // Only delegate if the updated scrollpane is still actively used by the DocumentViewOp // and when it still uses the overriden listener (this) if (activeScrollPane == scrollPane) { MouseWheelListener[] mwls = scrollPane.getListeners(MouseWheelListener.class); for (int i = 0; i < mwls.length; i++) { if (mwls[i] == this) { delegateListener.mouseWheelMoved(e); return; } } } }
public void addMouseWheelListener(MouseWheelListener listener) { if (myMouseWheelListeners == null) { myMouseWheelListeners = new ArrayList<MouseWheelListener>(); } //out("Listener: " + listener.getClass().getName()); myMouseWheelListeners.add(listener); }
public void addWheelListener(MouseWheelListener wheelListener) { super.addMouseWheelListener(wheelListener); for (int i = 0; i < myMouseWheelListeners.size(); i++) { super.addMouseWheelListener(myMouseWheelListeners.get(i)); } }
private void setWheelScrollHandler(final JScrollBar scrollBar) { chart.addMouseWheelListener(new MouseWheelListener() { public void mouseWheelMoved(MouseWheelEvent e) { scroll(scrollBar, e); } }); }
private void configureWheelListener() { addMouseWheelListener(new MouseWheelListener() { public void mouseWheelMoved(MouseWheelEvent e) { if (e.getScrollType() != MouseWheelEvent.WHEEL_UNIT_SCROLL) return; Object newValue = (e.getWheelRotation() < 0 ? JExtendedSpinner.this.getNextValue() : JExtendedSpinner.this.getPreviousValue()); if (newValue != null) JExtendedSpinner.this.setValue(newValue); } }); }
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); }
public PrintPreviewComponent(RamusPrintable printable, int columnCount, GUIFramework framework) { this.printable = printable; this.columnCount = columnCount; this.framework = framework; MouseWheelListener l = new MouseWheelListener() { @Override public void mouseWheelMoved(MouseWheelEvent e) { if (e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) { if (e.getModifiers() == KeyEvent.CTRL_MASK) { double r = e.getWheelRotation(); double zoom = getZoom() - 0.2 * r; setCurrentZoom(zoom); } else { Rectangle rect = getVisibleRect(); scrollRectToVisible(new Rectangle(rect.x, rect.y + e.getWheelRotation() * 150, rect.width, rect.height)); } } } }; this.addMouseWheelListener(l); layout = Options.getInteger("PREVIW_LAYOUT", PREV_LAYOUT_GRID); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { setCurrentZoom(Options.getDouble("PREV_ZOOM", 1d)); } }); setCurrentZoom(Options.getDouble("PREV_ZOOM", 1d)); }
/** * Called when the mouse wheel is moved. * If CTRL key is down, modify current zoom ratio accordingly, otherwise * forward the wheel event to proper container (JScrollPane usually). * * @param e the mouse wheel event */ @Override public void mouseWheelMoved (MouseWheelEvent e) { // CTRL is down? if (e.isControlDown()) { double ratio = zoom.getRatio(); if (e.getWheelRotation() > 0) { ratio /= factor; } else { ratio *= factor; } zoom.setRatio(ratio); } else { // Forward event to some container of the component? Container container = component.getParent(); while (container != null) { if (container instanceof JComponent) { JComponent comp = (JComponent) container; MouseWheelListener[] listeners = comp.getMouseWheelListeners(); if (listeners.length > 0) { for (MouseWheelListener listener : listeners) { listener.mouseWheelMoved(e); } return; } } container = container.getParent(); } } }
public JointRotationPanel(String jointName, JointView jointView) { this.jointName = jointName; this.jointView = jointView; this.mouseWheelListener = new MouseWheelListener() { @Override public void mouseWheelMoved(MouseWheelEvent arg0) { if (arg0.getSource() instanceof JSlider) { // JSlider slider = (JSlider) arg0.getSource(); // slider.setValue(slider.getValue() + // arg0.getUnitsToScroll()); } } }; panel.setLayout(new BoxLayout(panel, BoxLayout.LINE_AXIS)); undoButton = new JButton(); panelState = new State(); pitchSlider = new JSlider(JSlider.HORIZONTAL, -180, 180, 0); yawSlider = new JSlider(JSlider.HORIZONTAL, -180, 180, 0); rollSlider = new JSlider(JSlider.HORIZONTAL, -180, 180, 0); useInKeyFrameCheckBox = new JCheckBox(); setupLabel(jointName); setupSlider(pitchSlider); setupSlider(yawSlider); setupSlider(rollSlider); setupCheckbox(useInKeyFrameCheckBox); setupUndoButton(); }
/** * Calls appropriate method on the listener based on this events ID. * * @param listener the target for dispatch. */ public void dispatchTo(final Object listener) { final MouseWheelListener mouseWheelListener = (MouseWheelListener) listener; switch (getID()) { case MouseEvent.MOUSE_WHEEL: mouseWheelListener.mouseWheelMoved(this); break; default: throw new RuntimeException("PMouseWheelEvent with bad ID"); } }