changeset 3287:5788c0441c97

TextArea code cleanup (mostly just formatting).
author jgiles
date Fri, 12 Apr 2013 16:28:24 +1200
parents 988b37ad5577
children 9ba7cb9d439c 4f184a258645
files javafx-ui-controls/src/com/sun/javafx/scene/control/skin/TextAreaSkin.java javafx-ui-controls/src/com/sun/javafx/scene/control/skin/TextInputControlSkin.java
diffstat 2 files changed, 110 insertions(+), 129 deletions(-) [+]
line wrap: on
line diff
--- a/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/TextAreaSkin.java	Fri Apr 12 15:42:33 2013 +1200
+++ b/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/TextAreaSkin.java	Fri Apr 12 16:28:24 2013 +1200
@@ -119,8 +119,7 @@
             });
         }
 
-        @Override
-        protected ObservableList<Node> getChildren() {
+        @Override protected ObservableList<Node> getChildren() {
             return super.getChildren();
         }
 
@@ -128,59 +127,57 @@
             return Orientation.HORIZONTAL;
         }
 
-        @Override
-        protected double computePrefWidth(double height) {
-          if (computedPrefWidth < 0) {
+        @Override protected double computePrefWidth(double height) {
+            if (computedPrefWidth < 0) {
+                double prefWidth = 0;
 
-            double prefWidth = 0;
+                for (Node node : paragraphNodes.getChildren()) {
+                    Text paragraphNode = (Text)node;
+                    prefWidth = Math.max(prefWidth,
+                            Utils.computeTextWidth(paragraphNode.getFont(),
+                                    paragraphNode.getText(), 0));
+                }
 
-            for (Node node : paragraphNodes.getChildren()) {
-                Text paragraphNode = (Text)node;
-                prefWidth = Math.max(prefWidth,
-                                     Utils.computeTextWidth(paragraphNode.getFont(),
-                                                            paragraphNode.getText(), 0));
+                prefWidth += leftPadding() + rightPadding();
+
+                Bounds viewPortBounds = scrollPane.getViewportBounds();
+                computedPrefWidth = Math.max(prefWidth, (viewPortBounds != null) ? viewPortBounds.getWidth() : 0);
             }
-
-            prefWidth += leftPadding() + rightPadding();
-
-            Bounds viewPortBounds = scrollPane.getViewportBounds();
-            computedPrefWidth = Math.max(prefWidth, (viewPortBounds != null) ? viewPortBounds.getWidth() : 0);
-          }
-          return computedPrefWidth;
+            return computedPrefWidth;
         }
 
         @Override
         protected double computePrefHeight(double width) {
-          if (width != widthForComputedPrefHeight) {
-              invalidateMetrics();
-              widthForComputedPrefHeight = width;
-          }
-
-          if (computedPrefHeight < 0) {
-
-
-            double wrappingWidth;
-            if (width == -1) {
-                wrappingWidth = 0;
-            } else {
-                wrappingWidth = Math.max(width - (leftPadding() + rightPadding()), 0);
+            if (width != widthForComputedPrefHeight) {
+                invalidateMetrics();
+                widthForComputedPrefHeight = width;
             }
 
-            double prefHeight = 0;
+            if (computedPrefHeight < 0) {
+                double wrappingWidth;
+                if (width == -1) {
+                    wrappingWidth = 0;
+                } else {
+                    wrappingWidth = Math.max(width - (leftPadding() + rightPadding()), 0);
+                }
 
-            for (Node node : paragraphNodes.getChildren()) {
-                Text paragraphNode = (Text)node;
-                prefHeight += Utils.computeTextHeight(paragraphNode.getFont(),
-                                                      paragraphNode.getText(),
-                                                      wrappingWidth, paragraphNode.getBoundsType());
+                double prefHeight = 0;
+
+                for (Node node : paragraphNodes.getChildren()) {
+                    Text paragraphNode = (Text)node;
+                    prefHeight += Utils.computeTextHeight(
+                            paragraphNode.getFont(),
+                            paragraphNode.getText(),
+                            wrappingWidth, 
+                            paragraphNode.getBoundsType());
+                }
+
+                prefHeight += topPadding() + bottomPadding();
+
+                Bounds viewPortBounds = scrollPane.getViewportBounds();
+                computedPrefHeight = Math.max(prefHeight, (viewPortBounds != null) ? viewPortBounds.getHeight() : 0);
             }
-
-            prefHeight += topPadding() + bottomPadding();
-
-            Bounds viewPortBounds = scrollPane.getViewportBounds();
-            computedPrefHeight = Math.max(prefHeight, (viewPortBounds != null) ? viewPortBounds.getHeight() : 0);
-          }
-          return computedPrefHeight;
+            return computedPrefHeight;
         }
 
         @Override protected double computeMinWidth(double height) {
@@ -227,15 +224,18 @@
             double wrappingWidth = Math.max(width - (leftPadding + rightPadding()), 0);
 
             double y = topPadding;
+            
+            final List<Node> paragraphNodesChildren = paragraphNodes.getChildren();
 
-            for (Node node : paragraphNodes.getChildren()) {
+            for (int i = 0; i < paragraphNodesChildren.size(); i++) {
+                Node node = paragraphNodesChildren.get(i);
                 Text paragraphNode = (Text)node;
                 paragraphNode.setWrappingWidth(wrappingWidth);
 
                 Bounds bounds = paragraphNode.getBoundsInLocal();
                 paragraphNode.setLayoutX(leftPadding);
                 paragraphNode.setLayoutY(y);
-
+                
                 y += bounds.getHeight();
             }
 
@@ -269,11 +269,11 @@
                 // Position the handle for the anchor. This could be handle1 or handle2.
                 // Do this before positioning the actual caret.
                 if (selection.getLength() > 0) {
-                    int paragraphIndex = paragraphNodes.getChildren().size();
+                    int paragraphIndex = paragraphNodesChildren.size();
                     int paragraphOffset = textArea.getLength() + 1;
                     Text paragraphNode = null;
                     do {
-                        paragraphNode = (Text)paragraphNodes.getChildren().get(--paragraphIndex);
+                        paragraphNode = (Text)paragraphNodesChildren.get(--paragraphIndex);
                         paragraphOffset -= paragraphNode.getText().length() + 1;
                     } while (anchorPos < paragraphOffset);
 
@@ -296,12 +296,12 @@
 
             {
                 // Position caret
-                int paragraphIndex = paragraphNodes.getChildren().size();
+                int paragraphIndex = paragraphNodesChildren.size();
                 int paragraphOffset = textArea.getLength() + 1;
 
                 Text paragraphNode = null;
                 do {
-                    paragraphNode = (Text)paragraphNodes.getChildren().get(--paragraphIndex);
+                    paragraphNode = (Text)paragraphNodesChildren.get(--paragraphIndex);
                     paragraphOffset -= paragraphNode.getText().length() + 1;
                 } while (caretPos < paragraphOffset);
 
@@ -324,7 +324,8 @@
             // Update selection fg and bg
             int start = selection.getStart();
             int end = selection.getEnd();
-            for (Node paragraphNode : paragraphNodes.getChildren()) {
+            for (int i = 0, max = paragraphNodesChildren.size(); i < max; i++) {
+                Node paragraphNode = paragraphNodesChildren.get(i);
                 Text textNode = (Text)paragraphNode;
                 int paragraphLength = textNode.getText().length() + 1;
                 if (end > start && start < paragraphLength) {
@@ -599,45 +600,45 @@
             }
         });
 
-      if (USE_MULTIPLE_NODES) {
-        textArea.getParagraphs().addListener(new ListChangeListener<CharSequence>() {
-            @Override
-            public void onChanged(ListChangeListener.Change<? extends CharSequence> change) {
-                while (change.next()) {
-                    int from = change.getFrom();
-                    int to = change.getTo();
-                    List<? extends CharSequence> removed = change.getRemoved();
-                    if (from < to) {
+        if (USE_MULTIPLE_NODES) {
+            textArea.getParagraphs().addListener(new ListChangeListener<CharSequence>() {
+                @Override
+                public void onChanged(ListChangeListener.Change<? extends CharSequence> change) {
+                    while (change.next()) {
+                        int from = change.getFrom();
+                        int to = change.getTo();
+                        List<? extends CharSequence> removed = change.getRemoved();
+                        if (from < to) {
 
-                        if (removed.isEmpty()) {
-                            // This is an add
-                            for (int i = from, n = to; i < n; i++) {
-                                addParagraphNode(i, change.getList().get(i).toString());
+                            if (removed.isEmpty()) {
+                                // This is an add
+                                for (int i = from, n = to; i < n; i++) {
+                                    addParagraphNode(i, change.getList().get(i).toString());
+                                }
+                            } else {
+                                // This is an update
+                                for (int i = from, n = to; i < n; i++) {
+                                    Node node = paragraphNodes.getChildren().get(i);
+                                    Text paragraphNode = (Text) node;
+                                    paragraphNode.setText(change.getList().get(i).toString());
+                                }
                             }
                         } else {
-                            // This is an update
-                            for (int i = from, n = to; i < n; i++) {
-                                Node node = paragraphNodes.getChildren().get(i);
-                                Text paragraphNode = (Text) node;
-                                paragraphNode.setText(change.getList().get(i).toString());
-                            }
+                            // This is a remove
+                            paragraphNodes.getChildren().subList(from, from + removed.size()).clear();
                         }
-                    } else {
-                        // This is a remove
-                        paragraphNodes.getChildren().subList(from, from + removed.size()).clear();
                     }
                 }
-            }
-        });
-      } else {
-        textArea.textProperty().addListener(new InvalidationListener() {
-            @Override public void invalidated(Observable observable) {
-                invalidateMetrics();
-                ((Text)paragraphNodes.getChildren().get(0)).setText(textArea.textProperty().getValueSafe());
-                contentView.requestLayout();
-            }
-        });
-      }
+            });
+        } else {
+            textArea.textProperty().addListener(new InvalidationListener() {
+                @Override public void invalidated(Observable observable) {
+                    invalidateMetrics();
+                    ((Text)paragraphNodes.getChildren().get(0)).setText(textArea.textProperty().getValueSafe());
+                    contentView.requestLayout();
+                }
+            });
+        }
 
         usePromptText = new BooleanBinding() {
             { bind(textArea.textProperty(), textArea.promptTextProperty()); }
@@ -798,6 +799,7 @@
 
     @Override public void layoutChildren(final double x, final double y,
             final double w, final double h) {
+        
         scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.AS_NEEDED);
         scrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.AS_NEEDED);
 
--- a/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/TextInputControlSkin.java	Fri Apr 12 15:42:33 2013 +1200
+++ b/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/TextInputControlSkin.java	Fri Apr 12 16:28:24 2013 +1200
@@ -101,104 +101,83 @@
     /**
      * The fill to use for the text under normal conditions
      */
-    protected final ObjectProperty<Paint> textFill = 
-        new StyleableObjectProperty<Paint>(Color.BLACK) {
-
-        @Override
-        public Object getBean() {
+    protected final ObjectProperty<Paint> textFill = new StyleableObjectProperty<Paint>(Color.BLACK) {
+        @Override public Object getBean() {
             return TextInputControlSkin.this;
         }
 
-        @Override
-        public String getName() {
+        @Override public String getName() {
             return "textFill";
         }
 
-        @Override
-        public CssMetaData<TextInputControl,Paint> getCssMetaData() {
+        @Override public CssMetaData<TextInputControl,Paint> getCssMetaData() {
             return StyleableProperties.TEXT_FILL;
         }
     };
-    protected final ObjectProperty<Paint> promptTextFill = 
-        new StyleableObjectProperty<Paint>(Color.GRAY) {
-
-        @Override
-        public Object getBean() {
+    
+    protected final ObjectProperty<Paint> promptTextFill = new StyleableObjectProperty<Paint>(Color.GRAY) {
+        @Override public Object getBean() {
             return TextInputControlSkin.this;
         }
 
-        @Override
-        public String getName() {
+        @Override public String getName() {
             return "promptTextFill";
         }
 
-        @Override
-        public CssMetaData<TextInputControl,Paint> getCssMetaData() {
+        @Override public CssMetaData<TextInputControl,Paint> getCssMetaData() {
             return StyleableProperties.PROMPT_TEXT_FILL;
         }
     };
+    
     /**
      * The fill to use for the text when highlighted.
      */
-    protected final ObjectProperty<Paint> highlightFill = 
-        new StyleableObjectProperty<Paint>(Color.DODGERBLUE) {
-
+    protected final ObjectProperty<Paint> highlightFill = new StyleableObjectProperty<Paint>(Color.DODGERBLUE) {
         @Override protected void invalidated() {
             updateHighlightFill();
         }
 
-        @Override
-        public Object getBean() {
+        @Override public Object getBean() {
             return TextInputControlSkin.this;
         }
 
-        @Override
-        public String getName() {
+        @Override public String getName() {
             return "highlightFill";
         }
 
-        @Override
-        public CssMetaData<TextInputControl,Paint> getCssMetaData() {
+        @Override public CssMetaData<TextInputControl,Paint> getCssMetaData() {
             return StyleableProperties.HIGHLIGHT_FILL;
         }
     };
-    protected final ObjectProperty<Paint> highlightTextFill = 
-        new StyleableObjectProperty<Paint>(Color.WHITE) {
-
+    
+    protected final ObjectProperty<Paint> highlightTextFill = new StyleableObjectProperty<Paint>(Color.WHITE) {
         @Override protected void invalidated() {
             updateHighlightTextFill();
         }
 
-        @Override
-        public Object getBean() {
+        @Override public Object getBean() {
             return TextInputControlSkin.this;
         }
 
-        @Override
-        public String getName() {
+        @Override public String getName() {
             return "highlightTextFill";
         }
 
-        @Override
-        public CssMetaData<TextInputControl,Paint> getCssMetaData() {
+        @Override public CssMetaData<TextInputControl,Paint> getCssMetaData() {
             return StyleableProperties.HIGHLIGHT_TEXT_FILL;
         }
     };
-    protected final BooleanProperty displayCaret = 
-        new StyleableBooleanProperty(true) {
-
-        @Override
-        public Object getBean() {
+    
+    protected final BooleanProperty displayCaret = new StyleableBooleanProperty(true) {
+        @Override public Object getBean() {
             return TextInputControlSkin.this;
         }
 
-        @Override
-        public String getName() {
+        @Override public String getName() {
             return "displayCaret";
         }
 
-        @Override
-        public CssMetaData<TextInputControl,Boolean> getCssMetaData() {
+        @Override public CssMetaData<TextInputControl,Boolean> getCssMetaData() {
             return StyleableProperties.DISPLAY_CARET;
         }
     };