Example usage for java.awt.event MouseWheelEvent getScrollType

List of usage examples for java.awt.event MouseWheelEvent getScrollType

Introduction

In this page you can find the example usage for java.awt.event MouseWheelEvent getScrollType.

Prototype

public int getScrollType() 

Source Link

Document

Returns the type of scrolling that should take place in response to this event.

Usage

From source file:Main.java

public static MouseEvent convertMouseEvent(Component source, MouseEvent sourceEvent, Component destination) {
    Point p = SwingUtilities.convertPoint(source, new Point(sourceEvent.getX(), sourceEvent.getY()),
            destination);//from  w w w.j av  a  2 s  .c  o m
    Component newSource;

    if (destination != null)
        newSource = destination;
    else
        newSource = source;

    MouseEvent newEvent;
    if (sourceEvent instanceof MouseWheelEvent) {
        MouseWheelEvent sourceWheelEvent = (MouseWheelEvent) sourceEvent;
        newEvent = new MouseWheelEvent(newSource, sourceWheelEvent.getID(), sourceWheelEvent.getWhen(),
                sourceEvent.getModifiers() | sourceEvent.getModifiersEx(), p.x, p.y,
                sourceWheelEvent.getClickCount(), sourceWheelEvent.isPopupTrigger(),
                sourceWheelEvent.getScrollType(), sourceWheelEvent.getScrollAmount(),
                sourceWheelEvent.getWheelRotation());
    } else if (sourceEvent instanceof MenuDragMouseEvent) {
        MenuDragMouseEvent sourceMenuDragEvent = (MenuDragMouseEvent) sourceEvent;
        newEvent = new MenuDragMouseEvent(newSource, sourceMenuDragEvent.getID(), sourceMenuDragEvent.getWhen(),
                sourceEvent.getModifiers() | sourceEvent.getModifiersEx(), p.x, p.y,
                sourceMenuDragEvent.getClickCount(), sourceMenuDragEvent.isPopupTrigger(),
                sourceMenuDragEvent.getPath(), sourceMenuDragEvent.getMenuSelectionManager());
    } else {
        newEvent = new MouseEvent(newSource, sourceEvent.getID(), sourceEvent.getWhen(),
                sourceEvent.getModifiers() | sourceEvent.getModifiersEx(), p.x, p.y,
                sourceEvent.getClickCount(), sourceEvent.isPopupTrigger(), sourceEvent.getButton());
    }
    return newEvent;
}

From source file:com.vgi.mafscaling.MafChartPanel.java

public void mouseWheelMoved(MouseWheelEvent e) {
    if (e.getScrollType() != MouseWheelEvent.WHEEL_UNIT_SCROLL)
        return;// w w  w. j  av a 2s  .  c  o m
    if (e.getWheelRotation() < 0)
        zoomChartAxis(chartPanel, true);
    else
        zoomChartAxis(chartPanel, false);
}

From source file:api3.transform.PlotWave.java

private MouseWheelListener addZoomWheel() {
    return new MouseWheelListener() {
        private void zoomChartAxis(ChartPanel chartP, boolean increase) {
            int width = chartP.getMaximumDrawWidth() - chartP.getMinimumDrawWidth();
            int height = chartP.getMaximumDrawHeight() - chartP.getMinimumDrawWidth();
            if (increase) {
                chartP.zoomInDomain(width / 2, height / 2);
            } else {
                chartP.zoomOutDomain(width / 2, height / 2);
            }//from w  ww . j a  va 2  s.  c  o m
            lastValue = SLIDER_DEFAULT_VALUE;
            slider.setValue(lastValue);

        }

        public synchronized void decreaseZoom(JComponent chart, boolean saveAction) {
            ChartPanel ch = (ChartPanel) chart;
            zoomChartAxis(ch, false);
        }

        public synchronized void increaseZoom(JComponent chart, boolean saveAction) {
            ChartPanel ch = (ChartPanel) chart;
            zoomChartAxis(ch, true);
        }

        @Override
        public void mouseWheelMoved(MouseWheelEvent e) {
            if (e.getScrollType() != MouseWheelEvent.WHEEL_UNIT_SCROLL) {
                return;
            }
            if (e.getWheelRotation() < 0) {
                increaseZoom((ChartPanel) e.getComponent(), true);
            } else {
                decreaseZoom((ChartPanel) e.getComponent(), true);
            }
        }
    };
}

From source file:Main.java

public void mouseWheelMoved(MouseWheelEvent e) {
    String message;/*from w  w w . j av  a  2  s. c  om*/
    int notches = e.getWheelRotation();
    if (notches < 0) {
        message = "Mouse wheel moved UP " + -notches + " notch(es)" + newline;
    } else {
        message = "Mouse wheel moved DOWN " + notches + " notch(es)" + newline;
    }
    if (e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) {
        message += "    Scroll type: WHEEL_UNIT_SCROLL" + newline;
        message += "    Scroll amount: " + e.getScrollAmount() + " unit increments per notch" + newline;
        message += "    Units to scroll: " + e.getUnitsToScroll() + " unit increments" + newline;
        message += "    Vertical unit increment: " + scrollPane.getVerticalScrollBar().getUnitIncrement(1)
                + " pixels" + newline;
    } else { // scroll type == MouseWheelEvent.WHEEL_BLOCK_SCROLL
        message += "    Scroll type: WHEEL_BLOCK_SCROLL" + newline;
        message += "    Vertical block increment: " + scrollPane.getVerticalScrollBar().getBlockIncrement(1)
                + " pixels" + newline;
    }
    saySomething(message, e);
}

