Source Code Cross Referenced for JColorChooser.java in  » Apache-Harmony-Java-SE » javax-package » javax » swing » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Apache Harmony Java SE » javax package » javax.swing 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */
017:
018:        package javax.swing;
019:
020:        import java.awt.BorderLayout;
021:        import java.awt.Color;
022:        import java.awt.Component;
023:        import java.awt.Dialog;
024:        import java.awt.Frame;
025:        import java.awt.GraphicsEnvironment;
026:        import java.awt.HeadlessException;
027:        import java.awt.Window;
028:        import java.awt.event.ActionEvent;
029:        import java.awt.event.ActionListener;
030:        import javax.accessibility.Accessible;
031:        import javax.accessibility.AccessibleContext;
032:        import javax.accessibility.AccessibleRole;
033:        import javax.swing.colorchooser.AbstractColorChooserPanel;
034:        import javax.swing.colorchooser.ColorChooserComponentFactory;
035:        import javax.swing.colorchooser.ColorSelectionModel;
036:        import javax.swing.colorchooser.DefaultColorSelectionModel;
037:        import javax.swing.plaf.ColorChooserUI;
038:
039:        import org.apache.harmony.x.swing.internal.nls.Messages;
040:
041:        /**
042:         * <p>
043:         * <i>JColorChooser</i>
044:         * </p>
045:         * <h3>Implementation Notes:</h3>
046:         * <ul>
047:         * <li>The <code>serialVersionUID</code> fields are explicitly declared as a performance
048:         * optimization, not as a guarantee of serialization compatibility.</li>
049:         * </ul>
050:         */
051:        public class JColorChooser extends JComponent implements  Accessible {
052:            private static final long serialVersionUID = -3698198979867714534L;
053:
054:            protected class AccessibleJColorChooser extends
055:                    AccessibleJComponent {
056:                private static final long serialVersionUID = -4916849065058077868L;
057:
058:                @Override
059:                public AccessibleRole getAccessibleRole() {
060:                    return AccessibleRole.COLOR_CHOOSER;
061:                }
062:            }
063:
064:            public static final String SELECTION_MODEL_PROPERTY = "selectionModel";
065:
066:            public static final String PREVIEW_PANEL_PROPERTY = "previewPanel";
067:
068:            public static final String CHOOSER_PANELS_PROPERTY = "chooserPanels";
069:
070:            private ColorSelectionModel colorSelectionModel;
071:
072:            private boolean dragEnabled;
073:
074:            private JComponent previewPanel;
075:
076:            private AbstractColorChooserPanel[] chooserPanels = new AbstractColorChooserPanel[] {};
077:
078:            private static Color resultColor;
079:
080:            public JColorChooser() {
081:                this (new DefaultColorSelectionModel(Color.WHITE));
082:            }
083:
084:            public JColorChooser(Color initialColor) {
085:                this (new DefaultColorSelectionModel(initialColor));
086:            }
087:
088:            public JColorChooser(ColorSelectionModel model) {
089:                colorSelectionModel = model;
090:                setLayout(new BorderLayout());
091:                updateUI();
092:            }
093:
094:            @SuppressWarnings("deprecation")
095:            public static Color showDialog(Component component, String title,
096:                    Color initialColor) throws HeadlessException {
097:                final JColorChooser colorChooser = new JColorChooser(
098:                        initialColor);
099:                ActionListener okListener = new ActionListener() {
100:                    public void actionPerformed(ActionEvent e) {
101:                        resultColor = colorChooser.getColor();
102:                    }
103:                };
104:                ActionListener cancelListener = new ActionListener() {
105:                    public void actionPerformed(ActionEvent e) {
106:                        resultColor = null;
107:                    }
108:                };
109:                createDialog(component, title, true, colorChooser, okListener,
110:                        cancelListener).show();
111:                return resultColor;
112:            }
113:
114:            public static JDialog createDialog(Component c, String title,
115:                    boolean modal, final JColorChooser chooserPane,
116:                    ActionListener okListener, ActionListener cancelListener)
117:                    throws HeadlessException {
118:                Window ancestingWindow = c instanceof  Window ? (Window) c
119:                        : SwingUtilities.getWindowAncestor(c);
120:                final JDialog result;
121:                if (ancestingWindow instanceof  Frame) {
122:                    result = new JDialog((Frame) ancestingWindow);
123:                } else if (ancestingWindow instanceof  Dialog) {
124:                    result = new JDialog((Dialog) ancestingWindow);
125:                } else {
126:                    result = new JDialog();
127:                }
128:                result.setModal(modal);
129:                result.setLocationRelativeTo(c);
130:                result.setTitle(title);
131:                result.getContentPane().add(chooserPane);
132:                if (JDialog.isDefaultLookAndFeelDecorated()) {
133:                    result.getRootPane().setWindowDecorationStyle(
134:                            JRootPane.COLOR_CHOOSER_DIALOG);
135:                }
136:                JPanel buttonsPanel = new JPanel();
137:                ActionListener disposeListener = new ActionListener() {
138:                    public void actionPerformed(ActionEvent e) {
139:                        result.dispose();
140:                    }
141:                };
142:                String okText = UIManager.getString("ColorChooser.okText");
143:                final JButton okButton = new JButton(okText);
144:                okButton.addActionListener(okListener);
145:                String cancelText = UIManager
146:                        .getString("ColorChooser.cancelText");
147:                final JButton cancelButton = new JButton(cancelText);
148:                cancelButton.addActionListener(cancelListener);
149:                String resetText = UIManager
150:                        .getString("ColorChooser.resetText");
151:                JButton resetButton = new JButton(resetText);
152:                int resetMnemonic = UIManager
153:                        .getInt("ColorChooser.resetMnemonic");
154:                resetButton.setMnemonic(resetMnemonic);
155:                resetButton.addActionListener(new ActionListener() {
156:                    public void actionPerformed(ActionEvent e) {
157:                        chooserPane.setColor(Color.WHITE);
158:                    }
159:                });
160:                okButton.addActionListener(disposeListener);
161:                cancelButton.addActionListener(disposeListener);
162:                buttonsPanel.setLayout(new BoxLayout(buttonsPanel,
163:                        BoxLayout.X_AXIS));
164:                buttonsPanel.setBorder(BorderFactory.createEmptyBorder(5, 0, 5,
165:                        5));
166:                buttonsPanel.add(Box.createHorizontalGlue());
167:                buttonsPanel.add(okButton);
168:                buttonsPanel.add(Box.createHorizontalStrut(6));
169:                buttonsPanel.add(cancelButton);
170:                buttonsPanel.add(Box.createHorizontalStrut(6));
171:                buttonsPanel.add(resetButton);
172:                result.add(buttonsPanel, BorderLayout.SOUTH);
173:                result.getRootPane().setDefaultButton(okButton);
174:                result.pack();
175:                InputMap map = LookAndFeel.makeComponentInputMap(chooserPane,
176:                        new Object[] { "ESCAPE", "cancelAction" });
177:                SwingUtilities.replaceUIInputMap(chooserPane,
178:                        JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, map);
179:                chooserPane.getActionMap().put("cancelAction",
180:                        new AbstractAction() {
181:                            private static final long serialVersionUID = 1L;
182:
183:                            public void actionPerformed(ActionEvent e) {
184:                                cancelButton.doClick(0);
185:                            }
186:                        });
187:                return result;
188:            }
189:
190:            public ColorChooserUI getUI() {
191:                return (ColorChooserUI) ui;
192:            }
193:
194:            public void setUI(ColorChooserUI ui) {
195:                super .setUI(ui);
196:            }
197:
198:            @Override
199:            public void updateUI() {
200:                setUI((ColorChooserUI) UIManager.getUI(this ));
201:            }
202:
203:            @Override
204:            public String getUIClassID() {
205:                return "ColorChooserUI";
206:            }
207:
208:            public Color getColor() {
209:                return colorSelectionModel.getSelectedColor();
210:            }
211:
212:            public void setColor(Color color) {
213:                colorSelectionModel.setSelectedColor(color);
214:            }
215:
216:            public void setColor(int r, int g, int b) {
217:                setColor(new Color(r, g, b));
218:            }
219:
220:            public void setColor(int c) {
221:                setColor(new Color(c));
222:            }
223:
224:            public void setDragEnabled(boolean b) {
225:                if (b && GraphicsEnvironment.isHeadless()) {
226:                    throw new HeadlessException();
227:                }
228:                dragEnabled = b;
229:            }
230:
231:            public boolean getDragEnabled() {
232:                return dragEnabled;
233:            }
234:
235:            public void setPreviewPanel(JComponent preview) {
236:                JComponent oldValue = previewPanel;
237:                if (preview == null) {
238:                    previewPanel = ColorChooserComponentFactory
239:                            .getPreviewPanel();
240:                } else {
241:                    previewPanel = preview;
242:                }
243:                firePropertyChange(PREVIEW_PANEL_PROPERTY, oldValue,
244:                        previewPanel);
245:            }
246:
247:            public JComponent getPreviewPanel() {
248:                return previewPanel;
249:            }
250:
251:            public void addChooserPanel(AbstractColorChooserPanel panel) {
252:                AbstractColorChooserPanel[] newChooserPanels = new AbstractColorChooserPanel[chooserPanels.length + 1];
253:                System.arraycopy(chooserPanels, 0, newChooserPanels, 0,
254:                        chooserPanels.length);
255:                newChooserPanels[chooserPanels.length] = panel;
256:                setChooserPanels(newChooserPanels);
257:            }
258:
259:            public AbstractColorChooserPanel removeChooserPanel(
260:                    AbstractColorChooserPanel panel) {
261:                AbstractColorChooserPanel panelToRemove = null;
262:                int index = 0;
263:                for (int i = 0; i < chooserPanels.length; i++) {
264:                    if (panel.equals(chooserPanels[i])) {
265:                        panelToRemove = chooserPanels[i];
266:                        index = i;
267:                        break;
268:                    }
269:                }
270:                if (panelToRemove == null) {
271:                    throw new IllegalArgumentException(Messages
272:                            .getString("swing.0A")); //$NON-NLS-1$
273:                }
274:                AbstractColorChooserPanel[] newChooserPanels = new AbstractColorChooserPanel[chooserPanels.length - 1];
275:                System.arraycopy(chooserPanels, 0, newChooserPanels, 0, index);
276:                System.arraycopy(chooserPanels, index + 1, newChooserPanels,
277:                        index, newChooserPanels.length - index);
278:                setChooserPanels(newChooserPanels);
279:                return panelToRemove;
280:            }
281:
282:            public void setChooserPanels(AbstractColorChooserPanel[] panels) {
283:                AbstractColorChooserPanel[] oldValue = chooserPanels;
284:                chooserPanels = panels;
285:                firePropertyChange(CHOOSER_PANELS_PROPERTY, oldValue,
286:                        chooserPanels);
287:            }
288:
289:            public AbstractColorChooserPanel[] getChooserPanels() {
290:                return chooserPanels;
291:            }
292:
293:            public ColorSelectionModel getSelectionModel() {
294:                return colorSelectionModel;
295:            }
296:
297:            public void setSelectionModel(ColorSelectionModel newModel) {
298:                ColorSelectionModel oldModel = colorSelectionModel;
299:                colorSelectionModel = newModel;
300:                firePropertyChange(SELECTION_MODEL_PROPERTY, oldModel, newModel);
301:            }
302:
303:            @Override
304:            public AccessibleContext getAccessibleContext() {
305:                if (accessibleContext == null) {
306:                    accessibleContext = new AccessibleJColorChooser();
307:                }
308:                return accessibleContext;
309:            }
310:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.