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 2020/05/01 22:54:08 UTC

svn commit: r1877274 - in /pivot/trunk: demos/src/org/apache/pivot/demos/text/ tests/src/org/apache/pivot/tests/ tutorials/src/org/apache/pivot/tutorials/ wtk/src/org/apache/pivot/wtk/ wtk/src/org/apache/pivot/wtk/text/ wtk/test/org/apache/pivot/wtk/test/

Author: rwhitcomb
Date: Fri May  1 22:54:08 2020
New Revision: 1877274

URL: http://svn.apache.org/viewvc?rev=1877274&view=rev
Log:
The "Style" enum was introduced to make setting component styles more
foolproof by defining the style names in terms of an enum that can be
checked at compile-time.  So, go through all the uses of "getStyles"
and correct anything that is still being set via a string constant
(if possible, some things are just custom JSON, for instance).

Add a few Style values that were being set via strings.

Make some "check-style" changes in the files that were changed,
as well as convert some callbacks to lambdas as appropriate.

A bunch of changes to TextPaneDemo suggested some improvements
to Span, which then required new tests in SpanTest as well. And
a new method added to Node: "getParagraph".


Modified:
    pivot/trunk/demos/src/org/apache/pivot/demos/text/TextPaneDemo.java
    pivot/trunk/tests/src/org/apache/pivot/tests/GaugeTest.java
    pivot/trunk/tests/src/org/apache/pivot/tests/LabelAntialiasTest.java
    pivot/trunk/tests/src/org/apache/pivot/tests/NativeDragDropTest.java
    pivot/trunk/tutorials/src/org/apache/pivot/tutorials/HelloJava.java
    pivot/trunk/wtk/src/org/apache/pivot/wtk/FontUtilities.java
    pivot/trunk/wtk/src/org/apache/pivot/wtk/Span.java
    pivot/trunk/wtk/src/org/apache/pivot/wtk/Style.java
    pivot/trunk/wtk/src/org/apache/pivot/wtk/text/Element.java
    pivot/trunk/wtk/src/org/apache/pivot/wtk/text/Node.java
    pivot/trunk/wtk/test/org/apache/pivot/wtk/test/SpanTest.java

Modified: pivot/trunk/demos/src/org/apache/pivot/demos/text/TextPaneDemo.java
URL: http://svn.apache.org/viewvc/pivot/trunk/demos/src/org/apache/pivot/demos/text/TextPaneDemo.java?rev=1877274&r1=1877273&r2=1877274&view=diff
==============================================================================
--- pivot/trunk/demos/src/org/apache/pivot/demos/text/TextPaneDemo.java (original)
+++ pivot/trunk/demos/src/org/apache/pivot/demos/text/TextPaneDemo.java Fri May  1 22:54:08 2020
@@ -42,6 +42,7 @@ import org.apache.pivot.wtk.ColorChooser
 import org.apache.pivot.wtk.DesktopApplicationContext;
 import org.apache.pivot.wtk.Display;
 import org.apache.pivot.wtk.FileBrowserSheet;
+import org.apache.pivot.wtk.FontUtilities;
 import org.apache.pivot.wtk.HorizontalAlignment;
 import org.apache.pivot.wtk.ListButton;
 import org.apache.pivot.wtk.ListButtonSelectionListener;
@@ -91,7 +92,7 @@ public class TextPaneDemo implements App
     }
 
     @Override
