KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > swing > plaf > metal > MetalIconFactory


1 /*
2  * @(#)MetalIconFactory.java 1.60 04/02/15
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package javax.swing.plaf.metal;
9
10 import javax.swing.*;
11 import javax.swing.plaf.UIResource JavaDoc;
12 import java.awt.*;
13 import java.awt.image.BufferedImage JavaDoc;
14 import java.io.Serializable JavaDoc;
15 import java.util.Enumeration JavaDoc;
16 import java.util.Vector JavaDoc;
17
18 /**
19  * Factory object that vends <code>Icon</code>s for
20  * the Java<sup><font size="-2">TM</font></sup> look and feel (Metal).
21  * These icons are used extensively in Metal via the defaults mechanism.
22  * While other look and feels often use GIFs for icons, creating icons
23  * in code facilitates switching to other themes.
24  *
25  * <p>
26  * Each method in this class returns
27  * either an <code>Icon</code> or <code>null</code>,
28  * where <code>null</code> implies that there is no default icon.
29  *
30  * <p>
31  * <strong>Warning:</strong>
32  * Serialized objects of this class will not be compatible with
33  * future Swing releases. The current serialization support is
34  * appropriate for short term storage or RMI between applications running
35  * the same version of Swing. As of 1.4, support for long term storage
36  * of all JavaBeans<sup><font size="-2">TM</font></sup>
37  * has been added to the <code>java.beans</code> package.
38  * Please see {@link java.beans.XMLEncoder}.
39  *
40  * @version 1.60 02/15/04
41  * @author Michael C. Albers
42  */

43 public class MetalIconFactory implements Serializable JavaDoc {
44
45     // List of code-drawn Icons
46
private static Icon fileChooserDetailViewIcon;
47     private static Icon fileChooserHomeFolderIcon;
48     private static Icon fileChooserListViewIcon;
49     private static Icon fileChooserNewFolderIcon;
50     private static Icon fileChooserUpFolderIcon;
51     private static Icon internalFrameAltMaximizeIcon;
52     private static Icon internalFrameCloseIcon;
53     private static Icon internalFrameDefaultMenuIcon;
54     private static Icon internalFrameMaximizeIcon;
55     private static Icon internalFrameMinimizeIcon;
56     private static Icon radioButtonIcon;
57     private static Icon treeComputerIcon;
58     private static Icon treeFloppyDriveIcon;
59     private static Icon treeHardDriveIcon;
60
61
62     private static Icon menuArrowIcon;
63     private static Icon menuItemArrowIcon;
64     private static Icon checkBoxMenuItemIcon;
65     private static Icon radioButtonMenuItemIcon;
66     private static Icon checkBoxIcon;
67
68
69     // Ocean icons
70
private static Icon oceanHorizontalSliderThumb;
71     private static Icon oceanVerticalSliderThumb;
72
73     // Constants
74
public static final boolean DARK = false;
75     public static final boolean LIGHT = true;
76
77     // Accessor functions for Icons. Does the caching work.
78
public static Icon getFileChooserDetailViewIcon() {
79     if (fileChooserDetailViewIcon == null) {
80         fileChooserDetailViewIcon = new FileChooserDetailViewIcon();
81     }
82     return fileChooserDetailViewIcon;
83     }
84
85     public static Icon getFileChooserHomeFolderIcon() {
86     if (fileChooserHomeFolderIcon == null) {
87         fileChooserHomeFolderIcon = new FileChooserHomeFolderIcon();
88     }
89     return fileChooserHomeFolderIcon;
90     }
91
92     public static Icon getFileChooserListViewIcon() {
93     if (fileChooserListViewIcon == null) {
94         fileChooserListViewIcon = new FileChooserListViewIcon();
95     }
96     return fileChooserListViewIcon;
97     }
98
99     public static Icon getFileChooserNewFolderIcon() {
100     if (fileChooserNewFolderIcon == null) {
101         fileChooserNewFolderIcon = new FileChooserNewFolderIcon();
102     }
103     return fileChooserNewFolderIcon;
104     }
105
106     public static Icon getFileChooserUpFolderIcon() {
107     if (fileChooserUpFolderIcon == null) {
108         fileChooserUpFolderIcon = new FileChooserUpFolderIcon();
109     }
110     return fileChooserUpFolderIcon;
111     }
112
113     public static Icon getInternalFrameAltMaximizeIcon(int size) {
114     return new InternalFrameAltMaximizeIcon(size);
115     }
116
117     public static Icon getInternalFrameCloseIcon(int size) {
118     return new InternalFrameCloseIcon(size);
119     }
120
121     public static Icon getInternalFrameDefaultMenuIcon() {
122     if (internalFrameDefaultMenuIcon == null) {
123         internalFrameDefaultMenuIcon = new InternalFrameDefaultMenuIcon();
124     }
125     return internalFrameDefaultMenuIcon;
126     }
127
128     public static Icon getInternalFrameMaximizeIcon(int size) {
129     return new InternalFrameMaximizeIcon(size);
130     }
131
132     public static Icon getInternalFrameMinimizeIcon(int size) {
133     return new InternalFrameMinimizeIcon(size);
134     }
135
136     public static Icon getRadioButtonIcon() {
137     if (radioButtonIcon == null) {
138         radioButtonIcon = new RadioButtonIcon();
139     }
140     return radioButtonIcon;
141     }
142
143     /**
144      * Returns a checkbox icon.
145      * @since 1.3
146      */

147     public static Icon getCheckBoxIcon() {
148     if (checkBoxIcon == null) {
149         checkBoxIcon = new CheckBoxIcon();
150     }
151     return checkBoxIcon;
152     }
153
154     public static Icon getTreeComputerIcon() {
155         if ( treeComputerIcon == null ) {
156         treeComputerIcon = new TreeComputerIcon();
157     }
158     return treeComputerIcon;
159     }
160
161     public static Icon getTreeFloppyDriveIcon() {
162         if ( treeFloppyDriveIcon == null ) {
163         treeFloppyDriveIcon = new TreeFloppyDriveIcon();
164     }
165     return treeFloppyDriveIcon;
166     }
167
168     public static Icon getTreeFolderIcon() {
169     return new TreeFolderIcon();
170     }
171
172     public static Icon getTreeHardDriveIcon() {
173         if ( treeHardDriveIcon == null ) {
174         treeHardDriveIcon = new TreeHardDriveIcon();
175     }
176     return treeHardDriveIcon;
177     }
178
179     public static Icon getTreeLeafIcon() {
180     return new TreeLeafIcon();
181     }
182
183     public static Icon getTreeControlIcon( boolean isCollapsed ) {
184         return new TreeControlIcon( isCollapsed );
185     }
186
187     public static Icon getMenuArrowIcon() {
188     if (menuArrowIcon == null) {
189         menuArrowIcon = new MenuArrowIcon();
190     }
191     return menuArrowIcon;
192     }
193
194     /**
195      * Returns an icon to be used by <code>JCheckBoxMenuItem</code>.
196      *
197      * @return the default icon for check box menu items,
198      * or <code>null</code> if no default exists
199      */

200     public static Icon getMenuItemCheckIcon() {
201         return null;
202     }
203
204     public static Icon getMenuItemArrowIcon() {
205     if (menuItemArrowIcon == null) {
206         menuItemArrowIcon = new MenuItemArrowIcon();
207     }
208     return menuItemArrowIcon;
209     }
210
211     public static Icon getCheckBoxMenuItemIcon() {
212     if (checkBoxMenuItemIcon == null) {
213         checkBoxMenuItemIcon = new CheckBoxMenuItemIcon();
214     }
215     return checkBoxMenuItemIcon;
216     }
217
218     public static Icon getRadioButtonMenuItemIcon() {
219     if (radioButtonMenuItemIcon == null) {
220         radioButtonMenuItemIcon = new RadioButtonMenuItemIcon();
221     }
222     return radioButtonMenuItemIcon;
223     }
224
225     public static Icon getHorizontalSliderThumbIcon() {
226         if (MetalLookAndFeel.usingOcean()) {
227             if (oceanHorizontalSliderThumb == null) {
228                 oceanHorizontalSliderThumb =
229                                new OceanHorizontalSliderThumbIcon();
230             }
231             return oceanHorizontalSliderThumb;
232         }
233       // don't cache these, bumps don't get updated otherwise
234
return new HorizontalSliderThumbIcon();
235     }
236
237     public static Icon getVerticalSliderThumbIcon() {
238         if (MetalLookAndFeel.usingOcean()) {
239             if (oceanVerticalSliderThumb == null) {
240                 oceanVerticalSliderThumb = new OceanVerticalSliderThumbIcon();
241             }
242             return oceanVerticalSliderThumb;
243         }
244         // don't cache these, bumps don't get updated otherwise
245
return new VerticalSliderThumbIcon();
246     }
247
248     // File Chooser Detail View code
249
private static class FileChooserDetailViewIcon implements Icon, UIResource JavaDoc, Serializable JavaDoc {
250         public void paintIcon(Component c, Graphics g, int x, int y) {
251         g.translate(x, y);
252
253         // Draw outside edge of each of the documents
254
g.setColor(MetalLookAndFeel.getPrimaryControlInfo());
255         // top
256
g.drawLine(2,2, 5,2); // top
257
g.drawLine(2,3, 2,7); // left
258
g.drawLine(3,7, 6,7); // bottom
259
g.drawLine(6,6, 6,3); // right
260
// bottom
261
g.drawLine(2,10, 5,10); // top
262
g.drawLine(2,11, 2,15); // left
263
g.drawLine(3,15, 6,15); // bottom
264
g.drawLine(6,14, 6,11); // right
265

266         // Draw little dots next to documents
267
// Same color as outside edge
268
g.drawLine(8,5, 15,5); // top
269
g.drawLine(8,13, 15,13); // bottom
270

271         // Draw inner highlight on documents
272
g.setColor(MetalLookAndFeel.getPrimaryControl());
273         g.drawRect(3,3, 2,3); // top
274
g.drawRect(3,11, 2,3); // bottom
275

276         // Draw inner inner highlight on documents
277
g.setColor(MetalLookAndFeel.getPrimaryControlHighlight());
278         g.drawLine(4,4, 4,5); // top
279
g.drawLine(4,12, 4,13); // bottom
280

281         g.translate(-x, -y);
282     }
283     
284     public int getIconWidth() {
285         return 18;
286     }
287     
288     public int getIconHeight() {
289         return 18;
290     }
291     } // End class FileChooserDetailViewIcon
292

293     // File Chooser Home Folder code
294
private static class FileChooserHomeFolderIcon implements Icon, UIResource JavaDoc, Serializable JavaDoc {
295         public void paintIcon(Component c, Graphics g, int x, int y) {
296         g.translate(x, y);
297
298         // Draw outside edge of house
299
g.setColor(MetalLookAndFeel.getPrimaryControlInfo());
300         g.drawLine(8,1, 1,8); // left edge of roof
301
g.drawLine(8,1, 15,8); // right edge of roof
302
g.drawLine(11,2, 11,3); // left edge of chimney
303
g.drawLine(12,2, 12,4); // right edge of chimney
304
g.drawLine(3,7, 3,15); // left edge of house
305
g.drawLine(13,7, 13,15); // right edge of house
306
g.drawLine(4,15, 12,15); // bottom edge of house
307
// Draw door frame
308
// same color as edge of house
309
g.drawLine( 6,9, 6,14); // left
310
g.drawLine(10,9, 10,14); // right
311
g.drawLine( 7,9, 9, 9); // top
312

313         // Draw roof body
314
g.setColor(MetalLookAndFeel.getControlDarkShadow());
315         g.fillRect(8,2, 1,1); //top toward bottom
316
g.fillRect(7,3, 3,1);
317         g.fillRect(6,4, 5,1);
318         g.fillRect(5,5, 7,1);
319         g.fillRect(4,6, 9,2);
320         // Draw doornob
321
// same color as roof body
322
g.drawLine(9,12, 9,12);
323
324         // Paint the house
325
g.setColor(MetalLookAndFeel.getPrimaryControl());
326         g.drawLine(4,8, 12,8); // above door
327
g.fillRect(4,9, 2,6); // left of door
328
g.fillRect(11,9, 2,6); // right of door
329

330         g.translate(-x, -y);
331     }
332     
333     public int getIconWidth() {
334         return 18;
335     }
336     
337     public int getIconHeight() {
338         return 18;
339     }
340     } // End class FileChooserHomeFolderIcon
341

342     // File Chooser List View code
343
private static class FileChooserListViewIcon implements Icon, UIResource JavaDoc, Serializable JavaDoc {
344         public void paintIcon(Component c, Graphics g, int x, int y) {
345         g.translate(x, y);
346
347         // Draw outside edge of each of the documents
348
g.setColor(MetalLookAndFeel.getPrimaryControlInfo());
349         // top left
350
g.drawLine(2,2, 5,2); // top
351
g.drawLine(2,3, 2,7); // left
352
g.drawLine(3,7, 6,7); // bottom
353
g.drawLine(6,6, 6,3); // right
354
// top right
355
g.drawLine(10,2, 13,2); // top
356
g.drawLine(10,3, 10,7); // left
357
g.drawLine(11,7, 14,7); // bottom
358
g.drawLine(14,6, 14,3); // right
359
// bottom left
360
g.drawLine(2,10, 5,10); // top
361
g.drawLine(2,11, 2,15); // left
362
g.drawLine(3,15, 6,15); // bottom
363
g.drawLine(6,14, 6,11); // right
364
// bottom right
365
g.drawLine(10,10, 13,10); // top
366
g.drawLine(10,11, 10,15); // left
367
g.drawLine(11,15, 14,15); // bottom
368
g.drawLine(14,14, 14,11); // right
369

370         // Draw little dots next to documents
371
// Same color as outside edge
372
g.drawLine(8,5, 8,5); // top left
373
g.drawLine(16,5, 16,5); // top right
374
g.drawLine(8,13, 8,13); // bottom left
375
g.drawLine(16,13, 16,13); // bottom right
376

377         // Draw inner highlight on documents
378
g.setColor(MetalLookAndFeel.getPrimaryControl());
379         g.drawRect(3,3, 2,3); // top left
380
g.drawRect(11,3, 2,3); // top right
381
g.drawRect(3,11, 2,3); // bottom left
382
g.drawRect(11,11, 2,3); // bottom right
383

384         // Draw inner inner highlight on documents
385
g.setColor(MetalLookAndFeel.getPrimaryControlHighlight());
386         g.drawLine(4,4, 4,5); // top left
387
g.drawLine(12,4, 12,5); // top right
388
g.drawLine(4,12, 4,13); // bottom left
389
g.drawLine(12,12, 12,13); // bottom right
390

391         g.translate(-x, -y);
392     }
393     
394     public int getIconWidth() {
395         return 18;
396     }
397     
398     public int getIconHeight() {
399         return 18;
400     }
401     } // End class FileChooserListViewIcon
402

403     // File Chooser New Folder code
404
private static class FileChooserNewFolderIcon implements Icon, UIResource JavaDoc, Serializable JavaDoc {
405         public void paintIcon(Component c, Graphics g, int x, int y) {
406         g.translate(x, y);
407
408         // Fill background
409
g.setColor(MetalLookAndFeel.getPrimaryControl());
410         g.fillRect(3,5, 12,9);
411
412         // Draw outside edge of folder
413
g.setColor(MetalLookAndFeel.getPrimaryControlInfo());
414         g.drawLine(1,6, 1,14); // left
415
g.drawLine(2,14, 15,14); // bottom
416
g.drawLine(15,13, 15,5); // right
417
g.drawLine(2,5, 9,5); // top left
418
g.drawLine(10,6, 14,6); // top right
419

420         // Draw inner folder highlight
421
g.setColor(MetalLookAndFeel.getPrimaryControlHighlight());
422         g.drawLine( 2,6, 2,13); // left
423
g.drawLine( 3,6, 9,6); // top left
424
g.drawLine(10,7, 14,7); // top right
425

426         // Draw tab on folder
427
g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow());
428         g.drawLine(11,3, 15,3); // top
429
g.drawLine(10,4, 15,4); // bottom
430

431         g.translate(-x, -y);
432     }
433     
434     public int getIconWidth() {
435         return 18;
436     }
437     
438     public int getIconHeight() {
439         return 18;
440     }
441     } // End class FileChooserNewFolderIcon
442

