Esempio n. 1
0
 public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
   if (image != null && showimage) {
     // TODO: add ability to scale maintaining aspect ratio fitting to size of parent
     // TODO: Need to add not zoom all the way, but zoom to a box of aspect ratio 4/3
     Graphics2D g2 = (Graphics2D) g;
     AffineTransform tran = new AffineTransform(1f, 0f, 0f, 1f, 0, 0);
     float widthscale = (float) c.getWidth() / image.getWidth();
     float heightscale = (float) c.getHeight() / image.getHeight();
     switch (drawmode) {
       case DRAW_MODE_ASPECT:
         float scale;
         if (widthscale < heightscale) {
           scale = widthscale;
         } else {
           scale = heightscale;
         }
         tran.scale(scale, scale);
         g2.drawImage(
             image,
             new AffineTransformOp(tran, AffineTransformOp.TYPE_BILINEAR),
             (int) (c.getWidth() - image.getWidth() * scale) / 2,
             (int) (c.getHeight() - image.getHeight() * scale) / 2);
         break;
       case DRAW_MODE_WIDTH:
         tran.scale(widthscale, widthscale);
         g2.drawImage(image, tran, null);
         break;
       case DRAW_MODE_HEIGHT:
         tran.scale(heightscale, heightscale);
         g2.drawImage(image, tran, null);
         break;
       default:
         tran.scale(widthscale, heightscale);
         g2.drawImage(image, tran, null);
         break;
     }
   }
 }
Esempio n. 2
0
 static void fillRect(final Graphics g, final Component c) {
   fillRect(g, c, c.getBackground(), 0, 0, c.getWidth(), c.getHeight());
 }