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

📄 kbdisplayarea.java

📁 toocom源代码,主要应用在本体匹配方面!
💻 JAVA
字号:
package toocom.ui;

import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.event.*;
import java.awt.*;
import java.lang.*; 
import toocom.ocgl.*;
import toocom.iotools.*;
import java.io.*;
import javax.swing.filechooser.*;

/** 
 * This class represents the graphical window into which the knowledge base is displayed.
 *
 * @author Fr閐閞ic F黵st
 */
public class KBDisplayArea extends GraphEditionPanel implements MouseListener, MouseMotionListener{

	private InferenceEngineFrame ief;
	// Concepts and Relations used to display projection
	private LinkedList tempCon;
	private LinkedList tempRel;
	
	public void clearGraph(){
		super.clearGraph();
		this.tempCon.clear();
		this.tempRel.clear();
		this.repaint();
	}
	
	public void paint(Graphics gr){
		((Graphics2D) gr).setBackground(bgColor);
		gr.setColor(bgColor);
		gr.fillRect(0,0,this.getWidth(),this.getHeight());
		if(g != null){
			for(Iterator i = tempRel.iterator();i.hasNext();){
				((Relation) i.next()).paintLinks(gr,mf.getOntologyLanguage());
			}
			for(Iterator i = tempRel.iterator();i.hasNext();){
				((Relation) i.next()).paintObjectAsConclusion(gr,mf.getOntologyLanguage());
			}
			for(Iterator i = tempCon.iterator();i.hasNext();){
				((Concept) i.next()).paintObjectAsConclusion(gr,mf.getOntologyLanguage());
			}
			g.paintObject(gr,mf.getOntologyLanguage());
		}
		if((dragBegin != null) && (pointerPosition != null)){
			gr.setColor(Constants.SELECT_RECT_COLOR);
			gr.drawRect(Math.min(dragBegin.x,pointerPosition.x),Math.min(dragBegin.y,pointerPosition.y),Math.abs(dragBegin.x - pointerPosition.x),Math.abs(dragBegin.y - pointerPosition.y));
		}
	}
	
	public void changeProjection(){
		tempCon.clear();
		tempRel.clear();
		for(Iterator i = g.getConcepts().iterator();i.hasNext();){
			Concept c = (Concept) i.next();
			c.setHighlighted(false);
		}
		for(Iterator i = g.getRelations().iterator();i.hasNext();){
			Relation r = (Relation) i.next();
			r.setHighlighted(false);
		}
		Projection p = ief.getProjection();
		if(p != null){
			Rule rule = ief.getSelectedRule();
			if(rule != null){
				Hashtable concConcepts = new Hashtable();
				for(Iterator i = rule.getPureConclusionConcepts().iterator();i.hasNext();){
					Concept c = (Concept) i.next();
					Concept cBis = c.cloneConcept();
					this.tempCon.add(cBis);
					concConcepts.put(c,cBis);
				}
				for(Iterator i = rule.getConclusionRelations().iterator();i.hasNext();){
					Relation r = (Relation) i.next();
					Relation rBis = r.cloneRelation();
					int cpt = 1;
					for(Iterator j = r.getLinkedConcepts().iterator();j.hasNext();cpt ++){
						Concept c = (Concept) j.next();
						if(!rule.hasHypothesisConclusionConcept(c)){
							rBis.setLinkedConcept((Concept) concConcepts.get(c),cpt);
						}
						else{
							int conId = p.getCorrespondance(c.getId());
							rBis.setLinkedConcept(g.getConcept(conId),cpt);
						}
					}
					this.tempRel.add(rBis);
				}
				for(Iterator i = p.getCorrespondances().values().iterator();i.hasNext();){
					int id = ((Integer) i.next()).intValue();
					g.getObject(id).setHighlighted(true);
				}
			}
			Constraint cons = ief.getSelectedConstraint();
			if(cons != null){
				for(Iterator i = p.getCorrespondances().values().iterator();i.hasNext();){
					int id = ((Integer) i.next()).intValue();
					g.getObject(id).setHighlighted(true);
				}
				if(cons instanceof PositiveConstraint){
					Hashtable concConcepts = new Hashtable();
					for(Iterator i = cons.getPureConclusionConcepts().iterator();i.hasNext();){
						Concept c = (Concept) i.next();
						Concept cBis = c.cloneConcept();
						cBis.setTransparent(true);
						this.tempCon.add(cBis);
						concConcepts.put(c,cBis);
					}
					for(Iterator i = cons.getConclusionRelations().iterator();i.hasNext();){
						Relation r = (Relation) i.next();
						Relation rBis = r.cloneRelation();
						rBis.setTransparent(true);
						int cpt = 1;
						for(Iterator j = r.getLinkedConcepts().iterator();j.hasNext();cpt ++){
							Concept c = (Concept) j.next();
							if(!cons.hasHypothesisConclusionConcept(c)){
								rBis.setLinkedConcept((Concept) concConcepts.get(c),cpt);
							}
							else{
								int conId = p.getCorrespondance(c.getId());
								rBis.setLinkedConcept(g.getConcept(conId),cpt);
							}
						}
						this.tempRel.add(rBis);
					}
				}
			}
			Graph gh = ief.getSelectedQuestion();
			if(gh != null){
				for(Iterator i = p.getCorrespondances().values().iterator();i.hasNext();){
				 	int id = ((Integer) i.next()).intValue();
					g.getObject(id).setHighlighted(true);
				}
			}
		}
	}
	
	public KBDisplayArea(MainFrame mf,InferenceEngineFrame ief){
		super(mf,Constants.INFERENCE_ENGINE_FRAME_COLOR);
		this.mf = mf;
		this.setPreferredSize(new Dimension(ief.getSize().width - Constants.IE_BUTTON_PANEL_WIDTH,ief.getSize().height));
		try{
			mf.getCogitantClient().createServerSupport(mf.getOntology(),mf.getOntologyLanguage());
		}
		catch(Exception e){
			System.out.println(e.getMessage());
		}
		this.tempCon = new LinkedList();
		this.tempRel = new LinkedList();
		this.ief = ief;
	}
	
	
}
	

⌨️ 快捷键说明

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