Spec-Zone .ru
спецификации, руководства, описания, API
|
001/* 002 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 004 * 005 * This code is free software; you can redistribute it and/or modify it 006 * under the terms of the GNU General Public License version 2 only, as 007 * published by the Free Software Foundation. Oracle designates this 008 * particular file as subject to the "Classpath" exception as provided 009 * by Oracle in the LICENSE file that accompanied this code. 010 * 011 * This code is distributed in the hope that it will be useful, but WITHOUT 012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 014 * version 2 for more details (a copy is included in the LICENSE file that 015 * accompanied this code). 016 * 017 * You should have received a copy of the GNU General Public License version 018 * 2 along with this work; if not, write to the Free Software Foundation, 019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 020 * 021 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 022 * or visit www.oracle.com if you need additional information or have any 023 * questions. 024 */ 025 026package javafx.scene.control; 027 028import javafx.collections.FXCollections; 029import javafx.collections.ObservableList; 030import javafx.scene.paint.Color; 031import com.sun.javafx.scene.control.skin.ColorPickerSkin; 032 033/** 034 * <p>ColorPicker control allows the user to select a color from either a standard 035 * palette of colors with a simple one click selection OR define their own custom color. 036 * 037 * <p>The {@link #valueProperty() value} is the currently selected {@link javafx.scene.paint.Color}. 038 * An initial color can be set by calling setColor or via the constructor. If nothing 039 * is specified, a default initial color is used. 040 * 041 * <p>The ColorPicker control provides a color palette with a predefined set of colors. If 042 * the user does not want to choose from the predefined set, they can create a custom 043 * color by interacting with a custom color dialog. This dialog provides RGB, 044 * HSB and Web modes of interaction, to create new colors. It also lets the opacity 045 * of the color to be modified. 046 * 047 * <p>Once a new color is defined, users can choose whether they want to save it 048 * or just use it. If the new color is saved, this color will then appear in the 049 * custom colors area on the color palette. Also {@link #getCustomColors() getCustomColors} 050 * returns the list of saved custom colors. 051 * 052 * <p>The {@link #promptTextProperty() promptText} is not supported and hence is a no-op. 053 * But it may be supported in the future. 054 * 055 * <pre><code> 056 * final ColorPicker colorPicker = new ColorPicker(); 057 * colorPicker.setOnAction(new EventHandler() { 058 * public void handle(Event t) { 059 * Color c = colorPicker.getValue(); 060 * System.out.println("New Color's RGB = "+c.getRed()+" "+c.getGreen()+" "+c.getBlue()); 061 * } 062 * }); 063 * </code></pre> 064 * 065 * <p>The ColorPicker control's appearance can be styled in three ways: a simple Button mode, 066 * MenuButton mode or SplitMenuButton mode. The default is MenuButton mode. 067 * For a Button like appearance the style class to use is {@link #STYLE_CLASS_BUTTON STYLE_CLASS_BUTTON} 068 * and for SplitMenuButton appearance and behavior, the style class to use is 069 * {@link #STYLE_CLASS_SPLIT_BUTTON STYLE_CLASS_SPLIT_BUTTON}. 070 * 071 * <pre><code> 072 * colorPicker.getStyleClass().add("button"); 073 * </code></pre> 074 * or 075 * <pre><code> 076 * colorPicker.getStyleClass().add("split-button"); 077 * </pre><code> 078 * @since 2.2 079 */ 080public class ColorPicker extends ComboBoxBase<Color> { 081 082 /** 083 * The style class to specify a Button like appearance of ColorPicker control. 084 */ 085 public static final String STYLE_CLASS_BUTTON = "button"; 086 087 /** 088 * The style class to specify a SplitMenuButton like appearance of ColorPicker control. 089 */ 090 public static final String STYLE_CLASS_SPLIT_BUTTON = "split-button"; 091 092 /** 093 * The custom colors added to the Color Palette by the user. 094 */ 095 private ObservableList<Color> customColors = FXCollections.<Color>observableArrayList(); 096 /** 097 * Gets the list of custom colors added to the Color Palette by the user. 098 */ 099 public final ObservableList<Color> getCustomColors() { 100 return customColors; 101 } 102 103 /** 104 * Creates a default ColorPicker instance with a selected color set to white. 105 */ 106 public ColorPicker() { 107 this(Color.WHITE); 108 } 109 110 /** 111 * Creates a ColorPicker instance and sets the selected color to the given color. 112 * @param color to be set as the currently selected color of the ColorPicker. 113 */ 114 public ColorPicker(Color color) { 115 setValue(color); 116 getStyleClass().add(DEFAULT_STYLE_CLASS); 117 } 118 119 @Override void valueInvalidated() { 120 // do nothing - we dont want to fire action event when value changes. 121 } 122 123 /*************************************************************************** 124 * * 125 * Methods * 126 * * 127 **************************************************************************/ 128 129 /** {@inheritDoc} */ 130 @Override protected Skin<?> createDefaultSkin() { 131 return new ColorPickerSkin(this); 132 } 133 134 /*************************************************************************** 135 * * 136 * Stylesheet Handling * 137 * * 138 **************************************************************************/ 139 140 private static final String DEFAULT_STYLE_CLASS = "color-picker"; 141}