diff --git a/Classes/css/core/Context.java b/Classes/css/core/Context.java index 3c7ee4e..3a8768e 100644 --- a/Classes/css/core/Context.java +++ b/Classes/css/core/Context.java @@ -2,19 +2,72 @@ 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, 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/user/ContextBuilder.java b/Classes/css/user/ContextBuilder.java index 992a275..b248a7a 100644 --- a/Classes/css/user/ContextBuilder.java +++ b/Classes/css/user/ContextBuilder.java @@ -14,6 +14,10 @@ public class ContextBuilder{ Context.bind("header-height", 50); Context.bind("menu-width", 237); + /* (3) Colors */ + Context.bind("main-color", 63, 81, 181); + Context.bind("menu-bg", 255, 255, 253); + } } diff --git a/Classes/css/user/Header.java b/Classes/css/user/Header.java index 4e21bdb..b582f25 100644 --- a/Classes/css/user/Header.java +++ b/Classes/css/user/Header.java @@ -15,18 +15,15 @@ public class Header{ // .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-height", Context.getInt("header-height")) + .add("pref-height", Context.getInt("header-height")) + .add("max-height", Context.getInt("header-height")) - .add("min-width", Context.get("screen-width")) - .add("pref-width", Context.get("screen-width")) - .add("max-width", Context.get("screen-width")) + .add("min-width", Context.getInt("screen-width")) + .add("pref-width", Context.getInt("screen-width")) + .add("max-width", Context.getInt("screen-width")) - .add("background-color", "#3f51b5") - -// .add("border-width", "0 0 1 0") -// .add("border-color", "#3240a3") + .add("background-color", Context.getString("main-color")) .apply(); } diff --git a/Classes/css/user/MenuContainer.java b/Classes/css/user/MenuContainer.java index 894b268..7b3b010 100644 --- a/Classes/css/user/MenuContainer.java +++ b/Classes/css/user/MenuContainer.java @@ -9,23 +9,18 @@ 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 */ + /* (1) Set rules */ Ruleset.load(target) - .add("top", Context.get("header-height")) + .add("top", Context.getInt("header-height")) .add("left", 0) - .add("min-width", Context.get("menu-width")) - .add("max-width", Context.get("menu-width")) + .add("min-width", Context.getInt("menu-width")) + .add("max-width", Context.getInt("menu-width")) - .add("min-height", menu_height) - .add("max-height", menu_height) + .add("min-height", Context.getInt("screen-height") - Context.getInt("header-height")) + .add("max-height", Context.getInt("screen-height") - Context.getInt("header-height")) - .add("background-color", "#fffffd") + .add("background-color", Context.getString("menu-bg")) .apply(); } 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..cf280f8 100644 --- a/css/menu.css +++ b/css/menu.css @@ -17,7 +17,7 @@ } -/* + #menu_container{ -fx-min-width: 237; @@ -28,4 +28,4 @@ -fx-background-color: #fffffd; -}*/ \ No newline at end of file +} \ No newline at end of file