package Classes.css.core.rule; import java.util.ArrayList; import Classes.css.core.Rule; import javafx.geometry.Insets; import javafx.scene.Node; import javafx.scene.layout.Region; public class Padding extends Rule{ /* Attributes */ private Integer top; private Integer right; private Integer bottom; private Integer left; /* Constructor -> Dispatch attributes */ public Padding(Object[] r_side) throws Exception{ /* (1) Initialization ------------------------------------------*/ /* (1) Initialize values */ this.top = null; this.left = null; this.bottom = null; this.right = null; /* (2) Cast Object[] to ArrayList */ ArrayList_r_side = this.auto_cast(r_side); /* (2) Manage/store values ------------------------------------------*/ switch(r_side.length){ /* (1) If 4 -> (top, right, bottom, left) */ case 4: this.top = _r_side.get(0); this.right = _r_side.get(1); this.bottom = _r_side.get(2); this.left = _r_side.get(3); break; /* (2) If 3 -> (top, right+left, bottom) */ case 3: this.top = _r_side.get(0); this.right = _r_side.get(1); this.left = _r_side.get(1); this.bottom = _r_side.get(2); break; /* (3) If 2 -> (top+botton, right+left) */ case 2: this.top = _r_side.get(0); this.bottom = _r_side.get(0); this.right = _r_side.get(1); this.left = _r_side.get(1); break; /* (4) If 1 -> (top+botton+right+left) */ case 1: this.top = _r_side.get(0); this.bottom = _r_side.get(0); this.right = _r_side.get(0); this.left = _r_side.get(0); break; } } public void apply(Node target){ /* (1) Set padding inset */ Insets pad_inset = new Insets(this.top, this.right, this.bottom, this.left); /* (2) Apply to target */ Region _target = (Region) target; _target.setPadding(pad_inset); } /* Cast from Object[] to Integer[] */ private ArrayList auto_cast(Object[] cast_in) throws Exception{ /* (1) Init. output */ ArrayList cast_out = new ArrayList(); /* (2) Parse input to try to parse values */ for( Object obj_in : cast_in ) cast_out.add( Integer.valueOf(obj_in.toString()) ); /* (3) Return casted array */ return cast_out; } @Override public String toString() { return "padding: "+this.top+" "+this.right+" "+this.bottom+" "+this.left+";"; } }