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 2017/12/14 17:02:25 UTC

svn commit: r1818168 - in /pivot/trunk: tutorials/src/org/apache/pivot/tutorials/explorer/ tutorials/src/org/apache/pivot/tutorials/navigation/ wtk/src/org/apache/pivot/wtk/

Author: rwhitcomb
Date: Thu Dec 14 17:02:25 2017
New Revision: 1818168

URL: http://svn.apache.org/viewvc?rev=1818168&view=rev
Log:
PIVOT-1017:  Move the "Ruler" and associated classes (Skin and Listener) into
the mainline code for general use.  Remove it from the "tutorials" area (both
copies) and update the references to use the general one.
Made one change to the code:  update the drawing to make the 1/2 mark slightly
longer than the others to look more like a real Ruler.

Added:
    pivot/trunk/wtk/src/org/apache/pivot/wtk/Ruler.java
    pivot/trunk/wtk/src/org/apache/pivot/wtk/RulerListener.java
    pivot/trunk/wtk/src/org/apache/pivot/wtk/RulerSkin.java
Removed:
    pivot/trunk/tutorials/src/org/apache/pivot/tutorials/explorer/Ruler.java
    pivot/trunk/tutorials/src/org/apache/pivot/tutorials/explorer/RulerListener.java
    pivot/trunk/tutorials/src/org/apache/pivot/tutorials/explorer/RulerSkin.java
    pivot/trunk/tutorials/src/org/apache/pivot/tutorials/navigation/Ruler.java
    pivot/trunk/tutorials/src/org/apache/pivot/tutorials/navigation/RulerListener.java
    pivot/trunk/tutorials/src/org/apache/pivot/tutorials/navigation/RulerSkin.java
Modified:
    pivot/trunk/tutorials/src/org/apache/pivot/tutorials/explorer/scroll_pane.bxml
    pivot/trunk/tutorials/src/org/apache/pivot/tutorials/navigation/scroll_panes.bxml

Modified: pivot/trunk/tutorials/src/org/apache/pivot/tutorials/explorer/scroll_pane.bxml
URL: http://svn.apache.org/viewvc/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/explorer/scroll_pane.bxml?rev=1818168&r1=1818167&r2=1818168&view=diff
==============================================================================
--- pivot/trunk/tutorials/src/org/apache/pivot/tutorials/explorer/scroll_pane.bxml (original)
+++ pivot/trunk/tutorials/src/org/apache/pivot/tutorials/explorer/scroll_pane.bxml Thu Dec 14 17:02:25 2017
@@ -17,16 +17,15 @@ limitations under the License.
 -->
 
 <ScrollPane xmlns:bxml="http://pivot.apache.org/bxml"
-    xmlns:explorer="org.apache.pivot.tutorials.explorer"
     xmlns="org.apache.pivot.wtk">
     <ImageView image="/org/apache/pivot/tutorials/IMG_1147.jpg"
         tooltipText="Pemaquid Point Lighthouse, Bristol ME"/>
 
     <columnHeader>
-        <explorer:Ruler orientation="horizontal"/>
+        <Ruler orientation="horizontal"/>
     </columnHeader>
 
     <rowHeader>
-        <explorer:Ruler orientation="vertical"/>
+        <Ruler orientation="vertical"/>
     </rowHeader>
 </ScrollPane>

Modified: pivot/trunk/tutorials/src/org/apache/pivot/tutorials/navigation/scroll_panes.bxml
URL: http://svn.apache.org/viewvc/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/navigation/scroll_panes.bxml?rev=1818168&r1=1818167&r2=1818168&view=diff
==============================================================================
--- pivot/trunk/tutorials/src/org/apache/pivot/tutorials/navigation/scroll_panes.bxml (original)
+++ pivot/trunk/tutorials/src/org/apache/pivot/tutorials/navigation/scroll_panes.bxml Thu Dec 14 17:02:25 2017
@@ -18,7 +18,6 @@ limitations under the License.
 
 <Window title="Scroll Panes" maximized="true"
     xmlns:bxml="http://pivot.apache.org/bxml"
-    xmlns:navigation="org.apache.pivot.tutorials.navigation"
     xmlns="org.apache.pivot.wtk">
     <Border styles="{color:10}">
         <ScrollPane>
@@ -26,11 +25,11 @@ limitations under the License.
                 tooltipText="Pemaquid Point Lighthouse, Bristol ME"/>
 
             <columnHeader>
-                <navigation:Ruler orientation="horizontal"/>
+                <Ruler orientation="horizontal"/>
             </columnHeader>
 
             <rowHeader>
-                <navigation:Ruler orientation="vertical"/>
+                <Ruler orientation="vertical"/>
             </rowHeader>
         </ScrollPane>
     </Border>

Added: pivot/trunk/wtk/src/org/apache/pivot/wtk/Ruler.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/Ruler.java?rev=1818168&view=auto
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/Ruler.java (added)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/Ruler.java Thu Dec 14 17:02:25 2017
@@ -0,0 +1,61 @@
+/*
+ * 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.wtk;
+
+import org.apache.pivot.util.ListenerList;
+import org.apache.pivot.util.Utils;
+import org.apache.pivot.wtk.Component;
+import org.apache.pivot.wtk.Orientation;
+
+/**
+ * A viewport header that displays a ruler along either the top or left side.
+ */
+public class Ruler extends Component {
+
+    private static class RulerListenerList extends ListenerList<RulerListener> implements
+        RulerListener {
+        @Override
+        public void orientationChanged(Ruler ruler) {
+            forEach(listener -> listener.orientationChanged(ruler));
+        }
+    }
+
+    private Orientation orientation;
+
+    private RulerListenerList rulerListeners = new RulerListenerList();
+
+    public Ruler() {
+        setSkin(new RulerSkin());
+    }
+
+    public Orientation getOrientation() {
+        return orientation;
+    }
+
+    public void setOrientation(Orientation orientation) {
+        Utils.checkNull(orientation, "orientation");
+
+        if (this.orientation != orientation) {
+            this.orientation = orientation;
+            rulerListeners.orientationChanged(this);
+        }
+    }
+
+    public ListenerList<RulerListener> getRulerListeners() {
+        return rulerListeners;
+    }
+}

Added: pivot/trunk/wtk/src/org/apache/pivot/wtk/RulerListener.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/RulerListener.java?rev=1818168&view=auto
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/RulerListener.java (added)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/RulerListener.java Thu Dec 14 17:02:25 2017
@@ -0,0 +1,21 @@
+/*
+ * 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.wtk;
+
+public interface RulerListener {
+    public void orientationChanged(Ruler ruler);
+}

Added: pivot/trunk/wtk/src/org/apache/pivot/wtk/RulerSkin.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/RulerSkin.java?rev=1818168&view=auto
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/RulerSkin.java (added)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/RulerSkin.java Thu Dec 14 17:02:25 2017
@@ -0,0 +1,114 @@
+/*
+ * 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.wtk;
+
+import java.awt.Color;
+import java.awt.Graphics2D;
+
+import org.apache.pivot.wtk.Component;
+import org.apache.pivot.wtk.Orientation;
+import org.apache.pivot.wtk.skin.ComponentSkin;
+
+class RulerSkin extends ComponentSkin implements RulerListener {
+    @Override
+    public void install(Component component) {
+        super.install(component);
+
+        Ruler ruler = (Ruler) component;
+        ruler.getRulerListeners().add(this);
+    }
+
+    @Override
+    public void layout() {
+        // No-op
+    }
+
+    @Override
+    public int getPreferredHeight(int width) {
+        Ruler ruler = (Ruler) getComponent();
+        Orientation orientation = ruler.getOrientation();
+
+        return (orientation == Orientation.HORIZONTAL) ? 20 : 0;
+    }
+
+    @Override
+    public int getPreferredWidth(int height) {
+        Ruler ruler = (Ruler) getComponent();
+        Orientation orientation = ruler.getOrientation();
+
+        return (orientation == Orientation.VERTICAL) ? 20 : 0;
+    }
+
+    @Override
+    public void paint(Graphics2D graphics) {
+        int width = getWidth();
+        int height = getHeight();
+
+        Ruler ruler = (Ruler) getComponent();
+
+        graphics.setColor(CSSColor.LightYellow.getColor());
+        graphics.fillRect(0, 0, width, height);
+
+        graphics.setColor(Color.BLACK);
+        graphics.drawRect(0, 0, width - 1, height - 1);
+
+        Orientation orientation = ruler.getOrientation();
+        switch (orientation) {
+            case HORIZONTAL: {
+                for (int i = 0, n = width / 5 + 1; i < n; i++) {
+                    int x = i * 5;
+
+                    if (i % 4 == 0) {
+                        graphics.drawLine(x, 0, x, height / 2);
+                    } else if (i % 2 == 0) {
+                        graphics.drawLine(x, 0, x, height / 3);
+                    } else {
+                        graphics.drawLine(x, 0, x, height / 4);
+                    }
+                }
+
+                break;
+            }
+
+            case VERTICAL: {
+                for (int i = 0, n = height / 5 + 1; i < n; i++) {
+                    int y = i * 5;
+
+                    if (i % 4 == 0) {
+                        graphics.drawLine(0, y, width / 2, y);
+                    } else if (i % 2 == 0) {
+                        graphics.drawLine(0, y, width / 3, y);
+                    } else {
+                        graphics.drawLine(0, y, width / 4, y);
+                    }
+                }
+
+                break;
+            }
+
+            default: {
+                break;
+            }
+        }
+    }
+
+    @Override
+    public void orientationChanged(Ruler ruler) {
+        invalidateComponent();
+    }
+
+}