Source for javax.swing.plaf.basic.BasicIconFactory

   1: /* BasicIconFactory.java --
   2:    Copyright (C) 2002, 2004  Free Software Foundation, Inc.
   3: 
   4: This file is part of GNU Classpath.
   5: 
   6: GNU Classpath is free software; you can redistribute it and/or modify
   7: it under the terms of the GNU General Public License as published by
   8: the Free Software Foundation; either version 2, or (at your option)
   9: any later version.
  10: 
  11: GNU Classpath is distributed in the hope that it will be useful, but
  12: WITHOUT ANY WARRANTY; without even the implied warranty of
  13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14: General Public License for more details.
  15: 
  16: You should have received a copy of the GNU General Public License
  17: along with GNU Classpath; see the file COPYING.  If not, write to the
  18: Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  19: 02110-1301 USA.
  20: 
  21: Linking this library statically or dynamically with other modules is
  22: making a combined work based on this library.  Thus, the terms and
  23: conditions of the GNU General Public License cover the whole
  24: combination.
  25: 
  26: As a special exception, the copyright holders of this library give you
  27: permission to link this library with independent modules to produce an
  28: executable, regardless of the license terms of these independent
  29: modules, and to copy and distribute the resulting executable under
  30: terms of your choice, provided that you also meet, for each linked
  31: independent module, the terms and conditions of the license of that
  32: module.  An independent module is a module which is not derived from
  33: or based on this library.  If you modify this library, you may extend
  34: this exception to your version of the library, but you are not
  35: obligated to do so.  If you do not wish to do so, delete this
  36: exception statement from your version. */
  37: 
  38: 
  39: package javax.swing.plaf.basic;
  40: 
  41: import java.awt.Color;
  42: import java.awt.Component;
  43: import java.awt.Graphics;
  44: import java.awt.Polygon;
  45: import java.io.Serializable;
  46: 
  47: import javax.swing.AbstractButton;
  48: import javax.swing.Icon;
  49: import javax.swing.UIDefaults;
  50: import javax.swing.UIManager;
  51: 
  52: /**
  53:  * STUBBED
  54:  */
  55: public class BasicIconFactory implements Serializable
  56: {
  57:   static final long serialVersionUID = 5605588811185324383L;
  58: 
  59:   private static class DummyIcon 
  60:     implements Icon
  61:   {    
  62:     public int getIconHeight() { return 10; }
  63:     public int getIconWidth() { return 10; }
  64:     public void paintIcon(Component c, Graphics g, int x, int y)
  65:     {
  66:       Color save = g.getColor();
  67:       g.setColor(c.getForeground());
  68:       g.drawRect(x, y, 10, 10);
  69:       g.setColor(save);
  70:     }
  71:   }
  72: 
  73: 
  74:   public BasicIconFactory()
  75:   {
  76:   }
  77:   public static Icon getMenuItemCheckIcon()
  78:   {
  79:     return new DummyIcon();
  80:   }
  81:   public static Icon getMenuItemArrowIcon()
  82:   {
  83:     return new DummyIcon();
  84:   }
  85:   public static Icon getMenuArrowIcon()
  86:   {
  87:     return new Icon()
  88:       {
  89:     public int getIconHeight()
  90:     {
  91:       return 12;
  92:     }
  93: 
  94:     public int getIconWidth()
  95:     {
  96:       return 12;
  97:     }
  98: 
  99:     public void paintIcon(Component c, Graphics g, int x, int y)
 100:     {
 101:       g.translate(x, y);
 102: 
 103:       Color saved = g.getColor();
 104: 
 105:       g.setColor(Color.BLACK);
 106: 
 107:       g.fillPolygon(new Polygon(new int[] { 3, 9, 3 },
 108:                                   new int[] { 2, 6, 10 },
 109:                                   3));
 110: 
 111:       g.setColor(saved);
 112:       g.translate(-x, -y);
 113:     }
 114:       };
 115:   }
 116: 
 117:   public static Icon getCheckBoxIcon()
 118:   {
 119:     return new Icon()
 120:       {        
 121:         public int getIconHeight() 
 122:         { 
 123:           return 10; 
 124:         }
 125:         public int getIconWidth() 
 126:         { 
 127:           return 10; 
 128:         }
 129:         public void paintIcon(Component c, Graphics g, int x, int y)
 130:         {
 131:           if (c instanceof AbstractButton)
 132:             {
 133:               UIDefaults defaults;
 134:               defaults = UIManager.getLookAndFeelDefaults();
 135:               Color hi = defaults.getColor("CheckBox.highlight");
 136:               Color low = defaults.getColor("CheckBox.darkShadow");
 137:               Color sel = defaults.getColor("CheckBox.foreground");
 138:               Color dim = defaults.getColor("CheckBox.shadow");
 139:               Polygon check = new Polygon(new int[] {x+3, x+3, x+8},
 140:                                           new int[] {y+5, y+9, y+3}, 3);
 141:               AbstractButton b = (AbstractButton) c;
 142:               Color saved = g.getColor();
 143:               if (b.isEnabled())
 144:                 {
 145:                   g.setColor(low);
 146:                   g.drawRect(x, y, 10, 10);
 147:                   g.setColor(hi);
 148:                   g.drawRect(x+1, y+1, 10, 10);
 149:                   if (b.isSelected())
 150:                     {
 151:                       g.setColor(sel);
 152:                       if (b.isSelected())
 153:                         {
 154:                           g.drawLine(x+3, y+5, x+3, y+8);
 155:                           g.drawLine(x+4, y+5, x+4, y+8);
 156:                           g.drawLine(x+3, y+8, x+8, y+3);
 157:                           g.drawLine(x+4, y+8, x+8, y+3);
 158:                         }
 159:                     }
 160:                 }
 161:               else
 162:                 {                  
 163:                   g.setColor(hi);
 164:                   g.drawRect(x, y, 10, 10);
 165:                   if (b.isSelected())
 166:                     {
 167:                       g.drawLine(x+3, y+5, x+3, y+9);
 168:                       g.drawLine(x+3, y+9, x+8, y+3);
 169:                     }
 170:                 }
 171:               g.setColor(saved);
 172:             }
 173:         }
 174:       };
 175:   }
 176: 
 177:   public static Icon getRadioButtonIcon()
 178:   {
 179:     return new Icon()
 180:       {        
 181:         public int getIconHeight() 
 182:         { 
 183:           return 12; 
 184:         }
 185:         public int getIconWidth() 
 186:         { 
 187:           return 12; 
 188:         }
 189:         public void paintIcon(Component c, Graphics g, int x, int y)
 190:         {
 191:           UIDefaults defaults;      
 192:           defaults = UIManager.getLookAndFeelDefaults();
 193:           Color hi = defaults.getColor("RadioButton.highlight");
 194:           Color low = defaults.getColor("RadioButton.darkShadow");
 195:           Color sel = defaults.getColor("RadioButton.foreground");
 196:           Color dim = defaults.getColor("RadioButton.shadow");
 197: 
 198:           if (c instanceof AbstractButton)
 199:             {
 200:               AbstractButton b = (AbstractButton) c;
 201:               Color saved = g.getColor();
 202:               if (b.isEnabled())
 203:                 {
 204:                   g.setColor(low);
 205:                   g.drawOval(x, y, 12, 12);
 206:                   g.setColor(hi);
 207:                   g.drawOval(x+1, y+1, 12, 12);
 208:                   if (b.isSelected())
 209:                     {
 210:                       g.setColor(sel);
 211:                       g.fillOval(x+4, y+4, 6, 6);
 212:                     }
 213:                 }
 214:               else
 215:                 {                  
 216:                   g.setColor(hi);
 217:                   g.drawOval(x, y, 12, 12);
 218:                   if (b.isSelected())
 219:                     g.fillOval(x+4, y+4, 6, 6);
 220:                 }
 221:               g.setColor(saved);
 222:             }
 223:         }
 224:       };
 225:   }
 226:   public static Icon getCheckBoxMenuItemIcon()
 227:   {
 228:     return getCheckBoxIcon();
 229:   }
 230:   public static Icon getRadioButtonMenuItemIcon()
 231:   {
 232:     return getRadioButtonIcon();
 233:   }
 234:   public static Icon createEmptyFrameIcon()
 235:   {
 236:     return new DummyIcon();
 237:   }
 238: } // class BasicIconFactory