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

📄 mainframe.java

📁 toocom源代码,主要应用在本体匹配方面!
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
			JOptionPane.showMessageDialog(this,Constants.HELP_FILE_CANNOT_BE_FOUND);
		}
	}
	
	public void helpAbout(){
		JOptionPane.showMessageDialog(this,Constants.ABOUT_MESSAGE,Constants.ABOUT_TITLE + CGConstants.TOOCOM_VERSION,JOptionPane.PLAIN_MESSAGE,new InterfaceIcon(Constants.LINA_ICON));
	}
	
	/** Set the panels visible or not. */
	public void setPanelsVisible(boolean visible){
		this.osFrame.setVisible(visible);
		this.ctFrame.setVisible(visible);
		this.rtFrame.setVisible(visible);
		this.axiomsFrame.setVisible(visible);
	}
	
	/** Enable or disable the panels. */
	public void setPanelsEnabled(boolean enabled){
		this.osFrame.setEnabled(enabled);
		this.ctFrame.setEnabled(enabled);
		this.rtFrame.setEnabled(enabled);
		this.axiomsFrame.setEnabled(enabled);
	}
	
	public void processWindowEvent(WindowEvent e){
		if(e.getID() == WindowEvent.WINDOW_CLOSING) this.exitOntology();
	}
	
	public void actionPerformed(ActionEvent event){
			if(event.getActionCommand().equals("New ontology")) this.newOntology();
			if(event.getActionCommand().equals("Open ontology")) this.openOntology();
			if((event.getActionCommand().equals("Save ontology")) && (this.ontology != null)) this.saveOntology();
	}
	
	private JMenuBar constructMenuBar(){
		JMenuBar bar = new JMenuBar();
		// Ontology menu
		JMenu ontologyMenu = new JMenu(Constants.ONTOLOGY_MENU);
		this.newOntology = new JMenuItem(Constants.ONTOLOGY_NEW);
		this.newOntology.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				newOntology();
			}
		});
		ontologyMenu.add(newOntology);
		ontologyMenu.addSeparator();
		this.openOntology = new JMenuItem(Constants.ONTOLOGY_OPEN);
		this.openOntology.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				openOntology();
			}
		});
		ontologyMenu.add(openOntology);
		ontologyMenu.addSeparator();
		this.importOWLOntology = new JMenuItem(Constants.ONTOLOGY_IMPORT_OWL);
		this.importOWLOntology.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				importOWLOntology();
			}
		});
		ontologyMenu.add(importOWLOntology);
		ontologyMenu.addSeparator();
		this.operationalizeOntology = new JMenuItem(Constants.ONTOLOGY_OPERATIONALIZE);
		this.operationalizeOntology.setEnabled(false);
		this.operationalizeOntology.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				operationalizeOntology();
			}
		});
		ontologyMenu.add(operationalizeOntology);
		ontologyMenu.addSeparator();
		this.closeOntology = new JMenuItem(Constants.ONTOLOGY_CLOSE);
		this.closeOntology.setEnabled(false);
		this.closeOntology.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				closeOntology();
			}
		});
		ontologyMenu.add(closeOntology);
		ontologyMenu.addSeparator();
		this.saveOntology = new JMenuItem(Constants.ONTOLOGY_SAVE);
		this.saveOntology.setEnabled(false);
		this.saveOntology.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				saveOntology();
			}
		});
		ontologyMenu.add(saveOntology);
		//ontologyMenu.addSeparator();
		this.saveAsOntology = new JMenuItem(Constants.ONTOLOGY_SAVE_AS);
		this.saveAsOntology.setEnabled(false);
		this.saveAsOntology.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				saveAsOntology();
			}
		});
		ontologyMenu.add(saveAsOntology);
		ontologyMenu.addSeparator();
		this.exitOntology = new JMenuItem(Constants.ONTOLOGY_EXIT);
		this.exitOntology.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				exitOntology();
			}
		});
		ontologyMenu.add(exitOntology);
		bar.add(ontologyMenu);
		// Test Menu
		testsMenu = new JMenu(Constants.TESTS_MENU);
		testsMenu.setEnabled(false);
		JMenuItem testCT = new JMenuItem(Constants.CT_TEST);
		testCT.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				testCT();
			}
		});
		testsMenu.add(testCT);
		JMenuItem testInstances = new JMenuItem(Constants.INSTANCES_TEST);
		testInstances.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				testInstances();
			}
		});
		testsMenu.add(testInstances);
		JMenuItem testRT = new JMenuItem(Constants.RT_TEST);
		testRT.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				testRT();
			}
		});
		testsMenu.add(testRT);
		JMenuItem testAxioms = new JMenuItem(Constants.AXIOMS_TEST);
		testAxioms.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				testAxioms();
			}
		});
		testsMenu.add(testAxioms);
		JMenuItem testOntology = new JMenuItem(Constants.ONTOLOGY_TEST);
		testOntology.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				testOntology();
			}
		});
		testsMenu.add(testOntology);
		bar.add(testsMenu);
		// Matching Menu
		JMenu matchingMenu = new JMenu(Constants.MATCHING_MENU);
		JMenuItem matchingMatch = new JMenuItem(Constants.MATCHING_MATCH);
		matchingMatch.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				match(true);
			}
		});
		matchingMenu.add(matchingMatch);
		bar.add(matchingMenu);
		// Options Menu
		JMenu optionsMenu = new JMenu(Constants.OPTIONS_MENU);
		JMenuItem optionsConnect = new JMenuItem(Constants.OPTIONS_CONNECT);
		optionsConnect.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				connectToCogitant(true);
			}
		});
		optionsMenu.add(optionsConnect);
		optionsMenu.addSeparator();
		JMenuItem optionsMeta = new JMenuItem(Constants.OPTIONS_META);
		optionsMeta.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				meta();
			}
		});
		optionsMenu.add(optionsMeta);
		optionsMenu.addSeparator();		
		/*JMenuItem optionsInterfaceLanguage = new JMenuItem(Constants.OPTIONS_INTERFACE_LANGUAGE);
		optionsInterfaceLanguage.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				optionsInterfaceLanguage();
			}
		
		});
		optionsMenu.add(optionsInterfaceLanguage);*/
		LinkedList languages = Language.getAllLanguages();
		languageItemList = new LinkedList();
		optionsOntologyLanguage = new JMenu(Constants.OPTIONS_ONTOLOGY_LANGUAGE);
		int cpt = 0;
		for(Iterator i = languages.iterator();i.hasNext();){
			JRadioButtonMenuItem item = new JRadioButtonMenuItem(((Language) i.next()).getLabel());
			item.addActionListener(new ActionListener(){
				public void actionPerformed(ActionEvent e){
					optionsOntologyLanguage(e);
				}
			});
			if(cpt == 0) item.setSelected(true);
			cpt ++;
			optionsOntologyLanguage.add(item);
			languageItemList.add(item);
		}
		optionsMenu.add(optionsOntologyLanguage);
		bar.add(optionsMenu);	
		// Help menu
		JMenu helpMenu = new JMenu(Constants.HELP_MENU);
		JMenuItem helpHelp = new JMenuItem(Constants.HELP_HELP);
		helpHelp.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				helpHelp();
			}
		
		});
		helpMenu.add(helpHelp);
		helpMenu.addSeparator();
		JMenuItem helpAbout = new JMenuItem(Constants.HELP_ABOUT);
		helpAbout.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				helpAbout();
			}
		});
		helpMenu.add(helpAbout);
		bar.add(helpMenu);	
		return bar;
	}
	    	
	/** Connects TooCoM to CoGITaNT server. Display success or failure message if the message boolean
	 *  is true. */
	public void connectToCogitant(boolean message){
		if(cc == null){
			try{
				this.cc = new CogitantClient(CGConstants.COGITANT_IP,CGConstants.COGITANT_PORT,CGConstants.TRACE);
				System.out.println("Connection to CoGITaNT etablished");
				if(message) JOptionPane.showMessageDialog(this,Constants.CONNECTION_TO_COGITANT_SUCCEEDED);
			}
			catch(IOException e){
				System.out.println(e.getMessage());
				System.out.println("Be sure that the cogitant server is running!!");
				if(message) JOptionPane.showMessageDialog(this,Constants.CONNECTION_TO_COGITANT_FAILED);
			}
		}
		else JOptionPane.showMessageDialog(this,Constants.CONNECTION_TO_COGITANT_ALREADY_ETABLISHED);
	}
	
	/** Open the ontology metagraph builder. */    	
	public void meta(){
		JFileChooser fileChooser = new JFileChooser(Constants.APPLICATION_DIRECTORY);
		fileChooser.setDialogTitle(Constants.ONTOLOGY_METAGRAPH_ONTO_TITLE);
		fileChooser.setAcceptAllFileFilterUsed(false);
		fileChooser.setFileFilter(new CGXMLFileFilter());
		if(fileChooser.showDialog(this,Constants.SELECT_BUTTON_LABEL) == JFileChooser.APPROVE_OPTION){
			File source = fileChooser.getSelectedFile();
			if(source.exists()){
				fileChooser = new JFileChooser(Constants.APPLICATION_DIRECTORY);
				fileChooser.setDialogTitle(Constants.ONTOLOGY_METAGRAPH_GRAPH_TITLE);
				fileChooser.setAcceptAllFileFilterUsed(false);
				fileChooser.setFileFilter(new CGXMLFileFilter());
				if(fileChooser.showDialog(this,Constants.SELECT_BUTTON_LABEL) == JFileChooser.APPROVE_OPTION){
					File target = fileChooser.getSelectedFile();
					if(!target.getName().endsWith(CGXMLFileFilter.CGXML_FILE_EXTENSION)) target = new File(target.getAbsolutePath() + CGXMLFileFilter.CGXML_FILE_EXTENSION);
					try{
						MetaGraph.buildMetaGraph(source,target,new File(Constants.METAOCGL_FILE_NAME),this.getOntologyLanguage());
						System.gc();
						JOptionPane.showMessageDialog(this,Constants.METAGRAPH_BUILDING_SUCCESSFULL);
					}
					catch(Exception e){
						System.out.println(e.toString());
						JOptionPane.showMessageDialog(this,Constants.METAGRAPH_BUILDING_PROBLEM_MESSAGE + "\n\n" + e.getMessage());
					}
				}
			}
			else JOptionPane.showMessageDialog(this,Constants.FILE_NOT_FOUND_OR_ACCESS_PROBLEM);
		}
	}
	
	public void importOWLOntology(){
		if((ontology == null) || this.closeOntology()){
			JFileChooser fileChooser = new JFileChooser(Constants.APPLICATION_DIRECTORY);
			fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES );
			fileChooser.setAcceptAllFileFilterUsed(false);
			fileChooser.setFileFilter(new OWLFileFilter());
			if(fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION){
				try{
					this.ontology = OWLParser.loadOntology(fileChooser.getSelectedFile().toURI(),this.getOntologyLanguage(),true);
					if(this.ontology != null){
						this.closeOntology.setEnabled(true);
						this.saveOntology.setEnabled(true);
						this.saveAsOntology.setEnabled(true);
						this.operationalizeOntology.setEnabled(true);
						this.testsMenu.setEnabled(true);
						this.setTitle(Constants.TOOCOM_TITLE + " - " + this.ontology.getTerm(this.getOntologyLanguage()));
						this.ontoFile = fileChooser.getSelectedFile().getPath();
						this.osFrame.refresh();
						this.axiomsFrame.clear();
						this.ctFrame.refreshTree();
						this.rtFrame.refreshTree();
					}
					else{
						JOptionPane.showMessageDialog(this,Constants.LOADING_ONTOLOGY_PROBLEM_MESSAGE);
					}
				}
				catch(Exception e){
					System.out.println(e.getClass().toString());
					System.out.println(e.getMessage());
					JOptionPane.showMessageDialog(this,Constants.FILE_NOT_FOUND_OR_ACCESS_PROBLEM);
				}
			}
		}
	}
	
	public MainFrame(){
		super(Constants.TOOCOM_TITLE + " - " + Constants.NO_ONTOLOGY_TITLE);
		this.setIconImage((new InterfaceIcon(Constants.TOOCOM_ICON)).getImage());
		this.interfaceLanguage = Language.ENGLISH;
		this.ontologyLanguage = Language.ENGLISH;
		Locale.setDefault(Locale.UK);
		this.connectToCogitant(false);
		Dimension screenDimension = Toolkit.getDefaultToolkit().getScreenSize();
	    Constants.setDimensions(screenDimension.width,screenDimension.height);
	    this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
	    JPanel jp = new JPanel(new BorderLayout());
	    jp.setOpaque(true);
	    this.setContentPane(jp);
		//this.getContentPane().setLayout(new BorderLayout());
		this.setJMenuBar(this.constructMenuBar());
		// Construction of the internal frames
		tabbedPane = new JTabbedPane();
		tabbedPane.setBackground(Constants.TABBED_PANE_COLOR);
		this.ctFrame = new ConceptTypesFrame(this);
		this.rtFrame = new RelationTypesFrame(this);
		this.axiomsFrame = new AxiomsFrame(this);
		tabbedPane.addTab(Constants.CONCEPT_TYPES_TAB_LABEL,ctFrame);
		tabbedPane.setBackgroundAt(0,Constants.CONCEPT_TYPES_FRAME_COLOR);
		tabbedPane.addTab(Constants.RELATIONS_TYPES_TAB_LABEL,rtFrame);
		tabbedPane.setBackgroundAt(1,Constants.RELATION_TYPES_FRAME_COLOR);
		tabbedPane.addTab(Constants.AXIOMS_TAB_LABEL,axiomsFrame);
		tabbedPane.setBackgroundAt(2,Constants.AXIOMS_FRAME_COLOR);
		tabbedPane.setSelectedIndex(0);
		this.getContentPane().add(tabbedPane,BorderLayout.EAST);
		this.osFrame = new OntologySummaryFrame(this);
		JScrollPane leftScrollPanel = new JScrollPane(osFrame);
		tabbedPane.setPreferredSize(new Dimension(Constants.TABBED_PANE_WIDTH,Constants.TABBED_PANE_HEIGHT));
	  	JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,leftScrollPanel,tabbedPane);
	    splitPane.setDividerSize(Constants.SPLIT_DIVIDER_SIZE);
	    splitPane.setOneTouchExpandable(true);
	    this.getContentPane().add(splitPane,BorderLayout.NORTH);
		// Key listener
		this.getRootPane().registerKeyboardAction(this,"New ontology",KeyStroke.getKeyStroke(Constants.NEW_ONTOLOGY_KEY),JComponent.WHEN_IN_FOCUSED_WINDOW);
		this.getRootPane().registerKeyboardAction(this,"Open ontology",KeyStroke.getKeyStroke(Constants.OPEN_ONTOLOGY_KEY),JComponent.WHEN_IN_FOCUSED_WINDOW);
		this.getRootPane().registerKeyboardAction(this,"Save ontology",KeyStroke.getKeyStroke(Constants.SAVE_ONTOLOGY_KEY),JComponent.WHEN_IN_FOCUSED_WINDOW);
		// Window listener
		this.addWindowListener(new WindowAdapter(){});
	    this.setResizable(true);
	    this.pack();
	    splitPane.setDividerLocation(Constants.SPLIT_PANE_DIVIDER_LOCATION);
		this.setVisible(true);
		this.setExtendedState(Frame.MAXIMIZED_BOTH);				
	}
			
	public static void main(String[] args){
		if(args.length > 0){
			Constants.APPLICATION_DIRECTORY = args[0];
		}
		else Constants.APPLICATION_DIRECTORY = System.getProperty("user.dir");
		MainFrame mainFrame = new MainFrame();
		if(args.length > 1) mainFrame.openOntologyFile(args[1]);
		
	}	

}

⌨️ 快捷键说明

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