443     // File Chooser Up Folder code
444
private static class FileChooserUpFolderIcon implements Icon, UIResource JavaDoc, Serializable JavaDoc {
445         public void paintIcon(Component c, Graphics g, int x, int y) {
446         g.translate(x, y);
447
448         // Fill background
449
g.setColor(MetalLookAndFeel.getPrimaryControl());
450         g.fillRect(3,5, 12,9);
451
452         // Draw outside edge of folder
453
g.setColor(MetalLookAndFeel.getPrimaryControlInfo());
454         g.drawLine(1,6, 1,14); // left
455
g.drawLine(2,14, 15,14); // bottom
456
g.drawLine(15,13, 15,5); // right
457
g.drawLine(2,5, 9,5); // top left
458
g.drawLine(10,6, 14,6); // top right
459
// Draw the UP arrow
460
// same color as edge
461
g.drawLine(8,13, 8,16); // arrow shaft
462
g.drawLine(8, 9, 8, 9); // arrowhead top
463
g.drawLine(7,10, 9,10);
464         g.drawLine(6,11, 10,11);
465         g.drawLine(5,12, 11,12);
466
467         // Draw inner folder highlight
468
g.setColor(MetalLookAndFeel.getPrimaryControlHighlight());
469         g.drawLine( 2,6, 2,13); // left
470
g.drawLine( 3,6, 9,6); // top left
471
g.drawLine(10,7, 14,7); // top right
472

473         // Draw tab on folder
474
g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow());
475         g.drawLine(11,3, 15,3); // top
476
g.drawLine(10,4, 15,4); // bottom
477

478         g.translate(-x, -y);
479     }
480     
481     public int getIconWidth() {
482         return 18;
483     }
484     
485     public int getIconHeight() {
486         return 18;
487     }
488     } // End class FileChooserUpFolderIcon
489

