Bug 8135 fixed: An exception was thrown when restoring files on MacOS X 54/2154/1
Calixte DENIZET [Thu, 30 Sep 2010 12:42:27 +0000 (14:42 +0200)]
Change-Id: I5c1a26f81388f1cf3295582483970af4ee96f39b

scilab/CHANGES_5.3.X
scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/actions/CopySelectionInNewTabAction.java
scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/actions/EvaluateSelectionAction.java
scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/actions/GenerateHelpFromFunctionAction.java
scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/actions/HelpOnKeywordAction.java
scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/actions/OpenURLAction.java
scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/actions/OverwriteAction.java
scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/actions/SelectBlockAction.java
scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/actions/SplitAction.java
scilab/modules/scinotes/tests/nonreg_tests/bug_8135.tst [new file with mode: 0644]

index 676b62d..912e824 100644 (file)
@@ -25,6 +25,8 @@ SciNotes:
 
 * bug 8095 fixed - The Set Colors window was too height with OpenJDK.
 
+* bug 8135 fixed - An exception was thrown when restoring files on MacOS X.
+
 
 Bug Fixes:
 ==========
index 39e00d1..5154925 100644 (file)
@@ -59,8 +59,10 @@ public final class CopySelectionInNewTabAction extends DefaultAction {
         final MenuItem menuitem = createMenu(label, null, new CopySelectionInNewTabAction(label, editor), key);
         ((JMenuItem) menuitem.getAsSimpleMenuItem()).addPropertyChangeListener(new PropertyChangeListener() {
                 public void propertyChange(PropertyChangeEvent e) {
-                    String selection = editor.getTextPane().getSelectedText();
-                    menuitem.setEnabled(selection != null);
+                    if (editor.getTextPane() != null) {
+                        String selection = editor.getTextPane().getSelectedText();
+                        menuitem.setEnabled(selection != null);
+                    }
                 }
             });
 
index 4c46fa4..33660f0 100644 (file)
@@ -73,11 +73,13 @@ public final class EvaluateSelectionAction extends DefaultAction {
         }
         ((JMenuItem) menuitem.getAsSimpleMenuItem()).addPropertyChangeListener(new PropertyChangeListener() {
                 public void propertyChange(PropertyChangeEvent e) {
-                    String select = editor.getTextPane().getSelectedText();
-                    if (select == null) {
-                        menuitem.setText(label2);
-                    } else {
-                        menuitem.setText(label1);
+                    if (editor.getTextPane() != null) {
+                        String select = editor.getTextPane().getSelectedText();
+                        if (select == null) {
+                            menuitem.setText(label2);
+                        } else {
+                            menuitem.setText(label1);
+                        }
                     }
                 }
             });
index 7c95648..e0a00df 100644 (file)
@@ -122,10 +122,12 @@ public class GenerateHelpFromFunctionAction extends DefaultAction {
         final MenuItem menuitem = createMenu(label, null, new GenerateHelpFromFunctionAction(label, editor), key);
         ((JMenuItem) menuitem.getAsSimpleMenuItem()).addPropertyChangeListener(new PropertyChangeListener() {
                 public void propertyChange(PropertyChangeEvent e) {
-                    Element root = editor.getTextPane().getDocument().getDefaultRootElement();
-                    int pos = editor.getTextPane().getCaretPosition();
-                    ScilabDocument.ScilabLeafElement elem = (ScilabDocument.ScilabLeafElement) root.getElement(root.getElementIndex(pos));
-                    menuitem.setEnabled(elem.isFunction());
+                    if (editor.getTextPane() != null) {
+                        Element root = editor.getTextPane().getDocument().getDefaultRootElement();
+                        int pos = editor.getTextPane().getCaretPosition();
+                        ScilabDocument.ScilabLeafElement elem = (ScilabDocument.ScilabLeafElement) root.getElement(root.getElementIndex(pos));
+                        menuitem.setEnabled(elem.isFunction());
+                    }
                 }
             });
 
index 4382446..4133c56 100644 (file)
@@ -92,22 +92,24 @@ public class HelpOnKeywordAction extends DefaultAction {
         final MenuItem menuitem = createMenu(label1, null, hoka, key);
         ((JMenuItem) menuitem.getAsSimpleMenuItem()).addPropertyChangeListener(new PropertyChangeListener() {
                 public void propertyChange(PropertyChangeEvent e) {
-                    String select = editor.getTextPane().getSelectedText();
-                    if (select == null) {
-                        KeywordEvent kwe = ((ScilabEditorPane) editor.getTextPane()).getKeywordEvent(!hoka.isPopup, true);
-                        if (ScilabLexerConstants.isHelpable(kwe.getType())) {
-                            try {
-                                String kw = editor.getTextPane().getDocument().getText(kwe.getStart(), kwe.getLength());
-                                menuitem.setText(label1 + SciNotesMessages.QUOTE + kw + SciNotesMessages.QUOTE);
-                                menuitem.setEnabled(true);
-                            } catch (BadLocationException ex) { }
+                    if (editor.getTextPane() != null) {
+                        String select = editor.getTextPane().getSelectedText();
+                        if (select == null) {
+                            KeywordEvent kwe = ((ScilabEditorPane) editor.getTextPane()).getKeywordEvent(!hoka.isPopup, true);
+                            if (ScilabLexerConstants.isHelpable(kwe.getType())) {
+                                try {
+                                    String kw = editor.getTextPane().getDocument().getText(kwe.getStart(), kwe.getLength());
+                                    menuitem.setText(label1 + SciNotesMessages.QUOTE + kw + SciNotesMessages.QUOTE);
+                                    menuitem.setEnabled(true);
+                                } catch (BadLocationException ex) { }
+                            } else {
+                                menuitem.setText(label1 + SciNotesMessages.DOTS);
+                                menuitem.setEnabled(false);
+                            }
                         } else {
-                            menuitem.setText(label1 + SciNotesMessages.DOTS);
-                            menuitem.setEnabled(false);
+                            menuitem.setText(label2);
+                            menuitem.setEnabled(true);
                         }
-                    } else {
-                        menuitem.setText(label2);
-                        menuitem.setEnabled(true);
                     }
                 }
             });
index 9dc33f5..076a946 100644 (file)
@@ -66,11 +66,13 @@ public class OpenURLAction extends DefaultAction {
     public static MenuItem createMenu(String label, final SciNotes editor, KeyStroke key) {
         final MenuItem menuitem = createMenu(label, null, new OpenURLAction(label, editor), key);
         ((JMenuItem) menuitem.getAsSimpleMenuItem()).addPropertyChangeListener(new PropertyChangeListener() {
-                public void propertyChange(PropertyChangeEvent arg0) {
-                    String keyword = editor.getTextPane().getSelectedText();
-                    if (keyword == null) {
-                        KeywordEvent kwe = editor.getTextPane().getKeywordEvent();
-                        menuitem.setEnabled(ScilabLexerConstants.MAIL == kwe.getType() || ScilabLexerConstants.URL == kwe.getType());
+                public void propertyChange(PropertyChangeEvent e) {
+                    if (editor.getTextPane() != null) {
+                        String keyword = editor.getTextPane().getSelectedText();
+                        if (keyword == null) {
+                            KeywordEvent kwe = editor.getTextPane().getKeywordEvent();
+                            menuitem.setEnabled(ScilabLexerConstants.MAIL == kwe.getType() || ScilabLexerConstants.URL == kwe.getType());
+                        }
                     }
                 }
             });
index bfd5c09..30f3150 100644 (file)
@@ -47,7 +47,9 @@ public final class OverwriteAction extends DefaultAction {
         final MenuItem menuitem = createMenu(label, null, new OverwriteAction(label, editor), key);
         ((JMenuItem) menuitem.getAsSimpleMenuItem()).addPropertyChangeListener(new PropertyChangeListener() {
                 public void propertyChange(PropertyChangeEvent e) {
-                    menuitem.setEnabled(editor.getTextPane().checkExternalModif());
+                    if (editor.getTextPane() != null) {
+                        menuitem.setEnabled(editor.getTextPane().checkExternalModif());
+                    }
                 }
             });
 
index dcb3616..5c457f6 100644 (file)
@@ -99,10 +99,12 @@ public class SelectBlockAction extends DefaultAction {
         final MenuItem menuitem = createMenu(label, null, sba, key);
         ((JMenuItem) menuitem.getAsSimpleMenuItem()).addPropertyChangeListener(new PropertyChangeListener() {
                 public void propertyChange(PropertyChangeEvent e) {
-                    ScilabEditorPane sep = editor.getTextPane();
-                    boolean block = ScilabLexerConstants.isMatchable(sep.getKeywordEvent(!sba.isPopup, false).getType());
-                    block = block || ScilabLexerConstants.isMatchable(sep.getKeywordEvent(!sba.isPopup, true).getType());
-                    menuitem.setEnabled(block);
+                    if (editor.getTextPane() != null) {
+                        ScilabEditorPane sep = editor.getTextPane();
+                        boolean block = ScilabLexerConstants.isMatchable(sep.getKeywordEvent(!sba.isPopup, false).getType());
+                        block = block || ScilabLexerConstants.isMatchable(sep.getKeywordEvent(!sba.isPopup, true).getType());
+                        menuitem.setEnabled(block);
+                    }
                 }
             });
 
index 37f02fa..6bd2664 100644 (file)
@@ -100,17 +100,19 @@ public final class SplitAction extends DefaultAction {
 
         ((JMenu) menu.getAsSimpleMenu()).addPropertyChangeListener(new PropertyChangeListener() {
                 public void propertyChange(PropertyChangeEvent e) {
-                    JComponent c = editor.getTextPane().getParentComponent();
-                    int state = 0;
-                    if (c instanceof JSplitPane) {
-                        JSplitPane split = (JSplitPane) c;
-                        if (split.getOrientation() == JSplitPane.HORIZONTAL_SPLIT) {
-                            state = 1;
-                        } else {
-                            state = 2;
+                    if (editor.getTextPane() != null) {
+                        JComponent c = editor.getTextPane().getParentComponent();
+                        int state = 0;
+                        if (c instanceof JSplitPane) {
+                            JSplitPane split = (JSplitPane) c;
+                            if (split.getOrientation() == JSplitPane.HORIZONTAL_SPLIT) {
+                                state = 1;
+                            } else {
+                                state = 2;
+                            }
                         }
+                        arr[state].setSelected(true);
                     }
-                    arr[state].setSelected(true);
                 }
             });
 
diff --git a/scilab/modules/scinotes/tests/nonreg_tests/bug_8135.tst b/scilab/modules/scinotes/tests/nonreg_tests/bug_8135.tst
new file mode 100644 (file)
index 0000000..5b9991a
--- /dev/null
@@ -0,0 +1,23 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2010 - Calixte DENIZET
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+
+// <-- INTERACTIVE TEST -->
+// <-- TEST WITH SCINOTES -->
+//
+// <-- Non-regression test for bug 8135 -->
+//
+// <-- Bugzilla URL -->
+// http://bugzilla.scilab.org/8135
+//
+// <-- Short Description -->
+// An exception was thrown when restoring files on MacOS X.
+
+edit test_run;
+closeEditor;
+edit test_run;
+
+// Check in the terminal if an exception is thrown.