100 * @since JavaFX 2.0
101 */
102 @IDProperty("id")
103 public class MenuItem implements EventTarget, Styleable {
104
105 /***************************************************************************
106 * *
107 * Constructors *
108 * *
109 **************************************************************************/
110
111 /**
112 * Constructs a MenuItem with no display text.
113 */
114 public MenuItem() {
115 this(null,null);
116 }
117
118 /**
119 * Constructs a MenuItem and sets the display text with the specified text
120 * @see #setText
121 */
122 public MenuItem(String text) {
123 this(text,null);
124 }
125
126 /**
127 * Constructor s MenuItem and sets the display text with the specified text
128 * and sets the graphic {@link Node} to the given node.
129 * @see #setText
130 * @see #setGraphic
131 */
132 public MenuItem(String text, Node graphic) {
133 setText(text);
134 setGraphic(graphic);
135 styleClass.add(DEFAULT_STYLE_CLASS);
136 }
137
138
139
140 /***************************************************************************
141 * *
142 * Instance Variables *
143 * *
144 **************************************************************************/
145
146 private final ObservableList<String> styleClass = FXCollections.observableArrayList();
147
148 final EventHandlerManager eventHandlerManager =
564 /**
565 * {@inheritDoc}
566 * @return {@code getParentMenu()}, or {@code getParentPopup()}
567 * if {@code parentMenu} is null
568 * @since JavaFX 8.0
569 */
570 @Override
571 public Styleable getStyleableParent() {
572
573 if(getParentMenu() == null) {
574 return getParentPopup();
575 } else {
576 return getParentMenu();
577 }
578 }
579
580 /**
581 * {@inheritDoc}
582 * @since JavaFX 8.0
583 */
584 public final ObservableSet<PseudoClass> getPseudoClassStates() {
585 return FXCollections.emptyObservableSet();
586 }
587
588 @Override
589 public List<CssMetaData<? extends Styleable, ?>> getCssMetaData() {
590 return Collections.emptyList();
591 }
592
593 /** {@inheritDoc} */
594 @Override public Node getStyleableNode() {
595 // Fix for RT-20582. We dive into the visual representation
596 // of this MenuItem so that we may return it to the caller.
597 ContextMenu parentPopup = MenuItem.this.getParentPopup();
598 if (parentPopup == null || ! (parentPopup.getSkin() instanceof ContextMenuSkin)) return null;
599
600 ContextMenuSkin skin = (ContextMenuSkin) parentPopup.getSkin();
601 if (! (skin.getNode() instanceof ContextMenuContent)) return null;
602
603 ContextMenuContent content = (ContextMenuContent) skin.getNode();
|
100 * @since JavaFX 2.0
101 */
102 @IDProperty("id")
103 public class MenuItem implements EventTarget, Styleable {
104
105 /***************************************************************************
106 * *
107 * Constructors *
108 * *
109 **************************************************************************/
110
111 /**
112 * Constructs a MenuItem with no display text.
113 */
114 public MenuItem() {
115 this(null,null);
116 }
117
118 /**
119 * Constructs a MenuItem and sets the display text with the specified text
120 * @param text the display text
121 * @see #setText
122 */
123 public MenuItem(String text) {
124 this(text,null);
125 }
126
127 /**
128 * Constructor s MenuItem and sets the display text with the specified text
129 * and sets the graphic {@link Node} to the given node.
130 * @param text the display text
131 * @param graphic the graphic node
132 * @see #setText
133 * @see #setGraphic
134 */
135 public MenuItem(String text, Node graphic) {
136 setText(text);
137 setGraphic(graphic);
138 styleClass.add(DEFAULT_STYLE_CLASS);
139 }
140
141
142
143 /***************************************************************************
144 * *
145 * Instance Variables *
146 * *
147 **************************************************************************/
148
149 private final ObservableList<String> styleClass = FXCollections.observableArrayList();
150
151 final EventHandlerManager eventHandlerManager =
567 /**
568 * {@inheritDoc}
569 * @return {@code getParentMenu()}, or {@code getParentPopup()}
570 * if {@code parentMenu} is null
571 * @since JavaFX 8.0
572 */
573 @Override
574 public Styleable getStyleableParent() {
575
576 if(getParentMenu() == null) {
577 return getParentPopup();
578 } else {
579 return getParentMenu();
580 }
581 }
582
583 /**
584 * {@inheritDoc}
585 * @since JavaFX 8.0
586 */
587 @Override
588 public final ObservableSet<PseudoClass> getPseudoClassStates() {
589 return FXCollections.emptyObservableSet();
590 }
591
592 @Override
593 public List<CssMetaData<? extends Styleable, ?>> getCssMetaData() {
594 return Collections.emptyList();
595 }
596
597 /** {@inheritDoc} */
598 @Override public Node getStyleableNode() {
599 // Fix for RT-20582. We dive into the visual representation
600 // of this MenuItem so that we may return it to the caller.
601 ContextMenu parentPopup = MenuItem.this.getParentPopup();
602 if (parentPopup == null || ! (parentPopup.getSkin() instanceof ContextMenuSkin)) return null;
603
604 ContextMenuSkin skin = (ContextMenuSkin) parentPopup.getSkin();
605 if (! (skin.getNode() instanceof ContextMenuContent)) return null;
606
607 ContextMenuContent content = (ContextMenuContent) skin.getNode();
|