490
491     /**
492      * Defines an icon for Palette close
493      * @since 1.3
494      */

495     public static class PaletteCloseIcon implements Icon, UIResource JavaDoc, Serializable JavaDoc{
496         int iconSize = 7;
497
498         public void paintIcon(Component c, Graphics g, int x, int y) {
499         JButton parentButton = (JButton)c;
500         ButtonModel buttonModel = parentButton.getModel();
501
502         Color back;
503         Color highlight = MetalLookAndFeel.getPrimaryControlHighlight();
504         Color shadow = MetalLookAndFeel.getPrimaryControlInfo();
505         if (buttonModel.isPressed() && buttonModel.isArmed()) {
506             back = shadow;
507         } else {
508             back = MetalLookAndFeel.getPrimaryControlDarkShadow();
509         }
510
511         g.translate(x, y);
512         g.setColor(back);
513         g.drawLine( 0, 1, 5, 6);
514         g.drawLine( 1, 0, 6, 5);
515         g.drawLine( 1, 1, 6, 6);
516         g.drawLine( 6, 1, 1, 6);
517         g.drawLine( 5,0, 0,5);
518         g.drawLine(5,1, 1,5);
519        
520         g.setColor(highlight);
521         g.drawLine(6,2, 5,3);
522         g.drawLine(2,6, 3, 5);
523         g.drawLine(6,6,6,6);
524
525
526         g.translate(-x, -y);
527     }
528
529     public int getIconWidth() {
530         return iconSize;
531     }
532     
533     public int getIconHeight() {
534         return iconSize;
535     }
536     }
537
538     // Internal Frame Close code
539
private static class InternalFrameCloseIcon implements Icon, UIResource JavaDoc, Serializable JavaDoc {
540     int iconSize = 16;
541     
542         public InternalFrameCloseIcon(int size) {
543         iconSize = size;
544     }
545     
546         public void paintIcon(Component c, Graphics g, int x, int y) {
547         JButton parentButton = (JButton)c;
548         ButtonModel buttonModel = parentButton.getModel();
549
550         Color backgroundColor = MetalLookAndFeel.getPrimaryControl();
551         Color internalBackgroundColor =
552         MetalLookAndFeel.getPrimaryControl();
553         Color mainItemColor =
554         MetalLookAndFeel.getPrimaryControlDarkShadow();
555         Color darkHighlightColor = MetalLookAndFeel.getBlack();
556         Color xLightHighlightColor = MetalLookAndFeel.getWhite();
557         Color boxLightHighlightColor = MetalLookAndFeel.getWhite();
558         
559         // if the inactive window
560
if (parentButton.getClientProperty("paintActive") != Boolean.TRUE)
561         {
562         backgroundColor = MetalLookAndFeel.getControl();
563         internalBackgroundColor = backgroundColor;
564         mainItemColor = MetalLookAndFeel.getControlDarkShadow();
565         // if inactive and pressed
566
if (buttonModel.isPressed() && buttonModel.isArmed()) {
567             internalBackgroundColor =
568             MetalLookAndFeel.getControlShadow();
569             xLightHighlightColor = internalBackgroundColor;
570             mainItemColor = darkHighlightColor;
571         }
572         }
573         // if pressed
574
else if (buttonModel.isPressed() && buttonModel.isArmed()) {
575         internalBackgroundColor =
576             MetalLookAndFeel.getPrimaryControlShadow();
577         xLightHighlightColor = internalBackgroundColor;
578         mainItemColor = darkHighlightColor;
579         // darkHighlightColor is still "getBlack()"
580
}
581
582         // Some calculations that are needed more than once later on.
583
int oneHalf = (int)(iconSize / 2); // 16 -> 8
584

585         g.translate(x, y);
586
587         // fill background
588
g.setColor(backgroundColor);
589         g.fillRect(0,0, iconSize,iconSize);
590         
591         // fill inside of box area
592
g.setColor(internalBackgroundColor);
593         g.fillRect(3,3, iconSize-6,iconSize-6);
594
595         // THE BOX
596
// the top/left dark higlight - some of this will get overwritten
597
g.setColor(darkHighlightColor);
598         g.drawRect(1,1, iconSize-3,iconSize-3);
599         // draw the inside bottom/right highlight
600
g.drawRect(2,2, iconSize-5,iconSize-5);
601         // draw the light/outside, bottom/right highlight
602
g.setColor(boxLightHighlightColor);
603         g.drawRect(2,2, iconSize-3,iconSize-3);
604         // draw the "normal" box
605
g.setColor(mainItemColor);
606         g.drawRect(2,2, iconSize-4,iconSize-4);
607         g.drawLine(3,iconSize-3, 3,iconSize-3); // lower left
608
g.drawLine(iconSize-3,3, iconSize-3,3); // up right
609

610         // THE "X"
611
// Dark highlight
612
g.setColor(darkHighlightColor);
613         g.drawLine(4,5, 5,4); // far up left
614
g.drawLine(4,iconSize-6, iconSize-6,4); // against body of "X"
615
// Light highlight
616
g.setColor(xLightHighlightColor);
617         g.drawLine(6,iconSize-5, iconSize-5,6); // against body of "X"
618
// one pixel over from the body
619
g.drawLine(oneHalf,oneHalf+2, oneHalf+2,oneHalf);
620           // bottom right
621
g.drawLine(iconSize-5,iconSize-5, iconSize-4,iconSize-5);
622         g.drawLine(iconSize-5,iconSize-4, iconSize-5,iconSize-4);
623         // Main color
624
g.setColor(mainItemColor);
625           // Upper left to lower right
626
g.drawLine(5,5, iconSize-6,iconSize-6); // g.drawLine(5,5, 10,10);
627
g.drawLine(6,5, iconSize-5,iconSize-6); // g.drawLine(6,5, 11,10);
628
g.drawLine(5,6, iconSize-6,iconSize-5); // g.drawLine(5,6, 10,11);
629
// Lower left to upper right
630
g.drawLine(5,iconSize-5, iconSize-5,5); // g.drawLine(5,11, 11,5);
631
g.drawLine(5,iconSize-6, iconSize-6,5); // g.drawLine(5,10, 10,5);
632

633         g.translate(-x, -y);
634     }
635     
636     public int getIconWidth() {
637         return iconSize;
638     }
639
640     public int getIconHeight() {
641         return iconSize;
642     }
643     } // End class InternalFrameCloseIcon
644

