@Override
  public void buttonClicked(JButton button)
  {
    if (button == cancel)
    {
      for (PieceSelection ps : types)
        ps.isSelected = true;
      
      onlyLockedLayer.setSelected(false);
      
      setVisible(false);
    }
    else if (button == execute)
    {
      Set<PieceType> set = new HashSet<PieceType>();
      for (PieceSelection ps : types)
        if (ps.isSelected && ps.type != null)
          set.add(ps.type);
      
      if (set.isEmpty())
      {
        Dialogs.showErrorDialog(ReplaceColorFrame.this, "Error", "You must select at least one piece type.");
        return;
      }
      else if (fromColor.getSelectedItem() == toColor.getSelectedItem())
      {
        Dialogs.showErrorDialog(ReplaceColorFrame.this, "Error", "Source and destination color must be different.");
        return;
      }
      
      Task task = null;
      
      if (onlyLockedLayer.isSelected())
        task = new ModelOperations.ReplaceColor(model, Main.sketch.levelStackView.getLocked(), (PieceColor)fromColor.getSelectedItem(), (PieceColor)toColor.getSelectedItem(), set);
      else
        task = new ModelOperations.ReplaceColor(model, (PieceColor)fromColor.getSelectedItem(), (PieceColor)toColor.getSelectedItem(), set);
      
      task.execute();
      Main.sketch.redraw();
      setVisible(false);
    }
  }