package Classes.css.core.rule; import Classes.css.core.Rule; import javafx.scene.Node; import javafx.scene.layout.AnchorPane; public class Position extends Rule{ /* Attributes */ private String direction; private Integer offset; /* Constructor -> Dispatch attributes */ public Position(String l_side, int r_side){ this.direction = l_side; this.offset = r_side; } public void apply(Node target) throws Exception{ /* (1) Initialization ------------------------------------ */ /* (1) If not anchor pane -> abort */ if( !(target.getParent() instanceof AnchorPane) ) throw new Exception("Target's parent is not an 'AnchorPane'"); /* (2) Cast for readability */ double _offset = this.offset; /* (2) Manage directions ------------------------------------ */ /* (1) Direction: TOP */ if( this.direction == "top" ) AnchorPane.setTopAnchor(target, _offset); /* (2) Direction: LEFT */ else if( this.direction == "left" ) AnchorPane.setLeftAnchor(target, _offset); /* (3) Direction: RIGHT */ else if( this.direction == "right" ) AnchorPane.setRightAnchor(target, _offset); /* (4) Direction: BOTTOM */ else if( this.direction == "bottom" ) AnchorPane.setBottomAnchor(target, _offset); } @Override public String toString() { return this.direction+": "+this.offset+";"; } }