@@ -38,8 +38,10 @@ public class BorderPainter {
3838 public static final int BOTTOM = 4 ;
3939 public static final int RIGHT = 8 ;
4040 public static final int ALL = TOP | LEFT | BOTTOM | RIGHT ;
41+
4142 /**
4243 * Generates a full round rectangle that is made of bounds and border
44+ *
4345 * @param bounds Dimensions of the rect
4446 * @param border The border specs
4547 * @param inside Set true if you want the inner bounds of borders
@@ -56,6 +58,7 @@ public static Shape generateBorderBounds(Rectangle bounds, BorderPropertySet bor
5658
5759 /**
5860 * Generates one side of a border
61+ *
5962 * @param bounds bounds of the container
6063 * @param side what side you want
6164 * @param border border props
@@ -65,8 +68,10 @@ public static Shape generateBorderBounds(Rectangle bounds, BorderPropertySet bor
6568 public static Path2D generateBorderShape (Rectangle bounds , int side , BorderPropertySet border , boolean drawInterior ) {
6669 return generateBorderShape (bounds , side , border , drawInterior , 0 , 1 , true );
6770 }
71+
6872 /**
6973 * Generates one side of a border
74+ *
7075 * @param bounds bounds of the container
7176 * @param side what side you want
7277 * @param border border props
@@ -80,6 +85,7 @@ public static Path2D generateBorderShape(Rectangle bounds, int side, BorderPrope
8085
8186 /**
8287 * Generates one side of a border
88+ *
8389 * @param bounds bounds of the container
8490 * @param side what side you want
8591 * @param border border props
@@ -115,39 +121,39 @@ public static Path2D generateBorderShape(Rectangle bounds, int side, BorderPrope
115121 if (widthSum != 0.0f ) { // Avoid NaN
116122 angle = fullAngle * props .getTop () / widthSum ;
117123 }
118- appendPath (path , 0 - props .getLeft (), 0 - props .getTop (), props .getLeftCorner ().left (), props .getLeftCorner ().right (), 90 + angle + overlapAngle , -angle - overlapAngle , props .getTop (), props .getLeft (), scaledOffset , true );
124+ appendPath (path , 0 - props .getLeft (), 0 - props .getTop (), props .getLeftCorner ().left (), props .getLeftCorner ().right (), 90 + angle + overlapAngle , -angle - overlapAngle , props .getTop (), props .getLeft (), scaledOffset , true );
119125
120126 angle = defaultAngle ;
121127 widthSum = props .getTop () + props .getRight ();
122128 if (widthSum != 0.0f ) { // Avoid NaN
123129 angle = fullAngle * props .getTop () / widthSum ;
124130 }
125- appendPath (path , sideWidth + props .getRight (), 0 - props .getTop (), props .getRightCorner ().right (), props .getRightCorner ().left (), 90 , -angle - overlapAngle , props .getTop (), props .getRight (), scaledOffset , false );
131+ appendPath (path , sideWidth + props .getRight (), 0 - props .getTop (), props .getRightCorner ().right (), props .getRightCorner ().left (), 90 , -angle - overlapAngle , props .getTop (), props .getRight (), scaledOffset , false );
126132
127- if (drawInterior ) {
133+ if (drawInterior ) {
128134 //border = border.normalizeBorderRadius(new Rectangle((int)(bounds.width), (int)(bounds.height)));
129135 //props = new RelativeBorderProperties(bounds, border, 0f, side, 1+scaledOffset, 1);
130136
131- appendPath (path , sideWidth , 0 , props .getRightCorner ().right (), props .getRightCorner ().left (), 90 - angle - overlapAngle , angle + overlapAngle , props .getTop (), props .getRight (), scaledOffset + 1 , false );
137+ appendPath (path , sideWidth , 0 , props .getRightCorner ().right (), props .getRightCorner ().left (), 90 - angle - overlapAngle , angle + overlapAngle , props .getTop (), props .getRight (), scaledOffset + 1 , false );
132138
133139 angle = defaultAngle ;
134140 widthSum = props .getTop () + props .getLeft ();
135141 if (widthSum != 0.0f ) { // Avoid NaN
136142 angle = fullAngle * props .getTop () / widthSum ;
137143 }
138- appendPath (path , 0 , 0 , props .getLeftCorner ().left (), props .getLeftCorner ().right (), 90 , angle + overlapAngle , props .getTop (), props .getLeft (), scaledOffset + 1 , true );
144+ appendPath (path , 0 , 0 , props .getLeftCorner ().left (), props .getLeftCorner ().right (), 90 , angle + overlapAngle , props .getTop (), props .getLeft (), scaledOffset + 1 , true );
139145 path .closePath ();
140146 }
141147
142148
143149 path .transform (AffineTransform .getTranslateInstance (
144- (!props .isDimensionsSwapped () ? -bounds .width / 2f : -bounds .height / 2f ) + (scaledOffset + 1 )* props .getLeft (),
145- (props .isDimensionsSwapped () ? -bounds .width / 2f : -bounds .height / 2f ) + (scaledOffset + 1 )* props .getTop ()));
150+ (!props .isDimensionsSwapped () ? -bounds .width / 2f : -bounds .height / 2f ) + (scaledOffset + 1 ) * props .getLeft (),
151+ (props .isDimensionsSwapped () ? -bounds .width / 2f : -bounds .height / 2f ) + (scaledOffset + 1 ) * props .getTop ()));
146152 path .transform (AffineTransform .getRotateInstance (
147153 props .getRotation ()));
148154 // empirical: add 0.5 to better play with rasterization rules
149155 path .transform (AffineTransform .getTranslateInstance (
150- bounds .width / 2f + bounds .x , bounds .height / 2f + bounds .y ));
156+ bounds .width / 2f + bounds .x , bounds .height / 2f + bounds .y ));
151157
152158 return path ;
153159 }
@@ -187,36 +193,36 @@ private static class RelativeBorderProperties {
187193 public RelativeBorderProperties (BorderPropertySet props , int side , float widthScale ) {
188194
189195 if ((side & BorderPainter .TOP ) == BorderPainter .TOP ) {
190- _top = props .top ()* widthScale ;
191- _left = props .left ()* widthScale ;
192- _right = props .right ()* widthScale ;
196+ _top = props .top () * widthScale ;
197+ _left = props .left () * widthScale ;
198+ _right = props .right () * widthScale ;
193199 _leftCorner = props .getTopLeft ();
194200 _rightCorner = props .getTopRight ();
195201 _rotation = 0 ;
196202 _dimensionsSwapped = false ;
197203 } else if ((side & BorderPainter .RIGHT ) == BorderPainter .RIGHT ) {
198- _top = props .right ()* widthScale ;
199- _left = props .top ()* widthScale ;
200- _right = props .bottom ()* widthScale ;
204+ _top = props .right () * widthScale ;
205+ _left = props .top () * widthScale ;
206+ _right = props .bottom () * widthScale ;
201207 _leftCorner = props .getTopRight ();
202208 _rightCorner = props .getBottomRight ();
203- _rotation = Math .PI / 2 ;
209+ _rotation = Math .PI / 2 ;
204210 _dimensionsSwapped = true ;
205211 } else if ((side & BorderPainter .BOTTOM ) == BorderPainter .BOTTOM ) {
206- _top = props .bottom ()* widthScale ;
207- _left = props .right ()* widthScale ;
208- _right = props .left ()* widthScale ;
212+ _top = props .bottom () * widthScale ;
213+ _left = props .right () * widthScale ;
214+ _right = props .left () * widthScale ;
209215 _leftCorner = props .getBottomRight ();
210216 _rightCorner = props .getBottomLeft ();
211217 _rotation = Math .PI ;
212218 _dimensionsSwapped = false ;
213219 } else if ((side & BorderPainter .LEFT ) == BorderPainter .LEFT ) {
214- _top = props .left ()* widthScale ;
215- _left = props .bottom ()* widthScale ;
216- _right = props .top ()* widthScale ;
220+ _top = props .left () * widthScale ;
221+ _left = props .bottom () * widthScale ;
222+ _right = props .top () * widthScale ;
217223 _leftCorner = props .getBottomLeft ();
218224 _rightCorner = props .getTopLeft ();
219- _rotation = 3 * Math .PI / 2 ;
225+ _rotation = 3 * Math .PI / 2 ;
220226 _dimensionsSwapped = true ;
221227 } else {
222228 throw new IllegalArgumentException ("No side found" );
@@ -226,15 +232,19 @@ public RelativeBorderProperties(BorderPropertySet props, int side, float widthSc
226232 public BorderRadiusCorner getRightCorner () {
227233 return _rightCorner ;
228234 }
235+
229236 public BorderRadiusCorner getLeftCorner () {
230237 return _leftCorner ;
231238 }
239+
232240 public float getTop () {
233241 return _top ;
234242 }
243+
235244 public float getLeft () {
236245 return _left ;
237246 }
247+
238248 public float getRight () {
239249 return _right ;
240250 }
@@ -319,19 +329,19 @@ private static void paintBorderSide(OutputDevice outputDevice, final BorderPrope
319329 0 , 1 , currentSide );
320330 } else if (borderSideStyle == IdentValue .SOLID ) {
321331 outputDevice .setStroke (new BasicStroke (1f ));
322- if (currentSide == TOP ) {
332+ if (currentSide == TOP ) {
323333 outputDevice .setColor (border .topColor ());
324334 outputDevice .fill (generateBorderShape (bounds , TOP , border , true , 0 , 1 , true ));
325335 }
326- if (currentSide == RIGHT ) {
336+ if (currentSide == RIGHT ) {
327337 outputDevice .setColor (border .rightColor ());
328338 outputDevice .fill (generateBorderShape (bounds , RIGHT , border , true , 0 , 1 , true ));
329339 }
330- if (currentSide == BOTTOM ) {
340+ if (currentSide == BOTTOM ) {
331341 outputDevice .setColor (border .bottomColor ());
332342 outputDevice .fill (generateBorderShape (bounds , BOTTOM , border , true , 0 , 1 , true ));
333343 }
334- if (currentSide == LEFT ) {
344+ if (currentSide == LEFT ) {
335345 outputDevice .setColor (border .leftColor ());
336346 outputDevice .fill (generateBorderShape (bounds , LEFT , border , true , 0 , 1 , true ));
337347 }
@@ -340,10 +350,18 @@ private static void paintBorderSide(OutputDevice outputDevice, final BorderPrope
340350 paintDoubleBorder (outputDevice , border , bounds , currentSide );
341351 } else {
342352 int thickness = 0 ;
343- if (currentSide == BorderPainter .TOP ) thickness = (int ) border .top ();
344- if (currentSide == BorderPainter .BOTTOM ) thickness = (int ) border .bottom ();
345- if (currentSide == BorderPainter .RIGHT ) thickness = (int ) border .right ();
346- if (currentSide == BorderPainter .LEFT ) thickness = (int ) border .left ();
353+ if (currentSide == BorderPainter .TOP ) {
354+ thickness = (int ) border .top ();
355+ }
356+ if (currentSide == BorderPainter .BOTTOM ) {
357+ thickness = (int ) border .bottom ();
358+ }
359+ if (currentSide == BorderPainter .RIGHT ) {
360+ thickness = (int ) border .right ();
361+ }
362+ if (currentSide == BorderPainter .LEFT ) {
363+ thickness = (int ) border .left ();
364+ }
347365 if (borderSideStyle == IdentValue .DASHED ) {
348366 //outputDevice.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
349367 paintPatternedRect (outputDevice , bounds , border , border , new float []{8.0f + thickness * 2 , 4.0f + thickness }, currentSide , xOffset );
@@ -362,10 +380,10 @@ private static void paintDoubleBorder(
362380 OutputDevice outputDevice , BorderPropertySet border ,
363381 Rectangle bounds , int currentSide ) {
364382 // draw outer border
365- paintSolid (outputDevice , bounds , border , 0 , 1 / 3f , currentSide );
383+ paintSolid (outputDevice , bounds , border , 0 , 1 / 3f , currentSide );
366384 // draw inner border
367385 //paintSolid(outputDevice, bounds, border, 1, 1/3f, sides, currentSide, bevel);
368- paintSolid (outputDevice , bounds , border , 2 , 1 / 3f , currentSide );
386+ paintSolid (outputDevice , bounds , border , 2 , 1 / 3f , currentSide );
369387 }
370388
371389 /**
@@ -389,22 +407,22 @@ private static void paintPatternedRect(OutputDevice outputDevice,
389407 outputDevice .setColor (color .topColor ());
390408 outputDevice .setStroke (new BasicStroke (2f * border .top (), BasicStroke .CAP_BUTT , BasicStroke .JOIN_BEVEL , 0 , pattern , xOffset ));
391409 outputDevice .drawBorderLine (
392- path , BorderPainter .TOP , (int )border .top (), false );
410+ path , BorderPainter .TOP , (int ) border .top (), false );
393411 } else if (currentSide == BorderPainter .LEFT ) {
394412 outputDevice .setColor (color .leftColor ());
395413 outputDevice .setStroke (new BasicStroke (2f * border .left (), BasicStroke .CAP_BUTT , BasicStroke .JOIN_BEVEL , 0 , pattern , 0 ));
396414 outputDevice .drawBorderLine (
397- path , BorderPainter .LEFT , (int )border .left (), false );
415+ path , BorderPainter .LEFT , (int ) border .left (), false );
398416 } else if (currentSide == BorderPainter .RIGHT ) {
399417 outputDevice .setColor (color .rightColor ());
400418 outputDevice .setStroke (new BasicStroke (2f * border .right (), BasicStroke .CAP_BUTT , BasicStroke .JOIN_BEVEL , 0 , pattern , 0 ));
401419 outputDevice .drawBorderLine (
402- path , BorderPainter .RIGHT , (int )border .right (), false );
420+ path , BorderPainter .RIGHT , (int ) border .right (), false );
403421 } else if (currentSide == BorderPainter .BOTTOM ) {
404422 outputDevice .setColor (color .bottomColor ());
405423 outputDevice .setStroke (new BasicStroke (2f * border .bottom (), BasicStroke .CAP_BUTT , BasicStroke .JOIN_BEVEL , 0 , pattern , xOffset ));
406424 outputDevice .drawBorderLine (
407- path , BorderPainter .BOTTOM , (int )border .bottom (), false );
425+ path , BorderPainter .BOTTOM , (int ) border .bottom (), false );
408426 }
409427
410428 outputDevice .setClip (old_clip );
0 commit comments