From source file:Main.java

public Main() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setSize(200, 200);//from   w  ww. ja  va 2  s  .c  om
    JTextArea textArea = new JTextArea();
    textArea.addMouseWheelListener(new MouseWheelListener() {
        public void mouseWheelMoved(MouseWheelEvent e) {
            if (e.getWheelRotation() < 0) {
                System.out.println("Up... " + e.getWheelRotation());
            } else {
                System.out.println("Down... " + e.getWheelRotation());
            }
            System.out.println("ScrollAmount: " + e.getScrollAmount());

            if (e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) {
                System.out.println("MouseWheelEvent.WHEEL_UNIT_SCROLL");
            }

            if (e.getScrollType() == MouseWheelEvent.WHEEL_BLOCK_SCROLL) {
                System.out.println("MouseWheelEvent.WHEEL_BLOCK_SCROLL");
            }
        }
    });

    getContentPane().add(textArea);
}

From source file:MouseWheelEventDemo.java

public void mouseWheelMoved(MouseWheelEvent e) {
    String message;// w w  w  .j  a v  a 2s .  co m
    int notches = e.getWheelRotation();
    if (notches < 0) {
        message = "Mouse wheel moved UP " + -notches + " notch(es)" + newline;
    } else {
        message = "Mouse wheel moved DOWN " + notches + " notch(es)" + newline;
    }
    if (e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) {
        message += "    Scroll type: WHEEL_UNIT_SCROLL" + newline;
        message += "    Scroll amount: " + e.getScrollAmount() + " unit increments per notch" + newline;
        message += "    Units to scroll: " + e.getUnitsToScroll() + " unit increments" + newline;
        message += "    Vertical unit increment: " + scrollPane.getVerticalScrollBar().getUnitIncrement(1)
                + " pixels" + newline;
    } else { //scroll type == MouseWheelEvent.WHEEL_BLOCK_SCROLL
        message += "    Scroll type: WHEEL_BLOCK_SCROLL" + newline;
        message += "    Vertical block increment: " + scrollPane.getVerticalScrollBar().getBlockIncrement(1)
                + " pixels" + newline;
    }
    saySomething(message, e);
}

From source file:events.MouseWheelEventDemo.java

public void mouseWheelMoved(MouseWheelEvent e) {
    String message;//from  w w w .j  av a  2  s  .c  o m
    int notches = e.getWheelRotation();
    if (notches < 0) {
        message = "Mouse wheel moved UP " + -notches + " notch(es)" + NEWLINE;
    } else {
        message = "Mouse wheel moved DOWN " + notches + " notch(es)" + NEWLINE;
    }
    if (e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) {
        message += "    Scroll type: WHEEL_UNIT_SCROLL" + NEWLINE;
        message += "    Scroll amount: " + e.getScrollAmount() + " unit increments per notch" + NEWLINE;
        message += "    Units to scroll: " + e.getUnitsToScroll() + " unit increments" + NEWLINE;
        message += "    Vertical unit increment: " + scrollPane.getVerticalScrollBar().getUnitIncrement(1)
                + " pixels" + NEWLINE;
    } else { //scroll type == MouseWheelEvent.WHEEL_BLOCK_SCROLL
        message += "    Scroll type: WHEEL_BLOCK_SCROLL" + NEWLINE;
        message += "    Vertical block increment: " + scrollPane.getVerticalScrollBar().getBlockIncrement(1)
                + " pixels" + NEWLINE;
    }
    eventOutput(message, e);
}

From source file:com.anrisoftware.prefdialog.miscswing.multichart.freechart.FreechartXYChart.java

private Object resolveObject() {
    this.p = new PropertyChangeSupport(this);
    this.mouseScrollListener = new MouseWheelListener() {

        @Override/*from w w w  .ja  va 2  s .c  om*/
        public void mouseWheelMoved(MouseWheelEvent e) {
            if (model == null) {
                return;
            }
            if (e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) {
                int offset = model.getOffset();
                setOffset(offset + e.getUnitsToScroll());
            }
        }
    };
    this.modelListener = new ChartModelListener() {

        @Override
        public void chartChanged(ChartModelEvent e) {
            updateChart(e);
        }
    };
    return this;
}

From source file:net.sf.firemox.clickable.target.card.MCard.java

