< prev index next >

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

Print this page




 118         setText(text);
 119     }
 120 
 121     /**
 122      * Creates a Label with text and a graphic
 123      * @param text The text for the label.
 124      * @param graphic The graphic for the label.
 125      */
 126     public Labeled(String text, Node graphic) {
 127         setText(text);
 128         ((StyleableProperty<Node>)(WritableValue<Node>)graphicProperty()).applyStyle(null, graphic);
 129     }
 130 
 131     /***************************************************************************
 132      *                                                                         *
 133      * Properties                                                              *
 134      *                                                                         *
 135      **************************************************************************/
 136     /**
 137      * The text to display in the label. The text may be null.

 138      */
 139     public final StringProperty textProperty() {
 140         if (text == null) {
 141             text = new SimpleStringProperty(this, "text", "");
 142         }
 143         return text;
 144     }
 145     private StringProperty text;
 146     public final void setText(String value) { textProperty().setValue(value); }
 147     public final String getText() { return text == null ? "" : text.getValue(); }
 148 
 149     /**
 150      * Specifies how the text and graphic within the Labeled should be
 151      * aligned when there is empty space within the Labeled.

 152      */
 153     public final ObjectProperty<Pos> alignmentProperty() {
 154         if (alignment == null) {
 155             alignment = new StyleableObjectProperty<Pos>(Pos.CENTER_LEFT) {
 156 
 157                 @Override public CssMetaData<Labeled,Pos> getCssMetaData() {
 158                     return StyleableProperties.ALIGNMENT;
 159                 }
 160 
 161                 @Override
 162                 public Object getBean() {
 163                     return Labeled.this;
 164                 }
 165 
 166                 @Override
 167                 public String getName() {
 168                     return "alignment";
 169                 }
 170             };
 171         }
 172         return alignment;
 173     }
 174     private ObjectProperty<Pos> alignment;
 175     public final void setAlignment(Pos value) { alignmentProperty().set(value); }
 176     public final Pos getAlignment() { return alignment == null ? Pos.CENTER_LEFT : alignment.get(); }
 177 
 178 
 179     /**
 180      * Specifies the behavior for lines of text <em>when text is multiline</em>
 181      * Unlike {@link #contentDisplayProperty} which affects the graphic and text, this setting
 182      * only affects multiple lines of text relative to the text bounds.

 183      */
 184     public final ObjectProperty<TextAlignment> textAlignmentProperty() {
 185         if (textAlignment == null) {
 186             textAlignment = new StyleableObjectProperty<TextAlignment>(TextAlignment.LEFT) {
 187 
 188                 @Override
 189                 public CssMetaData<Labeled,TextAlignment> getCssMetaData() {
 190                     return StyleableProperties.TEXT_ALIGNMENT;
 191                 }
 192 
 193                 @Override
 194                 public Object getBean() {
 195                     return Labeled.this;
 196                 }
 197 
 198                 @Override
 199                 public String getName() {
 200                     return "textAlignment";
 201                 }
 202             };
 203         }
 204         return textAlignment;
 205     }
 206     private ObjectProperty<TextAlignment> textAlignment;
 207     public final void setTextAlignment(TextAlignment value) { textAlignmentProperty().setValue(value); }
 208     public final TextAlignment getTextAlignment() { return textAlignment == null ? TextAlignment.LEFT : textAlignment.getValue(); }
 209 
 210     /**
 211      * Specifies the behavior to use if the text of the {@code Labeled}
 212      * exceeds the available space for rendering the text.

 213      */
 214     public final ObjectProperty<OverrunStyle> textOverrunProperty() {
 215         if (textOverrun == null) {
 216             textOverrun = new StyleableObjectProperty<OverrunStyle>(OverrunStyle.ELLIPSIS) {
 217 
 218                 @Override
 219                 public CssMetaData<Labeled,OverrunStyle> getCssMetaData() {
 220                     return StyleableProperties.TEXT_OVERRUN;
 221                 }
 222 
 223                 @Override
 224                 public Object getBean() {
 225                     return Labeled.this;
 226                 }
 227 
 228                 @Override
 229                 public String getName() {
 230                     return "textOverrun";
 231                 }
 232             };
 233         }
 234         return textOverrun;
 235     }
 236     private ObjectProperty<OverrunStyle> textOverrun;
 237     public final void setTextOverrun(OverrunStyle value) { textOverrunProperty().setValue(value); }
 238     public final OverrunStyle getTextOverrun() { return textOverrun == null ? OverrunStyle.ELLIPSIS : textOverrun.getValue(); }
 239 
 240     /**
 241      * Specifies the string to display for the ellipsis when text is truncated.
 242      *
 243      * <table border="0" cellpadding="0" cellspacing="0"><tr><th>Examples</th></tr>
 244      *   <tr class="altColor"><td align="right">"..."</td>        <td>- Default value for most locales</td>
 245      *   <tr class="rowColor"><td align="right">" . . . "</td>    <td></td>
 246      *   <tr class="altColor"><td align="right">" [...] "</td>    <td></td>
 247      *   <tr class="rowColor"><td align="right">"\u2026"</td> <td>- The Unicode ellipsis character '&hellip;'</td>
 248      *   <tr class="altColor"><td align="right">""</td>           <td>- No ellipsis, just display the truncated string</td>
 249      * </table>
 250      *
 251      * <p>Note that not all fonts support all Unicode characters.
 252      *


 253      * @see <a href="http://en.wikipedia.org/wiki/Ellipsis#Computer_representations">Wikipedia:ellipsis</a>
 254      * @since JavaFX 2.2
 255      */
 256     public final StringProperty ellipsisStringProperty() {
 257         if (ellipsisString == null) {
 258             ellipsisString = new StyleableStringProperty(DEFAULT_ELLIPSIS_STRING) {
 259                 @Override public Object getBean() {
 260                     return Labeled.this;
 261                 }
 262 
 263                 @Override public String getName() {
 264                     return "ellipsisString";
 265                 }
 266 
 267                 @Override public CssMetaData<Labeled,String> getCssMetaData() {
 268                     return StyleableProperties.ELLIPSIS_STRING;
 269                 }
 270             };
 271         }
 272         return ellipsisString;
 273     }
 274     private StringProperty ellipsisString;
 275     public final void setEllipsisString(String value) { ellipsisStringProperty().set((value == null) ? "" : value); }
 276     public final String getEllipsisString() { return ellipsisString == null ? DEFAULT_ELLIPSIS_STRING : ellipsisString.get(); }
 277 
 278 
 279     /**
 280      * If a run of text exceeds the width of the Labeled, then this variable
 281      * indicates whether the text should wrap onto another line.

 282      */
 283     public final BooleanProperty wrapTextProperty() {
 284         if (wrapText == null) {
 285             wrapText = new StyleableBooleanProperty() {
 286 
 287                 @Override
 288                 public CssMetaData<Labeled,Boolean> getCssMetaData() {
 289                     return StyleableProperties.WRAP_TEXT;
 290                 }
 291 
 292                 @Override
 293                 public Object getBean() {
 294                     return Labeled.this;
 295                 }
 296 
 297                 @Override
 298                 public String getName() {
 299                     return "wrapText";
 300                 }
 301             };
 302         }
 303         return wrapText;
 304     }
 305     private BooleanProperty wrapText;
 306     public final void setWrapText(boolean value) { wrapTextProperty().setValue(value); }
 307     public final boolean isWrapText() { return wrapText == null ? false : wrapText.getValue(); }
 308 
 309     /**
 310      * If wrapText is true, then contentBias will be HORIZONTAL, otherwise it is null.
 311      * @return orientation of width/height dependency or null if there is none
 312      */
 313     @Override public Orientation getContentBias() {
 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) {


 377 
 378                 @Override
 379                 public String getName() {
 380                     return "font";
 381                 }
 382             };
 383         }
 384         return font;
 385     }
 386     private ObjectProperty<Font> font;
 387     public final void setFont(Font value) { fontProperty().setValue(value); }
 388     public final Font getFont() { return font == null ? Font.getDefault() : font.getValue(); }
 389 
 390 
 391     /**
 392      * An optional icon for the Labeled. This can be positioned relative to the
 393      * text by using {@link #setContentDisplay}.  The node specified for this
 394      * variable cannot appear elsewhere in the scene graph, otherwise
 395      * the {@code IllegalArgumentException} is thrown.  See the class
 396      * description of {@link javafx.scene.Node Node} for more detail.

 397      */
 398     public final ObjectProperty<Node> graphicProperty() {
 399         if (graphic == null) {
 400             graphic = new StyleableObjectProperty<Node>() {
 401 
 402                 // The graphic is styleable by css, but it is the
 403                 // imageUrlProperty that handles the style value.
 404                 @Override
 405                 public CssMetaData getCssMetaData() {
 406                     return StyleableProperties.GRAPHIC;
 407                 }
 408 
 409                 @Override
 410                 public Object getBean() {
 411                     return Labeled.this;
 412                 }
 413 
 414                 @Override
 415                 public String getName() {
 416                     return "graphic";


 534                     return Labeled.this;
 535                 }
 536 
 537                 @Override
 538                 public String getName() {
 539                     return "imageUrl";
 540                 }
 541 
 542                 @Override
 543                 public CssMetaData<Labeled,String> getCssMetaData() {
 544                     return StyleableProperties.GRAPHIC;
 545                 }
 546 
 547             };
 548         }
 549         return imageUrl;
 550     }
 551 
 552     /**
 553      * Whether all text should be underlined.

 554      */
 555     public final BooleanProperty underlineProperty() {
 556         if (underline == null) {
 557             underline = new StyleableBooleanProperty(false) {
 558 
 559                 @Override
 560                 public CssMetaData<Labeled, Boolean> getCssMetaData() {
 561                     return StyleableProperties.UNDERLINE;
 562                 }
 563 
 564                 @Override
 565                 public Object getBean() {
 566                     return Labeled.this;
 567                 }
 568 
 569                 @Override
 570                 public String getName() {
 571                     return "underline";
 572                 }
 573             };
 574         }
 575         return underline;
 576     }
 577     private BooleanProperty underline;
 578     public final void setUnderline(boolean value) { underlineProperty().setValue(value); }
 579     public final boolean isUnderline() { return underline == null ? false : underline.getValue(); }
 580 
 581     /**
 582      * Specifies the space in pixel between lines.

 583      * @since JavaFX 8.0
 584      */
 585     public final DoubleProperty lineSpacingProperty() {
 586         if (lineSpacing == null) {
 587             lineSpacing = new StyleableDoubleProperty(0) {
 588 
 589                 @Override
 590                 public CssMetaData<Labeled,Number> getCssMetaData() {
 591                     return StyleableProperties.LINE_SPACING;
 592                 }
 593 
 594                 @Override
 595                 public Object getBean() {
 596                     return Labeled.this;
 597                 }
 598 
 599                 @Override
 600                 public String getName() {
 601                     return "lineSpacing";
 602                 }
 603             };
 604         }
 605         return lineSpacing;
 606     }
 607     private DoubleProperty lineSpacing;
 608     public final void setLineSpacing(double value) { lineSpacingProperty().setValue(value); }
 609     public final double getLineSpacing() { return lineSpacing == null ? 0 : lineSpacing.getValue(); }
 610 
 611     /**
 612      * Specifies the positioning of the graphic relative to the text.

 613      */
 614     public final ObjectProperty<ContentDisplay> contentDisplayProperty() {
 615         if (contentDisplay == null) {
 616             contentDisplay = new StyleableObjectProperty<ContentDisplay>(ContentDisplay.LEFT) {
 617 
 618                 @Override
 619                 public CssMetaData<Labeled,ContentDisplay> getCssMetaData() {
 620                     return StyleableProperties.CONTENT_DISPLAY;
 621                 }
 622 
 623                 @Override
 624                 public Object getBean() {
 625                     return Labeled.this;
 626                 }
 627 
 628                 @Override
 629                 public String getName() {
 630                     return "contentDisplay";
 631                 }
 632             };
 633         }
 634         return contentDisplay;
 635     }
 636     private ObjectProperty<ContentDisplay> contentDisplay;
 637     public final void setContentDisplay(ContentDisplay value) { contentDisplayProperty().setValue(value); }
 638     public final ContentDisplay getContentDisplay() { return contentDisplay == null ? ContentDisplay.LEFT : contentDisplay.getValue(); }
 639 
 640     /**
 641      * The padding around the Labeled's text and graphic content.
 642      * By default labelPadding is Insets.EMPTY and cannot be set to null.
 643      * Subclasses may add nodes outside this padding and inside the Labeled's padding.
 644      *
 645      * This property can only be set from CSS.

 646      */
 647     public final ReadOnlyObjectProperty<Insets> labelPaddingProperty() {
 648         return labelPaddingPropertyImpl();
 649     }
 650     private ObjectProperty<Insets> labelPaddingPropertyImpl() {
 651         if (labelPadding == null) {
 652             labelPadding = new StyleableObjectProperty<Insets>(Insets.EMPTY) {
 653                 private Insets lastValidValue = Insets.EMPTY;
 654 
 655                 @Override
 656                 public void invalidated() {
 657                     final Insets newValue = get();
 658                     if (newValue == null) {
 659                         set(lastValidValue);
 660                         throw new NullPointerException("cannot set labelPadding to null");
 661                     }
 662                     lastValidValue = newValue;
 663                     requestLayout();
 664                 }
 665 


 670 
 671                 @Override
 672                 public Object getBean() {
 673                     return Labeled.this;
 674                 }
 675 
 676                 @Override
 677                 public String getName() {
 678                     return "labelPadding";
 679                 }
 680             };
 681         }
 682         return labelPadding;
 683     }
 684     private ObjectProperty<Insets> labelPadding;
 685     private void setLabelPadding(Insets value) { labelPaddingPropertyImpl().set(value); }
 686     public final Insets getLabelPadding() { return labelPadding == null ? Insets.EMPTY : labelPadding.get(); }
 687 
 688     /**
 689      * The amount of space between the graphic and text

 690      */
 691     public final DoubleProperty graphicTextGapProperty() {
 692         if (graphicTextGap == null) {
 693             graphicTextGap = new StyleableDoubleProperty(4) {
 694 
 695                 @Override
 696                 public CssMetaData<Labeled,Number> getCssMetaData() {
 697                     return StyleableProperties.GRAPHIC_TEXT_GAP;
 698                 }
 699 
 700                 @Override
 701                 public Object getBean() {
 702                     return Labeled.this;
 703                 }
 704 
 705                 @Override
 706                 public String getName() {
 707                     return "graphicTextGap";
 708                 }
 709             };


 791     //     */
 792 
 793     @Override public String toString() {
 794         StringBuilder builder =
 795             new StringBuilder(super.toString())
 796                 .append("'").append(getText()).append("'");
 797         return builder.toString();
 798     }
 799 
 800     /***************************************************************************
 801      *                                                                         *
 802      * Stylesheet Handling                                                     *
 803      *                                                                         *
 804      **************************************************************************/
 805 
 806     /**
 807      * Returns the initial alignment state of this control, for use
 808      * by the JavaFX CSS engine to correctly set its initial value. This method
 809      * is overridden to use Pos.CENTER_LEFT initially.
 810      *

 811      * @since 9
 812      */
 813     protected Pos getInitialAlignment() {
 814         return Pos.CENTER_LEFT;
 815     }
 816 
 817     private static class StyleableProperties {
 818         private static final FontCssMetaData<Labeled> FONT =
 819             new FontCssMetaData<Labeled>("-fx-font", Font.getDefault()) {
 820 
 821             @Override
 822             public boolean isSettable(Labeled n) {
 823                 return n.font == null || !n.font.isBound();
 824             }
 825 
 826             @Override
 827             public StyleableProperty<Font> getStyleableProperty(Labeled n) {
 828                 return (StyleableProperty<Font>)(WritableValue<Font>)n.fontProperty();
 829             }
 830         };




 118         setText(text);
 119     }
 120 
 121     /**
 122      * Creates a Label with text and a graphic
 123      * @param text The text for the label.
 124      * @param graphic The graphic for the label.
 125      */
 126     public Labeled(String text, Node graphic) {
 127         setText(text);
 128         ((StyleableProperty<Node>)(WritableValue<Node>)graphicProperty()).applyStyle(null, graphic);
 129     }
 130 
 131     /***************************************************************************
 132      *                                                                         *
 133      * Properties                                                              *
 134      *                                                                         *
 135      **************************************************************************/
 136     /**
 137      * The text to display in the label. The text may be null.
 138      * @return the text to display in the label
 139      */
 140     public final StringProperty textProperty() {
 141         if (text == null) {
 142             text = new SimpleStringProperty(this, "text", "");
 143         }
 144         return text;
 145     }
 146     private StringProperty text;
 147     public final void setText(String value) { textProperty().setValue(value); }
 148     public final String getText() { return text == null ? "" : text.getValue(); }
 149 
 150     /**
 151      * Specifies how the text and graphic within the Labeled should be
 152      * aligned when there is empty space within the Labeled.
 153      * @return the alignment within this labeled
 154      */
 155     public final ObjectProperty<Pos> alignmentProperty() {
 156         if (alignment == null) {
 157             alignment = new StyleableObjectProperty<Pos>(Pos.CENTER_LEFT) {
 158 
 159                 @Override public CssMetaData<Labeled,Pos> getCssMetaData() {
 160                     return StyleableProperties.ALIGNMENT;
 161                 }
 162 
 163                 @Override
 164                 public Object getBean() {
 165                     return Labeled.this;
 166                 }
 167 
 168                 @Override
 169                 public String getName() {
 170                     return "alignment";
 171                 }
 172             };
 173         }
 174         return alignment;
 175     }
 176     private ObjectProperty<Pos> alignment;
 177     public final void setAlignment(Pos value) { alignmentProperty().set(value); }
 178     public final Pos getAlignment() { return alignment == null ? Pos.CENTER_LEFT : alignment.get(); }
 179 
 180 
 181     /**
 182      * Specifies the behavior for lines of text <em>when text is multiline</em>
 183      * Unlike {@link #contentDisplayProperty} which affects the graphic and text, this setting
 184      * only affects multiple lines of text relative to the text bounds.
 185      * @return the alignment of lines of text within this labeled
 186      */
 187     public final ObjectProperty<TextAlignment> textAlignmentProperty() {
 188         if (textAlignment == null) {
 189             textAlignment = new StyleableObjectProperty<TextAlignment>(TextAlignment.LEFT) {
 190 
 191                 @Override
 192                 public CssMetaData<Labeled,TextAlignment> getCssMetaData() {
 193                     return StyleableProperties.TEXT_ALIGNMENT;
 194                 }
 195 
 196                 @Override
 197                 public Object getBean() {
 198                     return Labeled.this;
 199                 }
 200 
 201                 @Override
 202                 public String getName() {
 203                     return "textAlignment";
 204                 }
 205             };
 206         }
 207         return textAlignment;
 208     }
 209     private ObjectProperty<TextAlignment> textAlignment;
 210     public final void setTextAlignment(TextAlignment value) { textAlignmentProperty().setValue(value); }
 211     public final TextAlignment getTextAlignment() { return textAlignment == null ? TextAlignment.LEFT : textAlignment.getValue(); }
 212 
 213     /**
 214      * Specifies the behavior to use if the text of the {@code Labeled}
 215      * exceeds the available space for rendering the text.
 216      * @return the overrun behavior if the text exceeds the available space
 217      */
 218     public final ObjectProperty<OverrunStyle> textOverrunProperty() {
 219         if (textOverrun == null) {
 220             textOverrun = new StyleableObjectProperty<OverrunStyle>(OverrunStyle.ELLIPSIS) {
 221 
 222                 @Override
 223                 public CssMetaData<Labeled,OverrunStyle> getCssMetaData() {
 224                     return StyleableProperties.TEXT_OVERRUN;
 225                 }
 226 
 227                 @Override
 228                 public Object getBean() {
 229                     return Labeled.this;
 230                 }
 231 
 232                 @Override
 233                 public String getName() {
 234                     return "textOverrun";
 235                 }
 236             };
 237         }
 238         return textOverrun;
 239     }
 240     private ObjectProperty<OverrunStyle> textOverrun;
 241     public final void setTextOverrun(OverrunStyle value) { textOverrunProperty().setValue(value); }
 242     public final OverrunStyle getTextOverrun() { return textOverrun == null ? OverrunStyle.ELLIPSIS : textOverrun.getValue(); }
 243 
 244     /**
 245      * Specifies the string to display for the ellipsis when text is truncated.
 246      *
 247      * <table summary="" border="0" cellpadding="0" cellspacing="0"><tr><th>Examples</th></tr>
 248      *   <tr class="altColor"><td align="right">"..."</td>        <td>- Default value for most locales</td>
 249      *   <tr class="rowColor"><td align="right">" . . . "</td>    <td></td>
 250      *   <tr class="altColor"><td align="right">" [...] "</td>    <td></td>
 251      *   <tr class="rowColor"><td align="right">"\u2026"</td> <td>- The Unicode ellipsis character '&hellip;'</td>
 252      *   <tr class="altColor"><td align="right">""</td>           <td>- No ellipsis, just display the truncated string</td>
 253      * </table>
 254      *
 255      * <p>Note that not all fonts support all Unicode characters.
 256      *
 257      * @return the ellipsis property on the string to display for the ellipsis
 258      * when text is truncated
 259      * @see <a href="http://en.wikipedia.org/wiki/Ellipsis#Computer_representations">Wikipedia:ellipsis</a>
 260      * @since JavaFX 2.2
 261      */
 262     public final StringProperty ellipsisStringProperty() {
 263         if (ellipsisString == null) {
 264             ellipsisString = new StyleableStringProperty(DEFAULT_ELLIPSIS_STRING) {
 265                 @Override public Object getBean() {
 266                     return Labeled.this;
 267                 }
 268 
 269                 @Override public String getName() {
 270                     return "ellipsisString";
 271                 }
 272 
 273                 @Override public CssMetaData<Labeled,String> getCssMetaData() {
 274                     return StyleableProperties.ELLIPSIS_STRING;
 275                 }
 276             };
 277         }
 278         return ellipsisString;
 279     }
 280     private StringProperty ellipsisString;
 281     public final void setEllipsisString(String value) { ellipsisStringProperty().set((value == null) ? "" : value); }
 282     public final String getEllipsisString() { return ellipsisString == null ? DEFAULT_ELLIPSIS_STRING : ellipsisString.get(); }
 283 
 284 
 285     /**
 286      * If a run of text exceeds the width of the Labeled, then this variable
 287      * indicates whether the text should wrap onto another line.
 288      * @return the wrap property if a run of text exceeds the width of the Labeled
 289      */
 290     public final BooleanProperty wrapTextProperty() {
 291         if (wrapText == null) {
 292             wrapText = new StyleableBooleanProperty() {
 293 
 294                 @Override
 295                 public CssMetaData<Labeled,Boolean> getCssMetaData() {
 296                     return StyleableProperties.WRAP_TEXT;
 297                 }
 298 
 299                 @Override
 300                 public Object getBean() {
 301                     return Labeled.this;
 302                 }
 303 
 304                 @Override
 305                 public String getName() {
 306                     return "wrapText";
 307                 }
 308             };
 309         }
 310         return wrapText;
 311     }
 312     private BooleanProperty wrapText;
 313     public final void setWrapText(boolean value) { wrapTextProperty().setValue(value); }
 314     public final boolean isWrapText() { return wrapText == null ? false : wrapText.getValue(); }
 315 
 316     /**
 317      * If wrapText is true, then contentBias will be HORIZONTAL, otherwise it is null.
 318      * @return orientation of width/height dependency or null if there is none
 319      */
 320     @Override public Orientation getContentBias() {
 321         return isWrapText()? Orientation.HORIZONTAL : null;
 322     }
 323 
 324     /**
 325      * The default font to use for text in the Labeled. If the Label's text is
 326      * rich text then this font may or may not be used depending on the font
 327      * information embedded in the rich text, but in any case where a default
 328      * font is required, this font will be used.
 329      * @return the default font to use for text in this labeled
 330      */
 331     public final ObjectProperty<Font> fontProperty() {
 332 
 333         if (font == null) {
 334             font = new StyleableObjectProperty<Font>(Font.getDefault()) {
 335 
 336                 private boolean fontSetByCss = false;
 337 
 338                 @Override
 339                 public void applyStyle(StyleOrigin newOrigin, Font value) {
 340 
 341                     //
 342                     // RT-20727 - if CSS is setting the font, then make sure invalidate doesn't call NodeHelper.reapplyCSS
 343                     //
 344                     try {
 345                         // super.applyStyle calls set which might throw if value is bound.
 346                         // Have to make sure fontSetByCss is reset.
 347                         fontSetByCss = true;
 348                         super.applyStyle(newOrigin, value);
 349                     } catch(Exception e) {


 385 
 386                 @Override
 387                 public String getName() {
 388                     return "font";
 389                 }
 390             };
 391         }
 392         return font;
 393     }
 394     private ObjectProperty<Font> font;
 395     public final void setFont(Font value) { fontProperty().setValue(value); }
 396     public final Font getFont() { return font == null ? Font.getDefault() : font.getValue(); }
 397 
 398 
 399     /**
 400      * An optional icon for the Labeled. This can be positioned relative to the
 401      * text by using {@link #setContentDisplay}.  The node specified for this
 402      * variable cannot appear elsewhere in the scene graph, otherwise
 403      * the {@code IllegalArgumentException} is thrown.  See the class
 404      * description of {@link javafx.scene.Node Node} for more detail.
 405      * @return the optional icon for this labeled
 406      */
 407     public final ObjectProperty<Node> graphicProperty() {
 408         if (graphic == null) {
 409             graphic = new StyleableObjectProperty<Node>() {
 410 
 411                 // The graphic is styleable by css, but it is the
 412                 // imageUrlProperty that handles the style value.
 413                 @Override
 414                 public CssMetaData getCssMetaData() {
 415                     return StyleableProperties.GRAPHIC;
 416                 }
 417 
 418                 @Override
 419                 public Object getBean() {
 420                     return Labeled.this;
 421                 }
 422 
 423                 @Override
 424                 public String getName() {
 425                     return "graphic";


 543                     return Labeled.this;
 544                 }
 545 
 546                 @Override
 547                 public String getName() {
 548                     return "imageUrl";
 549                 }
 550 
 551                 @Override
 552                 public CssMetaData<Labeled,String> getCssMetaData() {
 553                     return StyleableProperties.GRAPHIC;
 554                 }
 555 
 556             };
 557         }
 558         return imageUrl;
 559     }
 560 
 561     /**
 562      * Whether all text should be underlined.
 563      * @return the underline property of all text in this labeled
 564      */
 565     public final BooleanProperty underlineProperty() {
 566         if (underline == null) {
 567             underline = new StyleableBooleanProperty(false) {
 568 
 569                 @Override
 570                 public CssMetaData<Labeled, Boolean> getCssMetaData() {
 571                     return StyleableProperties.UNDERLINE;
 572                 }
 573 
 574                 @Override
 575                 public Object getBean() {
 576                     return Labeled.this;
 577                 }
 578 
 579                 @Override
 580                 public String getName() {
 581                     return "underline";
 582                 }
 583             };
 584         }
 585         return underline;
 586     }
 587     private BooleanProperty underline;
 588     public final void setUnderline(boolean value) { underlineProperty().setValue(value); }
 589     public final boolean isUnderline() { return underline == null ? false : underline.getValue(); }
 590 
 591     /**
 592      * Specifies the space in pixel between lines.
 593      * @return the line spacing property between lines in this labeled
 594      * @since JavaFX 8.0
 595      */
 596     public final DoubleProperty lineSpacingProperty() {
 597         if (lineSpacing == null) {
 598             lineSpacing = new StyleableDoubleProperty(0) {
 599 
 600                 @Override
 601                 public CssMetaData<Labeled,Number> getCssMetaData() {
 602                     return StyleableProperties.LINE_SPACING;
 603                 }
 604 
 605                 @Override
 606                 public Object getBean() {
 607                     return Labeled.this;
 608                 }
 609 
 610                 @Override
 611                 public String getName() {
 612                     return "lineSpacing";
 613                 }
 614             };
 615         }
 616         return lineSpacing;
 617     }
 618     private DoubleProperty lineSpacing;
 619     public final void setLineSpacing(double value) { lineSpacingProperty().setValue(value); }
 620     public final double getLineSpacing() { return lineSpacing == null ? 0 : lineSpacing.getValue(); }
 621 
 622     /**
 623      * Specifies the positioning of the graphic relative to the text.
 624      * @return content display property of this labeled
 625      */
 626     public final ObjectProperty<ContentDisplay> contentDisplayProperty() {
 627         if (contentDisplay == null) {
 628             contentDisplay = new StyleableObjectProperty<ContentDisplay>(ContentDisplay.LEFT) {
 629 
 630                 @Override
 631                 public CssMetaData<Labeled,ContentDisplay> getCssMetaData() {
 632                     return StyleableProperties.CONTENT_DISPLAY;
 633                 }
 634 
 635                 @Override
 636                 public Object getBean() {
 637                     return Labeled.this;
 638                 }
 639 
 640                 @Override
 641                 public String getName() {
 642                     return "contentDisplay";
 643                 }
 644             };
 645         }
 646         return contentDisplay;
 647     }
 648     private ObjectProperty<ContentDisplay> contentDisplay;
 649     public final void setContentDisplay(ContentDisplay value) { contentDisplayProperty().setValue(value); }
 650     public final ContentDisplay getContentDisplay() { return contentDisplay == null ? ContentDisplay.LEFT : contentDisplay.getValue(); }
 651 
 652     /**
 653      * The padding around the Labeled's text and graphic content.
 654      * By default labelPadding is Insets.EMPTY and cannot be set to null.
 655      * Subclasses may add nodes outside this padding and inside the Labeled's padding.
 656      *
 657      * This property can only be set from CSS.
 658      * @return  the label padding property of this labeled
 659      */
 660     public final ReadOnlyObjectProperty<Insets> labelPaddingProperty() {
 661         return labelPaddingPropertyImpl();
 662     }
 663     private ObjectProperty<Insets> labelPaddingPropertyImpl() {
 664         if (labelPadding == null) {
 665             labelPadding = new StyleableObjectProperty<Insets>(Insets.EMPTY) {
 666                 private Insets lastValidValue = Insets.EMPTY;
 667 
 668                 @Override
 669                 public void invalidated() {
 670                     final Insets newValue = get();
 671                     if (newValue == null) {
 672                         set(lastValidValue);
 673                         throw new NullPointerException("cannot set labelPadding to null");
 674                     }
 675                     lastValidValue = newValue;
 676                     requestLayout();
 677                 }
 678 


 683 
 684                 @Override
 685                 public Object getBean() {
 686                     return Labeled.this;
 687                 }
 688 
 689                 @Override
 690                 public String getName() {
 691                     return "labelPadding";
 692                 }
 693             };
 694         }
 695         return labelPadding;
 696     }
 697     private ObjectProperty<Insets> labelPadding;
 698     private void setLabelPadding(Insets value) { labelPaddingPropertyImpl().set(value); }
 699     public final Insets getLabelPadding() { return labelPadding == null ? Insets.EMPTY : labelPadding.get(); }
 700 
 701     /**
 702      * The amount of space between the graphic and text
 703      * @return the graphics text gap property of this labeled
 704      */
 705     public final DoubleProperty graphicTextGapProperty() {
 706         if (graphicTextGap == null) {
 707             graphicTextGap = new StyleableDoubleProperty(4) {
 708 
 709                 @Override
 710                 public CssMetaData<Labeled,Number> getCssMetaData() {
 711                     return StyleableProperties.GRAPHIC_TEXT_GAP;
 712                 }
 713 
 714                 @Override
 715                 public Object getBean() {
 716                     return Labeled.this;
 717                 }
 718 
 719                 @Override
 720                 public String getName() {
 721                     return "graphicTextGap";
 722                 }
 723             };


 805     //     */
 806 
 807     @Override public String toString() {
 808         StringBuilder builder =
 809             new StringBuilder(super.toString())
 810                 .append("'").append(getText()).append("'");
 811         return builder.toString();
 812     }
 813 
 814     /***************************************************************************
 815      *                                                                         *
 816      * Stylesheet Handling                                                     *
 817      *                                                                         *
 818      **************************************************************************/
 819 
 820     /**
 821      * Returns the initial alignment state of this control, for use
 822      * by the JavaFX CSS engine to correctly set its initial value. This method
 823      * is overridden to use Pos.CENTER_LEFT initially.
 824      *
 825      * @return the initial alignment state of this control
 826      * @since 9
 827      */
 828     protected Pos getInitialAlignment() {
 829         return Pos.CENTER_LEFT;
 830     }
 831 
 832     private static class StyleableProperties {
 833         private static final FontCssMetaData<Labeled> FONT =
 834             new FontCssMetaData<Labeled>("-fx-font", Font.getDefault()) {
 835 
 836             @Override
 837             public boolean isSettable(Labeled n) {
 838                 return n.font == null || !n.font.isBound();
 839             }
 840 
 841             @Override
 842             public StyleableProperty<Font> getStyleableProperty(Labeled n) {
 843                 return (StyleableProperty<Font>)(WritableValue<Font>)n.fontProperty();
 844             }
 845         };


< prev index next >