JavaFXAction.java
001 /*
002  * Copyright 2008-2014 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.*;
019 import javafx.event.ActionEvent;
020 import javafx.event.EventHandler;
021 import javafx.scene.input.KeyCombination;
022 
023 /**
024  @author Andres Almiray
025  */
026 public class JavaFXAction {
027     // -- onAction
028 
029     private ObjectProperty<EventHandler<ActionEvent>> onAction;
030 
031     public final ObjectProperty<EventHandler<ActionEvent>> onActionProperty() {
032         if (onAction == null) {
033             onAction = new SimpleObjectProperty<>(this, "onAction");
034         }
035         return onAction;
036     }
037 
038     public void setOnAction(EventHandler<ActionEvent> value) {
039         onActionProperty().set(value);
040     }
041 
042     public EventHandler<ActionEvent> getOnAction() {
043         return onAction == null null : onActionProperty().get();
044     }
045 
046     // -- name
047 
048     private StringProperty name;
049 
050     public final StringProperty nameProperty() {
051         if (name == null) {
052             name = new SimpleStringProperty(this, "name");
053         }
054         return name;
055     }
056 
057     public void setName(String name) {
058         nameProperty().set(name);
059     }
060 
061     public String getName() {
062         return name == null null : nameProperty().get();
063     }
064 
065     // -- description
066 
067     private StringProperty description;
068 
069     public final StringProperty descriptionProperty() {
070         if (description == null) {
071             description = new SimpleStringProperty(this, "description");
072         }
073         return description;
074     }
075 
076     public void setDescription(String description) {
077         descriptionProperty().set(description);
078     }
079 
080     public String getDescription() {
081         return description == null null : descriptionProperty().get();
082     }
083 
084     // -- enabled
085 
086     private BooleanProperty enabled;
087 
088     public final BooleanProperty enabledProperty() {
089         if (enabled == null) {
090             enabled = new SimpleBooleanProperty(this, "enabled"true);
091         }
092         return enabled;
093     }
094 
095     public void setEnabled(boolean enabled) {
096         enabledProperty().set(enabled);
097     }
098 
099     public boolean getEnabled() {
100         return enabled != null && enabledProperty().get();
101     }
102 
103     // -- accelerator
104 
105     private ObjectProperty<KeyCombination> accelerator;
106 
107     public void setAccelerator(String accelerator) {
108         setAccelerator(KeyCombination.keyCombination(accelerator));
109     }
110 
111     public final void setAccelerator(KeyCombination value) {
112         acceleratorProperty().set(value);
113     }
114 
115     public final KeyCombination getAccelerator() {
116         return accelerator == null null : accelerator.get();
117     }
118 
119     public final ObjectProperty<KeyCombination> acceleratorProperty() {
120         if (accelerator == null) {
121             accelerator = new SimpleObjectProperty<>(this, "accelerator");
122         }
123         return accelerator;
124     }
125 
126     // -- icon
127 
128     private StringProperty icon;
129 
130     public final StringProperty iconProperty() {
131         if (icon == null) {
132             icon = new SimpleStringProperty(this, "icon");
133         }
134         return icon;
135     }
136 
137     public void setIcon(String icon) {
138         iconProperty().set(icon);
139     }
140 
141     public String getIcon() {
142         return icon == null null : iconProperty().get();
143     }
144 
145     // -- selected
146 
147     private BooleanProperty selected;
148 
149     public final BooleanProperty selectedProperty() {
150         if (selected == null) {
151             selected = new SimpleBooleanProperty(this, "selected");
152         }
153         return selected;
154     }
155 
156     public void setSelected(boolean selected) {
157         selectedProperty().set(selected);
158     }
159 
160     public boolean getSelected() {
161         return selected != null && selectedProperty().get();
162     }
163 }