OutputWriter writer;
@Override
public void performAction() {
InputOutput io = IOProvider.getDefault().getIO("PNG Images", false);
try {
writer = io.getOut();
io.select();
io.getOut().reset();
Setcps = GlobalPathRegistry.getDefault().getPaths(ClassPath.BOOT);
for (ClassPath cp : cps) {
Listentries = cp.entries();
for (ClassPath.Entry entry : entries) {
ClassPath entryCp = entry.getDefiningClassPath();
FileObject[] fos = entryCp.getRoots();
for (FileObject fo : fos) {
cycleThroughKids(fo);
}
}
}
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
}
private void cycleThroughKids(final FileObject fo) {
final Thread thread = new Thread() {
@Override
public void run() {
if (fo.getChildren().length > 0) {
for (FileObject oneKid : fo.getChildren()) {
if (oneKid.getMIMEType().equals("image/png")) { {
try {writer.println(oneKid.getPath(), new PngOutPutListener(oneKid));
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
}
cycleThroughKids(oneKid);
}
}
}
};
thread.start();
}
The line in bold above has as its final argument the creation of a NetBeans API OutputListener class, which magically returns a hyperlink for each line added to the Output window, as defined below:
class PngOutPutListener implements OutputListener {
FileObject oneKid;
PngOutPutListener(FileObject oneKid) {
this.oneKid = oneKid;
}
@Override
public void outputLineAction(OutputEvent arg0) {
try {
DataObject dObj = DataObject.find(oneKid);
OpenCookie open = (OpenCookie) dObj.getCookie(OpenCookie.class);
if (open != null) {
open.open();
}
} catch (DataObjectNotFoundException ex) {
Exceptions.printStackTrace(ex);
}
}
@Override
public void outputLineSelected(OutputEvent arg0) {}
@Override
public void outputLineCleared(OutputEvent arg0) {}
}
When a link is clicked, which is an event that a hyperlink implies should be performed, the file is opened in the editor. This is how the hyperlinks look in the Output window:
Upon being clicked, the related PNG file opens in the editor. Not useful in any way, though.
GlobalPathRegistry.getDefault().getPaths(ClassPath.BOOT) will only work if there are some (Java) projects open. You might prefer to use JavaPlatformManager directly to get the default JDK (or prompt the user for which JDK to list).