This is a DRAFT!
This is a continuation of the tutorial for building POV-Ray support for NetBeans. If you have not read the first or second, third and fourth parts of this tutorial, you may want to start there.MainFileProvider - find the main file of a project -
the one to render when the whole file is built, and allow a POV-Ray
scene file node to find out if it is the main file (so it can
bold-face its display name).RendererService - an API a POV-Ray file node can call
to ask that it be rendered as an image ViewService - an API a POV-Ray file can call to ask
that its associated image be shown in the IDE, rendering it if necessary.
org.netbeans.modules.examples.api.povray
called MainFileProvider, and implement it as follows:
public abstract class MainFileProvider {
public abstract FileObject getMainFile();
public abstract void setMainFile (FileObject file);
public boolean isMainFile (FileObject file) {
return obj.equals(getMainFile());
}
}
org.netbeans.modules.examples.api.povray
called RendererService, and implement it as follows:
public static final String PROJECT_RENDERER_KEY_PREFIX = "renderer.";
public static final String PRODUCTION_RENDERER_SETTINGS_NAME = "production";
public abstract FileObject render(FileObject scene, String propertiesName);
public abstract FileObject render (FileObject scene, Properties renderSettings);
public abstract FileObject render (FileObject scene);
public abstract FileObject render();
public abstract String[] getAvailableRendererSettingsNames();
public abstract Properties getRendererSettings (String name);
public abstract String getPreferredRendererSettingsNames();
public abstract String getDisplayName (String settingsName);
org.netbeans.modules.examples.api.povray
called ViewService, and implement it as follows:
boolean isRendered (FileObject file);
boolean isUpToDate (FileObject file);
void view (FileObject file);
(if you are wondering why the first two are abstract classes instead of interfaces,
the answer is simple: In the case of MainFileProvider, it allows
us to implement isMainFile(); in the case of the other
RendererService, it is highly probably that there will be new
requirements for it in the future, and you can add methods [with some sort of
default implementation] to an abstract class semi-backward-compatibly [name
collisions with subclasses are still possible], but not to an interface.
ViewService is simple and well-defined enough that it will probably never
change).
org.netbeans.api... to
indicate visually that they are intended to be API (and thus kept
backward compatible).
AbstractFileObject for a fast way
to find it).MainFileProvider
and ViewService to import FileObject.
Node will need to
look up the project it belongs to, and then query the project's Lookup
to try to find an implementation of our API classes.
org.netbeans.examples.modules.povfile.PovrayDataNode in
the code editor.PovrayDataNode:
private FileObject getFile() {
return getDataObject().getPrimaryFile();
}
private Object getFromProject (Class clazz) {
Object result;
Project p = FileOwnerQuery.getOwner(getFile());
if (p != null) {
result = p.getLookup().lookup (clazz);
} else {
result = null;
}
return result;
}
private boolean isMainFile() {
MainFileProvider prov = (MainFileProvider)
getFromProject (MainFileProvider.class);
boolean result;
if (prov == null) {
result = false;
} else {
FileObject myFile = getFile();
result = prov.isMainFile(myFile);
}
return result;
}
public String getHtmlDisplayName() {
return isMainFile() ? "" + getDisplayName() + "" : null;
}
What the above code does is fairly straightforward. getFile()
returns a FileObject (NetBeans
virtual
filesystem file) that this Node represents.
getFromProject tries to find the project that owns the file,
and if it finds one, queries its
Lookup,
asking it for an instance of the Class that was passed into
this method (e.g. one of the classes in the API we just defined).
isMainFile() uses the above two methods to decide if this
Node represents the "main file" of the project (the
one that should be rendered by POV-Ray if the user chooses to "build"
the project - POV-Ray supports file includes, so there may be many files in
a project, but only one master image. getHtmlDisplayName() is
where the rubber meets the road - this method will return a boldface
HTML string if this Node represents the main file.