Revision: 28b936f25319 Branch: WithBrailleFormatting Author: Brandon Roller <brandon.r.roller@xxxxxxxxx> Date: Tue Jul 2 09:14:48 2013 Log: Started branch with braille formatting http://code.google.com/p/brailleblaster/source/detail?r=28b936f25319&repo=newdesign Modified: /src/main/org/brailleblaster/abstractClasses/AbstractView.java /src/main/org/brailleblaster/mapping/MapList.java /src/main/org/brailleblaster/views/BrailleView.java /src/main/org/brailleblaster/views/TextView.java /src/main/org/brailleblaster/wordprocessor/BBDocument.java /src/main/org/brailleblaster/wordprocessor/BBEvent.java /src/main/org/brailleblaster/wordprocessor/BBSemanticsTable.java /src/main/org/brailleblaster/wordprocessor/DocumentManager.java =======================================--- /src/main/org/brailleblaster/abstractClasses/AbstractView.java Tue Jun 11 12:01:30 2013 +++ /src/main/org/brailleblaster/abstractClasses/AbstractView.java Tue Jul 2 09:14:48 2013
@@ -54,6 +54,7 @@ public static int currentLine; protected boolean locked; protected static int currentAlignment; + protected static int topIndex; public AbstractView() { } @@ -116,6 +117,7 @@ } protected void setFontRange(int start, int length, int style){ + // System.out.println(view.getCharCount() + " " + (start + length)); StyleRange styleRange = new StyleRange(); styleRange.start = start; styleRange.length = length; @@ -132,6 +134,7 @@ protected int getFontWidth(){ GC gc = new GC(this.view); FontMetrics fm =gc.getFontMetrics(); + gc.dispose(); return fm.getAverageCharWidth(); } @@ -182,6 +185,23 @@ int line = this.view.getLineAtOffset(start); view.setLineAlignment(line, 1, currentAlignment); } + + protected void handleLineWrap(String text, int indent){ + int pos = this.spaceBeforeText + this.total; + int newPos; + int i = 0; + while( i < text.length() && text.charAt(i) == '\n'){ + i++; + }+ // this.view.setLineWrapIndent(this.view.getLineAtOffset(pos), 1, this.view.getLineIndent(this.view.getLineAtOffset(pos))+ (indent * getFontWidth()));
+ for(; i < text.length(); i++){ + if(text.charAt(i) == '\n' && i != text.length() - 1){ + i++; + newPos = pos + i;+ this.view.setLineIndent(this.view.getLineAtOffset(newPos), 1, this.view.getLineIndent(this.view.getLineAtOffset(newPos)) + (indent * getFontWidth()));
+ } + } + } protected void checkForLineBreak(Element parent, Node n){ if(parent.indexOf(n) > 0){ @@ -203,6 +223,13 @@ checkForLineBreak((Element)newParent.getParent(), newParent); } } + + public void setTopIndex(int line){ + setListenerLock(true); + this.view.setTopIndex(line); + topIndex = line; + setListenerLock(false); + } protected abstract void setViewData(Message message); public abstract void resetView(); =======================================--- /src/main/org/brailleblaster/mapping/MapList.java Sun Jun 9 16:51:20 2013 +++ /src/main/org/brailleblaster/mapping/MapList.java Tue Jul 2 09:14:48 2013
@@ -221,16 +221,16 @@ for(int i = 0; i < arr.length; i++){ if(i == arr.length - 1){ - if(start == index + 1) + // if(start == index + 1) + // arr[i] = new UpdaterThread(this, start, this.size(), offset, total); + // else arr[i] = new UpdaterThread(this, start, this.size(), offset, total); - else - arr[i] = new UpdaterThread(this, start, this.size(), offset, total); } else { - if(start == index + 1 ) + // if(start == index + 1 )+ // arr[i] = new UpdaterThread(this, start, start + length , offset, total);
+ // elsearr[i] = new UpdaterThread(this, start, start + length , offset, total);
- else- arr[i] = new UpdaterThread(this, start, start + length , offset, total);
} arr[i].start(); @@ -254,15 +254,15 @@ for(int i = 0; i < arr.length; i++){ if(i == arr.length - 1){ - if(start == index) - arr[i] = new UpdaterThread(this, start, this.size(), offset, offset); - else + //if(start == index)+ //arr[i] = new UpdaterThread(this, start, this.size(), offset, offset);
+ //else arr[i] = new UpdaterThread(this, start, this.size(), offset, offset); } else { - if(start == index)- arr[i] = new UpdaterThread(this, start, start + length , offset, offset);
- else + //if(start == index)+ //arr[i] = new UpdaterThread(this, start, start + length , offset, offset);
+ //elsearr[i] = new UpdaterThread(this, start, start + length , offset, offset);
} =======================================--- /src/main/org/brailleblaster/views/BrailleView.java Tue Jun 11 12:01:30 2013 +++ /src/main/org/brailleblaster/views/BrailleView.java Tue Jul 2 09:14:48 2013
@@ -54,6 +54,8 @@ import org.eclipse.swt.events.FocusListener; import org.eclipse.swt.events.MouseEvent; import org.eclipse.swt.events.MouseListener; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.events.TraverseEvent; import org.eclipse.swt.events.TraverseListener; import org.eclipse.swt.events.VerifyEvent; @@ -142,6 +144,7 @@ currentLine = view.getLineAtOffset(view.getCaretOffset()); } } + // System.out.println("Braille Caret:\t" + view.getCaretOffset()); } }); @@ -158,6 +161,27 @@ view.setCaretOffset(currentStart); e.doit = false; } + } + }); + + view.getVerticalBar().addSelectionListener(new SelectionListener(){ + @Override + public void widgetDefaultSelected(SelectionEvent arg0) { + // TODO Auto-generated method stub + + } + + @Override + public void widgetSelected(SelectionEvent e) { + if(!getLock()){ + if(topIndex != view.getTopIndex()){ + topIndex = view.getTopIndex(); + Message scrollMessage = new Message(BBEvent.UPDATE_SCROLLBAR); + scrollMessage.put("sender", "braille"); + scrollMessage.put("offset", view.getOffsetAtLine(topIndex)); + dm.dispatch(scrollMessage); + } + } } }); @@ -185,6 +209,7 @@ previousEnd = (Integer)message.getValue("previousBrailleEnd"); this.pageRanges.clear();setPageRange((ArrayList<BrailleMapElement>)message.getValue("pageRanges"));
+ // System.out.println("Braille:\t " + currentStart + " " + currentEnd); } private void setPageRange(ArrayList<BrailleMapElement> list){ @@ -195,12 +220,19 @@ } public void setBraille(Node n, TextMapElement t){ + String text = n.getValue(); setListenerLock(true);String key = this.stylesTable.getKeyFromAttribute((Element)t.n.getParent());
Styles style = this.stylesTable.makeStylesElement(key, n); + if(insertNewLine(n)){ + view.append("\n"); + this.total++; + } + view.append(n.getValue()); handleStyle(style, n, (Element)t.n.getParent()); +// checkFinalNewline(n);t.brailleList.add(new BrailleMapElement(this.spaceBeforeText + this.total, this.spaceBeforeText + this.total + n.getValue().length(), n)); this.total += this.spaceBeforeText + n.getValue().length() + this.spaceAfterText;
@@ -220,11 +252,24 @@ return false; } + + private void checkFinalNewline(Node n){ + Element parent = (Element)n.getParent(); + int childCount = parent.getChildCount(); + + if(parent.indexOf(n) == childCount - 2){+ if(parent.getChild(childCount - 1) instanceof Element && ((Element)parent.getChild(childCount - 1)).getLocalName().equals("newline")){
+ view.append("\n"); + this.spaceAfterText++; + } + } + } private void handleStyle(Styles style, Node n, Element parent){ String viewText = n.getValue(); Element brailleParent = (Element)n.getParent(); int index = parent.indexOf(brailleParent); + /* if(index > 1){if(parent.getChild(index - 2) instanceof Element && ((Element)parent.getChild(index - 2)).getLocalName().equals("br")){
insertBefore(this.spaceBeforeText + this.total, "\n"); @@ -233,13 +278,13 @@ else if(parent.getAttributeValue("semantics").contains("action")){ checkForLineBreak((Element)parent.getParent(), parent); } - + */ for (StylesType styleType : style.getKeySet()) { switch(styleType){ case linesBefore: if(isFirst(n)){String textBefore = makeInsertionString(Integer.valueOf((String)style.get(styleType)),'\n');
- insertBefore(this.total - this.spaceBeforeText, textBefore); + insertBefore(this.total + this.spaceBeforeText, textBefore); } break; case linesAfter: @@ -250,19 +295,19 @@ break; case firstLineIndent: if(isFirst(n) && Integer.valueOf((String)style.get(styleType)) != -2){ - insertBefore(this.spaceBeforeText + this.total, "\t"); - // int spaces = Integer.valueOf((String)style.get(styleType));- // this.view.setLineIndent(this.view.getLineAtOffset(this.spaceBeforeText + this.total + this.spaceAfterText) , 1, spaces * getFontWidth());
+ int spaces = Integer.valueOf((String)style.get(styleType));+ this.view.setLineIndent(this.view.getLineAtOffset(this.spaceBeforeText + this.total) , 1, spaces * getFontWidth());
} break; case format:- this.view.setLineAlignment(this.view.getLineAtOffset( this.spaceBeforeText + this.total + this.spaceAfterText), 1, Integer.valueOf((String)style.get(styleType))); + this.view.setLineAlignment(this.view.getLineAtOffset(this.spaceBeforeText + this.total + this.spaceAfterText), 1, Integer.valueOf((String)style.get(styleType)));
break; case Font:- setFontRange(this.total, n.getValue().length() + this.spaceAfterText, SWT.ITALIC); + setFontRange(this.total, this.spaceBeforeText + n.getValue().length(), Integer.valueOf((String)style.get(styleType)));
break; case leftMargin:- // this.view.setLineWrapIndent(this.view.getLineAtOffset(this.spaceBeforeText + this.total), 1, this.view.getLineIndent(this.view.getLineAtOffset(this.spaceBeforeText + this.total))+ (2 * getFontWidth()));
+ if(!isFirst(n) && followsNewLine(n))+ this.view.setLineIndent(this.view.getLineAtOffset(this.spaceBeforeText + this.total), 1, this.view.getLineIndent(this.view.getLineAtOffset(this.spaceBeforeText + this.total))+ (Integer.valueOf((String)style.get(styleType)) * getFontWidth()));
break; default: System.out.println(styleType); @@ -277,19 +322,30 @@ }if(isLast(n) && grandParent.indexOf(parent) == grandParent.getChildCount() - 1){ - insertAfter(this.spaceBeforeText + this.total + n.getValue().length() + this.spaceAfterText, "\n"); + // insertAfter(this.spaceBeforeText + this.total + n.getValue().length() + this.spaceAfterText, "\n");
} } else if(parent.getAttributeValue("semantics").equals("style,list")){ - if(isLast(n))- insertAfter(this.spaceBeforeText + this.total + viewText.length() + this.spaceAfterText, "\n");
+ // if(isLast(n))+ // insertAfter(this.spaceBeforeText + this.total + viewText.length() + this.spaceAfterText, "\n");
} else if(isLast(n)){ Elements els = parent.getChildElements();- if(els.size() > 0 && els.get(els.size() - 1).getLocalName().equals("brl")) - insertAfter(this.spaceBeforeText + this.total + n.getValue().length() + this.spaceAfterText, "\n"); + // if(els.size() > 0 && els.get(els.size() - 1).getLocalName().equals("brl")) + // insertAfter(this.spaceBeforeText + this.total + n.getValue().length() + this.spaceAfterText, "\n");
} } + + private boolean followsNewLine(Node n){ + Element parent = (Element)n.getParent(); + int index = parent.indexOf(n); + + if(index > 0 && parent.getChild(index - 1) instanceof Element){+ if(((Element)parent.getChild(index - 1)).getLocalName().equals("newline"))
+ return true; + } + return false; + } private boolean isFirst(Node n){ //From earlier pre-formatted version @@ -315,7 +371,7 @@ return false; } - if(grandParent.getAttributeValue("semantics").contains("action")){+ if(grandParent.getAttributeValue("semantics").contains("action") && !grandParent.getLocalName().equals("lic")){
return isFirstElement(grandParent); } else { @@ -398,25 +454,26 @@ } public void updateBraille(TextMapElement t, Message message){ + StyleRange range = null; int total = (Integer)message.getValue("brailleLength");- int startLine = this.view.getLineAtOffset(t.brailleList.getFirst().start);
- int lineIndent = this.view.getLineIndent(startLine); + System.out.println("Value: " + t.n.getValue()); String insertionString = (String)message.getValue("newBrailleText"); if(t.brailleList.getFirst().start != -1){ setListenerLock(true); + if(t.brailleList.getFirst().start < view.getCharCount()) + range = view.getStyleRangeAtOffset(t.brailleList.getFirst().start); ++ int startLine = this.view.getLineAtOffset(t.brailleList.getFirst().start);
+ int lineIndent = this.view.getLineIndent(startLine);view.replaceTextRange(t.brailleList.getFirst().start, total, insertionString);
restoreStyleState(t.brailleList.getFirst().start); setListenerLock(false); view.setLineIndent(startLine, 1, lineIndent); - - if(t.brailleList.getFirst().start < view.getCharCount()){- StyleRange range = view.getStyleRangeAtOffset(t.brailleList.getFirst().start);
- if(range != null)- updateRange(range, t.brailleList.getFirst().start, insertionString.length());
- } + + if(range != null)+ updateRange(range, t.brailleList.getFirst().start, insertionString.length());
} - }public void removeWhitespace(int start, int length, char c, DocumentManager dm){
@@ -426,6 +483,7 @@ dm.dispatch(message); setViewData(message); + // System.out.println("Start" + start);if(c == SWT.DEL && view.getText(start, start).equals("\t") && (start != currentEnd && start != previousEnd)){
start--; } =======================================--- /src/main/org/brailleblaster/views/TextView.java Fri Jun 28 14:21:32 2013 +++ /src/main/org/brailleblaster/views/TextView.java Tue Jul 2 09:14:48 2013
@@ -71,7 +71,7 @@ private BBSemanticsTable stylesTable; private StyleRange range; private int[] selectionArray; - private SelectionListener selectionListener; + private SelectionListener selectionListener, scrollbarListener; private VerifyKeyListener verifyListener; private ExtendedModifyListener modListener; private FocusListener focusListener; @@ -132,15 +132,28 @@ e.doit = false; setSelection(-1, -1); } - /* +if(oldCursorPosition == currentStart && oldCursorPosition != previousEnd && e.character == SWT.BS && view.getLineIndent(view.getLineAtOffset(currentStart)) != 0 && currentStart != currentEnd){
Message message = new Message(BBEvent.ADJUST_INDENT); message.put("sender", "text"); message.put("indent", 0); + message.put("line", view.getLineAtOffset(currentStart)); view.setLineIndent(view.getLineAtOffset(currentStart), 1, 0); dm.dispatch(message); e.doit = false; } + /*+ else if(oldCursorPosition > 0 && oldCursorPosition < view.getCharCount() && e.character == SWT.BS){ + if(view.getLineAtOffset(oldCursorPosition) != view.getLineAtOffset(oldCursorPosition - 1) && view.getLineIndent(view.getLineAtOffset(oldCursorPosition)) != 0){
+ Message message = new Message(BBEvent.ADJUST_INDENT); + message.put("sender", "text"); + message.put("indent", 0); + message.put("line", view.getLineAtOffset(oldCursorPosition)); + view.setLineIndent(view.getLineAtOffset(oldCursorPosition), 1, 0); + dm.dispatch(message); + e.doit = false; + } + } */ if(selectionLength > 0){ saveStyleState(selectionStart); @@ -210,6 +223,7 @@ if(view.getLineAtOffset(view.getCaretOffset()) != currentLine){ sendStatusBarUpdate(dm); } + // System.out.println("Caret pos:\t" + view.getCaretOffset()); } }); @@ -257,6 +271,25 @@ } } }); ++ view.getVerticalBar().addSelectionListener(scrollbarListener = new SelectionListener(){
+ @Override + public void widgetDefaultSelected(SelectionEvent arg0) { + // TODO Auto-generated method stub + } + + @Override + public void widgetSelected(SelectionEvent e) { + if(!getLock()){ + if(topIndex != view.getTopIndex()){ + topIndex = view.getTopIndex(); + Message scrollMessage = new Message(BBEvent.UPDATE_SCROLLBAR); + scrollMessage.put("offset", view.getOffsetAtLine(topIndex)); + dm.dispatch(scrollMessage); + } + } + } + }); setListenerLock(false); } @@ -270,6 +303,7 @@ view.removeMouseListener(mouseListener); view.removeTraverseListener(traverseListener); view.removeCaretListener(caretListener); + view.getVerticalBar().removeSelectionListener(scrollbarListener); } } @@ -295,6 +329,7 @@ dm.dispatch(message); setViewData(message); charAtOffset = null; + // System.out.println("Current:\t" + currentStart + " " + currentEnd); }private void sendDeleteSpaceMessage(DocumentManager dm, int offset, int key){
@@ -380,12 +415,21 @@String key = this.stylesTable.getKeyFromAttribute((Element)n.getParent());
Styles style = this.stylesTable.makeStylesElement(key, n); - String text = n.getValue().replace("\n",""); - view.append(text); - handleStyle(style, n, text); + //String text = n.getValue().replace("\n",""); + String newText = appendToView(n); + //System.out.println("Length: " + newText.length()); + //System.out.println(newText); + view.append(newText); + handleStyle(style, n, newText); + // for(int i = 0; i < this.spaceAfterText; i++) + // view.append("\n");- list.add(new TextMapElement(this.spaceBeforeText + this.total, this.spaceBeforeText + this.total + text.length() + this.escapeChars,n)); - this.total += this.spaceBeforeText + text.length() + this.spaceAfterText + this.escapeChars; + list.add(new TextMapElement(this.spaceBeforeText + this.total, this.spaceBeforeText + this.total + newText.length() + this.spaceAfterText,n)); + this.total += this.spaceBeforeText + newText.length() + this.spaceAfterText;
+ + // if(view.getCharCount() != this.total){ + // System.out.println(view.getCharCount() + " " + this.total); + // } this.spaceAfterText = 0; this.spaceBeforeText = 0; this.escapeChars = 0; @@ -394,15 +438,20 @@ } public void reformatText(Node n, Message message, DocumentManager dm){ + String reformattedText; int pos = view.getCaretOffset(); setListenerLock(true); int indent = view.getLineIndent(view.getLineAtOffset(currentStart)); StyleRange range = getStyleRange(); - //String reformattedText = appendToView(n).substring(1); -- view.replaceTextRange(currentStart, currentEnd - currentStart, n.getValue()); - message.put("length", (n.getValue().length() + this.spaceAfterText) - (Integer)message.getValue("length"));
+ if(!n.getValue().equals("")) + reformattedText = reformatUpdatedText(n); + else + reformattedText = n.getValue(); ++ view.replaceTextRange(currentStart, currentEnd - currentStart, reformattedText); + // System.out.println(message.getValue("length") + " " + reformattedText.length() + " " + reformattedText.replace("\n","").length()); + message.put("length", (reformattedText.length() + this.spaceAfterText) - (Integer)message.getValue("length"));
view.setLineIndent(view.getLineAtOffset(currentStart), 1, indent); checkStyleRange(range); @@ -412,6 +461,70 @@ this.escapeChars = 0; setListenerLock(false); } + + private String reformatUpdatedText(Node n){ + String text = ""; + Element brl = getBrlNode(n); + int start = 0; + int end = 0; + int totalLength = 0; + + if(brl != null){ + int[] indexes = getIndexArray(brl); + if(indexes != null){ + for(int i = 0; i < brl.getChildCount(); i++){ + if(brl.getChild(i) instanceof Text){+ if(i > 0 && ((Element)brl.getChild(i - 1)).getLocalName().equals("newline")){
+ String brltext = brl.getChild(i).getValue(); + totalLength += brltext.length(); + end = indexes[totalLength - 1]; + if(totalLength == indexes.length){ + if(start == 0){ + text += n.getValue().substring(start); + } + else { + text += "\n" + n.getValue().substring(start); + this.escapeChars++; + } + } + else{ + end += indexes[totalLength] - end; + if(start == 0){ + text += n.getValue().substring(start, end); + } + else{ + text += "\n" + n.getValue().substring(start, end); + this.escapeChars++; + } + } + start = end; + } + else { + String brltext = brl.getChild(i).getValue(); + totalLength += brltext.length(); + end = indexes[totalLength - 1]; + if(totalLength == indexes.length){ + text += n.getValue().substring(start); + } + else{ + end += indexes[totalLength] - end; + text += n.getValue().substring(start, end); + } + start = end; + } + } + } + } + else { + text += n.getValue(); + } + } + else { + text += n.getValue(); + } + + return text; + } private String appendToView(Node n){ String text = ""; @@ -419,7 +532,7 @@ int start = 0; int end = 0; int totalLength = 0; - + if(brl != null){ int[] indexes = getIndexArray(brl); if(indexes != null){ @@ -430,25 +543,34 @@ totalLength += brltext.length(); end = indexes[totalLength - 1]; if(totalLength == indexes.length){ - text += "\n" + n.getValue().substring(start); - if(start == 0) + if(start == 0){ + view.append("\n"); + text += n.getValue().substring(start); this.spaceBeforeText++; - else + } + else { + text += "\n" + n.getValue().substring(start); this.escapeChars++; + } } else{ end += indexes[totalLength] - end; - text += "\n" + n.getValue().substring(start, end); - if(start == 0) + if(start == 0){ + view.append("\n"); + text += n.getValue().substring(start, end); this.spaceBeforeText++; - else + } + else{ + text += "\n" + n.getValue().substring(start, end); this.escapeChars++; + } } start = end; } else { String brltext = brl.getChild(i).getValue(); totalLength += brltext.length();+ // System.out.println("Array length " + indexes.length + " text Lwenvb: " + brltext.length());
end = indexes[totalLength - 1]; if(totalLength == indexes.length){ text += n.getValue().substring(start); @@ -463,50 +585,58 @@ } } else { - text += "\n" + n.getValue(); + view.append("\n"); + text += n.getValue(); this.spaceBeforeText++; } } else { text += n.getValue(); } - +/* + if(brl != null && brl.getChildCount() > 0){+ if(brl.getChild(brl.getChildCount() - 1) instanceof Element && ((Element)brl.getChild(brl.getChildCount() - 1)).getLocalName().equals("newline")){
+ this.spaceAfterText++; + } + } +*/ return text; } private void handleStyle(Styles style, Node n, String viewText){ Element parent = (Element)n.getParent(); - checkForLineBreak(parent, n); + //checkForLineBreak(parent, n); for (StylesType styleType : style.getKeySet()) { switch(styleType){ case linesBefore: if(isFirst(n)){String textBefore = makeInsertionString(Integer.valueOf((String)style.get(styleType)),'\n');
- insertBefore(this.total - this.spaceBeforeText, textBefore); + insertBefore(this.total + this.spaceBeforeText, textBefore); } break; case linesAfter: if(isLast(n)){String textAfter = makeInsertionString(Integer.valueOf((String)style.get(styleType)), '\n'); - insertAfter(this.spaceBeforeText + this.total + viewText.length() + this.spaceAfterText, textAfter); + insertAfter(this.spaceBeforeText + this.total + viewText.length(), textAfter);
} break; case firstLineIndent: - if(isFirst(n) && Integer.valueOf((String)style.get(styleType)) != -2){ - insertBefore(this.spaceBeforeText + this.total, "\t"); - // int spaces = Integer.valueOf((String)style.get(styleType));- // this.view.setLineIndent(this.view.getLineAtOffset(this.spaceBeforeText + this.total + this.spaceAfterText + this.escapeChars) , 1, spaces * getFontWidth());
+ if(isFirst(n) && Integer.valueOf((String)style.get(styleType)) != -2){ + int spaces = Integer.valueOf((String)style.get(styleType));+ this.view.setLineIndent(this.view.getLineAtOffset(this.spaceBeforeText + this.total) , 1, spaces * getFontWidth());
} break; case format:- this.view.setLineAlignment(this.view.getLineAtOffset(this.spaceBeforeText + this.total + this.spaceAfterText), 1, Integer.valueOf((String)style.get(styleType))); + this.view.setLineAlignment(this.view.getLineAtOffset(this.spaceBeforeText + this.total + this.spaceAfterText), getLineNumber(this.spaceBeforeText + this.total, viewText), Integer.valueOf((String)style.get(styleType)));
break; case Font:- setFontRange(this.total, viewText.length() + this.spaceAfterText, SWT.ITALIC); + setFontRange(this.total, this.spaceBeforeText + viewText.length(), Integer.valueOf((String)style.get(styleType)));
break; case leftMargin:- // this.view.setLineWrapIndent(this.view.getLineAtOffset(this.spaceBeforeText + this.total), 1, this.view.getLineIndent(this.view.getLineAtOffset(this.spaceBeforeText + this.total))+ (2 * getFontWidth())); + //System.out.println(this.view.getLineAtOffset(this.spaceBeforeText + this.total)); + //this.view.setLineWrapIndent(this.view.getLineAtOffset(this.spaceBeforeText + this.total), 1, this.view.getLineIndent(this.view.getLineAtOffset(this.spaceBeforeText + this.total))+ (2 * getFontWidth())); + handleLineWrap( viewText, Integer.valueOf((String)style.get(styleType)));
break; default: System.out.println(styleType); @@ -521,15 +651,22 @@ }if(isLast(n) && grandParent.indexOf(parent) == grandParent.getChildCount() - 1){ - insertAfter(this.spaceBeforeText + this.total + viewText.length() + this.spaceAfterText, "\n"); + // insertAfter(this.spaceBeforeText + this.total + viewText.length() + this.spaceAfterText, "\n");
} } else if(isLast(n)){ Elements els = parent.getChildElements();- if(els.size() > 0 && els.get(els.size() - 1).getLocalName().equals("brl")) - insertAfter(this.spaceBeforeText + this.total + viewText.length() + this.spaceAfterText, "\n"); + // if(els.size() > 0 && els.get(els.size() - 1).getLocalName().equals("brl")) + // insertAfter(this.spaceBeforeText + this.total + viewText.length() + this.spaceAfterText, "\n");
} } + + private int getLineNumber(int startOffset, String text){ + int startLine = view.getLineAtOffset(startOffset); + int endLine = view.getLineAtOffset(startOffset + text.length()); + + return (endLine - startLine) + 1; + } private void handleTextEdit(DocumentManager dm, ExtendedModifyEvent e){ int changes = e.length; @@ -568,6 +705,7 @@ selectionLength -= currentEnd - e.start; makeTextChange(changes - (currentEnd - e.start)); sendUpdate(dm); + setCurrent(dm); selectionStart = currentEnd; } @@ -587,6 +725,13 @@ else if(selectionStart > currentEnd){ sendAdjustRangeMessage(dm, "end", selectionStart - currentEnd); } + else if(e.start + replacedTextLength == currentEnd){ + changes -= replacedTextLength; + makeTextChange(changes); + sendUpdate(dm); + setCurrent(dm); + //Test more + } else { if(selectionLength > e.length) changes = e.length - selectionLength; @@ -614,7 +759,7 @@private void handleTextDeletion(DocumentManager dm, ExtendedModifyEvent e){
int offset = view.getCaretOffset() - oldCursorPosition; setListenerLock(true); - if(selectionLength > 0){ + if(e.replacedText.length() > 1){ view.setCaretOffset(selectionStart); setCurrent(dm); deleteSelection(dm); @@ -697,6 +842,7 @@ selectionLength -= changes; sendUpdate(dm); setCurrent(dm); + selectionStart = currentEnd; } else if(selectionStart == currentEnd && selectionStart != nextStart){ changes = nextStart - currentEnd; =======================================--- /src/main/org/brailleblaster/wordprocessor/BBDocument.java Fri Jun 21 14:16:47 2013 +++ /src/main/org/brailleblaster/wordprocessor/BBDocument.java Tue Jul 2 09:14:48 2013
@@ -86,13 +86,12 @@ // Use the default; we don't have a local version.configFileWithPath = fu.findInProgramData ("liblouisutdml" + BBIni.getFileSep() + "lbu_files" + BBIni.getFileSep() + configFile);
- if (configSettings == null) {- configWithUTD = "formatFor utd\n mode notUC\n paragraphs no\n printPages no\n";
+ configWithUTD = "formatFor utd\n mode notUC\n printPages no\n"; } else {- configWithUTD = configSettings + "formatFor utd\n mode notUC\n paragraphs no\n printPages no\n"; + configWithUTD = configSettings + "formatFor utd\n mode notUC\n printPages no\n";
} String outFile = BBIni.getTempFilesPath() + fileSep + "outFile.utd"; String logFile = BBIni.getLogFilesPath() + fileSep + "liblouisutdml.log"; @@ -163,6 +162,8 @@ private void updateNode(MapList list, Message message){ int total = 0; String text = (String)message.getValue("newText"); + text = text.replace("\n", "").replace("\r", ""); + message.put("newText", text); calculateDifference(list.getCurrent().n.getValue(), text, message); changeTextNode(list.getCurrent().n, text); @@ -188,6 +189,7 @@ private int changeBrailleNodes(TextMapElement t, Message message){Document d = getStringTranslation(t, (String)message.getValue("newText"));
+ // System.out.println(d.toXML().toString()); int total = 0; int startOffset = 0; String insertionString = ""; @@ -195,7 +197,7 @@ Element brlParent = ((Element)d.getRootElement().getChild(0)); Elements els = brlParent.getChildElements(); - if(els.get(0).getLocalName().equals("strong")){+ if(els.get(0).getLocalName().equals("strong") || els.get(0).getLocalName().equals("em")){
e = els.get(0).getChildElements().get(0); addNamespace(e); brlParent.getChildElements().get(0).removeChild(e); @@ -206,6 +208,7 @@ brlParent.removeChild(e); } + // System.out.println(e.getValue()); startOffset = t.brailleList.getFirst().start; String logString = ""; @@ -325,6 +328,10 @@ Element parent = (Element)t.n.getParent(); while(!parent.getAttributeValue("semantics").contains("style")){ if(parent.getAttributeValue("semantics").equals("action,italicx")){ + text = "<em>" + text + "</em>"; + break; + } + else if(parent.getAttributeValue("semantics").equals("action,boldx")){ text = "<strong>" + text + "</strong>"; break; } @@ -361,13 +368,13 @@ } private String getXMLString(String text){ + text = text.replace("\n", "");return "<?xml version=\"1.0\" encoding=\"UTF-8\"?><book><string>" + text + "</string></book>";
} private int translateString(String text, byte[] outbuffer) {String logFile = BBIni.getLogFilesPath() + BBIni.getFileSep() + BBIni.getInstanceID() + BBIni.getFileSep() + "liblouisutdml.log"; - String preferenceFile = BBIni.getProgramDataPath() + BBIni.getFileSep() + "liblouisutdml" + BBIni.getFileSep() + "lbu_files" +
- BBIni.getFileSep() + BBIni.getDefaultConfigFile();+ String preferenceFile = fu.findInProgramData ("liblouisutdml" + BBIni.getFileSep() + "lbu_files" + BBIni.getFileSep() + BBIni.getDefaultConfigFile());
byte[] inbuffer; try { @@ -375,7 +382,7 @@ int [] outlength = new int[1]; outlength[0] = text.length() * 10;- if(lutdml.translateString(preferenceFile, inbuffer, outbuffer, outlength, logFile, "formatFor utd\n mode notUC\n paragraphs no\n printPages no\n", 0)){ + if(lutdml.translateString(preferenceFile, inbuffer, outbuffer, outlength, logFile, "formatFor utd\n mode notUC\n printPages no\n", 0)){
return outlength[0]; } else { @@ -499,7 +506,7 @@ if(inFile.equals("")) - return false; + return false;boolean result = lutdml.translateFile (config, inFile, filePath, logFile, "formatFor brf\n", 0);
deleteTempFile(inFile); @@ -540,6 +547,18 @@ m.put("diff", diff); } ++ public boolean checkAttributeValue(Element e, String attribute, String value){
+ try { + if(e.getAttributeValue(attribute).equals(value)) + return true; + else + return false; + } + catch(Exception ex){ + return false; + } + } public void checkSemantics(Element e){ if(e.getAttributeValue("semantics") == null){ =======================================--- /src/main/org/brailleblaster/wordprocessor/BBEvent.java Thu May 23 07:34:42 2013 +++ /src/main/org/brailleblaster/wordprocessor/BBEvent.java Tue Jul 2 09:14:48 2013
@@ -41,5 +41,6 @@ ADJUST_INDENT, UPDATE_STATUSBAR, UPDATE_CURSORS, + UPDATE_SCROLLBAR, ADJUST_RANGE; } =======================================--- /src/main/org/brailleblaster/wordprocessor/BBSemanticsTable.java Tue Jun 11 12:01:30 2013 +++ /src/main/org/brailleblaster/wordprocessor/BBSemanticsTable.java Tue Jul 2 09:14:48 2013
@@ -79,7 +79,9 @@ makeHashTable(reader); reader.close(); makeStylesObject("italicx"); - insertValue("italicx","\tFont italic"); + insertValue("italicx","\tFont " + SWT.ITALIC); + makeStylesObject("boldx"); + insertValue("boldx","\tFont " + SWT.BOLD); } catch(Exception e){ e.printStackTrace(); @@ -170,7 +172,19 @@ if(!st.contains(styleType)){ st.put(styleType, (String)newStyle.get(styleType)); } + else if(st.contains(styleType) && styleType.equals(StylesType.Font)){+ st.put(styleType, (String.valueOf(combineFontStyles((String)st.get(styleType), (String)newStyle.get(styleType)))));
+ } } } + } + + private int combineFontStyles(String font1, String font2){ + if(font1.equals(font2)){ + return Integer.valueOf(font1); + } + else { + return Integer.valueOf(font1) + Integer.valueOf(font2); + } } } =======================================--- /src/main/org/brailleblaster/wordprocessor/DocumentManager.java Wed Jun 26 13:03:08 2013 +++ /src/main/org/brailleblaster/wordprocessor/DocumentManager.java Tue Jul 2 09:14:48 2013
@@ -260,9 +260,6 @@ this.treeView.setRoot(this.document.getRootElement(), this); initializeViews(this.document.getRootElement()); this.document.notifyUser(); - //list.getLast().brailleList.removeLast();- this.text.view.replaceTextRange(this.text.view.getCharCount() - 1, 1, ""); - this.braille.view.replaceTextRange(this.braille.view.getCharCount() - 1, 1, "");
this.text.initializeListeners(this); this.braille.initializeListeners(this); this.text.hasChanged = false; @@ -284,7 +281,7 @@ } private void initializeViews(Node current){- if(current instanceof Text && !((Element)current.getParent()).getLocalName().equals("brl")){ + if(current instanceof Text && !((Element)current.getParent()).getLocalName().equals("brl") && vaildTextElement(current.getValue())){
this.text.setText(current, list); } @@ -308,7 +305,9 @@ private void initializeBraille(Node current, TextMapElement t){if(current instanceof Text && ((Element)current.getParent()).getLocalName().equals("brl")){
- this.braille.setBraille(current, t); + Element grandParent = (Element)current.getParent().getParent();+ if(!(grandParent.getLocalName().equals("span") && this.document.checkAttributeValue(grandParent, "class", "brlonly")))
+ this.braille.setBraille(current, t); } for(int i = 0; i < current.getChildCount(); i++){ @@ -438,6 +437,16 @@ break; case GET_TEXT_MAP_ELEMENTS: list.findTextMapElements(message); + break; + case UPDATE_SCROLLBAR: + if(message.contains("sender")){ + index = list.findClosestBraille(message); + this.text.setTopIndex(this.braille.view.getTopIndex()); + } + else{ + index = list.findClosest(message, 0, list.size() - 1); + this.braille.setTopIndex(this.text.view.getTopIndex()); + } break; default: break; @@ -559,7 +568,10 @@ if(this.text.view.isFocusControl()){ currentOffset = this.text.view.getCaretOffset(); resetViews(); - this.text.view.setCaretOffset(currentOffset); + if(currentOffset < this.text.view.getCharCount()) + this.text.view.setCaretOffset(currentOffset); + else + this.text.view.setCaretOffset(0); m.put("sender", "text"); m.put("offset", currentOffset); this.dispatch(m); @@ -611,6 +623,17 @@ catch(Exception e){ e.printStackTrace(); } + } + + private boolean vaildTextElement(String text){ + int length = text.length(); + + for(int i = 0; i < length; i++){ + if(text.charAt(i) != '\n' && text.charAt(i) != '\t') + return true; + } + + return false; } public void toggleBrailleFont(){