Source Code Cross Referenced for BrowserTreeCellRenderer.java in  » Database-Client » executequery » org » executequery » components » table » 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 » Database Client » executequery » org.executequery.components.table 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * BrowserTreeCellRenderer.java
003:         *
004:         * Copyright (C) 2002, 2003, 2004, 2005, 2006 Takis Diakoumis
005:         *
006:         * This program is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU General Public License
008:         * as published by the Free Software Foundation; either version 2
009:         * of the License, or any later version.
010:         *
011:         * This program is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014:         * GNU General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU General Public License
017:         * along with this program; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
019:         *
020:         */
021:
022:        package org.executequery.components.table;
023:
024:        import java.awt.Color;
025:        import java.awt.Component;
026:        import java.awt.Font;
027:        import java.util.Map;
028:
029:        import javax.swing.ImageIcon;
030:        import javax.swing.JTree;
031:        import javax.swing.UIManager;
032:        import javax.swing.tree.DefaultMutableTreeNode;
033:
034:        import org.executequery.Constants;
035:        import org.underworldlabs.swing.tree.AbstractTreeCellRenderer;
036:        import org.executequery.gui.browser.BrowserConstants;
037:        import org.executequery.gui.browser.BrowserTreeNode;
038:        import org.executequery.gui.browser.ConnectionObject;
039:        import org.executequery.gui.browser.DatabaseObject;
040:        import org.underworldlabs.swing.plaf.UIUtils;
041:
042:        /* ----------------------------------------------------------
043:         * CVS NOTE: Changes to the CVS repository prior to the 
044:         *           release of version 3.0.0beta1 has meant a 
045:         *           resetting of CVS revision numbers.
046:         * ----------------------------------------------------------
047:         */
048:
049:        /**
050:         * Tree cell renderer or the database browser.
051:         * <P>
052:         * @author   Takis Diakoumis
053:         * @version  $Revision: 1.6 $
054:         * @date     $Date: 2006/07/15 16:24:39 $
055:         */
056:        public class BrowserTreeCellRenderer extends AbstractTreeCellRenderer {
057:
058:            /** String literal '(connected)' */
059:            private static final String DEFAULT_CONNECTED = " (connected)";
060:
061:            /** Icon collection for nodes */
062:            private static Map icons;
063:
064:            /** this label's font */
065:            private static Font font;
066:
067:            private static Color textBackground;
068:            private static Color textForeground;
069:            private static Color selectedBackground;
070:            private static Color selectedTextForeground;
071:
072:            /**
073:             * Constructs a new instance and initialises any variables
074:             */
075:            public BrowserTreeCellRenderer(Map icons) {
076:                this .icons = icons;
077:                /*
078:                if (font == null) {
079:                    font = new Font("Dialog", Font.PLAIN, 11);
080:                }
081:                 */
082:
083:                textBackground = UIManager.getColor("Tree.textBackground");
084:                textForeground = UIManager.getColor("Tree.textForeground");
085:                selectedBackground = UIManager
086:                        .getColor("Tree.selectionBackground");
087:                selectedTextForeground = UIManager
088:                        .getColor("Tree.selectionForeground");
089:
090:                if (UIUtils.isGtkLookAndFeel()) {
091:                    // has default black border on selection - ugly and wrong!
092:                    setBorderSelectionColor(null);
093:                }
094:
095:                //setFont(font);
096:                sb = new StringBuffer();
097:            }
098:
099:            /**
100:             * Sets the value of the current tree cell to value. If 
101:             * selected is true, the cell will be drawn as if selected. 
102:             * If expanded is true the node is currently expanded and if 
103:             * leaf is true the node represets a leaf and if hasFocus 
104:             * is true the node currently has focus. tree is the JTree 
105:             * the receiver is being configured for. Returns the Component 
106:             * that the renderer uses to draw the value.
107:             *
108:             * @return the Component that the renderer uses to draw the value
109:             */
110:            public Component getTreeCellRendererComponent(JTree tree,
111:                    Object value, boolean isSelected, boolean isExpanded,
112:                    boolean isLeaf, int row, boolean hasFocus) {
113:
114:                this .hasFocus = hasFocus;
115:
116:                BrowserTreeNode bNode = null;
117:                DefaultMutableTreeNode child = (DefaultMutableTreeNode) value;
118:                DatabaseObject node = (DatabaseObject) child.getUserObject();
119:
120:                int type = node.getType();
121:                //Log.debug("node: " +node+ " type: " + type);
122:
123:                switch (type) {
124:
125:                case BrowserConstants.ROOT_NODE:
126:                    setIcon((ImageIcon) icons
127:                            .get(BrowserConstants.CONNECTIONS_IMAGE));
128:                    break;
129:
130:                case BrowserConstants.HOST_NODE:
131:                    ConnectionObject _node = (ConnectionObject) node;
132:                    if (_node.isConnected()) {
133:                        setIcon((ImageIcon) icons
134:                                .get(BrowserConstants.HOST_CONNECTED_IMAGE));
135:                    } else {
136:                        setIcon((ImageIcon) icons
137:                                .get(BrowserConstants.HOST_NOT_CONNECTED_IMAGE));
138:                    }
139:                    break;
140:
141:                case BrowserConstants.CATALOG_NODE:
142:                    setIcon((ImageIcon) icons
143:                            .get(BrowserConstants.CATALOG_IMAGE));
144:                    break;
145:
146:                case BrowserConstants.SCHEMA_NODE:
147:                    setIcon((ImageIcon) icons
148:                            .get(BrowserConstants.SCHEMA_IMAGE));
149:                    break;
150:
151:                case BrowserConstants.SYSTEM_FUNCTION_NODE:
152:
153:                    if (child.isLeaf())
154:                        setIcon((ImageIcon) icons
155:                                .get(BrowserConstants.SYSTEM_FUNCTIONS_IMAGE));
156:                    else
157:                        setIcon((ImageIcon) icons
158:                                .get(BrowserConstants.DATABASE_OBJECT_IMAGE));
159:
160:                    break;
161:
162:                case BrowserConstants.FUNCTIONS_NODE:
163:
164:                    if (child.isLeaf())
165:                        setIcon((ImageIcon) icons
166:                                .get(BrowserConstants.FUNCTIONS_IMAGE));
167:                    else
168:                        setIcon((ImageIcon) icons
169:                                .get(BrowserConstants.DATABASE_OBJECT_IMAGE));
170:
171:                    break;
172:
173:                case BrowserConstants.INDEX_NODE:
174:
175:                    if (child.isLeaf())
176:                        setIcon((ImageIcon) icons
177:                                .get(BrowserConstants.INDEXES_IMAGE));
178:                    else
179:                        setIcon((ImageIcon) icons
180:                                .get(BrowserConstants.DATABASE_OBJECT_IMAGE));
181:
182:                    break;
183:
184:                case BrowserConstants.PROCEDURE_NODE:
185:
186:                    if (child.isLeaf())
187:                        setIcon((ImageIcon) icons
188:                                .get(BrowserConstants.PROCEDURES_IMAGE));
189:                    else
190:                        setIcon((ImageIcon) icons
191:                                .get(BrowserConstants.DATABASE_OBJECT_IMAGE));
192:
193:                    break;
194:
195:                case BrowserConstants.SEQUENCE_NODE:
196:
197:                    if (child.isLeaf())
198:                        setIcon((ImageIcon) icons
199:                                .get(BrowserConstants.SEQUENCES_IMAGE));
200:                    else
201:                        setIcon((ImageIcon) icons
202:                                .get(BrowserConstants.DATABASE_OBJECT_IMAGE));
203:
204:                    break;
205:
206:                case BrowserConstants.SYNONYM_NODE:
207:
208:                    if (child.isLeaf())
209:                        setIcon((ImageIcon) icons
210:                                .get(BrowserConstants.SYNONYMS_IMAGE));
211:                    else
212:                        setIcon((ImageIcon) icons
213:                                .get(BrowserConstants.DATABASE_OBJECT_IMAGE));
214:
215:                    break;
216:
217:                case BrowserConstants.VIEW_NODE:
218:
219:                    if (child.isLeaf())
220:                        setIcon((ImageIcon) icons
221:                                .get(BrowserConstants.VIEWS_IMAGE));
222:                    else
223:                        setIcon((ImageIcon) icons
224:                                .get(BrowserConstants.DATABASE_OBJECT_IMAGE));
225:
226:                    break;
227:
228:                case BrowserConstants.SYSTEM_TABLE_NODE:
229:
230:                    bNode = (BrowserTreeNode) child;
231:
232:                    if (child.isLeaf() || !bNode.isTypeParent())
233:                        setIcon((ImageIcon) icons
234:                                .get(BrowserConstants.SYSTEM_TABLES_IMAGE));
235:                    else
236:                        setIcon((ImageIcon) icons
237:                                .get(BrowserConstants.DATABASE_OBJECT_IMAGE));
238:
239:                    break;
240:
241:                case BrowserConstants.TABLE_NODE:
242:
243:                    bNode = (BrowserTreeNode) child;
244:
245:                    if (child.isLeaf() || !bNode.isTypeParent())
246:                        setIcon((ImageIcon) icons
247:                                .get(BrowserConstants.TABLES_IMAGE));
248:                    else
249:                        setIcon((ImageIcon) icons
250:                                .get(BrowserConstants.DATABASE_OBJECT_IMAGE));
251:
252:                    break;
253:
254:                case BrowserConstants.COLUMN_NODE:
255:                    setIcon((ImageIcon) icons
256:                            .get(BrowserConstants.COLUMNS_IMAGE));
257:                    break;
258:
259:                case BrowserConstants.SYSTEM_DATE_TIME_FUNCTIONS_NODE:
260:                case BrowserConstants.SYSTEM_NUMERIC_FUNCTIONS_NODE:
261:                case BrowserConstants.SYSTEM_STRING_FUNCTIONS_NODE:
262:                    setIcon((ImageIcon) icons
263:                            .get(BrowserConstants.SYSTEM_FUNCTIONS_IMAGE));
264:                    break;
265:
266:                /*
267:                 case TRIGGER_NODE:
268:                 setIcon((ImageIcon)icons.get(SCHEMA_IMAGE));
269:                 break;
270:                
271:                 case OTHER_NODE:
272:                 setIcon((ImageIcon)icons.get(SCHEMA_IMAGE));
273:                 break; */
274:
275:                default:
276:                    setIcon((ImageIcon) icons
277:                            .get(BrowserConstants.DATABASE_OBJECT_IMAGE));
278:                    break;
279:
280:                }
281:
282:                String label = node.getName();
283:                if ((type == BrowserConstants.SCHEMA_NODE || type == BrowserConstants.CATALOG_NODE)
284:                        && node.isDefaultCatalog()) {
285:                    label += DEFAULT_CONNECTED;
286:                }
287:                setText(label);
288:
289:                if (node.getType() == BrowserConstants.HOST_NODE) {
290:                    setToolTipText(buildToolTip((ConnectionObject) node));
291:                } else {
292:                    setToolTipText(label);
293:                }
294:
295:                selected = isSelected;
296:                if (!selected) {
297:                    setForeground(textForeground);
298:                } else {
299:                    setForeground(selectedTextForeground);
300:                }
301:
302:                return this ;
303:            }
304:
305:            /** tool tip string buffer */
306:            private StringBuffer sb;
307:
308:            /**
309:             * Builds a HTML tool tip describing this tree node.
310:             *
311:             * @param the connection object
312:             */
313:            private String buildToolTip(ConnectionObject node) {
314:                // reset
315:                sb.setLength(0);
316:
317:                // build the html display
318:                sb.append("<html>");
319:                sb.append(Constants.TABLE_TAG_START);
320:                sb.append("<tr><td><b>");
321:                sb.append(node.getName());
322:                sb.append("</b></td></tr>");
323:                sb.append(Constants.TABLE_TAG_END);
324:                sb.append("<hr>");
325:                sb.append(Constants.TABLE_TAG_START);
326:                sb.append("<tr><td>Host:</td><td width='30'></td><td>");
327:                sb.append(node.getDatabaseConnection().getHost());
328:                sb.append("</td></tr><td>Data Source:</td><td></td><td>");
329:                sb.append(node.getDatabaseConnection().getSourceName());
330:                sb.append("</td></tr><td>User:</td><td></td><td>");
331:                sb.append(node.getDatabaseConnection().getUserName());
332:                sb.append("</td></tr><td>Driver:</td><td></td><td>");
333:                sb.append(node.getDatabaseConnection().getDriverName());
334:                sb.append("</td></tr>");
335:                sb.append(Constants.TABLE_TAG_END);
336:                sb.append("</html>");
337:                return sb.toString();
338:            }
339:
340:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.