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
Related
I m trying to write an eclipse plugin which is suppose to render xml file some different manner. What actually I want is to replace the name of the file displayed in the project explorer with one of its element without originally change the file name. for example I have a file named 1234.xml with content
<name> dinesh </dinesh>
<college> NITT </college>
So I want to change the name of 1234.xml to dinesh.xml in the project explorer.
Can anybody tell me what are the possible ways I can achieve this.
I am new to eclipse plugin development. So please provide me as much information as possible.
There is no automatic way (I mean refactor) for this, so you must manually do it:
Change name of file 1234.xml to dinesh.xml
Search in your project all references to 1234.xml with CTRL + H / file search and appropiate patterns:
Change all references found of 1234.xml to dinesh.xml
If some issue appears search for 1234 in all the files to check if file was references only by name
Well I find the answer of what I wanted to do...
I have extended decorator extension point of eclipse to provide custom label provider for the desired files ...
One more thing to access the xml attribute use regex instead of xml parsing . It will make things bit faster than xml parsing ...
Thanks
I am trying to create a PDF file using struts 2.Action class location is as follows.
/home/Jagan/MATCH/Jagan/src/ActionClasses/PDFFile.java
Here workspace starts from
/MATCH
In PDFFile.java.I am writing as given below and it is working fine.
pdfwriter=PdfWriter.getInstance(document,new
FileOutputStream("/home/Jagan/xyz.pdf"));
But i have to create this under the folder
/home/Jagan/MATCH/Jagan/PDFs
I should not use /home/Jagan/ as it will become hardcode if i have to run this application in other system.
I tried
pdfwriter=PdfWriter.getInstance(document,new
FileOutputStream("../../../PDFs/xyz.pdf"));
But it is not creating file.Even if it works it is not feasible solution (because "../../../" does not work in windows ).
Please suggest me a good way to specify path for creating file.
Adding to the question.
I have to provide download option for downloading this created file in JSP page.Which struts tag should i use. Please provide me syntax for that
downloading files has 2 aproaches:
1. you can return it with outstream result like is explained here
2. as you are trying to save the file first at filesystem then access it from another url.
Answer to your question is you should get servletContext.getRealPath("/WEB-INF"), and after that everything is relative to WEB-INF.
I should not use /home/Jagan/ as it will become hardcode if i have to run this application in other system.
Correct, Use following instead
System.getProperty("user.home");///home/Jagan/, it will return you path to your home dir
Anyone plz let us know what to do when we have some configuration file which is basically xml.I want to for example give the path to save the image(for my java program) in a folder from some config file (xml in my case).In that case where should the config file be kept.Rt now every thing is converted to jar file when i create a java standalone package.But i want to give some setting from xml file.What to do in that case.How is it possible.This article only provides to create a single jar file for java project but talks nothing about the configuration settings that u can provide from some external source.
Regards
Sagar
I'm not sure I fully understand your question, but if it is where to put the XML file with configuration information, you can place your xml file in the same directory as your jar file, and then pass the XML file name and path into the Jar on the command line when calling the Jar. If you're running it in Windows, this is often done using a shortcut. Then you can get the full path string for the Jar from the main method's String[] arg array that accepts the command parameters.
Sagar,
The fact your java program is a standalone package (.jar file) has no bearing on where your configuration file is stored. Your java package is a program and that program can read any file from the file system that it so desires; it does not have to be part of the code inside the IDE i.e. you don't have to write it when you write the program. What you do need is some way, when you start the program, to find and read said configuration file.
Depending on how you expect the program to be configured, you might put that file in a number of locations. For example, /etc/yourimageprogram/config.xml or c:\program files\yourimageprogram\config.xml or perhaps c:\users\Sagar\Application Settings\yourimageprogram\config.xml. Which you choose of those options really depends on what the use case is and that I can't help with.
However, there are some main points to reading any file:
Does it exist?
Are we allowed to open it for reading?
Are we allowed to open it for writing? Might want to know if we want to update the config?
In Java, typically, you would test this with:
File configfile = new File("C:\test.xml");
if ( configfile.exists() && configfile.canRead() )
{
// read the file
}
else
{
// decide what to do if no config exists.
// might be first run of app.
}
The next stage is to parse the file. There are a number of parsers available for XML including sax and org.w3c.dom. What you need to do is to use these to extract the information you require and store that in a class. Probably a singleton class as you're unlikely to have multiple configuration instances per instance of the program.
I suggest you read about XML Parsers and File Handling under Java. Also look at the File object. See all your options for file io in java. These should give you some indication of how to proceed.
I know that you can use java.util.Properties to read Java properties files.
See: Java equivalent to app.config?
Is there a standard place to put this file? In .NET we put application.exe.config in the same directory as application.exe. The application looks for it here by default.
Java can be made to look for a properties file in the class path but I am struggling to understand the filename/path structure to use and how to use either a standard .properties format or XML format file.
Assuming I have an API packaged in org_example_api.jar (the root package is org.example.api). I don't want to put the properties file inside the jar as it should be editable by the user. I want the user to be able to put the required configuration properties in either a .properties or .xml file somewhere relative to the classpath so I can find it without needing to know anything about the ir file system structure.
Will this work on all systems:
/classpath/org_example_api.jar
/classpath/org/example/api/config.properties OR
/classpath/org/example/api/config.xml
Code:
java.util.Properties = ? //NEED SOME HELP HERE
This purely depends on the type of application you are developing.
1) If it is a web application the best place is inside the WEB-INF/classes/ folder.
2) If you are developing a standalone application there are many approaches. From your example I think the following structure will work.
/<dist>/org_example_api.jar
/<dist>/config.xml
/<dist>/run.sh
In the run.sh you can start the java application providing the current directory also in the classpath. Something like this.
java -cp .:org_example_api.jar ClassToExecute
3) If it is an API distribution it is up to the end user. You can tell the user that they can provide the config.xml in the classpath which should follow some predefined structure. You can look at Log4J as an example in this case.
The world is wide open to you here. The only best practice is what works best for you:
Whatever program the user is running can require the path to the properties file as an argument
Your application can be configured to look in the current directory for config.properties.
If the file can't be found, you could maybe fall back to the user.home directory, or fall back to wherever your application is installed.
Personally I usually have my applications attempt to read properties files from the classpath - but I'm not in a world where I have end-users update/change the file.
Whatever option you choose, just make sure you clearly document it for your users so they know which file to edit and where it needs to be!
You can put the properties file in a directory or JAR in your CLASSPATH, and then use
InputStream is = getClass().getResourceAsStream("/path/goes/here");
Properties props = new Properties();
props.load(is);
(I noticed you mentioned this in your OP, but others may find the code useful.)
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".