📄 thumbelinaframe.java
字号:
* Based on the action of the event, executes the necessary subroutine. * @param actionEvent The event describing the user action. */ public void actionPerformed (final ActionEvent actionEvent) { String action; action = actionEvent.getActionCommand (); if (action.equals ("Open")) open (); else if (action.equals ("Google")) googlesearch (); else if (action.equals ("Reset")) getThumbelina ().reset (); else if (action.equals ("Clear")) getThumbelina ().getPicturePanel ().reset (); else if (action.equals ("About")) about (); else if (action.equals ("Exit")) exit (); else { // must be a URL from the most recently used list getThumbelina ().open (action); updateMRU (action); updateMenu (); } } // // ItemListener interface // /** * Handles selections on the view state checkboxes. * @param event The event describing the checkbox affected. */ public void itemStateChanged (final ItemEvent event) { Object source; boolean visible; source = event.getItemSelectable (); visible = ItemEvent.SELECTED == event.getStateChange (); if (source == mStatusVisible) getThumbelina ().setStatusBarVisible (visible); else if (source == mHistoryVisible) getThumbelina ().setHistoryListVisible (visible); } // // PropertyChangeListener // /** * Handle a property change. * @param event The property old and new values. */ public void propertyChange (final PropertyChangeEvent event) { String url; if (event.getPropertyName ().equals ( Thumbelina.PROP_CURRENT_URL_PROPERTY)) { url = (String)event.getNewValue (); if (null == url) setTitle ("Thumbelina"); else setTitle ("Thumbelina - " + url); } } /** * Updates the user preferences based on the most recently used list. * @param url The URL that is to be placed at the top of the MRU list. */ public void updateMRU (String url) { Preferences prefs; int count; ArrayList list; String string; int max; if (url.startsWith ("http://")) url = url.substring (7); prefs = Preferences.userNodeForPackage (getClass ()); count = prefs.getInt (MRULENGTH, -1); list = new ArrayList (); for (int i = 0; i < count; i++) { string = prefs.get (MRUPREFIX + i, ""); if (!"".equals (string) && !url.equalsIgnoreCase (string)) list.add (string); } list.add (0, url); max = prefs.getInt (MRUMAX, -1); if (-1 == max) max = 8; while (list.size () > max) list.remove (max); prefs.putInt (MRULENGTH, list.size ()); prefs.putInt (MRUMAX, max); for (int i = 0; i < list.size (); i++) prefs.put (MRUPREFIX + i, (String)list.get (i)); try { prefs.flush (); } catch (BackingStoreException bse) { bse.printStackTrace (); } } /** * Opens a user specified URL. */ public void open () { String result; result = JOptionPane.showInputDialog ( this, "Enter the URL:", "Open URL", JOptionPane.PLAIN_MESSAGE); if (null != result) { getThumbelina ().open (result); updateMRU (result); updateMenu (); } } /** * Query google via user specified keywords and queue results. * Asks the user for keywords, and then submits them as input to the * usual google form: * <pre> * <form action="/search" name=f> * <span id=hf></span> * <table cellspacing=0 cellpadding=0> * <tr valign=middle> * <td width=75> </td> * <td align=center> * <input maxLength=256 size=55 name=q value=""> * <input type=hidden name=ie value="UTF-8"> * <input type=hidden name=oe value="UTF-8"> * <input name=hl type=hidden value=en><br> * <input type=submit value="Google Search" name=btnG> * <input type=submit value="I'm Feeling Lucky" name=btnI> * </td> * <td valign=top nowrap><font size=-2> * • <a href=/advanced_search?hl=en>Advanced Search</a> * <br> • <a href=/preferences?hl=en>Preferences</a> * <br> • <a href=/language_tools?hl=en>Language Tools</a> * </font> * </td> * </tr> * <tr> * <td colspan=3 align=center><font size=-1> * Search: <input id=all type=radio name=meta value="" checked> * <label for=all> the web</label> * <input id=cty type=radio name=meta value="cr=countryCA" > * <label for=cty>pages from Canada</label> * </font> * </td> * </tr> * </table> * </form> * </pre> * Creates a query of the form: * <pre> * http://www.google.ca/search?hl=en&ie=UTF-8&oe=UTF-8&q=thumbs&btnG=Google+Search&meta= * </pre> */ public void googlesearch () { Preferences prefs; String query; String terms; StringBuffer buffer; HttpURLConnection connection; URL url; Lexer lexer; URL[][] results; prefs = Preferences.userNodeForPackage (getClass ()); query = prefs.get (GOOGLEQUERY, DEFAULTGOOGLEQUERY); try { query = (String)JOptionPane.showInputDialog ( this, "Enter the search term:", "Search Google", JOptionPane.PLAIN_MESSAGE, null, null, query); if (null != query) { // replace spaces with + terms = query.replace (' ', '+'); buffer = new StringBuffer (1024); buffer.append ("http://www.google.ca/search?"); buffer.append ("q="); buffer.append (terms); buffer.append ("&ie=UTF-8"); buffer.append ("&oe=UTF-8"); buffer.append ("&hl=en"); buffer.append ("&btnG=Google+Search"); buffer.append ("&meta="); url = new URL (buffer.toString ()); connection = (HttpURLConnection)url.openConnection (); if (USE_MOZILLA_HEADERS) { // These are the Mozilla header fields: //Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,video/x-mng,image/png,image/jpeg,image/gif;q=0.2,text/css,*/*;q=0.1 //Accept-Language: en-us, en;q=0.50 //Connection: keep-alive //Host: grc.com //Referer: https://grc.com/x/ne.dll?bh0bkyd2 //User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20030225 //Content-Length: 27 //Content-Type: application/x-www-form-urlencoded //Accept-Encoding: gzip, deflate, compress;q=0.9 //Accept-Charset: ISO-8859-1, utf-8;q=0.66, *;q=0.66 //Keep-Alive: 300 connection.setRequestProperty ("Referer", "http://www.google.ca"); connection.setRequestProperty ("Accept", "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,video/x-mng,image/png,image/jpeg,image/gif;q=0.2,text/css,*/*;q=0.1"); connection.setRequestProperty ("Accept-Language", "en-us, en;q=0.50"); connection.setRequestProperty ("User-Agent", "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20030225"); connection.setRequestProperty ("Accept-Charset", "ISO-8859-1, utf-8;q=0.66, *;q=0.66"); } else { // These are the IE header fields: //Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */* //Accept-Language: en-ca //Connection: Keep-Alive //Host: grc.com //User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; trieste; .NET CLR 1.1.4322; .NET CLR 1.0.3705) //Content-Length: 32 //Content-Type: application/x-www-form-urlencoded //Accept-Encoding: gzip, deflate //Cache-Control: no-cache connection.setRequestProperty ("Accept", "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*"); connection.setRequestProperty ("Accept-Language", "en-ca"); connection.setRequestProperty ("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; trieste; .NET CLR 1.1.4322; .NET CLR 1.0.3705)"); } connection.setDoOutput (true); connection.setDoInput (true); connection.setUseCaches (false); lexer = new Lexer (connection); results = getThumbelina ().extractImageLinks (lexer, url); // add 'em getThumbelina ().reset (); // remove google links, not just append (results[1]); for (int i = 0; i < results[1].length; i++) { String found = results[1][i].toExternalForm (); if (-1 == found.indexOf ("google")) getThumbelina ().append (results[1][i]); } prefs.put (GOOGLEQUERY, query); try { prefs.flush (); } catch (BackingStoreException bse) { bse.printStackTrace (); } } } catch (Exception e) { System.out.println (e.getMessage ()); } } /** * Display information about Thumbelina. */ public void about () { URL url; try { url = new URL ("http://sourceforge.net/sflogo.php?group_id=24399"); } catch (MalformedURLException murle) { url = null; } JOptionPane.showMessageDialog ( this, "Scan and display the images behind thumbnails.\n" + "\n" + "An example application using the HTML Parser project.\n" + "Visit http://htmlparser.sourceforge.org for the latest\n" + "version and source code.\n", "Thumbelina - About", JOptionPane.PLAIN_MESSAGE, new ImageIcon (url)); } /** * Exits the application. * Saves user preferences before exiting. */ public void exit () { saveState (); System.exit (0); } /** * Alternate mainline for Thumbelina. * Similar code exists in the Thumbelina class, but this version doesn't * worry about java version. * @param args The command line arguments. * Optionally, arg[0] can be the URL to preload the Thumeblina bean with. */ public static void main (final String[] args) { String url; ThumbelinaFrame thumbelina; System.setProperty ("sun.net.client.defaultReadTimeout", "7000"); System.setProperty ("sun.net.client.defaultConnectTimeout", "7000"); url = null; if (0 != args.length) if (args[0].equalsIgnoreCase ("help") || args[0].equalsIgnoreCase ("-help") || args[0].equalsIgnoreCase ("-h") || args[0].equalsIgnoreCase ("?") || args[0].equalsIgnoreCase ("-?")) Thumbelina.help (); else url = args[0]; try { thumbelina = new ThumbelinaFrame (url); thumbelina.setVisible (true); } catch (MalformedURLException murle) { System.err.println (murle.getMessage ()); Thumbelina.help (); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -