JavaFXAction.java
001 /*
002  * SPDX-License-Identifier: Apache-2.0
003  *
004  * Copyright 2008-2017 the original author or authors.
005  *
006  * Licensed under the Apache License, Version 2.0 (the "License");
007  * you may not use this file except in compliance with the License.
008  * You may obtain a copy of the License at
009  *
010  *     http://www.apache.org/licenses/LICENSE-2.0
011  *
012  * Unless required by applicable law or agreed to in writing, software
013  * distributed under the License is distributed on an "AS IS" BASIS,
014  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015  * See the License for the specific language governing permissions and
016  * limitations under the License.
017  */
018 package griffon.javafx.support;
019 
020 import javafx.beans.property.BooleanProperty;
021 import javafx.beans.property.ObjectProperty;
022 import javafx.beans.property.SimpleBooleanProperty;
023 import javafx.beans.property.SimpleObjectProperty;
024 import javafx.beans.property.SimpleStringProperty;
025 import javafx.beans.property.StringProperty;
026 import javafx.event.ActionEvent;
027 import javafx.event.EventHandler;
028 import javafx.scene.Node;
029 import javafx.scene.image.Image;
030 import javafx.scene.input.KeyCombination;
031 
032 /**
033  @author Andres Almiray
034  */
035 public class JavaFXAction {
036     // -- onAction
037 
038     private ObjectProperty<EventHandler<ActionEvent>> onAction;
039 
040     public final ObjectProperty<EventHandler<ActionEvent>> onActionProperty() {
041         if (onAction == null) {
042             onAction = new SimpleObjectProperty<>(this, "onAction");
043         }
044         return onAction;
045     }
046 
047     public void setOnAction(EventHandler<ActionEvent> value) {
048         onActionProperty().set(value);
049     }
050 
051     public EventHandler<ActionEvent> getOnAction() {
052         return onAction == null null : onActionProperty().get();
053     }
054 
055     // -- name
056 
057     private StringProperty name;
058 
059     public final StringProperty nameProperty() {
060         if (name == null) {
061             name = new SimpleStringProperty(this, "name");
062         }
063         return name;
064     }
065 
066     public void setName(String name) {
067         nameProperty().set(name);
068     }
069 
070     public String getName() {
071         return name == null null : nameProperty().get();
072     }
073 
074     // -- description
075 
076     private StringProperty description;
077 
078     public final StringProperty descriptionProperty() {
079         if (description == null) {
080             description = new SimpleStringProperty(this, "description");
081         }
082         return description;
083     }
084 
085     public void setDescription(String description) {
086         descriptionProperty().set(description);
087     }
088 
089     public String getDescription() {
090         return description == null null : descriptionProperty().get();
091     }
092 
093     // -- enabled
094 
095     private BooleanProperty enabled;
096 
097     public final BooleanProperty enabledProperty() {
098         if (enabled == null) {
099             enabled = new SimpleBooleanProperty(this, "enabled"true);
100         }
101         return enabled;
102     }
103 
104     public void setEnabled(boolean enabled) {
105         enabledProperty().set(enabled);
106     }
107 
108     public boolean getEnabled() {
109         return enabled != null && enabledProperty().get();
110     }
111 
112     public boolean isEnabled() {
113         return enabled != null && enabledProperty().get();
114     }
115 
116     // -- accelerator
117 
118     private ObjectProperty<KeyCombination> accelerator;
119 
120     public void setAccelerator(String accelerator) {
121         setAccelerator(KeyCombination.keyCombination(accelerator));
122     }
123 
124     public final void setAccelerator(KeyCombination value) {
125         acceleratorProperty().set(value);
126     }
127 
128     public final KeyCombination getAccelerator() {
129         return accelerator == null null : accelerator.get();
130     }
131 
132     public final ObjectProperty<KeyCombination> acceleratorProperty() {
133         if (accelerator == null) {
134             accelerator = new SimpleObjectProperty<>(this, "accelerator");
135         }
136         return accelerator;
137     }
138 
139     // -- icon
140 
141     private StringProperty icon;
142 
143     public final StringProperty iconProperty() {
144         if (icon == null) {
145             icon = new SimpleStringProperty(this, "icon");
146         }
147         return icon;
148     }
149 
150     public void setIcon(String icon) {
151         iconProperty().set(icon);
152     }
153 
154     public String getIcon() {
155         return icon == null null : iconProperty().get();
156     }
157 
158     // -- image
159 
160     private ObjectProperty<Image> image;
161 
162     public final ObjectProperty<Image> imageProperty() {
163         if (image == null) {
164             image = new SimpleObjectProperty<>(this, "image");
165         }
166         return image;
167     }
168 
169     public void setImage(Image image) {
170         imageProperty().set(image);
171     }
172 
173     public Image getImage() {
174         return image == null null : imageProperty().get();
175     }
176 
177     // -- graphic
178 
179     private ObjectProperty<Node> graphic;
180 
181     public final ObjectProperty<Node> graphicProperty() {
182         if (graphic == null) {
183             graphic = new SimpleObjectProperty<>(this, "graphic");
184         }
185         return graphic;
186     }
187 
188     public void setGraphic(Node graphic) {
189         graphicProperty().set(graphic);
190     }
191 
192     public Node getGraphic() {
193         return graphic == null null : graphicProperty().get();
194     }
195 
196     // -- selected
197 
198     private BooleanProperty selected;
199 
200     public final BooleanProperty selectedProperty() {
201         if (selected == null) {
202             selected = new SimpleBooleanProperty(this, "selected");
203         }
204         return selected;
205     }
206 
207     public void setSelected(boolean selected) {
208         selectedProperty().set(selected);
209     }
210 
211     public boolean getSelected() {
212         return selected != null && selectedProperty().get();
213     }
214 
215     public boolean isSelected() {
216         return selected != null && selectedProperty().get();
217     }
218 
219     // -- visible
220 
221     private BooleanProperty visible;
222 
223     public final BooleanProperty visibleProperty() {
224         if (visible == null) {
225             visible = new SimpleBooleanProperty(this, "visible"true);
226         }
227         return visible;
228     }
229 
230     public void setVisible(boolean visible) {
231         visibleProperty().set(visible);
232     }
233 
234     public boolean getVisible() {
235         return visible != null && visibleProperty().get();
236     }
237 
238     public boolean isVisible() {
239         return visible != null && visibleProperty().get();
240     }
241 
242     // -- styleClass
243 
244     private StringProperty styleClass;
245 
246     public final StringProperty styleClassProperty() {
247         if (styleClass == null) {
248             styleClass = new SimpleStringProperty(this, "styleClass");
249         }
250         return styleClass;
251     }
252 
253     public void setStyleClass(String styleClass) {
254         styleClassProperty().set(styleClass);
255     }
256 
257     public String getStyleClass() {
258         return styleClass == null null : styleClassProperty().get();
259     }
260 
261     // -- style
262 
263     private StringProperty style;
264 
265     public final StringProperty styleProperty() {
266         if (style == null) {
267             style = new SimpleStringProperty(this, "style");
268         }
269         return style;
270     }
271 
272     public void setStyle(String style) {
273         styleProperty().set(style);
274     }
275 
276     public String getStyle() {
277         return style == null null : styleProperty().get();
278     }
279 
280     // -- graphicStyleClass
281 
282     private StringProperty graphicStyleClass;
283 
284     public final StringProperty graphicStyleClassProperty() {
285         if (graphicStyleClass == null) {
286             graphicStyleClass = new SimpleStringProperty(this, "graphicStyleClass");
287         }
288         return graphicStyleClass;
289     }
290 
291     public void setGraphicStyleClass(String graphicStyleClass) {
292         graphicStyleClassProperty().set(graphicStyleClass);
293     }
294 
295     public String getGraphicStyleClass() {
296         return graphicStyleClass == null null : graphicStyleClassProperty().get();
297     }
298 
299     // -- graphicStyle
300 
301     private StringProperty graphicStyle;
302 
303     public final StringProperty graphicStyleProperty() {
304         if (graphicStyle == null) {
305             graphicStyle = new SimpleStringProperty(this, "graphicStyle");
306         }
307         return graphicStyle;
308     }
309 
310     public void setGraphicStyle(String graphicStyle) {
311         graphicStyleProperty().set(graphicStyle);
312     }
313 
314     public String getGraphicStyle() {
315         return graphicStyle == null null : graphicStyleProperty().get();
316     }
317 }