Bug 12307 fixed: ftp adresses were not handled in help viewer 07/10507/2
Calixte DENIZET [Mon, 18 Feb 2013 09:16:51 +0000 (10:16 +0100)]
Change-Id: Ia864b622f15197df3796f9bb83bb46e17f32d15f

scilab/CHANGES_5.4.X
scilab/modules/gui/src/java/org/scilab/modules/gui/bridge/helpbrowser/SwingScilabHelpBrowserViewer.java
scilab/modules/gui/src/java/org/scilab/modules/gui/utils/WebBrowser.java

index b84811d..1fcdfa2 100644 (file)
@@ -368,6 +368,8 @@ Bug fixes
 
 * Bug #12304 fixed - Undock, redock and undock led to an exception.
 
+* Bug #12307 fixed - ftp addresses were not handled in help browser.
+
 
                     Changes between version 5.3.3 and 5.4.0
                     =======================================
index 9e4b592..09c77e9 100644 (file)
@@ -124,7 +124,7 @@ public class SwingScilabHelpBrowserViewer extends BasicContentViewerUI implement
      */
     public void hyperlinkUpdate(HyperlinkEvent event) {
         if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
-            if (event.getDescription().startsWith("http://") || event.getDescription().startsWith("https://")) {
+            if (event.getDescription().startsWith("http://") || event.getDescription().startsWith("https://") || event.getDescription().startsWith("ftp://")) {
                 WebBrowser.openUrl(event.getURL(), event.getDescription());
             } else if (event.getDescription().startsWith(SCILAB_PROTO)) {
                 if (helpSets == null) {
@@ -430,34 +430,34 @@ public class SwingScilabHelpBrowserViewer extends BasicContentViewerUI implement
         try {
             this.accessibleHtml = (javax.swing.JEditorPane) privateField.get(this);
             accessibleHtml.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
-                public void propertyChange(java.beans.PropertyChangeEvent evt) {
-                    // Crappy workaround to avoid bad html display (the icons play and edit can be misplaced)
-                    // To improve... (it doesn't always work)
-                    if (evt.getPropertyName().equals("document")) {
-                        accessibleHtml.setVisible(false);
-                        accessibleHtml.validate();
-                    }
-                    if (evt.getPropertyName().equals("page")) {
-                        if (!accessibleHtml.isVisible()) {
-                            modifyFont(0);
-                            SwingUtilities.invokeLater(new Runnable() {
-                                public void run() {
-                                    accessibleHtml.setVisible(true);
-                                }
-                            });
+                    public void propertyChange(java.beans.PropertyChangeEvent evt) {
+                        // Crappy workaround to avoid bad html display (the icons play and edit can be misplaced)
+                        // To improve... (it doesn't always work)
+                        if (evt.getPropertyName().equals("document")) {
+                            accessibleHtml.setVisible(false);
+                            accessibleHtml.validate();
+                        }
+                        if (evt.getPropertyName().equals("page")) {
+                            if (!accessibleHtml.isVisible()) {
+                                modifyFont(0);
+                                SwingUtilities.invokeLater(new Runnable() {
+                                        public void run() {
+                                            accessibleHtml.setVisible(true);
+                                        }
+                                    });
+                            }
                         }
                     }
-                }
-            });
+                });
 
             // The previous workaround hides the component accessibleHtml
             // and consequently the focus is given to an other component.
             // So we force the accessibleHtml to keep the focus.
             accessibleHtml.setFocusTraversalPolicy(new DefaultFocusTraversalPolicy() {
-                public Component getFirstComponent(Container aContainer) {
-                    return x;
-                }
-            });
+                    public Component getFirstComponent(Container aContainer) {
+                        return x;
+                    }
+                });
             accessibleHtml.setFocusCycleRoot(true);
 
             String keyModifier = "alt ";
@@ -468,28 +468,28 @@ public class SwingScilabHelpBrowserViewer extends BasicContentViewerUI implement
             InputMap inputmap = accessibleHtml.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
             inputmap.put(ScilabKeyStroke.getKeyStroke("OSSCKEY shift EQUALS"), SHIFTEQ);
             accessibleHtml.getActionMap().put(SHIFTEQ, new AbstractAction() {
-                public void actionPerformed(ActionEvent e) {
-                    SwingScilabHelpBrowserViewer.this.increaseFont();
-                }
-            });
+                    public void actionPerformed(ActionEvent e) {
+                        SwingScilabHelpBrowserViewer.this.increaseFont();
+                    }
+                });
             inputmap.put(ScilabKeyStroke.getKeyStroke(keyModifier + "LEFT"), "Previous-page");
             accessibleHtml.getActionMap().put("Previous-page", new AbstractAction() {
-                public void actionPerformed(ActionEvent e) {
-                    DefaultHelpHistoryModel history = SwingScilabHelpBrowser.getHelpHistory();
-                    if (history.getIndex() > 0) {
-                        history.goBack();
+                    public void actionPerformed(ActionEvent e) {
+                        DefaultHelpHistoryModel history = SwingScilabHelpBrowser.getHelpHistory();
+                        if (history.getIndex() > 0) {
+                            history.goBack();
+                        }
                     }
-                }
-            });
+                });
             inputmap.put(ScilabKeyStroke.getKeyStroke(keyModifier + "RIGHT"), "Next-page");
             accessibleHtml.getActionMap().put("Next-page", new AbstractAction() {
-                public void actionPerformed(ActionEvent e) {
-                    DefaultHelpHistoryModel history = SwingScilabHelpBrowser.getHelpHistory();
-                    if (history.getHistory().size() != (history.getIndex() + 1)) {
-                        history.goForward();
+                    public void actionPerformed(ActionEvent e) {
+                        DefaultHelpHistoryModel history = SwingScilabHelpBrowser.getHelpHistory();
+                        if (history.getHistory().size() != (history.getIndex() + 1)) {
+                            history.goForward();
+                        }
                     }
-                }
-            });
+                });
 
             inputmap = accessibleHtml.getInputMap(JComponent.WHEN_FOCUSED);
             inputmap.put(ScilabKeyStroke.getKeyStroke(keyModifier + "LEFT"), new Object());
