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

📄 grapheditionframe.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.*;

/**
 * This class represents the graphical window used for editing a graph.
 *
 * @author Fr閐閞ic F黵st
 */
public class GraphEditionFrame extends JDialog {	

	private MainFrame mf;
	private InferenceEngineFrame ief;
	private JToolBar tb;
	private GraphEditionPanel panel;
	private JButton loadGraph;
	private JButton saveGraph;
	private JButton checkGraph;
	private JButton init;
	private JButton createConcept;
	private JButton createRelation;
	private JButton destroyPrimitive;
	private JButton linkPrimitives;

	GraphEditionFrame(MainFrame mf,InferenceEngineFrame ief){
		super(ief,Constants.GRAPH_EDITION_FRAME_TITLE + " - " + mf.getOntology().getTerm(mf.getOntologyLanguage()));
		this.mf = mf;
		this.ief = ief;
		//this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
		this.addWindowListener(new WindowAdapter(){
			public void windowClosing(WindowEvent e){
				addQuestion();
			}
		});
		this.setLocation(1,1);
		this.setSize(mf.getSize().width - 10,mf.getSize().height -10);
		// Creating tool bar
		this.tb = new JToolBar();
		this.tb.setBackground(Constants.GRAPH_EDITION_TOOLBAR_COLOR);
		this.tb.setLayout(new FlowLayout(FlowLayout.CENTER));
		this.tb.setFloatable(false);
		// Load graph Button
    	this.loadGraph = new JButton(new InterfaceIcon(Constants.LOAD_GRAPH_ICON));
		this.loadGraph.setMaximumSize(new Dimension(Constants.INTERNAL_FRAME_BUTTON_DIM,Constants.INTERNAL_FRAME_BUTTON_DIM));
		this.loadGraph.setMinimumSize(new Dimension(Constants.INTERNAL_FRAME_BUTTON_DIM,Constants.INTERNAL_FRAME_BUTTON_DIM));
		this.loadGraph.setBorder(BorderFactory.createRaisedBevelBorder());
		this.loadGraph.addActionListener(new ActionListener(){
    		public void actionPerformed(ActionEvent e){
    			loadGraph();
    		}
    	});
    	this.loadGraph.setToolTipText(Constants.LOAD_GRAPH_TIPTEXT);
    	this.loadGraph.setVisible(true);
    	this.tb.add(this.loadGraph);
    	// Save graph Button
    	this.saveGraph = new JButton(new InterfaceIcon(Constants.SAVE_GRAPH_ICON));
		this.saveGraph.setMaximumSize(new Dimension(Constants.INTERNAL_FRAME_BUTTON_DIM,Constants.INTERNAL_FRAME_BUTTON_DIM));
		this.saveGraph.setMinimumSize(new Dimension(Constants.INTERNAL_FRAME_BUTTON_DIM,Constants.INTERNAL_FRAME_BUTTON_DIM));
		this.saveGraph.setBorder(BorderFactory.createRaisedBevelBorder());
		this.saveGraph.addActionListener(new ActionListener(){
    		public void actionPerformed(ActionEvent e){
    			saveGraph();
    		}
    	});
    	this.saveGraph.setToolTipText(Constants.SAVE_GRAPH_TIPTEXT);
    	this.saveGraph.setVisible(true);
    	this.tb.add(this.saveGraph);
    	// Check knowledge base Button
    	this.checkGraph = new JButton(new InterfaceIcon(Constants.CHECK_GRAPH_ICON));
		this.checkGraph.setMaximumSize(new Dimension(Constants.INTERNAL_FRAME_BUTTON_DIM,Constants.INTERNAL_FRAME_BUTTON_DIM));
		this.checkGraph.setMinimumSize(new Dimension(Constants.INTERNAL_FRAME_BUTTON_DIM,Constants.INTERNAL_FRAME_BUTTON_DIM));
		this.checkGraph.setBorder(BorderFactory.createRaisedBevelBorder());
		this.checkGraph.addActionListener(new ActionListener(){
    		public void actionPerformed(ActionEvent e){
    			checkGraph();
    		}
    	});
    	this.checkGraph.setToolTipText(Constants.CHECK_GRAPH_TIPTEXT);
    	this.checkGraph.setVisible(true);
    	this.tb.add(this.checkGraph);    	
    	// Create Concept Button
		this.createConcept = new JButton(new InterfaceIcon(Constants.CREATE_CONCEPT_ICON));
		this.createConcept.setMaximumSize(new Dimension(Constants.INTERNAL_FRAME_BUTTON_DIM,Constants.INTERNAL_FRAME_BUTTON_DIM));
		this.createConcept.setMinimumSize(new Dimension(Constants.INTERNAL_FRAME_BUTTON_DIM,Constants.INTERNAL_FRAME_BUTTON_DIM));
		this.createConcept.setBorder(BorderFactory.createRaisedBevelBorder());
		this.createConcept.addActionListener(new ActionListener(){
    		public void actionPerformed(ActionEvent e){
    			setPrimitiveMode(0);
    		}
    	});
    	this.createConcept.setToolTipText(Constants.CREATE_CONCEPT_TIPTEXT);
    	this.createConcept.setVisible(true);
    	this.tb.add(this.createConcept);
    	// Create Button
		this.createRelation = new JButton(new InterfaceIcon(Constants.CREATE_RELATION_ICON));
		this.createRelation.setMaximumSize(new Dimension(Constants.INTERNAL_FRAME_BUTTON_DIM,Constants.INTERNAL_FRAME_BUTTON_DIM));
		this.createRelation.setMinimumSize(new Dimension(Constants.INTERNAL_FRAME_BUTTON_DIM,Constants.INTERNAL_FRAME_BUTTON_DIM));
		this.createRelation.setBorder(BorderFactory.createRaisedBevelBorder());
		this.createRelation.addActionListener(new ActionListener(){
    		public void actionPerformed(ActionEvent e){
    			setPrimitiveMode(1);
    		}
    	});
    	this.createRelation.setToolTipText(Constants.CREATE_RELATION_TIPTEXT);
    	this.createRelation.setVisible(true);
    	this.tb.add(this.createRelation);
		// Destroy Button
		this.destroyPrimitive = new JButton(new InterfaceIcon(Constants.DESTROY_PRIMITIVE_ICON));
		this.destroyPrimitive.setMaximumSize(new Dimension(Constants.INTERNAL_FRAME_BUTTON_DIM,Constants.INTERNAL_FRAME_BUTTON_DIM));
		this.destroyPrimitive.setMinimumSize(new Dimension(Constants.INTERNAL_FRAME_BUTTON_DIM,Constants.INTERNAL_FRAME_BUTTON_DIM));
		this.destroyPrimitive.setBorder(BorderFactory.createRaisedBevelBorder());
		this.destroyPrimitive.addActionListener(new ActionListener(){
    		public void actionPerformed(ActionEvent e){
    			setPrimitiveMode(2);
    		}
    	});
    	this.destroyPrimitive.setToolTipText(Constants.DESTROY_PRIMITIVE_TIPTEXT);
    	this.tb.add(this.destroyPrimitive);
		// Link Button
		this.linkPrimitives = new JButton(new InterfaceIcon(Constants.LINK_PRIMITIVES_ICON));
		this.linkPrimitives.setMaximumSize(new Dimension(Constants.INTERNAL_FRAME_BUTTON_DIM,Constants.INTERNAL_FRAME_BUTTON_DIM));
		this.linkPrimitives.setMinimumSize(new Dimension(Constants.INTERNAL_FRAME_BUTTON_DIM,Constants.INTERNAL_FRAME_BUTTON_DIM));
		this.linkPrimitives.setBorder(BorderFactory.createRaisedBevelBorder());
		this.linkPrimitives.addActionListener(new ActionListener(){
    		public void actionPerformed(ActionEvent e){
    			setPrimitiveMode(3);
    		}
    	});
    	this.linkPrimitives.setToolTipText(Constants.LINK_PRIMITIVES_TIPTEXT);
    	this.tb.add(this.linkPrimitives);
    	// Exit running mode button
		this.init = new JButton(new InterfaceIcon(Constants.INIT_ICON));
		this.init.setMaximumSize(new Dimension(Constants.INTERNAL_FRAME_BUTTON_DIM,Constants.INTERNAL_FRAME_BUTTON_DIM));
		this.init.setMinimumSize(new Dimension(Constants.INTERNAL_FRAME_BUTTON_DIM,Constants.INTERNAL_FRAME_BUTTON_DIM));
		this.init.setBorder(BorderFactory.createRaisedBevelBorder());
		this.init.addActionListener(new ActionListener(){
    		public void actionPerformed(ActionEvent e){
    			init();
    		}
    	});
    	this.init.setToolTipText(Constants.INIT_TIPTEXT);
    	this.init.setVisible(true);
    	this.tb.add(this.init);
    	this.getContentPane().setLayout(new BorderLayout());
		this.getContentPane().add(tb,BorderLayout.NORTH);
		this.panel = new GraphEditionPanel(this.mf,Constants.GRAPH_EDITION_PANEL_COLOR);
    	this.getContentPane().add(new JScrollPane(panel),BorderLayout.CENTER);
		this.setVisible(true);
		this.toFront();
	}
		
