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 17:43:41 UTC
svn commit: r1818171 - in /pivot/trunk:
tutorials/src/org/apache/pivot/tutorials/navigation/
wtk/src/org/apache/pivot/wtk/ wtk/src/org/apache/pivot/wtk/skin/
Author: rwhitcomb
Date: Thu Dec 14 17:43:41 2017
New Revision: 1818171
URL: http://svn.apache.org/viewvc?rev=1818171&view=rev
Log:
PIVOT-1017: Do the recent updates to the newly-minted "Ruler" class:
* Move RulerSkin into the proper package (org.apache.pivot.wtk.skin).
* Move the RulerListerList into the RulerListener interface and rename
to "RulerListener.Listeners".
* Make the color and background color of the RulerSkin into properties,
and set to the defaults in the constructor now.
* Make the spacing for the markers into a style for the skin also.
* Update the navigation tutorial ("scroll_panes") to test these new
styles for the ruler.
* Install the skin from the Theme class.
* Make the Ruler set a default orientation.
Added:
pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/RulerSkin.java
- copied, changed from r1818170, pivot/trunk/wtk/src/org/apache/pivot/wtk/RulerSkin.java
Removed:
pivot/trunk/wtk/src/org/apache/pivot/wtk/RulerSkin.java
Modified:
pivot/trunk/tutorials/src/org/apache/pivot/tutorials/navigation/scroll_panes.bxml
pivot/trunk/wtk/src/org/apache/pivot/wtk/Ruler.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/RulerListener.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/Theme.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=1818171&r1=1818170&r2=1818171&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 17:43:41 2017
@@ -25,11 +25,11 @@ limitations under the License.
tooltipText="Pemaquid Point Lighthouse, Bristol ME"/>
<columnHeader>
- <Ruler orientation="horizontal"/>
+ <Ruler orientation="horizontal" styles="{markerSpacing:8, backgroundColor:'LightSteelBlue'}"/>
</columnHeader>
<rowHeader>
- <Ruler orientation="vertical"/>
+ <Ruler orientation="vertical" styles="{markerSpacing:8, backgroundColor:'LightSteelBlue'}"/>
</rowHeader>
</ScrollPane>
</Border>
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/Ruler.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/Ruler.java?rev=1818171&r1=1818170&r2=1818171&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/Ruler.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/Ruler.java Thu Dec 14 17:43:41 2017
@@ -26,20 +26,18 @@ import org.apache.pivot.wtk.Orientation;
*/
public class Ruler extends Component {
- private static class RulerListenerList extends ListenerList<RulerListener> implements
- RulerListener {
- @Override
- public void orientationChanged(Ruler ruler) {
- forEach(listener -> listener.orientationChanged(ruler));
- }
- }
-
private Orientation orientation;
- private RulerListenerList rulerListeners = new RulerListenerList();
+ private RulerListener.Listeners rulerListeners = new RulerListener.Listeners();
public Ruler() {
- setSkin(new RulerSkin());
+ this(Orientation.HORIZONTAL);
+ }
+
+ public Ruler(Orientation orientation) {
+ setOrientation(orientation);
+
+ installSkin(Ruler.class);
}
public Orientation getOrientation() {
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/RulerListener.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/RulerListener.java?rev=1818171&r1=1818170&r2=1818171&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/RulerListener.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/RulerListener.java Thu Dec 14 17:43:41 2017
@@ -16,6 +16,17 @@
*/
package org.apache.pivot.wtk;
+import org.apache.pivot.util.ListenerList;
+
+
public interface RulerListener {
+ public static class Listeners extends ListenerList<RulerListener> implements
+ RulerListener {
+ @Override
+ public void orientationChanged(Ruler ruler) {
+ forEach(listener -> listener.orientationChanged(ruler));
+ }
+ }
+
public void orientationChanged(Ruler ruler);
}
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/Theme.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/Theme.java?rev=1818171&r1=1818170&r2=1818171&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/Theme.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/Theme.java Thu Dec 14 17:43:41 2017
@@ -36,6 +36,7 @@ import org.apache.pivot.wtk.skin.ImageVi
import org.apache.pivot.wtk.skin.LabelSkin;
import org.apache.pivot.wtk.skin.MovieViewSkin;
import org.apache.pivot.wtk.skin.PanelSkin;
+import org.apache.pivot.wtk.skin.RulerSkin;
import org.apache.pivot.wtk.skin.ScrollPaneSkin;
import org.apache.pivot.wtk.skin.SeparatorSkin;
import org.apache.pivot.wtk.skin.StackPaneSkin;
@@ -92,6 +93,7 @@ public abstract class Theme {
componentSkinMap.put(Label.class, LabelSkin.class);
componentSkinMap.put(MovieView.class, MovieViewSkin.class);
componentSkinMap.put(Panel.class, PanelSkin.class);
+ componentSkinMap.put(Ruler.class, RulerSkin.class);
componentSkinMap.put(ScrollPane.class, ScrollPaneSkin.class);
componentSkinMap.put(Separator.class, SeparatorSkin.class);
componentSkinMap.put(StackPane.class, StackPaneSkin.class);
Copied: pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/RulerSkin.java (from r1818170, pivot/trunk/wtk/src/org/apache/pivot/wtk/RulerSkin.java)
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/RulerSkin.java?p2=pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/RulerSkin.java&p1=pivot/trunk/wtk/src/org/apache/pivot/wtk/RulerSkin.java&r1=1818170&r2=1818171&rev=1818171&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/RulerSkin.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/RulerSkin.java Thu Dec 14 17:43:41 2017
@@ -14,16 +14,33 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.pivot.wtk;
+package org.apache.pivot.wtk.skin;
import java.awt.Color;
import java.awt.Graphics2D;
+import org.apache.pivot.util.Utils;
import org.apache.pivot.wtk.Component;
+import org.apache.pivot.wtk.CSSColor;
+import org.apache.pivot.wtk.GraphicsUtilities;
import org.apache.pivot.wtk.Orientation;
-import org.apache.pivot.wtk.skin.ComponentSkin;
+import org.apache.pivot.wtk.Ruler;
+import org.apache.pivot.wtk.RulerListener;
+import org.apache.pivot.wtk.Theme;
+
+public class RulerSkin extends ComponentSkin implements RulerListener {
+ private Color color;
+ private Color backgroundColor;
+ private int markerSpacing;
+
+ public RulerSkin() {
+ // For now the default colors are not from the Theme.
+ setColor(Color.BLACK);
+ setBackgroundColor(CSSColor.LightYellow.getColor());
+
+ markerSpacing = 5;
+ }
-class RulerSkin extends ComponentSkin implements RulerListener {
@Override
public void install(Component component) {
super.install(component);
@@ -60,17 +77,17 @@ class RulerSkin extends ComponentSkin im
Ruler ruler = (Ruler) getComponent();
- graphics.setColor(CSSColor.LightYellow.getColor());
+ graphics.setColor(backgroundColor);
graphics.fillRect(0, 0, width, height);
- graphics.setColor(Color.BLACK);
+ graphics.setColor(color);
graphics.drawRect(0, 0, width - 1, height - 1);
Orientation orientation = ruler.getOrientation();
switch (orientation) {
case HORIZONTAL: {
- for (int i = 0, n = width / 5 + 1; i < n; i++) {
- int x = i * 5;
+ for (int i = 0, n = width / markerSpacing + 1; i < n; i++) {
+ int x = i * markerSpacing;
if (i % 4 == 0) {
graphics.drawLine(x, 0, x, height / 2);
@@ -85,8 +102,8 @@ class RulerSkin extends ComponentSkin im
}
case VERTICAL: {
- for (int i = 0, n = height / 5 + 1; i < n; i++) {
- int y = i * 5;
+ for (int i = 0, n = height / markerSpacing + 1; i < n; i++) {
+ int y = i * markerSpacing;
if (i % 4 == 0) {
graphics.drawLine(0, y, width / 2, y);
@@ -111,4 +128,92 @@ class RulerSkin extends ComponentSkin im
invalidateComponent();
}
+ public int getMarkerSpacing() {
+ return markerSpacing;
+ }
+
+ public void setMarkerSpacing(int spacing) {
+ Utils.checkNonNegative(spacing, "markerSpacing");
+
+ this.markerSpacing = spacing;
+ invalidateComponent();
+ }
+
+ public void setMarkerSpacing(Number spacing) {
+ Utils.checkNull(spacing, "markerSpacing");
+
+ setMarkerSpacing(spacing.intValue());
+ }
+
+ /**
+ * Returns the foreground color for the markers of the ruler.
+ *
+ * @return The foreground (marker) color.
+ */
+ public Color getColor() {
+ return color;
+ }
+
+ /**
+ * Sets the foreground color for the markers of the ruler.
+ *
+ * @param color The foreground (that is, the marker) color.
+ */
+ public void setColor(Color color) {
+ Utils.checkNull(color, "color");
+
+ this.color = color;
+ repaintComponent();
+ }
+
+ /**
+ * Sets the foreground color for the markers of the ruler.
+ *
+ * @param color Any of the {@linkplain GraphicsUtilities#decodeColor color
+ * values recognized by Pivot}.
+ */
+ public void setColor(String color) {
+ setColor(GraphicsUtilities.decodeColor(color, "color"));
+ }
+
+ public void setColor(int color) {
+ Theme theme = currentTheme();
+ setColor(theme.getColor(color));
+ }
+
+ /**
+ * Returns the background color of the ruler.
+ *
+ * @return The current background color.
+ */
+ public Color getBackgroundColor() {
+ return backgroundColor;
+ }
+
+ /**
+ * Sets the background color of the ruler.
+ *
+ * @param backgroundColor New background color value (can be {@code null}
+ * for a transparent background).
+ */
+ public void setBackgroundColor(Color backgroundColor) {
+ this.backgroundColor = backgroundColor;
+ repaintComponent();
+ }
+
+ /**
+ * Sets the background color of the ruler.
+ *
+ * @param backgroundColor Any of the
+ * {@linkplain GraphicsUtilities#decodeColor color values recognized by
+ * Pivot}.
+ */
+ public void setBackgroundColor(String backgroundColor) {
+ setBackgroundColor(GraphicsUtilities.decodeColor(backgroundColor, "backgroundColor"));
+ }
+
+ public void setBackgroundColor(int backgroundColor) {
+ Theme theme = currentTheme();
+ setBackgroundColor(theme.getColor(backgroundColor));
+ }
}