import java.awt.event.*; import java.awt.*; import javax.swing.*; import javax.swing.text.*; getKeyword() { noWordSep = "_/:"; lineNr = textArea.getCaretLine(); lineStart = textArea.getLineStartOffset(lineNr); offset = textArea.getCaretPosition() - lineStart; if(textArea.getLineLength(lineNr) == 0) return ""; String lineText = textArea.getLineText(lineNr); if(offset == textArea.getLineLength(lineNr)) offset--; wordStart = TextUtilities.findWordStart(lineText, offset, noWordSep); wordEnd = TextUtilities.findWordEnd(lineText, offset + 1, noWordSep); textArea.select(lineStart + wordStart, lineStart + wordEnd); String keyword = lineText.substring(wordStart, wordEnd); return keyword; } runQuery(keyword) { functionSearchCmd = "perldoc -t -T -f "; indexSearchCmd = "perlindex -nomenu -nocbreak "; keywordSearchCmd = "perldoc -t -T "; Vector resultVector= new Vector(); MainWin = new JFrame( "PerlDoc Results" ); SplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); SplitPane.setResizeWeight(0.0); doSearch(command, keyword) { String s; resultVector.removeAllElements(); p = Runtime.getRuntime().exec(command + keyword); out = new BufferedReader(new InputStreamReader(p.getInputStream())); while ( (s = out.readLine()) != null ) { resultVector.addElement(s); } p.waitFor(); if ( resultVector.size() == 0 ) { return 1; } else { return p.exitValue(); } } prepareKeywordSearchResults() { SimpleAttributeSet outputAttr = new SimpleAttributeSet(); DefaultStyledDocument textDocument = new DefaultStyledDocument(); JTextPane docPane = new JTextPane(textDocument); resElements = resultVector.elements(); while( resElements.hasMoreElements() ) { textDocument.insertString(textDocument.getLength(), resElements.nextElement() + "\n", outputAttr); } docPane.setEditable(false); docPane.setCaretPosition(0); JScrollPane docScrollPane = new JScrollPane( docPane ); docScrollPane.setMinimumSize(new Dimension(650,200)); return docScrollPane; } prepareIndexSearchResults() { i = 0; String[] columnNames = {"SCORE","DOCUMENT"}; String [][] resultArray = new String [15][2]; resElements = resultVector.elements(); while( resElements.hasMoreElements() ) { resTokens = new StringTokenizer( resElements.nextElement() ); while ( resTokens.hasMoreElements() ) { nextToken = resTokens.nextToken(); resultArray[i][0] = nextToken; nextToken = resTokens.nextToken(); if ( ! nextToken.startsWith("/") ) nextToken = "/" + nextToken; resultArray[i][1] = nextToken; i++; } } MenuTab = new JTable(resultArray, columnNames); MenuTab.getColumnModel().getColumn(0).setMaxWidth(100); MenuTab.setPreferredScrollableViewportSize(new Dimension(500, 100)); MenuTab.setSelectionBackground(new Color(255,255,155)); MenuTab.setRowSelectionAllowed(true); MenuTab.setDefaultEditor(Object.class, null); MenuTab.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); currentRow = 0; ListSelectionModel rowSM = MenuTab.getSelectionModel(); rowSM.addListSelectionListener(new ListSelectionListener() { void valueChanged(ListSelectionEvent e) { if ( ! e.getValueIsAdjusting() ) { currentRow = MenuTab.getSelectedRow(); keyword=""; keyword = MenuTab.getValueAt(currentRow,1); doSearch(keywordSearchCmd, keyword); showResultWin(prepareKeywordSearchResults(), "bottom"); } } }); JScrollPane docScrollPane = new JScrollPane( MenuTab ); docScrollPane.setMinimumSize(new Dimension(650,225)); return docScrollPane; } showIndexSearchDialog() { String keyword = ""; while ( keyword.length() == 0 ) { keyword = Macros.input(view, "Either you has not positioned the " + "cursor within a \nword or the word was no perl keyword. However " + "\nyou can search for any phrase in the complete \n" + "perl documentation and the documentation of all \n" + "installed modules using this dialog:" ); } return keyword; } showResultWin(results, hint) { MainWin.getContentPane().add(SplitPane); if ( hint.equals("top")) { MainWin.setSize(700,315); SplitPane.setTopComponent(results); } else { MainWin.setSize(700,500); SplitPane.setBottomComponent(results); } MainWin.getContentPane().setBorder(BorderFactory.createEmptyBorder(10,10,10,10)); MainWin.setDefaultCloseOperation( javax.swing.JFrame.DISPOSE_ON_CLOSE ); MainWin.show(); } if ( keyword.length() != 0 ) { if ( doSearch( functionSearchCmd, keyword ) == 0 ) { showResultWin(prepareKeywordSearchResults(), "top"); } else { if ( doSearch( indexSearchCmd, keyword ) == 0 ) { showResultWin( prepareIndexSearchResults(), "top" ); } else { if ( doSearch( indexSearchCmd, showIndexSearchDialog() ) == 0 ) { showResultWin( prepareIndexSearchResults(), "top" ); } else { Macros.message(view, "Sorry, your search returned no results"); } } } } else { if ( doSearch( indexSearchCmd, showIndexSearchDialog() ) == 0 ) { showResultWin( prepareIndexSearchResults(), "top" ); } else { Macros.message(view, "Sorry, your search returned no results"); } } } runQuery( getKeyword() );