[brailleblaster] [brailleblaster.newdesign] push by brandon....@xxxxxxxxx - Updated Code Handling Cursor Position on 2013-05-13 15:59 GMT

  • From: brailleblaster@xxxxxxxxxxxxxx
  • To: brailleblaster@xxxxxxxxxxxxx
  • Date: Mon, 13 May 2013 15:59:34 +0000

Revision: a5952b6c5c5c
Branch:   default
Author:   Brandon Roller <brandon.r.roller@xxxxxxxxx>
Date:     Mon May 13 08:46:10 2013
Log:      Updated Code Handling Cursor Position
http://code.google.com/p/brailleblaster/source/detail?r=a5952b6c5c5c&repo=newdesign

Modified:
 /src/main/org/brailleblaster/abstractClasses/AbstractView.java
 /src/main/org/brailleblaster/views/BrailleView.java
 /src/main/org/brailleblaster/views/TextView.java
 /src/main/org/brailleblaster/views/TreeView.java
 /src/main/org/brailleblaster/wordprocessor/BBEvent.java
 /src/main/org/brailleblaster/wordprocessor/DocumentManager.java

=======================================
--- /src/main/org/brailleblaster/abstractClasses/AbstractView.java Fri May 10 09:06:10 2013 +++ /src/main/org/brailleblaster/abstractClasses/AbstractView.java Mon May 13 08:46:10 2013
@@ -50,8 +50,8 @@
        public boolean hasChanged = false;
        protected int total;
        protected int spaceBeforeText, spaceAfterText;
-       public int positionFromStart;
-       public static int cursorOffset, currentLine, words;
+       public int positionFromStart, cursorOffset;
+       public static int currentLine, words;

        public AbstractView() {
        }
=======================================
--- /src/main/org/brailleblaster/views/BrailleView.java Fri May 10 11:18:36 2013 +++ /src/main/org/brailleblaster/views/BrailleView.java Mon May 13 08:46:10 2013
@@ -88,33 +88,22 @@
                                message.put("sender", "braille");
                                dm.dispatch(message);
                                setViewData(message);
+                               if(oldCursorPosition == -1 && positionFromStart 
 == 0){
+                                       
view.setCaretOffset((Integer)message.getValue("brailleStart"));
+                               }
// if(oldCursorPosition == -1 || oldCursorPosition < currentStart || oldCursorPosition > currentEnd){
                //                      
view.setCaretOffset((Integer)message.getValue("brailleStart"));
-               //                      oldCursorPosition = 
view.getCaretOffset();
+               //                  oldCursorPosition = view.getCaretOffset();
                //              }
                        }

                        @Override
                        public void focusLost(FocusEvent e) {
-                               int count = 0;
-                               positionFromStart = view.getCaretOffset() - 
currentStart;
- if(positionFromStart > 0 && currentStart + positionFromStart <= currentEnd){
-                                       String text = 
view.getTextRange(currentStart, positionFromStart);
-                                       count = text.length() - text.replaceAll("\n", 
"").length();
-                                       positionFromStart -= count;
-                                       positionFromStart -= 
checkPageRange(currentStart + positionFromStart);
-                                       cursorOffset = count;
-                               }
- else if(positionFromStart > 0 && currentStart + positionFromStart > currentEnd){
-                                       String text = 
view.getTextRange(currentStart, positionFromStart);
-                                       count = text.length() - text.replaceAll("\n", 
"").length();
-                                       cursorOffset = (currentStart + 
positionFromStart) - currentEnd;
-                                       positionFromStart = 99999;
-                               }
-                               else {
-                                       positionFromStart -= count;
-                                       cursorOffset = count;
-                               }
+                               setPositionFromStart();
+
+                               Message message = new 
Message(BBEvent.UPDATE_CURSORS);
+                               message.put("sender", "braille");
+                               dm.dispatch(message);
                        }
                });

@@ -187,7 +176,6 @@
                previousEnd = (Integer)message.getValue("previousBrailleEnd");
                this.pageRanges.clear();
