Commits

Eugene Ryzhikov committed b67a02d

Return actions to use Node instead of image in preparation of using icon font glyphs

Comments (0)

Files changed (11)

src/main/java/impl/org/controlsfx/skin/PropertySheetSkin.java

 import javafx.scene.control.ToolBar;
 import javafx.scene.control.Tooltip;
 import javafx.scene.image.Image;
+import javafx.scene.image.ImageView;
 import javafx.scene.layout.BorderPane;
 import javafx.scene.layout.GridPane;
 import javafx.scene.layout.HBox;
     
     private class ActionChangeMode extends AbstractAction {
         
+    	private final Image CATEGORY_IMAGE = new Image("/impl/org/controlsfx/dialog/resources/oxygen/16/format-indent-more.png");
+    	private final Image NAME_IMAGE = new Image("/impl/org/controlsfx/dialog/resources/oxygen/16/format-line-spacing-triple.png");
+    	
         private PropertySheet.Mode mode;
         
         public ActionChangeMode(PropertySheet.Mode mode) {
             final String text = "By " + capitalize(mode.toString());
             
             if (mode == Mode.CATEGORY) {
-                setGraphic(new Image("/impl/org/controlsfx/dialog/resources/oxygen/16/format-indent-more.png"));
+                setGraphic( new ImageView(CATEGORY_IMAGE));
                 setLongText(text);
             } else if (mode == Mode.NAME) {
-                setGraphic(new Image("/impl/org/controlsfx/dialog/resources/oxygen/16/format-line-spacing-triple.png"));
+                setGraphic(new ImageView(CATEGORY_IMAGE));
                 setLongText(text);
             } else {
                 setText(text);

src/main/java/org/controlsfx/control/action/AbstractAction.java

 import javafx.collections.FXCollections;
 import javafx.collections.ObservableMap;
 import javafx.event.ActionEvent;
+import javafx.scene.Node;
 import javafx.scene.control.Button;
-import javafx.scene.image.Image;
 
 /**
  * A convenience class that implements the {@link Action} interface and provides
     
     
     // --- graphic
-    private final ObjectProperty<Image> graphicProperty = new SimpleObjectProperty<Image>(this, "graphic");
+    private final ObjectProperty<Node> graphicProperty = new SimpleObjectProperty<Node>(this, "graphic");
     
     /** {@inheritDoc} */
-    @Override public ObjectProperty<Image> graphicProperty() {
+    @Override public ObjectProperty<Node> graphicProperty() {
         return graphicProperty;
     }
     
     //  javadoc auto-generated from property
-    public final Image getGraphic() {
+    public final Node getGraphic() {
         return graphicProperty.get();
     }
     
     //  javadoc auto-generated from property
-    public final void setGraphic(Image value) {
+    public final void setGraphic(Node value) {
         graphicProperty.set(value);
     }
     

src/main/java/org/controlsfx/control/action/Action.java

 import javafx.beans.property.StringProperty;
 import javafx.collections.ObservableMap;
 import javafx.event.ActionEvent;
+import javafx.scene.Node;
 import javafx.scene.control.Button;
 import javafx.scene.control.Menu;
-import javafx.scene.image.Image;
 
 /**
  * Common interface for dialog actions, where Actions are converted into buttons 
      * @return An observable {@link ObjectProperty} that represents the current
      *      graphic for this property, and which can be observed for changes.
      */
-    public ObjectProperty<Image> graphicProperty();
+    public ObjectProperty<Node> graphicProperty();
     
     /**
      * Returns an observable map of properties on this Action for use primarily

src/main/java/org/controlsfx/control/action/ActionGroup.java

 import javafx.collections.FXCollections;
 import javafx.collections.ObservableList;
 import javafx.event.ActionEvent;
+import javafx.scene.Node;
 import javafx.scene.control.ContextMenu;
 import javafx.scene.control.MenuBar;
 import javafx.scene.control.ToolBar;
-import javafx.scene.image.Image;
 
 /**
  * An ActionGroup (unsurprisingly) groups together zero or more {@link Action} 
      * @param icon The {@link Action#graphicProperty() image} of this {@link Action}.
      * @param actions Zero or more actions to insert into this ActionGroup.
      */
-    public ActionGroup(String text, Image icon, Action... actions) {
+    public ActionGroup(String text, Node icon, Action... actions) {
     	 this( text, icon, Arrays.asList(actions));
     }
     
      * @param icon The {@link Action#graphicProperty() image} of this {@link Action}.
      * @param actions Collection of actions to insert into this ActionGroup.
      */
-    public ActionGroup(String text, Image icon, Collection<Action> actions) {
+    public ActionGroup(String text, Node icon, Collection<Action> actions) {
         super(text);
         setGraphic(icon);
         getActions().addAll(actions);

src/main/java/org/controlsfx/control/action/ActionMap.java

 
 import javafx.event.ActionEvent;
 import javafx.scene.image.Image;
+import javafx.scene.image.ImageView;
 
 /**
  * Action Map provides an ability to create an action map of any object.
 		
 		String imageLocation = annotation.image().trim();
 		if ( !imageLocation.isEmpty()) {
-			this.setGraphic(new Image(imageLocation));
+			this.setGraphic(new ImageView(new Image(imageLocation)));
 		}
 		
 		String longText = annotation.longText().trim();

src/main/java/org/controlsfx/control/action/ActionUtils.java

 import javafx.scene.control.ToggleButton;
 import javafx.scene.control.ToolBar;
 import javafx.scene.control.Tooltip;
-import javafx.scene.image.Image;
 import javafx.scene.image.ImageView;
 
 import org.controlsfx.control.ButtonBar;
 import org.controlsfx.control.SegmentedButton;
+import org.controlsfx.tools.Duplicatable;
 
 /**
  * Convenience class for users of the {@link Action} API. Primarily this class
             return null;
         }
 
-        @Override public ObjectProperty<Image> graphicProperty() {
+        @Override public ObjectProperty<Node> graphicProperty() {
             return null;
         }
 
         
     }
     
+    private static Node copyNode( Node node ) {
+    	if ( node instanceof ImageView ) {
+    		return new ImageView( ((ImageView)node).getImage());
+    	} else if ( node instanceof Duplicatable<?> ) {
+    		return (Node) ((Duplicatable<?>)node).duplicate();
+    	} else {
+    	    return null;
+    	}
+    }
+    
     private static <T extends ButtonBase> T configure(final T btn, final Action action, final ActionTextBehavior textBahavior ) {
         
         if (action == null) {
         btn.disableProperty().bind(action.disabledProperty());
         
         
-        btn.graphicProperty().bind(new ObjectBinding<ImageView>() {
+        btn.graphicProperty().bind(new ObjectBinding<Node>() {
             { bind(action.graphicProperty()); }
 
-            @Override protected ImageView computeValue() {
-                Image image = action.graphicProperty().get();
-                return image == null? null: new ImageView(image);
+            @Override protected Node computeValue() {
+                return copyNode(action.graphicProperty().get());
             }
         });
         
         btn.textProperty().bind(action.textProperty());
         btn.disableProperty().bind(action.disabledProperty());
         
-        btn.graphicProperty().bind(new ObjectBinding<ImageView>() {
+        btn.graphicProperty().bind(new ObjectBinding<Node>() {
             { bind(action.graphicProperty()); }
 
-            @Override protected ImageView computeValue() {
-                Image image = action.graphicProperty().get();
-                return image == null? null: new ImageView(image);
+            @Override protected Node computeValue() {
+                return copyNode( action.graphicProperty().get());
             }
         });
         

src/main/java/org/controlsfx/dialog/Dialog.java

 import javafx.scene.control.ButtonBase;
 import javafx.scene.control.Hyperlink;
 import javafx.scene.control.Label;
-import javafx.scene.image.Image;
 import javafx.scene.layout.BorderPane;
 import javafx.scene.layout.ColumnConstraints;
 import javafx.scene.layout.GridPane;
         }
         
         /** {@inheritDoc} */
-        @Override public ObjectProperty<Image> graphicProperty() {
+        @Override public ObjectProperty<Node> graphicProperty() {
             return action.graphicProperty();
         }
         

src/main/java/org/controlsfx/dialog/Dialogs.java

         messageLabel.setMaxHeight(Double.MAX_VALUE);
         GridPane.setVgrow(messageLabel, Priority.SOMETIMES);
         
-        Image graphic = commandLink.getGraphic();
-        ImageView view = new ImageView( graphic == null? DialogResources.getImage("command.link.icon") : graphic);
+        Node graphic = commandLink.getGraphic();
+        Node view = graphic == null? new ImageView( DialogResources.getImage("command.link.icon")) : graphic;
         Pane graphicContainer = new Pane(view);
         graphicContainer.getStyleClass().add("graphic-container");
         GridPane.setValignment(graphicContainer, VPos.TOP);
      */
     public static class CommandLink extends AbstractDialogAction {
         
-        public CommandLink( Image graphic, String text, String longText ) {
+        public CommandLink( Node graphic, String text, String longText ) {
             super(text);
             setLongText(longText);
             setGraphic(graphic);

src/main/java/org/controlsfx/tools/Duplicatable.java

+package org.controlsfx.tools;
+
+public interface Duplicatable<T> {
+   T duplicate();
+}

src/samples/java/org/controlsfx/samples/actions/HelloActionGroup.java

 import javafx.scene.control.Label;
 import javafx.scene.control.Separator;
 import javafx.scene.image.Image;
+import javafx.scene.image.ImageView;
 import javafx.scene.layout.HBox;
 import javafx.scene.layout.Priority;
 import javafx.scene.layout.VBox;
 import javafx.scene.paint.Color;
-import javafx.scene.text.TextAlignment;
 import javafx.stage.Stage;
 
 import org.controlsfx.Sample;
 
 public class HelloActionGroup extends Application implements Sample {
     
-    private static final Image image = new Image("/org/controlsfx/samples/security-low.png");
+    private static final ImageView image = new ImageView( new Image("/org/controlsfx/samples/security-low.png"));
     
     private Collection<? extends Action> actions = Arrays.asList(
         new ActionGroup("Group 1", image, new DummyAction("Action 1.1", image), 
         new ActionGroup("Group 2", image, new DummyAction("Action 2.1"), 
                                           ACTION_SEPARATOR,
                                           new ActionGroup("Action 2.2", new DummyAction("Action 2.2.1"), 
-                                                                  new DummyAction("Action 2.2.2")),
+                                                                        new DummyAction("Action 2.2.2")),
                                           new DummyAction("Action 2.3") ),
         ACTION_SEPARATOR,                                    
         new DummyAction("Action 3", image),
     
     static class DummyAction extends AbstractAction {
 
-        public DummyAction(String name, Image image) {
+        public DummyAction(String name, Node image) {
             super(name);
             setGraphic(image);
         }

src/samples/java/org/controlsfx/samples/actions/HelloActionProxy.java

 import javafx.scene.control.Label;
 import javafx.scene.control.Separator;
 import javafx.scene.image.Image;
+import javafx.scene.image.ImageView;
 import javafx.scene.layout.HBox;
 import javafx.scene.layout.Priority;
 import javafx.scene.layout.VBox;
 public class HelloActionProxy extends Application implements Sample {
     
     private static final String imagePath = "/org/controlsfx/samples/security-low.png";
-    private static final Image image = new Image(imagePath);
+    private static final ImageView image = new ImageView(new Image(imagePath));
     
     private Collection<? extends Action> actions;