< prev index next >

src/java.desktop/share/classes/javax/swing/plaf/nimbus/AbstractRegionPainter.java

Print this page




 623             centerWidth = w - leftWidth - rightWidth;
 624             topHeight = ctx.c * f;
 625             bottomHeight = (float)(ctx.canvasSize.getHeight() - ctx.d) * f;
 626             centerHeight = h - topHeight - bottomHeight;
 627         }
 628 
 629         leftScale = ctx.a == 0f ? 0f : leftWidth / ctx.a;
 630         centerHScale = (ctx.b - ctx.a) == 0f ? 0f : centerWidth / (ctx.b - ctx.a);
 631         rightScale = (ctx.canvasSize.width - ctx.b) == 0f ? 0f : rightWidth / (ctx.canvasSize.width - ctx.b);
 632         topScale = ctx.c == 0f ? 0f : topHeight / ctx.c;
 633         centerVScale = (ctx.d - ctx.c) == 0f ? 0f : centerHeight / (ctx.d - ctx.c);
 634         bottomScale = (ctx.canvasSize.height - ctx.d) == 0f ? 0f : bottomHeight / (ctx.canvasSize.height - ctx.d);
 635     }
 636 
 637     private void paintWith9SquareCaching(Graphics2D g, PaintContext ctx,
 638                                          JComponent c, int w, int h,
 639                                          Object[] extendedCacheKeys) {
 640         // check if we can scale to the requested size
 641         Dimension canvas = ctx.canvasSize;
 642         Insets insets = ctx.stretchingInsets;
 643         if (insets.left + insets.right > w || insets.top + insets.bottom > h) {
 644             return;
 645         }
 646 
 647         if (w <= (canvas.width * ctx.maxHorizontalScaleFactor) && h <= (canvas.height * ctx.maxVerticalScaleFactor)) {
 648             // get image at canvas size
 649             VolatileImage img = getImage(g.getDeviceConfiguration(), c, canvas.width, canvas.height, extendedCacheKeys);
 650             if (img != null) {
 651                 // calculate dst inserts
 652                 // todo: destination inserts need to take into acount scale factor for high dpi. Note: You can use f for this, I think
 653                 Insets dstInsets;
 654                 if (ctx.inverted){
 655                     int leftRight = (w-(canvas.width-(insets.left+insets.right)))/2;
 656                     int topBottom = (h-(canvas.height-(insets.top+insets.bottom)))/2;
 657                     dstInsets = new Insets(topBottom,leftRight,topBottom,leftRight);
 658                 } else {
 659                     dstInsets = insets;
 660                 }
 661                 // paint 9 square scaled
 662                 Object oldScaleingHints = g.getRenderingHint(RenderingHints.KEY_INTERPOLATION);
 663                 g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_BILINEAR);
 664                 ImageScalingHelper.paint(g, 0, 0, w, h, img, insets, dstInsets,
 665                         ImageScalingHelper.PaintType.PAINT9_STRETCH, ImageScalingHelper.PAINT_ALL);
 666                 g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,




 623             centerWidth = w - leftWidth - rightWidth;
 624             topHeight = ctx.c * f;
 625             bottomHeight = (float)(ctx.canvasSize.getHeight() - ctx.d) * f;
 626             centerHeight = h - topHeight - bottomHeight;
 627         }
 628 
 629         leftScale = ctx.a == 0f ? 0f : leftWidth / ctx.a;
 630         centerHScale = (ctx.b - ctx.a) == 0f ? 0f : centerWidth / (ctx.b - ctx.a);
 631         rightScale = (ctx.canvasSize.width - ctx.b) == 0f ? 0f : rightWidth / (ctx.canvasSize.width - ctx.b);
 632         topScale = ctx.c == 0f ? 0f : topHeight / ctx.c;
 633         centerVScale = (ctx.d - ctx.c) == 0f ? 0f : centerHeight / (ctx.d - ctx.c);
 634         bottomScale = (ctx.canvasSize.height - ctx.d) == 0f ? 0f : bottomHeight / (ctx.canvasSize.height - ctx.d);
 635     }
 636 
 637     private void paintWith9SquareCaching(Graphics2D g, PaintContext ctx,
 638                                          JComponent c, int w, int h,
 639                                          Object[] extendedCacheKeys) {
 640         // check if we can scale to the requested size
 641         Dimension canvas = ctx.canvasSize;
 642         Insets insets = ctx.stretchingInsets;




 643         if (w <= (canvas.width * ctx.maxHorizontalScaleFactor) && h <= (canvas.height * ctx.maxVerticalScaleFactor)) {
 644             // get image at canvas size
 645             VolatileImage img = getImage(g.getDeviceConfiguration(), c, canvas.width, canvas.height, extendedCacheKeys);
 646             if (img != null) {
 647                 // calculate dst inserts
 648                 // todo: destination inserts need to take into acount scale factor for high dpi. Note: You can use f for this, I think
 649                 Insets dstInsets;
 650                 if (ctx.inverted){
 651                     int leftRight = (w-(canvas.width-(insets.left+insets.right)))/2;
 652                     int topBottom = (h-(canvas.height-(insets.top+insets.bottom)))/2;
 653                     dstInsets = new Insets(topBottom,leftRight,topBottom,leftRight);
 654                 } else {
 655                     dstInsets = insets;
 656                 }
 657                 // paint 9 square scaled
 658                 Object oldScaleingHints = g.getRenderingHint(RenderingHints.KEY_INTERPOLATION);
 659                 g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_BILINEAR);
 660                 ImageScalingHelper.paint(g, 0, 0, w, h, img, insets, dstInsets,
 661                         ImageScalingHelper.PaintType.PAINT9_STRETCH, ImageScalingHelper.PAINT_ALL);
 662                 g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,


< prev index next >