Source Code Cross Referenced for IconFactory.java in  » GIS » GeoTools-2.4.1 » org » geotools » gui » 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 » GIS » GeoTools 2.4.1 » org.geotools.gui.swing 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *    GeoTools - OpenSource mapping toolkit
003:         *    http://geotools.org
004:         *    (C) 2006, Geotools Project Managment Committee (PMC)
005:         *    
006:         *    This library is free software; you can redistribute it and/or
007:         *    modify it under the terms of the GNU Lesser General Public
008:         *    License as published by the Free Software Foundation; either
009:         *    version 2.1 of the License, or (at your option) any later version.
010:         *
011:         *    This library 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 GNU
014:         *    Lesser General Public License for more details.
015:         */
016:        package org.geotools.gui.swing;
017:
018:        // J2SE dependencies
019:        import java.net.URL;
020:        import java.util.HashMap;
021:        import java.util.Map;
022:        import javax.swing.Icon;
023:        import javax.swing.ImageIcon;
024:        import javax.swing.JButton;
025:
026:        /**
027:         * A factory for {@link Icon}. This class caches some of the created icons. This factory should be
028:         * used only for small icons, since they may be cached for the JVM lifetime. This class is used
029:         * especially for <A HREF="http://java.sun.com/developer/techDocs/hi/repository/">Java look and
030:         * feel Graphics Repository</A>. This class is thread safe.
031:         *
032:         * @since 2.3
033:         * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/extension/widgets-swing/src/main/java/org/geotools/gui/swing/IconFactory.java $
034:         * @version $Id: IconFactory.java 20883 2006-08-07 13:48:09Z jgarnett $
035:         * @author Martin Desruisseaux
036:         */
037:        public final class IconFactory {
038:            /**
039:             * The default factory instance.
040:             */
041:            public static final IconFactory DEFAULT = new IconFactory();
042:
043:            /**
044:             * The class loader to uses.
045:             */
046:            private final ClassLoader loader;
047:
048:            /**
049:             * The icons already loaded.
050:             */
051:            private final Map icons = new HashMap();
052:
053:            /**
054:             * Do not allows instantiation of this class.
055:             */
056:            private IconFactory() {
057:                loader = getClass().getClassLoader();
058:            }
059:
060:            /**
061:             * Returns the icon for the specified name, or {@code null} if none. If this method has
062:             * already been invoked for the specified path, then the previously created icon is returned.
063:             *
064:             * @param  path The icon path, relative to the application classpath.
065:             * @return The icon, or {@code null} if no image was found for the specified path.
066:             */
067:            public synchronized Icon getIcon(final String path) {
068:                Icon icon = (Icon) icons.get(path);
069:                if (icon == null) {
070:                    URL url = loader.getResource(path);
071:                    if (url != null) {
072:                        icon = new ImageIcon(url);
073:                        icons.put(path, icon);
074:                    }
075:                }
076:                return icon;
077:            }
078:
079:            /**
080:             * Returns an icon for the specified name and description, or {@code null} if none.
081:             *
082:             * @param  path The icon path, relative to the application classpath.
083:             * @param  description brief textual description of the image, or {@code null} if none.
084:             * @return The icon, or {@code null} if no image was found for the specified path.
085:             */
086:            public Icon getIcon(final String path, final String description) {
087:                Icon icon = getIcon(path);
088:                if (description != null) {
089:                    if (icon instanceof  ImageIcon) {
090:                        icon = new ImageIcon(((ImageIcon) icon).getImage(),
091:                                description);
092:                    }
093:                }
094:                return icon;
095:            }
096:
097:            /**
098:             * Returns a button with the specified image.
099:             *
100:             * @param  path The icon path, relative to the application classpath.
101:             * @param  description brief textual description of the image, or {@code null} if none.
102:             * @param  fallback A text to put in the button if the image were not found.
103:             */
104:            public JButton getButton(final String path,
105:                    final String description, final String fallback) {
106:                final Icon icon = getIcon(path, description);
107:                final JButton button;
108:                if (icon != null) {
109:                    button = new JButton(icon);
110:                } else {
111:                    button = new JButton(fallback);
112:                }
113:                button.setToolTipText(description);
114:                return button;
115:            }
116:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.