apps/toys/Hello/src/main/java/hello/dialog/dialogs/CommandLinksDialog.java

Print this page




  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package hello.dialog.dialogs;
  26 
  27 import java.util.ArrayList;
  28 import java.util.Arrays;
  29 import java.util.List;
  30 
  31 import javafx.scene.control.skin.AccordionSkin;
  32 import com.sun.javafx.scene.control.skin.resources.ControlResources;
  33 import hello.HelloAccordion;
  34 import javafx.beans.binding.DoubleBinding;
  35 import javafx.collections.ListChangeListener;
  36 import javafx.event.ActionEvent;
  37 import javafx.event.EventHandler;
  38 import javafx.geometry.Insets;
  39 import javafx.geometry.Pos;
  40 import javafx.geometry.VPos;
  41 import javafx.scene.Node;
  42 import javafx.scene.control.Button;
  43 import javafx.scene.control.ButtonBar.ButtonData;
  44 import javafx.scene.control.ButtonType;
  45 import javafx.scene.control.Dialog;
  46 import javafx.scene.control.DialogPane;
  47 import javafx.scene.control.Label;
  48 import javafx.scene.image.Image;
  49 import javafx.scene.image.ImageView;
  50 import javafx.scene.layout.GridPane;
  51 import javafx.scene.layout.Priority;
  52 
  53 public class CommandLinksDialog extends Dialog<ButtonType> {


  78         }
  79     };
  80     
  81     public CommandLinksDialog(ButtonType... links) {
  82         this(Arrays.asList(links));
  83     }
  84     
  85     public CommandLinksDialog(List<ButtonType> links) {
  86         this.grid.setHgap(gapSize);
  87         this.grid.setVgap(gapSize);
  88         
  89         final DialogPane dialogPane = new DialogPane() {
  90             @Override protected Node createButtonBar() {
  91                 return null;
  92             }
  93         }; 
  94         setDialogPane(dialogPane);
  95         
  96         dialogPane.getStylesheets().add(getClass().getResource("commandlink.css").toExternalForm());
  97 
  98         setTitle(ControlResources.getString("Dialog.info.title"));
  99 
 100         // FIXME extract to CSS
 101         dialogPane.setGraphic(new ImageView(new Image(AccordionSkin.class.getResource("modena/dialog-information.png").toExternalForm())));
 102         dialogPane.getButtonTypes().addAll(links);
 103         
 104         dialogPane.contentProperty().addListener(o -> updateGrid());
 105 
 106         updateGrid();
 107         dialogPane.getButtonTypes().addListener((ListChangeListener<? super ButtonType>)c -> {
 108             updateGrid();
 109         });
 110     }
 111     
 112     private void updateGrid() {
 113         final Node content = getDialogPane().getContent();
 114         final boolean dialogContentIsGrid = grid == content;
 115         
 116         if (! dialogContentIsGrid) {
 117             if (content != null) {
 118                 content.getStyleClass().add("command-link-message");
 119                 grid.add(content, 0, 0);
 120             }
 121         }


 183         });
 184         titleLabel.getStyleClass().addAll("line-1");
 185         titleLabel.setWrapText(true);
 186         titleLabel.setAlignment(Pos.TOP_LEFT);
 187         GridPane.setVgrow(titleLabel, Priority.NEVER);
 188 
 189         // TODO no support in DialogButton for long text or graphic
 190 //        Label messageLabel = new Label(commandLink.getLongText() );
 191 //        messageLabel.getStyleClass().addAll("line-2");
 192 //        messageLabel.setWrapText(true);
 193 //        messageLabel.setAlignment(Pos.TOP_LEFT);
 194 //        messageLabel.setMaxHeight(Double.MAX_VALUE);
 195 //        GridPane.setVgrow(messageLabel, Priority.SOMETIMES);
 196 //
 197 //        Image commandLinkImage = commandLink.getGraphic();
 198 //        Node view = commandLinkImage == null ? 
 199 //                new ImageView(getClass().getResource("arrow-green-right.png").toExternalForm()) : 
 200 //                new ImageView(commandLinkImage);
 201 //        Pane graphicContainer = new Pane(view);
 202 //        graphicContainer.getStyleClass().add("graphic-container");
 203         ImageView arrow = new ImageView(HelloAccordion.class.getResource("about_16.png").toExternalForm());

 204         GridPane.setValignment(arrow, VPos.TOP);
 205         GridPane.setMargin(arrow, new Insets(0,10,0,0));
 206 
 207         GridPane grid = new GridPane();
 208         grid.minWidthProperty().bind(titleLabel.prefWidthProperty());
 209         grid.setMaxHeight(Double.MAX_VALUE);
 210         grid.setMaxWidth(Double.MAX_VALUE);
 211         grid.getStyleClass().add("container");
 212         grid.add(arrow, 0, 0, 1, 2);
 213         grid.add(titleLabel, 1, 0);
 214 //        grid.add(messageLabel, 1, 1);
 215 
 216         button.setGraphic(grid);
 217         button.minWidthProperty().bind(titleLabel.prefWidthProperty());
 218 
 219         return button;
 220     }    
 221 }


  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package hello.dialog.dialogs;
  26 
  27 import java.util.ArrayList;
  28 import java.util.Arrays;
  29 import java.util.List;
  30 



  31 import javafx.beans.binding.DoubleBinding;
  32 import javafx.collections.ListChangeListener;
  33 import javafx.event.ActionEvent;
  34 import javafx.event.EventHandler;
  35 import javafx.geometry.Insets;
  36 import javafx.geometry.Pos;
  37 import javafx.geometry.VPos;
  38 import javafx.scene.Node;
  39 import javafx.scene.control.Button;
  40 import javafx.scene.control.ButtonBar.ButtonData;
  41 import javafx.scene.control.ButtonType;
  42 import javafx.scene.control.Dialog;
  43 import javafx.scene.control.DialogPane;
  44 import javafx.scene.control.Label;
  45 import javafx.scene.image.Image;
  46 import javafx.scene.image.ImageView;
  47 import javafx.scene.layout.GridPane;
  48 import javafx.scene.layout.Priority;
  49 
  50 public class CommandLinksDialog extends Dialog<ButtonType> {


  75         }
  76     };
  77     
  78     public CommandLinksDialog(ButtonType... links) {
  79         this(Arrays.asList(links));
  80     }
  81     
  82     public CommandLinksDialog(List<ButtonType> links) {
  83         this.grid.setHgap(gapSize);
  84         this.grid.setVgap(gapSize);
  85         
  86         final DialogPane dialogPane = new DialogPane() {
  87             @Override protected Node createButtonBar() {
  88                 return null;
  89             }
  90         }; 
  91         setDialogPane(dialogPane);
  92         
  93         dialogPane.getStylesheets().add(getClass().getResource("commandlink.css").toExternalForm());
  94 


  95         // FIXME extract to CSS
  96         dialogPane.setGraphic(new ImageView(new Image(getClass().getResource("/hello/dialog/dialog-information.png").toExternalForm())));
  97         dialogPane.getButtonTypes().addAll(links);
  98         
  99         dialogPane.contentProperty().addListener(o -> updateGrid());
 100 
 101         updateGrid();
 102         dialogPane.getButtonTypes().addListener((ListChangeListener<? super ButtonType>)c -> {
 103             updateGrid();
 104         });
 105     }
 106     
 107     private void updateGrid() {
 108         final Node content = getDialogPane().getContent();
 109         final boolean dialogContentIsGrid = grid == content;
 110         
 111         if (! dialogContentIsGrid) {
 112             if (content != null) {
 113                 content.getStyleClass().add("command-link-message");
 114                 grid.add(content, 0, 0);
 115             }
 116         }


 178         });
 179         titleLabel.getStyleClass().addAll("line-1");
 180         titleLabel.setWrapText(true);
 181         titleLabel.setAlignment(Pos.TOP_LEFT);
 182         GridPane.setVgrow(titleLabel, Priority.NEVER);
 183 
 184         // TODO no support in DialogButton for long text or graphic
 185 //        Label messageLabel = new Label(commandLink.getLongText() );
 186 //        messageLabel.getStyleClass().addAll("line-2");
 187 //        messageLabel.setWrapText(true);
 188 //        messageLabel.setAlignment(Pos.TOP_LEFT);
 189 //        messageLabel.setMaxHeight(Double.MAX_VALUE);
 190 //        GridPane.setVgrow(messageLabel, Priority.SOMETIMES);
 191 //
 192 //        Image commandLinkImage = commandLink.getGraphic();
 193 //        Node view = commandLinkImage == null ? 
 194 //                new ImageView(getClass().getResource("arrow-green-right.png").toExternalForm()) : 
 195 //                new ImageView(commandLinkImage);
 196 //        Pane graphicContainer = new Pane(view);
 197 //        graphicContainer.getStyleClass().add("graphic-container");
 198         
 199         ImageView arrow = new ImageView(getClass().getResource("/hello/about_16.png").toExternalForm());
 200         GridPane.setValignment(arrow, VPos.TOP);
 201         GridPane.setMargin(arrow, new Insets(0,10,0,0));
 202 
 203         GridPane grid = new GridPane();
 204         grid.minWidthProperty().bind(titleLabel.prefWidthProperty());
 205         grid.setMaxHeight(Double.MAX_VALUE);
 206         grid.setMaxWidth(Double.MAX_VALUE);
 207         grid.getStyleClass().add("container");
 208         grid.add(arrow, 0, 0, 1, 2);
 209         grid.add(titleLabel, 1, 0);
 210 //        grid.add(messageLabel, 1, 1);
 211 
 212         button.setGraphic(grid);
 213         button.minWidthProperty().bind(titleLabel.prefWidthProperty());
 214 
 215         return button;
 216     }    
 217 }