Author: rwhitcomb
Date: Fri May  1 22:15:49 2020
New Revision: 1877271

URL: http://svn.apache.org/viewvc?rev=1877271&view=rev
Log:
PIVOT-871: Final touches on the NumberRuler: add a style to show (or not)
the number at the zero position.

Enable this style on the ComponentExplorer source window.

Minor tweak: use a const style string for italic font in the inspector window.


Modified:
    
pivot/trunk/tutorials/src/org/apache/pivot/tutorials/explorer/component_explorer_window.bxml
    
pivot/trunk/tutorials/src/org/apache/pivot/tutorials/explorer/tools/ComponentInspectorSkin.java
    pivot/trunk/wtk/src/org/apache/pivot/wtk/NumberRuler.java
    pivot/trunk/wtk/src/org/apache/pivot/wtk/NumberRulerListener.java
    pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/NumberRulerSkin.java

Modified: 
pivot/trunk/tutorials/src/org/apache/pivot/tutorials/explorer/component_explorer_window.bxml
URL: 
http://svn.apache.org/viewvc/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/explorer/component_explorer_window.bxml?rev=1877271&r1=1877270&r2=1877271&view=diff
==============================================================================
--- 
pivot/trunk/tutorials/src/org/apache/pivot/tutorials/explorer/component_explorer_window.bxml
 (original)
+++ 
pivot/trunk/tutorials/src/org/apache/pivot/tutorials/explorer/component_explorer_window.bxml
 Fri May  1 22:15:49 2020
@@ -390,7 +390,7 @@ limitations under the License.
                                                 editable="false"
                                                 styles="{wrapText:false, 
font:'Courier 10'}"/>
                                             <columnHeader>
-                                                <NumberRuler 
orientation="horizontal" styles="{color:6,backgroundColor:5,font:'Courier 
10',markerSpacing:6,showMinorNumbers:true,markerInsets:{top:0,bottom:0,left:4,right:4}}"/>
+                                                <NumberRuler 
orientation="horizontal" styles="{color:6,backgroundColor:5,font:'Courier 
10',markerSpacing:6,showZeroNumber:true,showMinorNumbers:true,markerInsets:{top:0,bottom:0,left:4,right:4}}"/>
                                             </columnHeader>
                                             <rowHeader>
                                                 <NumberRuler 
orientation="vertical" styles="{color:6, backgroundColor:5,font:'Courier 
10',markerInsets:{top:3,bottom:3,left:0,right:0}}"/>

Modified: 
pivot/trunk/tutorials/src/org/apache/pivot/tutorials/explorer/tools/ComponentInspectorSkin.java
URL: 
http://svn.apache.org/viewvc/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/explorer/tools/ComponentInspectorSkin.java?rev=1877271&r1=1877270&r2=1877271&view=diff
==============================================================================
--- 
pivot/trunk/tutorials/src/org/apache/pivot/tutorials/explorer/tools/ComponentInspectorSkin.java
 (original)
+++ 
pivot/trunk/tutorials/src/org/apache/pivot/tutorials/explorer/tools/ComponentInspectorSkin.java
 Fri May  1 22:15:49 2020
@@ -63,6 +63,8 @@ abstract class ComponentInspectorSkin ex
     // Maps key to corresponding control component
     private HashMap<String, Component> controls = new HashMap<>();
 
+    private static final String ITALIC_STYLE = "{italic:true}";
+
     @Override
     public void install(Component component) {
         super.install(component);
@@ -507,7 +509,7 @@ abstract class ComponentInspectorSkin ex
         });
 
         Label label = new Label("x");
-        label.getStyles().put(Style.font, "{italic:true}");
+        label.getStyles().put(Style.font, ITALIC_STYLE);
         flowPane.add(label);
 
         flowPane = new FlowPane();
@@ -541,7 +543,7 @@ abstract class ComponentInspectorSkin ex
         });
 
         label = new Label("y");
-        label.getStyles().put(Style.font, "{italic:true}");
+        label.getStyles().put(Style.font, ITALIC_STYLE);
         flowPane.add(label);
 
         return boxPane;
