Java Doc for IconsFactory.java in  » Swing-Library » jide-common » com » jidesoft » icons » 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 » jide common » com.jidesoft.icons 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   com.jidesoft.icons.IconsFactory

IconsFactory
public class IconsFactory (Code)
IconsFactory provides a consistent way to access icon resource in any application.

Any application usually need to access image files. One way to do it is to put those image files in the installation and access them use direct file access. However this is not a good way because you have to know the full path to the image file. So a better way that most Java applications take is to bundle the image files with in the jar and use class loader to load them.

For example, if a class Foo needs to access image files foo.gif and bar.png, we put the image files right below the source code under icons subfolder. See an example directory structure below.

 /src/com/jidesoft/Foo.java
 /icons/foo.gif
 /icons/bar.png
 
When you compile the java class, you copy those images to class output directory like this.
 /classes/com/jidesoft/Foo.class
 /icons/foo.gif
 /icons/bar.png
 
Notes: In IntelliJ IDEA's "Compile" tab of "Project Property" dialog, there is a way to set "Resource Pattern". Here is the setting on my computer - "?*.properties;?*.xml;?*.html;?*.tree;?*.gif;?*.png;?*.jpeg;?*.jpg;?*.vm;?*.xsd;?*.ilayout;?*.gz;?*.txt" for your reference. If so, all your images will get copies automatically to class output folder. Although I haven't tried, I believe most Java IDEs have the same or similar feature. This feature will make the usage of IconsFactory much easier.

If you setup directory structure as above, you can now use IconsFactory to access the images like this.


 ImageIcon icon = IconsFactory.get(Foo.class, "icons/foo.gif");
 
IconsFactory will cache the icon for you. So next time if you get the same icon, it will get from cache instead of reading from disk again.

There are a few methods on IconsFactory to create difference variation from the original icon. For example, IconsFactory.getDisabledImageIcon(Class,String) will get the imaage icon with disabled effect.

We also suggest you to use the template below to create a number of IconsFactory classes in your application. The idea is that you should have one for each functional area so that all your image files can be grouped into each functional area. All images used in that functional area should be put under the folder where this IconsFactory is. Here is an template.


 class TemplateIconsFactory {
 public static class Group1 {
 public final static String IMAGE1 = "icons/image11.png";
 public final static String IMAGE2 = "icons/image12.png";
 public final static String IMAGE3 = "icons/image13.png";
 }
 

public static class Group2 { public final static String IMAGE1 = "icons/image21.png"; public final static String IMAGE2 = "icons/image22.png"; public final static String IMAGE3 = "icons/image23.png"; }

public static ImageIcon getImageIcon(String name) { if (name != null) return IconsFactory.getImageIcon(TemplateIconsFactory.class, name); else return null; }

public static void main(String[] argv) { IconsFactory.generateHTML(TemplateIconsFactory.class); } }

In your own IconsFactory, you can further divide images into different groups. The example above has two groups. There is also a convenient method getImageIcon() which takes just the icon name.

In the template, we defined the image names as constants. When you have a lot of images, it's hard to remember all of them when writing code. If using the IconsFactory above, you can use


 ImageIcon icon = TemplateIconsFactory.getImageIcon(TemplateIconsFactory.Group1.IMAGE1);
 
without saying the actual image file name. With the help of intelli-sense (or code completion) feature in most Java IDE, you will find it is much easier to find the icons you want. You can refer to JIDE Components Developer Guide to see a screenshot of what it looks like in IntelliJ IDEA.

You probably also notice this is a main() method in this template. You can run it. When you run, you will see a message printed out like this.


 "File is generated at "... some directory ...\com.jidesoft.icons.TemplateIconsFactory.html". Please copy it to the same directory as TemplateIconsFactory.java"
 
if you follow the instrcution and copy the html file to the same location as the source code and open the html, you will see the all image files defined in this IconsFactory are listed nicely in the page.


Field Summary
public static  ImageIconEMPTY_ICON
    
static  Map<String, ImageIcon>disableIcons
    
static  Map<String, ImageIcon>enhancedIcons
    
static  Map<String, ImageIcon>icons
    


Method Summary
public static  ImageIconcreateBrighterImage(Image image)
     Creates a brighter image from an input image.
public static  ImageIconcreateBrighterImage(Component c, Icon icon)
     Creates a gray version from an input image.
