public void setColor(int color, IndexColorModel model) {
    this.color = color;
    cm = model;

    chooser.setColors(model);
    chooser.setCurrentColor(color);

    if (chooser.isVisible()) {
      chooser.repaint();
    }
    this.repaint();
  }
  public void mouseClicked(MouseEvent e) {
    if (cm != null) {
      if (cm.getMapSize() == 2 && e.getClickCount() == 1) {
        // invert color
        color = (color == 1) ? 0 : 1;
        chooser.setCurrentColor(color);
        mainWindow.setActiveEditorColor(color);

        if (chooser.isVisible()) {
          chooser.repaint();
        }
        this.repaint();
      } else if (e.getClickCount() % 2 == 0) {
        chooser.setVisible(true);
      }
    }
  }