@@ -600,7 +602,7 @@ abstract class ComponentInspectorSkin ex
         });
 
         Label label = new Label("width");
-        label.getStyles().put(Style.font, "{italic:true}");
+        label.getStyles().put(Style.font, ITALIC_STYLE);
         flowPane.add(label);
 
         flowPane = new FlowPane();
@@ -634,7 +636,7 @@ abstract class ComponentInspectorSkin ex
         });
 
         label = new Label("height");
-        label.getStyles().put(Style.font, "{italic:true}");
+        label.getStyles().put(Style.font, ITALIC_STYLE);
         flowPane.add(label);
 
         return boxPane;
@@ -693,7 +695,7 @@ abstract class ComponentInspectorSkin ex
         });
 
         Label label = new Label("min");
-        label.getStyles().put(Style.font, "{italic:true}");
+        label.getStyles().put(Style.font, ITALIC_STYLE);
         flowPane.add(label);
 
         flowPane = new FlowPane();
@@ -727,7 +729,7 @@ abstract class ComponentInspectorSkin ex
         });
 
         label = new Label("max");
-        label.getStyles().put(Style.font, "{italic:true}");
+        label.getStyles().put(Style.font, ITALIC_STYLE);
         flowPane.add(label);
 
         return boxPane;
@@ -787,7 +789,7 @@ abstract class ComponentInspectorSkin ex
         });
 
         Label label = new Label("top");
-        label.getStyles().put(Style.font, "{italic:true}");
+        label.getStyles().put(Style.font, ITALIC_STYLE);
         flowPane.add(label);
 
         flowPane = new FlowPane();
@@ -822,7 +824,7 @@ abstract class ComponentInspectorSkin ex
         });
 
         label = new Label("left");
-        label.getStyles().put(Style.font, "{italic:true}");
+        label.getStyles().put(Style.font, ITALIC_STYLE);
         flowPane.add(label);
 
         flowPane = new FlowPane();
@@ -857,7 +859,7 @@ abstract class ComponentInspectorSkin ex
         });
 
         label = new Label("bottom");
-        label.getStyles().put(Style.font, "{italic:true}");
+        label.getStyles().put(Style.font, ITALIC_STYLE);
         flowPane.add(label);
 
         flowPane = new FlowPane();
@@ -892,7 +894,7 @@ abstract class ComponentInspectorSkin ex
         });
 
         label = new Label("right");
-        label.getStyles().put(Style.font, "{italic:true}");
+        label.getStyles().put(Style.font, ITALIC_STYLE);
         flowPane.add(label);
 
         return boxPane;
@@ -939,7 +941,7 @@ abstract class ComponentInspectorSkin ex
         });
 
         Label label = new Label("start");
-        label.getStyles().put(Style.font, "{italic:true}");
+        label.getStyles().put(Style.font, ITALIC_STYLE);
         flowPane.add(label);
 
         flowPane = new FlowPane();
@@ -975,7 +977,7 @@ abstract class ComponentInspectorSkin ex
         });
 
         label = new Label("end");
-        label.getStyles().put(Style.font, "{italic:true}");
+        label.getStyles().put(Style.font, ITALIC_STYLE);
         flowPane.add(label);
 
         return boxPane;
@@ -1035,7 +1037,7 @@ abstract class ComponentInspectorSkin ex
         });
 
         Label label = new Label("topLeft");
-        label.getStyles().put(Style.font, "{italic:true}");
+        label.getStyles().put(Style.font, ITALIC_STYLE);
         flowPane.add(label);
 
         flowPane = new FlowPane();
@@ -1070,7 +1072,7 @@ abstract class ComponentInspectorSkin ex
         });
 
         label = new Label("topRight");
-        label.getStyles().put(Style.font, "{italic:true}");
+        label.getStyles().put(Style.font, ITALIC_STYLE);
         flowPane.add(label);
 
         flowPane = new FlowPane();
@@ -1105,7 +1107,7 @@ abstract class ComponentInspectorSkin ex
         });
 
         label = new Label("bottomLeft");
