< prev index next >

src/share/classes/com/sun/java/swing/plaf/windows/WindowsScrollBarUI.java

Print this page
rev 1580 : 6727661: Code improvement and warnings removing from the swing/plaf packages
Summary: Removed unnecessary castings and other warnings
Reviewed-by: alexp
Contributed-by: Florian Brunner <fbrunnerlist@gmx.ch>


 352                 }
 353                 size = Math.max(size, 5);
 354             }
 355             return new Dimension(size, size);
 356         }
 357     }
 358 
 359 
 360     /**
 361      * This should be pulled out into its own class if more classes need to
 362      * use it.
 363      * <p>
 364      * Grid is used to draw the track for windows scrollbars. Grids
 365      * are cached in a HashMap, with the key being the rgb components
 366      * of the foreground/background colors. Further the Grid is held through
 367      * a WeakRef so that it can be freed when no longer needed. As the
 368      * Grid is rather expensive to draw, it is drawn in a BufferedImage.
 369      */
 370     private static class Grid {
 371         private static final int BUFFER_SIZE = 64;
 372         private static HashMap map;
 373 
 374         private BufferedImage image;
 375 
 376         static {
 377             map = new HashMap();
 378         }
 379 
 380         public static Grid getGrid(Color fg, Color bg) {
 381             String key = fg.getRGB() + " " + bg.getRGB();
 382             WeakReference ref = (WeakReference)map.get(key);
 383             Grid grid = (ref == null) ? null : (Grid)ref.get();
 384             if (grid == null) {
 385                 grid = new Grid(fg, bg);
 386                 map.put(key, new WeakReference(grid));
 387             }
 388             return grid;
 389         }
 390 
 391         public Grid(Color fg, Color bg) {
 392             int cmap[] = { fg.getRGB(), bg.getRGB() };
 393             IndexColorModel icm = new IndexColorModel(8, 2, cmap, 0, false, -1,
 394                                                       DataBuffer.TYPE_BYTE);
 395             image = new BufferedImage(BUFFER_SIZE, BUFFER_SIZE,
 396                                       BufferedImage.TYPE_BYTE_INDEXED, icm);
 397             Graphics g = image.getGraphics();
 398             try {
 399                 g.setClip(0, 0, BUFFER_SIZE, BUFFER_SIZE);
 400                 paintGrid(g, fg, bg);
 401             }
 402             finally {
 403                 g.dispose();
 404             }
 405         }
 406 




 352                 }
 353                 size = Math.max(size, 5);
 354             }
 355             return new Dimension(size, size);
 356         }
 357     }
 358 
 359 
 360     /**
 361      * This should be pulled out into its own class if more classes need to
 362      * use it.
 363      * <p>
 364      * Grid is used to draw the track for windows scrollbars. Grids
 365      * are cached in a HashMap, with the key being the rgb components
 366      * of the foreground/background colors. Further the Grid is held through
 367      * a WeakRef so that it can be freed when no longer needed. As the
 368      * Grid is rather expensive to draw, it is drawn in a BufferedImage.
 369      */
 370     private static class Grid {
 371         private static final int BUFFER_SIZE = 64;
 372         private static HashMap<String, WeakReference<Grid>> map;
 373 
 374         private BufferedImage image;
 375 
 376         static {
 377             map = new HashMap<String, WeakReference<Grid>>();
 378         }
 379 
 380         public static Grid getGrid(Color fg, Color bg) {
 381             String key = fg.getRGB() + " " + bg.getRGB();
 382             WeakReference<Grid> ref = map.get(key);
 383             Grid grid = (ref == null) ? null : ref.get();
 384             if (grid == null) {
 385                 grid = new Grid(fg, bg);
 386                 map.put(key, new WeakReference<Grid>(grid));
 387             }
 388             return grid;
 389         }
 390 
 391         public Grid(Color fg, Color bg) {
 392             int cmap[] = { fg.getRGB(), bg.getRGB() };
 393             IndexColorModel icm = new IndexColorModel(8, 2, cmap, 0, false, -1,
 394                                                       DataBuffer.TYPE_BYTE);
 395             image = new BufferedImage(BUFFER_SIZE, BUFFER_SIZE,
 396                                       BufferedImage.TYPE_BYTE_INDEXED, icm);
 397             Graphics g = image.getGraphics();
 398             try {
 399                 g.setClip(0, 0, BUFFER_SIZE, BUFFER_SIZE);
 400                 paintGrid(g, fg, bg);
 401             }
 402             finally {
 403                 g.dispose();
 404             }
 405         }
 406 


< prev index next >