* Fix BUG #12317 Eventhandler and keyboard events 52/10652/2
Bruno JOFRET [Fri, 1 Mar 2013 10:08:45 +0000 (11:08 +0100)]
* Avoid NPE when closing a figure using shortcut CTRL+W and the eventhandler tried to update the infobar.

Change-Id: I20a0452df49d6ea29445c5ae4254eb32c7df7d8e

scilab/CHANGES_5.4.X
scilab/modules/gui/src/java/org/scilab/modules/gui/bridge/canvas/SwingScilabCanvas.java
scilab/modules/gui/src/java/org/scilab/modules/gui/bridge/tab/SwingScilabTab.java

index e695d77..ce43834 100644 (file)
@@ -425,6 +425,8 @@ Bug fixes
 
 * Bug #12307 fixed - ftp addresses were not handled in help browser.
 
+* Bug #12317 fixed - eventhandler functions no more report keyboard events
+
 
                     Changes between version 5.3.3 and 5.4.0
                     =======================================
index f4c5861..59a4210 100644 (file)
@@ -102,6 +102,7 @@ public class SwingScilabCanvas extends JPanel implements SimpleCanvas {
 
         setBackground(Color.white);
         setFocusable(true);
+        setEnabled(true);
     }
 
     public void addNotify() {
@@ -325,7 +326,7 @@ public class SwingScilabCanvas extends JPanel implements SimpleCanvas {
      * @param listener listener to add.
      */
     public void addEventHandlerKeyListener(KeyListener listener) {
-        drawableComponent.addKeyListener(listener);
+        addKeyListener(listener);
     }
 
     /**
@@ -333,7 +334,7 @@ public class SwingScilabCanvas extends JPanel implements SimpleCanvas {
      * @param listener listener to remove.
      */
     public void removeEventHandlerKeyListener(KeyListener listener) {
-        drawableComponent.removeKeyListener(listener);
+        removeKeyListener(listener);
     }
 
     /**
index e0c586c..0b0f978 100644 (file)
@@ -285,77 +285,77 @@ public class SwingScilabTab extends View implements SwingViewObject, SimpleTab,
 
         /* Manage figure_position property */
         addHierarchyBoundsListener(new HierarchyBoundsListener() {
-                public void ancestorResized(HierarchyEvent arg0) {
-                }
+            public void ancestorResized(HierarchyEvent arg0) {
+            }
 
-                public void ancestorMoved(HierarchyEvent e) {
-                    if (e.getChanged() instanceof SwingScilabWindow) {
-                        Position parentPosition =  SwingScilabWindow.allScilabWindows.get(parentWindowId).getPosition();
-                        Integer[] newPosition = new Integer[] {parentPosition.getX(), parentPosition.getY()};
-                        GraphicController.getController().setProperty(id, __GO_POSITION__, newPosition);
-                    }
+            public void ancestorMoved(HierarchyEvent e) {
+                if (e.getChanged() instanceof SwingScilabWindow) {
+                    Position parentPosition =  SwingScilabWindow.allScilabWindows.get(parentWindowId).getPosition();
+                    Integer[] newPosition = new Integer[] {parentPosition.getX(), parentPosition.getY()};
+                    GraphicController.getController().setProperty(id, __GO_POSITION__, newPosition);
                 }
-            });
+            }
+        });
 
         /* Manage figure_size property */
         addComponentListener(new ComponentListener() {
 
-                public void componentShown(ComponentEvent arg0) {
-                }
+            public void componentShown(ComponentEvent arg0) {
+            }
 
-                public void componentResized(ComponentEvent arg0) {
+            public void componentResized(ComponentEvent arg0) {
 
-                    /* Update the figure_size property */
-                    Size parentSize =  SwingScilabWindow.allScilabWindows.get(parentWindowId).getDims();
-                    Integer[] newSize = new Integer[] {parentSize.getWidth(), parentSize.getHeight()};
-                    GraphicController.getController().setProperty(id, __GO_SIZE__, newSize);
+                /* Update the figure_size property */
+                Size parentSize =  SwingScilabWindow.allScilabWindows.get(parentWindowId).getDims();
+                Integer[] newSize = new Integer[] {parentSize.getWidth(), parentSize.getHeight()};
+                GraphicController.getController().setProperty(id, __GO_SIZE__, newSize);
 
-                    Boolean autoreSize = (Boolean) GraphicController.getController().getProperty(id, __GO_AUTORESIZE__);
+                Boolean autoreSize = (Boolean) GraphicController.getController().getProperty(id, __GO_AUTORESIZE__);
 
-                    if (autoreSize != null && autoreSize) {
-                        /* Update the axes_size property */
-                        Integer[] newAxesSize = new Integer[] {getContentPane().getWidth(), getContentPane().getHeight()};
-                        GraphicController.getController().setProperty(id, __GO_AXES_SIZE__, newAxesSize);
-                    }
+                if (autoreSize != null && autoreSize) {
+                    /* Update the axes_size property */
+                    Integer[] newAxesSize = new Integer[] {getContentPane().getWidth(), getContentPane().getHeight()};
+                    GraphicController.getController().setProperty(id, __GO_AXES_SIZE__, newAxesSize);
                 }
+            }
 
-                public void componentMoved(ComponentEvent arg0) {
-                }
+            public void componentMoved(ComponentEvent arg0) {
+            }
 
-                public void componentHidden(ComponentEvent arg0) {
-                }
-            });
+            public void componentHidden(ComponentEvent arg0) {
+            }
+        });
 
         /* Manage closerequestfcn */
         ClosingOperationsManager.registerClosingOperation(SwingScilabTab.this, new ClosingOperationsManager.ClosingOperation() {
 
-                public int canClose() {
-                    String closeRequestFcn = (String) GraphicController.getController().getProperty(getId(), __GO_CLOSEREQUESTFCN__);
-                    if (!closeRequestFcn.equals("")) {
-                        String closeCommand = "if exists(\"gcbo\") then %oldgcbo = gcbo; end;"
-                            + "gcbo = getcallbackobject(\"" + getId() + "\");"
-                            + closeRequestFcn + ";fire_closing_finished();"
-                            + ";if exists(\"%oldgcbo\") then gcbo = %oldgcbo; else clear gcbo; end;";
-                        InterpreterManagement.requestScilabExec(closeCommand);
-                        return -1;
-                    } else {
-                        closeAction.actionPerformed(null);
-                        return 1;
-                    }
+            public int canClose() {
+                String closeRequestFcn = (String) GraphicController.getController().getProperty(getId(), __GO_CLOSEREQUESTFCN__);
+                if (!closeRequestFcn.equals("")) {
+                    String closeCommand = "if exists(\"gcbo\") then %oldgcbo = gcbo; end;"
+                                          + "gcbo = getcallbackobject(\"" + getId() + "\");"
+                                          + closeRequestFcn + ";fire_closing_finished();"
+                                          + ";if exists(\"%oldgcbo\") then gcbo = %oldgcbo; else clear gcbo; end;";
+                    InterpreterManagement.requestScilabExec(closeCommand);
+                    return -1;
+                } else {
+                    closeAction.actionPerformed(null);
+                    return 1;
                 }
+            }
 
-                public void destroy() {
-                }
+            public void destroy() {
+            }
 
-                public String askForClosing(final List<SwingScilabTab> list) {
-                    return null;
-                }
+            public String askForClosing(final List<SwingScilabTab> list) {
+                return null;
+            }
 
-                @Override
-                public void updateDependencies(List<SwingScilabTab> list, ListIterator<SwingScilabTab> it) {
+            @Override
+            public void updateDependencies(List<SwingScilabTab> list, ListIterator<SwingScilabTab> it) {
 
-                }
-            });
+            }
+        });
         ClosingOperationsManager.addDependencyWithRoot(this);
     }
 