-        label.getStyles().put(Style.font, "{italic:true}");
+        label.getStyles().put(Style.font, ITALIC_STYLE);
         flowPane.add(label);
 
         flowPane = new FlowPane();
@@ -1140,7 +1142,7 @@ abstract class ComponentInspectorSkin ex
         });
 
         label = new Label("bottomRight");
-        label.getStyles().put(Style.font, "{italic:true}");
+        label.getStyles().put(Style.font, ITALIC_STYLE);
         flowPane.add(label);
 
         return boxPane;
@@ -1187,7 +1189,7 @@ abstract class ComponentInspectorSkin ex
         });
 
         Label label = new Label("start");
-        label.getStyles().put(Style.font, "{italic:true}");
+        label.getStyles().put(Style.font, ITALIC_STYLE);
         flowPane.add(label);
 
         flowPane = new FlowPane();
@@ -1223,7 +1225,7 @@ abstract class ComponentInspectorSkin ex
         });
 
         label = new Label("end");
-        label.getStyles().put(Style.font, "{italic:true}");
+        label.getStyles().put(Style.font, ITALIC_STYLE);
         flowPane.add(label);
 
         flowPane = new FlowPane();
@@ -1260,7 +1262,7 @@ abstract class ComponentInspectorSkin ex
         });
 
         label = new Label("extent");
-        label.getStyles().put(Style.font, "{italic:true}");
+        label.getStyles().put(Style.font, ITALIC_STYLE);
         flowPane.add(label);
 
         return boxPane;

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/NumberRuler.java
URL: 
http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/NumberRuler.java?rev=1877271&r1=1877270&r2=1877271&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/NumberRuler.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/NumberRuler.java Fri May  1 
22:15:49 2020
@@ -25,9 +25,26 @@ import org.apache.pivot.util.Utils;
  * ({@link TextArea} or {@link TextPane}).
  */
 public class NumberRuler extends Component {
+    /** Maximum allowed number of digits to display (arbitrary). */
+    private static final int MAX_TEXT_SIZE = 20;
+
+    /** Default number of digits to display for numbers in vertical rulers. */
+    private static final int DEFAULT_TEXT_SIZE = 5;
+
+    /** Default orientation for one of these (most commonly used for line 
numbering). */
     private Orientation orientation = Orientation.VERTICAL;
-    /** Maximum number of digits expected in the numbering. */
-    private int textSize = 5;
+
+    /**
+     * The expected number of digits to allow for in vertical rulers.
+     * <p> Since we don't know apriori how many rows/lines will be
+     * shown in a vertical ruler, we rely on the user/caller to tell
+     * us how much space to allow for the numbers.
+     * <p> Note: there is probably a better way to figure this out,
+     * but it would require, in general, expensive re-layout as
+     * more and more rows are added, and then what to do if rows
+     * get taken away?
+     */
+    private int textSize = DEFAULT_TEXT_SIZE;
 
     private NumberRulerListener.Listeners rulerListeners = new 
NumberRulerListener.Listeners();
 
@@ -39,7 +56,7 @@ public class NumberRuler extends Compone
         return orientation;
     }
 
