Source Code Cross Referenced for ColorComboBox.java in  » Swing-Library » substance-look-feel » test » check » 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 » Swing Library » substance look feel » test.check 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *                 Sun Public License Notice
003:         * 
004:         * The contents of this file are subject to the Sun Public License
005:         * Version 1.0 (the "License"). You may not use this file except in
006:         * compliance with the License. A copy of the License is available at
007:         * http://www.sun.com/
008:         * 
009:         * The Original Code is NetBeans. The Initial Developer of the Original
010:         * Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun
011:         * Microsystems, Inc. All Rights Reserved.
012:         */
013:
014:        package test.check;
015:
016:        import java.awt.*;
017:        import java.awt.event.ActionEvent;
018:        import java.awt.event.ActionListener;
019:        import java.util.HashMap;
020:        import java.util.Map;
021:
022:        import javax.swing.*;
023:
024:        import org.jvnet.substance.SubstanceBorder;
025:
026:        /**
027:         * 
028:         * @author Administrator
029:         */
030:        public class ColorComboBox extends JComboBox {
031:
032:            public static final String PROP_COLOR = "color"; // NOI18N
033:
034:            public static final Value CUSTOM_COLOR = new Value(loc("Custom"),
035:                    null); // NOI18N
036:
037:            private static Map<Color, String> colorMap = new HashMap<Color, String>();
038:            static {
039:                colorMap.put(Color.BLACK, loc("Black")); // NOI18N
040:                colorMap.put(Color.BLUE, loc("Blue")); // NOI18N
041:                colorMap.put(Color.CYAN, loc("Cyan")); // NOI18N
042:                colorMap.put(Color.DARK_GRAY, loc("Dark_Gray")); // NOI18N
043:                colorMap.put(Color.GRAY, loc("Gray")); // NOI18N
044:                colorMap.put(Color.GREEN, loc("Green")); // NOI18N
045:                colorMap.put(Color.LIGHT_GRAY, loc("Light_Gray")); // NOI18N
046:                colorMap.put(Color.MAGENTA, loc("Magenta")); // NOI18N
047:                colorMap.put(Color.ORANGE, loc("Orange")); // NOI18N
048:                colorMap.put(Color.PINK, loc("Pink")); // NOI18N
049:                colorMap.put(Color.RED, loc("Red")); // NOI18N
050:                colorMap.put(Color.WHITE, loc("White")); // NOI18N
051:                colorMap.put(Color.YELLOW, loc("Yellow")); // NOI18N
052:            }
053:
054:            private static Object[] content = new Object[] {
055:                    new Value(Color.BLACK), new Value(Color.BLUE),
056:                    new Value(Color.CYAN), new Value(Color.DARK_GRAY),
057:                    new Value(Color.GRAY), new Value(Color.GREEN),
058:                    new Value(Color.LIGHT_GRAY), new Value(Color.MAGENTA),
059:                    new Value(Color.ORANGE), new Value(Color.PINK),
060:                    new Value(Color.RED), new Value(Color.WHITE),
061:                    new Value(Color.YELLOW), CUSTOM_COLOR };
062:
063:            private Color lastColor;
064:
065:            /** Creates a new instance of ColorChooser */
066:            public ColorComboBox() {
067:                super (content);
068:                setRenderer(new Renderer());
069:                setEditable(true);
070:                setEditor(new Renderer());
071:                setSelectedItem(new Value(null, null));
072:                addActionListener(new ActionListener() {
073:                    public void actionPerformed(ActionEvent ev) {
074:                        if (getSelectedItem() == CUSTOM_COLOR) {
075:                            Color c = JColorChooser.showDialog(SwingUtilities
076:                                    .getAncestorOfClass(Dialog.class,
077:                                            ColorComboBox.this ),
078:                                    loc("SelectColor"), lastColor);
079:                            if (c != null)
080:                                setColor(c);
081:                        } else {
082:                            lastColor = ((Value) getSelectedItem()).color;
083:                        }
084:                        ColorComboBox.this .firePropertyChange(PROP_COLOR, null,
085:                                null);
086:                    }
087:                });
088:            }
089:
090:            public void setInheritedColor(Color color) {
091:                Object[] ncontent = new Object[content.length];
092:                System.arraycopy(content, 0, ncontent, 0, content.length);
093:                if (color != null)
094:                    ncontent[content.length - 1] = new Value(
095:                            loc("CTL_Inherited_Color"), color // NOI18N
096:                    );
097:                else
098:                    ncontent[content.length - 1] = new Value(
099:                            loc("CTL_None_Color"), null // NOI18N
100:                    );
101:                setModel(new DefaultComboBoxModel(ncontent));
102:            }
103:
104:            public void setColor(Color color) {
105:                if (color == null) {
106:                    setSelectedIndex(content.length - 1);
107:                    lastColor = ((Value) getItemAt(content.length - 1)).color;
108:                } else {
109:                    setSelectedItem(new Value(color));
110:                    lastColor = color;
111:                }
112:            }
113:
114:            public Color getColor() {
115:                if (getSelectedIndex() == (content.length - 1))
116:                    return null;
117:                return ((Value) getSelectedItem()).color;
118:            }
119:
120:            private static String loc(String key) {
121:                return key;
122:            }
123:
124:            // innerclasses ............................................................
125:
126:            public static class Value {
127:                String text;
128:
129:                Color color;
130:
131:                Value(Color color) {
132:                    this .color = color;
133:                    text = (String) colorMap.get(color);
134:                    if (text != null)
135:                        return;
136:                    StringBuffer sb = new StringBuffer();
137:                    sb.append('[').append(color.getRed()).append(',').append(
138:                            color.getGreen()).append(',').append(
139:                            color.getBlue()).append(']');
140:                    text = sb.toString();
141:                }
142:
143:                Value(String text, Color color) {
144:                    this .text = text;
145:                    this .color = color;
146:                }
147:            }
148:
149:            private class Renderer extends JComponent implements 
150:                    ListCellRenderer, ComboBoxEditor {
151:
152:                private int SIZE = 9;
153:
154:                private Value value;
155:
156:                Renderer() {
157:                    setPreferredSize(new Dimension(50, getFontMetrics(
158:                            ColorComboBox.this .getFont()).getHeight() + 2));
159:                    setOpaque(true);
160:                    setFocusable(true);
161:                    setBorder(new SubstanceBorder());
162:                }
163:
164:                public void paint(Graphics g) {
165:                    Color oldColor = g.getColor();
166:                    Dimension size = getSize();
167:                    if (isFocusOwner())
168:                        g.setColor(SystemColor.textHighlight);
169:                    else
170:                        g.setColor(getBackground());
171:                    g.fillRect(0, 0, size.width, size.height);
172:                    int i = (size.height - SIZE) / 2;
173:                    if (value.color != null) {
174:                        g.setColor(Color.black);
175:                        g.drawRect(i, i, SIZE, SIZE);
176:                        g.setColor(value.color);
177:                        g.fillRect(i + 1, i + 1, SIZE - 1, SIZE - 1);
178:                    }
179:                    if (value.text != null) {
180:                        if (isFocusOwner())
181:                            g.setColor(SystemColor.textHighlightText);
182:                        else
183:                            g.setColor(getForeground());
184:                        if (value.color != null)
185:                            g.drawString(value.text, i + SIZE + 5, i + SIZE);
186:                        else
187:                            g.drawString(value.text, 5, i + SIZE);
188:                    }
189:                    g.setColor(oldColor);
190:                }
191:
192:                public void setEnabled(boolean enabled) {
193:                    setBackground(enabled ? SystemColor.text
194:                            : SystemColor.control);
195:                    super .setEnabled(enabled);
196:                }
197:
198:                public Component getListCellRendererComponent(JList list,
199:                        Object value, int index, boolean isSelected,
200:                        boolean cellHasFocus) {
201:                    this .value = (Value) value;
202:                    setEnabled(list.isEnabled());
203:                    setBackground(isSelected ? SystemColor.textHighlight
204:                            : SystemColor.text);
205:                    setForeground(isSelected ? SystemColor.textHighlightText
206:                            : SystemColor.textText);
207:                    return this ;
208:                }
209:
210:                public Component getEditorComponent() {
211:                    setEnabled(ColorComboBox.this .isEnabled());
212:                    setBackground(ColorComboBox.this .isFocusOwner() ? SystemColor.textHighlight
213:                            : SystemColor.text);
214:                    setForeground(ColorComboBox.this .isFocusOwner() ? SystemColor.textHighlightText
215:                            : SystemColor.textText);
216:                    return this ;
217:                }
218:
219:                public void setItem(Object anObject) {
220:                    this .value = (Value) anObject;
221:                }
222:
223:                public Object getItem() {
224:                    return value;
225:                }
226:
227:                public void selectAll() {
228:                }
229:
230:                public void addActionListener(ActionListener l) {
231:                }
232:
233:                public void removeActionListener(ActionListener l) {
234:                }
235:            }
236:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.