645     // Internal Frame Alternate Maximize code (actually, the un-maximize icon)
646
private static class InternalFrameAltMaximizeIcon implements Icon, UIResource JavaDoc, Serializable JavaDoc {
647     int iconSize = 16;
648
649         public InternalFrameAltMaximizeIcon(int size) {
650         iconSize = size;
651     }
652
653         public void paintIcon(Component c, Graphics g, int x, int y) {
654         JButton parentButton = (JButton)c;
655         ButtonModel buttonModel = parentButton.getModel();
656
657         Color backgroundColor = MetalLookAndFeel.getPrimaryControl();
658         Color internalBackgroundColor =
659         MetalLookAndFeel.getPrimaryControl();
660         Color mainItemColor =
661         MetalLookAndFeel.getPrimaryControlDarkShadow();
662         Color darkHighlightColor = MetalLookAndFeel.getBlack();
663         // ul = Upper Left and lr = Lower Right
664
Color ulLightHighlightColor = MetalLookAndFeel.getWhite();
665         Color lrLightHighlightColor = MetalLookAndFeel.getWhite();
666         
667         // if the internal frame is inactive
668
if (parentButton.getClientProperty("paintActive") != Boolean.TRUE)
669         {
670         backgroundColor = MetalLookAndFeel.getControl();
671         internalBackgroundColor = backgroundColor;
672         mainItemColor = MetalLookAndFeel.getControlDarkShadow();
673         // if inactive and pressed
674
if (buttonModel.isPressed() && buttonModel.isArmed()) {
675             internalBackgroundColor =
676             MetalLookAndFeel.getControlShadow();
677             ulLightHighlightColor = internalBackgroundColor;
678             mainItemColor = darkHighlightColor;
679         }
680         }
681         // if the button is pressed and the mouse is over it
682
else if (buttonModel.isPressed() && buttonModel.isArmed()) {
683         internalBackgroundColor =
684             MetalLookAndFeel.getPrimaryControlShadow();
685         ulLightHighlightColor = internalBackgroundColor;
686         mainItemColor = darkHighlightColor;
687         // darkHighlightColor is still "getBlack()"
688
}
689
690         g.translate(x, y);
691
692         // fill background
693
g.setColor(backgroundColor);
694         g.fillRect(0,0, iconSize,iconSize);
695
696         // BOX
697
// fill inside the box
698
g.setColor(internalBackgroundColor);
699         g.fillRect(3,6, iconSize-9,iconSize-9);
700
701         // draw dark highlight color
702
g.setColor(darkHighlightColor);
703         g.drawRect(1,5, iconSize-8,iconSize-8);
704         g.drawLine(1,iconSize-2, 1,iconSize-2); // extra pixel on bottom
705

706         // draw lower right light highlight
707
g.setColor(lrLightHighlightColor);
708         g.drawRect(2,6, iconSize-7,iconSize-7);
709         // draw upper left light highlight
710
g.setColor(ulLightHighlightColor);
711         g.drawRect(3,7, iconSize-9,iconSize-9);
712
713         // draw the main box
714
g.setColor(mainItemColor);
715         g.drawRect(2,6, iconSize-8,iconSize-8);
716
717         // Six extraneous pixels to deal with
718
g.setColor(ulLightHighlightColor);
719         g.drawLine(iconSize-6,8,iconSize-6,8);
720         g.drawLine(iconSize-9,6, iconSize-7,8);
721         g.setColor(mainItemColor);
722         g.drawLine(3,iconSize-3,3,iconSize-3);
723         g.setColor(darkHighlightColor);
724         g.drawLine(iconSize-6,9,iconSize-6,9);
725         g.setColor(backgroundColor);
726         g.drawLine(iconSize-9,5,iconSize-9,5);
727
728         // ARROW
729
// do the shaft first
730
g.setColor(mainItemColor);
731         g.fillRect(iconSize-7,3, 3,5); // do a big block
732
g.drawLine(iconSize-6,5, iconSize-3,2); // top shaft
733
g.drawLine(iconSize-6,6, iconSize-2,2); // bottom shaft
734
g.drawLine(iconSize-6,7, iconSize-3,7); // bottom arrow head
735

736         // draw the dark highlight
737
g.setColor(darkHighlightColor);
738         g.drawLine(iconSize-8,2, iconSize-7,2); // top of arrowhead
739
g.drawLine(iconSize-8,3, iconSize-8,7); // left of arrowhead
740
g.drawLine(iconSize-6,4, iconSize-3,1); // top of shaft
741
g.drawLine(iconSize-4,6, iconSize-3,6); // top,right of arrowhead
742

743         // draw the light highlight
744
g.setColor(lrLightHighlightColor);
745         g.drawLine(iconSize-6,3, iconSize-6,3); // top
746
g.drawLine(iconSize-4,5, iconSize-2,3); // under shaft
747
g.drawLine(iconSize-4,8, iconSize-3,8); // under arrowhead
748
g.drawLine(iconSize-2,8, iconSize-2,7); // right of arrowhead
749

750         g.translate(-x, -y);
751     }
752     
753     public int getIconWidth() {
754         return iconSize;
755     }
756     
757     public int getIconHeight() {
758         return iconSize;
759     }
760     } // End class InternalFrameAltMaximizeIcon
761

