You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by no...@apache.org on 2010/07/29 15:10:10 UTC

svn commit: r980435 - in /pivot/trunk: tests/src/org/apache/pivot/tests/slider_test.bxml wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraSliderSkin.java

Author: noelgrandin
Date: Thu Jul 29 13:10:10 2010
New Revision: 980435

URL: http://svn.apache.org/viewvc?rev=980435&view=rev
Log:
PIVOT-28 Add tick marks to Slider component
added style tickSpacing to Slider skin

Modified:
    pivot/trunk/tests/src/org/apache/pivot/tests/slider_test.bxml
    pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraSliderSkin.java

Modified: pivot/trunk/tests/src/org/apache/pivot/tests/slider_test.bxml
URL: http://svn.apache.org/viewvc/pivot/trunk/tests/src/org/apache/pivot/tests/slider_test.bxml?rev=980435&r1=980434&r2=980435&view=diff
==============================================================================
--- pivot/trunk/tests/src/org/apache/pivot/tests/slider_test.bxml (original)
+++ pivot/trunk/tests/src/org/apache/pivot/tests/slider_test.bxml Thu Jul 29 13:10:10 2010
@@ -18,8 +18,8 @@ limitations under the License.
 
 <BoxPane xmlns:bxml="http://pivot.apache.org/bxml"
     xmlns="org.apache.pivot.wtk">
-    <Slider bxml:id="slider1" range="{start:-100, end:100}" value="0"/>
+    <Slider bxml:id="slider1" range="{start:-100, end:100}" value="0" styles="{ tickSpacing:10}"/>
     <Label bxml:id="valueLabel1" text="0"/>
-    <Slider bxml:id="slider2" range="{start:-100, end:100}" value="0" orientation="vertical"/>
+    <Slider bxml:id="slider2" range="{start:-100, end:100}" value="0" orientation="vertical" styles="{ tickSpacing:10}"/>
     <Label bxml:id="valueLabel2" text="0"/>
 </BoxPane>

Modified: pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraSliderSkin.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraSliderSkin.java?rev=980435&r1=980434&r2=980435&view=diff
==============================================================================
--- pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraSliderSkin.java (original)
+++ pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraSliderSkin.java Thu Jul 29 13:10:10 2010
@@ -251,6 +251,7 @@ public class TerraSliderSkin extends Sli
     private Color buttonBorderColor;
     private int thumbWidth;
     private int thumbHeight;
+    private Integer tickSpacing;
 
     // Derived colors
     private Color buttonBevelColor;
@@ -354,8 +355,30 @@ public class TerraSliderSkin extends Sli
             RenderingHints.VALUE_ANTIALIAS_ON);
         if (slider.getOrientation() == Orientation.HORIZONTAL) {
             graphics.fillRect(0, (height - trackWidth) / 2, width, trackWidth);
+            if (tickSpacing != null) {
+                int start = slider.getStart();
+                int end = slider.getEnd();
+                int value = start;
+                while (value <= end) {
+                    float ratio = (float)(value - start) / (end - start);
+                    int x = (int) (width * ratio);
+                    graphics.drawLine(x, height / 3, x, height * 2 / 3);
+                    value += tickSpacing;
+                }
+            }
         } else {
             graphics.fillRect((width - trackWidth) / 2, 0, trackWidth, height);
+            if (tickSpacing != null) {
+                int start = slider.getStart();
+                int end = slider.getEnd();
+                int value = start;
+                while (value <= end) {
+                    float ratio = (float)(value - start) / (end - start);
+                    int y = (int) (height * ratio);
+                    graphics.drawLine(width / 3, y, width * 2 / 3, y);
+                    value += tickSpacing;
+                }
+            }
         }
 
         if (thumb.isFocused()) {
@@ -497,6 +520,19 @@ public class TerraSliderSkin extends Sli
         setThumbHeight(thumbHeight.intValue());
     }
 
+    public Integer getTickSpacing() {
+        return tickSpacing;
+    }
+
+    public void setTickSpacing(Integer tickSpacing) {
+        this.tickSpacing = tickSpacing;
+        repaintComponent();
+    }
+    
+    public void setTickSpacing(Number tickSpacing) {
+        setTickSpacing(tickSpacing == null ? null : tickSpacing.intValue());
+    }
+    
     @Override
     public boolean mouseClick(Component component, Mouse.Button button, int x, int y, int count) {
         thumb.requestFocus();