diff --git a/Classes/css/core/Context.java b/Classes/css/core/Context.java index 3c7ee4e..3227dc2 100644 --- a/Classes/css/core/Context.java +++ b/Classes/css/core/Context.java @@ -2,19 +2,77 @@ package Classes.css.core; import java.util.HashMap; +import javafx.scene.paint.Color; + public class Context{ + + public final static int TYPE_INT = 1; + public final static int TYPE_STR = 2; + public final static int TYPE_COL = 3; /* Context data (associative array) */ - private static HashMap attr = new HashMap(); + private static HashMap attr = new HashMap(); + private static HashMap type = new HashMap(); /* Add data */ - public static void bind(String index, Object data){ + public static void bind(String index, Integer data){ /* INT */ Context.attr.put(index, data); + Context.type.put(index, Context.TYPE_INT); } - /* Fetch data */ - public static Object get(String index){ - return Context.attr.get(index); + public static void bind(String index, String data){ /* String */ + Context.attr.put(index, data); + 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); + } + + /* Fetch data -> String */ + public static String getString(String index){ + + /* (1) If color: return HEX */ + if( Context.type.get(index) == Context.TYPE_COL ) + + return String.format("#%02X%02X%02X", + (int)( ((Color) Context.attr.get(index)).getRed() * 255 ), + (int)( ((Color) Context.attr.get(index)).getGreen() * 255 ), + (int)( ((Color) Context.attr.get(index)).getBlue() * 255 ) + ); + + /* (2) By default -> String auto cast*/ + return Context.attr.get(index).toString(); + } + + /* Fetch data -> Int */ + public static Integer getInt(String index) throws Exception{ + + /* (1) If not INT -> abort */ + if( Context.type.get(index) != Context.TYPE_INT ) + throw new Exception("Not an int value"); + + + /* (2) By default -> int */ + return (Integer) Context.attr.get(index); + } + + /* Fetch data -> Color */ + public static Color getColor(String index) throws Exception{ + + /* (1) If not COLOR -> abort */ + if( Context.type.get(index) != Context.TYPE_COL ) + throw new Exception("Not a color value"); + + /* (2) By default -> COLOR */ + return (Color) Context.attr.get(index); + + } + } 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 992a275..059b9a7 100644 --- a/Classes/css/user/ContextBuilder.java +++ b/Classes/css/user/ContextBuilder.java @@ -13,6 +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/Header.java b/Classes/css/user/Header.java deleted file mode 100644 index 4e21bdb..0000000 --- a/Classes/css/user/Header.java +++ /dev/null @@ -1,34 +0,0 @@ -package Classes.css.user; - -import Classes.css.core.Context; -import Classes.css.core.Ruleset; -import javafx.scene.Node; - -public class Header{ - - /* Builds all necessary CSS/layout rules */ - public Header(Node target) throws Exception{ - - /* (1) Set rules */ - Ruleset.load(target) -// .add("top", 0) -// .add("left", 0) -// .add("right", 0) - - .add("min-height", Context.get("header-height")) - .add("pref-height", Context.get("header-height")) - .add("max-height", Context.get("header-height")) - - .add("min-width", Context.get("screen-width")) - .add("pref-width", Context.get("screen-width")) - .add("max-width", Context.get("screen-width")) - - .add("background-color", "#3f51b5") - -// .add("border-width", "0 0 1 0") -// .add("border-color", "#3240a3") - - .apply(); - } - -} 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/HeaderStyleSheet.java b/Classes/css/user/HeaderStyleSheet.java new file mode 100644 index 0000000..58d374e --- /dev/null +++ b/Classes/css/user/HeaderStyleSheet.java @@ -0,0 +1,32 @@ +package Classes.css.user; + +import Classes.css.core.Context; +import Classes.css.core.Ruleset; +import javafx.scene.Node; + +public class HeaderStyleSheet{ + + /* Builds all necessary CSS/layout rules */ + public HeaderStyleSheet(Node target) throws Exception{ + + /* (1) Set rules */ + Ruleset.load(target) +// .add("top", 0) +// .add("left", 0) +// .add("right", 0) + + .add("min-height", Context.getInt("header-height")) + .add("max-height", Context.getInt("header-height")) + + .add("min-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/MenuContainer.java deleted file mode 100644 index 894b268..0000000 --- a/Classes/css/user/MenuContainer.java +++ /dev/null @@ -1,32 +0,0 @@ -package Classes.css.user; - -import Classes.css.core.Context; -import Classes.css.core.Ruleset; -import javafx.scene.Node; - -public class MenuContainer{ - - /* Builds all necessary CSS/layout rules */ - public MenuContainer(Node target) throws Exception{ - - - /* (1) Calculate menu height (screen.height - header.height) */ - Integer menu_height = Integer.valueOf( Context.get("screen-height").toString() ); - menu_height -= Integer.valueOf( Context.get("header-height").toString() ); - - /* (2) Set rules */ - Ruleset.load(target) - .add("top", Context.get("header-height")) - .add("left", 0) - - .add("min-width", Context.get("menu-width")) - .add("max-width", Context.get("menu-width")) - - .add("min-height", menu_height) - .add("max-height", menu_height) - - .add("background-color", "#fffffd") - .apply(); - } - -} diff --git a/Classes/css/user/MenuStyleSheet.java b/Classes/css/user/MenuStyleSheet.java new file mode 100644 index 0000000..951f16e --- /dev/null +++ b/Classes/css/user/MenuStyleSheet.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 MenuStyleSheet{ + + /* Builds all necessary CSS/layout rules */ + 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 95cfe0b..b2d6ece 100644 --- a/controller/RootLayout.java +++ b/controller/RootLayout.java @@ -10,8 +10,10 @@ import Classes.Category; import Classes.Languages; import Classes.SortTypes; 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; @@ -63,10 +65,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/header.css b/css/header.css index b9aa92f..b4565fd 100644 --- a/css/header.css +++ b/css/header.css @@ -1,9 +1,8 @@ @import "./constants.css"; -/* + #header{ - -fx-border-width: 0 0 1 0; - -fx-border-color: #3240a3; -} */ + -fx-background-color: #3f51b5; +} #header_menu{ diff --git a/css/menu.css b/css/menu.css index e8cd14b..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; @@ -17,7 +18,7 @@ } -/* + #menu_container{ -fx-min-width: 237; @@ -28,4 +29,4 @@ -fx-background-color: #fffffd; -}*/ \ No newline at end of file +} \ No newline at end of file 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 @@ + +