Search in sources :

Example 1 with ComponentMouseWheelListener

use of org.apache.pivot.wtk.ComponentMouseWheelListener in project pivot by apache.

the class ScaleDecoratorDemo method startup.

@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
    BXMLSerializer bxmlSerializer = new BXMLSerializer();
    scaleWindow = (Window) bxmlSerializer.readObject(DecoratorDemo.class, "scale_window.bxml");
    bxmlSerializer.bind(this);
    imageView.getComponentMouseWheelListeners().add(new ComponentMouseWheelListener() {

        @Override
        public boolean mouseWheel(Component component, Mouse.ScrollType scrollType, int scrollAmount, int wheelRotation, int x, int y) {
            // Note: both scale values are the same
            float currentScale = scaleDecorator.getScaleX();
            if (wheelRotation < 0) {
                // UP == zoom in, make scale larger
                scaleDecorator.setScale(currentScale * 2.0f);
            } else {
                // DOWN == zoom out, make scale smaller
                scaleDecorator.setScale(currentScale / 2.0f);
            }
            component.repaint();
            return true;
        }
    });
    scaleWindow.open(display);
}
Also used : Mouse(org.apache.pivot.wtk.Mouse) ComponentMouseWheelListener(org.apache.pivot.wtk.ComponentMouseWheelListener) Component(org.apache.pivot.wtk.Component) BXMLSerializer(org.apache.pivot.beans.BXMLSerializer)

Aggregations

BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)1 Component (org.apache.pivot.wtk.Component)1 ComponentMouseWheelListener (org.apache.pivot.wtk.ComponentMouseWheelListener)1 Mouse (org.apache.pivot.wtk.Mouse)1