Bug 12270 fixed: When the console lost the focus, the caret could be visible. 95/10495/2
Calixte DENIZET [Fri, 15 Feb 2013 14:16:47 +0000 (15:16 +0100)]
Change-Id: I57e02c892abd8c6685c94f80acea77c51cc11a9d

scilab/CHANGES_5.4.X
scilab/modules/gui/src/java/org/scilab/modules/gui/bridge/console/SwingScilabConsole.java

index 1fcdfa2..d4eac81 100644 (file)
@@ -357,6 +357,8 @@ Bug fixes
 
 * Bug #12248 fixed - SciNotes toolbar had disappeared.
 
+* Bug #12270 fixed - When the console lost the focus, the caret could be visible.
+
 * Bug #12272 fixed - Fix a presentation of Cyrillic letters on sample images of russian help page for grand function.
 
 * Bug #12284 fixed - Completion in console could to a crash (or deadlock).
index c104911..00adfb4 100644 (file)
@@ -134,45 +134,45 @@ public class SwingScilabConsole extends SciConsole implements SimpleConsole {
                                  CallBack.JAVA));
         helpMenu.setMnemonic('M');
         PropertyChangeListener listener = new PropertyChangeListener() {
-            public void propertyChange(PropertyChangeEvent arg0) {
-                String keyword = getSelectedText();
-                if (keyword == null || keyword.length() == 0) {
-                    helpMenu.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 = getSelectedText();
+                    if (keyword == null || keyword.length() == 0) {
+                        helpMenu.setText(Messages.gettext("Help about a selected text"));
+                    } else {
+                        int nbOfDisplayedOnlyXChar = 10;
+                        if (keyword.length() > nbOfDisplayedOnlyXChar) {
+                            keyword = keyword.substring(0, nbOfDisplayedOnlyXChar) + "...";
+                        }
+                        helpMenu.setText(Messages.gettext("Help about '") + keyword + "'");
                     }
-                    helpMenu.setText(Messages.gettext("Help about '") + keyword + "'");
                 }
-            }
-        };
+            };
         helpMenu.addPropertyChangeListener(listener);
 
         final SwingScilabMenuItem evalWithEchoMenu = new SwingScilabMenuItem();
         evalWithEchoMenu.setText(Messages.gettext("Evaluate selection with echo"));
         evalWithEchoMenu.setCallback(ScilabCallBack.createCallback("org.scilab.modules.gui.bridge.CallScilabBridge.evaluateSelectionWithEcho",
-                                     CallBack.JAVA));
+                                                                   CallBack.JAVA));
         evalWithEchoMenu.setMnemonic('E');
         listener = new PropertyChangeListener() {
-            public void propertyChange(PropertyChangeEvent arg0) {
-                String str = getSelectedText();
-                evalWithEchoMenu.setEnabled(str != null && !str.isEmpty());
-            }
-        };
+                public void propertyChange(PropertyChangeEvent arg0) {
+                    String str = getSelectedText();
+                    evalWithEchoMenu.setEnabled(str != null && !str.isEmpty());
+                }
+            };
         evalWithEchoMenu.addPropertyChangeListener(listener);
 
         final SwingScilabMenuItem evalWithNoEchoMenu = new SwingScilabMenuItem();
         evalWithNoEchoMenu.setText(Messages.gettext("Evaluate selection with no echo"));
         evalWithNoEchoMenu.setCallback(ScilabCallBack.createCallback("org.scilab.modules.gui.bridge.CallScilabBridge.evaluateSelectionWithNoEcho",
-                                       CallBack.JAVA));
+                                                                     CallBack.JAVA));
         evalWithNoEchoMenu.setMnemonic('N');
         listener = new PropertyChangeListener() {
-            public void propertyChange(PropertyChangeEvent arg0) {
-                String str = getSelectedText();
-                evalWithNoEchoMenu.setEnabled(str != null && !str.isEmpty());
-            }
-        };
+                public void propertyChange(PropertyChangeEvent arg0) {
+                    String str = getSelectedText();
+                    evalWithNoEchoMenu.setEnabled(str != null && !str.isEmpty());
+                }
+            };
         evalWithEchoMenu.addPropertyChangeListener(listener);
 
         menu.add(cutMenu);
@@ -202,12 +202,12 @@ public class SwingScilabConsole extends SciConsole implements SimpleConsole {
         ((JTextPane) getConfiguration().getInputCommandView()).requestFocus();
 
         addFocusListener(new FocusListener() {
-            public void focusGained(FocusEvent e) {
-                ((JTextPane) getConfiguration().getInputCommandView()).requestFocus();
-            }
+                public void focusGained(FocusEvent e) {
+                    ((JTextPane) getConfiguration().getInputCommandView()).requestFocus();
+                }
 
-            public void focusLost(FocusEvent e) { }
-        });
+                public void focusLost(FocusEvent e) { }
+            });
     }
 
     /**
@@ -224,19 +224,22 @@ public class SwingScilabConsole extends SciConsole implements SimpleConsole {
      */
     public void displayPrompt() {
         SwingUtilities.invokeLater(new Runnable() {
-            public void run() {
-                InputCommandView inputCmdView = SwingScilabConsole.this.getConfiguration().getInputCommandView();
-
-                // Show the prompt
-                SwingScilabConsole.this.getConfiguration().getPromptView().setVisible(true);
-
-                // Show the input command view and its hidden components
-                inputCmdView.setEditable(true);
-                ((JTextPane) inputCmdView).setCaretColor(((JTextPane) inputCmdView).getForeground());
-                ((JTextPane) inputCmdView).getCaret().setVisible(true);
-                setToHome();
-            }
-        });
+                public void run() {
+                    InputCommandView inputCmdView = SwingScilabConsole.this.getConfiguration().getInputCommandView();
+
+                    // Show the prompt
+                    SwingScilabConsole.this.getConfiguration().getPromptView().setVisible(true);
+
+                    // Show the input command view and its hidden components
+                    inputCmdView.setEditable(true);
+                    JTextPane tp = (JTextPane) inputCmdView;
+                    tp.setCaretColor(tp.getForeground());
+                    if (tp.isFocusOwner()) {
+                        tp.getCaret().setVisible(true);
+                    }
+                    setToHome();
+                }
+            });
 
         ((SciOutputView) this.getConfiguration().getOutputView()).resetLastEOL();
 
@@ -298,10 +301,10 @@ public class SwingScilabConsole extends SciConsole implements SimpleConsole {
 
         final JTextPane cmdView = (JTextPane) this.getConfiguration().getInputCommandView();
         SwingUtilities.invokeLater(new Runnable() {
-            public void run() {
-                cmdView.getCaret().setVisible(true);
-            }
-        });
+                public void run() {
+                    cmdView.getCaret().setVisible(true);
+                }
+            });
 
         return retChar;
     }
@@ -370,10 +373,10 @@ public class SwingScilabConsole extends SciConsole implements SimpleConsole {
         if (ccc.checked) {
             final boolean[] checked = new boolean[1];
             final Action action = new AbstractAction() {
-                public void actionPerformed(ActionEvent e) {
-                    checked[0] = ((JCheckBox) e.getSource()).isSelected();
-                }
-            };
+                    public void actionPerformed(ActionEvent e) {
+                        checked[0] = ((JCheckBox) e.getSource()).isSelected();
+                    }
+                };
 
             if (ScilabModalDialog.show(this, new String[] { CLEAR_CONFIRM }, CLEAR, IconType.WARNING_ICON, ButtonType.YES_NO, DONT_SHOW, action) == AnswerOption.NO_OPTION) {
                 if (checked[0]) {