public void mouseWheelMoved(MouseWheelEvent e) {
    // Update mouse wheel layout only if this card is in play with nested cards
    if (getIdZone() == IdZones.PLAY && getComponentCount() > 1) {
        final LayoutManager layoutManager = getLayout();
        if (layoutManager != null && layoutManager instanceof AttachmentLayout
                && e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) {
            if (e.getWheelRotation() < 0) {
                ((AttachmentLayout) layoutManager).decreaseCardLayout(-e.getWheelRotation());
            } else {
                ((AttachmentLayout) layoutManager).increaseCardLayout(e.getWheelRotation());
            }//from  ww w. j a v  a  2  s.com
        }
        doLayout();
        getParent().doLayout();
        getContainer().doLayout();
    }
}

From source file:com.rapidminer.gui.plotter.charts.AbstractChartPanel.java

/**
 * Constructs a JFreeChart panel.//from  w  w  w.  j  a  v a  2s  .  co m
 * 
 * @param chart
 *            the chart.
 * @param width
 *            the preferred width of the panel.
 * @param height
 *            the preferred height of the panel.
 * @param minimumDrawWidth
 *            the minimum drawing width.
 * @param minimumDrawHeight
 *            the minimum drawing height.
 * @param maximumDrawWidth
 *            the maximum drawing width.
 * @param maximumDrawHeight
 *            the maximum drawing height.
 * @param useBuffer
 *            a flag that indicates whether to use the off-screen buffer to improve performance
 *            (at the expense of memory).
 * @param properties
 *            a flag indicating whether or not the chart property editor should be available via
 *            the popup menu.
 * @param copy
 *            a flag indicating whether or not a copy option should be available via the popup
 *            menu.
 * @param save
 *            a flag indicating whether or not save options should be available via the popup
 *            menu.
 * @param print
 *            a flag indicating whether or not the print option should be available via the
 *            popup menu.
 * @param zoom
 *            a flag indicating whether or not zoom options should be added to the popup menu.
 * @param tooltips
 *            a flag indicating whether or not tooltips should be enabled for the chart.
 * 
 * @since 1.0.13
 */
public AbstractChartPanel(JFreeChart chart, int width, int height, int minimumDrawWidth, int minimumDrawHeight,
        int maximumDrawWidth, int maximumDrawHeight, boolean useBuffer, boolean properties, boolean copy,
        boolean save, boolean print, boolean zoom, boolean tooltips) {
    super(chart, width, height, minimumDrawWidth, minimumDrawHeight, maximumDrawWidth, maximumDrawHeight, false,
            properties, copy, save, print, zoom, tooltips);
    setChart(chart);
    this.chartMouseListeners = new EventListenerList();
    this.info = new ChartRenderingInfo();
    setPreferredSize(new Dimension(width, height));

    this.minimumDrawWidth = minimumDrawWidth;
    this.minimumDrawHeight = minimumDrawHeight;
    this.maximumDrawWidth = maximumDrawWidth;
    this.maximumDrawHeight = maximumDrawHeight;
    this.zoomTriggerDistance = DEFAULT_ZOOM_TRIGGER_DISTANCE;

    // set up popup menu...
    this.popup = null;
    if (properties || copy || save || print || zoom) {
        this.popup = createPopupMenu(properties, copy, save, print, zoom);
    }

    enableEvents(AWTEvent.MOUSE_EVENT_MASK);
    enableEvents(AWTEvent.MOUSE_MOTION_EVENT_MASK);
    setDisplayToolTips(tooltips);
    // mouse listener registered in super class
    // addMouseListener(this);
    // addMouseMotionListener(this);

    this.defaultDirectoryForSaveAs = null;
    this.enforceFileExtensions = true;

    // initialize ChartPanel-specific tool tip delays with
    // values the from ToolTipManager.sharedInstance()
    ToolTipManager ttm = ToolTipManager.sharedInstance();
    this.ownToolTipInitialDelay = ttm.getInitialDelay();
    this.ownToolTipDismissDelay = ttm.getDismissDelay();
    this.ownToolTipReshowDelay = ttm.getReshowDelay();

    this.zoomAroundAnchor = false;
    this.selectionOutlinePaint = Color.blue;
    this.selectionFillPaint = new Color(0, 0, 255, 63);

    this.panMask = InputEvent.CTRL_MASK;
    // for MacOSX we can't use the CTRL key for mouse drags, see:
    // http://developer.apple.com/qa/qa2004/qa1362.html
    String osName = System.getProperty("os.name").toLowerCase();
    if (osName.startsWith("mac os x")) {
        this.panMask = InputEvent.ALT_MASK;
    }

    this.overlays = new java.util.ArrayList<>();

    // adding wheel listener
    addMouseWheelListener(new MouseWheelListener() {

        @Override
        public void mouseWheelMoved(MouseWheelEvent e) {
            if (e.getScrollType() != MouseWheelEvent.WHEEL_UNIT_SCROLL) {
                return;
            }
            if (e.getWheelRotation() < 0) {
                shrinkSelectionOnCenter(e.getX(), e.getY(), e);
            } else {
                enlargeSelectionOnCenter(e.getX(), e.getY(), e);
            }
        }
    });
}