NumericSpinnerData colorSpinnerData = new NumericSpinnerData(0, 255);
SpinnerItemRenderer colorSpinnerItemRenderer = new SpinnerItemRenderer();
colorSpinnerItemRenderer.getStyles().put("horizontalAlignment", HorizontalAlignment.RIGHT);
final Spinner redSpinner = new Spinner();
redSpinner.setSpinnerData(colorSpinnerData);
redSpinner.setItemRenderer(colorSpinnerItemRenderer);
redSpinner.setPreferredWidth(40);
redSpinner.setSelectedIndex(0);
final Spinner greenSpinner = new Spinner();
greenSpinner.setSpinnerData(colorSpinnerData);
greenSpinner.setItemRenderer(colorSpinnerItemRenderer);
greenSpinner.setPreferredWidth(40);
greenSpinner.setSelectedIndex(0);
final Spinner blueSpinner = new Spinner();
blueSpinner.setSpinnerData(colorSpinnerData);
blueSpinner.setItemRenderer(colorSpinnerItemRenderer);
blueSpinner.setPreferredWidth(40);
blueSpinner.setSelectedIndex(0);
BoxPane colorBoxPane = new BoxPane();
colorBoxPane.getStyles().put("fill", true);
colorBoxPane.getStyles().put("padding", "{left:4}");
colorBoxPane.add(redSpinner);
colorBoxPane.add(greenSpinner);
colorBoxPane.add(blueSpinner);
TablePane.Row row = new TablePane.Row();
row.add(colorChooserButton);
row.add(colorBoxPane);
colorChooserTablePane.getRows().add(row);
// Add listeners
ColorChooserButtonSelectionListener colorChooserButtonSelectionListener =
new ColorChooserButtonSelectionListener() {
@Override
public void selectedColorChanged(ColorChooserButton colorChooserButtonArgument,
Color previousSelectedColor) {
Color selectedColor = colorChooserButtonArgument.getSelectedColor();
redSpinner.setSelectedItem(selectedColor.getRed());
greenSpinner.setSelectedItem(selectedColor.getGreen());
blueSpinner.setSelectedItem(selectedColor.getBlue());
// Update the theme
TerraTheme terraTheme = (TerraTheme)Theme.getTheme();
int iLocal = colorChooserButtons.indexOf(colorChooserButtonArgument);
terraTheme.setBaseColor(iLocal, colorChooserButtons.get(iLocal).getSelectedColor());
// Update the palette
int offset = iLocal * 3;
for (int j = 0; j < 3; j++) {
Component colorPaletteCell = colorPaletteTablePane.getRows().get(iLocal).get(j);
colorPaletteCell.getStyles().put("backgroundColor", offset + j);
}
reloadContent();
}
};
colorChooserButton.getColorChooserButtonSelectionListeners().add(colorChooserButtonSelectionListener);
SpinnerSelectionListener spinnerSelectionListener = new SpinnerSelectionListener.Adapter() {
@Override
public void selectedItemChanged(Spinner spinner, Object previousSelectedItem) {
int red = (Integer)redSpinner.getSelectedItem();
int green = (Integer)greenSpinner.getSelectedItem();
int blue = (Integer)blueSpinner.getSelectedItem();
colorChooserButton.setSelectedColor(new Color(red, green, blue));
}
};
redSpinner.getSpinnerSelectionListeners().add(spinnerSelectionListener);
greenSpinner.getSpinnerSelectionListeners().add(spinnerSelectionListener);
blueSpinner.getSpinnerSelectionListeners().add(spinnerSelectionListener);
// Initialize the button color with the theme default
TerraTheme terraTheme = (TerraTheme)Theme.getTheme();
themeOriginalColors.add(terraTheme.getBaseColor(i));
colorChooserButton.setSelectedColor(terraTheme.getBaseColor(i));