@@ -438,14 +438,14 @@ public class SwingScilabTab extends View implements SwingViewObject, SimpleTab,
         } else {
             // Should not occur
             SwingUtilities.invokeLater(new Runnable() {
-                    public void run() {
-                        if (getParentWindow() != null) {
-                            setParentWindowId(getParentWindow().getId());
-                        } else {
-                            System.err.println("No window for tab:" + SwingScilabTab.this.getClass().getName() + " after docking complete");
-                        }
+                public void run() {
+                    if (getParentWindow() != null) {
+                        setParentWindowId(getParentWindow().getId());
+                    } else {
+                        System.err.println("No window for tab:" + SwingScilabTab.this.getClass().getName() + " after docking complete");
                     }
-                });
+                }
+            });
         }
     }
 
@@ -505,12 +505,12 @@ public class SwingScilabTab extends View implements SwingViewObject, SimpleTab,
         } else {
             try {
                 SwingUtilities.invokeAndWait(new Runnable() {
-                        @Override
-                        public void run() {
-                            setVisible(true);
-                            paintImmediately();
-                        }
-                    });
+                    @Override
+                    public void run() {
+                        setVisible(true);
+                        paintImmediately();
+                    }
+                });
             } catch (InterruptedException e) {
                 e.printStackTrace();
             } catch (InvocationTargetException e) {
@@ -1448,7 +1448,7 @@ public class SwingScilabTab extends View implements SwingViewObject, SimpleTab,
             if (
                 ((oldAxesSize.getWidth() != axesSize[0]) || (oldAxesSize.getHeight() != axesSize[1]))
                 && ((Boolean) GraphicController.getController().getProperty(getId(), __GO_AUTORESIZE__))
-                ) {
+            ) {
                 // TODO manage tabs when there are docked (do not change the window size if more than one tab docked)
                 int deltaX = axesSize[0] - (int) oldAxesSize.getWidth();
                 int deltaY = axesSize[1] - (int) oldAxesSize.getHeight();
@@ -1457,7 +1457,9 @@ public class SwingScilabTab extends View implements SwingViewObject, SimpleTab,
                     new Size(parentWindowSize.getWidth() + deltaX, parentWindowSize.getHeight() + deltaY));
             }
         } else if (property == __GO_INFO_MESSAGE__) {
-            getInfoBar().setText((String) value);
+            if (getInfoBar() != null) {
+                getInfoBar().setText((String) value);
+            }
         } else if (property == __GO_EVENTHANDLER_ENABLE__) {
             Boolean enabled = (Boolean) GraphicController.getController().getProperty(getId(), __GO_EVENTHANDLER_ENABLE__);
             setEventHandlerEnabled(enabled);
@@ -1476,9 +1478,9 @@ public class SwingScilabTab extends View implements SwingViewObject, SimpleTab,
         for (int kChild = 0; kChild < children.length; kChild++) {
             int childType = (Integer) GraphicController.getController().getProperty(children[kChild], __GO_TYPE__);
             if (childType == __GO_UIMENU__
-                || childType == __GO_UIPARENTMENU__
-                || childType == __GO_UICHILDMENU__
-                || childType == __GO_UICHECKEDMENU__) {
+                    || childType == __GO_UIPARENTMENU__
+                    || childType == __GO_UICHILDMENU__
+                    || childType == __GO_UICHECKEDMENU__) {
                 String cb = (String) GraphicController.getController().getProperty(children[kChild], __GO_CALLBACK__);
                 SwingView.getFromId(children[kChild]).update(__GO_CALLBACK__, replaceFigureID(cb, parentFigureId));
                 String[] menuChildren = (String[]) GraphicController.getController().getProperty(children[kChild], __GO_CHILDREN__);