< prev index next >
src/java.desktop/share/classes/javax/swing/JColorChooser.java
Print this page
*** 36,46 ****
import sun.swing.SwingUtilities2;
/**
! * <code>JColorChooser</code> provides a pane of controls designed to allow
* a user to manipulate and select a color.
* For information about using color choosers, see
* <a
href="http://docs.oracle.com/javase/tutorial/uiswing/components/colorchooser.html">How to Use Color Choosers</a>,
* a section in <em>The Java Tutorial</em>.
--- 36,46 ----
import sun.swing.SwingUtilities2;
/**
! * {@code JColorChooser} provides a pane of controls designed to allow
* a user to manipulate and select a color.
* For information about using color choosers, see
* <a
href="http://docs.oracle.com/javase/tutorial/uiswing/components/colorchooser.html">How to Use Color Choosers</a>,
* a section in <em>The Java Tutorial</em>.
*** 50,63 ****
* This class provides three levels of API:
* <ol>
* <li>A static convenience method which shows a modal color-chooser
* dialog and returns the color selected by the user.
* <li>A static convenience method for creating a color-chooser dialog
! * where <code>ActionListeners</code> can be specified to be invoked when
* the user presses one of the dialog buttons.
! * <li>The ability to create instances of <code>JColorChooser</code> panes
! * directly (within any container). <code>PropertyChange</code> listeners
* can be added to detect when the current "color" property changes.
* </ol>
* <p>
* <strong>Warning:</strong> Swing is not thread safe. For more
* information see <a
--- 50,63 ----
* This class provides three levels of API:
* <ol>
* <li>A static convenience method which shows a modal color-chooser
* dialog and returns the color selected by the user.
* <li>A static convenience method for creating a color-chooser dialog
! * where {@code ActionListeners} can be specified to be invoked when
* the user presses one of the dialog buttons.
! * <li>The ability to create instances of {@code JColorChooser} panes
! * directly (within any container). {@code PropertyChange} listeners
* can be added to detect when the current "color" property changes.
* </ol>
* <p>
* <strong>Warning:</strong> Swing is not thread safe. For more
* information see <a
*** 68,78 ****
* Serialized objects of this class will not be compatible with
* future Swing releases. The current serialization support is
* appropriate for short term storage or RMI between applications running
* the same version of Swing. As of 1.4, support for long term storage
* of all JavaBeans™
! * has been added to the <code>java.beans</code> package.
* Please see {@link java.beans.XMLEncoder}.
*
*
* @beaninfo
* attribute: isContainer false
--- 68,78 ----
* Serialized objects of this class will not be compatible with
* future Swing releases. The current serialization support is
* appropriate for short term storage or RMI between applications running
* the same version of Swing. As of 1.4, support for long term storage
* of all JavaBeans™
! * has been added to the {@code java.beans} package.
* Please see {@link java.beans.XMLEncoder}.
*
*
* @beaninfo
* attribute: isContainer false
*** 121,136 ****
* Shows a modal color-chooser dialog and blocks until the
* dialog is hidden. If the user presses the "OK" button, then
* this method hides/disposes the dialog and returns the selected color.
* If the user presses the "Cancel" button or closes the dialog without
* pressing "OK", then this method hides/disposes the dialog and returns
! * <code>null</code>.
*
! * @param component the parent <code>Component</code> for the dialog
* @param title the String containing the dialog's title
* @param initialColor the initial Color set when the color-chooser is shown
! * @return the selected color or <code>null</code> if the user opted out
* @exception HeadlessException if GraphicsEnvironment.isHeadless()
* returns true.
* @see java.awt.GraphicsEnvironment#isHeadless
*/
public static Color showDialog(Component component,
--- 121,136 ----
* Shows a modal color-chooser dialog and blocks until the
* dialog is hidden. If the user presses the "OK" button, then
* this method hides/disposes the dialog and returns the selected color.
* If the user presses the "Cancel" button or closes the dialog without
* pressing "OK", then this method hides/disposes the dialog and returns
! * {@code null}.
*
! * @param component the parent {@code Component} for the dialog
* @param title the String containing the dialog's title
* @param initialColor the initial Color set when the color-chooser is shown
! * @return the selected color or {@code null} if the user opted out
* @exception HeadlessException if GraphicsEnvironment.isHeadless()
* returns true.
* @see java.awt.GraphicsEnvironment#isHeadless
*/
public static Color showDialog(Component component,
*** 142,159 ****
* Shows a modal color-chooser dialog and blocks until the
* dialog is hidden. If the user presses the "OK" button, then
* this method hides/disposes the dialog and returns the selected color.
* If the user presses the "Cancel" button or closes the dialog without
* pressing "OK", then this method hides/disposes the dialog and returns
! * <code>null</code>.
*
! * @param component the parent <code>Component</code> for the dialog
* @param title the String containing the dialog's title
* @param initialColor the initial Color set when the color-chooser is shown
* @param colorTransparencySelectionEnabled true if the transparency of
* a color can be selected
! * @return the selected color or <code>null</code> if the user opted out
* @exception HeadlessException if GraphicsEnvironment.isHeadless()
* returns true.
* @see java.awt.GraphicsEnvironment#isHeadless
*/
@SuppressWarnings("deprecation")
--- 142,159 ----
* Shows a modal color-chooser dialog and blocks until the
* dialog is hidden. If the user presses the "OK" button, then
* this method hides/disposes the dialog and returns the selected color.
* If the user presses the "Cancel" button or closes the dialog without
* pressing "OK", then this method hides/disposes the dialog and returns
! * {@code null}.
*
! * @param component the parent {@code Component} for the dialog
* @param title the String containing the dialog's title
* @param initialColor the initial Color set when the color-chooser is shown
* @param colorTransparencySelectionEnabled true if the transparency of
* a color can be selected
! * @return the selected color or {@code null} if the user opted out
* @exception HeadlessException if GraphicsEnvironment.isHeadless()
* returns true.
* @see java.awt.GraphicsEnvironment#isHeadless
*/
@SuppressWarnings("deprecation")
*** 179,193 ****
return ok.getColor();
}
/**
* Creates and returns a new dialog containing the specified
! * <code>ColorChooser</code> pane along with "OK", "Cancel", and "Reset"
* buttons. If the "OK" or "Cancel" buttons are pressed, the dialog is
* automatically hidden (but not disposed). If the "Reset"
* button is pressed, the color-chooser's color will be reset to the
! * color which was set the last time <code>show</code> was invoked on the
* dialog and the dialog will remain showing.
*
* @param c the parent component for the dialog
* @param title the title for the dialog
* @param modal a boolean. When true, the remainder of the program
--- 179,193 ----
return ok.getColor();
}
/**
* Creates and returns a new dialog containing the specified
! * {@code ColorChooser} pane along with "OK", "Cancel", and "Reset"
* buttons. If the "OK" or "Cancel" buttons are pressed, the dialog is
* automatically hidden (but not disposed). If the "Reset"
* button is pressed, the color-chooser's color will be reset to the
! * color which was set the last time {@code show} was invoked on the
* dialog and the dialog will remain showing.
*
* @param c the parent component for the dialog
* @param title the title for the dialog
* @param modal a boolean. When true, the remainder of the program
*** 234,267 ****
}
/**
* Creates a color chooser pane with the specified
! * <code>ColorSelectionModel</code>.
*
! * @param model the <code>ColorSelectionModel</code> to be used
*/
public JColorChooser(ColorSelectionModel model) {
selectionModel = model;
updateUI();
dragEnabled = false;
}
/**
* Returns the L&F object that renders this component.
*
! * @return the <code>ColorChooserUI</code> object that renders
* this component
*/
public ColorChooserUI getUI() {
return (ColorChooserUI)ui;
}
/**
* Sets the L&F object that renders this component.
*
! * @param ui the <code>ColorChooserUI</code> L&F object
* @see UIDefaults#getUI
*
* @beaninfo
* bound: true
* hidden: true
--- 234,267 ----
}
/**
* Creates a color chooser pane with the specified
! * {@code ColorSelectionModel}.
*
! * @param model the {@code ColorSelectionModel} to be used
*/
public JColorChooser(ColorSelectionModel model) {
selectionModel = model;
updateUI();
dragEnabled = false;
}
/**
* Returns the L&F object that renders this component.
*
! * @return the {@code ColorChooserUI} object that renders
* this component
*/
public ColorChooserUI getUI() {
return (ColorChooserUI)ui;
}
/**
* Sets the L&F object that renders this component.
*
! * @param ui the {@code ColorChooserUI} L&F object
* @see UIDefaults#getUI
*
* @beaninfo
* bound: true
* hidden: true
*** 270,282 ****
public void setUI(ColorChooserUI ui) {
super.setUI(ui);
}
/**
! * Notification from the <code>UIManager</code> that the L&F has changed.
* Replaces the current UI object with the latest version from the
! * <code>UIManager</code>.
*
* @see JComponent#updateUI
*/
public void updateUI() {
setUI((ColorChooserUI)UIManager.getUI(this));
--- 270,282 ----
public void setUI(ColorChooserUI ui) {
super.setUI(ui);
}
/**
! * Notification from the {@code UIManager} that the L&F has changed.
* Replaces the current UI object with the latest version from the
! * {@code UIManager}.
*
* @see JComponent#updateUI
*/
public void updateUI() {
setUI((ColorChooserUI)UIManager.getUI(this));
*** 303,313 ****
return selectionModel.getSelectedColor();
}
/**
* Sets the current color of the color chooser to the specified color.
! * The <code>ColorSelectionModel</code> will fire a <code>ChangeEvent</code>
* @param color the color to be set in the color chooser
* @see JComponent#addPropertyChangeListener
*
* @beaninfo
* bound: false
--- 303,313 ----
return selectionModel.getSelectedColor();
}
/**
* Sets the current color of the color chooser to the specified color.
! * The {@code ColorSelectionModel} will fire a {@code ChangeEvent}
* @param color the color to be set in the color chooser
* @see JComponent#addPropertyChangeListener
*
* @beaninfo
* bound: false
*** 346,381 ****
public void setColor(int c) {
setColor((c >> 16) & 0xFF, (c >> 8) & 0xFF, c & 0xFF);
}
/**
! * Sets the <code>dragEnabled</code> property,
! * which must be <code>true</code> to enable
* automatic drag handling (the first part of drag and drop)
* on this component.
! * The <code>transferHandler</code> property needs to be set
! * to a non-<code>null</code> value for the drag to do
! * anything. The default value of the <code>dragEnabled</code>
* property
! * is <code>false</code>.
*
* <p>
*
* When automatic drag handling is enabled,
* most look and feels begin a drag-and-drop operation
* when the user presses the mouse button over the preview panel.
* Some look and feels might not support automatic drag and drop;
* they will ignore this property. You can work around such
* look and feels by modifying the component
! * to directly call the <code>exportAsDrag</code> method of a
! * <code>TransferHandler</code>.
*
! * @param b the value to set the <code>dragEnabled</code> property to
* @exception HeadlessException if
! * <code>b</code> is <code>true</code> and
! * <code>GraphicsEnvironment.isHeadless()</code>
! * returns <code>true</code>
*
* @since 1.4
*
* @see java.awt.GraphicsEnvironment#isHeadless
* @see #getDragEnabled
--- 346,381 ----
public void setColor(int c) {
setColor((c >> 16) & 0xFF, (c >> 8) & 0xFF, c & 0xFF);
}
/**
! * Sets the {@code dragEnabled} property,
! * which must be {@code true} to enable
* automatic drag handling (the first part of drag and drop)
* on this component.
! * The {@code transferHandler} property needs to be set
! * to a non-{@code null} value for the drag to do
! * anything. The default value of the {@code dragEnabled}
* property
! * is {@code false}.
*
* <p>
*
* When automatic drag handling is enabled,
* most look and feels begin a drag-and-drop operation
* when the user presses the mouse button over the preview panel.
* Some look and feels might not support automatic drag and drop;
* they will ignore this property. You can work around such
* look and feels by modifying the component
! * to directly call the {@code exportAsDrag} method of a
! * {@code TransferHandler}.
*
! * @param b the value to set the {@code dragEnabled} property to
* @exception HeadlessException if
! * {@code b} is {@code true} and
! * {@code GraphicsEnvironment.isHeadless()}
! * returns {@code true}
*
* @since 1.4
*
* @see java.awt.GraphicsEnvironment#isHeadless
* @see #getDragEnabled
*** 392,417 ****
}
dragEnabled = b;
}
/**
! * Gets the value of the <code>dragEnabled</code> property.
*
! * @return the value of the <code>dragEnabled</code> property
* @see #setDragEnabled
* @since 1.4
*/
public boolean getDragEnabled() {
return dragEnabled;
}
/**
* Sets the current preview panel.
! * This will fire a <code>PropertyChangeEvent</code> for the property
* named "previewPanel".
*
! * @param preview the <code>JComponent</code> which displays the current color
* @see JComponent#addPropertyChangeListener
*
* @beaninfo
* bound: true
* hidden: true
--- 392,417 ----
}
dragEnabled = b;
}
/**
! * Gets the value of the {@code dragEnabled} property.
*
! * @return the value of the {@code dragEnabled} property
* @see #setDragEnabled
* @since 1.4
*/
public boolean getDragEnabled() {
return dragEnabled;
}
/**
* Sets the current preview panel.
! * This will fire a {@code PropertyChangeEvent} for the property
* named "previewPanel".
*
! * @param preview the {@code JComponent} which displays the current color
* @see JComponent#addPropertyChangeListener
*
* @beaninfo
* bound: true
* hidden: true
*** 427,446 ****
}
/**
* Returns the preview panel that shows a chosen color.
*
! * @return a <code>JComponent</code> object -- the preview panel
*/
public JComponent getPreviewPanel() {
return previewPanel;
}
/**
* Adds a color chooser panel to the color chooser.
*
! * @param panel the <code>AbstractColorChooserPanel</code> to be added
*/
public void addChooserPanel( AbstractColorChooserPanel panel ) {
AbstractColorChooserPanel[] oldPanels = getChooserPanels();
AbstractColorChooserPanel[] newPanels = new AbstractColorChooserPanel[oldPanels.length+1];
System.arraycopy(oldPanels, 0, newPanels, 0, oldPanels.length);
--- 427,446 ----
}
/**
* Returns the preview panel that shows a chosen color.
*
! * @return a {@code JComponent} object -- the preview panel
*/
public JComponent getPreviewPanel() {
return previewPanel;
}
/**
* Adds a color chooser panel to the color chooser.
*
! * @param panel the {@code AbstractColorChooserPanel} to be added
*/
public void addChooserPanel( AbstractColorChooserPanel panel ) {
AbstractColorChooserPanel[] oldPanels = getChooserPanels();
AbstractColorChooserPanel[] newPanels = new AbstractColorChooserPanel[oldPanels.length+1];
System.arraycopy(oldPanels, 0, newPanels, 0, oldPanels.length);
*** 492,502 ****
/**
* Specifies the Color Panels used to choose a color value.
*
! * @param panels an array of <code>AbstractColorChooserPanel</code>
* objects
*
* @beaninfo
* bound: true
* hidden: true
--- 492,502 ----
/**
* Specifies the Color Panels used to choose a color value.
*
! * @param panels an array of {@code AbstractColorChooserPanel}
* objects
*
* @beaninfo
* bound: true
* hidden: true
*** 509,538 ****
}
/**
* Returns the specified color panels.
*
! * @return an array of <code>AbstractColorChooserPanel</code> objects
*/
public AbstractColorChooserPanel[] getChooserPanels() {
return chooserPanels;
}
/**
* Returns the data model that handles color selections.
*
! * @return a <code>ColorSelectionModel</code> object
*/
public ColorSelectionModel getSelectionModel() {
return selectionModel;
}
/**
* Sets the model containing the selected color.
*
! * @param newModel the new <code>ColorSelectionModel</code> object
*
* @beaninfo
* bound: true
* hidden: true
* description: The model which contains the currently selected color.
--- 509,538 ----
}
/**
* Returns the specified color panels.
*
! * @return an array of {@code AbstractColorChooserPanel} objects
*/
public AbstractColorChooserPanel[] getChooserPanels() {
return chooserPanels;
}
/**
* Returns the data model that handles color selections.
*
! * @return a {@code ColorSelectionModel} object
*/
public ColorSelectionModel getSelectionModel() {
return selectionModel;
}
/**
* Sets the model containing the selected color.
*
! * @param newModel the new {@code ColorSelectionModel} object
*
* @beaninfo
* bound: true
* hidden: true
* description: The model which contains the currently selected color.
*** 543,554 ****
firePropertyChange(JColorChooser.SELECTION_MODEL_PROPERTY, oldModel, newModel);
}
/**
! * See <code>readObject</code> and <code>writeObject</code> in
! * <code>JComponent</code> for more
* information about serialization in Swing.
*/
private void writeObject(ObjectOutputStream s) throws IOException {
s.defaultWriteObject();
if (getUIClassID().equals(uiClassID)) {
--- 543,554 ----
firePropertyChange(JColorChooser.SELECTION_MODEL_PROPERTY, oldModel, newModel);
}
/**
! * See {@code readObject} and {@code writeObject} in
! * {@code JComponent} for more
* information about serialization in Swing.
*/
private void writeObject(ObjectOutputStream s) throws IOException {
s.defaultWriteObject();
if (getUIClassID().equals(uiClassID)) {
*** 560,577 ****
}
}
/**
! * Returns a string representation of this <code>JColorChooser</code>.
* This method
* is intended to be used only for debugging purposes, and the
* content and format of the returned string may vary between
* implementations. The returned string may be empty but may not
! * be <code>null</code>.
*
! * @return a string representation of this <code>JColorChooser</code>
*/
protected String paramString() {
StringBuilder chooserPanelsString = new StringBuilder();
for (AbstractColorChooserPanel panel : chooserPanels) {
chooserPanelsString.append('[').append(panel)
--- 560,577 ----
}
}
/**
! * Returns a string representation of this {@code JColorChooser}.
* This method
* is intended to be used only for debugging purposes, and the
* content and format of the returned string may vary between
* implementations. The returned string may be empty but may not
! * be {@code null}.
*
! * @return a string representation of this {@code JColorChooser}
*/
protected String paramString() {
StringBuilder chooserPanelsString = new StringBuilder();
for (AbstractColorChooserPanel panel : chooserPanels) {
chooserPanelsString.append('[').append(panel)
*** 610,620 ****
return accessibleContext;
}
/**
* This class implements accessibility support for the
! * <code>JColorChooser</code> class. It provides an implementation of the
* Java Accessibility API appropriate to color chooser user-interface
* elements.
*/
protected class AccessibleJColorChooser extends AccessibleJComponent {
--- 610,620 ----
return accessibleContext;
}
/**
* This class implements accessibility support for the
! * {@code JColorChooser} class. It provides an implementation of the
* Java Accessibility API appropriate to color chooser user-interface
* elements.
*/
protected class AccessibleJColorChooser extends AccessibleJComponent {
< prev index next >