< prev index next >

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

Print this page




 108      * @since JavaFX 8u40
 109      */
 110     public Tab(String text, Node content) {
 111         setText(text);
 112         setContent(content);
 113         styleClass.addAll(DEFAULT_STYLE_CLASS);
 114     }
 115 
 116 
 117     /***************************************************************************
 118      *                                                                         *
 119      * Properties                                                              *
 120      *                                                                         *
 121      **************************************************************************/
 122 
 123     private StringProperty id;
 124 
 125     /**
 126      * Sets the id of this tab. This simple string identifier is useful for
 127      * finding a specific Tab within the {@code TabPane}. The default value is {@code null}.

 128      */
 129    public final void setId(String value) { idProperty().set(value); }
 130 
 131     /**
 132      * The id of this tab.
 133      *
 134      * @return The id of the tab.
 135      */
 136     @Override
 137     public final String getId() { return id == null ? null : id.get(); }
 138 
 139     /**
 140      * The id of this tab.

 141      */
 142     public final StringProperty idProperty() {
 143         if (id == null) {
 144             id = new SimpleStringProperty(this, "id");
 145         }
 146         return id;
 147     }
 148 
 149     private StringProperty style;
 150 
 151     /**
 152      * A string representation of the CSS style associated with this
 153      * tab. This is analogous to the "style" attribute of an
 154      * HTML element. Note that, like the HTML style attribute, this
 155      * variable contains style properties and values and not the
 156      * selector portion of a style rule.
 157      * <p>
 158      * Parsing this style might not be supported on some limited
 159      * platforms. It is recommended to use a standalone CSS file instead.
 160      *

 161      */
 162    public final void setStyle(String value) { styleProperty().set(value); }
 163 
 164     /**
 165      * The CSS style string associated to this tab.
 166      *
 167      * @return The CSS style string associated to this tab.
 168      */
 169     @Override
 170     public final String getStyle() { return style == null ? null : style.get(); }
 171 
 172     /**
 173      * The CSS style string associated to this tab.

 174      */
 175     public final StringProperty styleProperty() {
 176         if (style == null) {
 177             style = new SimpleStringProperty(this, "style");
 178         }
 179         return style;
 180     }
 181 
 182     private ReadOnlyBooleanWrapper selected;
 183 
 184     final void setSelected(boolean value) {
 185         selectedPropertyImpl().set(value);
 186     }
 187 
 188     /**
 189      * <p>Represents whether this tab is the currently selected tab,
 190      * To change the selected Tab use {@code tabPane.getSelectionModel().select()}
 191      * </p>

 192      */
 193     public final boolean isSelected() {
 194         return selected == null ? false : selected.get();
 195     }
 196 
 197     /**
 198      * The currently selected tab.

 199      */
 200     public final ReadOnlyBooleanProperty selectedProperty() {
 201         return selectedPropertyImpl().getReadOnlyProperty();
 202     }
 203 
 204     private ReadOnlyBooleanWrapper selectedPropertyImpl() {
 205         if (selected == null) {
 206             selected = new ReadOnlyBooleanWrapper() {
 207                 @Override protected void invalidated() {
 208                     if (getOnSelectionChanged() != null) {
 209                         Event.fireEvent(Tab.this, new Event(SELECTION_CHANGED_EVENT));
 210                     }
 211                 }
 212 
 213                 @Override
 214                 public Object getBean() {
 215                     return Tab.this;
 216                 }
 217 
 218                 @Override
 219                 public String getName() {
 220                     return "selected";
 221                 }
 222             };
 223         }
 224         return selected;
 225     }
 226 
 227     private ReadOnlyObjectWrapper<TabPane> tabPane;
 228 
 229     final void setTabPane(TabPane value) {
 230         tabPanePropertyImpl().set(value);
 231     }
 232 
 233     /**
 234      * <p>A reference to the TabPane that contains this tab instance.</p>

 235      */
 236     public final TabPane getTabPane() {
 237         return tabPane == null ? null : tabPane.get();
 238     }
 239 
 240     /**
 241      * The TabPane that contains this tab.

 242      */
 243     public final ReadOnlyObjectProperty<TabPane> tabPaneProperty() {
 244         return tabPanePropertyImpl().getReadOnlyProperty();
 245     }
 246 
 247     private ReadOnlyObjectWrapper<TabPane> tabPanePropertyImpl() {
 248         if (tabPane == null) {
 249             tabPane = new ReadOnlyObjectWrapper<TabPane>(this, "tabPane") {
 250                 private WeakReference<TabPane> oldParent;
 251 
 252                 @Override protected void invalidated() {
 253                     if(oldParent != null && oldParent.get() != null) {
 254                         oldParent.get().disabledProperty().removeListener(parentDisabledChangedListener);
 255                     }
 256                     updateDisabled();
 257                     TabPane newParent = get();
 258                     if (newParent != null) {
 259                         newParent.disabledProperty().addListener(parentDisabledChangedListener);
 260                     }
 261                     oldParent = new WeakReference<TabPane>(newParent);
 262                     super.invalidated();
 263                 }
 264             };
 265         }
 266         return tabPane;
 267     }
 268 
 269     private final InvalidationListener parentDisabledChangedListener = valueModel -> {
 270         updateDisabled();
 271     };
 272 
 273     private StringProperty text;
 274 
 275     /**
 276      * <p>Sets the text to show in the tab to allow the user to differentiate between
 277      * the function of each tab. The text is always visible
 278      * </p>

 279      */
 280     public final void setText(String value) {
 281         textProperty().set(value);
 282     }
 283 
 284     /**
 285      * The text shown in the tab.
 286      *
 287      * @return The text shown in the tab.
 288      */
 289     public final String getText() {
 290         return text == null ? null : text.get();
 291     }
 292 
 293     /**
 294      * The text shown in the tab.

 295      */
 296     public final StringProperty textProperty() {
 297         if (text == null) {
 298             text = new SimpleStringProperty(this, "text");
 299         }
 300         return text;
 301     }
 302 
 303     private ObjectProperty<Node> graphic;
 304 
 305     /**
 306      * <p>Sets the graphic to show in the tab to allow the user to differentiate
 307      * between the function of each tab. By default the graphic does not rotate
 308      * based on the TabPane.tabPosition value, but it can be set to rotate by
 309      * setting TabPane.rotateGraphic to true.</p>

 310      */
 311     public final void setGraphic(Node value) {
 312         graphicProperty().set(value);
 313     }
 314 
 315     /**
 316      * The graphic shown in the tab.
 317      *
 318      * @return The graphic shown in the tab.
 319      */
 320     public final Node getGraphic() {
 321         return graphic == null ? null : graphic.get();
 322     }
 323 
 324     /**
 325      * The graphic in the tab.
 326      *
 327      * @return The graphic in the tab.
 328      */
 329     public final ObjectProperty<Node> graphicProperty() {
 330         if (graphic == null) {
 331             graphic = new SimpleObjectProperty<Node>(this, "graphic");
 332         }
 333         return graphic;
 334     }
 335 
 336     private ObjectProperty<Node> content;
 337 
 338     /**
 339      * <p>The content to show within the main TabPane area. The content
 340      * can be any Node such as UI controls or groups of nodes added
 341      * to a layout container.</p>

 342      */
 343     public final void setContent(Node value) {
 344         contentProperty().set(value);
 345     }
 346 
 347     /**
 348      * <p>The content associated with the tab.</p>
 349      *
 350      * @return The content associated with the tab.
 351      */
 352     public final Node getContent() {
 353         return content == null ? null : content.get();
 354     }
 355 
 356     /**
 357      * <p>The content associated with the tab.</p>

 358      */
 359     public final ObjectProperty<Node> contentProperty() {
 360         if (content == null) {
 361             content = new SimpleObjectProperty<Node>(this, "content");
 362         }
 363         return content;
 364     }
 365 
 366 
 367     private ObjectProperty<ContextMenu> contextMenu;
 368 
 369     /**
 370      * <p>Specifies the context menu to show when the user right-clicks on the tab.
 371      * </p>

 372      */
 373     public final void setContextMenu(ContextMenu value) {
 374         contextMenuProperty().set(value);
 375     }
 376 
 377     /**
 378      * The context menu associated with the tab.
 379      * @return The context menu associated with the tab.
 380      */
 381     public final ContextMenu getContextMenu() {
 382         return contextMenu == null ? null : contextMenu.get();
 383     }
 384 
 385     /**
 386      * The context menu associated with the tab.

 387      */
 388     public final ObjectProperty<ContextMenu> contextMenuProperty() {
 389         if (contextMenu == null) {
 390             contextMenu = new SimpleObjectProperty<ContextMenu>(this, "contextMenu") {
 391                 private WeakReference<ContextMenu> contextMenuRef;
 392 
 393                 @Override protected void invalidated() {
 394                     ContextMenu oldMenu = contextMenuRef == null ? null : contextMenuRef.get();
 395                     if (oldMenu != null) {
 396                         ControlAcceleratorSupport.removeAcceleratorsFromScene(oldMenu.getItems(), Tab.this);
 397                     }
 398 
 399                     ContextMenu ctx = get();
 400                     contextMenuRef = new WeakReference<>(ctx);
 401 
 402                     if (ctx != null) {
 403                         // if a context menu is set, we need to install any accelerators
 404                         // belonging to its menu items ASAP into the scene that this
 405                         // Control is in (if the control is not in a Scene, we will need
 406                         // to wait until it is and then do it).
 407                         ControlAcceleratorSupport.addAcceleratorsIntoScene(ctx.getItems(), Tab.this);
 408                     }
 409                 }
 410             };
 411         }
 412         return contextMenu;
 413     }
 414 
 415     private BooleanProperty closable;
 416 
 417     /**
 418      * <p>Sets {@code true} if the tab is closable.  If this is set to {@code false},
 419      * then regardless of the TabClosingPolicy, it will not be
 420      * possible for the user to close this tab. Therefore, when this
 421      * property is {@code false}, no 'close' button will be shown on the tab.
 422      * The default is {@code true}.</p>
 423      *

 424      */
 425     public final void setClosable(boolean value) {
 426         closableProperty().set(value);
 427     }
 428 
 429     /**
 430      * Returns {@code true} if this tab is closable.
 431      *
 432      * @return {@code true} if the tab is closable.
 433      */
 434     public final boolean isClosable() {
 435         return closable == null ? true : closable.get();
 436     }
 437 
 438     /**
 439      * The closable state for this tab.

 440      */
 441     public final BooleanProperty closableProperty() {
 442         if (closable == null) {
 443             closable = new SimpleBooleanProperty(this, "closable", true);
 444         }
 445         return closable;
 446     }
 447 
 448 
 449     /**
 450      * <p>Called when the tab becomes selected or unselected.</p>
 451      */
 452     public static final EventType<Event> SELECTION_CHANGED_EVENT =
 453             new EventType<Event> (Event.ANY, "SELECTION_CHANGED_EVENT");
 454     private ObjectProperty<EventHandler<Event>> onSelectionChanged;
 455 
 456     /**
 457      * Defines a function to be called when a selection changed has occurred on the tab.

 458      */
 459     public final void setOnSelectionChanged(EventHandler<Event> value) {
 460         onSelectionChangedProperty().set(value);
 461     }
 462 
 463     /**
 464      * The event handler that is associated with a selection on the tab.
 465      *
 466      * @return The event handler that is associated with a tab selection.
 467      */
 468     public final EventHandler<Event> getOnSelectionChanged() {
 469         return onSelectionChanged == null ? null : onSelectionChanged.get();
 470     }
 471 
 472     /**
 473      * The event handler that is associated with a selection on the tab.

 474      */
 475     public final ObjectProperty<EventHandler<Event>> onSelectionChangedProperty() {
 476         if (onSelectionChanged == null) {
 477             onSelectionChanged = new ObjectPropertyBase<EventHandler<Event>>() {
 478                 @Override protected void invalidated() {
 479                     setEventHandler(SELECTION_CHANGED_EVENT, get());
 480                 }
 481 
 482                 @Override
 483                 public Object getBean() {
 484                     return Tab.this;
 485                 }
 486 
 487                 @Override
 488                 public String getName() {
 489                     return "onSelectionChanged";
 490                 }
 491             };
 492         }
 493         return onSelectionChanged;
 494     }
 495 
 496     /**
 497      * <p>Called when a user closes this tab. This is useful for freeing up memory.</p>
 498      */
 499     public static final EventType<Event> CLOSED_EVENT = new EventType<Event>(Event.ANY, "TAB_CLOSED");
 500     private ObjectProperty<EventHandler<Event>> onClosed;
 501 
 502     /**
 503      * Defines a function to be called when the tab is closed.

 504      */
 505     public final void setOnClosed(EventHandler<Event> value) {
 506         onClosedProperty().set(value);
 507     }
 508 
 509     /**
 510      * The event handler that is associated with the tab when the tab is closed.
 511      *
 512      * @return The event handler that is associated with the tab when the tab is closed.
 513      */
 514     public final EventHandler<Event> getOnClosed() {
 515         return onClosed == null ? null : onClosed.get();
 516     }
 517 
 518     /**
 519      * The event handler that is associated with the tab when the tab is closed.

 520      */
 521     public final ObjectProperty<EventHandler<Event>> onClosedProperty() {
 522         if (onClosed == null) {
 523             onClosed = new ObjectPropertyBase<EventHandler<Event>>() {
 524                 @Override protected void invalidated() {
 525                     setEventHandler(CLOSED_EVENT, get());
 526                 }
 527 
 528                 @Override
 529                 public Object getBean() {
 530                     return Tab.this;
 531                 }
 532 
 533                 @Override
 534                 public String getName() {
 535                     return "onClosed";
 536                 }
 537             };
 538         }
 539         return onClosed;
 540     }
 541 
 542     private ObjectProperty<Tooltip> tooltip;
 543 
 544     /**
 545      * <p>Specifies the tooltip to show when the user hovers over the tab.</p>

 546      */
 547     public final void setTooltip(Tooltip value) { tooltipProperty().setValue(value); }
 548 
 549     /**
 550      * The tooltip associated with this tab.
 551      * @return The tooltip associated with this tab.
 552      */
 553     public final Tooltip getTooltip() { return tooltip == null ? null : tooltip.getValue(); }
 554 
 555     /**
 556      * The tooltip associated with this tab.

 557      */
 558     public final ObjectProperty<Tooltip> tooltipProperty() {
 559         if (tooltip == null) {
 560             tooltip = new SimpleObjectProperty<Tooltip>(this, "tooltip");
 561         }
 562         return tooltip;
 563     }
 564 
 565     private final ObservableList<String> styleClass = FXCollections.observableArrayList();
 566 
 567     private BooleanProperty disable;
 568 
 569     /**
 570      * Sets the disabled state of this tab.
 571      *
 572      * @param value the state to set this tab
 573      *
 574      * @defaultValue false
 575      * @since JavaFX 2.2
 576      */
 577     public final void setDisable(boolean value) {
 578         disableProperty().set(value);
 579     }
 580 
 581     /**
 582      * Returns {@code true} if this tab is disable.

 583      * @since JavaFX 2.2
 584      */
 585     public final boolean isDisable() { return disable == null ? false : disable.get(); }
 586 
 587     /**
 588      * Sets the disabled state of this tab. A disable tab is no longer interactive
 589      * or traversable, but the contents remain interactive.  A disable tab
 590      * can be selected using {@link TabPane#getSelectionModel()}.
 591      *

 592      * @defaultValue false
 593      * @since JavaFX 2.2
 594      */
 595     public final BooleanProperty disableProperty() {
 596         if (disable == null) {
 597             disable = new BooleanPropertyBase(false) {
 598                 @Override
 599                 protected void invalidated() {
 600                     updateDisabled();
 601                 }
 602 
 603                 @Override
 604                 public Object getBean() {
 605                     return Tab.this;
 606                 }
 607 
 608                 @Override
 609                 public String getName() {
 610                     return "disable";
 611                 }
 612             };
 613         }
 614         return disable;
 615     }
 616 
 617     private ReadOnlyBooleanWrapper disabled;
 618 
 619     private final void setDisabled(boolean value) {
 620         disabledPropertyImpl().set(value);
 621     }
 622 
 623     /**
 624      * Returns true when the {@code Tab} {@link #disableProperty disable} is set to
 625      * {@code true} or if the {@code TabPane} is disabled.

 626      * @since JavaFX 2.2
 627      */
 628     public final boolean isDisabled() {
 629         return disabled == null ? false : disabled.get();
 630     }
 631 
 632     /**
 633      * Indicates whether or not this {@code Tab} is disabled.  A {@code Tab}
 634      * will become disabled if {@link #disableProperty disable} is set to {@code true} on either
 635      * itself or if the {@code TabPane} is disabled.
 636      *

 637      * @defaultValue false
 638      * @since JavaFX 2.2
 639      */
 640     public final ReadOnlyBooleanProperty disabledProperty() {
 641         return disabledPropertyImpl().getReadOnlyProperty();
 642     }
 643 
 644     private ReadOnlyBooleanWrapper disabledPropertyImpl() {
 645         if (disabled == null) {
 646             disabled = new ReadOnlyBooleanWrapper() {
 647                 @Override
 648                 public Object getBean() {
 649                     return Tab.this;
 650                 }
 651 
 652                 @Override
 653                 public String getName() {
 654                     return "disabled";
 655                 }
 656             };




 108      * @since JavaFX 8u40
 109      */
 110     public Tab(String text, Node content) {
 111         setText(text);
 112         setContent(content);
 113         styleClass.addAll(DEFAULT_STYLE_CLASS);
 114     }
 115 
 116 
 117     /***************************************************************************
 118      *                                                                         *
 119      * Properties                                                              *
 120      *                                                                         *
 121      **************************************************************************/
 122 
 123     private StringProperty id;
 124 
 125     /**
 126      * Sets the id of this tab. This simple string identifier is useful for
 127      * finding a specific Tab within the {@code TabPane}. The default value is {@code null}.
 128      * @param value the id of this tab
 129      */
 130    public final void setId(String value) { idProperty().set(value); }
 131 
 132     /**
 133      * The id of this tab.
 134      *
 135      * @return The id of the tab.
 136      */
 137     @Override
 138     public final String getId() { return id == null ? null : id.get(); }
 139 
 140     /**
 141      * The id of this tab.
 142      * @return the id property of this tab
 143      */
 144     public final StringProperty idProperty() {
 145         if (id == null) {
 146             id = new SimpleStringProperty(this, "id");
 147         }
 148         return id;
 149     }
 150 
 151     private StringProperty style;
 152 
 153     /**
 154      * A string representation of the CSS style associated with this
 155      * tab. This is analogous to the "style" attribute of an
 156      * HTML element. Note that, like the HTML style attribute, this
 157      * variable contains style properties and values and not the
 158      * selector portion of a style rule.
 159      * <p>
 160      * Parsing this style might not be supported on some limited
 161      * platforms. It is recommended to use a standalone CSS file instead.
 162      *
 163      * @param value the style string
 164      */
 165    public final void setStyle(String value) { styleProperty().set(value); }
 166 
 167     /**
 168      * The CSS style string associated to this tab.
 169      *
 170      * @return The CSS style string associated to this tab.
 171      */
 172     @Override
 173     public final String getStyle() { return style == null ? null : style.get(); }
 174 
 175     /**
 176      * The CSS style string associated to this tab.
 177      * @return the CSS style string property associated to this tab
 178      */
 179     public final StringProperty styleProperty() {
 180         if (style == null) {
 181             style = new SimpleStringProperty(this, "style");
 182         }
 183         return style;
 184     }
 185 
 186     private ReadOnlyBooleanWrapper selected;
 187 
 188     final void setSelected(boolean value) {
 189         selectedPropertyImpl().set(value);
 190     }
 191 
 192     /**
 193      * <p>Represents whether this tab is the currently selected tab,
 194      * To change the selected Tab use {@code tabPane.getSelectionModel().select()}
 195      * </p>
 196      * @return true if selected
 197      */
 198     public final boolean isSelected() {
 199         return selected == null ? false : selected.get();
 200     }
 201 
 202     /**
 203      * The currently selected tab.
 204      * @return the selected tab
 205      */
 206     public final ReadOnlyBooleanProperty selectedProperty() {
 207         return selectedPropertyImpl().getReadOnlyProperty();
 208     }
 209 
 210     private ReadOnlyBooleanWrapper selectedPropertyImpl() {
 211         if (selected == null) {
 212             selected = new ReadOnlyBooleanWrapper() {
 213                 @Override protected void invalidated() {
 214                     if (getOnSelectionChanged() != null) {
 215                         Event.fireEvent(Tab.this, new Event(SELECTION_CHANGED_EVENT));
 216                     }
 217                 }
 218 
 219                 @Override
 220                 public Object getBean() {
 221                     return Tab.this;
 222                 }
 223 
 224                 @Override
 225                 public String getName() {
 226                     return "selected";
 227                 }
 228             };
 229         }
 230         return selected;
 231     }
 232 
 233     private ReadOnlyObjectWrapper<TabPane> tabPane;
 234 
 235     final void setTabPane(TabPane value) {
 236         tabPanePropertyImpl().set(value);
 237     }
 238 
 239     /**
 240      * <p>A reference to the TabPane that contains this tab instance.</p>
 241      * @return the TabPane
 242      */
 243     public final TabPane getTabPane() {
 244         return tabPane == null ? null : tabPane.get();
 245     }
 246 
 247     /**
 248      * The TabPane that contains this tab.
 249      * @return the TabPane property
 250      */
 251     public final ReadOnlyObjectProperty<TabPane> tabPaneProperty() {
 252         return tabPanePropertyImpl().getReadOnlyProperty();
 253     }
 254 
 255     private ReadOnlyObjectWrapper<TabPane> tabPanePropertyImpl() {
 256         if (tabPane == null) {
 257             tabPane = new ReadOnlyObjectWrapper<TabPane>(this, "tabPane") {
 258                 private WeakReference<TabPane> oldParent;
 259 
 260                 @Override protected void invalidated() {
 261                     if(oldParent != null && oldParent.get() != null) {
 262                         oldParent.get().disabledProperty().removeListener(parentDisabledChangedListener);
 263                     }
 264                     updateDisabled();
 265                     TabPane newParent = get();
 266                     if (newParent != null) {
 267                         newParent.disabledProperty().addListener(parentDisabledChangedListener);
 268                     }
 269                     oldParent = new WeakReference<TabPane>(newParent);
 270                     super.invalidated();
 271                 }
 272             };
 273         }
 274         return tabPane;
 275     }
 276 
 277     private final InvalidationListener parentDisabledChangedListener = valueModel -> {
 278         updateDisabled();
 279     };
 280 
 281     private StringProperty text;
 282 
 283     /**
 284      * <p>Sets the text to show in the tab to allow the user to differentiate between
 285      * the function of each tab. The text is always visible
 286      * </p>
 287      * @param value the text string
 288      */
 289     public final void setText(String value) {
 290         textProperty().set(value);
 291     }
 292 
 293     /**
 294      * The text shown in the tab.
 295      *
 296      * @return The text shown in the tab.
 297      */
 298     public final String getText() {
 299         return text == null ? null : text.get();
 300     }
 301 
 302     /**
 303      * The text shown in the tab.
 304      * @return the text property
 305      */
 306     public final StringProperty textProperty() {
 307         if (text == null) {
 308             text = new SimpleStringProperty(this, "text");
 309         }
 310         return text;
 311     }
 312 
 313     private ObjectProperty<Node> graphic;
 314 
 315     /**
 316      * <p>Sets the graphic to show in the tab to allow the user to differentiate
 317      * between the function of each tab. By default the graphic does not rotate
 318      * based on the TabPane.tabPosition value, but it can be set to rotate by
 319      * setting TabPane.rotateGraphic to true.</p>
 320      * @param value the graphic node
 321      */
 322     public final void setGraphic(Node value) {
 323         graphicProperty().set(value);
 324     }
 325 
 326     /**
 327      * The graphic shown in the tab.
 328      *
 329      * @return The graphic shown in the tab.
 330      */
 331     public final Node getGraphic() {
 332         return graphic == null ? null : graphic.get();
 333     }
 334 
 335     /**
 336      * The graphic in the tab.
 337      *
 338      * @return The graphic in the tab.
 339      */
 340     public final ObjectProperty<Node> graphicProperty() {
 341         if (graphic == null) {
 342             graphic = new SimpleObjectProperty<Node>(this, "graphic");
 343         }
 344         return graphic;
 345     }
 346 
 347     private ObjectProperty<Node> content;
 348 
 349     /**
 350      * <p>The content to show within the main TabPane area. The content
 351      * can be any Node such as UI controls or groups of nodes added
 352      * to a layout container.</p>
 353      * @param value the content node
 354      */
 355     public final void setContent(Node value) {
 356         contentProperty().set(value);
 357     }
 358 
 359     /**
 360      * <p>The content associated with the tab.</p>
 361      *
 362      * @return The content associated with the tab.
 363      */
 364     public final Node getContent() {
 365         return content == null ? null : content.get();
 366     }
 367 
 368     /**
 369      * <p>The content associated with the tab.</p>
 370      * @return the content property
 371      */
 372     public final ObjectProperty<Node> contentProperty() {
 373         if (content == null) {
 374             content = new SimpleObjectProperty<Node>(this, "content");
 375         }
 376         return content;
 377     }
 378 
 379 
 380     private ObjectProperty<ContextMenu> contextMenu;
 381 
 382     /**
 383      * <p>Specifies the context menu to show when the user right-clicks on the tab.
 384      * </p>
 385      * @param value the context menu
 386      */
 387     public final void setContextMenu(ContextMenu value) {
 388         contextMenuProperty().set(value);
 389     }
 390 
 391     /**
 392      * The context menu associated with the tab.
 393      * @return The context menu associated with the tab.
 394      */
 395     public final ContextMenu getContextMenu() {
 396         return contextMenu == null ? null : contextMenu.get();
 397     }
 398 
 399     /**
 400      * The context menu associated with the tab.
 401      * @return the context menu property
 402      */
 403     public final ObjectProperty<ContextMenu> contextMenuProperty() {
 404         if (contextMenu == null) {
 405             contextMenu = new SimpleObjectProperty<ContextMenu>(this, "contextMenu") {
 406                 private WeakReference<ContextMenu> contextMenuRef;
 407 
 408                 @Override protected void invalidated() {
 409                     ContextMenu oldMenu = contextMenuRef == null ? null : contextMenuRef.get();
 410                     if (oldMenu != null) {
 411                         ControlAcceleratorSupport.removeAcceleratorsFromScene(oldMenu.getItems(), Tab.this);
 412                     }
 413 
 414                     ContextMenu ctx = get();
 415                     contextMenuRef = new WeakReference<>(ctx);
 416 
 417                     if (ctx != null) {
 418                         // if a context menu is set, we need to install any accelerators
 419                         // belonging to its menu items ASAP into the scene that this
 420                         // Control is in (if the control is not in a Scene, we will need
 421                         // to wait until it is and then do it).
 422                         ControlAcceleratorSupport.addAcceleratorsIntoScene(ctx.getItems(), Tab.this);
 423                     }
 424                 }
 425             };
 426         }
 427         return contextMenu;
 428     }
 429 
 430     private BooleanProperty closable;
 431 
 432     /**
 433      * <p>Sets {@code true} if the tab is closable.  If this is set to {@code false},
 434      * then regardless of the TabClosingPolicy, it will not be
 435      * possible for the user to close this tab. Therefore, when this
 436      * property is {@code false}, no 'close' button will be shown on the tab.
 437      * The default is {@code true}.</p>
 438      *
 439      * @param value the closable value
 440      */
 441     public final void setClosable(boolean value) {
 442         closableProperty().set(value);
 443     }
 444 
 445     /**
 446      * Returns {@code true} if this tab is closable.
 447      *
 448      * @return {@code true} if the tab is closable.
 449      */
 450     public final boolean isClosable() {
 451         return closable == null ? true : closable.get();
 452     }
 453 
 454     /**
 455      * The closable state for this tab.
 456      * @return the closable property
 457      */
 458     public final BooleanProperty closableProperty() {
 459         if (closable == null) {
 460             closable = new SimpleBooleanProperty(this, "closable", true);
 461         }
 462         return closable;
 463     }
 464 
 465 
 466     /**
 467      * <p>Called when the tab becomes selected or unselected.</p>
 468      */
 469     public static final EventType<Event> SELECTION_CHANGED_EVENT =
 470             new EventType<Event> (Event.ANY, "SELECTION_CHANGED_EVENT");
 471     private ObjectProperty<EventHandler<Event>> onSelectionChanged;
 472 
 473     /**
 474      * Defines a function to be called when a selection changed has occurred on the tab.
 475      * @param value the on selection changed event handler
 476      */
 477     public final void setOnSelectionChanged(EventHandler<Event> value) {
 478         onSelectionChangedProperty().set(value);
 479     }
 480 
 481     /**
 482      * The event handler that is associated with a selection on the tab.
 483      *
 484      * @return The event handler that is associated with a tab selection.
 485      */
 486     public final EventHandler<Event> getOnSelectionChanged() {
 487         return onSelectionChanged == null ? null : onSelectionChanged.get();
 488     }
 489 
 490     /**
 491      * The event handler that is associated with a selection on the tab.
 492      * @return the on selection changed event handler property
 493      */
 494     public final ObjectProperty<EventHandler<Event>> onSelectionChangedProperty() {
 495         if (onSelectionChanged == null) {
 496             onSelectionChanged = new ObjectPropertyBase<EventHandler<Event>>() {
 497                 @Override protected void invalidated() {
 498                     setEventHandler(SELECTION_CHANGED_EVENT, get());
 499                 }
 500 
 501                 @Override
 502                 public Object getBean() {
 503                     return Tab.this;
 504                 }
 505 
 506                 @Override
 507                 public String getName() {
 508                     return "onSelectionChanged";
 509                 }
 510             };
 511         }
 512         return onSelectionChanged;
 513     }
 514 
 515     /**
 516      * <p>Called when a user closes this tab. This is useful for freeing up memory.</p>
 517      */
 518     public static final EventType<Event> CLOSED_EVENT = new EventType<Event>(Event.ANY, "TAB_CLOSED");
 519     private ObjectProperty<EventHandler<Event>> onClosed;
 520 
 521     /**
 522      * Defines a function to be called when the tab is closed.
 523      * @param value the on closed event handler
 524      */
 525     public final void setOnClosed(EventHandler<Event> value) {
 526         onClosedProperty().set(value);
 527     }
 528 
 529     /**
 530      * The event handler that is associated with the tab when the tab is closed.
 531      *
 532      * @return The event handler that is associated with the tab when the tab is closed.
 533      */
 534     public final EventHandler<Event> getOnClosed() {
 535         return onClosed == null ? null : onClosed.get();
 536     }
 537 
 538     /**
 539      * The event handler that is associated with the tab when the tab is closed.
 540      * @return the on closed event handler property
 541      */
 542     public final ObjectProperty<EventHandler<Event>> onClosedProperty() {
 543         if (onClosed == null) {
 544             onClosed = new ObjectPropertyBase<EventHandler<Event>>() {
 545                 @Override protected void invalidated() {
 546                     setEventHandler(CLOSED_EVENT, get());
 547                 }
 548 
 549                 @Override
 550                 public Object getBean() {
 551                     return Tab.this;
 552                 }
 553 
 554                 @Override
 555                 public String getName() {
 556                     return "onClosed";
 557                 }
 558             };
 559         }
 560         return onClosed;
 561     }
 562 
 563     private ObjectProperty<Tooltip> tooltip;
 564 
 565     /**
 566      * <p>Specifies the tooltip to show when the user hovers over the tab.</p>
 567      * @param value the tool tip value
 568      */
 569     public final void setTooltip(Tooltip value) { tooltipProperty().setValue(value); }
 570 
 571     /**
 572      * The tooltip associated with this tab.
 573      * @return The tooltip associated with this tab.
 574      */
 575     public final Tooltip getTooltip() { return tooltip == null ? null : tooltip.getValue(); }
 576 
 577     /**
 578      * The tooltip associated with this tab.
 579      * @return the tool tip property
 580      */
 581     public final ObjectProperty<Tooltip> tooltipProperty() {
 582         if (tooltip == null) {
 583             tooltip = new SimpleObjectProperty<Tooltip>(this, "tooltip");
 584         }
 585         return tooltip;
 586     }
 587 
 588     private final ObservableList<String> styleClass = FXCollections.observableArrayList();
 589 
 590     private BooleanProperty disable;
 591 
 592     /**
 593      * Sets the disabled state of this tab.
 594      *
 595      * @param value the state to set this tab
 596      *
 597      * @defaultValue false
 598      * @since JavaFX 2.2
 599      */
 600     public final void setDisable(boolean value) {
 601         disableProperty().set(value);
 602     }
 603 
 604     /**
 605      * Returns {@code true} if this tab is disable.
 606      * @return true if this tab is disable
 607      * @since JavaFX 2.2
 608      */
 609     public final boolean isDisable() { return disable == null ? false : disable.get(); }
 610 
 611     /**
 612      * Sets the disabled state of this tab. A disable tab is no longer interactive
 613      * or traversable, but the contents remain interactive.  A disable tab
 614      * can be selected using {@link TabPane#getSelectionModel()}.
 615      *
 616      * @return the disable property
 617      * @defaultValue false
 618      * @since JavaFX 2.2
 619      */
 620     public final BooleanProperty disableProperty() {
 621         if (disable == null) {
 622             disable = new BooleanPropertyBase(false) {
 623                 @Override
 624                 protected void invalidated() {
 625                     updateDisabled();
 626                 }
 627 
 628                 @Override
 629                 public Object getBean() {
 630                     return Tab.this;
 631                 }
 632 
 633                 @Override
 634                 public String getName() {
 635                     return "disable";
 636                 }
 637             };
 638         }
 639         return disable;
 640     }
 641 
 642     private ReadOnlyBooleanWrapper disabled;
 643 
 644     private final void setDisabled(boolean value) {
 645         disabledPropertyImpl().set(value);
 646     }
 647 
 648     /**
 649      * Returns true when the {@code Tab} {@link #disableProperty disable} is set to
 650      * {@code true} or if the {@code TabPane} is disabled.
 651      * @return true if the TabPane is disabled
 652      * @since JavaFX 2.2
 653      */
 654     public final boolean isDisabled() {
 655         return disabled == null ? false : disabled.get();
 656     }
 657 
 658     /**
 659      * Indicates whether or not this {@code Tab} is disabled.  A {@code Tab}
 660      * will become disabled if {@link #disableProperty disable} is set to {@code true} on either
 661      * itself or if the {@code TabPane} is disabled.
 662      *
 663      * @return the disabled property
 664      * @defaultValue false
 665      * @since JavaFX 2.2
 666      */
 667     public final ReadOnlyBooleanProperty disabledProperty() {
 668         return disabledPropertyImpl().getReadOnlyProperty();
 669     }
 670 
 671     private ReadOnlyBooleanWrapper disabledPropertyImpl() {
 672         if (disabled == null) {
 673             disabled = new ReadOnlyBooleanWrapper() {
 674                 @Override
 675                 public Object getBean() {
 676                     return Tab.this;
 677                 }
 678 
 679                 @Override
 680                 public String getName() {
 681                     return "disabled";
 682                 }
 683             };


< prev index next >