762     // Code for the default icons that goes in the upper left corner
763
private static class InternalFrameDefaultMenuIcon implements Icon, UIResource JavaDoc, Serializable JavaDoc {
764         public void paintIcon(Component c, Graphics g, int x, int y) {
765
766         Color windowBodyColor = MetalLookAndFeel.getWindowBackground();
767         Color titleColor = MetalLookAndFeel.getPrimaryControl();
768         Color edgeColor = MetalLookAndFeel.getPrimaryControlDarkShadow();
769
770         g.translate(x, y);
771
772         // draw background color for title area
773
// catch four corners and title area
774
g.setColor(titleColor);
775         g.fillRect(0,0, 16,16);
776
777         // fill body of window
778
g.setColor(windowBodyColor);
779         g.fillRect(2,6, 13,9);
780         // draw light parts of two "bumps"
781
g.drawLine(2,2, 2,2);
782         g.drawLine(5,2, 5,2);
783         g.drawLine(8,2, 8,2);
784         g.drawLine(11,2, 11,2);
785         
786         // draw line around edge of title and icon
787
g.setColor(edgeColor);
788         g.drawRect(1,1, 13,13); // entire inner edge
789
g.drawLine(1,0, 14,0); // top outter edge
790
g.drawLine(15,1, 15,14); // right outter edge
791
g.drawLine(1,15, 14,15); // bottom outter edge
792
g.drawLine(0,1, 0,14); // left outter edge
793
g.drawLine(2,5, 13,5); // bottom of title bar area
794
// draw dark part of four "bumps" (same color)
795
g.drawLine(3,3, 3,3);
796         g.drawLine(6,3, 6,3);
797         g.drawLine(9,3, 9,3);
798         g.drawLine(12,3, 12,3);
799
800         g.translate(-x, -y);
801     }
802     
803     public int getIconWidth() {
804         return 16;
805     }
806     
807     public int getIconHeight() {
808         return 16;
809     }
810     } // End class InternalFrameDefaultMenuIcon
811

