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
  23  * questions.
  24  */
  25 
  26 package javafx.scene.control.skin;
  27 
  28 import javafx.scene.Node;
  29 import javafx.scene.control.Label;
  30 import javafx.scene.control.Skin;
  31 import javafx.scene.control.Tooltip;
  32 
  33 /**
  34  * CSS based skin for Tooltip. It deals mostly with show hide logic for
  35  * Popup based controls, and specifically in this case for tooltip. It also
  36  * implements some of the Skin interface methods.
  37  *
  38  * TooltipContent class is the actual skin implementation of the tooltip.
  39  */
  40 public class TooltipSkin implements Skin<Tooltip> {
  41 
  42     /***************************************************************************
  43      *                                                                         *
  44      * Private fields                                                          *
  45      *                                                                         *
  46      **************************************************************************/
  47 
  48     private Label tipLabel;
  49 
  50     private Tooltip tooltip;
  51 
  52 
  53 
  54     /***************************************************************************
  55      *                                                                         *
  56      * Constructors                                                            *
  57      *                                                                         *
  58      **************************************************************************/
  59 
  60     /**
  61      * Creates a new TooltipSkin instance for the given {@link Tooltip}.
  62      * @param t the tooltip
  63      */
  64     public TooltipSkin(Tooltip t) {
  65         this.tooltip = t;
  66         tipLabel = new Label();
  67         tipLabel.contentDisplayProperty().bind(t.contentDisplayProperty());
  68         tipLabel.fontProperty().bind(t.fontProperty());
  69         tipLabel.graphicProperty().bind(t.graphicProperty());
  70         tipLabel.graphicTextGapProperty().bind(t.graphicTextGapProperty());
  71         tipLabel.textAlignmentProperty().bind(t.textAlignmentProperty());
  72         tipLabel.textOverrunProperty().bind(t.textOverrunProperty());
  73         tipLabel.textProperty().bind(t.textProperty());
  74         tipLabel.wrapTextProperty().bind(t.wrapTextProperty());
  75         tipLabel.minWidthProperty().bind(t.minWidthProperty());
  76         tipLabel.prefWidthProperty().bind(t.prefWidthProperty());
  77         tipLabel.maxWidthProperty().bind(t.maxWidthProperty());
  78         tipLabel.minHeightProperty().bind(t.minHeightProperty());
  79         tipLabel.prefHeightProperty().bind(t.prefHeightProperty());
  80         tipLabel.maxHeightProperty().bind(t.maxHeightProperty());
  81 
  82         // RT-7512 - skin needs to have styleClass of the control
  83         // TODO - This needs to be bound together, not just set! Probably should
  84         // do the same for id and style as well.
  85         tipLabel.getStyleClass().setAll(t.getStyleClass());
  86         tipLabel.setStyle(t.getStyle());
  87         tipLabel.setId(t.getId());
  88     }
  89 
  90 
  91 
  92     /***************************************************************************
  93      *                                                                         *
  94      * Public API                                                              *
  95      *                                                                         *
  96      **************************************************************************/
  97 
  98     /** {@inheritDoc} */
  99     @Override public Tooltip getSkinnable() {
 100         return tooltip;
 101     }
 102 
 103     /** {@inheritDoc} */
 104     @Override public Node getNode() {
 105         return tipLabel;
 106     }
 107 
 108     /** {@inheritDoc} */
 109     @Override public void dispose() {
 110         tooltip = null;
 111         tipLabel = null;
 112     }
 113 }