touchgraphentityrenderer.java

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

JAVA
1,463
字号
//	public static final String NAME = "Graphical View";//	public static final int    DEFAULT_DEPTH = 2;//	public static final int    DEFAULT_DISTANCE = 40;//	//	public static final String FORALL = "\u2200";  // all restriction//	public static final String EXISTS = "\u2203";  // some restriction//	public static final String MUSTBE= " = ";      // value restriction//	//public static final String //	//	public static final String EQUALS = "(=)";//	public static final String GREATERTHAN = "(\u2265)";//	public static final String LESSTHAN    = "(\u2264)";//	public static final String SUBCLASSOF  = "\u2286";//	public static final String EQUIVALENTTO = "\u2261";//	//	public static final String INTERSECTION = "\u2293";  // AND//	public static final String UNION        = "\u2294";  // OR//	public static final String NOT          = "\u00ac";  // NOT//	//	public static final String ISA          = "a"; //	//	private Set myAllURIs;//	private SwoopModel myModel;//	private GraphPanel myPanel;//	//	public static final Color CENTER_NODE_COLOR = new Color(254, 155, 46);//	public static final Color IND_NODE_COLOR    = new Color(255, 103, 141);//	public static final Color LIT_NODE_COLOR    = new Color(35, 150, 228);//	public static final Color OBJ_PROP_NODE_COLOR   = new Color(198, 106, 106);//	public static final Color DATA_PROP_NODE_COLOR   = new Color(90, 146, 146);//	//public static final Color CLASS_NODE_COLOR//	//    public HVScroll hvScroll;//    public ZoomScroll zoomScroll;//    //public HyperScroll hyperScroll; // unused//    public RotateScroll rotateScroll;//    public LocalityScroll localityScroll;//	//	public TouchGraphEntityRenderer()//	{//		init();//	}//	//	private void init()//	{//		TGPanel p = new TGPanel();//		myPanel = new GraphPanel( );//        myPanel.setVisible(true);//	}////	//	public void render(OWLEntity entity, SwoopModel swoopModel, Writer writer) throws RendererException {//	    try{//	    	fontSize = swoopModel.getFontSize();//	    	OWLOntology ontology = swoopModel.getSelectedOntology();//	    	this.myAllURIs = OntologyHelper.allURIs(ontology);//	    	this.myModel = swoopModel;//	    	//	    	myPanel.clear();//	    	//	    	// set TemrsDisplay so it can receive HyperlinkEvents from GraphNagigateUI//	    	myPanel.setTermsDisplay( swoopModel.getFrame().termDisplay );//	    	//	    	super.render(entity, swoopModel, new StringWriter() );//	    }//	    catch (OWLException ex){//	    	ex.printStackTrace();//	    }//	  }//	//	//	public String getName() {//		return TouchGraphEntityRenderer.NAME;//	}////	public Component getDisplayComponent(SwoopDisplayPanel panel) //	{//		if (!(panel instanceof TermsDisplay ))//			throw new IllegalArgumentException();//		//		//myPanel.addHyperlinkListener( (TermsDisplay)panel );//		return myPanel;//	}//////	public SwoopRenderingVisitor createVisitor() {//		return new TouchGraphVisitor( this, myPanel );//	}////	protected void renderAnnotationProperty(OWLAnnotationProperty prop) throws OWLException //	{//		// nothing to do here//	}////	protected Node renderAnnotationContent(Object o) throws OWLException//	{//		//		try{//				if (o instanceof URI) //				{//					//					Node contentNode = new SwoopNode( null, super.shortForm((URI)o), myModel); //					myPanel.addNode( contentNode );//					contentNode.setBackColor( LIT_NODE_COLOR );//					return contentNode;//				} //				else if (o instanceof OWLIndividual)//				{//					TouchGraphVisitor TV = (TouchGraphVisitor)visitor;//					OWLIndividual ind = (OWLIndividual)o;//					ind.accept(TV);//					//					Node indNode =  TV.getResult();					//					return indNode;//				}//				else if (o instanceof OWLDataValue) {//					OWLDataValue dv = (OWLDataValue) o;//					//					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 = "^^" + super.shortForm(uri);//					} //					else //					{//						if (dvlang != null)//						 garnish =  "@" + dvlang;//					}//					//					// add to graph//					Node contentNode = new SwoopNode( null, value + garnish, myModel); //					myPanel.addNode( contentNode );//					contentNode.setBackColor( LIT_NODE_COLOR );//					return contentNode;//				} //				else //				{//					Node contentNode = new SwoopNode( null, o.toString(), myModel); //					myPanel.addNode(contentNode );//					contentNode.setBackColor( LIT_NODE_COLOR );//					return contentNode;//				}//			}//			catch ( TGException tge )//			{//            	tge.printStackTrace();//        	}//		return null;//	}	//////	/** Render the annotations for an object *///	protected void renderAnnotations(OWLNamedObject object, Node source ) throws OWLException //	{//		/* Bit nasty this -- annotations result in a new axiom *///		TouchGraphVisitor TV = (TouchGraphVisitor)visitor;		//		//		try//		{//			if (!object.getAnnotations(reasoner.getOntology()).isEmpty()) {//				for (Iterator it = object.getAnnotations(reasoner.getOntology()).iterator(); it.hasNext();) {//					OWLAnnotationInstance oai = (OWLAnnotationInstance) it.next();//					//					String annotationType = super.shortForm(oai.getProperty().getURI());//						//					// Just whack out the content. This isn't quite right... //					Node annotationContent = renderAnnotationContent(oai.getContent() );					//					myPanel.addNode( annotationContent );//					//					Edge edge = new Edge( source, annotationContent, DEFAULT_DISTANCE);//					edge.setID( annotationType );//					myPanel.addEdge( edge );//				}//			}		//		}//		catch ( TGException tge ) {//            tge.printStackTrace();//        }//	}	////	protected void renderClass(OWLClass clazz) throws OWLException //	{//		//System.out.println( "renderingClass");//        try {//        	OWLClass owlThing = reasoner.getOntology().getOWLDataFactory().getOWLThing();			//			TouchGraphVisitor TV =  (TouchGraphVisitor)visitor;//			//			// rendering class node//			String classQName = super.shortForm( clazz.getURI() );//			URI classURI = clazz.getURI();//			Node classNode = new SwoopNode( classURI, classURI.toString(), classQName, myModel ); //			myPanel.addNode( classNode );////			classNode.setBackColor( CENTER_NODE_COLOR );//			//			// rendering type//			URI uri = new URI(OWL_CLASS);//			Node prop = new SwoopNode( uri, super.shortForm(uri), myModel); //			myPanel.addNode( prop );//			Edge edge = new Edge( classNode, prop, DEFAULT_DISTANCE );//			myPanel.addEdge( edge );//			edge.setID("a");//			//			// rendering ANNOTATIONS//			if(!clazz.getAnnotations(reasoner.getOntology()).isEmpty()) {//				renderAnnotations(clazz, classNode);//			}//			  //			// render INTERSECTIONs equivalent to this class//			Iterator it = OWLDescriptionFinder.getIntersections(clazz, reasoner.getOntologies()).iterator();//			//			while(it.hasNext()) {//				OWLAnd intersection = (OWLAnd) it.next();////				intersection.accept(TV);//				Node branchNode = TV.getResult();//				Node andNode = TV.getResult();//				Edge equiEdge = new Edge( classNode, andNode, DEFAULT_DISTANCE);//				equiEdge.setID( EQUIVALENTTO );//				myPanel.addEdge( equiEdge );//			}//			//			// render UNIONs equivalent to this class//			it = OWLDescriptionFinder.getUnions(clazz, reasoner.getOntologies()).iterator();//			while(it.hasNext()) {//				OWLOr union = (OWLOr) it.next();//				union.accept(TV);//				Node orNode = TV.getResult();//				Edge equiEdge = new Edge( classNode, orNode, DEFAULT_DISTANCE);//				equiEdge.setID( EQUIVALENTTO );//				myPanel.addEdge( equiEdge );//			}//			//			// render ENUMERATIONs of classes that are equivalent to this class//			it = OWLDescriptionFinder.getEnumerations(clazz, reasoner.getOntologies()).iterator();//			while(it.hasNext()) {//				OWLEnumeration oneOf = (OWLEnumeration) it.next();//				oneOf.accept(TV);//				Node enumNode = TV.getResult();//				Edge enumEdge = new Edge( classNode, enumNode, DEFAULT_DISTANCE);//				enumEdge.setID( TV.result() );//				myPanel.addEdge( enumEdge );		//			}////			// print EQUIVALENT classes//			Set eqs = OWLDescriptionFinder.getEquivalentClasses(clazz, reasoner.getOntologies());//			it = eqs.iterator();			//			while(it.hasNext()) {//				OWLDescription desc = (OWLDescription) it.next();//				if(!(desc instanceof OWLRestriction || desc instanceof OWLClass))//					it.remove();//			}//			if(reasoner.isConsistent(clazz))//				eqs.addAll(reasoner.equivalentClassesOf(clazz));  // add all named equivalent classes//			it = eqs.iterator();//			//			uri = new URI(OWL_EQUIVALENTCLASS);//			String eqName = super.shortForm( uri );//			//			while (it.hasNext())//			{//				OWLDescription eq = (OWLDescription)it.next();//				TV.reset();//				eq.accept(TV);		//				Node equivalenceNode = TV.getResult();//				Edge eqEdge = new Edge( classNode, equivalenceNode, DEFAULT_DISTANCE );//				eqEdge.setID( eqName );//				myPanel.addEdge( eqEdge );//			}//			//			// DISJOINT CLASSES//			Set disjoints = OWLDescriptionFinder.getDisjoints(clazz, reasoner.getOntologies());//			uri = new URI(OWL_DISJOINTWITH);//			Node disjointNode = new Node( super.shortForm( uri ));//			for (it = disjoints.iterator(); it.hasNext(); )//			{//				OWLDescription desc = (OWLDescription)it.next();//				TV.reset();//				desc.accept(TV);//				Node distNode = TV.getResult();//				Edge distEdge = new Edge( classNode, distNode, DEFAULT_DISTANCE);//				distEdge.setID( super.shortForm(uri) );//				myPanel.addEdge( distEdge );//			}////			//			// SUBCLASS OF//			//			// acquiring all non-inferred super classes (named or anon)//			Set supers = OWLDescriptionFinder.getSuperClasses(clazz, reasoner.getOntologies());//			if(reasoner.isConsistent(clazz)) {//				// remove all the named classes because reasoner will eventually add them//				it = supers.iterator();//				while(it.hasNext())//					if(it.next() instanceof OWLClass)//						it.remove();		//				// add all the named superclasses (including inferred)//				supers.addAll(reasoner.superClassesOf(clazz));//				// remove owl:Thing from the superclass set//				it = supers.iterator();//				while(it.hasNext()) {//					Object o = it.next();//					if(o instanceof Set && ((Set)o).contains(owlThing))//						it.remove();//				}//			}//			uri = new URI(RDFS_SUBCLASSOF);//			Node subClassNode = new Node( );//			subClassNode.setType( Node.TYPE_NOTHING );//			//			for (it = supers.iterator(); it.hasNext(); )//			{//				Object obj = (Object)it.next();				//				// if there is more than one element for this line//				// we only print the first one. rest are either//				// equivalent classes (or properties) //				if(obj instanceof Collection)//					obj = ((Collection)obj).iterator().next();				//				TV.reset();//				OWLDescription desc = (OWLDescription)obj;//				desc.accept(TV);//				Node superNode = TV.getResult();//				Edge superEdge = new Edge( classNode, superNode, DEFAULT_DISTANCE);//				superEdge.setID( SUBCLASSOF );//				myPanel.addEdge( superEdge );//			}//			//        } catch ( TGException tge ) {//            tge.printStackTrace();//        }catch ( URISyntaxException ex){//        	ex.printStackTrace();//        }//	}////	//	protected void renderObjectProperty(OWLObjectProperty prop) throws OWLException //	{//		try{//			TouchGraphVisitor TV =  (TouchGraphVisitor)visitor;			//			//			// rendering prop node//			String propName = super.shortForm( prop.getURI() );//			URI uri = prop.getURI();//			Node propNode = new SwoopNode( uri, uri.toString(), propName, myModel); //			myPanel.addNode( propNode );//			propNode.setType( Node.TYPE_ELLIPSE );//			propNode.setBackColor( CENTER_NODE_COLOR );//			//			// rendering type//			uri = new URI(OWL_OBJECTPROPERTY);//			Node propTypeNode = new SwoopNode( uri, super.shortForm( uri ), myModel ); //			myPanel.addNode( propTypeNode );//			Edge propEdge = new Edge( propNode, propTypeNode, DEFAULT_DISTANCE );//			propEdge.setID( ISA );//			myPanel.addEdge( propEdge );//			//			// annotations//			if(!prop.getAnnotations(reasoner.getOntology()).isEmpty()) {//				renderAnnotations(prop, propNode);//			}//		//			// is TRANSITIVE?

⌨️ 快捷键说明

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