⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 termsdisplay.java

📁 Semantic Web Ontology Editor
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
	}		/**	 * Sets up the popup menu that gets invoked when the user	 * right clicks over the entity pane	 * Useful option in the popup includes a call to a web browser	 * or mail client depending on type of selected entity (as determined from its url)	 */	private void setupPopupMenu() {				popupMenu = new JPopupMenu();		// add menu items		JMenuItem refsMenu = new JMenuItem("Show References");		JMenuItem addBMMenu = new JMenuItem("Add to Bookmarks");		JMenuItem addCompMenu = new JMenuItem("Add to Resource Holder (for comparison)");		openBrowserMenu = new JMenuItem();		JMenu optionsMenu = new JMenu("Options");		JMenuItem hideMenu = new JMenuItem("Hide");				// add listeners		refsMenu.addActionListener(new ActionListener() {			public void actionPerformed(ActionEvent e) {												OWLOntology ontology = swoopModel.getSelectedOntology();				OWLEntity entity = null;				try {					entity = ontology.getClass(new URI(urlClicked));					if (entity==null) entity = ontology.getDataProperty(new URI(urlClicked));					if (entity==null) entity = ontology.getObjectProperty(new URI(urlClicked));					if (entity==null) entity = ontology.getIndividual(new URI(urlClicked));									}				catch (Exception ex) {					ex.printStackTrace();									}				if (entity==null) entity = swoopModel.getSelectedEntity();				showReferencesTerm(ontology, entity);				popupMenu.setVisible(false);				rightClicked = false;				urlClicked = "";			}			});					addBMMenu.addActionListener(new ActionListener() {			public void actionPerformed(ActionEvent e) {								swoopHandler.addBookmark();				popupMenu.setVisible(false);				rightClicked = false;				urlClicked = "";			}		});				addCompMenu.addActionListener(new ActionListener() {			public void actionPerformed(ActionEvent e) {				try {					addEntityToResourceHolder();					popupMenu.setVisible(false);					rightClicked = false;					urlClicked = "";				}				catch (Exception ex) {					ex.printStackTrace();				}			}		});		openBrowserMenu.addActionListener(new ActionListener() {			public void actionPerformed(ActionEvent e) {								if (urlClicked.equals("") && swoopModel.getSelectedEntity()!=null) {					try {						OWLEntity entity = swoopModel.getSelectedEntity();						urlClicked = entity.getURI().toString();					}					catch (Exception ex) {						ex.printStackTrace();					}				}								BrowserControl.displayURL(urlClicked);				popupMenu.setVisible(false);				rightClicked = false;				urlClicked = "";			}		});				hideMenu.addActionListener(new ActionListener() {			public void actionPerformed(ActionEvent e) {				popupMenu.setVisible(false);				rightClicked = false;				urlClicked = "";			}		});				// UI stuff		popupMenu.add(refsMenu);		popupMenu.addSeparator();		popupMenu.add(addBMMenu);		popupMenu.add(addCompMenu);		popupMenu.addSeparator();		popupMenu.add(openBrowserMenu);		popupMenu.addSeparator();		popupMenu.add(hideMenu);		popupMenu.setSize(100, 200);		popupMenu.setVisible(false);	}		/**	 * Create a JEditorPane with the specified contentType and set default attributes	 * @param contentType	 * @return	 */	private JEditorPane getEditorPane(String contentType) {		JEditorPane editorPane = null;		if(contentType.equals("text/plain")) {			editorPane = new JEditorPane();			//editorPane.setFont(new Font("Verdana", Font.PLAIN, 10));                        editorPane.setFont(new Font("SansSerif", Font.PLAIN, 10));		}		else if(contentType.equals("text/html")) {			editorPane = new JEditorPane();			editorPane.addHyperlinkListener(this);			editorPane.addMouseListener(this);				}		else if(contentType.equals("text/xml"))			editorPane = new JEditorPane();		else			throw new RuntimeException("Cannot create an editor pane for content type " + contentType);				editorPane.setEditable(false);		editorPane.setContentType(contentType);		return editorPane;	}	/**	 * Popup panel for creating a new OWL Class/Property/Individual	 * @param type	 * @param ont	 * @throws OWLException	 */	protected void popup(String type, OWLOntology ont) throws OWLException {		PopupNew popupPanel = new PopupNew(this, swoopModel, type, ont);		swoopModel.addListener(popupPanel);		popupPanel.setLocation(200,200);		popupPanel.setVisible( true );				if (type.equals("Class")) termTabPane.setSelectedIndex(0);		else if (type.equals("Property")) termTabPane.setSelectedIndex(1);		else if (type.equals("Individual")) termTabPane.setSelectedIndex(2);			}		public void addNewClass(OWLOntology ont) {		try {			popup("Class", ont);		}		catch (Exception ex) {			ex.printStackTrace();		}	}		public void addNewProperty(OWLOntology ont) {		try {			popup("Property", ont);		}		catch (Exception ex) {			ex.printStackTrace();		}	}		public void addNewIndividual(OWLOntology ont) {		try {			popup("Individual", ont);		}		catch (Exception ex) {			ex.printStackTrace();		}	}		/*	 * Popup to create a new GCI to add to 	 * the currently selected ontology	 */	private void popupNewGCI() {		// select GCIs List		termTabPane.setSelectedIndex(2);		filterCombo.setSelectedIndex(4);		PopupAddClass popup = new PopupAddClass(swoopModel.getReasoner(), "GCI-LEFT", swoopModel);		popup.setLocation(200, 200);		popup.setVisible( true );		 	}		/**	 * Remove all references of an OWL entity from the ontology	 * @param ont	 * @param entity	 */	public void removeEntity(OWLOntology ont, OWLEntity entity, boolean warning) {		try {			int result = -1;						if (warning) {				String title = "Remove OWL Entity";				int options = JOptionPane.YES_NO_OPTION;				result = JOptionPane.showConfirmDialog(this, "This is going to remove ALL References of the Entity from the Ontology. Continue?", title, options);			}						if(result==JOptionPane.YES_OPTION || !warning) {								// save checkpoint before removing entity if auto-save checkpoints is enabled				if (swoopModel.getEnableAutoSaveChkPts()) {					swoopHandler.changeLog.saveCheckPoint(ChangeLog.ONTOLOGY_SCOPE, ont, entity, "Saving State of Ontology BEFORE removing Entity:" + swoopModel.shortForm(entity.getURI()), null);				}				swoopModel.removeEntity(ont, entity, true);				// save checkpoint after removing entity if auto-save checkpoints is enabled				if (swoopModel.getEnableAutoSaveChkPts()) {					swoopHandler.changeLog.saveCheckPoint(ChangeLog.ONTOLOGY_SCOPE, ont, entity, "Saving State of Ontology AFTER removing Entity:" + swoopModel.shortForm(entity.getURI()), null);				}			}			}		catch (Exception ex) {			ex.printStackTrace();		}	}		/**	 * Clear tree and alphabetical list selections	 * Turn off listeners while clearing selection!	 *	 */	public void clearSelections() {		this.disableUIListeners();		if (trees[0]!=null) trees[0].clearSelection();		if (trees[1]!=null) trees[1].clearSelection();		if (termList!=null) termList.clearSelection();		this.enableUIListeners();	}		/**	 * IMPORTANT NOTE: Many bugs in Swoop loading/traversal have been caused	 * because multiple copies of listeners are added on the same UI element	 * e.g. multiple List/Tree selection listeners..this obviously creates all	 * sorts of problems and to prevent this, we remove all listeners	 * 	 * Disable tree,list selection and tabPane change listeners	 * Used during history traversal	 */	public void disableUIListeners() {		//		for (int safe=0; safe<5; safe++) {			// turn off all listeners			for (int i=0; i<trees.length; i++) if (trees[i]!=null) {				trees[i].removeTreeSelectionListener(this);	// when tree node selected, render new entity						}			termList.removeListSelectionListener(this); // when alphabetic term list selection changes, render new entity			termTabPane.removeChangeListener(this); // when tab changes trees are redrawn			termDisplayPane.removeChangeListener(this);	// whenever renderer tab changes, term re-rendered//		}	}		public void enableUIListeners() {				// below is a safety mechanism to ensure that multiple copies of listener aren't added		this.disableUIListeners(); 				// turn on all listeners		for (int i=0; i<trees.length; i++) if (trees[i]!=null) {			trees[i].addTreeSelectionListener(this);		}		termList.addListSelectionListener(this);		termTabPane.addChangeListener(this);		termDisplayPane.addChangeListener(this);	}		protected void traverseHistory(OWLNamedObject namedObj, OWLOntology histOnt, boolean histImports) throws OWLException {				// disable ontDisplay listeners		this.historyTraversing = true;		swoopHandler.disableUIListeners();		swoopHandler.ontDisplay.disableUIListeners();			if (namedObj instanceof OWLEntity) {						// disable termDisplay listeners			this.disableUIListeners();			OWLEntity entity = (OWLEntity) namedObj;			swoopModel.selectedEntity = entity;						// check if histOnt is selected or not			// also check for toggling of the show_imports setting			if (swoopModel.selectedOntology.equals(histOnt)) {				if (swoopModel.getShowImports() != (histImports==true)) {					// current imports has been toggled from history					swoopModel.setShowImports(true);					this.showImportChk.setSelected(true);				}								URI uri = entity.getURI();				if ( uri.toString().startsWith( XMLSchemaSimpleDatatypeVocabulary.XS ) 				 || (uri.toString().startsWith(OWLVocabularyAdapter.OWL) && !swoopModel.isViewOWLVocabularyAsRDF()							&& !uri.toString().equals(OWLVocabularyAdapter.OWL))				 || (uri.toString().startsWith(RDFSVocabularyAdapter.RDFS) && !swoopModel.isViewRDFVocabularyAsRDF() 							&& !uri.toString().equals(RDFSVocabularyAdapter.RDFS))				 || (uri.toString().startsWith(RDFVocabularyAdapter.RDF) && !swoopModel.isViewRDFVocabularyAsRDF()							&& !uri.toString().equals(RDFVocabularyAdapter.RDF)				|| (uri.toString().indexOf("#ClassExpression") != -1)))				{						swoopHandler.updateAddressBar( uri.toString() );									}				else {					// current selected ontology match					selectEntity(entity.getURI().toString());				}			}			else {				// different ontology needs to be selected				// see if imports setting of that ontology matched history imports setting				if (swoopModel.getImportsSetting(histOnt) != (histImports==true)) {					List setting = swoopModel.getOntSetting(histOnt);					List newSetting = new ArrayList();					newSetting.add("true"); // set show_imports true in that setting					newSetting.add(setting.get(1));					newSetting.add(setting.get(2));					swoopModel.setOntSetting(histOnt, newSetting);					this.removeFromCache(histOnt);				}				// different ontology - construct an XPointer				String xpointerURI = entity.getURI() + XPointers.asDefinedIn + "(" + histOnt.getURI() + ")";				selectEntity(xpointerURI); // select node in class/property tree or individual in termlist			}						displayTerm(); 			swoopHandler.changeLog.refreshChangePane();			swoopHandler.displayEntityPane();			swoopHandler.annotRenderer.SwoopSelectionChanged();						// enable termDisplay listeners			this.enableUIListeners();								}		else if (namedObj instanceof OWLOntology) {			OWLOntology ont = (OWLOntology) namedObj;			if (swoopModel.getOntology(ont.getURI())==null) {				String ontName = swoopModel.shortForm(ont.getURI());				JOptionPane.showMessageDialog(this, "Ontology "+ontName+" not present in SWOOP", "History Error", JOptionPane.ERROR_MESSAGE);				return;			}			// disable termDisplay listeners			this.disableUIListeners();			swoopModel.setSelectedOntology(ont); // this causes rendering of ontology in ontDisplay (see its modelChanged - Ont Selection Changed)			swoopHandler.ontDisplay.ontList.setSelectedValue(ont, true);			swoopHandler.ontDisplay.ontHideBox.setSelectedItem(ont);			// enable termDisplay listeners			this.enableUIListeners();		}				// enable ontDisplay listeners		swoopHandler.ontDisplay.enableUIListeners();		swoopHandler.enableUIListeners();		this.historyTraversing = false;	}		/**	 * Traverse to the previous element in the History	 * Calls traverseHistory with the appropriate arguments (entity, ontology, imports)	 * as obtained from the historyEntity list.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -