You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by gb...@apache.org on 2009/11/11 14:39:28 UTC

svn commit: r834880 - in /incubator/pivot/trunk: core/src/org/apache/pivot/util/ demos/src/org/apache/pivot/demos/explorer/progress/ wtk/src/org/apache/pivot/wtk/ wtk/src/org/apache/pivot/wtk/skin/terra/ wtk/test/org/apache/pivot/wtk/test/

Author: gbrown
Date: Wed Nov 11 13:39:27 2009
New Revision: 834880

URL: http://svn.apache.org/viewvc?rev=834880&view=rev
Log:
Minor updates to Time, Meter, SplitPane, and Slider.

Modified:
    incubator/pivot/trunk/core/src/org/apache/pivot/util/Time.java
    incubator/pivot/trunk/demos/src/org/apache/pivot/demos/explorer/progress/meter.wtkx
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Meter.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/MeterListener.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/SplitPane.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/SplitPaneListener.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraMeterSkin.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraSliderSkin.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraSplitPaneSkin.java
    incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/SplitPaneTest.java
    incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/splitpane_test.wtkx

Modified: incubator/pivot/trunk/core/src/org/apache/pivot/util/Time.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/core/src/org/apache/pivot/util/Time.java?rev=834880&r1=834879&r2=834880&view=diff
==============================================================================
--- incubator/pivot/trunk/core/src/org/apache/pivot/util/Time.java (original)
+++ incubator/pivot/trunk/core/src/org/apache/pivot/util/Time.java Wed Nov 11 13:39:27 2009
@@ -203,7 +203,13 @@
     public static final int MILLISECONDS_PER_DAY = 24 * MILLISECONDS_PER_HOUR;
 
     public Time() {
-        GregorianCalendar calendar = new GregorianCalendar();
+        this(new GregorianCalendar());
+    }
+
+    public Time(Calendar calendar) {
+        if (calendar == null) {
+            throw new IllegalArgumentException();
+        }
 
         this.hour = calendar.get(Calendar.HOUR_OF_DAY);
         this.minute = calendar.get(Calendar.MINUTE);
@@ -267,10 +273,10 @@
      * The resulting time.
      */
     public Time add(int milliseconds) {
-        milliseconds %= MILLISECONDS_PER_DAY;
-
         milliseconds += toMilliseconds();
 
+        milliseconds %= MILLISECONDS_PER_DAY;
+
         if (milliseconds < 0) {
             milliseconds += MILLISECONDS_PER_DAY;
         }

Modified: incubator/pivot/trunk/demos/src/org/apache/pivot/demos/explorer/progress/meter.wtkx
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/demos/src/org/apache/pivot/demos/explorer/progress/meter.wtkx?rev=834880&r1=834879&r2=834880&view=diff
==============================================================================
--- incubator/pivot/trunk/demos/src/org/apache/pivot/demos/explorer/progress/meter.wtkx (original)
+++ incubator/pivot/trunk/demos/src/org/apache/pivot/demos/explorer/progress/meter.wtkx Wed Nov 11 13:39:27 2009
@@ -16,6 +16,6 @@
 limitations under the License.
 -->
 
-<Meter preferredWidth="200" preferredHeight="16" percentage="0.5"
+<Meter percentage="0.5"
     xmlns:wtkx="http://pivot.apache.org/wtkx"
     xmlns="org.apache.pivot.wtk"/>

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Meter.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Meter.java?rev=834880&r1=834879&r2=834880&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Meter.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Meter.java Wed Nov 11 13:39:27 2009
@@ -30,7 +30,7 @@
                 listener.orientationChanged(meter);
             }
         }
