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