public static  ImageIconcreateGrayImage(Image image)
     Creates a gray version from an input image.
public static  ImageIconcreateGrayImage(Component c, Icon icon)
     Creates a gray version from an input image.
public static  ImageIconcreateMaskImage(Component c, Icon icon, Color oldColor, Color newColor)
     Creates a version from an input image which replaces one color with another color.
Parameters:
  c - The component to get properties useful for painting, e.g.
public static  ImageIconcreateNegativeImage(Image image)
     Creates a gray version from an input image.
public static  ImageIconcreateNegativeImage(Component c, Icon icon)
     Creates a negative version from an input black image which basically replaces black pixel with white pixel.
Parameters:
  c - The component to get properties useful for painting, e.g.
public static  ImageIconfindImageIcon(Class clazz, String fileName)
     Gets ImageIcon by passing class and a relative image file path.
public static  voidgenerateHTML(Class clazz)
     Generates HTML that lists all icons in IconsFactory.
public static  ImageIcongetBrighterImageIcon(Class clazz, String fileName)
     Gets a brighter ImageIcon by passing class and a relative image file path.
public static  ImageIcongetDisabledImageIcon(Class clazz, String fileName)
     Gets a disabled version of ImageIcon by passing class and a relative image file path.
public static  ImageIcongetIcon(Component c, ImageIcon icon, int x, int y, int width, int height)
     Gets part of the image from input image icon.
public static  ImageIcongetIcon(Component c, ImageIcon icon, int x, int y, int width, int height, int destWidth, int destHeight)
     Gets part of the image from input image icon.
public static  ImageIcongetIcon(Component c, ImageIcon icon, int x, int y, int width, int height, int imageType)
     Gets part of the image from input image icon.
public static  ImageIcongetIcon(Component c, ImageIcon icon, int x, int y, int width, int height, int imageType, int destWidth, int destHeight)
     Gets part of the image from input image icon.
public static  ImageIcongetImageIcon(Class clazz, String fileName)
     Gets ImageIcon by passing class and a relative image file path.

Please note, getImageIcon will print out error message to stderr if image is not found. The reason we did so is because we want you to make sure all image files are there in your application.

public static  ImageIcongetOverlayIcon(Component c, ImageIcon icon, ImageIcon overlayIcon, int location)
     Gets a new icon with the overlayIcon paints over the orginal icon.
Parameters:
  c - the component where the returned icon will be used.
public static  ImageIcongetOverlayIcon(Component c, ImageIcon icon, ImageIcon overlayIcon, int location, Insets insets)
     Gets a new icon with the overlayIcon paints over the orginal icon.
Parameters:
  c - the component where the returned icon will be used.
public static  ImageIcongetOverlayIcon(Component c, ImageIcon icon, ImageIcon overlayIcon, int x, int y)
     Gets a new icon with the overlayIcon paints over the orginal icon.
Parameters:
  c - the component where the returned icon will be used.

Field Detail
EMPTY_ICON
public static ImageIcon EMPTY_ICON(Code)



disableIcons
static Map<String, ImageIcon> disableIcons(Code)



enhancedIcons
static Map<String, ImageIcon> enhancedIcons(Code)



icons
static Map<String, ImageIcon> icons(Code)





Method Detail
createBrighterImage
public static ImageIcon createBrighterImage(Image image)(Code)
Creates a brighter image from an input image. If input image is null, a blank ImageIcon will be returned.
Parameters:
  image - image dimmed version of the image



createBrighterImage
public static ImageIcon createBrighterImage(Component c, Icon icon)(Code)
Creates a gray version from an input image. Usually gray icon indicates disabled. If input icon is null, a blank ImageIcon will be returned.
Parameters:
  c - The component to get properties useful for painting, e.g. the foreground or background color.
Parameters:
  icon - icon gray version of the image



createGrayImage
public static ImageIcon createGrayImage(Image image)(Code)
Creates a gray version from an input image. Usually gray icon indicates disabled. If input image is null, a blank ImageIcon will be returned.
Parameters:
  image - image gray version of the image



createGrayImage
public static ImageIcon createGrayImage(Component c, Icon icon)(Code)
Creates a gray version from an input image. Usually gray icon indicates disabled. If input icon is null, a blank ImageIcon will be returned.
Parameters:
  c - The component to get properties useful for painting, e.g. the foreground or background color.
Parameters:
  icon - icon gray version of the image



