public static void addScrollListener(final ImagePlus img, final AdjustmentListener al, final MouseWheelListener ml) { for (final Component c : img.getWindow().getComponents()) { if (c instanceof Scrollbar) ((Scrollbar) c).addAdjustmentListener(al); else if (c instanceof Container) { for (final Component c2 : ((Container) c).getComponents()) { if (c2 instanceof Scrollbar) { ((Scrollbar) c2).addAdjustmentListener(al); } } } } img.getWindow().addMouseWheelListener(ml); }
protected void register() { ImagePlus.addImageListener(this); notifyIfChanged(); if (window == null) return; window.addMouseWheelListener(this); for (Component child : window.getComponents()) if (child instanceof Scrollbar) ((Scrollbar)child).addAdjustmentListener(this); else if (child instanceof Container) for (Component child2 : ((Container)child).getComponents()) if (child2 instanceof Scrollbar) ((Scrollbar)child2).addAdjustmentListener(this); }
public void unregister() { ImagePlus.removeImageListener(this); if (window == null) return; window.removeWindowListener(this); window.removeMouseWheelListener(this); for (Component child : window.getComponents()) if (child instanceof Scrollbar) ((Scrollbar)child).removeAdjustmentListener(this); else if (child instanceof Container) for (Component child2 : ((Container)child).getComponents()) if (child2 instanceof Scrollbar) ((Scrollbar)child2).removeAdjustmentListener(this); }
protected void handleImage(ImagePlus image, boolean addAsListener) { ImageWindow window = image.getWindow(); for (Component comp : window.getComponents()) if (comp instanceof Scrollbar) { Scrollbar bar = (Scrollbar)comp; if (addAsListener) bar.addAdjustmentListener(this); else bar.removeAdjustmentListener(this); } if (addAsListener) window.addWindowListener(this); else window.removeWindowListener(this); }