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 23:09:02 UTC

svn commit: r1818221 - in /pivot/trunk/wtk/src/org/apache/pivot/wtk: Borders.java GraphicsUtilities.java skin/RulerSkin.java

Author: rwhitcomb
Date: Thu Dec 14 23:09:02 2017
New Revision: 1818221

URL: http://svn.apache.org/viewvc?rev=1818221&view=rev
Log:
PIVOT-1017:  Enhance the border drawing for RulerSkin:
* Add the remaining choices to Borders for all the two and three border cases.
* Move the border drawing into GraphicsUtilities.drawBorders and out of RulerSkin.

Modified:
    pivot/trunk/wtk/src/org/apache/pivot/wtk/Borders.java
    pivot/trunk/wtk/src/org/apache/pivot/wtk/GraphicsUtilities.java
    pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/RulerSkin.java

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/Borders.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/Borders.java?rev=1818221&r1=1818220&r2=1818221&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/Borders.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/Borders.java Thu Dec 14 23:09:02 2017
@@ -20,6 +20,36 @@ package org.apache.pivot.wtk;
  * Enumeration defining the possible border configurations for a Ruler.
  */
 public enum Borders {
-    NONE, ALL, LEFT, RIGHT, TOP, BOTTOM,
-    LEFT_RIGHT, TOP_BOTTOM
+    /** No borders at all. */
+    NONE,
+    /** All four borders. */
+    ALL,
+    /** Only the left side. */
+    LEFT,
+    /** Only the right side. */
+    RIGHT,
+    /** Only the top. */
+    TOP,
+    /** Only the bottom. */
+    BOTTOM,
+    /** Both the left and right sides. */
+    LEFT_RIGHT,
+    /** Both the top and bottom. */
+    TOP_BOTTOM,
+    /** The left side and the top. */
+    LEFT_TOP,
+    /** The left side and the bottom. */
+    LEFT_BOTTOM,
+    /** The right side and the top. */
+    RIGHT_TOP,
+    /** The right side and the bottom. */
+    RIGHT_BOTTOM,
+    /** All sides except the right side. */
+    NOT_RIGHT,
+    /** All sides except the bottom. */
+    NOT_BOTTOM,
+    /** All sides except the left side. */
+    NOT_LEFT,
+    /** All sides except the top. */
+    NOT_TOP
 }

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/GraphicsUtilities.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/GraphicsUtilities.java?rev=1818221&r1=1818220&r2=1818221&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/GraphicsUtilities.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/GraphicsUtilities.java Thu Dec 14 23:09:02 2017
@@ -517,5 +517,88 @@ public final class GraphicsUtilities {
         return caretRect;
     }
 
+    /**
+     * Draw borders around a rectangular area.
+     *
+     * @param graphics The graphics area to draw in.
+     * @param borders The borders specification.
+     * @param top The top coordinate (typically 0)
+     * @param left The left coordinate (typically 0)
+     * @param bottom The bottom interior coordinate (height - 1)
+     * @param right The right interior coordinate (width - 1)
+     */
+    public static void drawBorders(Graphics2D graphics, Borders borders, int top, int left, int bottom, int right) {
+        // The single line/object cases, or the first of the multiple line cases
+        switch (borders) {
+            case NONE:
+                break;
+            case ALL:
+                graphics.drawRect(left, top, right, bottom);
+                break;
+            case TOP:
+            case TOP_BOTTOM:
+                // The top here
+                graphics.drawLine(left, top, right, top);
+                break;
+            case BOTTOM:
+                // The bottom here
+                graphics.drawLine(left, bottom, right, bottom);
+                break;
+            case LEFT:
+            case LEFT_RIGHT:
+            case LEFT_TOP:
+            case LEFT_BOTTOM:
+            case NOT_RIGHT:
+            case NOT_BOTTOM:
+            case NOT_TOP:
+                // The left here
+                graphics.drawLine(0, 0, 0, bottom);
+                break;
+            case RIGHT:
+            case RIGHT_TOP:
+            case RIGHT_BOTTOM:
+            case NOT_LEFT:
+                // The right here
+                graphics.drawLine(right, 0, right, bottom);
+                break;
+        }
+
+        // The second of the double/triple line cases
+        switch (borders) {
+            case LEFT_RIGHT:
+            case NOT_BOTTOM:
+            case NOT_TOP:
+                // The right side now
+                graphics.drawLine(right, top, right, bottom);
+                break;
+            case TOP_BOTTOM:
+            case LEFT_BOTTOM:
+            case RIGHT_BOTTOM:
+            case NOT_LEFT:
+                // The bottom now
+                graphics.drawLine(left, bottom, right, bottom);
+                break;
+            case LEFT_TOP:
+            case RIGHT_TOP:
+            case NOT_RIGHT:
+                // The top now
+                graphics.drawLine(left, top, right, top);
+                break;
+        }
+
+        // Now the third of the triple line cases
+        switch (borders) {
+            case NOT_RIGHT:
+            case NOT_TOP:
+                // The bottom now
+                graphics.drawLine(left, bottom, right, bottom);
+                break;
+            case NOT_LEFT:
+            case NOT_BOTTOM:
+                // The top now
+                graphics.drawLine(left, top, right, top);
+                break;
+        }
+    }
 }
 

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/RulerSkin.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/RulerSkin.java?rev=1818221&r1=1818220&r2=1818221&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/RulerSkin.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/RulerSkin.java Thu Dec 14 23:09:02 2017
@@ -98,33 +98,7 @@ public class RulerSkin extends Component
         graphics.fillRect(0, 0, width, height);
 
         graphics.setColor(color);
-        switch (borders) {
-            case NONE:
-                break;
-            case ALL:
-                graphics.drawRect(0, 0, width - 1, height - 1);
-                break;
-            case TOP:
-                graphics.drawLine(0, 0, width - 1, 0);
-                break;
-            case BOTTOM:
-                graphics.drawLine(0, height - 1, width - 1, height - 1);
-                break;
-            case LEFT:
-                graphics.drawLine(0, 0, 0, height - 1);
-                break;
-            case RIGHT:
-                graphics.drawLine(width - 1, 0, width - 1, height - 1);
-                break;
-            case LEFT_RIGHT:
-                graphics.drawLine(0, 0, 0, height - 1);
-                graphics.drawLine(width - 1, 0, width - 1, height - 1);
-                break;
-            case TOP_BOTTOM:
-                graphics.drawLine(0, 0, width - 1, 0);
-                graphics.drawLine(0, height - 1, width - 1, height - 1);
-                break;
-        }
+        GraphicsUtilities.drawBorders(graphics, borders, 0, 0, height - 1, width - 1);
 
         height -= markerInsets.getHeight();
         width -= markerInsets.getWidth();