Source code: com/flexstor/common/gui/browse/BrowseDefaultImages.java
1 /*
2 * BrowseDefaultImages.java
3 *
4 * Copyright $Date: 2003/08/11 02:22:48 $ FLEXSTOR.net Inc.
5 *
6 * This work is licensed for use and distribution under license terms found at
7 * http://www.flexstor.org/license.html
8 *
9 */
10
11 package com.flexstor.common.gui.browse;
12
13 import java.awt.Image;
14 import java.awt.MediaTracker;
15 import java.awt.Panel;
16 import java.util.Hashtable;
17
18 import com.flexstor.common.awt.AWTUtil;
19 import com.flexstor.common.awt.image.ImageGenerator;
20
21 public class BrowseDefaultImages
22 {
23 private static Hashtable htColors = null;
24 private static Panel pnlDummy = new Panel();
25
26 private static void setColors()
27 {
28 if ( htColors == null )
29 {
30 htColors = new Hashtable();
31 htColors.put( " ", ImageGenerator.prepColor( 0, 0, 0, 0 ) ); // transparent
32 htColors.put( "W", ImageGenerator.prepColor( 255, 255, 255, 255 ) ); // white
33 htColors.put( "B", ImageGenerator.prepColor( 0, 0, 0, 255 ) ); // black
34 htColors.put( "D", ImageGenerator.prepColor( 128, 128, 128, 255 ) ); // dark gray
35 htColors.put( "Y", ImageGenerator.prepColor( 255, 255, 0, 220 ) ); // yellow
36 }
37 }
38
39
40 private static Image getImage( String sName, String[] saImageData )
41 {
42 Image i = AWTUtil.checkImage( sName );
43
44 if ( i == null )
45 {
46 i = ImageGenerator.generateImage( htColors, saImageData );
47
48 MediaTracker mt = new MediaTracker( pnlDummy );
49 mt.addImage( i, 1 );
50
51 try
52 {
53 mt.waitForID( 1 );
54 AWTUtil.addImage( sName, i );
55 }
56 catch ( InterruptedException e )
57 {
58 }
59 finally
60 {
61 if ( mt.isErrorAny() )
62 i = null;
63 }
64 }
65
66 return i;
67 }
68
69 public static Image getFileImage()
70 {
71 setColors();
72
73 String saImageData[] = {
74 " BBBBBBBB ",
75 " BWWWWWBDB ",
76 " BWWWWWBDDB ",
77 " BWWWWWBDDDB ",
78 " BWWWWWBBBBB ",
79 " BWWWWWWWWWB ",
80 " BWWWWWWWWWB ",
81 " BWWWWWWWWWB ",
82 " BWWWWWWWWWB ",
83 " BWWWWWWWWWB ",
84 " BWWWWWWWWWB ",
85 " BWWWWWWWWWB ",
86 " BBBBBBBBBBB ",
87 };
88
89 return getImage( "BrowseDefault:File", saImageData );
90 }
91
92 } // end of class