touchgraphentityrenderer.java

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

JAVA
1,463
字号
//The MIT License//// Copyright (c) 2004 Mindswap Research Group, University of Maryland, College Park//// Permission is hereby granted, free of charge, to any person obtaining a copy// of this software and associated documentation files (the "Software"), to// deal in the Software without restriction, including without limitation the// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or// sell copies of the Software, and to permit persons to whom the Software is// furnished to do so, subject to the following conditions://// The above copyright notice and this permission notice shall be included in// all copies or substantial portions of the Software.//// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS// IN THE SOFTWARE.package org.mindswap.swoop.renderer.entity;import java.awt.Color;import java.awt.Component;import java.io.StringWriter;import java.io.Writer;import java.net.URI;import java.net.URISyntaxException;import java.util.Collection;import java.util.Iterator;import java.util.Map;import java.util.Set;import org.mindswap.swoop.SwoopDisplayPanel;import org.mindswap.swoop.SwoopModel;import org.mindswap.swoop.TermsDisplay;import org.mindswap.swoop.renderer.BaseEntityRenderer;import org.mindswap.swoop.renderer.SwoopEntityRenderer;import org.mindswap.swoop.renderer.SwoopRenderingVisitor;import org.mindswap.swoop.renderer.entity.graph.GraphPanel;import org.mindswap.swoop.renderer.entity.graph.SwoopNode;import org.mindswap.swoop.utils.owlapi.OWLDescriptionFinder;import org.semanticweb.owl.io.RendererException;import org.semanticweb.owl.io.ShortFormProvider;import org.semanticweb.owl.model.OWLAnd;import org.semanticweb.owl.model.OWLAnnotationInstance;import org.semanticweb.owl.model.OWLAnnotationProperty;import org.semanticweb.owl.model.OWLClass;import org.semanticweb.owl.model.OWLDataAllRestriction;import org.semanticweb.owl.model.OWLDataCardinalityRestriction;import org.semanticweb.owl.model.OWLDataEnumeration;import org.semanticweb.owl.model.OWLDataProperty;import org.semanticweb.owl.model.OWLDataPropertyInstance;import org.semanticweb.owl.model.OWLDataPropertyRangeAxiom;import org.semanticweb.owl.model.OWLDataRange;import org.semanticweb.owl.model.OWLDataSomeRestriction;import org.semanticweb.owl.model.OWLDataType;import org.semanticweb.owl.model.OWLDataValue;import org.semanticweb.owl.model.OWLDataValueRestriction;import org.semanticweb.owl.model.OWLDescription;import org.semanticweb.owl.model.OWLDifferentIndividualsAxiom;import org.semanticweb.owl.model.OWLDisjointClassesAxiom;import org.semanticweb.owl.model.OWLEntity;import org.semanticweb.owl.model.OWLEnumeration;import org.semanticweb.owl.model.OWLEquivalentClassesAxiom;import org.semanticweb.owl.model.OWLEquivalentPropertiesAxiom;import org.semanticweb.owl.model.OWLException;import org.semanticweb.owl.model.OWLFrame;import org.semanticweb.owl.model.OWLFunctionalPropertyAxiom;import org.semanticweb.owl.model.OWLIndividual;import org.semanticweb.owl.model.OWLIndividualTypeAssertion;import org.semanticweb.owl.model.OWLInverseFunctionalPropertyAxiom;import org.semanticweb.owl.model.OWLInversePropertyAxiom;import org.semanticweb.owl.model.OWLNamedObject;import org.semanticweb.owl.model.OWLNot;import org.semanticweb.owl.model.OWLObjectAllRestriction;import org.semanticweb.owl.model.OWLObjectCardinalityRestriction;import org.semanticweb.owl.model.OWLObjectProperty;import org.semanticweb.owl.model.OWLObjectPropertyInstance;import org.semanticweb.owl.model.OWLObjectPropertyRangeAxiom;import org.semanticweb.owl.model.OWLObjectSomeRestriction;import org.semanticweb.owl.model.OWLObjectValueRestriction;import org.semanticweb.owl.model.OWLOntology;import org.semanticweb.owl.model.OWLOr;import org.semanticweb.owl.model.OWLPropertyDomainAxiom;import org.semanticweb.owl.model.OWLRestriction;import org.semanticweb.owl.model.OWLSameIndividualsAxiom;import org.semanticweb.owl.model.OWLSubClassAxiom;import org.semanticweb.owl.model.OWLSubPropertyAxiom;import org.semanticweb.owl.model.OWLSymmetricPropertyAxiom;import org.semanticweb.owl.model.OWLTransitivePropertyAxiom;import org.semanticweb.owl.model.helper.OntologyHelper;import com.touchgraph.graphlayout.Edge;import com.touchgraph.graphlayout.Node;import com.touchgraph.graphlayout.TGException;import com.touchgraph.graphlayout.TGPanel;import com.touchgraph.graphlayout.interaction.HVScroll;import com.touchgraph.graphlayout.interaction.LocalityScroll;import com.touchgraph.graphlayout.interaction.RotateScroll;import com.touchgraph.graphlayout.interaction.ZoomScroll;/** * @author Dave * * To change the template for this generated type comment go to * Window - Preferences - Java - Code Generation - Code and Comments */public class TouchGraphEntityRenderer { // extends BaseEntityRenderer  implements SwoopEntityRenderer //{////	class TouchGraphVisitor implements org.mindswap.swoop.renderer.SwoopRenderingVisitor //	{//		private ShortFormProvider shortForms;//		//private Node mySourceNode = null;//		private Node myResultNode = null;//		private GraphPanel myPanel   = null;//		private String myEdgeID     = null;//		//		public TouchGraphVisitor(ShortFormProvider shortForms, GraphPanel panel) {//			this.shortForms = shortForms;//			this.myPanel    = panel;//			reset();//		}//		//		public void reset() //		{//			myResultNode = null;//			myEdgeID      = null;//		}////		public String result() {//			return myEdgeID;//		}//		//		public Node getResult()//		{//			return myResultNode;//		}//////		// and (DONE)//		public void visit(OWLAnd and) throws OWLException //		{			//			try//			{	//				URI uri = new URI(OWL_INTERSECTIONOF);								//				Node andNode = new SwoopNode( uri, INTERSECTION, myModel );//				andNode.setBackColor( Color.WHITE );//				andNode.setTextColor( Color.BLACK );//				myPanel.addNode( andNode );//				for ( Iterator it = and.getOperands().iterator();it.hasNext(); ) {//					OWLDescription desc = (OWLDescription) it.next();//					desc.accept( this );//					myPanel.addEdge( andNode, myResultNode, DEFAULT_DISTANCE );					//				}//				andNode.setBackColor( Edge.DEFAULT_COLOR );//				andNode.setType( Node.TYPE_HOLLOW_CIRCLE );//				myResultNode = andNode;//			}//			catch (Exception ex)//			{ //				ex.printStackTrace(); //			}//		}//		//		// or (DONE)//		public void visit(OWLOr or) throws OWLException //		{//			try//			{	//				URI uri = new URI(OWL_UNIONOF);				//				Node orNode = new SwoopNode( uri, UNION, myModel );//				orNode.setBackColor( Color.WHITE );//				orNode.setTextColor( Color.BLACK );//				myPanel.addNode( orNode );//				//				for ( Iterator it = or.getOperands().iterator();it.hasNext(); ) {//					OWLDescription desc = (OWLDescription) it.next();//					desc.accept( this );//					myPanel.addEdge( orNode, myResultNode, DEFAULT_DISTANCE );					//				}//				orNode.setBackColor( Edge.DEFAULT_COLOR );//				orNode.setType( Node.TYPE_HOLLOW_CIRCLE );//				myResultNode = orNode;//			}//			catch (Exception ex)//			{ //				ex.printStackTrace(); //			}//		}//		//		// not (DONE)//		public void visit(OWLNot not) throws OWLException //		{//			try//			{					//				URI uri = new URI(OWL_COMPLEMENTOF);//				//				Node notNode = new SwoopNode( uri, NOT, myModel);//				notNode.setBackColor( Color.WHITE );//				notNode.setTextColor( Color.BLACK );//				myPanel.addNode( notNode );//				//				OWLDescription desc = not.getOperand();//				desc.accept(this);//				Edge expEdge = new Edge( notNode, myResultNode, DEFAULT_DISTANCE );//				myPanel.addEdge( expEdge );//				//				notNode.setBackColor( Edge.DEFAULT_COLOR );//				notNode.setType( Node.TYPE_HOLLOW_CIRCLE );//				myResultNode = notNode;//			}//			catch (Exception ex)			//			{ ex.printStackTrace(); }		//		}//		//		// class//		public void visit( OWLClass clazz ) throws OWLException //		{//			try//			{	//				URI uri = clazz.getURI();//				Node classNode = new SwoopNode( uri, uri.toString(), shortForms.shortForm( uri ), myModel);//				myResultNode = myPanel.addNode( classNode );//				//myResultNode = classNode;//			}//			catch (Exception ex)//			{ //				ex.printStackTrace(); //			}//		}//		//		// object property//		public void visit(OWLObjectProperty prop) throws OWLException //		{//			try//			{	//				URI uri = prop.getURI();//				Node propNode = new SwoopNode( uri, uri.toString(), shortForms.shortForm(uri), myModel);//				myResultNode = myPanel.addNode( propNode );//				//				myPanel.addNode( propNode );//				myResultNode.setBackColor( OBJ_PROP_NODE_COLOR );//				myResultNode.setType( Node.TYPE_ELLIPSE );////			}//			catch (Exception ex)//			{ //				ex.printStackTrace(); //			}//		}//		//		// data property//		public void visit(OWLDataProperty prop) throws OWLException //		{//			try//			{	//				URI uri = prop.getURI();//				Node propNode = new SwoopNode( uri, uri.toString(), shortForms.shortForm(uri), myModel);//				myResultNode = myPanel.addNode( propNode );//				//				myResultNode.setBackColor( DATA_PROP_NODE_COLOR );//			}//			catch (Exception ex)//			{ //				ex.printStackTrace(); //			}//		}//		//		// data enumeration (DONE)//		public void visit(OWLDataEnumeration enumeration) throws OWLException //		{//			try//			{//				URI uri = new URI(OWL_ONEOF);//				Node oneOfNode = new SwoopNode( uri, UNION, myModel);//				myPanel.addNode( oneOfNode );//				oneOfNode.setBackColor( Color.WHITE );//				oneOfNode.setTextColor( Color.BLACK );//				//				for ( Iterator it = enumeration.getValues().iterator();it.hasNext(); ) //				{//					OWLDescription desc = (OWLDescription) it.next();//					desc.accept( this );//					myPanel.addEdge( oneOfNode, myResultNode, DEFAULT_DISTANCE );//				}//				oneOfNode.setBackColor( Edge.DEFAULT_COLOR );//				oneOfNode.setType( Node.TYPE_HOLLOW_CIRCLE );//				myResultNode = oneOfNode;//				myEdgeID = "";//			}//			catch (Exception ex)//			{ throw new OWLException(ex.toString()); }//		}//		//		// datatype//		public void visit(OWLDataType ocdt) throws OWLException //		{//			try//			{//				URI uri = ocdt.getURI() ;//				Node dataTypeNode = new SwoopNode( uri, uri.toString(), shortForms.shortForm(ocdt.getURI()), myModel);//				myResultNode = dataTypeNode;//				myResultNode.setBackColor(  LIT_NODE_COLOR );//				myResultNode.setType( Node.TYPE_ELLIPSE );//			}//			catch(Exception ex)//			{ ex.printStackTrace(); }//		}//		//		// data value//		// data values don't have URI's//		public void visit(OWLDataValue dv) throws OWLException //		{		//			try//			{//				String value = "\"" + escape(dv.getValue()) + "\"";					//				/* Only show it if it's not string *///				URI uri = dv.getURI();//				String dvlang = dv.getLang();//				String garnish = "";//				if (uri != null) {//					garnish = "^^" + shortForms.shortForm(uri);//				} //				else //				{//					if (dvlang != null)//					garnish =  "@" + dvlang;//				}//				//				// add to graph//				Node valueNode = new SwoopNode( null, value + garnish, myModel);//				myPanel.addNode( valueNode );//				myResultNode = valueNode;//				myResultNode.setBackColor(  LIT_NODE_COLOR );//			}//			catch (Exception ex)//			{ //				ex.printStackTrace(); //			}//		}//		//		// individual//		public void visit(OWLIndividual ind) throws OWLException //		{//			try//			{//				if ( ind.isAnonymous() ) //				{//					Node anonNode = new SwoopNode(null, "", myModel); // anonymous individual//					myResultNode = myPanel.addNode(anonNode);//				} else //				{//					URI uri = ind.getURI();//					Node anonNode = new SwoopNode(uri, uri.toString(), shortForms.shortForm( uri ), myModel);//					myPanel.addNode(anonNode);//					myResultNode = anonNode;					//				}//				myResultNode.setBackColor( IND_NODE_COLOR);//			}//			catch (Exception ex)//			{ 

⌨️ 快捷键说明

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