setPageRange((ArrayList<BrailleMapElement>)message.getValue("pageRanges"));
-               setCursorPosition(message);
        }

        private void setPageRange(ArrayList<BrailleMapElement> list){
@@ -335,8 +323,37 @@
        public void changeIndent(int start, Message message){
view.setLineIndent(view.getLineAtOffset(start), 1, (Integer)message.getValue("indent"));
        }
+
+       public void updateCursorPosition(Message message){
+               setViewData(message);
+               setCursorPosition(message);
+               setPositionFromStart();
+       }
+
+       private void setPositionFromStart(){
+               int count = 0;
+               positionFromStart = view.getCaretOffset() - currentStart;
+ if(positionFromStart > 0 && currentStart + positionFromStart <= currentEnd){
+                       String text = view.getTextRange(currentStart, 
positionFromStart);
+                       count = text.length() - text.replaceAll("\n", 
"").length();
+                       positionFromStart -= count;
+                       positionFromStart -= checkPageRange(currentStart + 
positionFromStart);
+                       cursorOffset = count;
+               }
+ else if(positionFromStart > 0 && currentStart + positionFromStart > currentEnd){
+                       String text = view.getTextRange(currentStart, 
positionFromStart);
+                       count = text.length() - text.replaceAll("\n", 
"").length();
+                       cursorOffset = (currentStart + positionFromStart) - 
currentEnd;
+                       positionFromStart = 99999;
+               }
+               else {
+                       positionFromStart -= count;
+                       cursorOffset = count;
+               }
+       }

        private void setCursorPosition(Message message){
+               int offset = (Integer)message.getValue("offset");
                if(message.contains("element")){
                        Element e = 
getBrlNode((Node)message.getValue("element"));
                        int pos;
@@ -352,10 +369,10 @@
                                        if((Integer)message.getValue("lastPosition") < 0 
&& currentStart > 0)
                                                pos = currentStart + 
(Integer)message.getValue("lastPosition");
                                        else 
if((Integer)message.getValue("lastPosition") == 99999){
-                                               pos = currentEnd + cursorOffset;
+                                               pos = currentEnd + offset;
                                        }
                                        else {
- pos = currentStart + findCurrentPosition(arr, (Integer)message.getValue("lastPosition")) + cursorOffset; + pos = currentStart + findCurrentPosition(arr, (Integer)message.getValue("lastPosition")) + offset;
                                                pos += checkPageRange(pos);
                                        }
                                }
=======================================
--- /src/main/org/brailleblaster/views/TextView.java Fri May 10 09:06:10 2013 +++ /src/main/org/brailleblaster/views/TextView.java Mon May 13 08:46:10 2013
@@ -163,8 +163,10 @@
                            message.put("offset",view.getCaretOffset());
                                dm.dispatch(message);
                                setViewData(message);
- // if(oldCursorPosition == -1 || oldCursorPosition < currentStart || oldCursorPosition > currentEnd)
-                       //              
view.setCaretOffset((Integer)message.getValue("start"));
+                               if(oldCursorPosition == -1 && positionFromStart 
== 0){
+                                       
view.setCaretOffset((Integer)message.getValue("start"));
+                               }
+
                                Message statusMessage = new 
Message(BBEvent.UPDATE_STATUSBAR);
statusMessage.put("line", "Line: " + String.valueOf(view.getLineAtOffset(view.getCaretOffset()) + 1) + " Words: " + words);
                                dm.dispatch(statusMessage);
@@ -175,24 +177,11 @@
                        public void focusLost(FocusEvent e) {
                                if(textChanged == true)
                                        sendUpdate(dm);
-                               int count = 0;
-                               positionFromStart = view.getCaretOffset() - 
currentStart;
- if(positionFromStart > 0 && currentStart + positionFromStart <= currentEnd){
-                                       String text = 
view.getTextRange(currentStart, positionFromStart);
-                                       count = text.length() - text.replaceAll("\n", 
"").length();
-                                       positionFromStart -= count;
-                                       cursorOffset = count;
-                               }
- else if(positionFromStart > 0 && currentStart + positionFromStart > currentEnd){
-                                       String text = 
view.getTextRange(currentStart, positionFromStart);
-                                       count = text.length() - text.replaceAll("\n", 
"").length();
-                                       cursorOffset = (currentStart + 
positionFromStart) - currentEnd;
-                                       positionFromStart = 99999;
-                               }
-                               else {
-                                       positionFromStart -= count;
-                                       cursorOffset = count;
-                               }
+
+                               setPositionFromStart();
+                               Message message = new 
Message(BBEvent.UPDATE_CURSORS);
+                               message.put("sender", "text");
+                               dm.dispatch(message);
                        }
                });

@@ -337,7 +326,6 @@
                if(currentStart < view.getCharCount()){
                        range = getStyleRange();
                }
-               setCursorPosition(message);
        }

        private void makeTextChange(int offset){
@@ -743,7 +731,14 @@
                view.paste();
        }

-       public void setCursorPosition(Message message){
+       public void updateCursorPosition(Message message){
+               setViewData(message);
+               setCursorPosition(message);
+               setPositionFromStart();
+       }
+
+       private void setCursorPosition(Message message){
+               int offset = (Integer)message.getValue("offset");
                if(message.contains("element")){
                        Element e = 
getBrlNode((Node)message.getValue("element"));
                        int pos;
@@ -761,9 +756,9 @@
                                        else 
if((Integer)message.getValue("lastPosition") == arr.length)
                                                pos = currentEnd;
                                        else 
if((Integer)message.getValue("lastPosition") > arr.length)
-                                               pos = currentEnd + cursorOffset;
+                                               pos = currentEnd + offset;
                                        else
- pos = currentStart + arr[(Integer)message.getValue("lastPosition")] + cursorOffset; + pos = currentStart + arr[(Integer)message.getValue("lastPosition")] + offset;
                                }

                                view.setCaretOffset(pos);
@@ -772,6 +767,27 @@
                                view.setCaretOffset(currentStart);
                        }
                }
