modules/controls/src/main/java/com/sun/javafx/scene/control/skin/TextAreaSkin.java

Print this page
rev 9047 : RT-36454: [Modena, TextArea] Vertical scrollbar appears in TextArea and then disappears
   1 /*
   2  * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 335                         selectionHandle1.setLayoutY(b.getMinY() - selectionHandle1.getHeight() + 1);
 336                     } else {
 337                         selectionHandle2.setLayoutX(b.getMinX() - selectionHandle2.getWidth() / 2);
 338                         selectionHandle2.setLayoutY(b.getMaxY() - 1);
 339                     }
 340                 } else {
 341                     caretHandle.setLayoutX(b.getMinX() - caretHandle.getWidth() / 2 + 1);
 342                     caretHandle.setLayoutY(b.getMaxY());
 343                 }
 344             }
 345 
 346             if (scrollPane.getPrefViewportWidth() == 0
 347                 || scrollPane.getPrefViewportHeight() == 0) {
 348                 updatePrefViewportWidth();
 349                 updatePrefViewportHeight();
 350                 if (getParent() != null && scrollPane.getPrefViewportWidth() > 0
 351                                         || scrollPane.getPrefViewportHeight() > 0) {
 352                     // Force layout of viewRect in ScrollPaneSkin
 353                     getParent().requestLayout();
 354                 }















 355             }
 356         }
 357     }
 358 
 359     private ContentView contentView = new ContentView();
 360     private Group paragraphNodes = new Group();
 361 
 362     private Text promptNode;
 363     private ObservableBooleanValue usePromptText;
 364 
 365     private ObservableIntegerValue caretPosition;
 366     private Group selectionHighlightGroup = new Group();
 367 
 368     private ScrollPane scrollPane;
 369     private Bounds oldViewportBounds;
 370 
 371     private VerticalDirection scrollDirection = null;
 372 
 373     private Path characterBoundingPath = new Path();
 374 


   1 /*
   2  * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 335                         selectionHandle1.setLayoutY(b.getMinY() - selectionHandle1.getHeight() + 1);
 336                     } else {
 337                         selectionHandle2.setLayoutX(b.getMinX() - selectionHandle2.getWidth() / 2);
 338                         selectionHandle2.setLayoutY(b.getMaxY() - 1);
 339                     }
 340                 } else {
 341                     caretHandle.setLayoutX(b.getMinX() - caretHandle.getWidth() / 2 + 1);
 342                     caretHandle.setLayoutY(b.getMaxY());
 343                 }
 344             }
 345 
 346             if (scrollPane.getPrefViewportWidth() == 0
 347                 || scrollPane.getPrefViewportHeight() == 0) {
 348                 updatePrefViewportWidth();
 349                 updatePrefViewportHeight();
 350                 if (getParent() != null && scrollPane.getPrefViewportWidth() > 0
 351                                         || scrollPane.getPrefViewportHeight() > 0) {
 352                     // Force layout of viewRect in ScrollPaneSkin
 353                     getParent().requestLayout();
 354                 }
 355             }
 356 
 357             // RT-36454: Fit to width/height only if smaller than viewport.
 358             // That is, grow to fit but don't shrink to fit.
 359             Bounds viewportBounds = scrollPane.getViewportBounds();
 360             boolean wasFitToWidth = scrollPane.isFitToWidth();
 361             boolean wasFitToHeight = scrollPane.isFitToHeight();
 362             boolean setFitToWidth = textArea.isWrapText() || computePrefWidth(-1) <= viewportBounds.getWidth();
 363             boolean setFitToHeight = computePrefHeight(width) <= viewportBounds.getHeight();
 364             if (wasFitToWidth != setFitToWidth || wasFitToHeight != setFitToHeight) {
 365                 Platform.runLater(() -> {
 366                     scrollPane.setFitToWidth(setFitToWidth);
 367                     scrollPane.setFitToHeight(setFitToHeight);
 368                 });
 369                 getParent().requestLayout();
 370             }
 371         }
 372     }
 373 
 374     private ContentView contentView = new ContentView();
 375     private Group paragraphNodes = new Group();
 376 
 377     private Text promptNode;
 378     private ObservableBooleanValue usePromptText;
 379 
 380     private ObservableIntegerValue caretPosition;
 381     private Group selectionHighlightGroup = new Group();
 382 
 383     private ScrollPane scrollPane;
 384     private Bounds oldViewportBounds;
 385 
 386     private VerticalDirection scrollDirection = null;
 387 
 388     private Path characterBoundingPath = new Path();
 389