-        
+
         @Override
         public void percentageChanged(Meter meter, double oldPercentage) {
             for (MeterListener listener : this) {
@@ -54,7 +54,7 @@
     public Meter() {
         this(Orientation.HORIZONTAL);
     }
-    
+
     public Meter(Orientation orientation) {
         this.orientation = orientation;
         installThemeSkin(Meter.class);
@@ -110,7 +110,7 @@
 
         setOrientation(Orientation.valueOf(orientation.toUpperCase()));
     }
-    
+
     public ListenerList<MeterListener> getMeterListeners() {
         return meterListeners;
     }

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/MeterListener.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/MeterListener.java?rev=834880&r1=834879&r2=834880&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/MeterListener.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/MeterListener.java Wed Nov 11 13:39:27 2009
@@ -20,7 +20,7 @@
  * Meter listener interface.
  */
 public interface MeterListener {
-    
+
     public static class Adapter implements MeterListener {
         @Override
         public void percentageChanged(Meter meter, double previousPercentage) {
@@ -32,7 +32,7 @@
         public void orientationChanged(Meter meter) {
         }
     }
-    
+
     /**
      * Called when a meter's percentage value has changed.
      *
@@ -48,7 +48,7 @@
      * @param previousText
      */
     public void textChanged(Meter meter, String previousText);
-    
+
     /**
      * Called when a sliders's orientation has changed.
      *

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/SplitPane.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/SplitPane.java?rev=834880&r1=834879&r2=834880&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/SplitPane.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/SplitPane.java Wed Nov 11 13:39:27 2009
@@ -46,12 +46,13 @@
      * Enumeration defining split pane resizing modes.
      */
     public enum ResizeMode {
-        /** when resizing, maintain the ratio between the regions */
+        /** When resizing, maintains the ratio between the regions. */
         SPLIT_RATIO,
-        /** when resizing, preserve the size of the primary region */
+
+        /** When resizing, preserves the size of the primary region. */
         PRIMARY_REGION
     }
-    
+
     private static class SplitPaneListenerList extends ListenerList<SplitPaneListener>
         implements SplitPaneListener {
         @Override
@@ -95,7 +96,7 @@
                 listener.lockedChanged(splitPane);
             }
         }
-        
+
         @Override
         public void resizeModeChanged(SplitPane splitPane, ResizeMode previousResizeMode) {
             for (SplitPaneListener listener : this) {
@@ -306,7 +307,7 @@
         }
 
         ResizeMode previousResizeMode = this.resizeMode;
-        
+
         if (this.resizeMode != resizeMode) {
             this.resizeMode = resizeMode;
             splitPaneListeners.resizeModeChanged(this, previousResizeMode);
@@ -320,7 +321,7 @@
 
         setResizeMode(ResizeMode.valueOf(resizeMode.toUpperCase()));
     }
-    
+
     @Override
     public Sequence<Component> remove(int index, int count) {
         for (int i = index, n = index + count; i < n; i++) {

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/SplitPaneListener.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/SplitPaneListener.java?rev=834880&r1=834879&r2=834880&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/SplitPaneListener.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/SplitPaneListener.java Wed Nov 11 13:39:27 2009
@@ -76,7 +76,7 @@
      * The source of the event.
      */
     public void lockedChanged(SplitPane splitPane);
-    
+
     /**
      * Called when a split pane's split location has changed.
      *

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraMeterSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraMeterSkin.java?rev=834880&r1=834879&r2=834880&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraMeterSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraMeterSkin.java Wed Nov 11 13:39:27 2009
@@ -81,57 +81,54 @@
     @Override
     public int getPreferredWidth(int height) {
         Meter meter = (Meter)getComponent();
-        if (meter.getOrientation()==Orientation.HORIZONTAL) {
-            return internalGetPreferredWidth();
-        } else {
-            return internalGetPreferredHeight();
-        }
-    }
-    
-    @Override
-    public int getPreferredHeight(int width) {
-        Meter meter = (Meter)getComponent();
-        if (meter.getOrientation()==Orientation.HORIZONTAL) {
-            return internalGetPreferredHeight();
-        } else {
-            return internalGetPreferredWidth();
-        }
-    }
-    
-    private int internalGetPreferredWidth() {
-        Meter meter = (Meter)getComponent();
-        String text = meter.getText();
 
         int preferredWidth;
-        if (text != null
-            && text.length() > 0) {
-            Rectangle2D stringBounds = font.getStringBounds(text, FONT_RENDER_CONTEXT);
-            preferredWidth = (int)Math.ceil(stringBounds.getWidth()) + 2;
+
+        if (meter.getOrientation()==Orientation.HORIZONTAL) {
+            String text = meter.getText();
+
+            if (text != null
+                && text.length() > 0) {
+                Rectangle2D stringBounds = font.getStringBounds(text, FONT_RENDER_CONTEXT);
+                preferredWidth = (int)Math.ceil(stringBounds.getWidth()) + 2;
+            } else {
+                preferredWidth = 0;
+            }
+
+            // If the meter has no content, its preferred width is hard-coded by the
+            // class and is not affected by the height constraint
+            preferredWidth = Math.max(preferredWidth, DEFAULT_WIDTH);
+
         } else {
-            preferredWidth = 0;
+            preferredWidth = getPreferredHeight(-1);
         }
 
-        // If the meter has no content, its preferred width is hard-coded by the
-        // class and is not affected by the height constraint
-        preferredWidth = Math.max(preferredWidth, DEFAULT_WIDTH);
-
         return preferredWidth;
     }
 
-    private int internalGetPreferredHeight() {
+    @Override
+    public int getPreferredHeight(int width) {
         Meter meter = (Meter)getComponent();
-        String text = meter.getText();
 
-        int preferredHeight = 0;
-        if (text != null
-            && text.length() > 0) {
-            LineMetrics lm = font.getLineMetrics("", FONT_RENDER_CONTEXT);
-            preferredHeight = (int)Math.ceil(lm.getHeight()) + 2;
-        }
+        int preferredHeight;
 
-        // If the meter has no content, its preferred height is hard-coded by the
-        // class and is not affected by the width constraint
-        preferredHeight = Math.max(preferredHeight, DEFAULT_HEIGHT);
+        if (meter.getOrientation()==Orientation.HORIZONTAL) {
+            preferredHeight = getPreferredWidth(width);
+        } else {
+            String text = meter.getText();
+
+            if (text != null
+                && text.length() > 0) {
+                LineMetrics lm = font.getLineMetrics("", FONT_RENDER_CONTEXT);
+                preferredHeight = (int)Math.ceil(lm.getHeight()) + 2;
+            } else {
+                preferredHeight = 0;
+            }
+
+            // If the meter has no content, its preferred height is hard-coded by the
+            // class and is not affected by the width constraint
+            preferredHeight = Math.max(preferredHeight, DEFAULT_HEIGHT);
+        }
 
         return preferredHeight;
     }
@@ -156,11 +153,14 @@
         preferredWidth = Math.max(preferredWidth, DEFAULT_WIDTH);
         preferredHeight = Math.max(preferredHeight, DEFAULT_HEIGHT);
 
+        Dimensions preferredSize;
         if (meter.getOrientation()==Orientation.HORIZONTAL) {
-            return new Dimensions(preferredWidth, preferredHeight);
+            preferredSize = new Dimensions(preferredWidth, preferredHeight);
         } else {
-            return new Dimensions(preferredHeight, preferredWidth);
+            preferredSize = new Dimensions(preferredHeight, preferredWidth);
         }
+
+        return preferredSize;
     }
 
     @Override
@@ -168,20 +168,18 @@
         int baseline = -1;
 
         Meter meter = (Meter)getComponent();
-        
-        if (meter.getOrientation()==Orientation.VERTICAL) {
-            return -1;
-        }
-        
-        String text = meter.getText();
 
-        if (text != null
-            && text.length() > 0) {
-            LineMetrics lm = font.getLineMetrics("", FONT_RENDER_CONTEXT);
-            float ascent = lm.getAscent();
-            float textHeight = lm.getHeight();
+        if (meter.getOrientation() == Orientation.HORIZONTAL) {
+            String text = meter.getText();
 
-            baseline = Math.round((height - textHeight) / 2 + ascent);
+            if (text != null
+                && text.length() > 0) {
+                LineMetrics lm = font.getLineMetrics("", FONT_RENDER_CONTEXT);
+                float ascent = lm.getAscent();
+                float textHeight = lm.getHeight();
+
+                baseline = Math.round((height - textHeight) / 2 + ascent);
+            }
         }
 
         return baseline;
@@ -222,7 +220,7 @@
             graphics.setTransform(oldTransform);
         }
     }
-    
+
     private void drawMeter(Meter meter, Graphics2D graphics, int width, int height) {
         int meterStop = (int)(meter.getPercentage() * width);
         // Paint the interior fill
@@ -412,7 +410,7 @@
     public void textChanged(Meter meter, String previousText) {
         invalidateComponent();
     }
-    
+
     /**
      * Listener for meter orientation changes.
      *

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraSliderSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraSliderSkin.java?rev=834880&r1=834879&r2=834880&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraSliderSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraSliderSkin.java Wed Nov 11 13:39:27 2009
@@ -82,8 +82,7 @@
                 width / 2, height, buttonBackgroundColor));
             graphics.fillRect(0, 0, width, height);
 
-            float alpha = (highlighted
-                || dragOffset != null) ? 0.25f : 0.0f;
+            float alpha = (highlighted || dragOffset != null) ? 0.25f : 0.0f;
             graphics.setPaint(new Color(0, 0, 0, alpha));
             graphics.fillRect(0, 0, width, height);
 
@@ -111,7 +110,7 @@
             boolean consumed = super.mouseMove(component, x, y);
 
             if (Mouse.getCapturer() == component) {
-                Slider slider = (Slider) TerraSliderSkin.this.getComponent();
+                Slider slider = (Slider)TerraSliderSkin.this.getComponent();
                 if (slider.getOrientation() == Orientation.HORIZONTAL) {
                     int sliderWidth = slider.getWidth();
                     int thumbWidth = thumb.getWidth();
@@ -129,12 +128,12 @@
                         sliderX = maxX;
                     }
 
-                    float ratio = (float) (sliderX - dragOffset.x) / (sliderWidth - thumbWidth);
+                    float ratio = (float)(sliderX - dragOffset.x) / (sliderWidth - thumbWidth);
 
                     int start = slider.getStart();
                     int end = slider.getEnd();
 
-                    int value = (int) (start + (end - start) * ratio);
+                    int value = (int)(start + (end - start) * ratio);
                     slider.setValue(value);
                 } else {
                     int sliderHeight = slider.getHeight();
@@ -153,12 +152,12 @@
                         sliderY = maxY;
                     }
 
-                    float ratio = (float) (sliderY - dragOffset.y) / (sliderHeight - thumbHeight);
+                    float ratio = (float)(sliderY - dragOffset.y) / (sliderHeight - thumbHeight);
 
                     int start = slider.getStart();
                     int end = slider.getEnd();
 
-                    int value = (int) (start + (end - start) * ratio);
+                    int value = (int)(start + (end - start) * ratio);
                     slider.setValue(value);
                 }
             }
@@ -220,7 +219,8 @@
         public boolean keyPressed(Component component, int keyCode, Keyboard.KeyLocation keyLocation) {
             boolean consumed = super.keyPressed(component, keyCode, keyLocation);
 
-            Slider slider = (Slider) TerraSliderSkin.this.getComponent();
+            Slider slider = (Slider)TerraSliderSkin.this.getComponent();
+
             int start = slider.getStart();
             int end = slider.getEnd();
             int length = end - start;
@@ -228,10 +228,12 @@
             int value = slider.getValue();
             int increment = length / 10;
 
-            if (keyCode == Keyboard.KeyCode.LEFT) {
+            if (keyCode == Keyboard.KeyCode.LEFT
+                || keyCode == Keyboard.KeyCode.UP) {
                 slider.setValue(Math.max(start, value - increment));
                 consumed = true;
-            } else if (keyCode == Keyboard.KeyCode.RIGHT) {
+            } else if (keyCode == Keyboard.KeyCode.RIGHT
+                || keyCode == Keyboard.KeyCode.DOWN) {
                 slider.setValue(Math.min(end, value + increment));
                 consumed = true;
             }
@@ -258,7 +260,7 @@
     public static final int MINIMUM_THUMB_HEIGHT = 4;
 
     public TerraSliderSkin() {
-        TerraTheme theme = (TerraTheme) Theme.getTheme();
+        TerraTheme theme = (TerraTheme)Theme.getTheme();
 
         trackColor = theme.getColor(6);
         trackWidth = 2;
@@ -275,13 +277,13 @@
     public void install(Component component) {
         super.install(component);
 
-        Slider slider = (Slider) component;
+        Slider slider = (Slider)component;
         slider.add(thumb);
     }
 
     @Override
     public int getPreferredWidth(int height) {
-        Slider slider = (Slider) getComponent();
+        Slider slider = (Slider)getComponent();
 
         int preferredWidth;
         if (slider.getOrientation() == Orientation.HORIZONTAL) {
@@ -295,7 +297,7 @@
 
     @Override
     public int getPreferredHeight(int width) {
-        Slider slider = (Slider) getComponent();
+        Slider slider = (Slider)getComponent();
 
         int preferredHeight;
         if (slider.getOrientation() == Orientation.HORIZONTAL) {
@@ -314,7 +316,7 @@
 
     @Override
     public void layout() {
-        Slider slider = (Slider) getComponent();
+        Slider slider = (Slider)getComponent();
 
         int width = getWidth();
         int height = getHeight();
@@ -323,14 +325,14 @@
         int end = slider.getEnd();
         int value = slider.getValue();
 
-        float ratio = (float) (value - start) / (end - start);
+        float ratio = (float)(value - start) / (end - start);
 
         if (slider.getOrientation() == Orientation.HORIZONTAL) {
             thumb.setSize(thumbWidth, thumbHeight);
-            thumb.setLocation((int) ((width - thumbWidth) * ratio), (height - thumbHeight) / 2);
+            thumb.setLocation((int)((width - thumbWidth) * ratio), (height - thumbHeight) / 2);
         } else {
             thumb.setSize(thumbHeight, thumbWidth);
-            thumb.setLocation((width - thumbHeight) / 2, (int) ((height - thumbWidth) * ratio));
+            thumb.setLocation((width - thumbHeight) / 2, (int)((height - thumbWidth) * ratio));
         }
     }
 
@@ -341,7 +343,7 @@
     public void paint(Graphics2D graphics) {
         super.paint(graphics);
 
-        Slider slider = (Slider) getComponent();
+        Slider slider = (Slider)getComponent();
 
         int width = getWidth();
         int height = getHeight();

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraSplitPaneSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraSplitPaneSkin.java?rev=834880&r1=834879&r2=834880&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraSplitPaneSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraSplitPaneSkin.java Wed Nov 11 13:39:27 2009
@@ -487,7 +487,7 @@
     public void lockedChanged(SplitPane splitPane) {
         updateSplitterCursor();
     }
-    
+
     @Override
     public void resizeModeChanged(SplitPane splitPane, ResizeMode previousResizeMode) {
     }

Modified: incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/SplitPaneTest.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/SplitPaneTest.java?rev=834880&r1=834879&r2=834880&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/SplitPaneTest.java (original)
+++ incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/SplitPaneTest.java Wed Nov 11 13:39:27 2009
@@ -31,7 +31,7 @@
     public void startup(Display display, Map<String, String> properties) throws Exception {
         WTKXSerializer wtkxSerializer = new WTKXSerializer();
         window = new Window((Component)wtkxSerializer.readObject(getClass().getResource("splitpane_test.wtkx")));
-        
+
         window.setTitle("SplitPane Test");
         window.setMaximized(true);
         window.open(display);

Modified: incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/splitpane_test.wtkx
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/splitpane_test.wtkx?rev=834880&r1=834879&r2=834880&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/splitpane_test.wtkx (original)
+++ incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/splitpane_test.wtkx Wed Nov 11 13:39:27 2009
@@ -63,4 +63,3 @@
                 </bottom>
             </SplitPane>
 </BoxPane>
-            
\ No newline at end of file