Changeset 543


Ignore:
Timestamp:
11/27/13 14:33:22 (10 years ago)
Author:
jts21
Message:

Add correction for missing URL protocol, and detection of search URLs to JfxBrowser

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/items/widgets/JfxBrowser.java

    r541 r543  
    112112                        State = classLoader.loadClass("javafx.concurrent.Worker$State");
    113113                        StateConstants = Arrays.asList(State.getEnumConstants());
    114                         System.out.println(StateConstants);
    115114
    116115                } catch (Exception e) {
     
    149148                                        }
    150149                                });
    151                         } catch (IllegalAccessException e) {
    152                                 e.printStackTrace();
    153                         } catch (IllegalArgumentException e) {
    154                                 e.printStackTrace();
    155                         } catch (InvocationTargetException e) {
    156                                 e.printStackTrace();
    157                         } catch (InstantiationException e) {
     150                        } catch (Exception e) {
    158151                                e.printStackTrace();
    159152                        }
     
    233226
    234227                                WebEngineLoad.invoke(WebViewGetEngine.invoke(this.webview), url);
    235                         } catch (IllegalAccessException e) {
    236                                 e.printStackTrace();
    237                         } catch (IllegalArgumentException e) {
    238                                 e.printStackTrace();
    239                         } catch (InvocationTargetException e) {
    240                                 e.printStackTrace();
    241                         } catch (InstantiationException e) {
    242                                 e.printStackTrace();
    243                         } catch (SecurityException e) {
     228                        } catch (Exception e) {
    244229                                e.printStackTrace();
    245230                        }
     
    261246                                try {
    262247                                        WebViewSetPrefSize.invoke(this.webview, this.getWidth(), this.getHeight());
    263                                 } catch (IllegalAccessException e1) {
    264                                         e1.printStackTrace();
    265                                 } catch (IllegalArgumentException e1) {
    266                                         e1.printStackTrace();
    267                                 } catch (InvocationTargetException e1) {
    268                                         e1.printStackTrace();
    269                                 } catch (SecurityException e1) {
     248                                } catch (Exception e1) {
    270249                                        e1.printStackTrace();
    271250                                }
     
    308287                Text carried = null;
    309288                if ((carried = FreeItems.getTextAttachedToCursor()) != null) {
    310                         this.navigate(carried.getText());
     289                        String text = carried.getText().trim();
     290                        String textLower = text.toLowerCase();
     291                        // check if protocol is missing
     292                        // TODO: can/should we support other protocols such as ftp ???
     293                        if(!(textLower.startsWith("http://") || text.startsWith("https://"))) {
     294                                // check if it's a search (will be a search if there is a ' ' before the first '.')
     295                                // TODO: maybe support changing the default search engine (using a settings frame like the proxy settings frame)
     296                                int firstSpace = text.indexOf(" ");
     297                                int firstDot = text.indexOf(".");
     298                                if(firstSpace != -1 && firstSpace < firstDot) {
     299                                        // make it a search
     300                                        text = "https://duckduckgo.com/?q=" + text;
     301                                } else {
     302                                        // add the missing protocol
     303                                        text = "http://" + text;
     304                                }
     305                        }
     306                        this.navigate(text);
     307                        FreeItems.getInstance().clear();
    311308                        return true;
    312309                }
     
    320317                        try {
    321318                                r = new String[] { (String) WebEngineGetLocation.invoke(WebViewGetEngine.invoke(this._browser.webview)) };
    322                         } catch (IllegalAccessException e) {
     319                        } catch (Exception e) {
    323320                                e.printStackTrace();
    324                         } catch (IllegalArgumentException e) {
    325                                 e.printStackTrace();
    326                         } catch (InvocationTargetException e) {
    327                                 e.printStackTrace();
    328                         } catch (SecurityException e) {
    329                                 e.printStackTrace();
    330321                        }
    331322                }
Note: See TracChangeset for help on using the changeset viewer.