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

📄 operationalizationform.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 context of use of axioms are set.
 *
 * @author Fr閐閞ic F黵st
 */
public class OperationalizationForm extends JDialog{

	private MainFrame mf;
	private JComboBox[] boxes;
	private GridBagLayout lay;
	private GridBagConstraints gbc;
	private JToolBar buttonBox;
	
	public void refresh(){
		int cpt = 0;
		for(Iterator i = NamedObject.sortListByName(mf.getOntology().getAxioms(),mf.getOntologyLanguage()).iterator();i.hasNext();cpt ++){
			Axiom a = (Axiom) i.next();
			System.out.println("REFRESH : axiom " + a.getTerm(mf.getOntologyLanguage()) + " cou = " + a.getContextOfUse().getTerm(mf.getOntologyLanguage()));
			if(a.getContextOfUse().isInferential()){
				if(a.getContextOfUse().isExplicit()) boxes[cpt].setSelectedIndex(0);
				else boxes[cpt].setSelectedIndex(1);
			}
			else{
				if(a.getContextOfUse().isExplicit()) boxes[cpt].setSelectedIndex(2);
				else boxes[cpt].setSelectedIndex(3);
			}
		}
		
	}
		
	public void setContextOfUse(ItemEvent e,int axiomId){	
		Axiom a = (Axiom) mf.getOntology().getObject(axiomId);
		ContextOfUse cou = new ContextOfUse(true,true);
		if(((String) e.getItem()).equals(cou.getTerm(mf.getOntologyLanguage()))) a.setContextOfUse(new ContextOfUse(true,true));
		cou = new ContextOfUse(true,false);
		if(((String) e.getItem()).equals(cou.getTerm(mf.getOntologyLanguage()))) a.setContextOfUse(new ContextOfUse(true,false));
		cou = new ContextOfUse(false,true);
		if(((String) e.getItem()).equals(cou.getTerm(mf.getOntologyLanguage()))) a.setContextOfUse(new ContextOfUse(false,true));
		cou = new ContextOfUse(false,false);
		if(((String) e.getItem()).equals(cou.getTerm(mf.getOntologyLanguage()))) a.setContextOfUse(new ContextOfUse(false,false));
	}
	