812     // Internal Frame Maximize code
813
private static class InternalFrameMaximizeIcon implements Icon, UIResource JavaDoc, Serializable JavaDoc {
814     protected int iconSize = 16;
815
816         public InternalFrameMaximizeIcon(int size) {
817         iconSize = size;
818     }
819
820         public void paintIcon(Component c, Graphics g, int x, int y) {
821         JButton parentButton = (JButton)c;
822         ButtonModel buttonModel = parentButton.getModel();
823
824         Color backgroundColor = MetalLookAndFeel.getPrimaryControl();
825         Color internalBackgroundColor =
826         MetalLookAndFeel.getPrimaryControl();
827         Color mainItemColor =
828         MetalLookAndFeel.getPrimaryControlDarkShadow();
829         Color darkHighlightColor = MetalLookAndFeel.getBlack();
830         // ul = Upper Left and lr = Lower Right
831
Color ulLightHighlightColor = MetalLookAndFeel.getWhite();
832         Color lrLightHighlightColor = MetalLookAndFeel.getWhite();
833         
834         // if the internal frame is inactive
835
if (parentButton.getClientProperty("paintActive") != Boolean.TRUE)
836         {
837         backgroundColor = MetalLookAndFeel.getControl();
838         internalBackgroundColor = backgroundColor;
839         mainItemColor = MetalLookAndFeel.getControlDarkShadow();
840         // if inactive and pressed
841
if (buttonModel.isPressed() && buttonModel.isArmed()) {
842             internalBackgroundColor =
843