X

Geertjan's Blog

  • April 29, 2008

org.openide.filesystems.FileUtil.findBrother

Geertjan Wielenga
Product Manager
The org.openide.filesystems.FileUtil.findBrother method is typically used by the Matisse GUI Builder so that if a file named "xyz.java" is in the same folder as a file named "xyz.frm", the two are merged together and opened as one in the editor. Specifically, FileUtil.findBrother takes a FileObject and a file extension, which is the file extension of the "brother" file.

There are several other conceivable scenarios where this functionality might be handy, such as Wicket, which typically has "xyz.java" in the same folder as "xyz.html". The latter provides the markup for the former. Below you can see my point, the Java files that have a matching HTML file (i.e., the same name) have a Wicket icon merged with their Java icon:

So, first create a new DataObject for text/x-java—and make sure it will install before the standard Java DataObject. Then, use the DataLoader to branch the DataObject, depending on whether a "brother" is found:

@Override
protected MultiDataObject createMultiObject(FileObject primaryFile) throws DataObjectExistsException, IOException {
FileObject bro = FileUtil.findBrother(primaryFile, "html");
if (null != bro) {
//Return our own data object:
return new WicketDataObject(primaryFile, this);
}
//Return the standard data object:
return new JavaDataObject(primaryFile, this);
}

Finally, in the Node, use org.openide.util.Utilities.mergeImages to merge a small image on top of the standard Java icon:

private static final String WICKET_ICON_BASE = 
"org/netbeans/findbrotherdemo/wicket_8x8.png";
private static final String JAVA_ICON_BASE =
"org/netbeans/modules/java/resources/class.gif";
@Override
public Image getIcon(int arg0) {
Image wicket = Utilities.loadImage(WICKET_ICON_BASE);
Image java = Utilities.loadImage(JAVA_ICON_BASE);
Image result = Utilities.mergeImages(java, wicket, 8, 8);
return result;
}

Install the module and then Java files with HTML brothers will have our Wicket icon merged with their Java icon.

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.