@@ -518,15 +518,15 @@ public class SwingScilabHelpBrowserViewer extends BasicContentViewerUI implement
 
         /* Execute into Scilab */
         ActionListener actionListenerExecuteIntoScilab = new ActionListener() {
-            public void actionPerformed(ActionEvent actionEvent) {
-                String selection = accessibleHtml.getSelectedText();
-                if (selection == null) {
-                    ScilabHelpBrowser.getHelpBrowser().getInfoBar().setText(Messages.gettext("No text selected"));
-                } else {
-                    ScilabConsole.getConsole().getAsSimpleConsole().sendCommandsToScilab(selection, true /* display */, true /* store in history */);
+                public void actionPerformed(ActionEvent actionEvent) {
+                    String selection = accessibleHtml.getSelectedText();
+                    if (selection == null) {
+                        ScilabHelpBrowser.getHelpBrowser().getInfoBar().setText(Messages.gettext("No text selected"));
+                    } else {
+                        ScilabConsole.getConsole().getAsSimpleConsole().sendCommandsToScilab(selection, true /* display */, true /* store in history */);
+                    }
                 }
-            }
-        };
+            };
         menuItem = new JMenuItem(Messages.gettext("Execute into Scilab"));
         menuItem.addActionListener(actionListenerExecuteIntoScilab);
         if (!ScilabConsole.isExistingConsole()) { /* Only available in STD mode */
@@ -537,15 +537,15 @@ public class SwingScilabHelpBrowserViewer extends BasicContentViewerUI implement
 
         /* Edit in the Scilab Text Editor */
         ActionListener actionListenerLoadIntoTextEditor = new ActionListener() {
-            public void actionPerformed(ActionEvent actionEvent) {
-                String selection = accessibleHtml.getSelectedText();
-                if (selection == null) {
-                    ScilabHelpBrowser.getHelpBrowser().getInfoBar().setText(Messages.gettext("No text selected"));
-                } else {
-                    edit(selection);
+                public void actionPerformed(ActionEvent actionEvent) {
+                    String selection = accessibleHtml.getSelectedText();
+                    if (selection == null) {
+                        ScilabHelpBrowser.getHelpBrowser().getInfoBar().setText(Messages.gettext("No text selected"));
+                    } else {
+                        edit(selection);
+                    }
                 }
-            }
-        };
+            };
 
         menuItem = new JMenuItem(Messages.gettext("Edit in the Scilab Text Editor"));
         try {
@@ -560,14 +560,14 @@ public class SwingScilabHelpBrowserViewer extends BasicContentViewerUI implement
 
         /* Back in the history*/
         ActionListener actionListenerBackHistory = new ActionListener() {
-            public void actionPerformed(ActionEvent actionEvent) {
-                DefaultHelpHistoryModel history = SwingScilabHelpBrowser.getHelpHistory();
-                /* Not at the first position */
-                if (history.getIndex() > 0) {
-                    SwingScilabHelpBrowser.getHelpHistory().goBack();
+                public void actionPerformed(ActionEvent actionEvent) {
+                    DefaultHelpHistoryModel history = SwingScilabHelpBrowser.getHelpHistory();
+                    /* Not at the first position */
+                    if (history.getIndex() > 0) {
+                        SwingScilabHelpBrowser.getHelpHistory().goBack();
+                    }
                 }
-            }
-        };
+            };
 
         menuItem = new JMenuItem(Messages.gettext("Back"));
         menuItem.addActionListener(actionListenerBackHistory);
@@ -575,14 +575,14 @@ public class SwingScilabHelpBrowserViewer extends BasicContentViewerUI implement
 
         /* Forward in the history*/
         ActionListener actionListenerForwardHistory = new ActionListener() {
-            public void actionPerformed(ActionEvent actionEvent) {
-                DefaultHelpHistoryModel history = SwingScilabHelpBrowser.getHelpHistory();
-                /* Not at the last position */
-                if (history.getHistory().size() != (history.getIndex() + 1)) {
-                    SwingScilabHelpBrowser.getHelpHistory().goForward();
+                public void actionPerformed(ActionEvent actionEvent) {
+                    DefaultHelpHistoryModel history = SwingScilabHelpBrowser.getHelpHistory();
+                    /* Not at the last position */
+                    if (history.getHistory().size() != (history.getIndex() + 1)) {
+                        SwingScilabHelpBrowser.getHelpHistory().goForward();
+                    }
                 }
-            }
-        };
+            };
 
         menuItem = new JMenuItem(Messages.gettext("Forward"));
         menuItem.addActionListener(actionListenerForwardHistory);
@@ -597,10 +597,10 @@ public class SwingScilabHelpBrowserViewer extends BasicContentViewerUI implement
 
         /* Select all */
         ActionListener actionListenerSelectAll = new ActionListener() {
-            public void actionPerformed(ActionEvent actionEvent) {
-                accessibleHtml.selectAll();
-            }
-        };
+                public void actionPerformed(ActionEvent actionEvent) {
+                    accessibleHtml.selectAll();
+                }
+            };
         menuItem = new JMenuItem(Messages.gettext("Select All"));
         menuItem.addActionListener(actionListenerSelectAll);
         popup.add(menuItem);
@@ -609,29 +609,29 @@ public class SwingScilabHelpBrowserViewer extends BasicContentViewerUI implement
         final JMenuItem helpMenuItem = new JMenuItem("Help on the selected text");
 
         ActionListener actionListenerHelpOnKeyword = new ActionListener() {
-            public void actionPerformed(ActionEvent actionEvent) {
-                String selection = accessibleHtml.getSelectedText();
-                if (selection == null) {
-                    ScilabHelpBrowser.getHelpBrowser().getInfoBar().setText(Messages.gettext("No text selected"));
-                } else {
-                    ScilabHelpBrowser.getHelpBrowser().searchKeywork(selection);
+                public void actionPerformed(ActionEvent actionEvent) {
+                    String selection = accessibleHtml.getSelectedText();
+                    if (selection == null) {
+                        ScilabHelpBrowser.getHelpBrowser().getInfoBar().setText(Messages.gettext("No text selected"));
+                    } else {
+                        ScilabHelpBrowser.getHelpBrowser().searchKeywork(selection);
+                    }
                 }
-            }
-        };
+            };
         PropertyChangeListener listenerTextItem = new PropertyChangeListener() {
-            public void propertyChange(PropertyChangeEvent arg0) {
-                String keyword = accessibleHtml.getSelectedText();
-                if (keyword == null) {
-                    helpMenuItem.setText(Messages.gettext("Help about a selected text"));
-                } else {
-                    int nbOfDisplayedOnlyXChar = 10;
-                    if (keyword.length() > nbOfDisplayedOnlyXChar) {
-                        keyword = keyword.substring(0, nbOfDisplayedOnlyXChar) + "...";
+                public void propertyChange(PropertyChangeEvent arg0) {
+                    String keyword = accessibleHtml.getSelectedText();
+                    if (keyword == null) {
+                        helpMenuItem.setText(Messages.gettext("Help about a selected text"));
+                    } else {
+                        int nbOfDisplayedOnlyXChar = 10;
+                        if (keyword.length() > nbOfDisplayedOnlyXChar) {
+                            keyword = keyword.substring(0, nbOfDisplayedOnlyXChar) + "...";
+                        }
+                        helpMenuItem.setText(Messages.gettext("Help about '") + keyword + "'");
                     }
-                    helpMenuItem.setText(Messages.gettext("Help about '") + keyword + "'");
                 }
-            }
-        };
+            };
         helpMenuItem.addPropertyChangeListener(listenerTextItem);
         helpMenuItem.addActionListener(actionListenerHelpOnKeyword);
         popup.add(helpMenuItem);
@@ -660,20 +660,20 @@ public class SwingScilabHelpBrowserViewer extends BasicContentViewerUI implement
      */
     public void modifyFont(final int s) {
         SwingUtilities.invokeLater(new Runnable() {
-            public void run() {
-                try {
-                    HTMLDocument doc = (HTMLDocument) accessibleHtml.getDocument();
-                    StyleContext.NamedStyle style = (StyleContext.NamedStyle) doc.getStyleSheet().getStyle("body");
-                    MutableAttributeSet attr = (MutableAttributeSet) style.getResolveParent();
-                    currentFontSize = Math.min(Math.max(0, currentFontSize + s), 6);
-                    ConfigManager.setHelpFontSize(currentFontSize);
-                    StyleConstants.setFontSize(attr, fontSizes[currentFontSize]);
-                    style.setResolveParent(attr);
-                } catch (NullPointerException e) {
-                    // Can occur if the user is changing quickly the document
+                public void run() {
+                    try {
+                        HTMLDocument doc = (HTMLDocument) accessibleHtml.getDocument();
+                        StyleContext.NamedStyle style = (StyleContext.NamedStyle) doc.getStyleSheet().getStyle("body");
+                        MutableAttributeSet attr = (MutableAttributeSet) style.getResolveParent();
+                        currentFontSize = Math.min(Math.max(0, currentFontSize + s), 6);
+                        ConfigManager.setHelpFontSize(currentFontSize);
+                        StyleConstants.setFontSize(attr, fontSizes[currentFontSize]);
+                        style.setResolveParent(attr);
+                    } catch (NullPointerException e) {
+                        // Can occur if the user is changing quickly the document
+                    }
                 }
-            }
-        });
+            });
     }
 
     /**
index d18d440..8b2a406 100644 (file)
@@ -95,7 +95,7 @@ public final class WebBrowser implements XConfigurationListener {
 
         try {
             if (url.charAt(0) == 'h' || url.charAt(0) == 'f') {
-                // We have something like http://... or file://
+                // We have something like http://... or file://... or ftp://...
                 if (webprefs.defaultBrowser) {
                     Desktop.getDesktop().browse(new URI(url));
                 } else {