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

📄 relationpropertyframe.java

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

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

/**
 * This class represents the graphical window used to specify the properties of a relation.
 *
 * @author Fr閐閞ic F黵st
 */
public class RelationPropertyFrame extends JDialog implements ActionListener{
	
	private Relation r;
	private MainFrame mf;
	private GridBagLayout lay;
	private GridBagConstraints gbc;
	private JComboBox relationTypes;
	private int undefined;
	private JButton hypConc;
	private LinkedList rt;
	private Language currentLanguage;
	private boolean inAxiom;
	
	public RelationPropertyFrame(Relation r, MainFrame mf, boolean inAxiom){
		super(mf,Constants.PROPERTIES_OF_LABEL + r.getTerm(mf.getOntologyLanguage()),true);
		this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
		this.mf = mf;
		this.r = r;
		this.inAxiom = inAxiom;
		currentLanguage = mf.getOntologyLanguage();
		lay = new GridBagLayout();
		this.getContentPane().setLayout(lay);
		gbc = new GridBagConstraints();
		gbc.fill = GridBagConstraints.BOTH;
		gbc.weightx = 1.0;
		// Relation Types
		Label lab = new Label(Constants.RELATION_TYPE_LABEL);
		lay.setConstraints(lab,gbc);
		this.getContentPane().add(lab);
		relationTypes = new JComboBox();
		relationTypes.setMaximumRowCount(Constants.RELATION_TYPE_MAXIMUM_ROW_COUNT);
		rt = NamedObject.sortListByName(mf.getOntology().getRelationTypes(),mf.getOntologyLanguage());
		if(r.getType() == null){
			relationTypes.addItem(" ");
			this.undefined = 1;
		}
		else undefined = 0;
		for(Iterator i = rt.iterator();i.hasNext();){
			RelationType reltype = (RelationType) i.next();
			relationTypes.addItem(reltype.toString(mf.getOntologyLanguage()));
			if((r.getType() != null) && r.getType().equals(reltype)) relationTypes.setSelectedIndex(relationTypes.getItemCount() - 1);
		}
		relationTypes.addActionListener(new ActionListener(){
    		public void actionPerformed(ActionEvent e){
    			setType();
    		}
    	});
    	gbc.gridwidth = GridBagConstraints.REMAINDER;
    	lay.setConstraints(relationTypes,gbc);
    	this.getContentPane().add(relationTypes,gbc);
    	gbc.gridwidth = 1;
		// Hypothesis/Conclusion
    	if(inAxiom){	
	    	hypConc = new JButton(Constants.HYPOTHESIS_RELATION_LABEL);
			if(mf.getAxiomsFrame().getCurrentAxiom().hasConclusionRelation(r)) hypConc.setText(Constants.CONCLUSION_RELATION_LABEL);
			hypConc.addActionListener(new ActionListener(){
	    		public void actionPerformed(ActionEvent e){
	    			setHypConc();
	    		}
	    	});	
	    	gbc.weightx = 1.0;
	    	gbc.gridx = 0;
			gbc.gridwidth = GridBagConstraints.REMAINDER;
    		lay.setConstraints(hypConc,gbc);
			this.getContentPane().add(hypConc);
    	}	
		JButton ok = new JButton(Constants.OK_LABEL);
		ok.addActionListener(new ActionListener(){
    		public void actionPerformed(ActionEvent e){
    			setValues();
    		}
    	});
		gbc.weightx = 1.0;
		gbc.gridx = 0;
		gbc.gridwidth = GridBagConstraints.REMAINDER;
		lay.setConstraints(ok,gbc);
		this.getContentPane().add(ok);
		this.pack();
		this.setLocation((mf.getWidth() - this.getWidth())/2,(mf.getHeight() - this.getHeight())/2);
		this.getRootPane().registerKeyboardAction(this,"ok",KeyStroke.getKeyStroke(Constants.OK_KEY),JComponent.WHEN_IN_FOCUSED_WINDOW);
		this.setVisible(true);
		this.toFront();
	}
	
	public void actionPerformed(ActionEvent event){
		if(event.getActionCommand().equals("ok")) this.setValues();
	}
	
	public void processWindowEvent(WindowEvent e){
		if(e.getID() == WindowEvent.WINDOW_CLOSING) this.setValues();	
	}

	public void setValues(){
		if(this.inAxiom){
			if(mf.getAxiomsFrame().getCurrentAxiom().hasConclusionRelation(r) && hypConc.getText().equals(Constants.HYPOTHESIS_RELATION_LABEL)){
				mf.getAxiomsFrame().getCurrentAxiom().removeRelation(r);
				mf.getAxiomsFrame().getCurrentAxiom().addHypothesisRelation(r);
			}
			if(mf.getAxiomsFrame().getCurrentAxiom().hasHypothesisRelation(r) && hypConc.getText().equals(Constants.CONCLUSION_RELATION_LABEL)){
				mf.getAxiomsFrame().getCurrentAxiom().removeRelation(r);
				mf.getAxiomsFrame().getCurrentAxiom().addConclusionRelation(r);
			}
		}
		mf.repaint();
		this.dispose();
	}
	
	public void setType(){
		int i = relationTypes.getSelectedIndex() - undefined;
		if((i > -1) && (i < rt.size())) r.setType((RelationType) rt.get(i));
	}
	
	public void setHypConc(){
		if(hypConc.getText().equals(Constants.HYPOTHESIS_RELATION_LABEL)){
			hypConc.setText(Constants.CONCLUSION_RELATION_LABEL);
		}
		else hypConc.setText(Constants.HYPOTHESIS_RELATION_LABEL); 
	}
		
}

⌨️ 快捷键说明

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