J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2002-2003 Sun Microsystems, Inc. All Rights Reserved. |
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 only, as |
| 7 | * published by the Free Software Foundation. Sun designates this |
| 8 | * particular file as subject to the "Classpath" exception as provided |
| 9 | * by Sun in the LICENSE file that accompanied this code. |
| 10 | * |
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 14 | * version 2 for more details (a copy is included in the LICENSE file that |
| 15 | * accompanied this code). |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License version |
| 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | * |
| 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 22 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 23 | * have any questions. |
| 24 | */ |
| 25 | |
| 26 | package javax.swing.plaf.synth; |
| 27 | |
| 28 | |
| 29 | import javax.swing.*; |
| 30 | import javax.swing.colorchooser.*; |
| 31 | import javax.swing.event.*; |
| 32 | import javax.swing.border.*; |
| 33 | import javax.swing.plaf.*; |
| 34 | import javax.swing.plaf.basic.BasicColorChooserUI; |
| 35 | import java.util.*; |
| 36 | import java.awt.*; |
| 37 | import java.awt.image.*; |
| 38 | import java.awt.event.*; |
| 39 | import java.beans.PropertyChangeEvent; |
| 40 | import java.beans.PropertyChangeListener; |
| 41 | import java.io.Serializable; |
| 42 | import sun.swing.plaf.synth.SynthUI; |
| 43 | |
| 44 | |
| 45 | /** |
| 46 | * Synth's ColorChooserUI. |
| 47 | * |
| 48 | * @author Tom Santos |
| 49 | * @author Steve Wilson |
| 50 | */ |
| 51 | class SynthColorChooserUI extends BasicColorChooserUI implements |
| 52 | PropertyChangeListener, SynthUI { |
| 53 | private SynthStyle style; |
| 54 | |
| 55 | public static ComponentUI createUI(JComponent c) { |
| 56 | return new SynthColorChooserUI(); |
| 57 | } |
| 58 | |
| 59 | protected AbstractColorChooserPanel[] createDefaultChoosers() { |
| 60 | SynthContext context = getContext(chooser, ENABLED); |
| 61 | AbstractColorChooserPanel[] panels = (AbstractColorChooserPanel[]) |
| 62 | context.getStyle().get(context, "ColorChooser.panels"); |
| 63 | context.dispose(); |
| 64 | |
| 65 | if (panels == null) { |
| 66 | panels = ColorChooserComponentFactory.getDefaultChooserPanels(); |
| 67 | } |
| 68 | return panels; |
| 69 | } |
| 70 | |
| 71 | protected void installDefaults() { |
| 72 | updateStyle(chooser); |
| 73 | } |
| 74 | |
| 75 | private void updateStyle(JComponent c) { |
| 76 | SynthContext context = getContext(c, ENABLED); |
| 77 | style = SynthLookAndFeel.updateStyle(context, this); |
| 78 | context.dispose(); |
| 79 | } |
| 80 | |
| 81 | protected void uninstallDefaults() { |
| 82 | SynthContext context = getContext(chooser, ENABLED); |
| 83 | |
| 84 | style.uninstallDefaults(context); |
| 85 | context.dispose(); |
| 86 | style = null; |
| 87 | super.uninstallDefaults(); |
| 88 | } |
| 89 | |
| 90 | protected void installListeners() { |
| 91 | super.installListeners(); |
| 92 | chooser.addPropertyChangeListener(this); |
| 93 | } |
| 94 | |
| 95 | protected void uninstallListeners() { |
| 96 | chooser.removePropertyChangeListener(this); |
| 97 | super.uninstallListeners(); |
| 98 | } |
| 99 | |
| 100 | public SynthContext getContext(JComponent c) { |
| 101 | return getContext(c, getComponentState(c)); |
| 102 | } |
| 103 | |
| 104 | private SynthContext getContext(JComponent c, int state) { |
| 105 | return SynthContext.getContext(SynthContext.class, c, |
| 106 | SynthLookAndFeel.getRegion(c), style, state); |
| 107 | } |
| 108 | |
| 109 | private Region getRegion(JComponent c) { |
| 110 | return SynthLookAndFeel.getRegion(c); |
| 111 | } |
| 112 | |
| 113 | private int getComponentState(JComponent c) { |
| 114 | return SynthLookAndFeel.getComponentState(c); |
| 115 | } |
| 116 | |
| 117 | public void update(Graphics g, JComponent c) { |
| 118 | SynthContext context = getContext(c); |
| 119 | |
| 120 | SynthLookAndFeel.update(context, g); |
| 121 | context.getPainter().paintColorChooserBackground(context, g, 0, 0, |
| 122 | c.getWidth(), c.getHeight()); |
| 123 | paint(context, g); |
| 124 | context.dispose(); |
| 125 | } |
| 126 | |
| 127 | public void paint(Graphics g, JComponent c) { |
| 128 | SynthContext context = getContext(c); |
| 129 | |
| 130 | paint(context, g); |
| 131 | context.dispose(); |
| 132 | } |
| 133 | |
| 134 | protected void paint(SynthContext context, Graphics g) { |
| 135 | } |
| 136 | |
| 137 | public void paintBorder(SynthContext context, Graphics g, int x, |
| 138 | int y, int w, int h) { |
| 139 | context.getPainter().paintColorChooserBorder(context, g, x, y,w,h); |
| 140 | } |
| 141 | |
| 142 | public void propertyChange(PropertyChangeEvent e) { |
| 143 | if (SynthLookAndFeel.shouldUpdateStyle(e)) { |
| 144 | updateStyle((JColorChooser)e.getSource()); |
| 145 | } |
| 146 | } |
| 147 | } |