123 lines
2.6 KiB
Java
123 lines
2.6 KiB
Java
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;
|
|
import javafx.scene.layout.AnchorPane;
|
|
|
|
public class Ruleset {
|
|
|
|
private final static boolean DEBUG = false;
|
|
|
|
/* 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
|
|
new_rule = (Rule) new JavaFX(l_side, r_side[0].toString());
|
|
|
|
|
|
|
|
/* (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++ ){
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|