Bug 12833 fixed: In SciNotes, there was no autoscroll when searching a pattern 90/12290/2
Calixte DENIZET [Mon, 19 Aug 2013 09:08:54 +0000 (11:08 +0200)]
Change-Id: Ic747ef075829ff6eb62d6dafd55d65c4ffea6557

scilab/CHANGES_5.5.X
scilab/modules/commons/src/java/org/scilab/modules/commons/gui/ScilabCaret.java
scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/SciNotes.java
scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/ScilabEditorPane.java

index 3ce74bf..21019f1 100644 (file)
@@ -565,6 +565,8 @@ Bug fixes
 
 * Bug #12823 fixed - In help generation (toolbox) links were not correctly handled.
 
+* Bug #12833 fixed - In SciNotes, there was no autoscroll when searching a pattern.
+
 * Bug #12836 fixed - There was an error in strcmpi documentation.
 
 * Bug #12839 fixed - Typo fixes in Core doc: getVariablesOnStack().
index 089b74b..d31f2f2 100644 (file)
@@ -62,6 +62,10 @@ public class ScilabCaret extends DefaultCaret {
         this.mustAdjustVisibility = mustAdjustVisibility;
     }
 
+    public boolean getMustAdjustVisibility() {
+        return this.mustAdjustVisibility;
+    }
+
     /**
      * @param active the color of the selection when it is active
      * @param inactive the color of the selection when it is inactive
index 1342382..edcbd4e 100644 (file)
@@ -1813,7 +1813,12 @@ public class SciNotes extends SwingScilabTab {
     public ScilabEditorPane getTextPane() {
         try {
             EditorComponent c = (EditorComponent) tabPane.getSelectedComponent();
-            return c.getEditorPane();
+            ScilabEditorPane pane = c.getEditorPane();
+            if (ScilabEditorPane.getFocusedPane() == pane.getOtherPaneInSplit()) {
+                return pane.getOtherPaneInSplit();
+            }
+
+            return pane;
         } catch (NullPointerException e) {
             return null;
         } catch (ArrayIndexOutOfBoundsException e) {
@@ -1831,7 +1836,12 @@ public class SciNotes extends SwingScilabTab {
     public ScilabEditorPane getTextPane(int index) {
         try {
             EditorComponent c = (EditorComponent) tabPane.getComponentAt(index);
-            return c.getEditorPane();
+            ScilabEditorPane pane = c.getEditorPane();
+            if (ScilabEditorPane.getFocusedPane() == pane.getOtherPaneInSplit()) {
+                return pane.getOtherPaneInSplit();
+            }
+
+            return pane;
         } catch (NullPointerException e) {
             return null;
         } catch (ArrayIndexOutOfBoundsException e) {
index 229f88d..50bb633 100644 (file)
@@ -184,12 +184,14 @@ public class ScilabEditorPane extends JEditorPane implements Highlighter.Highlig
                         nav.update((ScilabDocument) getDocument());
                     }
                 }
-                ((ScilabCaret) getCaret()).setMustAdjustVisibility(true);
+                setMustAdjustVisibility(true);
             }
 
             public void focusLost(FocusEvent e) {
                 ((ScilabDocument) getDocument()).setFocused(false);
-                ((ScilabCaret) getCaret()).setMustAdjustVisibility(false);
+                if (e.getOppositeComponent() == getOtherPaneInSplit()) {
+                    setMustAdjustVisibility(false);
+                }
             }
         });
 
@@ -248,7 +250,7 @@ public class ScilabEditorPane extends JEditorPane implements Highlighter.Highlig
                             int start = e.getStart();
                             int end = start + e.getLength();
                             String exp = ((ScilabDocument) getDocument()).getText(start, e.getLength());
-                            int height = edComponent.getScrollPane().getHeight() + edComponent.getScrollPane().getVerticalScrollBar().getValue();
+                            int height = getScrollPane().getHeight() + getScrollPane().getVerticalScrollBar().getValue();
                             ScilabLaTeXViewer.displayExpression(ScilabEditorPane.this, height, exp, start, end);
                         } catch (BadLocationException ex) { }
                     } else {
@@ -788,6 +790,14 @@ public class ScilabEditorPane extends JEditorPane implements Highlighter.Highlig
         }
     }
 
+    public void setMustAdjustVisibility(boolean mustAdjustVisibility) {
+        ((ScilabCaret) getCaret()).setMustAdjustVisibility(mustAdjustVisibility);
+    }
+
+    public boolean getMustAdjustVisibility() {
+        return ((ScilabCaret) getCaret()).getMustAdjustVisibility();
+    }
+
     /**
      * Scroll the pane to have the line containing pos on the top of the pane
      * @param pos the position in the document
@@ -809,7 +819,7 @@ public class ScilabEditorPane extends JEditorPane implements Highlighter.Highlig
                     if (setCaret) {
                         setCaretPosition(pos);
                     }
-                    JScrollBar scrollbar = edComponent.getScrollPane().getVerticalScrollBar();
+                    JScrollBar scrollbar = getScrollPane().getVerticalScrollBar();
                     Rectangle rect = modelToView(pos);
                     if (centered) {
                         int value = scrollbar.getValue();
@@ -1432,11 +1442,20 @@ public class ScilabEditorPane extends JEditorPane implements Highlighter.Highlig
         return rightTextPane;
     }
 
+    public ScilabEditorPane getCurrent() {
+        if (focused == rightTextPane) {
+            return rightTextPane;
+        }
+
+        return this;
+    }
+
+
     /**
      * @return the scrollPane associated with this EditorPane
      */
-    public JScrollPane getScrollPane() {
-        return edComponent.getScrollPane();
+    public ScilabScrollPane getScrollPane() {
+        return (ScilabScrollPane) SwingUtilities.getAncestorOfClass(ScilabScrollPane.class, this);
     }
 
     /**
@@ -1616,7 +1635,7 @@ public class ScilabEditorPane extends JEditorPane implements Highlighter.Highlig
                     } catch (BadLocationException e) { }
                 }
 
-                ((ScilabScrollPane) edComponent.getScrollPane()).putMarks(marks);
+                getScrollPane().putMarks(marks);
 
                 if (centered && positions.size() != 0) {
                     scrollTextToPos(positions.get(0)[0], false, true);
@@ -1634,7 +1653,7 @@ public class ScilabEditorPane extends JEditorPane implements Highlighter.Highlig
             highlighter.removeHighlight(obj);
         }
         highlightedWords.clear();
-        ((ScilabScrollPane) edComponent.getScrollPane()).removeMarks();
+        getScrollPane().removeMarks();
     }
 
     /**
@@ -1664,7 +1683,7 @@ public class ScilabEditorPane extends JEditorPane implements Highlighter.Highlig
         doc.addDocumentListener(xln);
         doc.addDocumentListener(doc);
 
-        edComponent.getScrollPane().setRowHeaderView(xln);
+        getScrollPane().setRowHeaderView(xln);
         doc.setEditorPane(this);
 
         if (editor != null) {