popupontologysource.java
来自「Semantic Web Ontology Editor」· Java 代码 · 共 607 行 · 第 1/2 页
JAVA
607 行
while (true) { if (tmp.charAt(i)=='(') { balance++;seenFirst=true;} else if (tmp.charAt(i)==')') { balance--;seenFirst = true; } i++; if (balance==0 && seenFirst) break; if (i+start > doc.getLength()) { i = -1; break; } } if (i != -1) { codePane.select(start, start+i+1); } return start+i+1; } public String getEntityText(int startMatch, int endMatch) { Document doc = (Document) codePane.getDocument(); try { return doc.getText(startMatch, endMatch-startMatch); } catch (BadLocationException e) { return null; } } public int matchString(boolean forward, boolean showError) { // match the next occurence of originalSrc in codePane Document doc = (Document) codePane.getDocument(); if (forward) currentMatch++; else currentMatch--; try { boolean matchFound = false; while (currentMatch>=0 && currentMatch<(doc.getLength()-findMatch.length())) { String check = doc.getText(currentMatch, findMatch.length()); String prevChar = "_"; if (currentMatch>=1) prevChar = doc.getText(currentMatch-1, 1); String nextChar = "_"; if (currentMatch+findMatch.length()<doc.getLength()) nextChar = doc.getText(currentMatch+findMatch.length(), 1); int pcharValue = (int) prevChar.charAt(0); int ncharValue = (int) nextChar.charAt(0); boolean charsNotAlphabet = true; if (((ncharValue>=65 && ncharValue<=90) || (ncharValue>=97 && ncharValue<=122)) || ((pcharValue>=65 && pcharValue<=90) || (pcharValue>=97 && pcharValue<=122))) charsNotAlphabet = false; if (!matchCase) { check = check.toLowerCase(); findMatch = findMatch.toLowerCase(); } if ((matchWord && check.equals(findMatch) && charsNotAlphabet) || (!matchWord && check.indexOf(findMatch)>=0)) { matchFound = true; lastMatch = currentMatch; break; } if (forward) currentMatch++; else currentMatch--; } if (matchFound) { codePane.select(currentMatch, currentMatch+findMatch.length()); return currentMatch; } else { if (showError) JOptionPane.showMessageDialog(this, "No more matches found!", "Find Error", JOptionPane.ERROR_MESSAGE); currentMatch = lastMatch; } } catch (BadLocationException e) { e.printStackTrace(); } return -1; } public void actionPerformed(ActionEvent e) { if (e.getSource()==findMenu) { String findNewMatch = JOptionPane.showInputDialog( null, new Object[] { "Specify Search String:", caseChk, wordChk }, "Find", JOptionPane.PLAIN_MESSAGE ); if (findNewMatch!=null) { findMatch = findNewMatch; matchCase = caseChk.isSelected(); matchWord = wordChk.isSelected(); currentMatch = -1; matchString(true, true); } } if (e.getSource()==findPreviousMenu) { matchString(false, true); } if (e.getSource()==findNextMenu) { matchString(true, true); } if (e.getSource()==refreshOnt) { updateOntology(); } if (e.getSource()==saveOnt) { saveLocalOntology(); } if (e.getSource()==saveAsOnt) { ontFile = null; saveLocalOntology(); } } public void saveLocalOntology() { try { int returnVal; FileFilter[] filters = SwoopFileFilter.getOntologyFilters(); /* (*.swp, *.swo, *.owl, *.rdf, *.xml, ".txt) */ int mapFormatToFilterIndex[] = {1,4}; wrapChooser.setFileFilter(filters[mapFormatToFilterIndex[format]]); if(ontFile == null) { returnVal = wrapChooser.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { ontFile = wrapChooser.getSelectedFile(); } else { // load cancelled return; } } if (ontFile != null) { wrapChooser.setSelectedFile(ontFile); FileWriter writer = new FileWriter(ontFile); writer.write(codePane.getText()); writer.close(); } System.out.println("Ontology saved successfully at "+ontFile.getPath().toString()); } catch (Exception ex) { ex.printStackTrace(); } } public void windowClosing(WindowEvent e) { boolean closeWindow = true; if (srcChanged) { int result = JOptionPane.showConfirmDialog(this, "Do you want to update the ontology in SWOOP?", "Update Model", JOptionPane.YES_NO_CANCEL_OPTION); if(result==JOptionPane.YES_OPTION) { closeWindow = updateOntology(); } else if (result==JOptionPane.CANCEL_OPTION) { closeWindow = false; } else { closeWindow = true; } } if (closeWindow) { dispose(); } } public void windowOpened(WindowEvent arg0) { } public void windowClosed(WindowEvent arg0) { } public void windowIconified(WindowEvent arg0) { } public void windowDeiconified(WindowEvent arg0) { } public void windowActivated(WindowEvent arg0) { } public void windowDeactivated(WindowEvent arg0) { } public void keyPressed(KeyEvent arg0) { } public void keyTyped(KeyEvent arg0) { } public void keyReleased(KeyEvent arg0) { } // This one listens for edits that can be undone. protected class MyUndoableEditListener implements UndoableEditListener { public void undoableEditHappened(UndoableEditEvent e) { //Remember the edit and update the menus. undo.addEdit(e.getEdit()); undoAction.updateUndoState(); redoAction.updateRedoState(); } } class UndoAction extends AbstractAction { public UndoAction() { super("Undo"); setEnabled(false); putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_Z, ActionEvent.CTRL_MASK)); } public void actionPerformed(ActionEvent e) { try { undo.undo(); } catch (CannotUndoException ex) { System.out.println("Unable to undo: " + ex); ex.printStackTrace(); } updateUndoState(); redoAction.updateRedoState(); } protected void updateUndoState() { if (undo.canUndo()) { setEnabled(true); putValue(Action.NAME, undo.getUndoPresentationName()); putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_Z, ActionEvent.CTRL_MASK)); } else { setEnabled(false); putValue(Action.NAME, "Undo"); putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_Z, ActionEvent.CTRL_MASK)); } } } class RedoAction extends AbstractAction { public RedoAction() { super("Redo"); setEnabled(false); putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_Y, ActionEvent.CTRL_MASK)); } public void actionPerformed(ActionEvent e) { try { undo.redo(); } catch (CannotRedoException ex) { System.out.println("Unable to redo: " + ex); ex.printStackTrace(); } updateRedoState(); undoAction.updateUndoState(); } protected void updateRedoState() { if (undo.canRedo()) { setEnabled(true); putValue(Action.NAME, undo.getRedoPresentationName()); putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_Y, ActionEvent.CTRL_MASK)); } else { setEnabled(false); putValue(Action.NAME, "Redo"); putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_Y, ActionEvent.CTRL_MASK)); } } } private void srcModified() { srcChanged = true; dh.removeAllHighlights(); } public void insertUpdate(DocumentEvent arg0) { srcModified(); } public void removeUpdate(DocumentEvent arg0) { srcModified(); } public void changedUpdate(DocumentEvent arg0) { srcModified(); } public void mouseClicked(MouseEvent e) { } public void mousePressed(MouseEvent e) { if (e.getSource()==codePane) dh.removeAllHighlights(); } public void mouseReleased(MouseEvent arg0) { } public void mouseEntered(MouseEvent arg0) { } public void mouseExited(MouseEvent arg0) { }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?