Exemplo n.º 1
0
  /**
   * Adds color buttons to the specified panel.
   *
   * <p>This method will create a row containing the following items:
   *
   * <pre>
   * LABEL | COLOR (foreground) | COLOR (background)
   * </pre>
   *
   * @param gridPanel a 3 columns proportinal grid panel in which to add the buttons.
   * @param fontChooser used to decide which font to use in each color button's preview.
   * @param label label for the row.
   * @param foregroundId identifier of the color to display in the foreground button.
   * @param backgroundId identifier of the color to display in the background button.
   * @param comp component to register as a listener on the color buttons.
   */
  protected PreviewLabel addColorButtons(
      ProportionalGridPanel gridPanel,
      FontChooser fontChooser,
      String label,
      int foregroundId,
      int backgroundId,
      JComponent comp) {
    ColorButton colorButton;
    PreviewLabel previewLabel;

    // Adds the row's caption label.
    gridPanel.add(createCaptionLabel(label));

    // Initialises the color buttons' preview label.
    previewLabel = new PreviewLabel();
    previewLabel.setTextPainted(true);
    addFontChooserListener(fontChooser, previewLabel);

    // Creates the foreground color button.
    gridPanel.add(
        colorButton =
            new ColorButton(
                parent,
                themeData,
                foregroundId,
                PreviewLabel.FOREGROUND_COLOR_PROPERTY_NAME,
                previewLabel));
    if (comp != null) colorButton.addUpdatedPreviewComponent(comp);

    // Creates the background color button.
    gridPanel.add(
        colorButton =
            new ColorButton(
                parent,
                themeData,
                backgroundId,
                PreviewLabel.BACKGROUND_COLOR_PROPERTY_NAME,
                previewLabel));
    if (comp != null) colorButton.addUpdatedPreviewComponent(comp);

    return previewLabel;
  }