package greenfoot.core;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Properties;
| A set of read-only project properties, read from a file. Used in exported Greenfoot
| scenarios which just need to read the data without modifying it. The file is located
| using the class-loader, which makes sense in an exported JAR.
|
public class ExportedProjectProperties
implements ReadOnlyProjectProperties{
| Name of the greenfoot package file that holds information specific to a
| package/project
|
public static final String GREENFOOT_PKG_NAME = "project.greenfoot";
| Holds the actual properties
|
private Properties properties;
| Creates a new properties instance with the file loaded from the root of this class loader.
|
public ExportedProjectProperties()
{
properties = new Properties();
load();
}
| Tries to load the project-file with the default class loader.
|
private void load()
{
URL probsFile = this.getClass().getResource("/" + GREENFOOT_PKG_NAME);
InputStream is = null;
try {
is = probsFile.openStream();
properties.load(is);
}
catch (IOException ioe) {
}
finally {
if (is != null) {
try {
is.close();
}
catch (IOException e) {
}
}
}
}
| Gets a property as in Java's Properties class. Thread-safe.
|
public synchronized String getString(String key, String defaultValue)
{
return properties.getProperty(key, defaultValue);
}
}
top,
use,
map,
class ExportedProjectProperties
. ExportedProjectProperties
. load
. getString
70 neLoCode
+ 9 LoComm