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

Print this page




  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.Collections;
  29 import java.util.HashSet;
  30 import java.util.List;
  31 import java.util.Set;
  32 import java.util.function.Predicate;
  33 
  34 import javafx.scene.control.skin.AccordionSkin;
  35 
  36 import javafx.application.Platform;
  37 import javafx.beans.binding.DoubleBinding;
  38 import javafx.beans.value.ChangeListener;
  39 import javafx.beans.value.ObservableValue;
  40 import javafx.collections.FXCollections;
  41 import javafx.collections.transformation.FilteredList;
  42 import javafx.geometry.Pos;
  43 import javafx.scene.control.ButtonType;
  44 import javafx.scene.control.Dialog;
  45 import javafx.scene.control.DialogPane;
  46 import javafx.scene.control.Label;
  47 import javafx.scene.control.ListCell;
  48 import javafx.scene.control.ListView;
  49 import javafx.scene.image.Image;
  50 import javafx.scene.image.ImageView;
  51 import javafx.scene.layout.ColumnConstraints;
  52 import javafx.scene.layout.GridPane;
  53 import javafx.scene.layout.Priority;
  54 import javafx.scene.layout.RowConstraints;
  55 import javafx.scene.layout.StackPane;


  62 
  63 public class FontSelectorDialog extends Dialog<Font> {
  64     
  65     private FontPanel fontPanel;
  66     private Font defaultFont;
  67 
  68     public FontSelectorDialog(Font defaultFont) {
  69         fontPanel = new FontPanel();
  70         fontPanel.setFont(defaultFont);
  71         
  72         this.defaultFont = defaultFont;
  73         
  74         setResultConverter(dialogButton -> dialogButton == ButtonType.OK ? fontPanel.getFont() : null);
  75                 
  76         final DialogPane dialogPane = getDialogPane();
  77         
  78         setTitle("Select font");
  79         dialogPane.setHeaderText("Select font");
  80 
  81         // FIXME extract to CSS
  82         dialogPane.setGraphic(new ImageView(new Image(AccordionSkin.class.getResource("modena/dialog-confirm.png").toExternalForm())));
  83         dialogPane.getButtonTypes().addAll(ButtonType.OK, ButtonType.CANCEL);
  84         dialogPane.setContent(fontPanel);
  85     }
  86     
  87 
  88     
  89     /**************************************************************************
  90      * 
  91      * Support classes
  92      * 
  93      **************************************************************************/
  94 
  95     /**
  96      * Font style as combination of font weight and font posture. 
  97      * Weight does not have to be there (represented by null)
  98      * Posture is required, null posture is converted to REGULAR
  99      */
 100     private static class FontStyle implements Comparable<FontStyle> {
 101 
 102         private FontPosture posture; 




  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.Collections;
  29 import java.util.HashSet;
  30 import java.util.List;
  31 import java.util.Set;
  32 import java.util.function.Predicate;
  33 


  34 import javafx.application.Platform;
  35 import javafx.beans.binding.DoubleBinding;
  36 import javafx.beans.value.ChangeListener;
  37 import javafx.beans.value.ObservableValue;
  38 import javafx.collections.FXCollections;
  39 import javafx.collections.transformation.FilteredList;
  40 import javafx.geometry.Pos;
  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.control.ListCell;
  46 import javafx.scene.control.ListView;
  47 import javafx.scene.image.Image;
  48 import javafx.scene.image.ImageView;
  49 import javafx.scene.layout.ColumnConstraints;
  50 import javafx.scene.layout.GridPane;
  51 import javafx.scene.layout.Priority;
  52 import javafx.scene.layout.RowConstraints;
  53 import javafx.scene.layout.StackPane;


  60 
  61 public class FontSelectorDialog extends Dialog<Font> {
  62     
  63     private FontPanel fontPanel;
  64     private Font defaultFont;
  65 
  66     public FontSelectorDialog(Font defaultFont) {
  67         fontPanel = new FontPanel();
  68         fontPanel.setFont(defaultFont);
  69         
  70         this.defaultFont = defaultFont;
  71         
  72         setResultConverter(dialogButton -> dialogButton == ButtonType.OK ? fontPanel.getFont() : null);
  73                 
  74         final DialogPane dialogPane = getDialogPane();
  75         
  76         setTitle("Select font");
  77         dialogPane.setHeaderText("Select font");
  78 
  79         // FIXME extract to CSS
  80         dialogPane.setGraphic(new ImageView(new Image(getClass().getResource("/hello/dialog/dialog-confirm.png").toExternalForm())));
  81         dialogPane.getButtonTypes().addAll(ButtonType.OK, ButtonType.CANCEL);
  82         dialogPane.setContent(fontPanel);
  83     }
  84     
  85 
  86     
  87     /**************************************************************************
  88      * 
  89      * Support classes
  90      * 
  91      **************************************************************************/
  92 
  93     /**
  94      * Font style as combination of font weight and font posture. 
  95      * Weight does not have to be there (represented by null)
  96      * Posture is required, null posture is converted to REGULAR
  97      */
  98     private static class FontStyle implements Comparable<FontStyle> {
  99 
 100         private FontPosture posture;