swoopframe.java

来自「Semantic Web Ontology Editor」· Java 代码 · 共 1,892 行 · 第 1/5 页

JAVA
1,892
字号
		if (e.getSource() == refreshOntMenu) {			// refresh ontology in swoop			OWLEntity copySel = null;			// also save copy of selected entity if any			if (swoopModel.selectedOWLObject != null					&& swoopModel.selectedOWLObject instanceof OWLEntity)				copySel = (OWLEntity) swoopModel.selectedOWLObject;			if (swoopModel.selectedOntology != null) {				// call reloadOntology, but do not reset changes associated with ontology				swoopModel.reloadOntology(swoopModel.selectedOntology, false);				if (copySel != null)					swoopModel.setSelectedEntity(copySel);			}		}		else		if (e.getSource() == reloadOntMenu) {			// reload ontology from its physical location			if (swoopModel.selectedOntology != null) {				ontDisplay						.reloadOntologyFromPhysical(swoopModel.selectedOntology);			}		}		else		if (e.getSource() == ontCodeMenu) {			viewSource(0); //0 is for RDF/XML		}		else		if (e.getSource() == ontCodeASMenu) {			viewSource(1); // 1 is for AS format		}		else		if (e.getSource() == addrCombo) {			addressChanged();		}		else		if (e.getSource() == addResHoldMItem) {			termDisplay.addEntityToResourceHolder();		}		else		if (e.getSource() == viewResHoldMItem) {			termDisplay.comparator.show();		}		else		if (e.getSource() == viewSideBarMenu) {			if (viewSideBarMenu.isSelected()) {				sidePanel.setVisible(true);				centerPanel.setDividerLocation(sideBarPos);				repaint();			} else {				sideBarPos = centerPanel.getDividerLocation();				sidePanel.setVisible(false);				centerPanel.setDividerLocation(0);				repaint();			}		}		else		if (e.getSource() == viewOptionBarMenu) {			optionPanel.setVisible(viewOptionBarMenu.isSelected());		}		else		if (e.getSource() == viewChangeBarMenu) {			this.toggleChangeAnnotationPane(viewChangeBarMenu.isSelected());		}		else		if (e.getSource() == showChangeBarChk) {			this.toggleChangeAnnotationPane(showChangeBarChk.isSelected());		}		//****************************************************		//Added for Partitioning with Econnections		//****************************************************		else		if (e.getSource() == JMenuAutomatic) {			try {				OWLOntology ont = swoopModel.getSelectedOntology();				// we dont handle imports yet! flash warning and return				if (ont.getIncludedOntologies().size() > 0) {					JOptionPane							.showMessageDialog(									this,									"This version of SWOOP does not support Partitioning of Ontologies which IMPORT other Ontologies.",									"Unsupported", JOptionPane.ERROR_MESSAGE);					return;				}				int options = JOptionPane.YES_NO_OPTION;				int result = JOptionPane						.showConfirmDialog(								this,								"Transforming an OWL Ontology into an E-Connection. This may take time (few secs to mins) depending on the ontology size. Continue?",								"Warning", options);				if (result == JOptionPane.YES_OPTION) {					// depending on some threshold (typically size of the ontology),					// determine whether the partitions should be saved to disk					// or opened in Swoop directly (careful memory usage)					boolean saveToDisk = false;					int threshold = ont.getClasses().size();					threshold += ont.getDataProperties().size();					threshold += ont.getObjectProperties().size();					threshold += ont.getIndividuals().size();					if (threshold > 40000) {						saveToDisk = true;						JOptionPane								.showMessageDialog(										this,										"Because of memory/speed constraints Ontology Partitions will be written to disk.",										"Partitions",										JOptionPane.INFORMATION_MESSAGE);					}					AutoEconnPartitioning partitions = new AutoEconnPartitioning(							this, swoopModel, ont, false);					// pass applychanges?, debug?, saveToDisk? (all boolean)					partitions.findPartitions(true, false, saveToDisk, false);				}			} catch (Exception ex) {				ex.printStackTrace();			}		}		else		if (e.getSource() == queryMItem) {			this.popupQuery();		}		else		if (e.getSource() == repairMItem) {			// check to see if pellet reasoner is currently selected						if (swoopModel.getReasoner() instanceof PelletReasoner) {				RepairFrame repFrame = new RepairFrame(this, swoopModel, (PelletReasoner) swoopModel.getReasoner());				repFrame.launch();			}			else {				// otherwise create new instance of pellet				// and process ontology (all inside new SwingWorker thread)				final SwoopFrame swoopHandler = this;				SwingWorker worker = new SwingWorker() {					PelletReasoner pellet = new PelletReasoner();					public Object construct() {	    				try {	    					pellet.setOntology(swoopModel.getSelectedOntology());	    				} 	    				catch (Exception ex) {	    					ex.printStackTrace();	    				}	    				return null;	    			}	    			public void finished() {	    				RepairFrame repFrame = new RepairFrame(swoopHandler, swoopModel, pellet);	    				repFrame.launch();	    				// also generate plan on startup	    				repFrame.genPlan();	    				repFrame.refreshPlan();	    			}				};				worker.start();							}										}		else		if (e.getSource() == versionMItem) {			versionControl.refresh();			versionControl.setVisible(true);		}		else		if (e.getSource() == sudokuMItem) {			// launch Sudoku UI			Sudoku sud = new Sudoku(swoopModel, this, 4);						}//		 ***************************************************		// Added for enabling rules		// ***************************************************		if (e.getSource() == showEnableRules) {			if (showEnableRules.isSelected()) { 				swoopModel.setEnableRules(true);				}				else {					swoopModel.setEnableRules(false);				}			ontDisplay.displayOntology();			termDisplay.displayTerm();		}				}	/**	 * Popup the Pellet Query panel	 *	 */	public void popupQuery() {		// popup the query interface		JFrame frame = new JFrame("Pellet Query");		QueryInterface qi = new QueryInterface(this, swoopModel);		frame.getContentPane().add(qi);		frame.setSize(500, 500);		frame.setVisible(true);		frame.toFront();		qi.rdqlText.requestFocus();	}	/*	 * Toggle the visibility of the 'advanced' (current Change/Annotation sidepane)	 */	public void toggleChangeAnnotationPane(boolean isVisible) {		if (isVisible) {			advancedTabPane.setVisible(true);			rendererAdvancedPane.setDividerLocation(advancedPanePos);			repaint();			showChangeBarChk.setSelected(true);			viewChangeBarMenu.setSelected(true);		} else {			advancedPanePos = rendererAdvancedPane.getDividerLocation();			advancedTabPane.setVisible(false);			repaint();			showChangeBarChk.setSelected(false);			viewChangeBarMenu.setSelected(false);		}		swoopModel.setShowChangeAnnotBar(isVisible);	}	/**	 * Highlight the definition of the selected OWL Entity in the 	 * Abstract Syntax source code	 */	public void highlightEntityAS() {		if (swoopModel.getSelectedEntity() != null) {			String entityURI = "";			try {				entityURI = swoopModel.shortForm(						swoopModel.getSelectedEntity().getURI()).toString();				entityURI = entityURI.substring(entityURI.lastIndexOf(":") + 1);			} catch (OWLException e) {			}			// determine type of entity			String entityTag = "Class";			if (swoopModel.getSelectedEntity() instanceof OWLObjectProperty)				entityTag = "ObjectProperty";			else if (swoopModel.getSelectedEntity() instanceof OWLDataProperty)				entityTag = "DatatypeProperty";			else if (swoopModel.getSelectedEntity() instanceof OWLIndividual)				entityTag = "Individual";			boolean saveCaseSetting = srcWindow.matchCase;			boolean saveWordSetting = srcWindow.matchWord;			srcWindow.matchCase = false;			srcWindow.matchWord = false;			// get the ontology URI			String strOntologyURI = "";			try {				strOntologyURI = swoopModel.selectedOntology.getURI()						.toString();			} catch (OWLException e) {			}			// with the ontologyURI , search in the text for a match			String strOntologyPrefix = srcWindow.originalSrc.substring(					srcWindow.originalSrc.substring(0,							srcWindow.originalSrc.indexOf(strOntologyURI))							.lastIndexOf("Namespace(") + 10,					srcWindow.originalSrc.indexOf(strOntologyURI));			//now read the first token from strFound 			// and that's the prefix we are looking for			String[] tokens = strOntologyPrefix.split("(\\s)+");			strOntologyPrefix = tokens[0];			// match starting position of entity definition in source code			String find = entityTag + "(" + strOntologyPrefix + ":" + entityURI;			srcWindow.findMatch = find;			int startMatch = srcWindow.matchString(true, false);			// if match found, find ending position and select entire code fragment for selected entity			if (startMatch != -1) {				//look for the matching closing paren                						int endMatch = srcWindow.findClosingParent(startMatch);				// endMatch += srcWindow.findMatch.length();				try {					// srcWindow.codePane.select(startMatch, endMatch);						DefaultHighlightPainter defhp = new DefaultHighlighter.DefaultHighlightPainter(							Color.BLUE);					srcWindow.dh.addHighlight(startMatch, endMatch, defhp);				} catch (BadLocationException e) {					e.printStackTrace();				}			}			// reset settings			srcWindow.matchCase = saveCaseSetting;			srcWindow.matchWord = saveWordSetting;		}	}	/***	 * View RDF/XML source of current selected ontology	 * Also highlight code fragment corresponding to current selected entity	 * based on user preference setting	 */	public void viewSource(int format) {		// display ontology source in RDF/XML		if (swoopModel.getSelectedOntology() != null) {			if (srcWindow != null)				srcWindow.dispose();			int result = -1;			// get current preferences object from swoopModel			// and check setting for code_highlighting			srcWindow = new PopupOntologySource(this, swoopModel, format);			srcWindow.displaySrcCode(swoopModel.getSelectedOntology());			if (swoopModel.isHighlightCode()) {				if (format == 1) { //AS 					highlightEntityAS();				} else { //RDF/XML					// *** HACKY STUFF TO SELECT CODE FRAGMENT ***					// depends on how the RDF/XML code is generated by the OWL API					// jump to currently selected entity source code					if (swoopModel.getSelectedEntity() != null) {						String entityURI = addrCombo.getSelectedItem()								.toString();						// select entity defn.						// determine type of entity						String entityTag = "owl:Class";						if (swoopModel.getSelectedEntity() instanceof OWLObjectProperty)							entityTag = "owl:ObjectProperty";						else if (swoopModel.getSelectedEntity() instanceof OWLDataProperty)							entityTag = "owl:DatatypeProperty";						else if (swoopModel.getSelectedEntity() instanceof OWLIndividual)							entityTag = "rdf:Description";						boolean saveCaseSetting = srcWindow.matchCase;						boolean saveWordSetting = srcWindow.matchWord;						srcWindow.matchCase = false;						srcWindow.matchWord = false;						// match starting position of entity definition in source code						String find = "";						try {							String entityName = swoopModel.shortForm(new URI(									entityURI));							if (entityName.indexOf(":") >= 0)								entityName = entityName.substring(entityName										.indexOf(":") + 1, entityName.length());							find = "\n<" + entityTag + " rdf:about=\"#"									+ entityName + "\">";						} catch (URISyntaxException e1) {							e1.printStackTrace();							return;						}						srcWindow.findMatch = find;						int startMatch = srcWindow.matchString(true, false);						// if match found, find ending position and select entire code fragment for selected entity						if (startMatch != -1) {							srcWindow.findMatch = "\n</" + entityTag + ">";							int endMatch = srcWindow.matchString(true, false);							endMatch += srcWindow.findMatch.length();							try {								// srcWindow.codePane.select(startMatch, endMatch);								srcWindow.dh.addHighlight(startMatch, endMatch,										srcWindow.dhp);							} catch (BadLocationException e) {								e.printStackTrace();							}						}						// reset settings					

⌨️ 快捷键说明

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