You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by rw...@apache.org on 2015/12/01 01:28:32 UTC
svn commit: r1717360 - in
/pivot/trunk/demos/src/org/apache/pivot/demos/decorator:
ScaleDecoratorDemo.java scale_window.bxml
Author: rwhitcomb
Date: Tue Dec 1 00:28:32 2015
New Revision: 1717360
URL: http://svn.apache.org/viewvc?rev=1717360&view=rev
Log:
Add a demo program to illustrate how to use ScaleDecorator for zooming
in and out of an image.
Added:
pivot/trunk/demos/src/org/apache/pivot/demos/decorator/ScaleDecoratorDemo.java
pivot/trunk/demos/src/org/apache/pivot/demos/decorator/scale_window.bxml
Added: pivot/trunk/demos/src/org/apache/pivot/demos/decorator/ScaleDecoratorDemo.java
URL: http://svn.apache.org/viewvc/pivot/trunk/demos/src/org/apache/pivot/demos/decorator/ScaleDecoratorDemo.java?rev=1717360&view=auto
==============================================================================
--- pivot/trunk/demos/src/org/apache/pivot/demos/decorator/ScaleDecoratorDemo.java (added)
+++ pivot/trunk/demos/src/org/apache/pivot/demos/decorator/ScaleDecoratorDemo.java Tue Dec 1 00:28:32 2015
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pivot.demos.decorator;
+
+import org.apache.pivot.beans.BXML;
+import org.apache.pivot.beans.BXMLSerializer;
+import org.apache.pivot.collections.Map;
+import org.apache.pivot.wtk.Application;
+import org.apache.pivot.wtk.Component;
+import org.apache.pivot.wtk.ComponentMouseWheelListener;
+import org.apache.pivot.wtk.DesktopApplicationContext;
+import org.apache.pivot.wtk.Display;
+import org.apache.pivot.wtk.ImageView;
+import org.apache.pivot.wtk.Mouse;
+import org.apache.pivot.wtk.Window;
+import org.apache.pivot.wtk.effects.ScaleDecorator;
+
+public class ScaleDecoratorDemo extends Application.Adapter {
+ private Window scaleWindow;
+ @BXML private ImageView imageView;
+ @BXML private ScaleDecorator scaleDecorator;
+
+ @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);
+ }
+
+ @Override
+ public boolean shutdown(boolean optional) {
+ if (scaleWindow != null) {
+ scaleWindow.close();
+ }
+
+ return false;
+ }
+
+ public static void main(String[] args) {
+ DesktopApplicationContext.main(ScaleDecoratorDemo.class, args);
+ }
+
+}
Added: pivot/trunk/demos/src/org/apache/pivot/demos/decorator/scale_window.bxml
URL: http://svn.apache.org/viewvc/pivot/trunk/demos/src/org/apache/pivot/demos/decorator/scale_window.bxml?rev=1717360&view=auto
==============================================================================
--- pivot/trunk/demos/src/org/apache/pivot/demos/decorator/scale_window.bxml (added)
+++ pivot/trunk/demos/src/org/apache/pivot/demos/decorator/scale_window.bxml Tue Dec 1 00:28:32 2015
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements. See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to you under the Apache License,
+Version 2.0 (the "License"); you may not use this file except in
+compliance with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+-->
+
+<Window title="Scale Window" x="20" y="20"
+ xmlns:bxml="http://pivot.apache.org/bxml"
+ xmlns:effects="org.apache.pivot.wtk.effects"
+ xmlns="org.apache.pivot.wtk">
+
+ <BoxPane orientation="vertical" styles="{horizontalAlignment:'center'}">
+ <Label text="Use the mouse wheel over the image to zoom in and out."/>
+ <Border>
+ <ImageView image="@IMG_0767_2.jpg" bxml:id="imageView">
+ <decorators>
+ <effects:ScaleDecorator bxml:id="scaleDecorator"/>
+ </decorators>
+ </ImageView>
+ </Border>
+ </BoxPane>
+</Window>
+