Programmatically change/add icons?

Is there a way to programmatically add/change icons to a theme? I am being lazy here, did not feel like drilling through the source to see. In the latest beta versions I keep encountering messages like this:

A quick grep through the source indicates quite a few of the classes are using “gif” vs “png”.

Note: The following two commands assume that they are being executed relatively closely above or in the source tree.

List file names using “gif”

find . -name "*.java" -exec grep \-l \"*.gif\" {} \;

List the gory details of the file and display the line number where the “gif” was found.

find . -name "*.java" -exec grep \-n \"*.gif\" {} \;

I really don’t want to touch the source, maybe some of those gifs are suppose to be there?

For now I just dump the ITMILL/ into the web content, and then add in the missing icons. It’s just annoying to do this for every new project. Over-riding the icons programatically would be nicer, just point the dodgy piece wanting a gif to the appropriate png.

Andy

Hmm, Answer my own question.

Figured this out after tracking down the Resource.

Just add a new ThemeResource( theme_path_to_icon);

        
       /**
         * Gets the icon of this file.
         * 
         * @return the icon of this file.
         */
        public Resource getIcon() {
            LOG.debug("FileItem.getIcon()");
            if ( file.isDirectory() ) {
                return new ThemeResource("icon/files/folder.png");
            }
            return new ThemeResource("icon/files/file.png");
        }

If using the new default theme, the above would point to “icons/16/document.png” for the file and “icons/16/folder.png” for the folder.

Summary, use ThemeResource to add an icon programatically:

    
    ThemeResource("icon/files/file.png");

Hi,

What examples are you running when you’re getting those messages?

As you figured out, an application can use a icon from a theme by using a ThemeResource. The message indicates that an application is using a ThemResource that is not actually found in the theme being used.

I’ll take this opportunity to explain a bit more:

When using a ThemeResource, the point is that you can change the icon depeding on theme, so you can (for example) have a different “save.gif” in your “blue” and “red” theme, just make sure you have all the icons you need in both themes.

ThemeResource is not the only type of Resource you can use for icons though - you might for instance want to use ClassResource, depending on your application.

Best Regards,
Marc

Marc,

I am using itmill-toolkit-5.3.0_trunk_20090204, specifically the com.itmill.toolkit.data.util.FilesystemContainer class. This class is not the problem [see below]
.

Just re-tested it again to make sure it was using that build, also removed my local ITMILL directory, same message:

For now I just copy the FilesystemContainer class, rename it to FileSystemContainer and over-ride the getIcon() to add the ‘png’ icon that I want using ThemeResource(). This works.


The real issue is from the FileTypeResolver class (at least what I can see).

com.itmill.toolkit.service.FileTypeResolver


 46:            "icon/files/file.gif");
230:        addIcon("inode/drive", new ThemeResource("icon/files/drive.gif"));
231:        addIcon("inode/directory", new ThemeResource("icon/files/folder.gif"));

I also found “.gif” in these files

[quote]
com.itmill.toolkit.terminal.gwt.client.ui.richtextarea.IRichTextToolbar.java
com.itmill.toolkit.terminal.gwt.client.ApplicationConnection.java
[/quote]—

I test with the latest releases, and two older stable ones. I use the newer because it has features I need or want. I use older to make sure code I write is upgradable. … if this makes any sense :-). The Horizontal and Vertical layout changes come to mind as one such feature/change.

Andy