Source Code Cross Referenced for DefaultTreeCellRenderer.java in  » Apache-Harmony-Java-SE » javax-package » javax » swing » tree » 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.tree 
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:         * @author Anton Avtamonov
019:         * @version $Revision$
020:         */package javax.swing.tree;
021:
022:        import java.awt.Color;
023:        import java.awt.Component;
024:        import java.awt.Dimension;
025:        import java.awt.Font;
026:        import java.awt.Graphics;
027:        import java.awt.Rectangle;
028:
029:        import javax.swing.Icon;
030:        import javax.swing.JLabel;
031:        import javax.swing.JTree;
032:        import javax.swing.SwingConstants;
033:        import javax.swing.UIManager;
034:
035:        import org.apache.harmony.x.swing.Utilities;
036:
037:        public class DefaultTreeCellRenderer extends JLabel implements 
038:                TreeCellRenderer {
039:            protected boolean selected;
040:            protected boolean hasFocus;
041:            protected transient Icon closedIcon;
042:            protected transient Icon leafIcon;
043:            protected transient Icon openIcon;
044:            protected Color textSelectionColor;
045:            protected Color textNonSelectionColor;
046:            protected Color backgroundSelectionColor;
047:            protected Color backgroundNonSelectionColor;
048:            protected Color borderSelectionColor;
049:
050:            private Font font;
051:            private Color textDisabledColor;
052:            private boolean drawsFocusBorderAroundIcon;
053:
054:            public DefaultTreeCellRenderer() {
055:                setHorizontalAlignment(SwingConstants.LEFT);
056:                closedIcon = getDefaultClosedIcon();
057:                leafIcon = getDefaultLeafIcon();
058:                openIcon = getDefaultOpenIcon();
059:                textSelectionColor = UIManager
060:                        .getColor("Tree.selectionForeground");
061:                textNonSelectionColor = UIManager
062:                        .getColor("Tree.textForeground");
063:                backgroundSelectionColor = UIManager
064:                        .getColor("Tree.selectionBackground");
065:                backgroundNonSelectionColor = UIManager
066:                        .getColor("Tree.textBackground");
067:                borderSelectionColor = UIManager
068:                        .getColor("Tree.selectionBorderColor");
069:                textDisabledColor = UIManager
070:                        .getColor("Label.disabledForeground");
071:                drawsFocusBorderAroundIcon = UIManager
072:                        .getBoolean("Tree.drawsFocusBorderAroundIcon");
073:            }
074:
075:            public Icon getDefaultOpenIcon() {
076:                return UIManager.getIcon("Tree.openIcon");
077:            }
078:
079:            public Icon getDefaultClosedIcon() {
080:                return UIManager.getIcon("Tree.closedIcon");
081:            }
082:
083:            public Icon getDefaultLeafIcon() {
084:                return UIManager.getIcon("Tree.leafIcon");
085:            }
086:
087:            public void setOpenIcon(final Icon icon) {
088:                openIcon = icon;
089:            }
090:
091:            public Icon getOpenIcon() {
092:                return openIcon;
093:            }
094:
095:            public void setClosedIcon(final Icon icon) {
096:                closedIcon = icon;
097:            }
098:
099:            public Icon getClosedIcon() {
100:                return closedIcon;
101:            }
102:
103:            public void setLeafIcon(final Icon icon) {
104:                leafIcon = icon;
105:            }
106:
107:            public Icon getLeafIcon() {
108:                return leafIcon;
109:            }
110:
111:            public void setTextSelectionColor(final Color color) {
112:                textSelectionColor = color;
113:            }
114:
115:            public Color getTextSelectionColor() {
116:                return textSelectionColor;
117:            }
118:
119:            public void setTextNonSelectionColor(final Color color) {
120:                textNonSelectionColor = color;
121:            }
122:
123:            public Color getTextNonSelectionColor() {
124:                return textNonSelectionColor;
125:            }
126:
127:            public void setBackgroundSelectionColor(final Color color) {
128:                backgroundSelectionColor = color;
129:            }
130:
131:            public Color getBackgroundSelectionColor() {
132:                return backgroundSelectionColor;
133:            }
134:
135:            public void setBackgroundNonSelectionColor(final Color color) {
136:                backgroundNonSelectionColor = color;
137:            }
138:
139:            public Color getBackgroundNonSelectionColor() {
140:                return backgroundNonSelectionColor;
141:            }
142:
143:            public void setBorderSelectionColor(final Color color) {
144:                borderSelectionColor = color;
145:            }
146:
147:            public Color getBorderSelectionColor() {
148:                return borderSelectionColor;
149:            }
150:
151:            public void setFont(final Font font) {
152:                if (!Utilities.isUIResource(font)) {
153:                    this .font = font;
154:                }
155:            }
156:
157:            public Font getFont() {
158:                return font;
159:            }
160:
161:            public void setBackground(final Color color) {
162:                if (!Utilities.isUIResource(color)) {
163:                    super .setBackground(color);
164:                }
165:            }
166:
167:            public Component getTreeCellRendererComponent(final JTree tree,
168:                    final Object value, final boolean selected,
169:                    final boolean expanded, final boolean leaf, final int row,
170:                    final boolean hasFocus) {
171:                this .selected = selected;
172:                this .hasFocus = hasFocus;
173:
174:                setText(tree.convertValueToText(value, selected, expanded,
175:                        leaf, row, hasFocus));
176:                if (font == null) {
177:                    font = tree.getFont();
178:                }
179:                setBackground(selected ? getBackgroundSelectionColor()
180:                        : getBackgroundNonSelectionColor());
181:                if (tree.isEnabled()) {
182:                    setForeground(selected ? getTextSelectionColor()
183:                            : getTextNonSelectionColor());
184:                } else {
185:                    setForeground(textDisabledColor);
186:                }
187:
188:                if (leaf) {
189:                    setIcon(getLeafIcon());
190:                } else if (expanded) {
191:                    setIcon(getOpenIcon());
192:                } else {
193:                    setIcon(getClosedIcon());
194:                }
195:
196:                return this ;
197:            }
198:
199:            public void paint(final Graphics g) {
200:                Color oldColor = g.getColor();
201:
202:                if (selected) {
203:                    g.setColor(getBackgroundSelectionColor());
204:                } else {
205:                    g.setColor(getBackgroundNonSelectionColor());
206:                }
207:                int textOffest = getTextOffset();
208:                int x = getComponentOrientation().isLeftToRight() ? textOffest
209:                        : 0;
210:                g.fillRect(x, 0, getWidth() - textOffest, getHeight());
211:
212:                super .paint(g);
213:
214:                if (hasFocus) {
215:                    g.setColor(getBorderSelectionColor());
216:                    if (drawsFocusBorderAroundIcon) {
217:                        g.drawRect(0, 0, getWidth() - 1, getHeight() - 1);
218:                    } else {
219:                        g.drawRect(x, 0, getWidth() - textOffest - 1,
220:                                getHeight() - 1);
221:                    }
222:                }
223:
224:                g.setColor(oldColor);
225:            }
226:
227:            public Dimension getPreferredSize() {
228:                Dimension basePrefSize = super .getPreferredSize();
229:                return new Dimension(basePrefSize.width + 2,
230:                        basePrefSize.height);
231:            }
232:
233:            public void validate() {
234:            }
235:
236:            public void invalidate() {
237:            }
238:
239:            public void revalidate() {
240:            }
241:
242:            public void repaint(final long tm, final int x, final int y,
243:                    final int width, final int height) {
244:            }
245:
246:            public void repaint(final Rectangle r) {
247:            }
248:
249:            public void repaint() {
250:            }
251:
252:            protected void firePropertyChange(final String propertyName,
253:                    final Object oldValue, final Object newValue) {
254:            }
255:
256:            public void firePropertyChange(final String propertyName,
257:                    final byte oldValue, final byte newValue) {
258:            }
259:
260:            public void firePropertyChange(final String propertyName,
261:                    final char oldValue, final char newValue) {
262:            }
263:
264:            public void firePropertyChange(final String propertyName,
265:                    final short oldValue, final short newValue) {
266:            }
267:
268:            public void firePropertyChange(final String propertyName,
269:                    final int oldValue, final int newValue) {
270:            }
271:
272:            public void firePropertyChange(final String propertyName,
273:                    final long oldValue, final long newValue) {
274:            }
275:
276:            public void firePropertyChange(final String propertyName,
277:                    final float oldValue, final float newValue) {
278:            }
279:
280:            public void firePropertyChange(final String propertyName,
281:                    final double oldValue, final double newValue) {
282:            }
283:
284:            public void firePropertyChange(final String propertyName,
285:                    final boolean oldValue, final boolean newValue) {
286:            }
287:
288:            private int getTextOffset() {
289:                return getIcon() != null ? getIcon().getIconWidth() + 2 : 0;
290:            }
291:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.