< prev index next >

modules/controls/src/main/java/javafx/scene/control/Labeled.java

Print this page




  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;
  27 
  28 
  29 import com.sun.javafx.css.StyleManager;

  30 import javafx.css.converter.BooleanConverter;
  31 import javafx.css.converter.EnumConverter;
  32 import javafx.css.converter.InsetsConverter;
  33 import javafx.css.converter.PaintConverter;
  34 import javafx.css.converter.SizeConverter;
  35 import javafx.css.converter.StringConverter;
  36 
  37 import java.util.ArrayList;
  38 import java.util.Collections;
  39 import java.util.List;
  40 
  41 import javafx.beans.property.BooleanProperty;
  42 import javafx.beans.property.DoubleProperty;
  43 import javafx.beans.property.ObjectProperty;
  44 import javafx.beans.property.ReadOnlyObjectProperty;
  45 import javafx.beans.property.SimpleBooleanProperty;
  46 import javafx.beans.property.SimpleStringProperty;
  47 import javafx.beans.property.StringProperty;
  48 import javafx.beans.value.WritableValue;
  49 import javafx.geometry.Insets;


 313         return isWrapText()? Orientation.HORIZONTAL : null;
 314     }
 315 
 316     /**
 317      * The default font to use for text in the Labeled. If the Label's text is
 318      * rich text then this font may or may not be used depending on the font
 319      * information embedded in the rich text, but in any case where a default
 320      * font is required, this font will be used.
 321      */
 322     public final ObjectProperty<Font> fontProperty() {
 323 
 324         if (font == null) {
 325             font = new StyleableObjectProperty<Font>(Font.getDefault()) {
 326 
 327                 private boolean fontSetByCss = false;
 328 
 329                 @Override
 330                 public void applyStyle(StyleOrigin newOrigin, Font value) {
 331 
 332                     //
 333                     // RT-20727 - if CSS is setting the font, then make sure invalidate doesn't call impl_reapplyCSS
 334                     //
 335                     try {
 336                         // super.applyStyle calls set which might throw if value is bound.
 337                         // Have to make sure fontSetByCss is reset.
 338                         fontSetByCss = true;
 339                         super.applyStyle(newOrigin, value);
 340                     } catch(Exception e) {
 341                         throw e;
 342                     } finally {
 343                         fontSetByCss = false;
 344                     }
 345                 }
 346 
 347                 @Override
 348                 public void set(Font value) {
 349 
 350                     final Font oldValue = get();
 351                     if (value != null ? !value.equals(oldValue) : oldValue != null) {
 352                         super.set(value);
 353                     }
 354 
 355                 }
 356 
 357                 @Override
 358                 protected void invalidated() {
 359                     // RT-20727 - if font is changed by calling setFont, then
 360                     // css might need to be reapplied since font size affects
 361                     // calculated values for styles with relative values
 362                     if(fontSetByCss == false) {
 363                         Labeled.this.impl_reapplyCSS();
 364                     }
 365                 }
 366 
 367                 @Override
 368                 public CssMetaData<Labeled,Font> getCssMetaData() {
 369                     return StyleableProperties.FONT;
 370                 }
 371 
 372                 @Override
 373                 public Object getBean() {
 374                     return Labeled.this;
 375                 }
 376 
 377                 @Override
 378                 public String getName() {
 379                     return "font";
 380                 }
 381             };
 382         }
 383         return font;




  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;
  27 
  28 
  29 import com.sun.javafx.css.StyleManager;
  30 import com.sun.javafx.scene.NodeHelper;
  31 import javafx.css.converter.BooleanConverter;
  32 import javafx.css.converter.EnumConverter;
  33 import javafx.css.converter.InsetsConverter;
  34 import javafx.css.converter.PaintConverter;
  35 import javafx.css.converter.SizeConverter;
  36 import javafx.css.converter.StringConverter;
  37 
  38 import java.util.ArrayList;
  39 import java.util.Collections;
  40 import java.util.List;
  41 
  42 import javafx.beans.property.BooleanProperty;
  43 import javafx.beans.property.DoubleProperty;
  44 import javafx.beans.property.ObjectProperty;
  45 import javafx.beans.property.ReadOnlyObjectProperty;
  46 import javafx.beans.property.SimpleBooleanProperty;
  47 import javafx.beans.property.SimpleStringProperty;
  48 import javafx.beans.property.StringProperty;
  49 import javafx.beans.value.WritableValue;
  50 import javafx.geometry.Insets;


 314         return isWrapText()? Orientation.HORIZONTAL : null;
 315     }
 316 
 317     /**
 318      * The default font to use for text in the Labeled. If the Label's text is
 319      * rich text then this font may or may not be used depending on the font
 320      * information embedded in the rich text, but in any case where a default
 321      * font is required, this font will be used.
 322      */
 323     public final ObjectProperty<Font> fontProperty() {
 324 
 325         if (font == null) {
 326             font = new StyleableObjectProperty<Font>(Font.getDefault()) {
 327 
 328                 private boolean fontSetByCss = false;
 329 
 330                 @Override
 331                 public void applyStyle(StyleOrigin newOrigin, Font value) {
 332 
 333                     //
 334                     // RT-20727 - if CSS is setting the font, then make sure invalidate doesn't call NodeHelper.reapplyCSS
 335                     //
 336                     try {
 337                         // super.applyStyle calls set which might throw if value is bound.
 338                         // Have to make sure fontSetByCss is reset.
 339                         fontSetByCss = true;
 340                         super.applyStyle(newOrigin, value);
 341                     } catch(Exception e) {
 342                         throw e;
 343                     } finally {
 344                         fontSetByCss = false;
 345                     }
 346                 }
 347 
 348                 @Override
 349                 public void set(Font value) {
 350 
 351                     final Font oldValue = get();
 352                     if (value != null ? !value.equals(oldValue) : oldValue != null) {
 353                         super.set(value);
 354                     }
 355 
 356                 }
 357 
 358                 @Override
 359                 protected void invalidated() {
 360                     // RT-20727 - if font is changed by calling setFont, then
 361                     // css might need to be reapplied since font size affects
 362                     // calculated values for styles with relative values
 363                     if(fontSetByCss == false) {
 364                         NodeHelper.reapplyCSS(Labeled.this);
 365                     }
 366                 }
 367 
 368                 @Override
 369                 public CssMetaData<Labeled,Font> getCssMetaData() {
 370                     return StyleableProperties.FONT;
 371                 }
 372 
 373                 @Override
 374                 public Object getBean() {
 375                     return Labeled.this;
 376                 }
 377 
 378                 @Override
 379                 public String getName() {
 380                     return "font";
 381                 }
 382             };
 383         }
 384         return font;


< prev index next >