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 20:33:13 UTC
svn commit: r1818209 - in /pivot/trunk:
tutorials/src/org/apache/pivot/tutorials/navigation/scroll_panes.bxml
wtk/src/org/apache/pivot/wtk/Borders.java
wtk/src/org/apache/pivot/wtk/skin/RulerSkin.java
Author: rwhitcomb
Date: Thu Dec 14 20:33:13 2017
New Revision: 1818209
URL: http://svn.apache.org/viewvc?rev=1818209&view=rev
Log:
PIVOT-1017: Enhancements to the "RulerSkin" (adding styles):
* The "flip" style to switch the edge from which the markers are drawn.
* The "markerInsets" style to offset the markers from the edge in certain
situations (such as when the scroll pane's view has insets).
* The "borders" style to specify which of the borders of the ruler should
be drawn.
Add a new "Borders" enum for this last purpose.
Enhance the navigation tutorial to use these new styles as a test.
Added:
pivot/trunk/wtk/src/org/apache/pivot/wtk/Borders.java
Modified:
pivot/trunk/tutorials/src/org/apache/pivot/tutorials/navigation/scroll_panes.bxml
pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/RulerSkin.java
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=1818209&r1=1818208&r2=1818209&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 20:33:13 2017
@@ -25,11 +25,11 @@ limitations under the License.
tooltipText="Pemaquid Point Lighthouse, Bristol ME"/>
<columnHeader>
- <Ruler orientation="horizontal" styles="{markerSpacing:8, backgroundColor:'LightSteelBlue'}"/>
+ <Ruler orientation="horizontal" styles="{markerSpacing:8, backgroundColor:'LightSteelBlue', flip:true, borders:'bottom'}"/>
</columnHeader>
<rowHeader>
- <Ruler orientation="vertical" styles="{markerSpacing:8, backgroundColor:'LightSteelBlue'}"/>
+ <Ruler orientation="vertical" styles="{markerSpacing:8, backgroundColor:'LightSteelBlue', flip:true, borders:'right'}"/>
</rowHeader>
</ScrollPane>
</Border>
Added: 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=1818209&view=auto
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/Borders.java (added)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/Borders.java Thu Dec 14 20:33:13 2017
@@ -0,0 +1,25 @@
+/*
+ * 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;
+
+/**
+ * Enumeration defining the possible border configurations for a Ruler.
+ */
+public enum Borders {
+ NONE, ALL, LEFT, RIGHT, TOP, BOTTOM,
+ LEFT_RIGHT, TOP_BOTTOM
+}
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=1818209&r1=1818208&r2=1818209&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 20:33:13 2017
@@ -20,9 +20,11 @@ import java.awt.Color;
import java.awt.Graphics2D;
import org.apache.pivot.util.Utils;
+import org.apache.pivot.wtk.Borders;
import org.apache.pivot.wtk.Component;
import org.apache.pivot.wtk.CSSColor;
import org.apache.pivot.wtk.GraphicsUtilities;
+import org.apache.pivot.wtk.Insets;
import org.apache.pivot.wtk.Orientation;
import org.apache.pivot.wtk.Ruler;
import org.apache.pivot.wtk.RulerListener;
@@ -32,6 +34,9 @@ public class RulerSkin extends Component
private Color color;
private Color backgroundColor;
private int markerSpacing;
+ private Insets markerInsets;
+ private boolean flip;
+ private Borders borders;
public RulerSkin() {
// For now the default colors are not from the Theme.
@@ -39,6 +44,9 @@ public class RulerSkin extends Component
setBackgroundColor(CSSColor.LightYellow.getColor());
markerSpacing = 5;
+ markerInsets = new Insets(0);
+ flip = false;
+ borders = Borders.ALL;
}
@Override
@@ -75,26 +83,66 @@ public class RulerSkin extends Component
int width = getWidth();
int height = getHeight();
+ int top = markerInsets.top;
+ int left = markerInsets.left;
+ int bottom = height - markerInsets.getHeight();
+ int right = width - markerInsets.getWidth();
+
Ruler ruler = (Ruler) getComponent();
graphics.setColor(backgroundColor);
graphics.fillRect(0, 0, width, height);
graphics.setColor(color);
- graphics.drawRect(0, 0, width - 1, height - 1);
+ 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;
+ }
+
+ height -= markerInsets.getHeight();
+ width -= markerInsets.getWidth();
Orientation orientation = ruler.getOrientation();
switch (orientation) {
case HORIZONTAL: {
+ int start = flip ? bottom - 1 : top;
+ int end2 = flip ? (bottom - 1 - height / 2) : height / 2;
+ int end3 = flip ? (bottom - 1 - height / 3) : height / 3;
+ int end4 = flip ? (bottom - 1 - height / 4) : height / 4;
+
for (int i = 0, n = width / markerSpacing + 1; i < n; i++) {
- int x = i * markerSpacing;
+ int x = i * markerSpacing + left;
+
if (i % 4 == 0) {
- graphics.drawLine(x, 0, x, height / 2);
+ graphics.drawLine(x, start, x, end2);
} else if (i % 2 == 0) {
- graphics.drawLine(x, 0, x, height / 3);
+ graphics.drawLine(x, start, x, end3);
} else {
- graphics.drawLine(x, 0, x, height / 4);
+ graphics.drawLine(x, start, x, end4);
}
}
@@ -102,15 +150,20 @@ public class RulerSkin extends Component
}
case VERTICAL: {
+ int start = flip ? right - 1 : left;
+ int end2 = flip ? (right - 1 - width / 2) : width / 2;
+ int end3 = flip ? (right - 1 - width / 3) : width / 3;
+ int end4 = flip ? (right - 1 - width / 4) : width / 4;
+
for (int i = 0, n = height / markerSpacing + 1; i < n; i++) {
- int y = i * markerSpacing;
+ int y = i * markerSpacing + top;
if (i % 4 == 0) {
- graphics.drawLine(0, y, width / 2, y);
+ graphics.drawLine(start, y, end2, y);
} else if (i % 2 == 0) {
- graphics.drawLine(0, y, width / 3, y);
+ graphics.drawLine(start, y, end3, y);
} else {
- graphics.drawLine(0, y, width / 4, y);
+ graphics.drawLine(start, y, end4, y);
}
}
@@ -146,6 +199,46 @@ public class RulerSkin extends Component
}
/**
+ * @return Whether the ruler is "flipped", that is the markers
+ * start from the inside rather than the outside.
+ */
+ public boolean getFlip() {
+ return flip;
+ }
+
+ public void setFlip(boolean flip) {
+ this.flip = flip;
+ }
+
+ /**
+ * @return The border configuration for this ruler.
+ */
+ public Borders getBorders() {
+ return borders;
+ }
+
+ public void setBorders(Borders borders) {
+ Utils.checkNull(borders, "borders");
+
+ this.borders = borders;
+ repaintComponent();
+ }
+
+ /**
+ * @return The insets for the markers (on each edge).
+ */
+ public Insets getMarkerInsets() {
+ return markerInsets;
+ }
+
+ public void setMarkerInsets(Insets insets) {
+ Utils.checkNull(insets, "markerInsets");
+
+ this.markerInsets = insets;
+ repaintComponent();
+ }
+
+ /**
* Returns the foreground color for the markers of the ruler.
*
* @return The foreground (marker) color.