UseProtegeFormsInApplications
From Protege Wiki
Revision as of 14:22, June 3, 2008 by JenniferVendetti (talk | contribs) (migrated this page from protege web site)
Using Protege Forms in Other Applications
Protege forms can be used by external applications to display knowledge base instances. These applications may have no need to display any of the rest of the Protege user interface such as the main frame, Classes tab, etc.
Below is an example of how to display an instance from within your application. You first load the Protege project file and then pass the name of the instance you wish to display to the showInstance method of the ProjectView object.
Please note that the following code works with both Protege-Frames and Protege-OWL ontologies.
package app;
import java.util.*;
import javax.swing.*;
import edu.stanford.smi.protege.model.*;
public class MyExternalApplication {
private static String projectFileName = "c:\\temp\\newspaper\\newspaper.pprj";
private static String instanceName = "instance_00015";
public static void main(String[] args) {
Collection errors = new ArrayList();
Project project = new Project(projectFileName, errors);
if (errors.isEmpty()) {
// show an instance in a top level frame
project.show(instanceName);
// create a panel that contains and instance form and display it in my top level frame
Instance instance = project.getKnowledgeBase().getInstance(instanceName);
JComponent panel = (JComponent) project.createRuntimeClsWidget(instance);
JFrame frame = new JFrame("My Application Frame");
frame.getContentPane().add(panel);
frame.pack();
frame.show();
} else {
System.out.println("There were load errors");
}
}
}