Search in sources :

Example 91 with Theme

use of org.apache.pivot.wtk.Theme in project pivot by apache.

the class ColorSchemeBuilderWindow method initialize.

@Override
public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
    Theme theme = Theme.getTheme();
    createColorPalette();
    int numberOfPaletteColors = getNumberOfPaletteColors();
    themeOriginalColors = new ArrayList<>(numberOfPaletteColors);
    for (int i = 0; i < numberOfPaletteColors; i++) {
        final ColorChooserButton colorChooserButton = new ColorChooserButton();
        colorChooserButtons.add(colorChooserButton);
        colorChooserButton.setSelectedColor(Color.BLACK);
        NumericSpinnerData colorSpinnerData = new NumericSpinnerData(0, 255);
        SpinnerItemRenderer colorSpinnerItemRenderer = new SpinnerItemRenderer();
        colorSpinnerItemRenderer.getStyles().put(Style.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(Style.fill, true);
        colorBoxPane.getStyles().put(Style.padding, "{left:4}");
        colorBoxPane.add(redSpinner);
        colorBoxPane.add(greenSpinner);
        colorBoxPane.add(blueSpinner);
        TablePane.Row row = new TablePane.Row(colorChooserTablePane);
        row.add(colorChooserButton);
        row.add(colorBoxPane);
        // 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
                Theme themeLocal = Theme.getTheme();
                int iLocal = colorChooserButtons.indexOf(colorChooserButtonArgument);
                themeLocal.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(Style.backgroundColor, offset + j);
                }
                // Reload the sample part of the content (but not all the application),
                // this means that the rest of the application always show original colors
                reloadContent();
            }
        };
        colorChooserButton.getColorChooserButtonSelectionListeners().add(colorChooserButtonSelectionListener);
        SpinnerSelectionListener spinnerSelectionListener = new SpinnerSelectionListener() {

            @Override
            public void selectedItemChanged(Spinner spinner, Object previousSelectedItem) {
                int red = ((Integer) redSpinner.getSelectedItem()).intValue();
                int green = ((Integer) greenSpinner.getSelectedItem()).intValue();
                int blue = ((Integer) blueSpinner.getSelectedItem()).intValue();
                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
        themeOriginalColors.add(theme.getBaseColor(i));
        colorChooserButton.setSelectedColor(theme.getBaseColor(i));
    }
    copyToClipboardButton.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button button) {
            copyToClipboard();
        }
    });
    resetPaletteButton.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button button) {
            resetPalette();
        }
    });
    // Initialize content
    reloadContent();
}
Also used : SpinnerItemRenderer(org.apache.pivot.wtk.content.SpinnerItemRenderer) Spinner(org.apache.pivot.wtk.Spinner) Color(java.awt.Color) SpinnerSelectionListener(org.apache.pivot.wtk.SpinnerSelectionListener) NumericSpinnerData(org.apache.pivot.wtk.content.NumericSpinnerData) ButtonPressListener(org.apache.pivot.wtk.ButtonPressListener) ColorChooserButtonSelectionListener(org.apache.pivot.wtk.ColorChooserButtonSelectionListener) ColorChooserButton(org.apache.pivot.wtk.ColorChooserButton) BoxPane(org.apache.pivot.wtk.BoxPane) ColorChooserButton(org.apache.pivot.wtk.ColorChooserButton) PushButton(org.apache.pivot.wtk.PushButton) Button(org.apache.pivot.wtk.Button) Theme(org.apache.pivot.wtk.Theme) Component(org.apache.pivot.wtk.Component) TablePane(org.apache.pivot.wtk.TablePane)

Example 92 with Theme

use of org.apache.pivot.wtk.Theme in project pivot by apache.

the class NumberRulerSkin method install.

@Override
public void install(Component component) {
    super.install(component);
    Theme theme = Theme.getTheme();
    setFont(theme.getFont());
    setColor(0);
    setBackgroundColor(19);
    markerSpacing = 5;
    markerInsets = new Insets(0);
    rowPadding = new Insets(0);
    // Note: these aren't settable
    majorDivision = 10;
    minorDivision = 5;
    // But these are
    showMajorNumbers = true;
    showMinorNumbers = false;
    NumberRuler ruler = (NumberRuler) component;
    ruler.getRulerListeners().add(this);
}
Also used : NumberRuler(org.apache.pivot.wtk.NumberRuler) Insets(org.apache.pivot.wtk.Insets) Theme(org.apache.pivot.wtk.Theme)

Example 93 with Theme

use of org.apache.pivot.wtk.Theme in project pivot by apache.

the class TextAreaSkin method install.

@Override
public void install(Component component) {
    super.install(component);
    Theme theme = currentTheme();
    theme.setDefaultStyles(this);
    TextArea textArea = (TextArea) component;
    textArea.getTextAreaListeners().add(this);
    textArea.getTextAreaContentListeners().add(this);
    textArea.getTextAreaSelectionListeners().add(this);
    textArea.setCursor(Cursor.TEXT);
}
Also used : TextArea(org.apache.pivot.wtk.TextArea) Theme(org.apache.pivot.wtk.Theme)

Example 94 with Theme

use of org.apache.pivot.wtk.Theme in project pivot by apache.

the class RulerSkin method setBackgroundColor.

public final void setBackgroundColor(int backgroundColor) {
    Theme theme = currentTheme();
    setBackgroundColor(theme.getColor(backgroundColor));
}
Also used : Theme(org.apache.pivot.wtk.Theme)

Example 95 with Theme

use of org.apache.pivot.wtk.Theme in project pivot by apache.

the class RulerSkin method setColor.

public final void setColor(int color) {
    Theme theme = currentTheme();
    setColor(theme.getColor(color));
}
Also used : Theme(org.apache.pivot.wtk.Theme)

Aggregations

Theme (org.apache.pivot.wtk.Theme)176 Color (java.awt.Color)2 Font (java.awt.Font)2 Border (org.apache.pivot.wtk.Border)2 BoxPane (org.apache.pivot.wtk.BoxPane)2 TablePane (org.apache.pivot.wtk.TablePane)2 GradientPaint (java.awt.GradientPaint)1 Locale (java.util.Locale)1 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)1 Resources (org.apache.pivot.util.Resources)1 Button (org.apache.pivot.wtk.Button)1 ButtonPressListener (org.apache.pivot.wtk.ButtonPressListener)1 ColorChooserButton (org.apache.pivot.wtk.ColorChooserButton)1 ColorChooserButtonSelectionListener (org.apache.pivot.wtk.ColorChooserButtonSelectionListener)1 Component (org.apache.pivot.wtk.Component)1 Expander (org.apache.pivot.wtk.Expander)1 Insets (org.apache.pivot.wtk.Insets)1 Label (org.apache.pivot.wtk.Label)1 NumberRuler (org.apache.pivot.wtk.NumberRuler)1 PushButton (org.apache.pivot.wtk.PushButton)1