versionedontology.java

来自「Semantic Web Ontology Editor」· Java 代码 · 共 1,850 行 · 第 1/5 页

JAVA
1,850
字号
		leftPanel.add(northPnl, "North");
		leftPanel.add(ontChangePanel, "Center");
		
		// RIGHT PANEL
		// setup repository info
		JPanel repPanel = new JPanel();
		JLabel repAuthorLbl = (JLabel) initComponent(JLabel.class, "Repository Author:");
		JLabel repDateLbl = (JLabel) initComponent(JLabel.class, "Repository Created Date:");
		JLabel repURLLbl = (JLabel) initComponent(JLabel.class, "Repository URL:");
		repAuthorFld = (JTextField) initComponent(JTextField.class, "");
		repDateFld = (JTextField) initComponent(JTextField.class, "");
		repURLFld = (JTextField) initComponent(JTextField.class, "");
		repURLFld.addKeyListener(this);
		JLabel repBaseOntLbl = (JLabel) initComponent(JLabel.class, "Repository Base Ontology URI:");
		repBaseOntFld = (JTextField) initComponent(JTextField.class, "");
		repTypeBox = (JComboBox) initComponent(JComboBox.class, "");
		repTypeBox.addItem(this.getVersioningType());
		repPanel.setLayout(new SpringLayout());
		repPanel.add(repURLLbl);
		repPanel.add(repURLFld);
		repPanel.add(repAuthorLbl);
		repPanel.add(repAuthorFld);
		repPanel.add(repDateLbl);
		repPanel.add(repDateFld);		
		repPanel.add(repBaseOntLbl);
		repPanel.add(repBaseOntFld);
		SpringUtilities.makeCompactGrid(repPanel,
                4, 2, // rows, cols
                6, 6, //initX, initY
                6, 6); //xPad, yPad
		repPanel.setBorder(border);
		
		// create toolbar panel
		JToolBar repToolBar = new JToolBar();
		repDeleteBtn = (JButton) this.initComponent(JButton.class, "Delete");
		repSelAllBtn = (JButton) this.initComponent(JButton.class, "Select All");
		repTestBtn = (JButton) this.initComponent(JButton.class, "Test All");
		repFilterBtn = (JButton) this.initComponent(JButton.class, "Filter");
		repFilterBtn.addMouseListener(this);
		repToolBar.add(repSelAllBtn);
		repToolBar.add(repDeleteBtn);
		repToolBar.add(repTestBtn);
		repToolBar.add(repFilterBtn);
		
		// create changes panel
		JPanel repChangePanel = new JPanel();
		repChangePanel.setLayout(new BorderLayout());
		// initialize change treetable and change editorpane
		repRoot = getTreeRoot();
		// also initialize newCommitNode
		newCommitNode = new TreeTableNode(new SwoopChange(swoopModel.getUserName(), null, null, swoopModel.getTimeStamp(), "New Version Commit", true, true));
		newCommitNode.swoopChange.isTopNode = true;
		// add newCommitNode to root
		repRoot.addChild(newCommitNode);
		repChangeTT = new JTreeTable(new DefaultTreeTableModel(repRoot, cNames));
		this.repChangeTT.setFont(tahoma);
		repChangeTT.getTree().setRootVisible(false);
		repChangeTT.getTree().addTreeSelectionListener(this);
		repTablePane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
		repTablePane.setTopComponent(new JScrollPane(repChangeTT));
		repChangeEdPane = new JEditorPane();
		repChangeEdPane.setContentType("text/html");
		repChangeEdPane.setEditable(false);
		repChangeEdPane.addHyperlinkListener(this);
		repTablePane.setBottomComponent(new JScrollPane(repChangeEdPane));
		repChanges = new ArrayList();
		
		// initialize button panel
		JPanel repBtnPanel = new JPanel();
		repBtnPanel.setLayout(new GridLayout(1,4));
		repBtnPanel.add(new JLabel(""));
		repUpdateBtn = (JButton) this.initComponent(JButton.class, "Update");
		repCommitBtn = (JButton) this.initComponent(JButton.class, "Commit");
		repBtnPanel.add(repUpdateBtn);
		repBtnPanel.add(repCommitBtn);
		repBtnPanel.add(new JLabel(""));
		repChangePanel.add(repTablePane, "Center");
		repChangePanel.add(repBtnPanel, "South");
		
		// right panel setup
		rightPanel = new JPanel();
		rightPanel.setLayout(new BorderLayout());
		JPanel northPanel = new JPanel();
		northPanel.setLayout(new BorderLayout());
		northPanel.add(repPanel, "Center");
		northPanel.add(repToolBar, "South");
		rightPanel.add(northPanel, "North");
		rightPanel.add(repChangePanel, "Center");
		
		splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
		splitPane.setLeftComponent(leftPanel);
		splitPane.setRightComponent(rightPanel);
		
		// main panel setup
		setLayout(new BorderLayout());
		// create topPanel with advanced check box
		JPanel topPanel = new JPanel();
		topPanel.setLayout(new BorderLayout());
		this.advancedChk = (JCheckBox) this.initComponent(JCheckBox.class, "Advanced");
		topPanel.add(advancedChk, "East");
		add(topPanel, "North");
		add(splitPane, "Center");
		// add status bar at the south
		statusBar = (JLabel) this.initComponent(JLabel.class, "Status:");
		statusBar.setFont(new Font("Verdana", Font.BOLD, 10));
		add(statusBar, "South");
		// set dividers after adding to ui
		ontTablePane.setDividerLocation(200);
		repTablePane.setDividerLocation(200);
		splitPane.setDividerLocation(300);
	}
	
	/*
	 * Create PopupMenus for the Filtering options for each changeTreeTable
	 */
	private void setupFilterPopupMenus() {
		
		// setup swoop ontology filter menu
		this.swoFilterMenu = new JPopupMenu();
		this.swoRedFMenu = (JMenuItem) this.initComponent(JMenuItem.class, "Remove Redundant Changes");
		this.swoRepFMenu = (JMenuItem) this.initComponent(JMenuItem.class, "Remove Repository Changes");
		this.swoLocFMenu = (JMenuItem) this.initComponent(JMenuItem.class, "Remove Local Changes");
		this.swoFilterMenu.add(swoRedFMenu);
		this.swoFilterMenu.add(swoRepFMenu);
		this.swoFilterMenu.add(swoLocFMenu);
		
		// setup repository ontology filter menu
		this.repFilterMenu = new JPopupMenu();
		this.repRedFMenu = (JMenuItem) this.initComponent(JMenuItem.class, "Remove Redundant Changes");
		this.repFilterMenu.add(repRedFMenu);		
	}
	
	/**
	 * Common method to initialize JComponents in the UI
	 */
	private JComponent initComponent(Class compClass, String label) {
		JComponent comp = null;
		if (compClass == JLabel.class) {
			comp = new JLabel(label);			
		}
		else if (compClass == JTextField.class) {
			comp = new JTextField();			
		}
		else if (compClass == JComboBox.class) {
			comp = new JComboBox();
			((JComboBox) comp).addActionListener(this);
		}
		else if (compClass == JButton.class) {
			comp = new JButton(label);
			((JButton) comp).addActionListener(this);
		}
		else if (compClass == JRadioButton.class) {
			comp = new JRadioButton(label);
			((JRadioButton) comp).addActionListener(this);
		}
		else if (compClass == JMenuItem.class) {
			comp = new JMenuItem(label);
			((JMenuItem) comp).addActionListener(this);
		}
		else if (compClass == JCheckBox.class) {
			comp = new JCheckBox(label);
			((JCheckBox) comp).addActionListener(this);
		}
		comp.setFont(tahoma);
		return comp;
	}
	
	private JPanel createPanel(JComponent left, JComponent center, JComponent right) {
		JPanel panel = new JPanel();
		panel.setLayout(new BorderLayout());
		if (left!=null) panel.add(left, "West");
		panel.add(center, "Center");
		if (right!=null) panel.add(right, "East");
		return panel;
	}
	
	private String getVersioningType() {
		
		switch (versioningFormat) {
			case 0 :
				return "Annotated Change Set";
			// maybe other types of formats: ontology as a whole etc
		}
		return "";
	}
	
	public TreeTableNode getTreeRoot() {
		SwoopChange root = null;
		try {
			root = new SwoopChange("", new URI("/"), null, "", "", true, true);
		}
		catch (Exception ex) {
		}
		return new TreeTableNode(root);
	}

	public void actionPerformed(ActionEvent e) {
		
		// if ontology box is selected 
		if (e.getSource()==ontBox && e.getActionCommand().equals("comboBoxChanged")) {
			// load changes from Swoop into this pane
			
		}
		// if swoop ontology update button is pressed
		else if (e.getSource() == swoUpdateBtn) {
			this.updateOntChanges();
		}
		// if swoop ontology commit button is pressed
		else if (e.getSource() == swoCommitBtn) {
			this.commitOntChanges(false);
		}
		// if ont -> rep transfer button is pressed
		else if (e.getSource() == moveRBtn) {
			this.transferChanges(ontChangeTT, repChangeTT);
		}
		// if rep -> ont transfer button is pressed
		else if (e.getSource() == moveLBtn) {
			this.transferChanges(repChangeTT, ontChangeTT);
		}		
		// if rep commit button is pressed
		else if (e.getSource() == repCommitBtn) {
			this.commitRepChanges();
		}
		// if rep update button is pressed
		else if (e.getSource() == repUpdateBtn) {
			this.updateRepChanges(true);
		}
		// if delete swoop ontology annotations button is pressed
		else if (e.getSource() == swoDeleteBtn) {
			this.deleteChanges(ontChangeTT);
		}
		// if delete repository annotations button is pressed
		else if (e.getSource() == repDeleteBtn) {
			this.deleteChanges(repChangeTT);
//			this.deleteRepository(); // TESTING PURPOSES ONLY			
		}
		else if (e.getSource() == swoSelAllBtn) {
			ontChangeTT.selectAll();
			ontChangeTT.selectAll(); // need to do it twice?! Fix this
		}
		else if (e.getSource() == repSelAllBtn) {
			repChangeTT.selectAll();
			repChangeTT.selectAll();
		}
		// swoop ontology: test changes
		else if (e.getSource() == swoTestBtn) {
			this.testChanges(false);
		}
		// repository: test changes
		else if (e.getSource() == repTestBtn) {
			this.testChanges(true);
		}
		
		// filter menus
		else if (e.getSource() == swoRedFMenu) {
			this.filter(false, this.REDUNDANT_CHANGE);
		}
		else if (e.getSource() == swoRepFMenu) {
			this.filter(false, this.REPOSITORY_CHANGE);
		}
		else if (e.getSource() == swoLocFMenu) {
			this.filter(false, this.LOCAL_CHANGE);
		}
		else if (e.getSource() == repRedFMenu) {
			this.filter(true, this.REDUNDANT_CHANGE);
		}
		// advanced check box
		else if (e.getSource() == advancedChk) {
			this.toggleAdvanced(advancedChk.isSelected());
		}
	}
	
	/*
	 * Toggle the Advanced Check Box UI setting
	 */
	private void toggleAdvanced(boolean enable) {
		
		this.advanced = enable;
		if (enable) {
			this.leftPanel.setVisible(true);
			splitPane.setDividerLocation(splitPaneDivPos);			
//			controlHandler.setSize(800, 600);			
		}
		else {
			splitPaneDivPos = splitPane.getDividerLocation();
			this.leftPanel.setVisible(false);
			splitPane.setDividerLocation(0);
//			controlHandler.setSize(400, 600);			
		}
	}
	
	/*
	 * Refresh Ontology Selection Box from SwoopModel
	 *
	 */
	protected void refreshOntBox() {
		ontBox.removeAllItems();
		
		Set sortedOntSet = new TreeSet(OntologyComparator.INSTANCE);
		sortedOntSet.addAll(swoopModel.getOntologies());
		for (Iterator iter=sortedOntSet.iterator(); iter.hasNext();) {
			OWLOntology ont = (OWLOntology) iter.next();
			ontBox.addItem(ont);
		}
	}
	
	/* Create column panel for transfer buttons */
	private JPanel createColPanel(JButton btn1, JButton btn2) {
		JPanel colPanel = new JPanel();
		colPanel.setLayout(new GridLayout(10,1));
		for (int i=0; i<3; i++) colPanel.add(new JLabel(""));
		colPanel.add(btn1);
		colPanel.add(btn2);
		for (int i=0; i<5; i++) colPanel.add(new JLabel(""));
		return colPanel;
	}
	
	// update changes list from swoop ontology
	private void updateOntChanges() {
		try {
			String status = "Status: [ACTION - Update Local Ontology]...";
			statusBar.setText(status);
			if (existingOntRadio.isSelected()) {
				OWLOntology ont = (OWLOntology) ontBox.getSelectedItem();
				List changes = swoopModel.getChangesCache().getChangeList(ont.getURI());
				for (int i=0; i<changes.size(); i++) {
					SwoopChange swc = (SwoopChange) changes.get(i);
					if (!isPresent(ontChanges, swc)) ontChanges.add(swc.clone());
				}
				this.sortChanges(ontChanges);
				this.refreshOntTreeTable(); 
			}
			statusBar.setText(status+"DONE");
		}
		catch (OWLException ex) {
			ex.printStackTrace();
		}
	}
	
	public void refreshOntTreeTable() {

		// get rootnode from changetreetable
		JTree changeTree = ontChangeTT.getTree();
		TreeTableNode rootNode = (TreeTableNode) changeTree.getModel().getRoot();
		rootNode.children = new Vector();
		this.ontChangeEdPane.setText("");
		
		// populate node tree
		for (Iterator changeIter = ontChanges.iterator(); changeIter.hasNext();) {
			SwoopChange swc = (SwoopChange) changeIter.next();
			
			// skip checkpoint related changes
			if (!swc.isCheckpointRelated /*&& swc.isCommitted*/) {
				TreeTableNode changeNode = new TreeTableNode(swc);
				rootNode.addChild(changeNode);				
			}
		}
		
		ontChangeTT.getTree().updateUI();
		this.refreshUI();		
	}
	
	private void refreshUI() {
		int loc = ontTablePane.getDividerLocation();
		ontTablePane.setTopComponent(new JScrollPane(ontChangeTT));
		ontTablePane.setDividerLocation(loc);
		loc = repTablePane.getDividerLocation();
		repTablePane.setTopComponent(new JScrollPane(repChangeTT));
		repTablePane.setDividerLocation(loc);
	}

⌨️ 快捷键说明

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