/* Koders Search V3.1 * (c) 2008/06/12, by Thorsten Willert (thorsten.willert@gmx.de) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ import javax.swing.border.*; void koderssearch() { keyWord = new StringBuffer(); buffer.readLock(); int pos = textArea.getCaretPosition(); textArea.selectWord(); keyWord = textArea.getSelectedText(); textArea.setCaretPosition(pos); buffer.readUnlock(); //============================================================================== String sTitle = "www.koders.com - Koders Search V3.1, by Thorsten Willert"; String[] sLanguages = {"AUTO","*","ActionScript","Ada","ASP","Assembler","C","C#","Cpp","Cobol","ColdFusion","Delphi","Eiffel","Erlang","Fortran","Java","JavaScript","JSP","Lisp","Lua","Mathematica","Matlab","ObjectiveC","Perl","PHP","Prolog","Python","Ruby","Scheme","Smalltalk","SQL","Tcl","VB","VB.NET"}; String[] sLicense = {"*","AFL","AL20","ASL","APSL","BSD","CPL","EPL10","GTPL","GPL","LGPL","IBMPL","IOSL","MSCL","MSPL","MSRL","MSVSSDK","MITD","MPL10","MPL11","NPL10","NPL11","OSL","PSFL","SPL","W3C","WXWLL","ZLL","ZPL"}; //============================================================================== JFrame dialog = new JFrame(sTitle); content = new JPanel(new BorderLayout() ); dialog.setContentPane(content); dialog.setResizable(false); buttonPanel = new JPanel(new GridLayout(1,4,3,3) ); buttonPanel.setBorder( new EmptyBorder(3,3,3,3) ); buttonPanel.add( new JLabel("Language:") ); ComboType = new JComboBox(); for ( int i=0;i < sLanguages.length; i++) ComboType.addItem( sLanguages[i] ); buttonPanel.add( ComboType ); ComboType.setToolTipText("Select your programming language.
AUTO uses the edit-mode from the current buffer."); ButtonLicense = new JButton("License:"); // url doesn't work here! ButtonLicense.addActionListener(this); ButtonLicense.setToolTipText("Click for Open Source License Information"); ButtonLicense.setContentAreaFilled( false ); ButtonLicense.setBorderPainted( false ); buttonPanel.add( ButtonLicense ); ComboLicense = new JComboBox(); buttonPanel.add( ComboLicense ); for ( int i=0;i < sLicense.length; i++) ComboLicense.addItem( sLicense[i] ); content.add(buttonPanel, "Center"); ComboLicense.setToolTipText("Select your license."); ButtonSearchTerms = new JButton("Get"); ButtonSearchTerms.addActionListener(this); buttonPanel.add( ButtonSearchTerms ); ButtonSearchTerms.setToolTipText("Get the word unter the cursor."); SearchField = new HistoryTextField("macro.Koders_Search_Terms"); buttonPanel.add( SearchField ); SearchField.setToolTipText("
<search terms>Search for <search terms> within files.
cdef:<search terms>Search for classes whose name contains <search terms>
mdef:<search terms>Search for methods whose name contains <search terms>
idef:<search terms>Search for interfaces whose name contains <search terms>
file:<search terms>Search for files with names that match the <search terms>
"); ButtonSearch = new JButton("Search"); buttonPanel.add( ButtonSearch ); ButtonSearch.addActionListener(this); ButtonSearch.setToolTipText("Start searching ..."); dialog.pack(); dialog.setLocationRelativeTo(view); dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); dialog.setVisible(true); dialog.setAlwaysOnTop(true); if (keyWord != null) SearchField.setText( keyWord ); //============================================================================== void actionPerformed(e) { cmd = e.getActionCommand().toLowerCase(); if(cmd.indexOf("get") != -1) { buffer.readLock(); int pos = textArea.getCaretPosition(); textArea.selectWord(); keyWord = textArea.getSelectedText(); textArea.setCaretPosition(pos); buffer.readUnlock(); if (keyWord != null) SearchField.setText( keyWord ); } else if(cmd.indexOf("search") != -1) searchKoders(); else if(cmd.indexOf("license") != -1) openURL("http://www.koders.com/corp/support/license-info/"); } //============================================================================== void searchKoders() { // e.g. http://www.koders.com/default.aspx?s=md5&btn=&la=PHP&li=* if (ComboType.getSelectedItem().equals("AUTO")) { mode = buffer.getMode(); if ( mode.toString().equals("beanshell") ) mode = "java"; } else mode = ComboType.getSelectedItem(); String url = "http://www.koders.com/default.aspx?s=" + SearchField.getText() + "&btn=&la=" + mode + "&li=" + ComboLicense.getSelectedItem(); openURL(url); SearchField.addCurrentToHistory(); } //============================================================================== void openURL(url) { try { if (isWindowsPlatform() ) Runtime.getRuntime().exec( "rundll32 url.dll,FileProtocolHandler " + url ); else new HelpViewer(url); } catch(IOException x) { // couldn't exec browser System.err.println("Could not invoke browser"); System.err.println("Caught: " + x); } } } //============================================================================== public static boolean isWindowsPlatform() { String os = System.getProperty("os.name"); if ( os != null && os.startsWith("Windows")) return true; else return false; } //============================================================================== koderssearch(); /* Macro index data (in DocBook format) Koders_Search.bsh Searches for code on www.koders.com */