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