package bluej.pkgmgr;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
import threadchecker.OnThread;
import threadchecker.Tag;
| Reference to the Greenfoot project file(s). A Greenfoot project file is
| basically just a BlueJ package with some extra information added.
|
| @author Poul Henriksen
|
@OnThread(Tag.Any)
public class GreenfootProjectFile
implements PackageFile{
private static final String pkgfileName = "project.greenfoot";
private File dir;
private File pkgFile;
| @see PackageFileFactory
|
@OnThread(Tag.Any)
GreenfootProjectFile(File dir)
{
this.dir = dir;
this.pkgFile = new File(dir, pkgfileName);
}
public String toString()
{
return dir.toString() + File.separator + pkgfileName;
}
public void load(Properties p)
throws IOException
{
FileInputStream input = null;
try {
if (pkgFile.canRead()) {
input = new FileInputStream(pkgFile);
}
else {
throw new IOException("Can't read from project file: " + pkgFile);
}
p.load(input);
}
finally {
if (input != null) {
input.close();
}
}
}
| Save the given properties to the file.
|
| @throws IOException if something goes wrong while trying to write the
| file.
|
public void save(Properties props)
throws IOException
{
if (!pkgFile.canWrite())
{
throw new IOException("Greenfoot project file not writable: " + this);
}
FileOutputStream output = null;
try
{
output = new FileOutputStream(pkgFile);
String header = "Greenfoot project file";
props.store(output, header);
}
catch (IOException e)
{
throw new IOException("Error when storing properties to Greenfoot project file: " + this);
}
finally
{
if (output != null)
{
output.close();
}
}
}
| Whether a Greenfoot package file exists in this directory.
|
public static boolean exists(File dir)
{
if (dir == null)
return false;
if (dir.getPath().endsWith(":\\"))
return false;
if (!dir.isDirectory())
return false;
File packageFile = new File(dir, pkgfileName);
return packageFile.exists();
}
| Whether this file is the name has the name of a Greenfoot project file.
|
public static boolean isProjectFileName(String fileName)
{
return fileName.endsWith(pkgfileName);
}
| Creates the Greenfoot project file if it does not already exist.
|
| @return true if it created a package file, false if it didn't create any package files.
| @param dir The directory to create package file in.
| @throws IOException If the package file could not be created.
|
public boolean create()
throws IOException
{
File pkgFile = new File(dir, pkgfileName);
if (pkgFile.exists()) {
return false;
}
else {
pkgFile.createNewFile();
return true;
}
}
}
top,
use,
map,
class GreenfootProjectFile
. toString
. load
. save
. exists
. isProjectFileName
. create
158 neLoCode
+ 13 LoComm