11/*
2- * Copyright (C) 2025 Parisi Alessandro - alessandro.parisi406@gmail.com
2+ * Copyright (C) 2026 Parisi Alessandro - alessandro.parisi406@gmail.com
33 * This file is part of MaterialFX (https://github.com/palexdev/MaterialFX)
44 *
55 * MaterialFX is free software: you can redistribute it and/or
1616 * along with MaterialFX. If not, see <http://www.gnu.org/licenses/>.
1717 */
1818
19- package io .github .palexdev .mfxcore .builders ;
19+ package io .github .palexdev .mfxcore .utils . fx ;
2020
2121import javafx .geometry .Insets ;
2222import javafx .scene .layout .CornerRadii ;
2323
24- /// Convenience class to build [Insets] objects.
25- public class InsetsBuilder {
26- //================================================================================
27- // Properties
28- //================================================================================
29- private Insets insets ;
24+ /// Utility class for [Insets], also hosts the [InsetsBuilder] inner class.
25+ public class InsetsUtils {
3026
3127 //================================================================================
3228 // Constructors
3329 //================================================================================
34- public InsetsBuilder () {
35- this (Insets .EMPTY );
36- }
3730
38- public InsetsBuilder (Insets insets ) {
39- this .insets = insets ;
40- }
31+ private InsetsUtils () {}
4132
4233 //================================================================================
4334 // Static Methods
4435 //================================================================================
45- public static InsetsBuilder build () {
46- return new InsetsBuilder ();
47- }
4836
49- public static Insets of ( double top , double right , double bottom , double left ) {
50- return new Insets ( top , right , bottom , left );
37+ public static InsetsUtils insets ( ) {
38+ return new InsetsUtils ( );
5139 }
5240
5341 public static InsetsBuilder uniform (double all ) {
@@ -77,67 +65,73 @@ public static boolean isUniform(Insets insets) {
7765 }
7866
7967 public static String stringify (Insets insets ) {
80- if (isUniform (insets )) {
81- return String .valueOf (insets .getTop ());
82- }
68+ if (isUniform (insets )) return String .valueOf (insets .getTop ());
8369 return insets .getTop () + " " +
8470 insets .getRight () + " " +
8571 insets .getBottom () + " " +
8672 insets .getLeft ();
8773 }
8874
8975 //================================================================================
90- // Methods
76+ // Inner Classes
9177 //================================================================================
92- public InsetsBuilder withTop (double top ) {
93- insets = new Insets (top , insets .getRight (), insets .getBottom (), insets .getLeft ());
94- return this ;
95- }
9678
97- public InsetsBuilder withRight (double right ) {
98- insets = new Insets (insets .getTop (), right , insets .getBottom (), insets .getLeft ());
99- return this ;
100- }
79+ public static class InsetsBuilder {
10180
102- public InsetsBuilder withVertical (double topBottom ) {
103- insets = new Insets (topBottom , insets .getRight (), topBottom , insets .getLeft ());
104- return this ;
105- }
81+ private Insets insets ;
10682
107- public InsetsBuilder withBottom ( double bottom ) {
108- return new InsetsBuilder ( new Insets ( insets . getTop (), insets . getRight (), bottom , insets . getLeft ()) );
109- }
83+ public InsetsBuilder ( ) {
84+ this ( Insets . EMPTY );
85+ }
11086
111- public InsetsBuilder withLeft (double left ) {
112- insets = new Insets (insets .getTop (), insets .getRight (), insets .getBottom (), left );
113- return this ;
114- }
87+ public InsetsBuilder (Insets insets ) {
88+ this .insets = insets ;
89+ }
11590
116- public InsetsBuilder withHorizontal (double leftRight ) {
117- insets = new Insets (insets .getTop (), leftRight , insets .getBottom (), leftRight );
118- return this ;
119- }
91+ public InsetsBuilder top (double top ) {
92+ insets = new Insets (top , insets .getRight (), insets .getBottom (), insets . getLeft () );
93+ return this ;
94+ }
12095
121- public Insets get () {
122- return insets ;
123- }
96+ public InsetsBuilder right (double right ) {
97+ insets = new Insets (insets .getTop (), right , insets .getBottom (), insets .getLeft ());
98+ return this ;
99+ }
124100
125- public CornerRadii toRadius (boolean asPercent ) {
126- return new CornerRadii (insets .getTop (), insets .getRight (), insets .getBottom (), insets .getLeft (), asPercent );
127- }
101+ public InsetsBuilder bottom (double bottom ) {
102+ insets = new Insets (insets .getTop (), insets .getRight (), bottom , insets .getLeft ());
103+ return this ;
104+ }
128105
129- public boolean isUniform () {
130- return isUniform (insets );
131- }
106+ public InsetsBuilder left (double left ) {
107+ insets = new Insets (insets .getTop (), insets .getRight (), insets .getBottom (), left );
108+ return this ;
109+ }
132110
133- public String stringify () {
134- if (isUniform (insets )) {
135- return String .valueOf (insets .getTop ());
111+ public InsetsBuilder vertical (double topBottom ) {
112+ insets = new Insets (topBottom , insets .getRight (), topBottom , insets .getLeft ());
113+ return this ;
114+ }
115+
116+ public InsetsBuilder horizontal (double leftRight ) {
117+ insets = new Insets (insets .getTop (), leftRight , insets .getBottom (), leftRight );
118+ return this ;
119+ }
120+
121+ public Insets get () {
122+ return insets ;
123+ }
124+
125+ public CornerRadii toRadius (boolean asPercent ) {
126+ return new CornerRadii (insets .getTop (), insets .getRight (), insets .getBottom (), insets .getLeft (), asPercent );
136127 }
137- return insets .getTop () + " " +
138- insets .getRight () + " " +
139- insets .getBottom () + " " +
140- insets .getLeft ();
141- }
142- }
143128
129+ public boolean isUniform () {
130+ return InsetsUtils .isUniform (insets );
131+ }
132+
133+ public String stringify () {
134+ return InsetsUtils .stringify (insets );
135+ }
136+ }
137+ }
0 commit comments