createMaskImage
public static ImageIcon createMaskImage(Component c, Icon icon, Color oldColor, Color newColor)(Code)
Creates a version from an input image which replaces one color with another color.
Parameters:
  c - The component to get properties useful for painting, e.g. the foreground or background color.
Parameters:
  icon - icon
Parameters:
  oldColor - the old color to be replaced.
Parameters:
  newColor - the new color that will replace the old color. the image after replacing the color.



createNegativeImage
public static ImageIcon createNegativeImage(Image image)(Code)
Creates a gray version from an input image. Usually gray icon indicates disabled. If input image is null, a blank ImageIcon will be returned.
Parameters:
  image - image gray version of the image



createNegativeImage
public static ImageIcon createNegativeImage(Component c, Icon icon)(Code)
Creates a negative version from an input black image which basically replaces black pixel with white pixel.
Parameters:
  c - The component to get properties useful for painting, e.g. the foreground or background color.
Parameters:
  icon - icon the negative version of the image



findImageIcon
public static ImageIcon findImageIcon(Class clazz, String fileName) throws IOException(Code)
Gets ImageIcon by passing class and a relative image file path.
Parameters:
  clazz - the Class
Parameters:
  fileName - relative file name the ImageIcon
throws:
  IOException - when image file is not found.



generateHTML
public static void generateHTML(Class clazz)(Code)
Generates HTML that lists all icons in IconsFactory.
Parameters:
  clazz - the IconsFactory class



getBrighterImageIcon
public static ImageIcon getBrighterImageIcon(Class clazz, String fileName)(Code)
Gets a brighter ImageIcon by passing class and a relative image file path.
Parameters:
  clazz -
Parameters:
  fileName - the ImageIcon



getDisabledImageIcon
public static ImageIcon getDisabledImageIcon(Class clazz, String fileName)(Code)
Gets a disabled version of ImageIcon by passing class and a relative image file path.
Parameters:
  clazz -
Parameters:
  fileName - the ImageIcon



getIcon
public static ImageIcon getIcon(Component c, ImageIcon icon, int x, int y, int width, int height)(Code)
Gets part of the image from input image icon. It bascially takes a snapshot of the input image at {x, y} location and the size is width x height.
Parameters:
  c - the component where the returned icon will be used. The component is used as the ImageObserver. It could be null.
Parameters:
  icon - the original icon. This is the larger icon where a sub-image will be created using this method.
Parameters:
  x - the x location of the sub-image, relative to the original icon.
Parameters:
  x - the y location of the sub-image, relative to the original icon.
Parameters:
  width - the width of the sub-image. It should be less than the width of the original icon.
Parameters:
  height - the height of the sub-image. It should be less than the height of the original icon. an new image icon that was part of the input image icon.



getIcon
public static ImageIcon getIcon(Component c, ImageIcon icon, int x, int y, int width, int height, int destWidth, int destHeight)(Code)
Gets part of the image from input image icon. It bascially takes a snapshot of the input image at {x, y} location and the size is width x height, then resize it to a size of destWidth x destHeight.
Parameters:
  c - the component where the returned icon will be used. The component is used as the ImageObserver. It could be null.
Parameters:
  icon - the original icon. This is the larger icon where a sub-image will be created using this method.
Parameters:
  x - the x location of the sub-image, relative to the original icon.
Parameters:
  x - the y location of the sub-image, relative to the original icon.
Parameters:
  width - the width of the sub-image. It should be less than the width of the original icon.
Parameters:
  height - the height of the sub-image. It should be less than the height of the original icon.
Parameters:
  destWidth - the width of the returned icon. The sub-image will be resize if the destWidth is not the same as the width.
Parameters:
  destHeight - the height of the returned icon. The sub-image will be resize if the destHeight is not the same as the height. an new image icon that was part of the input image icon.



getIcon
public static ImageIcon getIcon(Component c, ImageIcon icon, int x, int y, int width, int height, int imageType)(Code)
Gets part of the image from input image icon. It bascially takes a snapshot of the input image at {x, y} location and the size is width x height.
Parameters:
  c - the component where the returned icon will be used. The component is used as the ImageObserver. It could be null.
Parameters:
  icon - the original icon. This is the larger icon where a small icon will be created using this method.
Parameters:
  x - the x location of the smaller icon, relative to the original icon.
Parameters:
  x - the y location of the smaller icon, relative to the original icon.
