|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +package com.jfoenix.controls; |
| 21 | + |
| 22 | +import com.jfoenix.skins.JFXColorPickerSkin; |
| 23 | +import javafx.css.CssMetaData; |
| 24 | +import javafx.css.SimpleStyleableBooleanProperty; |
| 25 | +import javafx.css.Styleable; |
| 26 | +import javafx.css.StyleableBooleanProperty; |
| 27 | +import javafx.css.converter.BooleanConverter; |
| 28 | +import javafx.scene.control.ColorPicker; |
| 29 | +import javafx.scene.control.Skin; |
| 30 | +import javafx.scene.paint.Color; |
| 31 | + |
| 32 | +import java.util.ArrayList; |
| 33 | +import java.util.Collections; |
| 34 | +import java.util.List; |
| 35 | + |
| 36 | +/** |
| 37 | + * JFXColorPicker is the metrial design implementation of color picker. |
| 38 | + * |
| 39 | + * @author Shadi Shaheen |
| 40 | + * @version 1.0 |
| 41 | + * @since 2016-03-09 |
| 42 | + */ |
| 43 | +public class JFXColorPicker extends ColorPicker { |
| 44 | + |
| 45 | + /** |
| 46 | + * {@inheritDoc} |
| 47 | + */ |
| 48 | + public JFXColorPicker() { |
| 49 | + initialize(); |
| 50 | + } |
| 51 | + |
| 52 | + /** |
| 53 | + * {@inheritDoc} |
| 54 | + */ |
| 55 | + public JFXColorPicker(Color color) { |
| 56 | + super(color); |
| 57 | + initialize(); |
| 58 | + } |
| 59 | + |
| 60 | + /** |
| 61 | + * {@inheritDoc} |
| 62 | + */ |
| 63 | + @Override |
| 64 | + protected Skin<?> createDefaultSkin() { |
| 65 | + return new JFXColorPickerSkin(this); |
| 66 | + } |
| 67 | + |
| 68 | + private void initialize() { |
| 69 | + this.getStyleClass().add(DEFAULT_STYLE_CLASS); |
| 70 | + } |
| 71 | + |
| 72 | + /** |
| 73 | + * Initialize the style class to 'jfx-color-picker'. |
| 74 | + * <p> |
| 75 | + * This is the selector class from which CSS can be used to style |
| 76 | + * this control. |
| 77 | + */ |
| 78 | + private static final String DEFAULT_STYLE_CLASS = "jfx-color-picker"; |
| 79 | + |
| 80 | + private double[] preDefinedColors = null; |
| 81 | + |
| 82 | + public double[] getPreDefinedColors() { |
| 83 | + return preDefinedColors; |
| 84 | + } |
| 85 | + |
| 86 | + public void setPreDefinedColors(double[] preDefinedColors) { |
| 87 | + this.preDefinedColors = preDefinedColors; |
| 88 | + } |
| 89 | + |
| 90 | + /** |
| 91 | + * disable animation on button action |
| 92 | + */ |
| 93 | + private final StyleableBooleanProperty disableAnimation = new SimpleStyleableBooleanProperty(StyleableProperties.DISABLE_ANIMATION, |
| 94 | + JFXColorPicker.this, |
| 95 | + "disableAnimation", |
| 96 | + false); |
| 97 | + |
| 98 | + public final StyleableBooleanProperty disableAnimationProperty() { |
| 99 | + return this.disableAnimation; |
| 100 | + } |
| 101 | + |
| 102 | + public final Boolean isDisableAnimation() { |
| 103 | + return disableAnimation != null && this.disableAnimationProperty().get(); |
| 104 | + } |
| 105 | + |
| 106 | + public final void setDisableAnimation(final Boolean disabled) { |
| 107 | + this.disableAnimationProperty().set(disabled); |
| 108 | + } |
| 109 | + |
| 110 | + private static final class StyleableProperties { |
| 111 | + |
| 112 | + private static final CssMetaData<JFXColorPicker, Boolean> DISABLE_ANIMATION = |
| 113 | + new CssMetaData<JFXColorPicker, Boolean>("-jfx-disable-animation", |
| 114 | + BooleanConverter.getInstance(), false) { |
| 115 | + @Override |
| 116 | + public boolean isSettable(JFXColorPicker control) { |
| 117 | + return control.disableAnimation == null || !control.disableAnimation.isBound(); |
| 118 | + } |
| 119 | + |
| 120 | + @Override |
| 121 | + public StyleableBooleanProperty getStyleableProperty(JFXColorPicker control) { |
| 122 | + return control.disableAnimationProperty(); |
| 123 | + } |
| 124 | + }; |
| 125 | + |
| 126 | + |
| 127 | + private static final List<CssMetaData<? extends Styleable, ?>> CHILD_STYLEABLES; |
| 128 | + |
| 129 | + static { |
| 130 | + final List<CssMetaData<? extends Styleable, ?>> styleables = |
| 131 | + new ArrayList<>(ColorPicker.getClassCssMetaData()); |
| 132 | + Collections.addAll(styleables, DISABLE_ANIMATION); |
| 133 | + CHILD_STYLEABLES = Collections.unmodifiableList(styleables); |
| 134 | + } |
| 135 | + } |
| 136 | + |
| 137 | + @Override |
| 138 | + public List<CssMetaData<? extends Styleable, ?>> getControlCssMetaData() { |
| 139 | + return getClassCssMetaData(); |
| 140 | + } |
| 141 | + |
| 142 | + public static List<CssMetaData<? extends Styleable, ?>> getClassCssMetaData() { |
| 143 | + return StyleableProperties.CHILD_STYLEABLES; |
| 144 | + } |
| 145 | +} |
0 commit comments