/**
   * Construct a new button that can be used to toggle between black and white.
   *
   * @param appState Reference to the model, used to change drawing colour.
   * @param identifier Identifier for this object.
   */
  public ToggleColourButton(ApplicationState appState, String identifier) {
    super();
    this.as = appState;
    this.identifier = identifier;
    this.fgCol = Colour.BLACK;
    this.bgCol = Colour.WHITE;

    addPressHandler(this);

    // Set class of button element
    setStyleName(STYLENAME);

    // Create element that shows foreground colour, set it up and add it
    fgColEl = DivElement.as(DOM.createElement("div"));
    fgColEl.setPropertyString("className", STYLENAME_FG_EL);
    fgColEl.getStyle().setBackgroundColor(fgCol.toString());
    getElement().appendChild(fgColEl);

    // Create element that shows background colour, set it up and add it
    bgColEl = DivElement.as(DOM.createElement("div"));
    bgColEl.setPropertyString("className", STYLENAME_BG_EL);
    bgColEl.getStyle().setBackgroundColor(bgCol.toString());
    getElement().appendChild(bgColEl);

    // Set the debug ID for the toggle colour button.
    ensureDebugId("toggleColor");
  }
  /**
   * Set the background colour properties for the foreground and background elements (using the
   * global {@link #fgCol} and {@link #bgCol}).
   *
   * @param updateWhat A constant to indicate if only the foreground colour, only the background
   *     colour or both should be updated.
   */
  protected void update(int updateWhat) {
    boolean updateBg = (updateWhat == UPDATE_BOTH || updateWhat == UPDATE_BG);
    boolean updateFg = (updateWhat == UPDATE_BOTH || updateWhat == UPDATE_FG);

    if (updateFg) {
      fgColEl.getStyle().setBackgroundColor(fgCol.toString());
    }
    if (updateBg) {
      bgColEl.getStyle().setBackgroundColor(bgCol.toString());
    }

    // There are two ToggleColourButtons, update both
    if (identifier.equals(TOGGLE_COLOUR)) {
      if (updateFg && !GuiState.toolMenuToggleColour.fgCol.equals(fgCol)) {
        GuiState.toolMenuToggleColour.setForegroundColour(fgCol);
      }
      if (updateBg && !GuiState.toolMenuToggleColour.bgCol.equals(bgCol)) {
        GuiState.toolMenuToggleColour.setBackgroundColour(bgCol);
      }
    } else {
      if (updateFg && !GuiState.toggleColour.fgCol.equals(fgCol)) {
        GuiState.toggleColour.setForegroundColour(fgCol);
      }
      if (updateBg && !GuiState.toggleColour.bgCol.equals(bgCol)) {
        GuiState.toggleColour.setBackgroundColour(bgCol);
      }
    }

    // Update the colours of the drawing tool buttons
    GuiState.squareDrawingTool.setColour(fgCol);
    GuiState.circleDrawingTool.setColour(fgCol);
  }