Esempio n. 1
0
  public ToolButton(PaletteListener listener, String iconName, String name, Tool tool) {
    super(listener);
    tool.addToolListener(this);
    setEnabled(tool.isUsable());

    // use a Mediatracker to ensure that all the images are initially loaded
    Iconkit kit = Iconkit.instance();
    if (kit == null) {
      throw new JHotDrawRuntimeException("Iconkit instance isn't set");
    }

    Image im[] = new Image[3];
    im[0] = kit.loadImageResource(iconName + "1.gif");
    im[1] = kit.loadImageResource(iconName + "2.gif");
    im[2] = kit.loadImageResource(iconName + "3.gif");

    MediaTracker tracker = new MediaTracker(this);
    for (int i = 0; i < 3; i++) {
      tracker.addImage(im[i], i);
    }
    try {
      tracker.waitForAll();
    } catch (Exception e) {
      // ignore exception
    }

    fIcon = new PaletteIcon(new Dimension(24, 24), im[0], im[1], im[2]);
    fTool = tool;
    fName = name;

    setIcon(new ImageIcon(im[0]));
    setPressedIcon(new ImageIcon(im[1]));
    setSelectedIcon(new ImageIcon(im[2]));
    setToolTipText(name);
  }
 protected void setTracker(Tool newTracker) {
   if (tracker != null) {
     tracker.deactivate(getEditor());
     tracker.removeToolListener(this);
   }
   tracker = newTracker;
   if (tracker != null) {
     tracker.activate(getEditor());
     tracker.addToolListener(this);
   }
 }
  public void toolDone(ToolEvent event) {
    // Empty
    Tool newTracker = getSelectAreaTracker();

    if (newTracker != null) {
      if (tracker != null) {
        tracker.deactivate(getEditor());
        tracker.removeToolListener(this);
      }
      tracker = newTracker;
      tracker.activate(getEditor());
      tracker.addToolListener(this);
    }
    fireToolDone();
  }
 /** Creates a new instance. */
 public SelectionTool() {
   tracker = getSelectAreaTracker();
   tracker.addToolListener(this);
 }