Parameters:
  width - the width of the smaller icon. It should be less than the width of the original icon.
Parameters:
  height - the height of the smaller icon. It should be less than the height of the original icon.
Parameters:
  imageType - image type is defined in BufferedImage, such as BufferedImage.TYPE_INT_ARGB, BufferedImage.TYPE_INT_RGB etc. an new image icon that was part of the input image icon.



getIcon
public static ImageIcon getIcon(Component c, ImageIcon icon, int x, int y, int width, int height, int imageType, int destWidth, int destHeight)(Code)
Gets part of the image from input image icon. It bascially takes a snapshot of the input image at {x, y} location and the size is width x height, then resize it to a size of destWidth x destHeight. if the original icon is null or the specified location is outside the original icon, EMPTY_ICON will be returned.
Parameters:
  c - the component where the returned icon will be used. The component is used as the ImageObserver. It could be null.
Parameters:
  icon - the original icon. This is the larger icon where a sub-image will be created using this method.
Parameters:
  x - the x location of the sub-image, relative to the original icon.
Parameters:
  x - the y location of the sub-image, relative to the original icon.
Parameters:
  width - the width of the sub-image. It should be less than the width of the original icon.
Parameters:
  height - the height of the sub-image. It should be less than the height of the original icon.
Parameters:
  imageType - image type is defined in BufferedImage, such as BufferedImage.TYPE_INT_ARGB, BufferedImage.TYPE_INT_RGB etc.
Parameters:
  destWidth - the width of the returned icon. The sub-image will be resize if the destWidth is not the same as the width.
Parameters:
  destHeight - the height of the returned icon. The sub-image will be resize if the destHeight is not the same as the height. an new image icon that was part of the input image icon.



getImageIcon
public static ImageIcon getImageIcon(Class clazz, String fileName)(Code)
Gets ImageIcon by passing class and a relative image file path.

Please note, getImageIcon will print out error message to stderr if image is not found. The reason we did so is because we want you to make sure all image files are there in your application. If you ever see the error message, you should correct it before shipping the product. But if you just want to test if the image file is there, you don't want any error message print out. If so, you can use IconsFactory.findImageIcon(Class,String) method. It will throw IOException when image is not found.
Parameters:
  clazz - the Class
Parameters:
  fileName - relative file name the ImageIcon




getOverlayIcon
public static ImageIcon getOverlayIcon(Component c, ImageIcon icon, ImageIcon overlayIcon, int location)(Code)
Gets a new icon with the overlayIcon paints over the orginal icon.
Parameters:
  c - the component where the returned icon will be used. The component is used as the ImageObserver. It could be null.
Parameters:
  icon - the original icon
Parameters:
  overlayIcon - the overlay icon.
Parameters:
  location - the location as defined in SwingConstants - CENTER, NORTH, SOUTH, WEST, EAST, NORTH_EAST, NORTH_WEST, SOUTH_WEST and SOUTH_EAST. the new icon.



getOverlayIcon
public static ImageIcon getOverlayIcon(Component c, ImageIcon icon, ImageIcon overlayIcon, int location, Insets insets)(Code)
Gets a new icon with the overlayIcon paints over the orginal icon.
Parameters:
  c - the component where the returned icon will be used. The component is used as the ImageObserver. It could be null.
Parameters:
  icon - the original icon
Parameters:
  overlayIcon - the overlay icon.
Parameters:
  location - the location as defined in SwingConstants - CENTER, NORTH, SOUTH, WEST, EAST, NORTH_EAST, NORTH_WEST, SOUTH_WEST and SOUTH_EAST.
Parameters:
  insets - the insets to the border. This parameter has no effect if the location is CENTER. For example, if the location is WEST, insets.left will be the gap of the left side of theoriginal icon and the left side of the overlay icon. the new icon.



getOverlayIcon
public static ImageIcon getOverlayIcon(Component c, ImageIcon icon, ImageIcon overlayIcon, int x, int y)(Code)
Gets a new icon with the overlayIcon paints over the orginal icon.
Parameters:
  c - the component where the returned icon will be used. The component is used as the ImageObserver. It could be null.
Parameters:
  icon - the original icon
Parameters:
  overlayIcon - the overlay icon.
Parameters:
  x - the x location relative to the original icon where the overlayIcon will be pained.
Parameters:
  y - the y location relative to the original icon where the overlayIcon will be pained.



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.