	public void loadGraph(){
		Graph g = IOInterface.loadGraph(this,Constants.APPLICATION_DIRECTORY,mf.getOntology(),mf.getOntologyLanguage());
		if(g != null) panel.setGraph(g);
	}
	
	public void saveGraph(){
		if((panel.getGraph() != null) && !panel.getGraph().isEmpty()){
			IOInterface.saveGraph(this,Constants.APPLICATION_DIRECTORY,mf.getOntology(),mf.getOntologyLanguage(),panel.getGraph());
		}
	}
	
	public void checkGraph(){
		if(panel.getGraph() != null) OntoEval.graphVerification(panel.getGraph(),mf.getOntology(),mf.getOntologyLanguage()).displayResults(mf,CGConstants.GRAPH + CGConstants.TESTS_RESULTS);
	}
	
	public void setPrimitiveMode(int mode){
		this.panel.setPrimitiveMode(mode);
		this.createConcept.setBackground(null);
		this.createRelation.setBackground(null);
		this.destroyPrimitive.setBackground(null);
		this.linkPrimitives.setBackground(null);
		if(mode == 0){
			this.createConcept.setBackground(Constants.SELECTED_BUTTON_COLOR);
		}
		if(mode == 1){
			this.createRelation.setBackground(Constants.SELECTED_BUTTON_COLOR);
		}
		if(mode == 2){
			this.destroyPrimitive.setBackground(Constants.SELECTED_BUTTON_COLOR);
		}
		if(mode == 3){
			this.linkPrimitives.setBackground(Constants.SELECTED_BUTTON_COLOR);
		}
		this.repaint();
	}
	
	public void init(){
		this.setPrimitiveMode(0);
		this.panel.clearGraph();
	}
	
	public void addQuestion(){
		Graph g = panel.getGraph();
		if(g != null){
			ief.updateQuestions(g);
		}
	}
	
}

⌨️ 快捷键说明

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