	public void saveOpe(){
		JFileChooser fileChooser = new JFileChooser(Constants.APPLICATION_DIRECTORY);
		fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES );
		fileChooser.setAcceptAllFileFilterUsed(false);
		fileChooser.setFileFilter(new OperationalizationFileFilter());
		if(fileChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION){
			try{
				File f = fileChooser.getSelectedFile();
				if(!f.getName().endsWith(OperationalizationFileFilter.OPERATIONALIZATION_FILE_EXTENSION)) f = new File(f.getPath() + OperationalizationFileFilter.OPERATIONALIZATION_FILE_EXTENSION);
				if(!f.exists() || (JOptionPane.showConfirmDialog(this,f.getName() + "\n" + Constants.OVERWRITE_FILE_MESSAGE) == JOptionPane.OK_OPTION)){
					PrintStream stream = new PrintStream(new FileOutputStream(f),true);	
					stream.print(CGConstants.OPERATIONALIZATION_FILE_HEADER);
					stream.println();
					stream.println();
					stream.print(mf.getOntology().getTerm(mf.getOntologyLanguage()));
					stream.println();
					stream.println();
					for(Iterator i = mf.getOntology().getAxioms().iterator();i.hasNext();){
						Axiom a = (Axiom) i.next();
						stream.print(a.getTerm(mf.getOntologyLanguage()) + " - " + a.getContextOfUse().getTerm(mf.getOntologyLanguage()));
						stream.println();
					}
					stream.close();
					JOptionPane.showMessageDialog(this,Constants.SAVING_OPERATIONALIZATION_SUCCESSFULL_MESSAGE);
				}
			}
			catch(Exception e){
				JOptionPane.showMessageDialog(this,Constants.SAVING_OPERATIONALIZATION_PROBLEM_MESSAGE);
				JOptionPane.showMessageDialog(this,e.getMessage());
			}
		}
	}
	
	public void loadOpe(){
		JFileChooser fileChooser = new JFileChooser(Constants.APPLICATION_DIRECTORY);
		fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES );
		fileChooser.setAcceptAllFileFilterUsed(false);
		fileChooser.setFileFilter(new OperationalizationFileFilter());
		if(fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION){
			try{
				BufferedReader stream = new BufferedReader(new FileReader(fileChooser.getSelectedFile().getPath()));	
				String line = stream.readLine();
				line = stream.readLine();
				line = stream.readLine();
				if(line.equals(mf.getOntology().getTerm(mf.getOntologyLanguage()))){
					line = stream.readLine();
					line = stream.readLine();
					while(line != null){
						int i = line.lastIndexOf(" - ");
						String name = line.substring(0,i);
						String cou = line.substring(i + 3);
						Axiom a = mf.getOntology().getAxiom(name,mf.getOntologyLanguage());
						ContextOfUse context = new ContextOfUse(true,true);
						if(cou.equals(context.getTerm(mf.getOntologyLanguage()))) a.setContextOfUse(context);
						else{
							context = new ContextOfUse(true,false);
							if(cou.equals(context.getTerm(mf.getOntologyLanguage()))) a.setContextOfUse(context);
							else{
								context = new ContextOfUse(false,true);
								if(cou.equals(context.getTerm(mf.getOntologyLanguage()))) a.setContextOfUse(context);
								else{
									context = new ContextOfUse(false,false);
									if(cou.equals(context.getTerm(mf.getOntologyLanguage()))) a.setContextOfUse(context);
								}
							}
						}
						line = stream.readLine();
						System.out.println("LOAD : axiom " + a.getTerm(mf.getOntologyLanguage()) + " cou = " + a.getContextOfUse().getTerm(mf.getOntologyLanguage()));
					}
				}
				else JOptionPane.showMessageDialog(this,Constants.LOADING_OPERATIONALIZATION_PROBLEM_MESSAGE + "\n" + Constants.BAD_ONTOLOGY_NAME_ERROR);
				this.refresh();
				stream.close();
			}
			catch(Exception e){
				JOptionPane.showMessageDialog(this,Constants.FILE_NOT_FOUND_OR_ACCESS_PROBLEM);
			}
		}
	}
	
	public void ok(){
		mf.launchInferenceEngine();
		this.dispose();
	}
	
	public OperationalizationForm(MainFrame mf){
		super(mf,Constants.OPERATIONALIZATION_FORM_FRAME_TITLE + " - " + mf.getOntology().getTerm(mf.getOntologyLanguage()));
		this.mf = mf;
		this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
		this.setBackground(Constants.OPERATIONALIZATION_FORM_FRAME_COLOR);
		this.setLocation(mf.getSize().width/6,mf.getSize().height/6);
		buttonBox = new JToolBar();
		buttonBox.setLayout(new FlowLayout(FlowLayout.CENTER));
		buttonBox.setFloatable(false);
		// Load operationalization Button
    	JButton loadOpe = new JButton(new InterfaceIcon(Constants.LOAD_OPERATIONALIZATION_ICON));
		loadOpe.setMaximumSize(new Dimension(Constants.INTERNAL_FRAME_BUTTON_DIM,Constants.INTERNAL_FRAME_BUTTON_DIM));
		loadOpe.setMinimumSize(new Dimension(Constants.INTERNAL_FRAME_BUTTON_DIM,Constants.INTERNAL_FRAME_BUTTON_DIM));
		loadOpe.setBorder(BorderFactory.createRaisedBevelBorder());
		loadOpe.addActionListener(new ActionListener(){
    		public void actionPerformed(ActionEvent e){
    			loadOpe();
    		}
    	});
    	loadOpe.setToolTipText(Constants.LOAD_OPERATIONALIZATION_TIPTEXT);
    	loadOpe.setVisible(true);
    	buttonBox.add(loadOpe);
    	// OK Button
    	JButton ok = new JButton(new InterfaceIcon(Constants.OK_ICON));
		ok.setMaximumSize(new Dimension(Constants.INTERNAL_FRAME_BUTTON_DIM,Constants.INTERNAL_FRAME_BUTTON_DIM));
		ok.setMinimumSize(new Dimension(Constants.INTERNAL_FRAME_BUTTON_DIM,Constants.INTERNAL_FRAME_BUTTON_DIM));
		ok.setBorder(BorderFactory.createRaisedBevelBorder());
		ok.addActionListener(new ActionListener(){
    		public void actionPerformed(ActionEvent e){
    			ok();
    		}
    	});
    	ok.setToolTipText(Constants.LAUNCH_INFERENCE_ENGINE_TIPTEXT);
    	ok.setVisible(true);
    	buttonBox.add(ok);
    	// Save operationalization Button
    	JButton saveOpe = new JButton(new InterfaceIcon(Constants.SAVE_OPERATIONALIZATION_ICON));
		saveOpe.setMaximumSize(new Dimension(Constants.INTERNAL_FRAME_BUTTON_DIM,Constants.INTERNAL_FRAME_BUTTON_DIM));
		saveOpe.setMinimumSize(new Dimension(Constants.INTERNAL_FRAME_BUTTON_DIM,Constants.INTERNAL_FRAME_BUTTON_DIM));
		saveOpe.setBorder(BorderFactory.createRaisedBevelBorder());
		saveOpe.addActionListener(new ActionListener(){
    		public void actionPerformed(ActionEvent e){
    			saveOpe();
    		}
    	});
    	saveOpe.setToolTipText(Constants.SAVE_OPERATIONALIZATION_TIPTEXT);
    	saveOpe.setVisible(true);
    	buttonBox.add(saveOpe);
    	this.getContentPane().setLayout(new BorderLayout());
    	this.getContentPane().add(buttonBox,BorderLayout.NORTH);
    	JPanel pane = new JPanel();
    	JScrollPane scroll = new JScrollPane(pane);
    	this.getContentPane().add(scroll,BorderLayout.CENTER);
    	lay = new GridBagLayout();
		pane.setLayout(lay);
		gbc = new GridBagConstraints();
		gbc.fill = GridBagConstraints.BOTH;
		gbc.weightx = 1.0;
		gbc.weighty = 2.0;
		gbc.gridwidth = GridBagConstraints.REMAINDER;
		//lay.setConstraints(buttonBox,gbc);		
		boxes = new JComboBox[mf.getOntology().getAxioms().size()];
		int cpt = 0;
		for(Iterator i = NamedObject.sortListByName(mf.getOntology().getAxioms(),mf.getOntologyLanguage()).iterator();i.hasNext();cpt ++){
			Axiom a = (Axiom) i.next();
			// Label
			JLabel lab = new JLabel(a.getTerm(mf.getOntologyLanguage()));
			gbc.weightx = 1.0;
			gbc.gridwidth = 1;
			lay.setConstraints(lab,gbc);
			pane.add(lab);
			lab = new JLabel(Constants.OPERATIONALIZED_IN_CONTEXT);
			lab.setFont(lab.getFont().deriveFont(Font.ITALIC));
			gbc.weightx = 1.0;
			gbc.gridwidth = 1;
			lay.setConstraints(lab,gbc);
			pane.add(lab);
			// Contexts of use
			JComboBox box = new JComboBox();
			for(Iterator j = ContextOfUse.getAllAvailableContexts().iterator();j.hasNext();){
				ContextOfUse cou = (ContextOfUse) j.next();
				box.addItem(cou.getTerm(mf.getOntologyLanguage()));
				if(cou.isInferential() && !cou.isExplicit()){
					a.setContextOfUse(cou);
					box.setSelectedIndex(box.getItemCount() - 1);
				}
			}
			final int id = a.getId();
			box.addItemListener(new ItemListener(){
    			public void itemStateChanged(ItemEvent e){
    				setContextOfUse(e,id);
    			}
    		});
    		gbc.weightx = 2.0;
			gbc.gridwidth = GridBagConstraints.REMAINDER;
			lay.setConstraints(box,gbc);
			pane.add(box);
			boxes[cpt] = box;
		}
		if(mf.getOntology().getAxioms().size() > 20) this.setSize(mf.getSize().width*2/3,mf.getSize().height*2/3);
		else this.pack();
		this.setVisible(true);
		this.toFront();
	}
	
	
}
	

⌨️ 快捷键说明

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