Back to index

moin  1.9.0~rc2
ToolButton.java
Go to the documentation of this file.
00001 /*
00002  * @(#)ToolButton.java 5.1
00003  *
00004  */
00005 
00006 package CH.ifa.draw.standard;
00007 
00008 import java.awt.*;
00009 import CH.ifa.draw.util.*;
00010 import CH.ifa.draw.framework.*;
00011 
00016 public class ToolButton extends PaletteButton {
00017 
00018     private String          fName;
00019     private Tool            fTool;
00020     private PaletteIcon     fIcon;
00021 
00022     public ToolButton(PaletteListener listener, String iconName, String name, Tool tool) {
00023         super(listener);
00024         // use a Mediatracker to ensure that all the images are initially loaded
00025         Iconkit kit = Iconkit.instance();
00026         if (kit == null)
00027             throw new HJDError("Iconkit instance isn't set");
00028 
00029         Image im[] = new Image[3];
00030 
00031         im[0] = kit.loadImageResource(iconName+"1.gif");
00032         im[1] = kit.loadImageResource(iconName+"2.gif");
00033         im[2] = kit.loadImageResource(iconName+"3.gif");
00034 
00035         MediaTracker tracker = new MediaTracker(this);
00036         for (int i = 0; i < 3; i++) {
00037             tracker.addImage(im[i], i);
00038         }
00039         try {
00040             tracker.waitForAll();
00041         } catch (Exception e) { 
00042            e.printStackTrace();
00043            throw new RuntimeException("Bugger " + e.getMessage() + " " + iconName);
00044        }
00045 
00046         fIcon = new PaletteIcon(new Dimension(24,24), im[0], im[1], im[2]);
00047         fTool = tool;
00048         fName = name;
00049     }
00050 
00051     public Tool tool() {
00052         return fTool;
00053     }
00054 
00055     public String name() {
00056         return fName;
00057     }
00058 
00059     public Object attributeValue() {
00060         return tool();
00061     }
00062 
00063     public Dimension getMinimumSize() {
00064         return new Dimension(fIcon.getWidth(), fIcon.getHeight());
00065     }
00066 
00067     public Dimension getPreferredSize() {
00068         return new Dimension(fIcon.getWidth(), fIcon.getHeight());
00069     }
00070 
00071     public void paintBackground(Graphics g) { }
00072 
00073     public void paintNormal(Graphics g) {
00074         if (fIcon.normal() != null)
00075             g.drawImage(fIcon.normal(), 0, 0, this);
00076     }
00077 
00078     public void paintPressed(Graphics g) {
00079         if (fIcon.pressed() != null)
00080             g.drawImage(fIcon.pressed(), 0, 0, this);
00081     }
00082 
00083     public void paintSelected(Graphics g) {
00084         if (fIcon.selected() != null)
00085             g.drawImage(fIcon.selected(), 0, 0, this);
00086     }
00087 
00088 }
00089