-    public void setOrientation(Orientation orientation) {
+    public void setOrientation(final Orientation orientation) {
         Utils.checkNull(orientation, "orientation");
 
         if (this.orientation != orientation) {
@@ -48,21 +65,47 @@ public class NumberRuler extends Compone
         }
     }
 
+    /**
+     * @return The number of digits of space to allow for the
+     * numbers in a vertical ruler.
+     */
     public int getTextSize() {
         return textSize;
     }
 
-    public void setTextSize(String size) {
+    /**
+     * Set the number of digits of space to allow for the numbers.
+     *
+     * @param size The (integer) number of digits to allow in vertical
+     * ruler numbers. The default of {@link #DEFAULT_TEXT_SIZE} allows
+     * for 99,999 maximum rows.
+     * @throws IllegalArgumentException if the value is negative,
+     * or exceeds {@link #MAX_TEXT_SIZE}.
+     */
+    public void setTextSize(final String size) {
         Utils.checkNullOrEmpty(size, "size");
 
-        int newSize = Integer.parseInt(size);
-        if (newSize <= 0 || newSize > 20) {
-            throw new IllegalArgumentException("Text size must be positive and 
less or equal to 20.");
+        setTextSize(Integer.parseInt(size));
+    }
+
+    /**
+     * Set the number of digits of space to allow for the numbers.
+     *
+     * @param size The number of digits to allow in vertical ruler numbers.
+     * The default of {@link #DEFAULT_TEXT_SIZE} allows
+     * for 99,999 maximum rows.
+     * @throws IllegalArgumentException if the value is negative,
+     * or exceeds {@link #MAX_TEXT_SIZE}.
+     */
+    public void setTextSize(final int size) {
+        if (size <= 0 || size > MAX_TEXT_SIZE) {
+            throw new IllegalArgumentException(
+                "Text size must be positive and less or equal to " + 
MAX_TEXT_SIZE + ".");
         }
 
-        if (newSize != textSize) {
+        if (size != textSize) {
             int previousSize = this.textSize;
-            this.textSize = newSize;
+            this.textSize = size;
             rulerListeners.textSizeChanged(this, previousSize);
         }
     }

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/NumberRulerListener.java
URL: 
http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/NumberRulerListener.java?rev=1877271&r1=1877270&r2=1877271&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/NumberRulerListener.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/NumberRulerListener.java Fri May  
1 22:15:49 2020
@@ -29,12 +29,12 @@ public interface NumberRulerListener {
     @Deprecated
     public static class Adapter implements NumberRulerListener {
         @Override
-        public void orientationChanged(NumberRuler ruler) {
+        public void orientationChanged(final NumberRuler ruler) {
             // Empty block
         }
 
         @Override
-        public void textSizeChanged(NumberRuler ruler, int previousSize) {
+        public void textSizeChanged(final NumberRuler ruler, final int 
previousSize) {
             // Empty block
         }
     }
@@ -45,11 +45,11 @@ public interface NumberRulerListener {
     public static class Listeners extends ListenerList<NumberRulerListener>
         implements NumberRulerListener {
         @Override
-        public void orientationChanged(NumberRuler ruler) {
+        public void orientationChanged(final NumberRuler ruler) {
             forEach(listener -> listener.orientationChanged(ruler));
         }
         @Override
-        public void textSizeChanged(NumberRuler ruler, int previousSize) {
+        public void textSizeChanged(final NumberRuler ruler, final int 
previousSize) {
             forEach(listener -> listener.textSizeChanged(ruler, previousSize));
         }
     }

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/NumberRulerSkin.java
URL: 
http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/NumberRulerSkin.java?rev=1877271&r1=1877270&r2=1877271&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/NumberRulerSkin.java 
(original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/NumberRulerSkin.java Fri May  
1 22:15:49 2020
@@ -44,8 +44,11 @@ import org.apache.pivot.wtk.Theme;
  * vertical header for viewports.
  */
 public class NumberRulerSkin extends ComponentSkin implements 
NumberRulerListener {
+    /** Number of pixels to use for major division tic marks. */
     private static final int MAJOR_SIZE = 10;
+    /** Number of pixels to use for minor division tic marks. */
     private static final int MINOR_SIZE = 8;
+    /** Number of pixels to use for regular tic marks. */
     private static final int REGULAR_SIZE = 5;
 
     private Font font;
@@ -57,6 +60,7 @@ public class NumberRulerSkin extends Com
     private Insets rowPadding;
     private int majorDivision;
     private int minorDivision;
+    private boolean showZeroNumber;
     private boolean showMajorNumbers;
     private boolean showMinorNumbers;
     private float charHeight, descent;
@@ -81,6 +85,7 @@ public class NumberRulerSkin extends Com
         majorDivision = 10;
         minorDivision = 5;
         // But these are
+        showZeroNumber = false;
         showMajorNumbers = true;
         showMinorNumbers = false;
 
@@ -100,7 +105,7 @@ public class NumberRulerSkin extends Com
 
         // Give a little extra height if showing numbers
         return (orientation == Orientation.HORIZONTAL)
-            ? ((showMajorNumbers || showMinorNumbers)
+            ? ((showZeroNumber || showMajorNumbers || showMinorNumbers)
                 ? ((int) Math.ceil(charHeight) + MAJOR_SIZE + 5) : MAJOR_SIZE 
* 2) : 0;
     }
 
@@ -187,13 +192,12 @@ public class NumberRulerSkin extends Com
 
                     if (majorDivision != 0 && i % majorDivision == 0) {
                         graphics.drawLine(x, start, x, end2);
-                        // Don't show any numbers at 0 -- make a style for 
this?
-                        if (showMajorNumbers && i > 0) {
+                        if ((showZeroNumber && i == 0) || (showMajorNumbers && 
i > 0)) {
                             showNumber(graphics, fontRenderContext, i, x, 
end2);
                         }
                     } else if (minorDivision != 0 && i % minorDivision == 0) {
                         graphics.drawLine(x, start, x, end3);
-                        if (showMinorNumbers && i > 0) {
+                        if ((showZeroNumber && i == 0) || (showMinorNumbers && 
i > 0)) {
                             // Show the minor numbers at the same y point as 
the major
                             showNumber(graphics, fontRenderContext, i, x, 
end2);
                         }
@@ -334,6 +338,12 @@ public class NumberRulerSkin extends Com
         invalidateComponent();
     }
 
+    /**
+     * Set the number of pixels interval at which to draw the markers
+     * (for horizontal orientation only).
+     *
+     * @param spacing The integer number of pixels between markers (must be 
&gt;= 1).
+     */
     public final void setMarkerSpacing(final Number spacing) {
         Utils.checkNull(spacing, "markerSpacing");
 
@@ -341,6 +351,29 @@ public class NumberRulerSkin extends Com
     }
 
     /**
+     * @return Whether to display a number at the zero point
+     * (only applicable for horizontal orientation).
+     */
+    public boolean getShowZeroNumber() {
+        return showZeroNumber;
+    }
+
+    /**
+     * Sets the flag to say whether to show a number at the zero point
+     * (only for horizontal orientation).
+     *
+     * @param showZeroNumber Whether a number should be shown for the zero 
point.
+     */
+    public final void setShowZeroNumber(final boolean showZeroNumber) {
+        this.showZeroNumber = showZeroNumber;
+
+        NumberRuler ruler = (NumberRuler) getComponent();
+        if (ruler.getOrientation() == Orientation.HORIZONTAL) {
+            invalidateComponent();
+        }
+    }
+
+    /**
      * @return Whether to display numbers at each major division
      * (only applicable for horizontal orientation).
      */
@@ -386,6 +419,9 @@ public class NumberRulerSkin extends Com
         }
     }
 
+    /**
+     * @return The font used to render the Ruler's text.
+     */
     public Font getFont() {
         return font;
     }
@@ -460,6 +496,12 @@ public class NumberRulerSkin extends Com
         setColor(GraphicsUtilities.decodeColor(color, "color"));
     }
 
+    /**
+     * Sets the foreground color of the text of the ruler to one of the
+     * theme colors.
+     *
+     * @param color Index of the theme color to use.
+     */
     public final void setColor(final int color) {
         Theme theme = currentTheme();
         setColor(theme.getColor(color));
@@ -494,6 +536,11 @@ public class NumberRulerSkin extends Com
         setBackgroundColor(GraphicsUtilities.decodeColor(backgroundColor, 
"backgroundColor"));
     }
 
+    /**
+     * Sets the background color of the ruler to one of the theme colors.
+     *
+     * @param backgroundColor Index of the theme color to use for the 
background.
+     */
     public final void setBackgroundColor(final int backgroundColor) {
         Theme theme = currentTheme();
         setBackgroundColor(theme.getColor(backgroundColor));


Reply via email to