/** * If the user hits ENTER key or double-click on a node, the corresponding file is open in * SciNotes. * * @param editor the editor where to open the file * @param the word pattern used * @param path the path of the node */ private static void validNode(SciNotes editor, final Pattern pat, TreePath path) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); Object userObj = node.getUserObject(); int lineNumber = -1; String fileName = null; boolean line = false; if (userObj instanceof SearchManager.MatchingPositions) { SearchManager.MatchingPositions pos = (SearchManager.MatchingPositions) userObj; lineNumber = 0; if (!pos.isDirectory()) { fileName = pos.getFileName(); } } else if (userObj instanceof SearchManager.Line) { SearchManager.Line l = (SearchManager.Line) userObj; lineNumber = l.getNumber(); fileName = ((SearchManager.MatchingPositions) ((DefaultMutableTreeNode) node.getParent()).getUserObject()) .getFileName(); line = true; } if (fileName != null) { final boolean fline = !line; final int ln = lineNumber; if (lineNumber != -1) { editor.openFile(fileName, 0, null); final ScilabEditorPane sep = editor.getTextPane(); if (sep.getName().equals(fileName)) { SwingUtilities.invokeLater( new Runnable() { @Override public void run() { sep.highlightWords(pat, fline); if (ln != 0) { sep.scrollTextToLineNumber(ln, false, false, true); } } }); } } } }
/** * actionPerformed * * @param ev ActionEvent */ public void actionPerformed(ActionEvent ev) { ScilabEditorPane sep = (ScilabEditorPane) ev.getSource(); ScilabDocument doc = (ScilabDocument) sep.getDocument(); int pos = sep.getCaretPosition(); Element root = doc.getDefaultRootElement(); int end = root.getElement(root.getElementIndex(pos)).getEndOffset() - 1; String str = ""; try { str = doc.getText(pos, end - pos); } catch (BadLocationException e) { System.err.println(e); } if (str.matches("[ \\t]+(then|do)")) { sep.setCaretPosition(end); } super.actionPerformed(ev); sep.getIndentManager().indentDoc(sep.getCaretPosition() - 1); }