+       }
+
+       private void setPositionFromStart(){
+               int count = 0;
+               positionFromStart = view.getCaretOffset() - currentStart;
+ if(positionFromStart > 0 && currentStart + positionFromStart <= currentEnd){
+                       String text = view.getTextRange(currentStart, 
positionFromStart);
+                       count = text.length() - text.replaceAll("\n", 
"").length();
+                       positionFromStart -= count;
+                       cursorOffset = count;
+               }
+ else if(positionFromStart > 0 && currentStart + positionFromStart > currentEnd){
+                       String text = view.getTextRange(currentStart, 
positionFromStart);
+                       count = text.length() - text.replaceAll("\n", 
"").length();
+                       cursorOffset = (currentStart + positionFromStart) - 
currentEnd;
+                       positionFromStart = 99999;
+               }
+               else {
+                       positionFromStart -= count;
+                       cursorOffset = count;
+               }
        }

        private StyleRange getStyleRange(){
=======================================
--- /src/main/org/brailleblaster/views/TreeView.java Fri May 10 09:06:10 2013 +++ /src/main/org/brailleblaster/views/TreeView.java Mon May 13 08:46:10 2013
@@ -97,6 +97,10 @@
                                        }
                                        cursorOffset = 0;
                                        dm.dispatch(message);
+
+                                       Message cursorMessage = new 
Message(BBEvent.UPDATE_CURSORS);
+                                       cursorMessage.put("sender", "tree");
+                                       dm.dispatch(cursorMessage);
                                }
                        }
                });
@@ -106,10 +110,17 @@
                        public void keyTraversed(TraverseEvent e) {
                                if(e.stateMask == SWT.MOD1 && e.keyCode == 
SWT.ARROW_DOWN){
                                        sendIncrementCurrent(dm);
+                                       Message cursorMessage = new 
Message(BBEvent.UPDATE_CURSORS);
+                                       cursorMessage.put("sender", "tree");
+                                       dm.dispatch(cursorMessage);
                                        e.doit = false;
                                }
                                else if(e.stateMask == SWT.MOD1 && e.keyCode == 
SWT.ARROW_UP){
                                        sendDecrementCurrent(dm);
+                                       Message cursorMessage = new 
Message(BBEvent.UPDATE_CURSORS);
+                                       cursorMessage.put("sender", "tree");
+                                       dm.dispatch(cursorMessage);
+                                       e.doit = false;
                                }
                        }
                });
=======================================
--- /src/main/org/brailleblaster/wordprocessor/BBEvent.java Fri May 10 09:06:10 2013 +++ /src/main/org/brailleblaster/wordprocessor/BBEvent.java Mon May 13 08:46:10 2013
@@ -11,5 +11,6 @@
        ADJUST_ALIGNMENT,
        ADJUST_INDENT,
        UPDATE_STATUSBAR,
+       UPDATE_CURSORS,
        ADJUST_RANGE;
 }
=======================================
--- /src/main/org/brailleblaster/wordprocessor/DocumentManager.java Fri May 10 09:06:10 2013 +++ /src/main/org/brailleblaster/wordprocessor/DocumentManager.java Mon May 13 08:46:10 2013
@@ -316,6 +316,25 @@
                        case DECREMENT:
                                list.decrementCurrent(message);
                                this.treeView.setSelection(list.getCurrent(), 
message);
+                               break;
+                       case UPDATE_CURSORS:
+                               message.put("element", list.getCurrent().n);
+                               if(message.getValue("sender").equals("text")){
+                                       message.put("lastPosition", 
this.text.positionFromStart);
+                                       message.put("offset", 
this.text.cursorOffset);
+                                       list.getCurrentNodeData(message);
+                                       
this.braille.updateCursorPosition(message);
+                               }
+                               else 
if(message.getValue("sender").equals("braille")) {
+                                       message.put("lastPosition", 
this.braille.positionFromStart);
+                                       message.put("offset", 
this.braille.cursorOffset);
+                                       list.getCurrentNodeData(message);
+                                       this.text.updateCursorPosition(message);
+                               }
+                               else {
+                                       
this.text.view.setCaretOffset(list.getCurrent().start);
+ this.braille.view.setCaretOffset(list.getCurrent().brailleList.getFirst().start);
+                               }
                                break;
                        case SET_CURRENT:
                                list.checkList();
@@ -342,13 +361,6 @@
                                }
                                break;
                        case GET_CURRENT:
-                               if(message.getValue("sender").equals("text")){
-                                       message.put("lastPosition", 
this.braille.positionFromStart);
-                               }
-                               else {
-                                       message.put("lastPosition", 
this.text.positionFromStart);
-                               }
-                               message.put("element", list.getCurrent().n);
message.put("selection", this.treeView.getSelection(list.getCurrent()));
                                list.getCurrentNodeData(message);
                                this.treeView.setSelection(list.getCurrent(), 
message);

Other related posts:

  • » [brailleblaster] [brailleblaster.newdesign] push by brandon....@xxxxxxxxx - Updated Code Handling Cursor Position on 2013-05-13 15:59 GMT - brailleblaster