From 63ccd44664b5ff2df3d5621ae286eac5f7b9b15f Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Wed, 15 Nov 2017 18:12:46 +0100 Subject: [PATCH] Updated css + added layout: main.submenu, main.container --- Classes/css/core/Context.java | 5 +++ Classes/css/core/Rule.java | 8 +++-- Classes/css/core/Ruleset.java | 20 ++++++++++- Classes/css/core/rule/JavaFX.java | 10 ++++-- Classes/css/core/rule/Padding.java | 9 ++++- Classes/css/core/rule/Position.java | 8 ++++- Classes/css/user/ContextBuilder.java | 2 ++ Classes/css/user/HeaderIconStyleSheet.java | 34 +++++++++++++++++++ .../{Header.java => HeaderStyleSheet.java} | 9 ++--- ...MenuContainer.java => MenuStyleSheet.java} | 12 ++++--- Classes/css/user/SubMenuStyleSheet.java | 31 +++++++++++++++++ controller/RootLayout.java | 16 ++++++--- css/menu.css | 3 +- fxml/model.fxml | 6 ++-- 14 files changed, 151 insertions(+), 22 deletions(-) create mode 100644 Classes/css/user/HeaderIconStyleSheet.java rename Classes/css/user/{Header.java => HeaderStyleSheet.java} (88%) rename Classes/css/user/{MenuContainer.java => MenuStyleSheet.java} (74%) create mode 100644 Classes/css/user/SubMenuStyleSheet.java diff --git a/Classes/css/core/Context.java b/Classes/css/core/Context.java index 3a8768e..3227dc2 100644 --- a/Classes/css/core/Context.java +++ b/Classes/css/core/Context.java @@ -25,6 +25,11 @@ public class Context{ Context.type.put(index, Context.TYPE_STR); } + public static void bind(String index, Color data){ /* Color */ + Context.attr.put(index, data); + Context.type.put(index, Context.TYPE_COL); + } + public static void bind(String index, int r, int g, int b){ /* Color */ Context.attr.put(index, Color.rgb(r, g, b)); Context.type.put(index, Context.TYPE_COL); diff --git a/Classes/css/core/Rule.java b/Classes/css/core/Rule.java index 81ccbf8..699b30e 100644 --- a/Classes/css/core/Rule.java +++ b/Classes/css/core/Rule.java @@ -1,9 +1,13 @@ package Classes.css.core; +import java.io.Serializable; + import javafx.scene.Node; -public interface Rule{ +public abstract class Rule implements Serializable{ - public void apply(Node target) throws Exception; + public abstract void apply(Node target) throws Exception; + + public abstract String toString(); } diff --git a/Classes/css/core/Ruleset.java b/Classes/css/core/Ruleset.java index 5d5a219..5c9dfe1 100644 --- a/Classes/css/core/Ruleset.java +++ b/Classes/css/core/Ruleset.java @@ -6,9 +6,12 @@ import Classes.css.core.rule.JavaFX; import Classes.css.core.rule.Padding; import Classes.css.core.rule.Position; import javafx.scene.Node; +import javafx.scene.layout.AnchorPane; public class Ruleset { + private final static boolean DEBUG = false; + /* Attributes */ private Node target; private ArrayList rule; @@ -89,9 +92,24 @@ public class Ruleset { int il = this.rule.size(); /* (2) Apply each rule */ - for( ; i < il ; i++ ) + for( ; i < il ; i++ ){ + + if( Ruleset.DEBUG ) + System.out.println("[SET] "+this.target.getId()+"."+this.rule.get(i)); + this.rule.get(i).apply(this.target); + if( Ruleset.DEBUG ){ + + // if position + if( this.rule.get(i) instanceof Position ) + System.out.println("[CHK] "+this.target.getId()+".position: "+AnchorPane.getTopAnchor(this.target)+" "+AnchorPane.getRightAnchor(this.target)+" "+AnchorPane.getBottomAnchor(this.target)+" "+AnchorPane.getLeftAnchor(this.target)); + System.out.println("[CHK] "+this.target.getId()+"."+this.target.getStyle()); + System.out.println(); + } + + } + /* (3) Stop the Chain design pattern */ return; diff --git a/Classes/css/core/rule/JavaFX.java b/Classes/css/core/rule/JavaFX.java index 4abdf99..3863480 100644 --- a/Classes/css/core/rule/JavaFX.java +++ b/Classes/css/core/rule/JavaFX.java @@ -3,7 +3,7 @@ package Classes.css.core.rule; import Classes.css.core.Rule; import javafx.scene.Node; -public class JavaFX implements Rule{ +public class JavaFX extends Rule{ /* Attributes */ private String l_side; @@ -23,7 +23,7 @@ public class JavaFX implements Rule{ public void apply(Node target){ /* (1) Prefix with '-fx-' */ - String css_prop = "-fx-"+this.l_side+": "+this.r_side+";"; // "name: val;" + String css_prop = this.toString(); // "name: val;" /* (2) Apply to target */ target.setStyle(css_prop); @@ -32,4 +32,10 @@ public class JavaFX implements Rule{ } + @Override + public String toString() { + return "-fx-"+this.l_side+": "+this.r_side+";"; + } + + } diff --git a/Classes/css/core/rule/Padding.java b/Classes/css/core/rule/Padding.java index 8a4720c..0c9c4b6 100644 --- a/Classes/css/core/rule/Padding.java +++ b/Classes/css/core/rule/Padding.java @@ -7,7 +7,7 @@ import javafx.geometry.Insets; import javafx.scene.Node; import javafx.scene.layout.Region; -public class Padding implements Rule{ +public class Padding extends Rule{ /* Attributes */ private Integer top; @@ -105,4 +105,11 @@ public class Padding implements Rule{ } + + @Override + public String toString() { + return "padding: "+this.top+" "+this.right+" "+this.bottom+" "+this.left+";"; + } + + } diff --git a/Classes/css/core/rule/Position.java b/Classes/css/core/rule/Position.java index 8c48564..12b12c6 100644 --- a/Classes/css/core/rule/Position.java +++ b/Classes/css/core/rule/Position.java @@ -4,7 +4,7 @@ import Classes.css.core.Rule; import javafx.scene.Node; import javafx.scene.layout.AnchorPane; -public class Position implements Rule{ +public class Position extends Rule{ /* Attributes */ private String direction; @@ -53,4 +53,10 @@ public class Position implements Rule{ } + @Override + public String toString() { + return this.direction+": "+this.offset+";"; + } + + } diff --git a/Classes/css/user/ContextBuilder.java b/Classes/css/user/ContextBuilder.java index b248a7a..059b9a7 100644 --- a/Classes/css/user/ContextBuilder.java +++ b/Classes/css/user/ContextBuilder.java @@ -13,10 +13,12 @@ public class ContextBuilder{ /* (2) Base layout dimension */ Context.bind("header-height", 50); Context.bind("menu-width", 237); + Context.bind("submenu-width", 200); /* (3) Colors */ Context.bind("main-color", 63, 81, 181); Context.bind("menu-bg", 255, 255, 253); + Context.bind("submenu-bg", 255, 0, 0); } diff --git a/Classes/css/user/HeaderIconStyleSheet.java b/Classes/css/user/HeaderIconStyleSheet.java new file mode 100644 index 0000000..7721683 --- /dev/null +++ b/Classes/css/user/HeaderIconStyleSheet.java @@ -0,0 +1,34 @@ +package Classes.css.user; + +import Classes.css.core.Context; +import Classes.css.core.Ruleset; +import javafx.scene.Node; + +public class HeaderIconStyleSheet{ + + /* Builds all necessary CSS/layout rules */ + public HeaderIconStyleSheet(Node target) throws Exception{ + + /* (1) Darken main-color */ + Context.bind("tmp", Context.getColor("main-color").darker() ); + + /* (2) Set rules */ + Ruleset.load(target) + .add("top", 0) + .add("left", 0) + + .add("min-width", Context.getInt("menu-width")) + .add("max-width", Context.getInt("menu-width")) + + .add("min-height", Context.getInt("header-height")) + .add("max-height", Context.getInt("header-height")) + + .add("pref-height", Context.getInt("header-height")) + .add("pref-width", Context.getInt("menu-width")) + + .add("background-color", Context.getString("tmp")) + .apply(); + + } + +} diff --git a/Classes/css/user/Header.java b/Classes/css/user/HeaderStyleSheet.java similarity index 88% rename from Classes/css/user/Header.java rename to Classes/css/user/HeaderStyleSheet.java index b582f25..58d374e 100644 --- a/Classes/css/user/Header.java +++ b/Classes/css/user/HeaderStyleSheet.java @@ -4,10 +4,10 @@ import Classes.css.core.Context; import Classes.css.core.Ruleset; import javafx.scene.Node; -public class Header{ +public class HeaderStyleSheet{ /* Builds all necessary CSS/layout rules */ - public Header(Node target) throws Exception{ + public HeaderStyleSheet(Node target) throws Exception{ /* (1) Set rules */ Ruleset.load(target) @@ -16,13 +16,14 @@ public class Header{ // .add("right", 0) .add("min-height", Context.getInt("header-height")) - .add("pref-height", Context.getInt("header-height")) .add("max-height", Context.getInt("header-height")) .add("min-width", Context.getInt("screen-width")) - .add("pref-width", Context.getInt("screen-width")) .add("max-width", Context.getInt("screen-width")) + .add("pref-height", Context.getInt("header-height")) + .add("pref-width", Context.getInt("screen-width")) + .add("background-color", Context.getString("main-color")) .apply(); diff --git a/Classes/css/user/MenuContainer.java b/Classes/css/user/MenuStyleSheet.java similarity index 74% rename from Classes/css/user/MenuContainer.java rename to Classes/css/user/MenuStyleSheet.java index 7b3b010..951f16e 100644 --- a/Classes/css/user/MenuContainer.java +++ b/Classes/css/user/MenuStyleSheet.java @@ -4,24 +4,28 @@ import Classes.css.core.Context; import Classes.css.core.Ruleset; import javafx.scene.Node; -public class MenuContainer{ +public class MenuStyleSheet{ /* Builds all necessary CSS/layout rules */ - public MenuContainer(Node target) throws Exception{ + public MenuStyleSheet(Node target) throws Exception{ /* (1) Set rules */ Ruleset.load(target) .add("top", Context.getInt("header-height")) .add("left", 0) - + .add("min-width", Context.getInt("menu-width")) .add("max-width", Context.getInt("menu-width")) - + .add("min-height", Context.getInt("screen-height") - Context.getInt("header-height")) .add("max-height", Context.getInt("screen-height") - Context.getInt("header-height")) + .add("pref-width", Context.getInt("menu-width")) + .add("pref-height", Context.getInt("screen-height") - Context.getInt("header-height")) + .add("background-color", Context.getString("menu-bg")) .apply(); + } } diff --git a/Classes/css/user/SubMenuStyleSheet.java b/Classes/css/user/SubMenuStyleSheet.java new file mode 100644 index 0000000..c0f27f7 --- /dev/null +++ b/Classes/css/user/SubMenuStyleSheet.java @@ -0,0 +1,31 @@ +package Classes.css.user; + +import Classes.css.core.Context; +import Classes.css.core.Ruleset; +import javafx.scene.Node; + +public class SubMenuStyleSheet{ + + /* Builds all necessary CSS/layout rules */ + public SubMenuStyleSheet(Node target) throws Exception{ + + /* (1) Set rules */ + Ruleset.load(target) + .add("top", Context.getInt("header-height")) + .add("left", Context.getInt("menu-width")) + .add("bottom", 0) + + .add("min-width", Context.getInt("submenu-width")) + .add("max-width", Context.getInt("submenu-width")) + + .add("min-height", Context.getInt("screen-height") - Context.getInt("header-height")) + .add("max-height", Context.getInt("screen-height") - Context.getInt("header-height")) + + .add("pref-width", Context.getInt("submenu-width")) + .add("pref-height", Context.getInt("screen-height") - Context.getInt("header-height")) + + .add("background-color", Context.getString("submenu-bg")) + .apply(); + } + +} diff --git a/controller/RootLayout.java b/controller/RootLayout.java index f508bb1..fa726f6 100644 --- a/controller/RootLayout.java +++ b/controller/RootLayout.java @@ -7,8 +7,10 @@ import org.json.JSONObject; import Classes.ApiCall; import Classes.css.user.ContextBuilder; -import Classes.css.user.Header; -import Classes.css.user.MenuContainer; +import Classes.css.user.HeaderStyleSheet; +import Classes.css.user.HeaderIconStyleSheet; +import Classes.css.user.MenuStyleSheet; +import Classes.css.user.SubMenuStyleSheet; import Interfaces.Callback; import Interfaces.Event; import Interfaces.EventObserver; @@ -57,10 +59,16 @@ public class RootLayout extends Application implements EventObserver { -------------------------------------*/ /* (1) #header */ - new Header( this.root_scene.lookup("#header") ); + new HeaderStyleSheet( this.root_scene.lookup("#header") ); /* (2) #menu_container */ - new MenuContainer( this.root_scene.lookup("#menu_container") ); + new MenuStyleSheet( this.root_scene.lookup("#menu") ); + + /* (3) #submenu */ + new SubMenuStyleSheet( this.root_scene.lookup("#submenu") ); + + /* (4) #header_icon*/ + new HeaderIconStyleSheet( this.root_scene.lookup("#header_icon") ); } diff --git a/css/menu.css b/css/menu.css index cf280f8..292ba4f 100644 --- a/css/menu.css +++ b/css/menu.css @@ -3,7 +3,8 @@ #header_icon{ - -fx-min-width: -v-header-height; + -fx-min-width: 660; + -fx-pref-width: 660; -fx-max-width: 660; -fx-min-height: -v-header-height; diff --git a/fxml/model.fxml b/fxml/model.fxml index f684e7c..b7e8479 100644 --- a/fxml/model.fxml +++ b/fxml/model.fxml @@ -17,10 +17,10 @@ - + - + @@ -51,5 +51,7 @@ + +