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;
|
2017-11-15 17:12:46 +00:00
|
|
|
import javafx.scene.layout.AnchorPane;
|
2017-11-14 15:53:47 +00:00
|
|
|
|
|
|
|
public class Ruleset {
|
|
|
|
|
2017-11-15 17:12:46 +00:00
|
|
|
private final static boolean DEBUG = false;
|
|
|
|
|
2017-11-14 15:53:47 +00:00
|
|
|
/* 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 */
|
2017-11-15 17:12:46 +00:00
|
|
|
for( ; i < il ; i++ ){
|
|
|
|
|
|
|
|
if( Ruleset.DEBUG )
|
|
|
|
System.out.println("[SET] "+this.target.getId()+"."+this.rule.get(i));
|
|
|
|
|
2017-11-14 15:53:47 +00:00
|
|
|
this.rule.get(i).apply(this.target);
|
|
|
|
|
2017-11-15 17:12:46 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-11-14 15:53:47 +00:00
|
|
|
/* (3) Stop the Chain design pattern */
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|