ontologydisplay.java
来自「Semantic Web Ontology Editor」· Java 代码 · 共 1,199 行 · 第 1/3 页
JAVA
1,199 行
} public boolean isURL(String str) { try { URL uri = new URL(str); } catch (Exception ex) { return false; } return true; } public void hyperlinkUpdate(HyperlinkEvent event) { String hLink = event.getDescription(); JEditorPane sourceRend = (JEditorPane) event.getSource(); if (isURL(hLink)) sourceRend.setToolTipText(hLink); else sourceRend.setToolTipText(""); // if hyperlink is clicked if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { // if hyperlink is URI if (isURI(hLink)) { try { URI uri = new URI(hLink); OWLOntology ont = swoopModel.getOntology(uri); if (ont != null) { ontHideBox.removeActionListener(this); ontList.setSelectedValue(ont, true); ontHideBox.setSelectedItem(ont); ontHideBox.addActionListener(this); } else { swoopHandler.termDisplay.selectEntity(hLink); } } catch (Exception e) { System.out.println(e.getMessage()); } } else if (hLink.startsWith("<EditURL")) { // edit the url of the ontology! editOntologyURL(true); } else if (hLink.startsWith("<AddO-IMP")) { // add imports to an ontology addImports(); } else if (hLink.startsWith("<AddO-ANN")) { // add annotation to an ontology PopupAddAnnotation popup = new PopupAddAnnotation(swoopModel, true); popup.setLocation(200, 200); popup.show(); } // else // if (hLink.startsWith("<RESTAT")) { // // recompute stats for ontology // swoopModel.removeOntStats(swoopModel.selectedOntology); // // refresh display which will cause a recompute // this.renderOntology(); // } else if (hLink.startsWith("<PSTAT:")) { // display prop stats String statKey = hLink.substring(hLink.indexOf(":") + 1, hLink .length()); HashMap statMap = swoopModel .getOntStats(swoopModel.selectedOntology); Set statVal = new HashSet(); if (statKey.equals(SwoopStatistics.MAX_DEPTH_PROP_TREE) || statKey.equals(SwoopStatistics.MIN_DEPTH_PROP_TREE)) { List list = (List) statMap.get(statKey); statVal = (Set) list.get(1); } else statVal = (HashSet) statMap.get(statKey); // prop attribs // or multiple // inherited // props try { swoopHandler.termDisplay.lookupPanel.printResults( swoopModel.selectedOntology, new HashSet(), statVal, new HashSet(), statKey, swoopModel .shortForm(swoopModel.selectedOntology .getURI())); } catch (OWLException e) { e.printStackTrace(); } } else if (hLink.startsWith("<CSTAT:")) { // display class stats String statKey = hLink.substring(hLink.indexOf(":") + 1, hLink .length()); HashMap statMap = swoopModel .getOntStats(swoopModel.selectedOntology); Set statVal = new HashSet(); // if set of disjoint axioms, expand to get classes in set if (statKey.equals(SwoopStatistics.NO_DISJOINT)) { Set disjAxioms = (HashSet) statMap.get(statKey); for (Iterator iter = disjAxioms.iterator(); iter.hasNext();) { OWLDisjointClassesAxiom axiom = (OWLDisjointClassesAxiom) iter .next(); try { statVal.addAll(axiom.getDisjointClasses()); } catch (OWLException e1) { e1.printStackTrace(); } } } else if (statKey.equals(SwoopStatistics.MAX_DEPTH_CLASS_TREE) || statKey.equals(SwoopStatistics.MIN_DEPTH_CLASS_TREE) || statKey.equals(SwoopStatistics.MAX_BRANCHING_FACTOR) || statKey.equals(SwoopStatistics.MIN_BRANCHING_FACTOR)) { List list = (List) statMap.get(statKey); statVal = (Set) list.get(1); } else statVal = (HashSet) statMap.get(statKey); // multiple // inherited // classes try { swoopHandler.termDisplay.lookupPanel.printResults( swoopModel.selectedOntology, statVal, new HashSet(), new HashSet(), statKey, swoopModel .shortForm(swoopModel.selectedOntology .getURI())); } catch (OWLException e) { e.printStackTrace(); } } else if (hLink.startsWith("<DLEXP:")) { // display DL expressivity String express = hLink.substring(hLink.indexOf(":") + 1, hLink .length()); JEditorPane ep = new JEditorPane(); ep.setEditable(false); ep.setContentType("text/html"); ep.setText(express); JOptionPane.showMessageDialog(this, new JScrollPane(ep)); } else if (hLink.startsWith("<Undo")) { try { List changes = new ArrayList(swoopModel .getUncommittedChanges()); System.out.println("Undo " + hLink); // parse Undo hyper-link int pos = hLink.lastIndexOf(":") + 1; int hashCode = Integer.parseInt(hLink.substring(pos, hLink .length())); int index = 0; while (index < changes.size()) { if (changes.get(index).hashCode() == hashCode) break; index++; } OntologyChange removeChange = (OntologyChange) changes .get(index); System.out.println("Undo " + index + " of " + changes.size() + " " + removeChange); changes.remove(removeChange); swoopModel.setUncommittedChanges(new ArrayList(changes)); swoopHandler.termDisplay.applyChangesBtn .setEnabled(swoopModel.getUncommittedChanges() .size() > 0); swoopHandler.termDisplay.undoChangesBtn .setEnabled(swoopModel.getUncommittedChanges() .size() > 0); this.refreshEditorMode(); } catch (Exception ex) { ex.printStackTrace(); } } else if (hLink.startsWith("<Delete")) { handleDeleteLink(hLink); } } } /** * Add a Remove* OntologyChange when the user clicks on the "Delete" * hyperlink in the SwoopOntologyInfo pane. Get the components required for * the change from the hashCode stored in the hLink and the current selected * Ontology * * @param hLink */ private void handleDeleteLink(String hLink) { try { // parse DELETE hyper-link int pos1 = hLink.indexOf("-"); int pos2 = hLink.lastIndexOf(":"); String hashCode = hLink.substring(pos2 + 1, hLink.length()); String titleCode = hLink.substring(pos1 + 1, pos2); SwoopOntologyInfo ontInfoRend = (SwoopOntologyInfo) renderers .get(0); Object obj = ontInfoRend.OWLObjectHash.get(hashCode); if (titleCode.equals("IMP")) { // Remove Imports Change OWLOntology currOnt = swoopModel.getSelectedOntology(); OWLOntology impOnt = (OWLOntology) obj; RemoveImport change = new RemoveImport(currOnt, impOnt, null); swoopModel.addUncommittedChange(change); } else if (titleCode.equals("ANN")) { // Remove Annotation Instance OWLOntology currOnt = swoopModel.getSelectedOntology(); if (obj instanceof OWLAnnotationInstance) { OWLAnnotationInstance oai = (OWLAnnotationInstance) obj; RemoveAnnotationInstance change = new RemoveAnnotationInstance( currOnt, currOnt, oai.getProperty(), oai .getContent(), null); swoopModel.addUncommittedChange(change); } } swoopHandler.termDisplay.applyChangesBtn.setEnabled(swoopModel .getUncommittedChanges().size() > 0); swoopHandler.termDisplay.undoChangesBtn.setEnabled(swoopModel .getUncommittedChanges().size() > 0); displayOntology(); } catch (Exception ex) { ex.printStackTrace(); } } /** * Load an Ontology into Swoop when its specified in a AddImports change and * the ontology doesn't currently exist in Swoop. Called by addImports(..) * * @param ontURI */ private void loadImport(URI ontURI) { System.out.println("Load imported uri " + ontURI.toString()); final URI uri = ontURI; final SwoopProgressDialog progress = new SwoopProgressDialog(swoopHandler, "Loading new ontology..."); progress.show(); final OWLOntology currentOntology = swoopModel.getSelectedOntology(); SwingWorker worker = new SwingWorker() { OWLOntology importOnt = null; Exception error = null; public Object construct() { try { if (swoopModel.getOntology(uri) != null) { importOnt = swoopModel.getOntology(uri); } else { importOnt = swoopModel.addOntology(uri); } } catch (Exception e) { error = e; } return null; } public void finished() { progress.dispose(); if (error != null) { ExceptionDialog.createDialog(swoopHandler, "Can't import ontology", error).show(); return; } AddImport change = new AddImport(currentOntology, importOnt, null); swoopModel.addUncommittedChange(change); swoopHandler.termDisplay.applyChangesBtn.setEnabled(swoopModel .getUncommittedChanges().size() > 0); swoopHandler.termDisplay.undoChangesBtn.setEnabled(swoopModel .getUncommittedChanges().size() > 0); displayOntology(); // change.accept((ChangeVisitor) currOnt); // swoopModel.setSelectedOntology(currOnt); } }; worker.start(); } /** * AddImports change to an OWL Ontology, Suppose the ontology to be imported * is not in Swoop, it calls loadImport(ont) to load this ontology into * Swoop. */ public void addImports() { try { // add imports PopupAddOntology popup = new PopupAddOntology(swoopModel); popup.setLocation(200, 200); popup.show(); URI ontURI = popup.ontologyURI; if (ontURI != null) loadImport(ontURI); } catch (Exception ex) { ex.printStackTrace(); } } public void stateChanged(ChangeEvent e) { if (e.getSource() == ontDescTab) { renderOntology(); } } /** * Edit the logical URL of the Ontology i.e. replace the base URI's for all * entities in the ontology. Warning - use carefully as lots of references * may be lost (eg. from external ontology)! */ public void editOntologyURL(boolean displayWarning) { if (displayWarning) { String title = "Change URL"; String msg = "You are going to change the logical URI of the ontology. All entity references in the ontology will be modified. Continue?"; int options = JOptionPane.YES_NO_OPTION; int result = JOptionPane.showConfirmDialog(this, msg, title, options); if (result == JOptionPane.NO_OPTION) return; } try { OWLOntology currOnt = swoopModel.selectedOntology; String ontURI = currOnt.getURI().toString(); String newURI = JOptionPane.showInputDialog(this, "Specify New Logical URI:", ontURI // "Changing Ontology URI", // JOptionPane.PLAIN_MESSAGE ); if (newURI != null && isURI(newURI)) { swoopModel.renameOWLObject(currOnt, ontURI, ontURI, newURI, true); } else { JOptionPane.showMessageDialog(this, "Invalid URI Error: Operation could not be completed.", "Error", JOptionPane.ERROR_MESSAGE); } } catch (Exception ex) { ex.printStackTrace(); } } private boolean isURI(String uriStr) { try { URI uri = new URI(uriStr); } catch (Exception ex) { return false; } return true; } public void mouseClicked(MouseEvent e) { // if mouse clicked over ontList, display ontology pane in swoop frame if (e.getSource() == ontList || e.getSource() == ontHideBox) { this.disableUIListeners(); swoopHandler.displayOntologyPane(); // displayOntology(); // swoopHandler.changeLog.ontRadio.setSelected(true); // swoopHandler.changeLog.setScope(ChangeLog.ONTOLOGY_SCOPE); swoopHandler.annotRenderer.SwoopSelectionChanged(); // add ontology element to history as well if (swoopModel.getSelectedOntology() != null) { swoopHandler.termDisplay.addToHistory(swoopModel .getSelectedOntology()); try { // now that ontology is loaded we can update the address bar swoopHandler.disableUIListeners(); swoopHandler.updateAddressBar(swoopModel .getSelectedOntology().getURI().toString()); } catch (OWLException e1) { e1.printStackTrace(); } finally { swoopHandler.enableUIListeners(); } } this.enableUIListeners(); } } public void mousePressed(MouseEvent arg0) { } public void mouseReleased(MouseEvent arg0) { } public void mouseEntered(MouseEvent arg0) { } public void mouseExited(MouseEvent arg0) { }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?