65
65
import sun .swing .StringUIClientPropertyKey ;
66
66
import sun .swing .SwingUtilities2 ;
67
67
68
+ import static sun .java2d .pipe .Region .clipRound ;
69
+
68
70
/**
69
71
* Factory object that can vend Borders appropriate for the metal L & F.
70
72
* @author Steve Wilson
@@ -247,19 +249,6 @@ public static class InternalFrameBorder extends AbstractBorder implements UIReso
247
249
*/
248
250
public InternalFrameBorder () {}
249
251
250
- /**
251
- * Rounds a double to the nearest integer. It rounds 0.5 down,
252
- * for example 1.5 is rounded to 1.0.
253
- *
254
- * @param d number to be rounded
255
- * @return the rounded value
256
- */
257
- private static int roundHalfDown (double d ) {
258
- double decP = (Math .ceil (d ) - d );
259
- return (int )((decP == 0.5 ) ? Math .floor (d ) : Math .round (d ));
260
- }
261
-
262
-
263
252
public void paintBorder (Component c , Graphics g , int x , int y ,
264
253
int w , int h ) {
265
254
Color background ;
@@ -276,41 +265,50 @@ public void paintBorder(Component c, Graphics g, int x, int y,
276
265
shadow = MetalLookAndFeel .getControlInfo ();
277
266
}
278
267
279
- Graphics2D g2d = (Graphics2D ) g ;
280
- AffineTransform at = g2d .getTransform ();
281
- Stroke oldStk = g2d .getStroke ();
282
- Color oldColor = g2d .getColor ();
268
+ AffineTransform at = null ;
269
+ Stroke oldStk = null ;
270
+ boolean resetTransform = false ;
283
271
int stkWidth = 1 ;
272
+ double scaleFactor = 1 ;
273
+
274
+ if (g instanceof Graphics2D g2d ) {
275
+ at = g2d .getTransform ();
276
+ scaleFactor = at .getScaleX ();
277
+ oldStk = g2d .getStroke ();
278
+
279
+ // if m01 or m10 is non-zero, then there is a rotation or shear
280
+ // skip resetting the transform
281
+ resetTransform = ((at .getShearX () == 0 ) && (at .getShearY () == 0 ));
284
282
285
- // if m01 or m10 is non-zero, then there is a rotation or shear
286
- // skip resetting the transform
287
- boolean resetTransform = ((at .getShearX () == 0 ) && (at .getShearY () == 0 ));
283
+ if (resetTransform ) {
284
+ g2d .setTransform (new AffineTransform ());
285
+ stkWidth = clipRound (Math .min (at .getScaleX (), at .getScaleY ()));
286
+ g2d .setStroke (new BasicStroke ((float ) stkWidth ));
287
+ }
288
+ }
288
289
289
290
int xtranslation ;
290
291
int ytranslation ;
291
292
int width ;
292
293
int height ;
293
294
294
295
if (resetTransform ) {
295
- g2d .setTransform (new AffineTransform ());
296
- stkWidth = roundHalfDown (Math .min (at .getScaleX (), at .getScaleY ()));
297
-
298
296
double xx = at .getScaleX () * x + at .getTranslateX ();
299
297
double yy = at .getScaleY () * y + at .getTranslateY ();
300
- xtranslation = roundHalfDown (xx );
301
- ytranslation = roundHalfDown (yy );
302
- width = roundHalfDown (at .getScaleX () * w + xx ) - xtranslation ;
303
- height = roundHalfDown (at .getScaleY () * h + yy ) - ytranslation ;
298
+ xtranslation = clipRound (xx );
299
+ ytranslation = clipRound (yy );
300
+ width = clipRound (at .getScaleX () * w + xx ) - xtranslation ;
301
+ height = clipRound (at .getScaleY () * h + yy ) - ytranslation ;
304
302
} else {
305
- width = w ;
306
- height = h ;
307
303
xtranslation = x ;
308
304
ytranslation = y ;
305
+ width = w ;
306
+ height = h ;
309
307
}
310
- g2d .translate (xtranslation , ytranslation );
308
+ g .translate (xtranslation , ytranslation );
311
309
312
310
// scaled border
313
- int thickness = (int ) Math .ceil (4 * at . getScaleX () );
311
+ int thickness = (int ) Math .ceil (4 * scaleFactor );
314
312
315
313
g .setColor (background );
316
314
// Draw the bulk of the border
@@ -319,17 +317,14 @@ public void paintBorder(Component c, Graphics g, int x, int y,
319
317
}
320
318
321
319
if (c instanceof JInternalFrame && ((JInternalFrame )c ).isResizable ()) {
322
- // set new stroke to draw shadow and highlight lines
323
- g2d .setStroke (new BasicStroke ((float ) stkWidth ));
324
-
325
320
// midpoint at which highlight & shadow lines
326
321
// are positioned on the border
327
322
int midPoint = thickness / 2 ;
328
- int offset = ((at . getScaleX () - stkWidth ) >= 0 && stkWidth % 2 != 0 ) ? 1 : 0 ;
323
+ int offset = ((( scaleFactor - stkWidth ) >= 0 ) && (( stkWidth % 2 ) != 0 ) ) ? 1 : 0 ;
329
324
int loc1 = thickness % 2 == 0 ? midPoint + stkWidth / 2 - stkWidth : midPoint ;
330
325
int loc2 = thickness % 2 == 0 ? midPoint + stkWidth / 2 : midPoint + stkWidth ;
331
326
// scaled corner
332
- int corner = (int ) Math .round (CORNER * at . getScaleX () );
327
+ int corner = (int ) Math .round (CORNER * scaleFactor );
333
328
334
329
// Draw the Long highlight lines
335
330
g .setColor (highlight );
@@ -351,9 +346,9 @@ public void paintBorder(Component c, Graphics g, int x, int y,
351
346
}
352
347
353
348
// restore previous transform
354
- g2d .translate (-xtranslation , -ytranslation );
349
+ g .translate (-xtranslation , -ytranslation );
355
350
if (resetTransform ) {
356
- g2d . setColor ( oldColor ) ;
351
+ Graphics2D g2d = ( Graphics2D ) g ;
357
352
g2d .setTransform (at );
358
353
g2d .setStroke (oldStk );
359
354
}
1 commit comments
openjdk-notifier[bot] commentedon Mar 21, 2024
Review
Issues