-    public void startup(Display display, Map<String, String> properties) throws Exception {
+    public void startup(final Display display, final Map<String, String> properties) throws Exception {
         System.out.println("startup(...)");
         System.out.println("\n"
             + "In this test application as a sample for setting the display scale on startup,\n"
@@ -143,174 +144,114 @@ public class TextPaneDemo implements App
         fontSizeListButton.setListData(new NumericSpinnerData(12, 30, 1));
         fontSizeListButton.setSelectedItem(12);
 
-        openFileButton.getButtonPressListeners().add(new ButtonPressListener() {
-            @Override
-            public void buttonPressed(Button button) {
-                final FileBrowserSheet fileBrowserSheet = new FileBrowserSheet();
+        openFileButton.getButtonPressListeners().add(button -> {
+            final FileBrowserSheet fileBrowserSheet = new FileBrowserSheet();
 
-                fileBrowserSheet.setMode(FileBrowserSheet.Mode.OPEN);
-                fileBrowserSheet.open(window, new SheetCloseListener() {
-                    @Override
-                    public void sheetClosed(Sheet sheet) {
-                        if (sheet.getResult()) {
-                            loadedFile = fileBrowserSheet.getSelectedFile();
-
-                            try {
-                                BufferedReader reader = new BufferedReader(new FileReader(
-                                    loadedFile));
-                                PlainTextSerializer serializer = new PlainTextSerializer();
-                                textPane.setDocument(serializer.readObject(reader));
-                                reader.close();
-                                window.setTitle(loadedFile.getCanonicalPath());
-                            } catch (IOException ex) {
-                                ex.printStackTrace();
-                                Alert.alert(ex.getMessage(), window);
-                            }
-                        }
+            fileBrowserSheet.setMode(FileBrowserSheet.Mode.OPEN);
+            fileBrowserSheet.open(window, sheet -> {
+                if (sheet.getResult()) {
+                    loadedFile = fileBrowserSheet.getSelectedFile();
+                    try (BufferedReader reader = new BufferedReader(new FileReader(loadedFile))) {
+                        PlainTextSerializer serializer = new PlainTextSerializer();
+                        textPane.setDocument(serializer.readObject(reader));
+                        window.setTitle(loadedFile.getCanonicalPath());
+                    } catch (IOException ex) {
+                        ex.printStackTrace();
+                        Alert.alert(ex.getMessage(), window);
                     }
-                });
-            }
+                }
+            });
         });
 
-        saveFileButton.getButtonPressListeners().add(new ButtonPressListener() {
-            @Override
-            public void buttonPressed(Button button) {
-                final FileBrowserSheet fileBrowserSheet = new FileBrowserSheet();
+        saveFileButton.getButtonPressListeners().add(button -> {
+            final FileBrowserSheet fileBrowserSheet = new FileBrowserSheet();
 
-                if (loadedFile != null) {
-                    fileBrowserSheet.setSelectedFile(loadedFile);
-                }
+            if (loadedFile != null) {
+                fileBrowserSheet.setSelectedFile(loadedFile);
+            }
 
-                fileBrowserSheet.setMode(FileBrowserSheet.Mode.SAVE_AS);
-                fileBrowserSheet.open(window, new SheetCloseListener() {
-                    @Override
-                    public void sheetClosed(Sheet sheet) {
-                        if (sheet.getResult()) {
-                            File selectedFile = fileBrowserSheet.getSelectedFile();
-
-                            try {
-                                FileWriter writer = new FileWriter(selectedFile);
-                                PlainTextSerializer serializer = new PlainTextSerializer();
-                                serializer.writeObject(textPane.getDocument(), writer);
-                                writer.close();
-                                loadedFile = selectedFile;
-                                window.setTitle(loadedFile.getCanonicalPath());
-                            } catch (IOException ex) {
-                                ex.printStackTrace();
-                                Alert.alert(ex.getMessage(), window);
-                            }
-                        }
+            fileBrowserSheet.setMode(FileBrowserSheet.Mode.SAVE_AS);
+            fileBrowserSheet.open(window, sheet -> {
+                if (sheet.getResult()) {
+                    File selectedFile = fileBrowserSheet.getSelectedFile();
+
+                    try (FileWriter writer = new FileWriter(selectedFile)) {
+                        PlainTextSerializer serializer = new PlainTextSerializer();
+                        serializer.writeObject(textPane.getDocument(), writer);
+                        loadedFile = selectedFile;
+                        window.setTitle(loadedFile.getCanonicalPath());
+                    } catch (IOException ex) {
+                        ex.printStackTrace();
+                        Alert.alert(ex.getMessage(), window);
                     }
-                });
-            }
+                }
+            });
         });
 
-        boldButton.getButtonPressListeners().add(new ButtonPressListener() {
-            @Override
-            public void buttonPressed(Button button) {
-                applyStyleToSelection(new StyleApplicator() {
-                    @Override
-                    public void apply(TextSpan span) {
-                        if (span.getFont() != null) {
-                            Font font = span.getFont();
-                            if (font.getStyle() == Font.PLAIN) {
-                                font = font.deriveFont(Font.BOLD);
-                            } else if (font.getStyle() == Font.BOLD) {
-                                font = font.deriveFont(Font.PLAIN);
-                            } else {
-                                // the font is BOLD+ITALIC
-                                font = font.deriveFont(Font.ITALIC);
-                            }
-                            span.setFont(font);
-                        } else {
-                            span.setFont("Arial BOLD 12");
-                        }
+        boldButton.getButtonPressListeners().add(button -> {
+            applyStyleToSelection(span -> {
+                if (span.getFont() != null) {
+                    Font font = span.getFont();
+                    if (font.getStyle() == Font.PLAIN) {
+                        font = font.deriveFont(Font.BOLD);
+                    } else if (font.getStyle() == Font.BOLD) {
+                        font = font.deriveFont(Font.PLAIN);
+                    } else {
+                        // the font is BOLD+ITALIC
+                        font = font.deriveFont(Font.ITALIC);
                     }
-                });
-                requestTextPaneFocus();
-            }
+                    span.setFont(font);
+                } else {
+                    span.setFont(FontUtilities.ARIAL, Font.BOLD, 12);
+                }
+            });
+            requestTextPaneFocus();
         });
 
-        italicButton.getButtonPressListeners().add(new ButtonPressListener() {
-            @Override
-            public void buttonPressed(Button button) {
-                applyStyleToSelection(new StyleApplicator() {
-                    @Override
-                    public void apply(TextSpan span) {
-                        if (span.getFont() != null) {
-                            Font font = span.getFont();
-                            if (font.getStyle() == Font.PLAIN) {
-                                font = font.deriveFont(Font.ITALIC);
-                            } else if (font.getStyle() == Font.ITALIC) {
-                                font = font.deriveFont(Font.PLAIN);
-                            } else {
-                                // the font is BOLD+ITALIC
-                                font = font.deriveFont(Font.BOLD);
-                            }
-                            span.setFont(font);
-                        } else {
-                            span.setFont("Arial ITALIC 12");
-                        }
+        italicButton.getButtonPressListeners().add(button -> {
+            applyStyleToSelection(span -> {
+                if (span.getFont() != null) {
+                    Font font = span.getFont();
+                    if (font.getStyle() == Font.PLAIN) {
+                        font = font.deriveFont(Font.ITALIC);
+                    } else if (font.getStyle() == Font.ITALIC) {
+                        font = font.deriveFont(Font.PLAIN);
+                    } else {
+                        // the font is BOLD+ITALIC
+                        font = font.deriveFont(Font.BOLD);
                     }
-                });
-                requestTextPaneFocus();
-            }
+                    span.setFont(font);
+                } else {
+                    span.setFont(FontUtilities.ARIAL, Font.ITALIC, 12);
+                }
+            });
+            requestTextPaneFocus();
         });
 
-        underlineButton.getButtonPressListeners().add(new ButtonPressListener() {
-            @Override
-            public void buttonPressed(Button button) {
-                applyStyleToSelection(new StyleApplicator() {
-                    @Override
-                    public void apply(TextSpan span) {
-                        span.setUnderline(!span.isUnderline());
-                    }
-                });
-                requestTextPaneFocus();
-            }
+        underlineButton.getButtonPressListeners().add(button -> {
+            applyStyleToSelection(span -> span.setUnderline(!span.isUnderline()));
+            requestTextPaneFocus();
         });
 
-        strikethroughButton.getButtonPressListeners().add(new ButtonPressListener() {
-            @Override
-            public void buttonPressed(Button button) {
-                applyStyleToSelection(new StyleApplicator() {
-                    @Override
-                    public void apply(TextSpan span) {
-                        span.setStrikethrough(!span.isStrikethrough());
-                    }
-                });
-                requestTextPaneFocus();
-            }
+        strikethroughButton.getButtonPressListeners().add(button -> {
+            applyStyleToSelection(span -> span.setStrikethrough(!span.isStrikethrough()));
+            requestTextPaneFocus();
         });
 
         foregroundColorChooserButton.getColorChooserButtonSelectionListeners().add(
-            new ColorChooserButtonSelectionListener() {
-                @Override
-                public void selectedColorChanged(ColorChooserButton colorChooserButton,
-                    Color previousSelectedColor) {
-                    applyStyleToSelection(new StyleApplicator() {
-                        @Override
-                        public void apply(TextSpan span) {
-                            span.setForegroundColor(foregroundColorChooserButton.getSelectedColor());
-                        }
-                    });
-                    requestTextPaneFocus();
-                }
+            (colorChooserButton, previousSelectedColor) -> {
+                applyStyleToSelection(span -> {
+                    span.setForegroundColor(foregroundColorChooserButton.getSelectedColor());
+                });
+                requestTextPaneFocus();
             });
 
         backgroundColorChooserButton.getColorChooserButtonSelectionListeners().add(
-            new ColorChooserButtonSelectionListener() {
-                @Override
-                public void selectedColorChanged(ColorChooserButton colorChooserButton,
-                    Color previousSelectedColor) {
-                    applyStyleToSelection(new StyleApplicator() {
-                        @Override
-                        public void apply(TextSpan span) {
-                            span.setBackgroundColor(backgroundColorChooserButton.getSelectedColor());
-                        }
-                    });
-                    requestTextPaneFocus();
-                }
+            (colorChooserButton, previousSelectedColor) -> {
+                applyStyleToSelection(span -> {
+                    span.setBackgroundColor(backgroundColorChooserButton.getSelectedColor());
+                });
+                requestTextPaneFocus();
             });
 
         ListButtonSelectionListener fontButtonPressListener = new ListButtonSelectionListener() {
@@ -320,48 +261,31 @@ public class TextPaneDemo implements App
                 String selectedFontFamily = (String) fontFamilyListButton.getSelectedItem();
                 final Font derivedFont = Font.decode(selectedFontFamily + " " + selectedFontSize);
 
-                applyStyleToSelection(new StyleApplicator() {
-                    @Override
-                    public void apply(TextSpan span) {
-                        span.setFont(derivedFont);
-                    }
-                });
+                applyStyleToSelection(span -> span.setFont(derivedFont));
                 requestTextPaneFocus();
             }
         };
         fontFamilyListButton.getListButtonSelectionListeners().add(fontButtonPressListener);
         fontSizeListButton.getListButtonSelectionListeners().add(fontButtonPressListener);
 
-        wrapTextCheckbox.getButtonPressListeners().add(new ButtonPressListener() {
-            @Override
-            public void buttonPressed(Button button) {
-                textPane.getStyles().put(Style.wrapText, wrapTextCheckbox.isSelected());
-                requestTextPaneFocus();
-            }
+        wrapTextCheckbox.getButtonPressListeners().add(button -> {
+            textPane.getStyles().put(Style.wrapText, wrapTextCheckbox.isSelected());
+            requestTextPaneFocus();
         });
 
-        alignLeftButton.getButtonPressListeners().add(new ButtonPressListener() {
-            @Override
-            public void buttonPressed(Button button) {
-                applyAlignmentStyle(HorizontalAlignment.LEFT);
-                requestTextPaneFocus();
-            }
+        alignLeftButton.getButtonPressListeners().add(button -> {
+            applyAlignmentStyle(HorizontalAlignment.LEFT);
+            requestTextPaneFocus();
         });
 
-        alignCentreButton.getButtonPressListeners().add(new ButtonPressListener() {
-            @Override
-            public void buttonPressed(Button button) {
-                applyAlignmentStyle(HorizontalAlignment.CENTER);
-                requestTextPaneFocus();
-            }
+        alignCentreButton.getButtonPressListeners().add(button -> {
+            applyAlignmentStyle(HorizontalAlignment.CENTER);
+            requestTextPaneFocus();
         });
 
-        alignRightButton.getButtonPressListeners().add(new ButtonPressListener() {
-            @Override
-            public void buttonPressed(Button button) {
-                applyAlignmentStyle(HorizontalAlignment.RIGHT);
-                requestTextPaneFocus();
-            }
+        alignRightButton.getButtonPressListeners().add(button -> {
+            applyAlignmentStyle(HorizontalAlignment.RIGHT);
+            requestTextPaneFocus();
         });
 
         String scaleProperty = properties.get("scale");
@@ -379,28 +303,21 @@ public class TextPaneDemo implements App
         requestTextPaneFocus();
     }
 
+    @FunctionalInterface
     private interface StyleApplicator {
         void apply(TextSpan span);
     }
 
-    private void applyAlignmentStyle(HorizontalAlignment horizontalAlignment) {
+    private void applyAlignmentStyle(final HorizontalAlignment horizontalAlignment) {
         Node node = textPane.getDocument().getDescendantAt(textPane.getSelectionStart());
-        while (node != null && !(node instanceof Paragraph)) {
-            node = node.getParent();
-        }
-        if (node != null) {
-            Paragraph paragraph = (Paragraph) node;
+        Paragraph paragraph = node.getParagraph();
+        if (paragraph != null) {
             paragraph.setHorizontalAlignment(horizontalAlignment);
         }
     }
 
     private void requestTextPaneFocus() {
-        ApplicationContext.scheduleCallback(new Runnable() {
-            @Override
-            public void run() {
-                textPane.requestFocus();
-            }
-        }, 200L);
+        ApplicationContext.scheduleCallback(() -> textPane.requestFocus(), 200L);
     }
 
     /** Debugging tools. */
@@ -410,7 +327,7 @@ public class TextPaneDemo implements App
     }
 
     /** Debugging tools. */
-    private void dumpDocumentNode(Node node, PrintStream printStream, final int indent) {
+    private void dumpDocumentNode(final Node node, final PrintStream printStream, final int indent) {
         for (int i = 0; i < indent; i++) {
             printStream.append("  ");
         }
@@ -441,16 +358,15 @@ public class TextPaneDemo implements App
         }
     }
 
-    private void applyStyleToSelection(StyleApplicator styleApplicator) {
+    private void applyStyleToSelection(final StyleApplicator styleApplicator) {
         Span span = textPane.getSelection();
-        if (span == null) {
-            return;
+        if (span != null) {
+            applyStyle(textPane.getDocument(), span, styleApplicator);
         }
-        applyStyle(textPane.getDocument(), span, styleApplicator);
     }
 
-    private void applyStyle(Document document, Span selectionSpan,
-        StyleApplicator styleApplicator) {
+    private void applyStyle(final Document document, final Span selectionSpan,
+        final StyleApplicator styleApplicator) {
         // I can't apply the styles while iterating over the tree, because I
         // need to update the tree.
         // So first collect a list of all the nodes in the tree.
@@ -471,8 +387,8 @@ public class TextPaneDemo implements App
                         textSpan);
                 }
             }
-            if (node instanceof org.apache.pivot.wtk.text.TextNode) {
-                org.apache.pivot.wtk.text.TextNode textNode = (org.apache.pivot.wtk.text.TextNode) node;
+            if (node instanceof TextNode) {
+                TextNode textNode = (TextNode) node;
                 int documentOffset = node.getDocumentOffset();
                 int characterCount = node.getCharacterCount();
                 Span textSpan = new Span(documentOffset, documentOffset + characterCount - 1);
@@ -487,9 +403,9 @@ public class TextPaneDemo implements App
         textPane.setSelection(selectionStart, selectionLength);
     }
 
-    private static void applyStyleToTextNode(Span selectionSpan,
-        StyleApplicator styleApplicator, org.apache.pivot.wtk.text.TextNode textNode,
-        int characterCount, Span textSpan) {
+    private static void applyStyleToTextNode(final Span selectionSpan,
+        final StyleApplicator styleApplicator, final TextNode textNode,
+        final int characterCount, final Span textSpan) {
         if (selectionSpan.contains(textSpan)) {
             // if the text-node is contained wholly inside the selection, remove
             // the text-node, replace it with a Span, and apply the style
@@ -550,9 +466,9 @@ public class TextPaneDemo implements App
         }
     }
 
-    private static void applyStyleToSpanNode(Span selectionSpan,
-        StyleApplicator styleApplicator, TextSpan spanNode, int characterCount,
-        Span textSpan) {
+    private static void applyStyleToSpanNode(final Span selectionSpan,
+        final StyleApplicator styleApplicator, final TextSpan spanNode, final int characterCount,
+        final Span textSpan) {
         if (selectionSpan.contains(textSpan)) {
             // if the span-node is contained wholly inside the
             // selection, apply the style
@@ -601,12 +517,12 @@ public class TextPaneDemo implements App
         }
     }
 
-    private void collectNodes(org.apache.pivot.wtk.text.Node node, List<Node> nodeList) {
+    private void collectNodes(Node node, List<Node> nodeList) {
         // don't worry about the text-nodes that are children of Span nodes.
         if (node instanceof TextSpan) {
             return;
         }
-        if (node instanceof org.apache.pivot.wtk.text.Element) {
+        if (node instanceof Element) {
             Element element = (Element) node;
             for (Node child : element) {
                 nodeList.add(child);
@@ -616,7 +532,7 @@ public class TextPaneDemo implements App
     }
 
     @Override
-    public boolean shutdown(boolean optional) {
+    public boolean shutdown(final boolean optional) {
         System.out.println("shutdown(" + optional + ")");
         if (window != null) {
             window.close();
@@ -625,7 +541,7 @@ public class TextPaneDemo implements App
         return false;
     }
 
-    public static void main(String[] args) {
+    public static void main(final String[] args) {
         DesktopApplicationContext.main(TextPaneDemo.class, args);
     }
 

Modified: pivot/trunk/tests/src/org/apache/pivot/tests/GaugeTest.java
URL: http://svn.apache.org/viewvc/pivot/trunk/tests/src/org/apache/pivot/tests/GaugeTest.java?rev=1877274&r1=1877273&r2=1877274&view=diff
==============================================================================
--- pivot/trunk/tests/src/org/apache/pivot/tests/GaugeTest.java (original)
+++ pivot/trunk/tests/src/org/apache/pivot/tests/GaugeTest.java Fri May  1 22:54:08 2020
@@ -28,6 +28,7 @@ import org.apache.pivot.wtk.DesktopAppli
 import org.apache.pivot.wtk.Display;
 import org.apache.pivot.wtk.Gauge;
 import org.apache.pivot.wtk.PushButton;
+import org.apache.pivot.wtk.Style;
 import org.apache.pivot.wtk.Theme;
 import org.apache.pivot.wtk.Window;
 
@@ -63,7 +64,7 @@ public final class GaugeTest implements
         } else if (speed > speedGauge.getWarningLevel()) {
             color = warningColor;
         }
-        speedGauge.getStyles().put("textColor", color);
+        speedGauge.getStyles().put(Style.textColor, color);
         speedGauge.setText(Integer.toString(speed) + " MpH");
     }
 
@@ -85,7 +86,7 @@ public final class GaugeTest implements
     }
 
     private void toggleMax(final Button.State state) {
-        speedGauge.getStyles().put("onlyMaxColor", state == Button.State.SELECTED);
+        speedGauge.getStyles().put(Style.onlyMaxColor, state == Button.State.SELECTED);
     }
 
     @Override
@@ -97,8 +98,8 @@ public final class GaugeTest implements
         brakePedal = (PushButton) bxmlSerializer.getNamespace().get("brakePedal");
         speedGauge = (Gauge<Integer>) bxmlSerializer.getNamespace().get("speedGauge");
         maxCheck = (Checkbox) bxmlSerializer.getNamespace().get("maxCheck");
-        warningColor = speedGauge.getStyles().getColor("warningColor");
-        criticalColor = speedGauge.getStyles().getColor("criticalColor");
+        warningColor = speedGauge.getStyles().getColor(Style.warningColor);
+        criticalColor = speedGauge.getStyles().getColor(Style.criticalColor);
         textColor = Theme.getTheme().getColor(6);
         setSpeed(speedGauge.getValue());
         gasPedal.getButtonPressListeners().add((button) -> hitTheGas());

Modified: pivot/trunk/tests/src/org/apache/pivot/tests/LabelAntialiasTest.java
URL: http://svn.apache.org/viewvc/pivot/trunk/tests/src/org/apache/pivot/tests/LabelAntialiasTest.java?rev=1877274&r1=1877273&r2=1877274&view=diff
==============================================================================
--- pivot/trunk/tests/src/org/apache/pivot/tests/LabelAntialiasTest.java (original)
+++ pivot/trunk/tests/src/org/apache/pivot/tests/LabelAntialiasTest.java Fri May  1 22:54:08 2020
@@ -27,6 +27,7 @@ import org.apache.pivot.wtk.Application;
 import org.apache.pivot.wtk.BoxPane;
 import org.apache.pivot.wtk.DesktopApplicationContext;
 import org.apache.pivot.wtk.Display;
+import org.apache.pivot.wtk.FontUtilities;
 import org.apache.pivot.wtk.HorizontalAlignment;
 import org.apache.pivot.wtk.Label;
 import org.apache.pivot.wtk.Orientation;
@@ -47,7 +48,7 @@ public final class LabelAntialiasTest im
     private Label buildLabel(final double rotation) {
         Label label = new Label();
 
-        Font font = new Font("Arial", Font.BOLD, 64);
+        Font font = new Font(FontUtilities.ARIAL, Font.BOLD, 64);
 
         AffineTransform fontAT = new AffineTransform();
         // Derive a new font using a rotation transform

Modified: pivot/trunk/tests/src/org/apache/pivot/tests/NativeDragDropTest.java
URL: http://svn.apache.org/viewvc/pivot/trunk/tests/src/org/apache/pivot/tests/NativeDragDropTest.java?rev=1877274&r1=1877273&r2=1877274&view=diff
==============================================================================
--- pivot/trunk/tests/src/org/apache/pivot/tests/NativeDragDropTest.java (original)
+++ pivot/trunk/tests/src/org/apache/pivot/tests/NativeDragDropTest.java Fri May  1 22:54:08 2020
@@ -27,6 +27,7 @@ import org.apache.pivot.wtk.Display;
 import org.apache.pivot.wtk.DragSource;
 import org.apache.pivot.wtk.DropAction;
 import org.apache.pivot.wtk.DropTarget;
+import org.apache.pivot.wtk.FontUtilities;
 import org.apache.pivot.wtk.Frame;
 import org.apache.pivot.wtk.HorizontalAlignment;
 import org.apache.pivot.wtk.Label;
@@ -43,7 +44,7 @@ public class NativeDragDropTest implemen
     @Override
     public void startup(final Display display, Map<String, String> properties) throws Exception {
         final Label label = new Label("http://pivot.apache.org/");
-        label.getStyles().put(Style.font, new Font("Arial", Font.PLAIN, 24));
+        label.getStyles().put(Style.font, new Font(FontUtilities.ARIAL, Font.PLAIN, 24));
         label.getStyles().put(Style.horizontalAlignment, HorizontalAlignment.CENTER);
         label.getStyles().put(Style.verticalAlignment, VerticalAlignment.CENTER);
 

Modified: pivot/trunk/tutorials/src/org/apache/pivot/tutorials/HelloJava.java
URL: http://svn.apache.org/viewvc/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/HelloJava.java?rev=1877274&r1=1877273&r2=1877274&view=diff
==============================================================================
--- pivot/trunk/tutorials/src/org/apache/pivot/tutorials/HelloJava.java (original)
+++ pivot/trunk/tutorials/src/org/apache/pivot/tutorials/HelloJava.java Fri May  1 22:54:08 2020
@@ -23,6 +23,7 @@ import org.apache.pivot.collections.Map;
 import org.apache.pivot.wtk.Application;
 import org.apache.pivot.wtk.DesktopApplicationContext;
 import org.apache.pivot.wtk.Display;
+import org.apache.pivot.wtk.FontUtilities;
 import org.apache.pivot.wtk.HorizontalAlignment;
 import org.apache.pivot.wtk.Label;
 import org.apache.pivot.wtk.Style;
@@ -38,7 +39,7 @@ public class HelloJava implements Applic
 
         Label label = new Label();
         label.setText("Hello World!");
-        label.getStyles().put(Style.font, new Font("Arial", Font.BOLD, 24));
+        label.getStyles().put(Style.font, new Font(FontUtilities.ARIAL, Font.BOLD, 24));
         label.getStyles().put(Style.color, Color.RED);
         label.getStyles().put(Style.horizontalAlignment, HorizontalAlignment.CENTER);
         label.getStyles().put(Style.verticalAlignment, VerticalAlignment.CENTER);

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/FontUtilities.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/FontUtilities.java?rev=1877274&r1=1877273&r2=1877274&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/FontUtilities.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/FontUtilities.java Fri May  1 22:54:08 2020
@@ -27,6 +27,9 @@ import org.apache.pivot.util.Utils;
  */
 public final class FontUtilities {
 
+    /** The standard name for the {@code Arial} font. */
+    public static final String ARIAL = "Arial";
+
     /**
      * Private constructor for utility class.
      */

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/Span.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/Span.java?rev=1877274&r1=1877273&r2=1877274&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/Span.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/Span.java Fri May  1 22:54:08 2020
@@ -271,6 +271,14 @@ public final class Span {
     }
 
     /**
+     * @return <tt>true</tt> if the span is "normal", meaning the start is
+     * less or equal the end.
+     */
+    public boolean isNormal() {
+        return start <= end;
+    }
+
+    /**
      * Create a span where the start value is less than or equal to the end value.
      *
      * @param start The new proposed start value.
@@ -278,15 +286,25 @@ public final class Span {
      * @return A span containing the normalized range.
      */
     public static Span normalize(final int start, final int end) {
-        return new Span(Math.min(start, end), Math.max(start, end));
+        if (start <= end) {
+            return new Span(start, end);
+        } else {
+            return new Span(end, start);
+        }
     }
 
     /**
      * @return A normalized equivalent of the span in which <tt>start</tt> is
-     * guaranteed to be less than <tt>end</tt>.
+     * guaranteed to be less or equal to <tt>end</tt>.
+     * <p> Note: if the span is already "normal", then no new object is
+     * created.
      */
     public Span normalize() {
-        return normalize(start, end);
+        if (start <= end) {
+            return this;
+        } else {
+            return new Span(end, start);
+        }
     }
 
     /**
@@ -300,7 +318,7 @@ public final class Span {
      * @return A new {@link Span} with updated values.
      */
     public Span offset(final int offset) {
-        return new Span(this.start + offset, this.end + offset);
+        return new Span(start + offset, end + offset);
     }
 
     /**
@@ -311,7 +329,7 @@ public final class Span {
      * @return A new {@link Span} with updated value.
      */
     public Span lengthen(final int offset) {
-        return new Span(this.start, this.end + offset);
+        return new Span(start, end + offset);
     }
 
     /**
@@ -322,7 +340,7 @@ public final class Span {
      * @return A new {@link Span} with updated value.
      */
     public Span move(final int offset) {
-        return new Span(this.start + offset, this.end);
+        return new Span(start + offset, end);
     }
 
     /**

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/Style.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/Style.java?rev=1877274&r1=1877273&r2=1877274&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/Style.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/Style.java Fri May  1 22:54:08 2020
@@ -40,6 +40,7 @@ public enum Style {
     closeTransitionDuration,
     closeTransitionRate,
     color,
+    criticalColor,
     disabledColor,
     editOnMouseDown,
     fill,
@@ -59,6 +60,7 @@ public enum Style {
     margin,
     markerSpacing,
     minimumAspectRatio,
+    onlyMaxColor,
     opacity,
     padding,
     resizable,
@@ -79,6 +81,7 @@ public enum Style {
     spacing,
     tabOrientation,
     tabWidth,
+    textColor,
     textDecoration,
     toolbar,
     units,
@@ -87,5 +90,6 @@ public enum Style {
     verticalAlignment,
     verticalGridColor,
     verticalSpacing,
+    warningColor,
     wrapText
 }

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/text/Element.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/text/Element.java?rev=1877274&r1=1877273&r2=1877274&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/text/Element.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/text/Element.java Fri May  1 22:54:08 2020
@@ -565,6 +565,10 @@ public abstract class Element extends No
         setFont(FontUtilities.decodeFont(font));
     }
 
+    public final void setFont(final String name, final int style, final int size) {
+        setFont(new Font(name, style, size));
+    }
+
     /**
      * @return The current foreground color, or <tt>null</tt> if no color is
      * foreground.

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/text/Node.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/text/Node.java?rev=1877274&r1=1877273&r2=1877274&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/text/Node.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/text/Node.java Fri May  1 22:54:08 2020
@@ -40,7 +40,7 @@ public abstract class Node {
         return parent;
     }
 
-    protected void setParent(Element parent) {
+    protected void setParent(final Element parent) {
         Element previousParent = this.parent;
 
         if (previousParent != parent) {
@@ -64,7 +64,7 @@ public abstract class Node {
      *
      * @param offset The new offset for this node.
      */
-    protected void setOffset(int offset) {
+    protected void setOffset(final int offset) {
         int previousOffset = this.offset;
 
         if (previousOffset != offset) {
@@ -93,6 +93,21 @@ public abstract class Node {
     }
 
     /**
+     * Get the parent paragraph of this node.
+     *
+     * @return The paragraph this node is contained within or {@code null}
+     * it there are none (should only be for top-level elements or the document
+     * itself).
+     */
+    public Paragraph getParagraph() {
+        Node node = this;
+        while (node != null && !(node instanceof Paragraph)) {
+            node = node.parent;
+        }
+        return (Paragraph) node;
+    }
+
+    /**
      * Inserts a range into the node. Note that the contents of the range,
      * rather than the range itself, is added to the node.
      *
@@ -120,7 +135,7 @@ public abstract class Node {
      * @return The removed range. This will be a copy of the node structure
      * relative to this node.
      */
-    public Node replaceRange(int offsetArgument, int characterCount, Node range) {
+    public Node replaceRange(final int offsetArgument, final int characterCount, final Node range) {
         Node removed = removeRange(offsetArgument, characterCount);
         insertRange(range, offsetArgument);
 
@@ -173,7 +188,7 @@ public abstract class Node {
      * @param offsetArgument Offset relative to this node.
      * @param characterCount Count of characters inserted.
      */
-    protected void rangeInserted(int offsetArgument, int characterCount) {
+    protected void rangeInserted(final int offsetArgument, final int characterCount) {
         if (parent != null) {
             parent.rangeInserted(offsetArgument + this.offset, characterCount);
         }
@@ -196,7 +211,7 @@ public abstract class Node {
      * @param removedChars The optional actual characters removed (only in the case
      * of direct removal from a text node).
      */
-    protected void rangeRemoved(Node node, int offsetArgument, int characterCount,
+    protected void rangeRemoved(final Node node, final int offsetArgument, final int characterCount,
         CharSequence removedChars) {
         if (parent != null) {
             parent.rangeRemoved(node, offsetArgument + this.offset, characterCount, removedChars);
@@ -218,7 +233,7 @@ public abstract class Node {
      * @param removed The actual sequence of nodes removed from that node.
      * @param offsetArgument Offset relative to this node.
      */
-    protected void nodesRemoved(Node node, Sequence<Node> removed, int offsetArgument) {
+    protected void nodesRemoved(final Node node, final Sequence<Node> removed, final int offsetArgument) {
         if (parent != null) {
             parent.nodesRemoved(node, removed, offsetArgument + this.offset);
         }
@@ -236,7 +251,7 @@ public abstract class Node {
      *
      * @param offsetArgument Offset relative to this node.
      */
-    protected void nodeInserted(int offsetArgument) {
+    protected void nodeInserted(final int offsetArgument) {
         if (parent != null) {
             parent.nodeInserted(offsetArgument + this.offset);
         }
@@ -267,7 +282,7 @@ public abstract class Node {
      * @param userData Any piece of data that has meaning to the user
      * application (can be {@code null}).
      */
-    public void setUserData(Object userData) {
+    public void setUserData(final Object userData) {
         this.userData = userData;
     }
 

Modified: pivot/trunk/wtk/test/org/apache/pivot/wtk/test/SpanTest.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/SpanTest.java?rev=1877274&r1=1877273&r2=1877274&view=diff
==============================================================================
--- pivot/trunk/wtk/test/org/apache/pivot/wtk/test/SpanTest.java (original)
+++ pivot/trunk/wtk/test/org/apache/pivot/wtk/test/SpanTest.java Fri May  1 22:54:08 2020
@@ -86,6 +86,13 @@ public class SpanTest {
         assertEquals(sp6.toString(), "Span {start:4, end:6}");
         assertEquals(sp6b, sp5b);
         assertEquals(sp6d, sp3a);
+
+        Span s9 = new Span(5, 6);
+        Span s9a = new Span(6, 5);
+        assertTrue(s9.isNormal());
+        assertFalse(s9a.isNormal());
+        assertEquals(s9, s9a.normalize());
+        assertEquals(s9, Span.normalize(6, 5));
     }
 
 }