Chooser Icons

  • Abstract class ChooserIcon can't itself be instantiated.
  • Static final members extend it.
  • A common ancestor ensures that all icons are the same size.
  • Coding icons by hand removes dependencies and ensures cross-platform consistency.
Interface
Icon
+ getIconHeight() : int
+ getIconWidth() : int
+ paintIcon(Component, Graphics, int, int)
ChooserIcon
DIR_ICON : Icon
FILE_ICON : Icon
UP_FOLDER_ICON : Icon
ChooserIcon()
+ getIconHeight() : int
+ getIconWidth() : int
+ paintIcon(Component, Graphics, int, int)

Warning: graphically challenged individuals should not attempt to code icons by hand.

abstract class ChooserIcon implements Icon {
    static final Icon DIR_ICON       = new DirIcon();
    static final Icon FILE_ICON      = new FileIcon();
    static final Icon UP_FOLDER_ICON = new UpFldIcon();

    public int getIconWidth()  { return 16; }
    public int getIconHeight() { return 16; }

    private static class DirIcon extends ChooserIcon {
        public void paintIcon(Component c, Graphics g, 
                                           int x, int y) {
            g.translate(x, y);

            // folder main, tab
            g.setColor(new Color(247, 241, 136));
            g.fillRect(2, 4, 12, 7);
            g.drawLine(2, 1, 5, 1);

            // folder outline
            g.setColor(new Color(207, 198, 14));
            g.drawLine(0, 2, 13, 2);
            g.drawLine(0, 2, 0, 11);
            g.drawLine(0, 11, 13, 11);
            g.drawLine(0, 2, 2, 0);
            g.drawLine(2, 0, 5, 0);

            // more...

            g.translate(-x, -y);
        }
    }

    private static class FileIcon extends ChooserIcon {
        public void paintIcon(Component c, Graphics g,  
                                           int x, int y) {
            ...
        }
    }

    private static class UpFldIcon extends ChooserIcon {
        public void paintIcon(Component c, Graphics g,  
                                           int x, int y) {
            ...
        }
    }
}