versionedontology.java
来自「Semantic Web Ontology Editor」· Java 代码 · 共 1,850 行 · 第 1/5 页
JAVA
1,850 行
/*
* Created on Apr 9, 2005
*
*/
package org.mindswap.swoop.change;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.StringReader;
import java.io.StringWriter;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.Vector;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JEditorPane;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTextField;
import javax.swing.JToolBar;
import javax.swing.JTree;
import javax.swing.SpringLayout;
import javax.swing.border.Border;
import javax.swing.border.EtchedBorder;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.TreePath;
import org.mindswap.swoop.ModelChangeEvent;
import org.mindswap.swoop.SwoopModel;
import org.mindswap.swoop.SwoopModelListener;
import org.mindswap.swoop.annotea.Annotea;
import org.mindswap.swoop.annotea.AnnoteaClient;
import org.mindswap.swoop.annotea.Description;
import org.mindswap.swoop.renderer.ontology.OntologyListRenderer;
import org.mindswap.swoop.treetable.JTreeTable;
import org.mindswap.swoop.utils.change.BooleanElementChange;
import org.mindswap.swoop.utils.change.EnumElementChange;
import org.mindswap.swoop.utils.owlapi.CorrectedRDFRenderer;
import org.mindswap.swoop.utils.ui.ChangeComparator;
import org.mindswap.swoop.utils.ui.OntologyComparator;
import org.mindswap.swoop.utils.ui.SpringUtilities;
import org.mindswap.swoop.utils.ui.SwoopIcons;
import org.semanticweb.owl.model.OWLClass;
import org.semanticweb.owl.model.OWLEntity;
import org.semanticweb.owl.model.OWLException;
import org.semanticweb.owl.model.OWLOntology;
import org.semanticweb.owl.model.change.ChangeVisitor;
import org.semanticweb.owl.model.change.OntologyChange;
import org.semanticweb.owl.model.helper.OWLBuilder;
/**
* @author Aditya
*
*/
public class VersionedOntology extends JPanel implements ActionListener, KeyListener, TreeSelectionListener, HyperlinkListener, MouseListener, SwoopModelListener {
// constants
public static int ANNOTATED_CHANGES = 0;
public static String serverURL = "http://www.mindswap.org/2004/annotea/Annotation";
public static int REDUNDANT_CHANGE = 1;
public static int REPOSITORY_CHANGE = 2;
public static int LOCAL_CHANGE = 3;
public static String separator = "SWOOP-ANNOTATED-CHANGE-SET";
AnnoteaClient client;
OWLClass annotType;
SwoopModel swoopModel;
VersionControl controlHandler;
// repository info
URI repositoryURI;
String repositoryAuthor;
String reposityCreatedDate;
public URI baseOntologyURI;
public int headVersionNumber;
// versioning info
List repChanges; // only corresponds to new changes to be added to repository, (those already at the repository are directly added to the tree)
TreeTableNode repRoot; // root of repChange tree
TreeTableNode newCommitNode; // new commit being made
int versioningFormat;
// for caching purposes
URL repHeaderLoc; // actual URL location of repository header annotation
TreeTableNode[] versionNodes; // array of version commit TreeTableNodes
Description[] versionDescriptions; // array of version commit Descriptions
// 0 - rep. header Description, 1..headVersionNum: version Descriptions
// swoop ontology info
OWLOntology swoopOnt, syncOntology;
URI swoopOntURI;
List ontChanges;
JComboBox ontBox;
// UI info
Font tahoma = new Font("Tahoma", Font.PLAIN, 11);
final String[] cNames = {"Author", "Description", "Date", "Entity"};
JTextField swoopOntFld;
JLabel swoopOntLbl;
JRadioButton existingOntRadio, newOntRadio;
JButton refreshBtn, swoUpdateBtn, swoCommitBtn, swoDeleteBtn, swoSelAllBtn, swoTestBtn, swoFilterBtn;
JSplitPane splitPane, ontTablePane, repTablePane;
JCheckBox advancedChk;
boolean advanced = true;
JPanel leftPanel, rightPanel;
JTextField repAuthorFld, repDateFld, repURLFld, repBaseOntFld;
JComboBox repTypeBox;
JTreeTable ontChangeTT, repChangeTT;
JEditorPane ontChangeEdPane, repChangeEdPane;
JButton repUpdateBtn, repCommitBtn, repDeleteBtn, repSelAllBtn, repTestBtn, repFilterBtn;
JButton moveRBtn, moveLBtn;
JPopupMenu swoFilterMenu, repFilterMenu;
JMenuItem swoRedFMenu, swoRepFMenu, swoLocFMenu, repRedFMenu;
public boolean DEBUG = true;
JLabel statusBar;
int splitPaneDivPos;
// cache info
Map nodeMap;
public VersionedOntology(SwoopModel swoopModel, VersionControl controlHandler) {
init(swoopModel, controlHandler);
}
// another constructor which accepts a preloaded versionDescriptions[] array and
// parses it to obtain all saved versioning info
public VersionedOntology(SwoopModel swoopModel, VersionControl controlHandler, URI repURI, Description[] verDesc) {
init(swoopModel, controlHandler);
this.repositoryURI = repURI;
this.versionDescriptions = verDesc;
// parse version Description array
try {
// first parse header
Description header = versionDescriptions[0];
// parse header description to get author, date, baseOntologyURI
this.repositoryAuthor = header.getAuthor();
this.reposityCreatedDate = header.getCreated();
this.baseOntologyURI = new URI(header.getAnnotatedEntityDefinition());
// and headVersionNumber
this.headVersionNumber = Integer.parseInt(header.getBody());
// also get actual URL location of annotation
this.repHeaderLoc = header.getLocation();
// set UI accordingly
this.repURLFld.setText(this.repositoryURI.toString());
this.repAuthorFld.setText(this.repositoryAuthor);
this.repDateFld.setText(this.reposityCreatedDate);
this.repBaseOntFld.setText(this.baseOntologyURI.toString());
this.toggleRepOptions(false);
// now for each version, parse and add node to repRoot
for (int ctr=1; ctr<=this.headVersionNumber; ctr++) {
Description version = versionDescriptions[ctr];
TreeTableNode mainNode = this.parseSingleCommit(version);
// set params on mainNode
mainNode.swoopChange.isOnRepository = true;
mainNode.location = version.getLocation();
versionNodes[ctr] = mainNode;
}
// again set UI accordingly
this.refreshRepTreeTable(true);
}
catch (Exception ex) {
ex.printStackTrace();
}
}
/*
* Simple initialization of this class
*/
private void init(SwoopModel swoopModel, VersionControl controlHandler) {
this.swoopModel = swoopModel;
this.swoopModel.addListener(this);
this.controlHandler = controlHandler;
this.versionNodes = new TreeTableNode[99999];
this.versionDescriptions = new Description[99999];
this.nodeMap = new HashMap();
this.setupUI();
this.refreshOntBox();
this.setupFilterPopupMenus();
this.toggleAdvanced(false);
}
/**
* @return Returns the headVersionNumber.
*/
public int getHeadVersionNumber() {
return headVersionNumber;
}
/**
* @param headVersionNumber The headVersionNumber to set.
*/
public void setHeadVersionNumber(int headVersionNumber) {
this.headVersionNumber = headVersionNumber;
}
/**
* @return Returns the repositoryAuthor.
*/
public String getRepositoryAuthor() {
return repositoryAuthor;
}
/**
* @param repositoryAuthor The repositoryAuthor to set.
*/
public void setRepositoryAuthor(String repositoryAuthor) {
this.repositoryAuthor = repositoryAuthor;
}
/**
* @return Returns the repositoryURL.
*/
public URI getRepositoryURL() {
return repositoryURI;
}
/**
* @param repositoryURL The repositoryURL to set.
*/
public void setRepositoryURL(URI repositoryURL) {
this.repositoryURI = repositoryURL;
}
/**
* @return Returns the reposityCreatedDate.
*/
public String getReposityCreatedDate() {
return reposityCreatedDate;
}
/**
* @param reposityCreatedDate The reposityCreatedDate to set.
*/
public void setReposityCreatedDate(String reposityCreatedDate) {
this.reposityCreatedDate = reposityCreatedDate;
}
/**
* @return Returns the versioningFormat.
*/
public int getVersioningFormat() {
return versioningFormat;
}
/**
* @param versioningFormat The versioningFormat to set.
*/
public void setVersioningFormat(int versioningFormat) {
this.versioningFormat = versioningFormat;
}
private void setupUI() {
// setup border
Border border = new EtchedBorder();
// explorer style interface - left: swoop ontology, right: repository ontology
// LEFT PANEL
// setup ontology panel
swoopOntLbl = (JLabel) this.initComponent(JLabel.class, "Specify Swoop Ontology");
swoopOntFld = (JTextField) this.initComponent(JTextField.class, "");
ontBox = new JComboBox();
ontBox.setRenderer(new OntologyListRenderer(swoopModel));
existingOntRadio = (JRadioButton) this.initComponent(JRadioButton.class, "Existing: ");
newOntRadio = (JRadioButton) this.initComponent(JRadioButton.class, "New URI:");
ButtonGroup group = new ButtonGroup();
group.add(existingOntRadio);
group.add(newOntRadio);
existingOntRadio.setSelected(true);
refreshBtn = (JButton) this.initComponent(JButton.class, "Refresh");
JPanel ontSelPanel = this.createPanel(null, ontBox, refreshBtn);
JPanel radio1 = this.createPanel(existingOntRadio, ontSelPanel, null);
JPanel radio2 = this.createPanel(newOntRadio, swoopOntFld, null);
JPanel ontPanel = new JPanel();
ontPanel.setLayout(new GridLayout(5,1));
ontPanel.add(swoopOntLbl);
ontPanel.add(radio1);
ontPanel.add(radio2);
ontPanel.add(new JLabel(""));
ontPanel.add(new JLabel(""));
// create swoop ontology toolbar
swoDeleteBtn = (JButton) this.initComponent(JButton.class, "Delete");
swoSelAllBtn = (JButton) this.initComponent(JButton.class, "Select All");
swoTestBtn = (JButton) this.initComponent(JButton.class, "Test All");
swoFilterBtn = (JButton) this.initComponent(JButton.class, "Filter");
swoFilterBtn.addMouseListener(this);
JToolBar swoToolBar = new JToolBar();
swoToolBar.add(swoSelAllBtn);
swoToolBar.add(swoDeleteBtn);
swoToolBar.add(swoTestBtn);
swoToolBar.add(swoFilterBtn);
// ontPanel.setBorder(border);
// create ont changes panel
JPanel ontChangePanel = new JPanel();
ontChangePanel.setLayout(new BorderLayout());
// initialize change treetable and change editorpane
ontChangeTT = new JTreeTable(new DefaultTreeTableModel(getTreeRoot(), cNames));
ontChangeTT.setFont(tahoma);
ontChangeTT.getTree().setRootVisible(false);
ontChangeTT.getTree().addTreeSelectionListener(this);
ontTablePane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
ontTablePane.setTopComponent(new JScrollPane(ontChangeTT));
ontChangeEdPane = new JEditorPane();
ontChangeEdPane.setContentType("text/html");
ontChangeEdPane.setEditable(false);
ontChangeEdPane.addHyperlinkListener(this);
ontTablePane.setBottomComponent(new JScrollPane(ontChangeEdPane));
ontChanges = new ArrayList();
// initialize button panel
JPanel ontBtnPanel = new JPanel();
ontBtnPanel.setLayout(new GridLayout(1,4));
ontBtnPanel.add(new JLabel(""));
swoUpdateBtn = (JButton) this.initComponent(JButton.class, "Update");
swoCommitBtn = (JButton) this.initComponent(JButton.class, "Commit");
ontBtnPanel.add(swoUpdateBtn);
ontBtnPanel.add(swoCommitBtn);
ontBtnPanel.add(new JLabel(""));
ontChangePanel.add(ontTablePane, "Center");
ontChangePanel.add(ontBtnPanel, "South");
moveRBtn = (JButton) this.initComponent(JButton.class, "");
SwoopIcons swi = new SwoopIcons();
moveRBtn.setIcon(swi.nextIcon);
moveLBtn = (JButton) this.initComponent(JButton.class, "");
moveLBtn.setIcon(swi.prevIcon);
JPanel movePanel = this.createColPanel(moveRBtn, moveLBtn);
ontChangePanel.add(movePanel, "East");
leftPanel = new JPanel();
leftPanel.setLayout(new BorderLayout());
JPanel northPnl = new JPanel();
northPnl.setLayout(new BorderLayout());
northPnl.add(ontPanel, "Center");
northPnl.add(swoToolBar, "South");
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?