📄 ontologysummaryframe.java
字号:
package toocom.ui;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.tree.*;
import javax.swing.event.*;
import java.util.*;
import toocom.ocgl.*;
/**
* This class represents the graphical window used to present and access the different objects of the ontology.
* It provides manipulation fonctions by using right mouse click.
*
* @author Fr閐閞ic F黵st
*/
public class OntologySummaryFrame extends JPanel implements MouseListener{
private JTree tree;
private DefaultTreeModel treeModel;
private DefaultMutableTreeNode top;
private DefaultMutableTreeNode conceptTypes;
private DefaultMutableTreeNode relationTypes;
private DefaultMutableTreeNode instances;
private DefaultMutableTreeNode axiomsSchema;
private DefaultMutableTreeNode axioms;
private MainFrame mf;
public OntologySummaryFrame(MainFrame mf){
super(true);
this.mf = mf;
top = new TooCoMMutableTreeNode(Constants.ONTOLOGY_LABEL,-1);
treeModel = new DefaultTreeModel(top);
tree = new JTree(treeModel);
tree.setEditable(false);
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
/*treeModel.addTreeModelListener(this);
tree.addTreeSelectionListener(new TreeSelectionListener(){
public void valueChanged(TreeSelectionEvent e){
treeSelectionChanged(e);
}
});*/
tree.addMouseListener(this);
tree.setShowsRootHandles(true);
tree.setCellRenderer(new TooCoMTreeCellRenderer());
conceptTypes = new DefaultMutableTreeNode(Constants.CONCEPT_TYPES_LABEL);
top.add(conceptTypes);
relationTypes = new DefaultMutableTreeNode(Constants.RELATION_TYPES_LABEL);
top.add(relationTypes);
instances = new DefaultMutableTreeNode(Constants.INSTANCES_LABEL);
top.add(instances);
axiomsSchema = new DefaultMutableTreeNode(Constants.AXIOMS_SCHEMA_LABEL);
top.add(axiomsSchema);
axioms = new DefaultMutableTreeNode(Constants.AXIOMS_LABEL);
top.add(axioms);
JScrollPane panel = new JScrollPane(tree);
this.add(tree);
}
public void mouseClicked(MouseEvent e){
TreePath path = tree.getPathForLocation(e.getX(),e.getY());
if((path != null) && (mf.getOntology() != null)){
tree.setSelectionPath(path);
if(e.getButton() == MouseEvent.BUTTON3){
if(path.getLastPathComponent() == instances){
new InstancePropertyFrame(mf,null);
}
if((path.getLastPathComponent() == top) && (mf.getOntology() != null)){
new OntologyPropertyFrame(mf,null);
}
if(path.getParentPath() != null){
if(path.getParentPath().getLastPathComponent() == instances){
new InstancePropertyFrame(mf,(Individual) mf.getOntology().getObject(((TooCoMMutableTreeNode) path.getLastPathComponent()).getId()));
}
if(path.getParentPath().getLastPathComponent() == axiomsSchema){
new AxiomPropertyFrame((Axiom) mf.getOntology().getObject(((TooCoMMutableTreeNode) path.getLastPathComponent()).getId()),mf,false);
}
if(path.getParentPath().getLastPathComponent() == axioms){
new AxiomPropertyFrame((Axiom) mf.getOntology().getObject(((TooCoMMutableTreeNode) path.getLastPathComponent()).getId()),mf,true);
}
}
}
if(e.getButton() == MouseEvent.BUTTON1){
if(path.getParentPath() != null){
if(((path.getParentPath().getLastPathComponent() == axioms) || (path.getParentPath().getLastPathComponent() == axiomsSchema))){
mf.getAxiomsFrame().loadAxiom((Axiom) mf.getOntology().getObject(((TooCoMMutableTreeNode) path.getLastPathComponent()).getId()));
mf.selectAxiomFrame();
}
if((path.getLastPathComponent() == conceptTypes) || (path.getParentPath().getLastPathComponent() == conceptTypes)){
mf.selectConceptTypesFrame();
}
if((path.getLastPathComponent() == relationTypes) || (path.getParentPath().getLastPathComponent() == relationTypes)){
mf.selectRelationTypesFrame();
}
}
}
}
}
public void mouseExited(MouseEvent e){}
public void mouseEntered(MouseEvent e){}
public void mousePressed(MouseEvent e){}
public void mouseReleased(MouseEvent e){}
private void addConceptType(ConceptType ct){
TooCoMMutableTreeNode node = new TooCoMMutableTreeNode("C-" + ct.getTerm(mf.getOntologyLanguage()),ct.getId());
treeModel.insertNodeInto(node,conceptTypes,conceptTypes.getChildCount());
tree.scrollPathToVisible(new TreePath(node.getPath()));
}
/** Returns the node corresponding to the given concept type (same id), null if any. */
public TooCoMMutableTreeNode getConceptTypeNode(ConceptType ct){
for(Enumeration e = conceptTypes.children();e.hasMoreElements();){
TooCoMMutableTreeNode node = (TooCoMMutableTreeNode) e.nextElement();
if(node.getId() == ct.getId()) return node;
}
return null;
}
private void addRelationType(RelationType rt){
TooCoMMutableTreeNode node = new TooCoMMutableTreeNode("R-" + rt.getTerm(mf.getOntologyLanguage()),rt.getId());
treeModel.insertNodeInto(node,relationTypes,relationTypes.getChildCount());
tree.scrollPathToVisible(new TreePath(node.getPath()));
}
/** Returns the node corresponding to the given relation type (same id), null if any. */
public TooCoMMutableTreeNode getRelationTypeNode(RelationType rt){
for(Enumeration e = relationTypes.children();e.hasMoreElements();){
TooCoMMutableTreeNode node = (TooCoMMutableTreeNode) e.nextElement();
if(node.getId() == rt.getId()) return node;
}
return null;
}
private void addInstance(Individual i){
TooCoMMutableTreeNode node = new TooCoMMutableTreeNode("I-" + i.getType().getTerm(mf.getOntologyLanguage()) + " : " + i.getTerm(mf.getOntologyLanguage()),i.getId());
treeModel.insertNodeInto(node,instances,instances.getChildCount());
tree.scrollPathToVisible(new TreePath(node.getPath()));
}
/** Returns the node corresponding to the given instance (same id), null if any. */
public TooCoMMutableTreeNode getInstanceNode(Individual i){
for(Enumeration e = instances.children();e.hasMoreElements();){
TooCoMMutableTreeNode node = (TooCoMMutableTreeNode) e.nextElement();
if(node.getId() == i.getId()) return node;
}
return null;
}
private void addAxiom(Axiom a){
if(this.getAxiomNode(a) == null){
TooCoMMutableTreeNode node = new TooCoMMutableTreeNode("A-" + a.getTerm(mf.getOntologyLanguage()),a.getId());
treeModel.insertNodeInto(node,axioms,axioms.getChildCount());
tree.scrollPathToVisible(new TreePath(node.getPath()));
}
}
private void addAxiomSchema(Axiom a){
if(this.getAxiomNode(a) == null){
TooCoMMutableTreeNode node = new TooCoMMutableTreeNode("A-" + a.getTerm(mf.getOntologyLanguage()),a.getId());
treeModel.insertNodeInto(node,axiomsSchema,axiomsSchema.getChildCount());
tree.scrollPathToVisible(new TreePath(node.getPath()));
}
}
/** Returns the node corresponding to the root of the summary, ie the node with the name
* of the ontology. */
public TooCoMMutableTreeNode getOntologyNode(){
return (TooCoMMutableTreeNode) top;
}
/** Returns the node corresponding to the given axiom or axiom schema (same id),
* null if any. */
public TooCoMMutableTreeNode getAxiomNode(Axiom a){
for(Enumeration e = axioms.children();e.hasMoreElements();){
TooCoMMutableTreeNode node = (TooCoMMutableTreeNode) e.nextElement();
if(node.getId() == a.getId()) return node;
}
for(Enumeration e = axiomsSchema.children();e.hasMoreElements();){
TooCoMMutableTreeNode node = (TooCoMMutableTreeNode) e.nextElement();
if(node.getId() == a.getId()) return node;
}
return null;
}
/** Repaint the ontology summary with the names of conceptual objects, according to the
* ontology language in use. */
public void refresh(){
this.clear();
if(mf.getOntology() != null) top.setUserObject(Constants.ONTOLOGY_LABEL + " : " + mf.getOntology().getTerm(mf.getOntologyLanguage()));
for(Iterator i = mf.getOntology().getOrganizedConceptTypesList(mf.getOntologyLanguage()).iterator();i.hasNext();){
this.addConceptType((ConceptType) i.next());
}
for(Iterator i = mf.getOntology().getOrganizedRelationTypesList(mf.getOntologyLanguage()).iterator();i.hasNext();){
this.addRelationType((RelationType) i.next());
}
for(Iterator i = mf.getOntology().getOrganizedIndividualsList(mf.getOntologyLanguage()).iterator();i.hasNext();){
this.addInstance((Individual) i.next());
}
for(Iterator i = mf.getOntology().getOrganizedAxiomsList(mf.getOntologyLanguage()).iterator();i.hasNext();){
Axiom a = (Axiom) i.next();
if(a.isFinalized()) this.addAxiomSchema(a);
else this.addAxiom(a);
}
}
public void clear(){
top.setUserObject(Constants.ONTOLOGY_LABEL);
this.conceptTypes.removeAllChildren();
this.relationTypes.removeAllChildren();
this.instances.removeAllChildren();
this.axiomsSchema.removeAllChildren();
this.axioms.removeAllChildren();
this.treeModel.reload();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -