1  /*
  2   *  File:  SystemColors.java
  3   *
  4   *  Display the colors used by the system
  5   *
  6   *  Copyright:  Northeast Parallel Architectures Center
  7   *  
  8   */
  9  
 10  import java.applet.Applet;
 11  import java.awt.Graphics;
 12  import java.awt.Font;
 13  import java.awt.FontMetrics;
 14  import java.awt.Color;
 15  import java.awt.SystemColor;
 16  import java.util.Hashtable;
 17  import java.util.Enumeration;
 18  
 19  public class SystemColors extends Applet {
 20  
 21     // size of each color swatch:
 22     private final int swatchSize = 70;
 23     // whitespace around each color swatch:
 24     private final int border = 15;
 25     // total size, including whitespace:
 26     private final int unitSize = swatchSize + 2*border;
 27     // number of color swatches per row:
 28     private final int cols = 4;
 29  
 30     // A hashtable of colors:
 31     private Hashtable colors = new Hashtable();
 32     
 33     // Put the system colors in the hashtable:
 34     public void init() {
 35        colors.put( "desktop", SystemColor.desktop );
 36        colors.put( "activeCaption", SystemColor.activeCaption );
 37        colors.put( "activeCaptionText", SystemColor.activeCaptionText );
 38        colors.put( "activeCaptionBorder", SystemColor.activeCaptionBorder );
 39        colors.put( "inactiveCaption", SystemColor.inactiveCaption );
 40        colors.put( "inactiveCaptionText", SystemColor.inactiveCaptionText );
 41        colors.put( "inactiveCaptionBorder", SystemColor.inactiveCaptionBorder );
 42        colors.put( "window", SystemColor.window );
 43        colors.put( "windowBorder", SystemColor.windowBorder );
 44        colors.put( "windowText", SystemColor.windowText );
 45        colors.put( "menu", SystemColor.menu );
 46        colors.put( "menuText", SystemColor.menuText );
 47        colors.put( "text", SystemColor.text );
 48        colors.put( "textText", SystemColor.textText );
 49        colors.put( "textHighlight", SystemColor.textHighlight );
 50        colors.put( "textHighlightText", SystemColor.textHighlightText );
 51        colors.put( "textInactiveText", SystemColor.textInactiveText );
 52        colors.put( "control", SystemColor.control );
 53        colors.put( "controlText", SystemColor.controlText );
 54        colors.put( "controlHighlight", SystemColor.controlHighlight );
 55        colors.put( "controlLtHighlight", SystemColor.controlLtHighlight );
 56        colors.put( "controlShadow", SystemColor.controlShadow );
 57        colors.put( "controlDkShadow", SystemColor.controlDkShadow );
 58        colors.put( "scrollbar", SystemColor.scrollbar );
 59        colors.put( "info", SystemColor.info );
 60        colors.put( "infoText", SystemColor.infoText );
 61     }
 62     
 63     public void paint( Graphics g ) {
 64        
 65        // local variables:
 66        int x, y;
 67        Color color;
 68        String colorstring;
 69  
 70        g.setFont( new Font( "SansSerif", Font.PLAIN, 9 ) );
 71        
 72        // vertical adjustment for color labels:
 73        int descender = g.getFontMetrics().getDescent();
 74        
 75        // an enumeration of keys in the hashtable:
 76        Enumeration colorstrings = colors.keys();
 77        
 78        // Display rows of color boxes:
 79        int rows = ( int ) Math.ceil( ( double ) colors.size()/cols );
 80        for ( int i = 0; i < rows; i++ ) {
 81           y = border + unitSize*i;
 82           for ( int j = 0; j < cols; j++ ) {
 83              if ( !colorstrings.hasMoreElements() ) break;
 84              colorstring = ( String ) colorstrings.nextElement();
 85              color = ( Color ) colors.get( colorstring );
 86              x = border + unitSize*j;
 87              g.setColor( color );
 88              g.fillRect( x, y, swatchSize, swatchSize );
 89              g.setColor( Color.black );
 90              g.drawString( colorstring, x, y - descender );
 91           }
 92        }
 93        
 94     }
 95  
 96  }
 97