Changing "Favorites" Tooltip in Java Help - java

In my helpset file, I'm declaring a favorites view, using
<view>
<name>Lesezeichen</name>
<label>Lesezeichen</label>
<type>javax.help.FavoritesView</type>
<data></data>
</view>
This automatically adds an appropriate button to the toolbar (in the swing application). Unfortunately, the tooltip of the button reads "Add to favorites". I would like to replace this by my own text, but didn't find anything about this in the documentation or using a google search. Any ideas or pointers?
Disclaimer: I already posted this question to JavaRanch, didn't get an answer yet, though.

If you extract the src.jar (rename it to src.zip and extract) and open the java class jh2.0/src/src/javax/help/resources/Constants.java you will notice that in the section
// Tooltips for Actions
is located entry for localization:
{ "tooltip.FavoritesAction", "Add to Favorites"},
This constant is missing from the jh2.0/src/src/javax/help/resources/Constants_de.java which is used in your case. Just add the right translation, compile the source or just this class and add it to the jh.jar (you may treat the jar as a simple zip archive)
Yes, I know this is dirty hack, but generally JavaHelp is quite useful

Now this sounds weird.
The ResourceBundle mechanism supports to "override" the class resource content by using a .properties file with the resource bundle.
Try placing the looked up resource bundle as a properties file in the respective folder denoted by the bundle name.
E.g. if HelpUtilities looks after javax.help.resources.Constants by calling
ResourceBundle.getBundle("javax.help.resources.Constants", locale);
you'd be placing your file in a folder structure at /javax/help/resources/Constants_de_DE.properties. This must be located in your applications "working directory".

Related

How to remove the compass from nasa worldwind

I am working on a project related with nasa worldwind.
Can anybody explain how can I remove the compass ,which is
located at the top right of screen.
simply remove the following code from your Javascript file:
wwd.addLayer(new WorldWind.CompassLayer());
Good luck !
Since you've tagged the question with swing and java tags I assume you are referring to WorldWindJava and the solution in the other answer related to WebWorldWind will not work. To remove the compass layer from WorldWind you can do it either programmatically or via the worldwind.layers.xml file.
For a programmatic approach you can look at this question:
How to Hide(or remove the) Standard layer (like star,atmosphere,earth at night) in World wind java
and then call that method there as: removeLayerWithName("Compass").
The XML configuration file approach is the easiest and you can see a full example of the worldwind.layers.xml file here. So, basically you copy that file, remove the:
<Layer className="gov.nasa.worldwind.layers.CompassLayer"/>
entry there at the bottom. You then need to place this file in a folder that is located in your application's current-working-directory. I suggest you give it a unique name to differentiate it from the default worldwind.layers.xml file for example worldwind.custom.layers.xml. You then need to specify that WorldWind should use this custom file by modifying the worldwind.xml file. You can get a template of this file here. Copy this file to the same folder in your application's current-working-directory. Also give it a different name like worldwind.custom.xml. You then need to modify this entry:
<LayerList href="config/worldwind.layers.xml"/>
in worldwind.custom.xml to point to your file like so:
<LayerList href="some-folder/worldwind.custom.layers.xml"/>
Lastly, you need to specify that WorldWind should use your custom configuration file via the gov.nasa.worldwind.app.config.document system property. So, if you have a script to launch your app you add the following in your run.sh file:
java -cp "...classpath-stuff" -Dgov.nasa.worldwind.app.config.document="some-folder/worldwind.custom.xml" com.example.MainClass

Accessing files under .jar in a swing application?

Referring to my previous question, I want to ask that how can I read a file in different
folder into the similar .jar.
The folder hierarchy and details are provided with that question.
My main problem is with a line of code:
JTextPane textPane = ... //general initialization
textPane.setPage("path/file.html");
The problem is I have to keep that file.html in my .jar.
Moreover I would like to know suggestions on this topic.
For loading resources in a JAR, you can use Class.getResource(). This works equally well when loading from an ordinary folder structure not in a JAR:
textPane.setPage(ThisClass.class.getResource("relative/path/to/file.html"));
The path here is from whatever folder ThisClass.class is in. It is generally better to explicitly name the class rather than using this.getClass(), which may end up looking in a different (and unintended) location if this method is called for a subclass.

Does Java getResource method only work with particular extensions?

