JavaFX/Classes/css/core/rule/Padding.java

116 lines
2.4 KiB
Java
Raw Normal View History

2017-11-14 15:53:47 +00:00
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{
2017-11-14 15:53:47 +00:00
/* 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<Integer> */
ArrayList<Integer>_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<Integer> auto_cast(Object[] cast_in) throws Exception{
/* (1) Init. output */
ArrayList<Integer> cast_out = new ArrayList<Integer>();
/* (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+";";
}
2017-11-14 15:53:47 +00:00
}