modules/web/src/main/java/com/sun/javafx/webkit/theme/ScrollBarThemeImpl.java

Print this page
rev 9240 : 8076423: JEP 253: Prepare JavaFX UI Controls & CSS APIs for Modularization


  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
  23  * questions.
  24  */
  25 
  26 package com.sun.javafx.webkit.theme;
  27 
  28 import java.lang.ref.WeakReference;
  29 import java.util.logging.Level;
  30 import java.util.logging.Logger;
  31 
  32 import com.sun.javafx.util.Utils;
  33 import javafx.beans.Observable;
  34 import javafx.geometry.Orientation;
  35 import javafx.scene.Node;
  36 import javafx.scene.control.Control;
  37 import javafx.scene.control.ScrollBar;
  38 
  39 import com.sun.javafx.scene.control.skin.ScrollBarSkin;
  40 import com.sun.webkit.graphics.Ref;
  41 import com.sun.webkit.graphics.ScrollBarTheme;
  42 import com.sun.webkit.graphics.WCGraphicsContext;
  43 import com.sun.javafx.webkit.Accessor;
  44 import com.sun.javafx.webkit.theme.RenderThemeImpl.Pool;
  45 import com.sun.javafx.webkit.theme.RenderThemeImpl.ViewListener;
  46 import com.sun.javafx.webkit.theme.RenderThemeImpl.Widget;
  47 import com.sun.javafx.webkit.theme.RenderThemeImpl.WidgetType;
  48 import com.sun.webkit.graphics.WCSize;
  49 
  50 public final class ScrollBarThemeImpl extends ScrollBarTheme {
  51 
  52     private final static Logger log = Logger.getLogger(ScrollBarThemeImpl.class.getName());
  53 
  54     private WeakReference<ScrollBar> testSBRef = // used for hit testing
  55             new WeakReference<ScrollBar>(null);
  56 
  57     private boolean thicknessInitialized = false;
  58 
  59     private final Accessor accessor;


 389         int pos = thumbPosition();
 390         log.log(Level.FINEST, "thumb position: {0}", pos);
 391         return pos;
 392     }
 393 
 394     private void initializeThickness() {
 395         if (!thicknessInitialized) {
 396             ScrollBar testSB = testSBRef.get();
 397             if (testSB == null) {
 398                 return;
 399             }
 400             int thickness = (int) testSB.prefWidth(-1);
 401             if (thickness != 0 && ScrollBarTheme.getThickness() != thickness) {
 402                 ScrollBarTheme.setThickness(thickness);
 403             }
 404             thicknessInitialized = true;
 405         }
 406     }
 407 
 408     private static Node getThumb(ScrollBar scrollBar) {
 409         return ((ScrollBarSkin)scrollBar.getSkin()).getThumb();

 410     }
 411 
 412     private static Node getTrack(ScrollBar scrollBar) {
 413         return ((ScrollBarSkin)scrollBar.getSkin()).getTrack();

 414     }
 415 
 416     private static Node getIncButton(ScrollBar scrollBar) {
 417         return ((ScrollBarSkin)scrollBar.getSkin()).getIncButton();

 418     }
 419 
 420     private static Node getDecButton(ScrollBar scrollBar) {
 421         return ((ScrollBarSkin)scrollBar.getSkin()).getDecButton();










 422     }
 423 }


  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
  23  * questions.
  24  */
  25 
  26 package com.sun.javafx.webkit.theme;
  27 
  28 import java.lang.ref.WeakReference;
  29 import java.util.logging.Level;
  30 import java.util.logging.Logger;
  31 
  32 import com.sun.javafx.util.Utils;
  33 import javafx.beans.Observable;
  34 import javafx.geometry.Orientation;
  35 import javafx.scene.Node;
  36 import javafx.scene.control.Control;
  37 import javafx.scene.control.ScrollBar;
  38 
  39 import javafx.scene.control.skin.ScrollBarSkin;
  40 import com.sun.webkit.graphics.Ref;
  41 import com.sun.webkit.graphics.ScrollBarTheme;
  42 import com.sun.webkit.graphics.WCGraphicsContext;
  43 import com.sun.javafx.webkit.Accessor;
  44 import com.sun.javafx.webkit.theme.RenderThemeImpl.Pool;
  45 import com.sun.javafx.webkit.theme.RenderThemeImpl.ViewListener;
  46 import com.sun.javafx.webkit.theme.RenderThemeImpl.Widget;
  47 import com.sun.javafx.webkit.theme.RenderThemeImpl.WidgetType;
  48 import com.sun.webkit.graphics.WCSize;
  49 
  50 public final class ScrollBarThemeImpl extends ScrollBarTheme {
  51 
  52     private final static Logger log = Logger.getLogger(ScrollBarThemeImpl.class.getName());
  53 
  54     private WeakReference<ScrollBar> testSBRef = // used for hit testing
  55             new WeakReference<ScrollBar>(null);
  56 
  57     private boolean thicknessInitialized = false;
  58 
  59     private final Accessor accessor;


 389         int pos = thumbPosition();
 390         log.log(Level.FINEST, "thumb position: {0}", pos);
 391         return pos;
 392     }
 393 
 394     private void initializeThickness() {
 395         if (!thicknessInitialized) {
 396             ScrollBar testSB = testSBRef.get();
 397             if (testSB == null) {
 398                 return;
 399             }
 400             int thickness = (int) testSB.prefWidth(-1);
 401             if (thickness != 0 && ScrollBarTheme.getThickness() != thickness) {
 402                 ScrollBarTheme.setThickness(thickness);
 403             }
 404             thicknessInitialized = true;
 405         }
 406     }
 407 
 408     private static Node getThumb(ScrollBar scrollBar) {
 409 //        return ((ScrollBarSkin)scrollBar.getSkin()).getThumb();
 410         return findNode(scrollBar, "thumb");
 411     }
 412 
 413     private static Node getTrack(ScrollBar scrollBar) {
 414 //        return ((ScrollBarSkin)scrollBar.getSkin()).getTrack();
 415         return findNode(scrollBar, "track");
 416     }
 417 
 418     private static Node getIncButton(ScrollBar scrollBar) {
 419 //        return ((ScrollBarSkin)scrollBar.getSkin()).getIncrementButton();
 420         return findNode(scrollBar, "increment-button");
 421     }
 422 
 423     private static Node getDecButton(ScrollBar scrollBar) {
 424 //        return ((ScrollBarSkin)scrollBar.getSkin()).getDecrementButton();
 425         return findNode(scrollBar, "decrement-button");
 426     }
 427 
 428     private static Node findNode(ScrollBar scrollBar, String styleclass) {
 429         for (Node n : scrollBar.getChildrenUnmodifiable()) {
 430             if (n.getStyleClass().contains(styleclass)) {
 431                 return n;
 432             }
 433         }
 434         return null;
 435     }
 436 }