The following piece of code works fine
getClass().getResource("/index.xml");
However when I do a full refactor to
getClass().getResource("/index.html");
The above line throws NullPointerException. I know I have refactored correctly because I rename the file using IDE smart refactor i.e. the file index.html definitely exists in the same directory. As soon as I switch back to
getClass().getResource("/index.xml");
Everything is fine again. Is there any reason why only the .xml extension works?
As #a_horse_with_no_name mentions, using getResourceAsStream( ) should work fine with any file and any extension.
I'd be inclined to believe (based on the information presented) that your IDE hasn't properly refreshed its file hierarchy after the refactor. I'd suggest running a full clean and build of your project, see if that helps the situation.
So, most of the other answers, the class/class loader shouldn't be looking at file extension You could write a ClassLoader which did that, but it would be odd.
I'm going to take a stab at what your problem is. I am guessing using some IDE (you don't specify which) that is copying certain files from your source folder into the destination (either a jar or a directory of classes and resources). For Java code, you want the compiled .class object files there and not the .java sources. So the IDE will be configured, with some reasonable default [magic], to copy files with only certain extensions. HTML files were used for old package JavaDocs (package-info.html rather than package-info.java which can include package-wide annotations), so are arguably reasonable to exclude by default.
Therefore, you should investigate what the project is doing in this area, and change any configurations accordingly.
Using getResourceAsStream() should work with any file extension (at least it does for me)
Recognised Java Resources are either a class extending ResourceBundle or .property file.
You can write your own extenstions to enable Resource to be gathered from other extensions.
I'm unsure why .xml files are a viable extension. Are you using Java 7?
From the JavaDoc guide:
The name of a resource is independent of the Java implementation; in
particular, the path separator is always a slash (/). However, the
Java implementation controls the details of how the contents of the
resource are mapped into a file, database, or other object containing
the actual resource.
A resource is identified by a string consisting of a sequence of
substrings, delimited by slashes (/), followed by a resource name.
Each substring must be a valid Java identifier. The resource name is
of the form shortName or shortName.extension. Both shortName and
extension must be Java identifiers.
And read this doc which tell us : an absolute resource name is constructed from the given resource name using this algorithm.
getResource() will work regardless of the type of resource. All it does it return a URL. This example works fine for me.
public class Example {
public static void main(String... args) {
System.out.println(Example.class.getResource("jaxb.properties"));
System.out.println(Example.class.getResource("test.xml"));
System.out.println(Example.class.getResource("foo.html"));
System.out.println(Example.class.getResource("danger.exe"));
}
}

Java Properties File not loading

I need a configuration file in my program to store some information, I saw some examples of properties files and was trying to use them but whenever I try this second line on NetBeans i get 'Package sortConfig doesn't exist' '<identifier> Expected' and 'Illegal start of type'.
The problem is I already saw some 10 examples all doing this in the same way, and I have no clue to what's going on.
Properties sortConfig = new Properties();
sortConfig.load(this.getClass().getClassLoader().getResourceAsStream("sortConfig.properties"));
Any help would be appreciated
my .java classes and my properties file are on the src, inside the same package folder
It looks like you do not have the fully qualified path to your properties file. You can get to it in 2 ways:-
Using java.util.ResourceBundle:
ResourceBundle bundle
=ResourceBundle.getBundle("br.com.example.sortConfig");
//.properties is implied
or
Using ClassLoader.getResouceAsStream:
sortConfig.load(this.getClass().getClassLoader().getResourceAsStream("br/com/example/sortConfig.propertie"));
For a good tutorial on how to load properties files resources check out this link.
An alternative could be to use this.getClass().getResourceAsStream() which accepts relative pathnames (relative to the package your class is in, that is), so you could simply write
sortConfig.load(this.getClass().getResourceAsStream("sortConfig.properties"));
This is useful when you specifically want to rely on your class and properties file being in the same package. (So when you move one during a refactoring, you'll have to move the other too.)

File Explorer - Altering File/Folder associated icon programmatically

Have you noticed modifications to the icons associated with files and folders when using file explorer in windows/linux while having a svn client installed (e.g., TortoiseSVN). Basically, when a folder is saved in a SVN repository, normally there is a tiny green tick icon added to the associated file icon. I want to know how TortoiseSVN/Dropbox/... do this and whether I can achieve similar results using Java6 JDIC ?
Thanks,
-A
Those are called "icon overlays" in Shell jargon. Here's a start:
http://msdn.microsoft.com/en-us/library/cc144123(v=VS.85).aspx
-scott
This should help you out..
http://java.sun.com/developer/technicalArticles/J2SE/Desktop/jdic_assoc/
org.jdesktop.jdic.filetypes.Association
The Association class allows
programmers to create new file types
or edit existing ones. The class
includes methods to edit the file
extension type, the MIME extension
type, the icon that goes with the file
type, and the actions that are
associated with the file type.associated with the file type.

Categories