JavaFX/Classes/css/core/Ruleset.java

105 lines
2.0 KiB
Java
Raw Normal View History

2017-11-14 15:53:47 +00:00
package Classes.css.core;
import java.util.ArrayList;
import Classes.css.core.rule.JavaFX;
import Classes.css.core.rule.Padding;
import Classes.css.core.rule.Position;
import javafx.scene.Node;
public class Ruleset {
/* Attributes */
private Node target;
private ArrayList<Rule> rule;
/* Builder -> static instance builder */
public static Ruleset load(Node target) {
/* (1) Create instance */
Ruleset instance = new Ruleset(target);
/* (2) Chain design pattern */
return instance;
}
/* Constructor */
private Ruleset(Node target) {
/* (1) Store target */
this.target = target;
/* (2) Init. rule list */
this.rule = new ArrayList<Rule>();
}
/* Add a rule */
public Ruleset add(String l_side, Object... r_side) throws Exception{
/* (1) Init.
------------------------------------ */
/* (1) If no argument -> abort */
if( r_side.length == 0 )
throw new Exception("No @r_side given");
/* (2) Init. rule container */
Rule new_rule = null;
/* (1) Manage Rule Type (auto Builder)
------------------------------------ */
/* (1) Padding*/
if( l_side == "padding" )
new_rule = (Rule) new Padding(r_side);
/* (2) Position */
else if( l_side == "top" || l_side == "left" || l_side == "right" || l_side == "bottom" )
new_rule = (Rule) new Position(l_side, (int) r_side[0]);
/* (x) If nothing custom -> suppose java fx rule */
else
2017-11-15 13:23:13 +00:00
new_rule = (Rule) new JavaFX(l_side, r_side[0].toString());
2017-11-14 15:53:47 +00:00
/* (2) Add the rule to the ruleset
------------------------------------ */
/* (1) Add the rule to the ruleset (only if not null) */
if( new_rule != null )
this.rule.add( new_rule );
/* (2) Chain design pattern */
return this;
}
/* Apply all rules */
public void apply() throws Exception{
/* (1) Init. meter */
int i = 0;
int il = this.rule.size();
/* (2) Apply each rule */
for( ; i < il ; i++ )
this.rule.get(i).apply(this.target);
/* (3) Stop the Chain design pattern */
return;
}
}