Revision: a771fa22f946 Branch: rt1991 Author: Rebecca Luttmer <rebecca.luttmer@xxxxxxxxx> Date: Mon Feb 2 17:23:00 2015 UTC Log: user modifies lines box https://code.google.com/p/brailleblaster/source/detail?r=a771fa22f946 Modified: /.hgtags /dist/programData/settings/about.properties /src/main/org/brailleblaster/BBIni.java /src/main/org/brailleblaster/perspectives/braille/Manager.java/src/main/org/brailleblaster/perspectives/braille/document/BrailleDocument.java
/src/main/org/brailleblaster/perspectives/braille/eventQueue/Event.java/src/main/org/brailleblaster/perspectives/braille/eventQueue/EventFrame.java /src/main/org/brailleblaster/perspectives/braille/eventQueue/EventQueue.java /src/main/org/brailleblaster/perspectives/braille/eventQueue/EventTypes.java
/src/main/org/brailleblaster/perspectives/braille/eventQueue/RedoQueue.java /src/main/org/brailleblaster/perspectives/braille/eventQueue/UndoQueue.java /src/main/org/brailleblaster/perspectives/braille/mapping/maps/MapList.java /src/main/org/brailleblaster/perspectives/braille/messages/BBEvent.java /src/main/org/brailleblaster/perspectives/braille/messages/Message.java/src/main/org/brailleblaster/perspectives/braille/stylers/BoxlineHandler.java /src/main/org/brailleblaster/perspectives/braille/stylers/HideActionHandler.java
/src/main/org/brailleblaster/perspectives/braille/ui/BBToolBar.java/src/main/org/brailleblaster/perspectives/braille/viewInitializer/WebInitializer.java
/src/main/org/brailleblaster/perspectives/braille/views/tree/TreeView.java /src/main/org/brailleblaster/perspectives/braille/views/wp/BrailleView.java /src/main/org/brailleblaster/perspectives/braille/views/wp/TextView.java /src/main/org/brailleblaster/perspectives/braille/views/wp/WPView.java /src/main/org/brailleblaster/search/SearchDialog.java /src/main/org/brailleblaster/settings/SettingsManager.java /src/main/org/brailleblaster/settings/ui/PageNumbersTab.java /src/main/org/brailleblaster/settings/ui/PagePropertiesTab.java /src/main/org/brailleblaster/util/Notify.java /src/main/org/brailleblaster/wordprocessor/RecentDocuments.java /src/main/org/brailleblaster/wordprocessor/WPManager.java ======================================= --- /.hgtags Tue Jan 6 13:04:09 2015 UTC +++ /.hgtags Mon Feb 2 17:23:00 2015 UTC @@ -23,4 +23,3 @@ a16d029f4665728751800b1f730f887f22ae4d71 2014.10.31 b0e6ffea1bdd814224659b173a8b48793558f63c 2014.11.28 ba3dbf4c833440afc2d8c4f59abde69946e756d7 2014.12.12 -eb2d6e6173de029d57ee188c3dcda98347ae4fd0 2015.01.02 ======================================= --- /dist/programData/settings/about.properties Tue Jan 6 13:04:27 2015 UTC +++ /dist/programData/settings/about.properties Mon Feb 2 17:23:00 2015 UTC @@ -1,3 +1,3 @@ name=BrailleBlaster -version=0.11.0 -date=January 2, 2015 +version=0.10.0 +date=December 12, 2014 ======================================= --- /src/main/org/brailleblaster/BBIni.java Thu Dec 11 16:44:03 2014 UTC +++ /src/main/org/brailleblaster/BBIni.java Mon Feb 2 17:23:00 2015 UTC @@ -63,6 +63,10 @@ * @author cmyers * */ +/** + * @author cmyers + * + */ public final class BBIni { private static BBIni bbini; @@ -90,6 +94,8 @@ private static String releaseDate; private static String brailleblasterPath; // FO + private static String osName; + private static String osVersion; private static String fileSep; private static String nativeCommandPath; private static String nativeLibraryPath; @@ -108,6 +114,7 @@ public final static String propExtension = ".properties"; private static boolean hSubcommands = false; private static boolean hLiblouisutdml = false; + // private static FileHandler logFile; private static final String BBID = "brlblst"; private static String instanceId; private static String defaultCfg; @@ -122,6 +129,8 @@ platformName = SWT.getPlatform(); Main m = new Main(); brailleblasterPath = getBrailleblasterPath(m); + osName = System.getProperty("os.name"); + osVersion = System.getProperty("os.version"); fileSep = System.getProperty("file.separator"); String userHome = System.getProperty("user.home"); String BBHome; @@ -436,10 +445,6 @@ public static String getVersion() { return BBVersion; } - - public static boolean gotGUI(){ - return gotGui; - } public static String getReleaseDate() { return releaseDate; =======================================--- /src/main/org/brailleblaster/perspectives/braille/Manager.java Mon Jan 26 17:23:45 2015 UTC +++ /src/main/org/brailleblaster/perspectives/braille/Manager.java Mon Feb 2 17:23:00 2015 UTC
@@ -36,6 +36,7 @@ import java.io.File; import java.io.IOException; import java.util.ArrayList; +import java.util.Iterator; import java.util.LinkedHashSet; import java.util.Set; @@ -54,9 +55,15 @@ import org.brailleblaster.localization.LocaleHandler; import org.brailleblaster.perspectives.Controller; import org.brailleblaster.perspectives.braille.document.BBSemanticsTable;+import org.brailleblaster.perspectives.braille.document.BBSemanticsTable.Styles; +import org.brailleblaster.perspectives.braille.document.BBSemanticsTable.StylesType;
import org.brailleblaster.perspectives.braille.document.BrailleDocument; import org.brailleblaster.perspectives.braille.eventQueue.EventFrame; -import org.brailleblaster.perspectives.braille.eventQueue.QueueManager; +import org.brailleblaster.perspectives.braille.eventQueue.EventQueue; +import org.brailleblaster.perspectives.braille.eventQueue.RedoQueue; +import org.brailleblaster.perspectives.braille.eventQueue.UndoQueue;+import org.brailleblaster.perspectives.braille.mapping.elements.BrlOnlyMapElement; +import org.brailleblaster.perspectives.braille.mapping.elements.PageMapElement;
import org.brailleblaster.perspectives.braille.mapping.elements.Range;import org.brailleblaster.perspectives.braille.mapping.elements.SectionElement; import org.brailleblaster.perspectives.braille.mapping.elements.TextMapElement;
@@ -66,13 +73,7 @@import org.brailleblaster.perspectives.braille.spellcheck.SpellCheckManager;
import org.brailleblaster.perspectives.braille.stylepanel.StyleManager; import org.brailleblaster.perspectives.braille.stylers.BoxlineHandler;-import org.brailleblaster.perspectives.braille.stylers.InsertElementHandler; -import org.brailleblaster.perspectives.braille.stylers.RemoveElementHandler;
-import org.brailleblaster.perspectives.braille.stylers.SplitElementHandler; import org.brailleblaster.perspectives.braille.stylers.HideActionHandler; -import org.brailleblaster.perspectives.braille.stylers.StyleHandler; -import org.brailleblaster.perspectives.braille.stylers.TextUpdateHandler; -import org.brailleblaster.perspectives.braille.stylers.WhiteSpaceHandler; import org.brailleblaster.search.*; import org.brailleblaster.perspectives.braille.viewInitializer.ViewFactory;import org.brailleblaster.perspectives.braille.viewInitializer.ViewInitializer;
@@ -91,7 +92,6 @@ import org.brailleblaster.wordprocessor.BBStatusBar; import org.brailleblaster.wordprocessor.FontManager; import org.brailleblaster.wordprocessor.WPManager; - import org.eclipse.swt.SWT; import org.eclipse.swt.custom.SashForm; import org.eclipse.swt.custom.StyledText; @@ -123,13 +123,14 @@ private FontManager fontManager; private boolean simBrailleDisplayed; private MapList list; - private QueueManager queueManager; + private EventQueue undoQueue, redoQueue; SearchDialog srch = null; //Constructor that sets things up for a new document. public Manager(WPManager wp, String docName) { super(wp); - queueManager = new QueueManager(); + undoQueue = new UndoQueue(); + redoQueue = new RedoQueue(); simBrailleDisplayed = loadSimBrailleProperty(); fontManager = new FontManager(this); styles = new BBSemanticsTable(BBIni.getDefaultConfigFile()); @@ -152,7 +153,7 @@ document = new BrailleDocument(this, styles); pb = new BBProgressBar(wp.getShell()); fontManager.setFontWidth(simBrailleDisplayed); -// srch = new SearchDialog(wp.getShell(), SWT.NONE, this); + srch = new SearchDialog(wp.getShell(), SWT.NONE, this); if(docName != null) openDocument(docName); else { @@ -166,8 +167,10 @@ else { arch = ArchiverFactory.getArchive( templateFile, false);vi = ViewFactory.createUpdater(arch, document, text, braille, treeView);
+ //list = vi.getList(this); resetConfiguations(); initializeAllViews(docName, templateFile, null); + //formatTemplateDocument(); setTabTitle(docName); } } @@ -178,7 +181,8 @@ public Manager(WPManager wp, Document doc, TabItem item, Archiver arch){ super(wp); - queueManager = new QueueManager(); + undoQueue = new UndoQueue(); + redoQueue = new RedoQueue(); this.arch = arch; simBrailleDisplayed = loadSimBrailleProperty(); fontManager = new FontManager(this); @@ -261,10 +265,12 @@ PropertyFileManager pfm = BBIni.getPropertyFileManager(); String view = pfm.getProperty("editorView"); if(view != null){ - if(view.equals(text.getClass().getCanonicalName())) + if(view.equals(text.getClass().getCanonicalName())){ editorSash.setMaximizedControl(text.view); - else if(view.equals(braille.getClass().getCanonicalName())) + } + else if(view.equals(braille.getClass().getCanonicalName())){ editorSash.setMaximizedControl(braille.view); + } } } @@ -314,12 +320,7 @@ /////////////////////////////////////////////////////////////// // Opens the search/replace dialog. public void search() { - if (srch == null) { - srch = new SearchDialog(wp.getShell(), SWT.NONE, this); - srch.open(); - } else { - srch.openWithPreviousValues(); - } + srch.open(); } public void fileSave(){ @@ -405,6 +406,7 @@ else { System.out.println("The Document Base document tree is empty");logger.error("The Document Base document tree is null, the file failed to parse properly");
+ //workingFilePath = null; } } catch(Exception e){ @@ -430,7 +432,7 @@ case GET_CURRENT: handleGetCurrent(message); break; - case WHITESPACE_DELETION: + case TEXT_DELETION: handleTextDeletion(message); break; case UPDATE: @@ -442,6 +444,9 @@ case REMOVE_NODE: handleRemoveNode(message); break; + case REMOVE_MATHML: + handleRemoveMathML(message); + break; case UPDATE_STATUSBAR: handleUpdateStatusBar(message); break; @@ -508,8 +513,11 @@ if(secList.get(i).getParent().equals(e)){ if(secList.get(i).isVisible()) list.findTextMapElements(message); - else + else { secList.get(i).getList().findTextMapElements(message); + //list = vi.resetViews(i); + //list.findTextMapElements(message); + } } } } @@ -622,25 +630,150 @@ } private void handleTextDeletion(Message message){ - WhiteSpaceHandler wsp = new WhiteSpaceHandler(this, list); - wsp.removeWhitespace(message); + int brailleStart = 0; + list.checkList(); + if(list.size() > 0){ + int start = (Integer)message.getValue("offset"); + int index = list.findClosest(message, 0, list.size() - 1); + TextMapElement t = list.get(index); + if(start < t.start){ + if(index > 0){ + if(t.brailleList.size() > 0)+ brailleStart = t.brailleList.getFirst().start + (Integer)message.getValue("length");
+ } + else{ + brailleStart = 0; + } + } + else if(t.brailleList.size() > 0) + brailleStart = t.brailleList.getLast().end; ++ braille.removeWhitespace(brailleStart, (Integer)message.getValue("length"));
+ + if(start >= t.end && index != list.size() - 1 && list.size() > 1)+ list.shiftOffsetsFromIndex(index + 1, (Integer)message.getValue("length"), (Integer)message.getValue("length"), (Integer)message.getValue("offset")); + else if(index != list.size() -1 || (index == list.size() - 1 && start < t.start)) + list.shiftOffsetsFromIndex(index, (Integer)message.getValue("length"), (Integer)message.getValue("length"), (Integer)message.getValue("offset"));
+ } + else + braille.removeWhitespace(0, (Integer)message.getValue("length")); } private void handleUpdate(Message message){ - TextUpdateHandler tuh = new TextUpdateHandler(this, vi, list); - tuh.updateText(message); + message.put("selection", treeView.getSelection(list.getCurrent())); + if(list.getCurrent().isMathML()){+ handleRemoveMathML(Message.createRemoveMathMLMessage((Integer)message.getValue("offset"), list.getCurrent().end - list.getCurrent().start, list.getCurrent()));
+ message.put("diff", 0); + } + else { + document.updateDOM(list, message); + braille.updateBraille(list.getCurrent(), message); + text.reformatText(list.getCurrent().n, message, this); + list.updateOffsets(list.getCurrentIndex(), message); + list.checkList(); + } + arch.setDocumentEdited(true); } private void handleInsertNode(Message m){ if(m.getValue("split").equals(true)){ - SplitElementHandler splitter = new SplitElementHandler(this, vi, list); - splitter.splitElement(m); + splitElement(m); } else {- InsertElementHandler inserter = new InsertElementHandler(this, vi, list);
- inserter.insertElement(m); + if(m.getValue("atStart").equals(true)) + insertElementAtBeginning(m); + else + insertElementAtEnd(m); } } + + private void splitElement(Message m){ + int origPos =list.getCurrent().start; + int treeIndex = treeView.getBlockElementIndex(); ++ ArrayList<Integer> originalElements = list.findTextMapElementRange(list.getCurrentIndex(), (Element)list.getCurrent().parentElement(), true); + ArrayList<Element> els = document.splitElement(list, list.getCurrent(), m);
+ + int textStart = list.get(originalElements.get(0)).start;+ int textEnd = list.get(originalElements.get(originalElements.size() - 1)).end; + int brailleStart = list.get(originalElements.get(0)).brailleList.getFirst().start;
++ int brailleEnd = list.get(originalElements.get(originalElements.size() - 1)).brailleList.getLast().end;
+ + int currentIndex = list.getCurrentIndex(); + + for(int i = originalElements.size() - 1; i >= 0; i--){ + int pos = originalElements.get(i); + + if(pos < currentIndex){ + vi.remove(list, pos); + currentIndex--; + } + else if(pos >= currentIndex){ + vi.remove(list, pos); + } + } + + text.clearTextRange(textStart, textEnd - textStart); + braille.clearTextRange(brailleStart, brailleEnd - brailleStart);+ list.shiftOffsetsFromIndex(currentIndex, -(textEnd - textStart), -(brailleEnd - brailleStart), origPos);
+ + int firstElementIndex = currentIndex;+ currentIndex = insertElement(els.get(0), currentIndex, textStart, brailleStart) - 1;
+ + String insertionString = "";+ Styles style = styles.get(styles.getKeyFromAttribute(document.getParent(list.get(currentIndex).n, true)));
+ + if(style.contains(StylesType.linesBefore)){+ for(int i = 0; i < Integer.valueOf((String)style.get(StylesType.linesBefore)) + 1; i++){
+ insertionString += "\n"; + } + } + else if(style.contains(StylesType.linesAfter)){+ for(int i = 0; i < Integer.valueOf((String)style.get(StylesType.linesAfter)) + 1; i++){
+ insertionString += "\n"; + } + } + else { + insertionString = "\n"; + } + + text.insertText(list.get(currentIndex).end, insertionString);+ braille.insertText(list.get(currentIndex).brailleList.getLast().end, insertionString);
+ m.put("length", insertionString.length()); + + int secondElementIndex = currentIndex + 1;+ currentIndex = insertElement(els.get(1), currentIndex + 1, list.get(currentIndex).end + insertionString.length(), list.get(currentIndex).brailleList.getLast().end + insertionString.length());
++ list.shiftOffsetsFromIndex(currentIndex, list.get(currentIndex - 1).end - textStart, list.get(currentIndex - 1).brailleList.getLast().end - brailleStart, origPos);
++ treeView.split(Message.createSplitTreeMessage(firstElementIndex, secondElementIndex, currentIndex, treeIndex));
+ } ++ private int insertElement(Element e, int index, int start, int brailleStart){
+ int count = e.getChildCount(); + int currentIndex = index; + int currentStart = start; + int currentBrailleStart = brailleStart; + + for(int i = 0; i < count; i++){ + if(e.getChild(i) instanceof Text){ + text.insertText(vi,list, currentIndex, currentStart, e.getChild(i)); + currentStart = list.get(currentIndex).end; + i++;+ insertBraille((Element)e.getChild(i), currentIndex, currentBrailleStart);
+ currentBrailleStart = list.get(currentIndex).brailleList.getLast().end; + currentIndex++; + }+ else if(e.getChild(i) instanceof Element && !((Element)e.getChild(i)).getLocalName().equals("brl")){ + currentIndex = insertElement((Element)e.getChild(i), currentIndex, currentStart, currentBrailleStart);
+ currentStart = list.get(currentIndex - 1).end;+ currentBrailleStart = list.get(currentIndex - 1).brailleList.getLast().end;
+ } + } + + return currentIndex; + } public void insertBraille(Element e, int index, int brailleStart){ int count = e.getChildCount(); @@ -652,23 +785,98 @@ } } } + + private void insertElementAtBeginning(Message m){ + int origPos = list.getCurrent().start; + if(list.getCurrentIndex() > 0 && list.getCurrent().start != 0)+ document.insertEmptyTextNode(vi, list, list.getCurrent(), list.getCurrent().start - 1, list.getCurrent().brailleList.getFirst().start - 1,list.getCurrentIndex(),(String) m.getValue("elementName"));
+ else+ document.insertEmptyTextNode(vi, list, list.getCurrent(), list.getCurrent().start, list.getCurrent().brailleList.getFirst().start, list.getCurrentIndex(),(String) m.getValue("elementName"));
+ + if(list.size() - 1 != list.getCurrentIndex() - 1){ + if(list.getCurrentIndex() == 0) + list.shiftOffsetsFromIndex(list.getCurrentIndex() + 1, 1, 1, origPos); + else + list.shiftOffsetsFromIndex(list.getCurrentIndex(), 1, 1, origPos); + } + int index = treeView.getSelectionIndex(); + + m.put("length", 1); + m.put("newBrailleLength", 1); + m.put("brailleLength", 0); ++ braille.insertLineBreak(list.getCurrent().brailleList.getFirst().start - 1);
+ + treeView.newTreeItem(list.get(list.getCurrentIndex()), index, 0); + } + + private void insertElementAtEnd(Message m){ + int origPos = list.getCurrent().start;+ document.insertEmptyTextNode(vi, list, list.getCurrent(), list.getCurrent().end + 1, list.getCurrent().brailleList.getLast().end + 1, list.getCurrentIndex() + 1,(String) m.getValue("elementName"));
+ if(list.size() - 1 != list.getCurrentIndex() + 1) + list.shiftOffsetsFromIndex(list.getCurrentIndex() + 2, 1, 1, origPos); + + int index = treeView.getSelectionIndex(); + + m.put("length", 1); + m.put("newBrailleLength", 1); + m.put("brailleLength", 0); + + braille.insertLineBreak(list.getCurrent().brailleList.getLast().end); + treeView.newTreeItem(list.get(list.getCurrentIndex() + 1), index, 1); + } public void insertTranscriberNote(){ text.update(false);ArrayList<Integer>posList = list.findTextMapElementRange(list.getCurrentIndex(), (Element)list.getCurrent().n.getParent(), true);
- if (arch.getCurrentConfig().equals("epub.cfg")) + if (arch.getCurrentConfig().equals("epub.cfg")){text.insertNewNode(list.get(posList.get(posList.size() - 1)).end,"aside");
- else + } + else{text.insertNewNode(list.get(posList.get(posList.size() - 1)).end,"prodnote");
+ } - text.refreshStyle(list.getCurrent()); - braille.refreshStyle(list.getCurrent()); + Styles style = styles.get("trnote");+ Message styleMessage = Message.createUpdateStyleMessage(style, false, false);
+ dispatch(styleMessage); } private void handleRemoveNode(Message message){ - RemoveElementHandler er = new RemoveElementHandler(this, vi, list); - er.removeNode(message); + int index = (Integer)message.getValue("index"); + treeView.removeItem(list.get(index), message); + document.updateDOM(list, message); + list.get(index).brailleList.clear(); + vi.remove(list, index); + //list.remove(index); + + if(list.size() == 0){ + text.removeListeners(); + braille.removeListeners(); + treeView.removeListeners(); + list.clearList(); + text.view.setEditable(false); + } + } + + private void handleRemoveMathML(Message m){ + TextMapElement t = (TextMapElement)m.getValue("TextMapElement"); + document.updateDOM(list, m); + braille.removeMathML(t); + text.removeMathML(m); + treeView.removeMathML(t); + int index = list.indexOf(t); + list.updateOffsets(index, m); + vi.remove(list, index); + //list.remove(t); + + if(list.size() == 0){ + text.removeListeners(); + braille.removeListeners(); + treeView.removeListeners(); + list.clearList(); + text.view.setEditable(false); + } } private void handleUpdateStatusBar(Message message){ @@ -690,6 +898,23 @@ else braille.positionScrollbar(text.view.getTopIndex()); } + + /*** + * Get parent style of the current TextMapElement + * @param current + * @param message + * @return + */ + private Element parentStyle(TextMapElement current, Message message) { + Element parent;+ if(current instanceof PageMapElement || current instanceof BrlOnlyMapElement)
+ parent = current.parentElement(); + else + parent = document.getParent(current.n, true); ++ message.put("previousStyle", styles.get(styles.getKeyFromAttribute(parent)));
+ return parent; + } /*** * Handle style for all cases @@ -699,18 +924,204 @@ if (document.getDOM() != null && text.view.getText().length() > 0) { containerSash.setRedraw(false); if(message.getValue("isBoxline").equals(true)){ - BoxlineHandler bxh = new BoxlineHandler(this, vi ,list); - bxh.handleBoxline(message); + if(message.getValue("multiSelect").equals(false)) + handleSingleBoxLine(message); + else + handleMultiBoxLine(message); } else{ - StyleHandler sh = new StyleHandler(this, vi, list); - sh.updateStyle(message); + if(message.getValue("multiSelect").equals(false)) + handleStyleSingleSelected(message); + else + handleStyleMultiSelected(message); } containerSash.setRedraw(true); } else notify(lh.localValue("nothingToApply")); } + + /*** + * Handle style if user just move cursor+ * @param message: Message object passed containing information from style table manager
+ */ + private void handleStyleSingleSelected(Message message) { + Element parent = parentStyle(list.getCurrent(), message); + document.changeSemanticAction(message, parent);+ ArrayList<TextMapElement> itemList = list.findTextMapElements(list.getCurrentIndex(), parent, true);
+ adjustStyle(itemList, message); + } + + /*** + * Apply styles to selected text for multiple elements+ * @param start: starting offset of highlighted text used to find first block element + * @param end: end position of highlighted text used to find last block element + * @param message: Message object passed containing information from style table manager
+ */ + private void handleStyleMultiSelected(Message message){ + + int start=text.getSelectedText()[0]; + int end=text.getSelectedText()[1]; + + Set<TextMapElement> itemSet = getElementSelected(start, end); + Iterator<TextMapElement> itr = itemSet.iterator(); + ArrayList<Element>parents = new ArrayList<Element>(); + + while (itr.hasNext()) { + TextMapElement tempElement= itr.next();+ if( (!((tempElement instanceof BrlOnlyMapElement) || (tempElement instanceof PageMapElement)))){ + Message styleMessage = Message.createUpdateStyleMessage((Styles)message.getValue("Style"), (Boolean)message.getValue("multiSelect"), (Boolean)message.getValue("isBoxline"));
+ Element parent = parentStyle(tempElement, styleMessage); + parents.add(parent); + document.changeSemanticAction(message, parent);+ ArrayList<TextMapElement> itemList = list.findTextMapElements(list.getNodeIndex(tempElement), parent, true);
+ adjustStyle( itemList,styleMessage); + } + } + } + ++ /** Prepares object needed by boxline handler to create boxline around a single element + * @param message: Message object passed containing information from style table manager
+ */ + private void handleSingleBoxLine(Message message){ + Element parent = parentStyle(list.getCurrent(), message); + ArrayList<Element>parents = new ArrayList<Element>(); + parents.add(parent);+ ArrayList<TextMapElement> itemList = list.findTextMapElements(list.getCurrentIndex(), parent, true);
+ + if(((Styles)message.getValue("Style")).getName().equals("boxline")){ + boolean invalid = false; + for(int i = 0; i < itemList.size() && !invalid; i++){ + if(itemList.get(i) instanceof PageMapElement) + invalid = true; + } + if(!invalid){ + adjustStyle(itemList, message); + BoxlineHandler bxh = new BoxlineHandler(this, list, vi); + bxh.createBoxline(parents, message, itemList); + } + else + notify(lh.localValue("invalidBoxline.containsPage")); + } + else { + adjustStyle(itemList, message);+ TextMapElement box = list.findJoiningBoxline((BrlOnlyMapElement)itemList.get(0));
+ if(box != null){ + if(list.indexOf(box) < list.indexOf(itemList.get(0))) + itemList.add(0, box); + else + itemList.add(box); + } + + BoxlineHandler bxh = new BoxlineHandler(this, list, vi); + bxh.removeSingleBoxline(parent, itemList); + + if(list.getCurrentIndex() > list.size())+ dispatch(Message.createSetCurrentMessage(Sender.TEXT, list.get(list.size() - 1).start, false));
+ else if(list.size() > 0)+ dispatch(Message.createSetCurrentMessage(Sender.TEXT, list.get(list.getCurrentIndex()).start, false));
+ } + } ++ /** Prepares object needed by boxline handler to create boxline around a multiple elements + * @param message: Message object passed containing information from style table manager
+ */ + private void handleMultiBoxLine(Message message){ + int start=text.getSelectedText()[0]; + int end=text.getSelectedText()[1]; + + Set<TextMapElement> itemSet = getElementSelected(start, end); + Iterator<TextMapElement> itr = itemSet.iterator(); + ArrayList<Element>parents = new ArrayList<Element>(); + ArrayList<TextMapElement>itemList = new ArrayList<TextMapElement>(); + + boolean invalid = false; + + while(itr.hasNext() && !invalid){ + TextMapElement tempElement= itr.next(); + if(tempElement instanceof BrlOnlyMapElement){+ BrlOnlyMapElement b = list.findJoiningBoxline((BrlOnlyMapElement)tempElement); + if((b == null && !tempElement.parentElement().getAttributeValue("semantics").contains("middleBox") && !tempElement.parentElement().getAttributeValue("semantics").contains("bottomBox") )
+ || (b != null && (b.start > end || b.end < start))){ + invalid = true; + notify(lh.localValue("invalidBoxline.incorrectSelection")); + break; + } + } + Element parent = parentStyle(tempElement, message);+ itemList.addAll(list.findTextMapElements(list.getNodeIndex(tempElement), parent, true));
+ parents.add(parent); + } + + for(int i = 0; i < itemList.size() && !invalid; i++){ + if(itemList.get(i) instanceof PageMapElement){ + invalid = true; + notify(lh.localValue("invalidBoxline.containsPage")); + } + } + + if(!invalid){ + if(((Styles)message.getValue("Style")).getName().equals("boxline")){ + adjustStyle(itemList, message); + BoxlineHandler bxh = new BoxlineHandler(this, list, vi); + bxh.createBoxline(parents, message, itemList); + } + else { + BoxlineHandler bxh = new BoxlineHandler(this, list, vi); + bxh.removeMultiBoxline(itemList); + if(list.getCurrentIndex() > list.size())+ dispatch(Message.createSetCurrentMessage(Sender.TEXT, list.get(list.size() - 1).start, false));
+ else if(list.size() > 0)+ dispatch(Message.createSetCurrentMessage(Sender.TEXT, list.get(list.getCurrentIndex()).start, false));
+ + dispatch(Message.createUpdateCursorsMessage(Sender.TREE)); + } + } + } + + /*** + * Adjust style of elements in the list base on previous and next element + * @param itemList : all selected items which we want style to be applied + * @param message : passing information regarding styles + */+ private void adjustStyle(ArrayList<TextMapElement> itemList, Message message) {
+ int start = list.indexOf(itemList.get(0)); + int end = list.indexOf(itemList.get(itemList.size() - 1)); + int origPos = list.get(list.getNodeIndex(itemList.get(0))).start; + if (start > 0) { + message.put("prev", list.get(start - 1).end); + message.put("braillePrev", + list.get(start - 1).brailleList.getLast().end); + } else { + message.put("prev", -1); + message.put("braillePrev", -1); + } + + if (end < list.size() - 1) { + message.put("next", list.get(end + 1).start); + message.put("brailleNext", + list.get(end + 1).brailleList.getFirst().start); + } else { + message.put("next", -1); + message.put("brailleNext", -1); + } + + text.adjustStyle(message, itemList); + braille.adjustStyle(message, itemList); + + if (message.contains("linesBeforeOffset")) + list.shiftOffsetsFromIndex(start, + (Integer) message.getValue("linesBeforeOffset"), + (Integer) message.getValue("linesBeforeOffset"), origPos); + if (message.contains("linesAfterOffset") && list.size() > 1 + && end < list.size() - 1) + list.shiftOffsetsFromIndex(end + 1, + (Integer) message.getValue("linesAfterOffset"), + (Integer) message.getValue("linesAfterOffset"), origPos); + + treeView.adjustItemStyle(list.getCurrent()); + } public void saveAs(){ String filePath; @@ -831,8 +1242,9 @@ } public void printPreview(){ - if(braille.view.getCharCount() > 0) + if(braille.view.getCharCount() > 0){ new PrintPreview(this.getDisplay(), document, this); + } }private void setCurrentOnRefresh(Sender sender, int offset, boolean isBraille){
@@ -944,6 +1356,8 @@ if(index != -1) vi.bufferViews(index); + //if(arch.getOrigDocPath() == null && list.size() == 0) + // formatTemplateDocument(); } catch (IOException e) {new Notify("An error occurred while refreshing the document. Please save your work and try again.");
@@ -960,11 +1374,12 @@ public void toggleAttributeEditor(){ if(!sm.panelIsVisible()){ - if(list.empty()) - sm.displayTable(null); - else + if(list.size() == 0){ + sm.displayTable(null); + } + else { sm.displayTable(list.getCurrent()); - + } setTabList(); PropertyFileManager pfm = BBIni.getPropertyFileManager(); String weight = pfm.getProperty("stylePanelWeight"); @@ -1028,7 +1443,7 @@ } public void hide(){ - HideActionHandler h = new HideActionHandler(this, vi, list); + HideActionHandler h = new HideActionHandler(this, list, vi); h.hideText(); } @@ -1079,7 +1494,7 @@ } public TextMapElement getNext(){ - if(!list.empty() && list.getCurrentIndex() <= list.size() - 1) + if(list.size() > 0 && list.getCurrentIndex() <= list.size() - 1) return list.get(list.getCurrentIndex() + 1); else return null; @@ -1100,14 +1515,13 @@ else return null; } - /*** * Return all elements that selected in text * @param start :start location of where text selected * @param end: where selection ended * @return: Set of all element where in selection */ - public Set<TextMapElement> getElementInSelectedRange(int start, int end) { + public Set<TextMapElement> getElementSelected(int start, int end) {Set<TextMapElement> elementSelectedSet = new LinkedHashSet<TextMapElement>();
Set<Element> parentElement = new LinkedHashSet<Element>(); @@ -1125,7 +1539,8 @@ j=t.end+1; } - else { + else + { j=j+1; } } @@ -1456,30 +1871,25 @@ } public void addUndoEvent(EventFrame f){ - queueManager.addUndoEvent(f); - } - - public void addRedoEvent(EventFrame f){ - queueManager.addRedoEvent(f); + undoQueue.add(f); } public void undo(){ - queueManager.undo(vi, document, list, this); + EventFrame f = undoQueue.popEvent(vi, document, list, this); + if(f != null) + redoQueue.add(f); } public void redo(){ - queueManager.redo(vi, document, list, this); - } - - public EventFrame peekUndoEvent(){ - return queueManager.peekUndoEvent(); + redoQueue.popEvent(vi, document, list, this); } /** Creates a Notify class alert box if debugging is not active* @param notify : String to be used in an alert box, should already be localized
*/ - public void notify(String notify){ + private void notify(String notify){ if(!BBIni.debugging()) new Notify(notify); } + } =======================================--- /src/main/org/brailleblaster/perspectives/braille/document/BrailleDocument.java Wed Jan 7 21:10:16 2015 UTC +++ /src/main/org/brailleblaster/perspectives/braille/document/BrailleDocument.java Mon Feb 2 17:23:00 2015 UTC
@@ -12,7 +12,6 @@ import nu.xom.Element; import nu.xom.Elements; import nu.xom.Node; -import nu.xom.Nodes; import nu.xom.ParsingException; import nu.xom.Text; @@ -59,7 +58,10 @@ updateNode(list, message); break; case REMOVE_NODE: - removeNode(list, message); + removeNode(list.get((Integer)message.getValue("index")), message); + break; + case REMOVE_MATHML:+ removeMathML((TextMapElement)message.getValue("TextMapElement"), message);
break; default: System.out.println("No available operations for this message type"); @@ -98,8 +100,8 @@ message.put("brailleLength", total); }- /** Inserts an Element into the DOM. This is used for inserting transcribers notes, paragraphs when a user hits enter, etc.
- * @param vi : View Initializer managing segments of a DOM+ /** Inserts an empty text node into the DOM. This is used for inserting trasncribes notes, paragraphs when a user hits enter, etc.
+ * @param vi : View Intializer managing segments of a DOM * @param list : maplist currently visible in the views * @param current : element used to determine insertion point in DOM* @param textOffset : position in text view for start and end of text element inserted
@@ -107,16 +109,18 @@ * @param index : insertion index in maplist * @param elem : Name of element to insert */- public void insertElement(ViewInitializer vi, MapList list, TextMapElement current, int textOffset, int brailleOffset, int index,String elem){ + public void insertEmptyTextNode(ViewInitializer vi, MapList list, TextMapElement current, int textOffset, int brailleOffset, int index,String elem){
String type = this.semHandler.getDefault(elem); Element p = makeElement(elem, "semantics", "style," + type); //Add new attribute for epub aside and for nimas prodnoteif ((elem.equalsIgnoreCase("prodnote") )||( elem.equalsIgnoreCase("aside"))){
p.addAttribute(new Attribute("render", "optional")); + p.addAttribute(new Attribute("showin", "bxx")); + p.addAttribute(new Attribute("class", "utd-trnote")); + } - p.appendChild(new Text("")); Element parent = current.parentElement(); @@ -136,19 +140,14 @@ parent.insertChild(p, nodeIndex + 1); - Element brl = appendBRLNode(p);- TextMapElement t = new TextMapElement(textOffset, textOffset, p.getChild(0)); - t.brailleList.add(new BrailleMapElement(brailleOffset, brailleOffset, brl.getChild(0)));
- vi.addElementToSection(list, t, index); - } - - private Element appendBRLNode(Element e){+ vi.addElementToSection(list, new TextMapElement(textOffset, textOffset, p.getChild(0)), index); + //list.add(index, new TextMapElement(textOffset, textOffset, p.getChild(0)));
+ Element brl = new Element("brl"); brl.appendChild(new Text("")); - e.appendChild(brl); + p.appendChild(brl); addNamespace(brl); - - return brl;+ list.get(index).brailleList.add(new BrailleMapElement(brailleOffset, brailleOffset, brl.getChild(0)));
} /** Updates the text of a given text node prior to translation @@ -189,7 +188,7 @@ Element child = (Element)t.brailleList.getFirst().n.getParent(); while(!child.getParent().equals(parent)){ child = (Element)child.getParent(); - } + }; parent.replaceChild(child, e); t.brailleList.clear(); @@ -297,43 +296,21 @@ m.put("brailleLength", 0); m.put("newBrailleLength", insertionString.length()); } - - private void removeNode(MapList list, Message message){ - int index = (Integer)message.getValue("index"); - if(list.get(index).isMathML()) - removeMathML(list.get(index), message); - else if(message.contains("element")) - removeElement(message); - else - removeNode(list.get((Integer)message.getValue("index"))); - } - - private void removeElement(Message m){ - Element e = (Element)m.getValue("element"); - e.getParent().removeChild(e); - } -- /** Removes a node from the DOM, checks whether other children exists, if not the entire element is removed
- * @param t : TextMapElement containing node to remove - * @param message : message to put element information - */ - private void removeNode(TextMapElement t){ - Element e = (Element)t.brailleList.getFirst().n.getParent(); - t.parentElement().removeChild(e); - t.parentElement().removeChild(t.n); - } /** Removes MathML from DOM - * @param t : TextMapElement to remove + * @param t : TextMapElemetn to remove * @param m : message to contain offset information */ private void removeMathML(TextMapElement t, Message m){int length = t.brailleList.getLast().end - t.brailleList.getFirst().start;
- Nodes nodes = (Nodes)m.getValue("nodes"); - Element parent = (Element)t.parentElement(); - while(nodes.size() > 0) - parent.removeChild(nodes.remove(0)); + Element parent = t.parentElement(); + int index = parent.indexOf(t.n); + + parent.removeChild(index);+ while(index < parent.getChildCount() && parent.getChild(index) instanceof Element && ((Element)parent.getChild(index)).getLocalName().equals("brl")){
+ parent.removeChild(index); + } if(parent.getChildElements().size() == 0) parent.getParent().removeChild(parent); @@ -459,11 +436,12 @@ outlength[0] = text.length() * 10; String semPath; - if(dm.getWorkingPath() == null) + if(dm.getWorkingPath() == null){semPath = BBIni.getTempFilesPath() + BBIni.getFileSep() + "outFile.utd";
- else + } + else {semPath = BBIni.getTempFilesPath() + BBIni.getFileSep() + fu.getFileName(dm.getWorkingPath()) + ".xml";
- + }String configSettings = "formatFor utd\n mode notUC\n printPages no\n" + semHandler.getSemanticsConfigSetting(semPath); if(lutdml.translateString(preferenceFile, inbuffer, outbuffer, outlength, logFile, configSettings + sm.getSettings(), 0)){
return outlength[0]; @@ -514,12 +492,36 @@ d = getXML(xml); return d; } ++ /** Removes a node from the DOM, checks whether other children exists, if not the entire element is removed
+ * @param t : TextMapElement containing node to remove + * @param message : message to put element information + */ + private void removeNode(TextMapElement t, Message message){+ if(hasNonBrailleChildren(t.parentElement()) && !(t.n instanceof Element)){
+ Element e = (Element)t.brailleList.getFirst().n.getParent(); + t.parentElement().removeChild(e); + t.parentElement().removeChild(t.n); + } + else { + Element parent = t.parentElement(); + while(!parent.getAttributeValue("semantics").contains("style")){ + if(((Element)parent.getParent()).getChildElements().size() <= 1) + parent = (Element)parent.getParent(); + else + break; + } + + message.put("element", parent); + parent.getParent().removeChild(parent); + } + } /** Checks if an element contains other elements other than brl * @param e : Element to check * @return true if non-braille children exist, false if not */ - public boolean hasNonBrailleChildren(Element e){ + private boolean hasNonBrailleChildren(Element e){ Elements els = e.getChildElements(); for(int i = 0; i <els.size(); i++){ if(!els.get(i).getLocalName().equals("brl")){ @@ -835,14 +837,17 @@ boxline.addAttribute(new Attribute("semantics","style,boxline")); for(int i = 0; i < parents.size(); i++){ Element parent = (Element)parents.get(i).getParent(); + // int index = parent.indexOf(parents.get(i)); if(!parents.contains(parent)) boxline.appendChild(parent.removeChild(parents.get(i))); } + //if(parent != null){ grandparent.insertChild(boxline, grandParentIndex); addNamespace(boxline); return boxline; + //} } return null; =======================================--- /src/main/org/brailleblaster/perspectives/braille/eventQueue/Event.java Mon Dec 22 15:26:49 2014 UTC +++ /src/main/org/brailleblaster/perspectives/braille/eventQueue/Event.java Mon Feb 2 17:23:00 2015 UTC
@@ -1,15 +1,43 @@ package org.brailleblaster.perspectives.braille.eventQueue; +import java.util.ArrayList; + +import nu.xom.Element; +import nu.xom.ParentNode; + public class Event { EventTypes eventType; + Element element; + int firstSectionIndex, listIndex, parentIndex, textOffset, brailleOffset; + ArrayList<Integer> treeIndexes; + ParentNode parent; - int textOffset, brailleOffset; - - public Event(EventTypes eventType, int textOffset, int brailleOffset){ - this.eventType = eventType; -+ public Event(EventTypes eventType, Element e, int firstSectionIndex, int listIndex, int textOffset, int brailleOffset, ArrayList<Integer> treeIndexes){
+ this.eventType = eventType; + this.element = (Element)e.copy(); + this.parent = e.getParent(); + this.parentIndex = parent.indexOf(e); + this.firstSectionIndex = firstSectionIndex; + this.listIndex = listIndex; this.textOffset = textOffset; this.brailleOffset = brailleOffset; + this.treeIndexes = treeIndexes; + } + + public Element getElement(){ + return element; + } + + public ParentNode getParent(){ + return parent; + } + + public int getParentIndex(){ + return parentIndex; + } + + public int getListIndex(){ + return listIndex; } public int getTextOffset(){ @@ -20,7 +48,11 @@ return brailleOffset; } - public EventTypes getEventType(){ - return eventType; + public ArrayList<Integer> getTreeIndex(){ + return treeIndexes; + } + + public int getFirstSectionIndex(){ + return firstSectionIndex; } } =======================================--- /src/main/org/brailleblaster/perspectives/braille/eventQueue/EventFrame.java Mon Jan 12 18:40:10 2015 UTC +++ /src/main/org/brailleblaster/perspectives/braille/eventQueue/EventFrame.java Mon Feb 2 17:23:00 2015 UTC
@@ -2,9 +2,9 @@ import java.util.ArrayList; + public class EventFrame { ArrayList<Event>eventList; - int sequenceId; public EventFrame(){ eventList = new ArrayList<Event>(); @@ -21,30 +21,4 @@ public Event get(int index){ return eventList.get(index); } - - public void setId(int sequenceId){ - this.sequenceId = sequenceId; - } - - public int getId(){ - return sequenceId; - } - - public Event peek(){ - if(!empty()) - return get(eventList.size() - 1); - else - return null; - } - - public Event pop(){ - if(!empty()) - return eventList.remove(eventList.size() - 1); - else - return null; - } - - public boolean empty(){ - return eventList.size() == 0; - } } =======================================--- /src/main/org/brailleblaster/perspectives/braille/eventQueue/EventQueue.java Thu Jan 8 14:10:27 2015 UTC +++ /src/main/org/brailleblaster/perspectives/braille/eventQueue/EventQueue.java Mon Feb 2 17:23:00 2015 UTC
@@ -2,8 +2,8 @@ import java.util.concurrent.LinkedBlockingDeque; +import org.brailleblaster.document.BBDocument; import org.brailleblaster.perspectives.braille.Manager; -import org.brailleblaster.perspectives.braille.document.BrailleDocument; import org.brailleblaster.perspectives.braille.mapping.maps.MapList;import org.brailleblaster.perspectives.braille.viewInitializer.ViewInitializer;
@@ -16,7 +16,7 @@ super(SIZE); }- public EventFrame popEvent(ViewInitializer vi, BrailleDocument doc, MapList list, Manager manager){ + public EventFrame popEvent(ViewInitializer vi, BBDocument doc, MapList list, Manager manager){
if(size() > 0){ EventFrame f = removeLast(); handleEvent(f, vi, doc, list, manager); @@ -26,26 +26,5 @@ return null; } - @Override - public boolean add(EventFrame f) { - if(size() == SIZE) - removeFirst(); - - return super.add(f); - } - - @Override - public EventFrame peek(){ - if(empty()) - return null; - else - return getLast(); - } - - public boolean empty(){ - return size() == 0; - } - -- protected abstract void handleEvent(EventFrame f, ViewInitializer vi, BrailleDocument doc, MapList list, Manager manager); + protected abstract void handleEvent(EventFrame f, ViewInitializer vi, BBDocument doc, MapList list, Manager manager);
} =======================================--- /src/main/org/brailleblaster/perspectives/braille/eventQueue/EventTypes.java Mon Dec 22 18:29:25 2014 UTC +++ /src/main/org/brailleblaster/perspectives/braille/eventQueue/EventTypes.java Mon Feb 2 17:23:00 2015 UTC
@@ -2,10 +2,7 @@ public enum EventTypes { Update, - Edit, - Whitespace, Delete, Hide, - Style_Change, Insert; } =======================================--- /src/main/org/brailleblaster/perspectives/braille/eventQueue/RedoQueue.java Tue Dec 30 20:13:40 2014 UTC +++ /src/main/org/brailleblaster/perspectives/braille/eventQueue/RedoQueue.java Mon Feb 2 17:23:00 2015 UTC
@@ -1,14 +1,9 @@ package org.brailleblaster.perspectives.braille.eventQueue; +import org.brailleblaster.document.BBDocument; import org.brailleblaster.perspectives.braille.Manager; -import org.brailleblaster.perspectives.braille.document.BrailleDocument; import org.brailleblaster.perspectives.braille.mapping.maps.MapList;-import org.brailleblaster.perspectives.braille.stylers.InsertElementHandler; -import org.brailleblaster.perspectives.braille.stylers.RemoveElementHandler;
import org.brailleblaster.perspectives.braille.stylers.HideActionHandler; -import org.brailleblaster.perspectives.braille.stylers.StyleHandler; -import org.brailleblaster.perspectives.braille.stylers.TextUpdateHandler; -import org.brailleblaster.perspectives.braille.stylers.WhiteSpaceHandler;import org.brailleblaster.perspectives.braille.viewInitializer.ViewInitializer;
public class RedoQueue extends EventQueue{ @@ -20,37 +15,19 @@ } @Override- protected void handleEvent(EventFrame frame, ViewInitializer vi, BrailleDocument doc, MapList list, Manager manager) {
- for(int i = 0; i < frame.size(); i++){ - Event event = frame.get(i);+ protected void handleEvent(EventFrame f, ViewInitializer vi, BBDocument doc, MapList list, Manager manager) {
+ for(int i = 0; i < f.size(); i++){ + Event event = f.get(i); switch(event.eventType){ - case Edit:- TextUpdateHandler editUpdater = new TextUpdateHandler(manager, vi, list);
- editUpdater.redoEdit(frame); - break; case Update: - TextUpdateHandler tuh = new TextUpdateHandler(manager, vi, list); - tuh.redoText(frame); break; case Insert:- InsertElementHandler inserter = new InsertElementHandler(manager, vi, list);
- inserter.redoInsert(frame); break; case Delete:- RemoveElementHandler remover = new RemoveElementHandler(manager, vi, list);
- remover.removeNode(frame); break; case Hide: - HideActionHandler h = new HideActionHandler(manager, vi, list); - h.hideText(frame); - break; - case Style_Change: - StyleHandler s = new StyleHandler(manager, vi, list); - s.redoStyle(frame); - break; - case Whitespace: - WhiteSpaceHandler wsh = new WhiteSpaceHandler(manager, list); - wsh.redoDelete(frame); + HideActionHandler h = new HideActionHandler(manager, list, vi); + h.hideText(event); break; default: break; =======================================--- /src/main/org/brailleblaster/perspectives/braille/eventQueue/UndoQueue.java Mon Jan 12 14:19:07 2015 UTC +++ /src/main/org/brailleblaster/perspectives/braille/eventQueue/UndoQueue.java Mon Feb 2 17:23:00 2015 UTC
@@ -1,55 +1,32 @@ package org.brailleblaster.perspectives.braille.eventQueue; +import org.brailleblaster.document.BBDocument; import org.brailleblaster.perspectives.braille.Manager; -import org.brailleblaster.perspectives.braille.document.BrailleDocument; import org.brailleblaster.perspectives.braille.mapping.maps.MapList;-import org.brailleblaster.perspectives.braille.stylers.InsertElementHandler; -import org.brailleblaster.perspectives.braille.stylers.RemoveElementHandler;
-import org.brailleblaster.perspectives.braille.stylers.StyleHandler; -import org.brailleblaster.perspectives.braille.stylers.TextUpdateHandler; -import org.brailleblaster.perspectives.braille.stylers.WhiteSpaceHandler; +import org.brailleblaster.perspectives.braille.stylers.ElementInserter;import org.brailleblaster.perspectives.braille.viewInitializer.ViewInitializer;
public class UndoQueue extends EventQueue { private static final long serialVersionUID = 1658714661481118195L; - + public UndoQueue(){ - super(); + super(); } @Override- protected void handleEvent(EventFrame frame, ViewInitializer vi, BrailleDocument doc, MapList list, Manager manager){
- while(!frame.empty()){ - Event event = frame.get(frame.size() - 1);+ protected void handleEvent(EventFrame f, ViewInitializer vi, BBDocument doc, MapList list, Manager manager){
+ for(int i = f.size() - 1; i >= 0; i--){ + Event event = f.get(i); switch(event.eventType){ - case Edit:- TextUpdateHandler editHandler = new TextUpdateHandler(manager, vi, list);
- editHandler.undoEdit(frame); - break; case Update: - TextUpdateHandler tuh = new TextUpdateHandler(manager, vi, list); - tuh.undoText(frame); break; case Insert:- RemoveElementHandler remover = new RemoveElementHandler(manager, vi, list);
- remover.undoInsert(frame); - break; - case Delete:- InsertElementHandler inserter = new InsertElementHandler(manager, vi, list);
- inserter.insertElement(frame); break; case Hide: - InsertElementHandler ei = new InsertElementHandler(manager, vi, list); - ei.resetElement(frame); - break; - case Style_Change: - StyleHandler sh = new StyleHandler(manager, vi, list); - sh.undoStyle(frame); - break; - case Whitespace: - WhiteSpaceHandler wsh = new WhiteSpaceHandler(manager, list); - wsh.UndoDelete(frame); + case Delete: + ElementInserter es = new ElementInserter(vi, doc, list, manager); + es.resetElement(event); break; default: break; =======================================--- /src/main/org/brailleblaster/perspectives/braille/mapping/maps/MapList.java Fri Dec 12 17:44:51 2014 UTC +++ /src/main/org/brailleblaster/perspectives/braille/mapping/maps/MapList.java Mon Feb 2 17:23:00 2015 UTC
@@ -236,7 +236,7 @@ }- public void shiftOffsetsFromIndex(int index, int offset, int brailleOffset){ + public void shiftOffsetsFromIndex(int index, int offset, int brailleOffset, int origPos){
UpdaterThread [] arr = new UpdaterThread[PROCESSORS]; int length = (this.size() - index) / PROCESSORS; int start = index; @@ -253,7 +253,7 @@ for (int i = 0; i < arr.length; i++) { try { - arr[i].join(); + arr[i].join(); } catch (InterruptedException e) { e.printStackTrace(); } @@ -369,7 +369,7 @@ dm.dispatch(message); return this.currentIndex; } - else if(empty()){ + else if(this.size() == 0){ return -1; } else { @@ -717,8 +717,4 @@ return false; } - - public boolean empty(){ - return size() == 0; - } } =======================================--- /src/main/org/brailleblaster/perspectives/braille/messages/BBEvent.java Tue Dec 30 20:13:40 2014 UTC +++ /src/main/org/brailleblaster/perspectives/braille/messages/BBEvent.java Mon Feb 2 17:23:00 2015 UTC
@@ -33,8 +33,7 @@ public enum BBEvent { INCREMENT, DECREMENT, - WHITESPACE_DELETION, - EDIT, + TEXT_DELETION, UPDATE, INSERT_NODE, REMOVE_NODE, @@ -48,5 +47,6 @@ UPDATE_SCROLLBAR, UPDATE_STYLE, ADJUST_RANGE, + REMOVE_MATHML, SPLIT_TREE; } =======================================--- /src/main/org/brailleblaster/perspectives/braille/messages/Message.java Wed Jan 7 21:10:16 2015 UTC +++ /src/main/org/brailleblaster/perspectives/braille/messages/Message.java Mon Feb 2 17:23:00 2015 UTC
@@ -35,7 +35,6 @@import org.brailleblaster.perspectives.braille.document.BBSemanticsTable.Styles; import org.brailleblaster.perspectives.braille.mapping.elements.TextMapElement;
-import org.eclipse.swt.custom.ExtendedModifyEvent; import nu.xom.Text; @@ -157,15 +156,23 @@ return m; }- public static Message createTextDeletionMessage(int offset, int length, String replacedText, boolean update){
- Message m = new Message(BBEvent.WHITESPACE_DELETION);+ public static Message createTextDeletionMessage(int offset, int length, boolean update){
+ Message m = new Message(BBEvent.TEXT_DELETION); m.put("offset", offset); m.put("length", length); - m.put("replacedText", replacedText); m.put("update", update); return m; } ++ public static Message createRemoveMathMLMessage(int offset, int length, TextMapElement t){
+ Message m = new Message(BBEvent.REMOVE_MATHML); + m.put("start", offset); + m.put("length", length); + m.put("TextMapElement", t); + + return m; + }public static Message createSplitTreeMessage(int firstElementIndex, int secondElementIndex, int currentIndex, int treeIndex){
Message m = new Message(BBEvent.SPLIT_TREE); @@ -181,7 +188,7 @@ * Create a Message object base on multiple selection is true or false * @param style: Style to add, remove, or adjust* @param multiSelect: signifies whether multiple elements have been selected - * @param isBoxline: signifies whether selection is adding or removing a boxline, since boxline are handled differently than other styles + * @param isBoxline: signifies whether selection is addining or removing a boxline, since boxline are handled differently than other styles
* @return */public static Message createUpdateStyleMessage(Styles style, boolean multiSelect, boolean isBoxline){
@@ -191,13 +198,6 @@ m.put("isBoxline", isBoxline); return m; } - - public static Message createEditEventMesag(ExtendedModifyEvent e){ - Message m = new Message(BBEvent.EDIT); - m.put("event", e); - - return m; - } public void put(String key, Object value){ args.put(key, value); =======================================--- /src/main/org/brailleblaster/perspectives/braille/stylers/BoxlineHandler.java Mon Dec 22 14:31:48 2014 UTC +++ /src/main/org/brailleblaster/perspectives/braille/stylers/BoxlineHandler.java Mon Feb 2 17:23:00 2015 UTC
@@ -1,23 +1,20 @@ package org.brailleblaster.perspectives.braille.stylers; import java.util.ArrayList; -import java.util.Iterator; -import java.util.Set; +import nu.xom.Attribute; import nu.xom.Document; import nu.xom.Element; import nu.xom.Elements; import nu.xom.Node; import nu.xom.Text; -import org.brailleblaster.localization.LocaleHandler; import org.brailleblaster.perspectives.braille.Manager; import org.brailleblaster.perspectives.braille.document.BBSemanticsTable;import org.brailleblaster.perspectives.braille.document.BBSemanticsTable.Styles; import org.brailleblaster.perspectives.braille.document.BBSemanticsTable.StylesType;
import org.brailleblaster.perspectives.braille.document.BrailleDocument;import org.brailleblaster.perspectives.braille.mapping.elements.BrlOnlyMapElement; -import org.brailleblaster.perspectives.braille.mapping.elements.PageMapElement; import org.brailleblaster.perspectives.braille.mapping.elements.TextMapElement;
import org.brailleblaster.perspectives.braille.mapping.maps.MapList; import org.brailleblaster.perspectives.braille.messages.Message; @@ -28,142 +25,32 @@ import org.brailleblaster.perspectives.braille.views.wp.BrailleView; import org.brailleblaster.perspectives.braille.views.wp.TextView; -public class BoxlineHandler extends Handler{ +public class BoxlineHandler { + private static final String BOXLINE = "boxline"; + private static final String FULLBOX = "fullBox"; + private static final String TOPBOX = "topBox"; + private static final String MIDDLEBOX = "middleBox"; + private static final String BOTTOMBOX = "bottomBox"; + + Manager manager; BrailleDocument document; BBSemanticsTable styles; BBTree treeView; TextView text; BrailleView braille; + MapList list; + ViewInitializer vi; - public BoxlineHandler(Manager manager, ViewInitializer vi, MapList list){ - super(manager, vi, list); - + public BoxlineHandler(Manager manager, MapList list, ViewInitializer vi){ + this.manager = manager; this.document = manager.getDocument(); this.styles = manager.getStyleTable(); this.text = manager.getText(); this.braille = manager.getBraille(); this.treeView = manager.getTreeView(); - } - - public void handleBoxline(Message message){ - if(message.getValue("multiSelect").equals(false)) - handleSingleBoxLine(message); - else - handleMultiBoxLine(message); - } -- /** Prepares object needed by boxline handler to create boxline around a single element - * @param message: Message object passed containing information from style table manager
- */ - private void handleSingleBoxLine(Message message){ - Element parent = parentStyle(list.getCurrent(), message); - ArrayList<Element>parents = new ArrayList<Element>(); - parents.add(parent);- ArrayList<TextMapElement> itemList = list.findTextMapElements(list.getCurrentIndex(), parent, true);
- - if(((Styles)message.getValue("Style")).getName().equals("boxline")) - createSingleBoxLine(itemList, parents, message); - else - removeSingleBoxLine(itemList, parent, message); - } -- private void createSingleBoxLine(ArrayList<TextMapElement> itemList, ArrayList<Element>parents, Message message){
- boolean invalid = false; - for(int i = 0; i < itemList.size() && !invalid; i++){ - if(itemList.get(i) instanceof PageMapElement) - invalid = true; - } - - if(!invalid){ - getBounds(itemList, message); - createBoxline(parents, message, itemList); - } - else{ - LocaleHandler lh = new LocaleHandler(); - manager.notify(lh.localValue("invalidBoxline.containsPage")); - } - } -- private void removeSingleBoxLine(ArrayList<TextMapElement> itemList, Element parent, Message message){
- getBounds(itemList, message);- TextMapElement box = list.findJoiningBoxline((BrlOnlyMapElement)itemList.get(0));
- if(box != null){ - if(list.indexOf(box) < list.indexOf(itemList.get(0))) - itemList.add(0, box); - else - itemList.add(box); - } - - removeSingleBoxline(parent, itemList); - - if(list.getCurrentIndex() > list.size())- manager.dispatch(Message.createSetCurrentMessage(Sender.TEXT, list.get(list.size() - 1).start, false));
- else if(list.size() > 0)- manager.dispatch(Message.createSetCurrentMessage(Sender.TEXT, list.get(list.getCurrentIndex()).start, false));
- } -- /** Prepares object needed by boxline handler to create boxline around a multiple elements - * @param message: Message object passed containing information from style table manager
- */ - private void handleMultiBoxLine(Message message){ - int start=text.getSelectedText()[0]; - int end=text.getSelectedText()[1]; -- Set<TextMapElement> itemSet = manager.getElementInSelectedRange(start, end);
- Iterator<TextMapElement> itr = itemSet.iterator(); - ArrayList<Element>parents = new ArrayList<Element>(); - ArrayList<TextMapElement>itemList = new ArrayList<TextMapElement>(); - - boolean invalid = false; - - while(itr.hasNext() && !invalid){ - TextMapElement tempElement= itr.next(); - if(tempElement instanceof BrlOnlyMapElement){- BrlOnlyMapElement b = list.findJoiningBoxline((BrlOnlyMapElement)tempElement); - if((b == null && !tempElement.parentElement().getAttributeValue(SEMANTICS).contains("middleBox") && !tempElement.parentElement().getAttributeValue(SEMANTICS).contains("bottomBox") )
- || (b != null && (b.start > end || b.end < start))){ - invalid = true; - LocaleHandler lh = new LocaleHandler(); - manager.notify(lh.localValue("invalidBoxline.incorrectSelection")); - break; - } - } - Element parent = parentStyle(tempElement, message);- itemList.addAll(list.findTextMapElements(list.getNodeIndex(tempElement), parent, true));
- parents.add(parent); - } - - for(int i = 0; i < itemList.size() && !invalid; i++){ - if(itemList.get(i) instanceof PageMapElement){ - invalid = true; - LocaleHandler lh = new LocaleHandler(); - manager.notify(lh.localValue("invalidBoxline.containsPage")); - } - } - - if(!invalid){ - if(((Styles)message.getValue("Style")).getName().equals("boxline")) - createMultipleBoxline(itemList, parents,message); - else - removeMultipleBoxlines(itemList); - } - } -- private void createMultipleBoxline(ArrayList<TextMapElement> itemList, ArrayList<Element> parents, Message message){
- getBounds(itemList, message); - createBoxline(parents, message, itemList); - } - - private void removeMultipleBoxlines(ArrayList<TextMapElement> itemList){ - removeMultiBoxline(itemList); - - if(list.getCurrentIndex() > list.size())- manager.dispatch(Message.createSetCurrentMessage(Sender.TEXT, list.get(list.size() - 1).start, false));
- else if(list.size() > 0)- manager.dispatch(Message.createSetCurrentMessage(Sender.TEXT, list.get(list.getCurrentIndex()).start, false));
- - manager.dispatch(Message.createUpdateCursorsMessage(Sender.TREE)); + this.list = list; + this.vi = vi; }/** Wraps a block level element in the appropriate tag then translates and adds boxline brl top and bottom nodes
@@ -171,7 +58,7 @@ * @param m: message passed to views containing offset positions * @param itemList: arraylist containing text nodes of the block element */- private void createBoxline(ArrayList<Element>parents, Message m, ArrayList<TextMapElement> itemList){ + public void createBoxline(ArrayList<Element>parents, Message m, ArrayList<TextMapElement> itemList){
Element wrapper = document.wrapElement(parents, BOXLINE); if(wrapper != null){ ArrayList<Element>sidebarList = findBoxlines(wrapper); @@ -198,7 +85,7 @@ Document doc = document.translateElements(elList); Element parent = (Element)doc.getChild(0); - String style = getSemanticAttribute(wrapper); + String style = getStyle(wrapper); Message m = new Message(null); if(style.equals(TOPBOX)) createFullBoxline(wrapper, parents, m, itemList); @@ -295,7 +182,7 @@ //set text text.insertText(start, list.get(startPos).getText() + "\n");braille.insertText(brailleStart, list.get(startPos).brailleList.getFirst().value() + "\n"); - list.shiftOffsetsFromIndex(startPos + 1, list.get(startPos).getText().length() + 1, list.get(startPos).brailleList.getFirst().value().length() + 1); + list.shiftOffsetsFromIndex(startPos + 1, list.get(startPos).getText().length() + 1, list.get(startPos).brailleList.getFirst().value().length() + 1, list.get(startPos + 1).start);
return startPos; } @@ -331,19 +218,19 @@ //set text text.insertText(end, "\n" + list.get(endPos).getText());braille.insertText(brailleEnd, "\n" + list.get(endPos).brailleList.getFirst().value()); - list.shiftOffsetsFromIndex(endPos + 1, list.get(endPos).getText().length() + 1, list.get(endPos).brailleList.getFirst().value().length() + 1); + list.shiftOffsetsFromIndex(endPos + 1, list.get(endPos).getText().length() + 1, list.get(endPos).brailleList.getFirst().value().length() + 1, list.get(endPos).start);
return endPos; } private void resetSidebars(ArrayList<Element> elList, Element parent){ while(elList.size() > 0){- if(getSemanticAttribute(parent.getChildElements().get(0)).equals(TOPBOX) || getSemanticAttribute(parent.getChildElements().get(0)).equals(BOXLINE)) + if(getStyle(parent.getChildElements().get(0)).equals(TOPBOX) || getStyle(parent.getChildElements().get(0)).equals(BOXLINE))
changeToFullBox(elList.get(0), parent.getChildElements().get(0));- else if(getSemanticAttribute(parent.getChildElements().get(0)).equals(BOTTOMBOX) || getSemanticAttribute(parent.getChildElements().get(0)).equals(MIDDLEBOX)) + else if(getStyle(parent.getChildElements().get(0)).equals(BOTTOMBOX) || getStyle(parent.getChildElements().get(0)).equals(MIDDLEBOX))
changeToHalfBox(elList.get(0), parent.getChildElements().get(0));- setStyle(elList.get(0), getSemanticAttribute(parent.getChildElements().get(0)));
+ setStyle(elList.get(0), getStyle(parent.getChildElements().get(0))); parent.removeChild(0); elList.remove(0); } @@ -386,7 +273,7 @@ } private void insertBoxLine(int index, Element box, Element brl){ - String style = getSemanticAttribute(list.get(index).parentElement()); + String style = getStyle(list.get(index).parentElement()); Styles firstStyle = styles.get(style); //inserted in DOM box.insertChild(brl, 0); @@ -411,7 +298,7 @@ //set text text.insertText(start, list.get(index).getText() + "\n");braille.insertText(brailleStart, list.get(index).brailleList.getFirst().value() + "\n"); - list.shiftOffsetsFromIndex(index + 1, list.get(index).getText().length() + 1, list.get(index).brailleList.getFirst().value().length() + 1); + list.shiftOffsetsFromIndex(index + 1, list.get(index).getText().length() + 1, list.get(index).brailleList.getFirst().value().length() + 1, list.get(index + 1).start);
} private void replaceBoxLine(Element brl, Element replacement){ @@ -423,7 +310,7 @@braille.replaceTextRange(list.get(index).brailleList.getFirst().start, list.get(index).brailleList.getLast().end - list.get(index).brailleList.getFirst().start, t.getValue());
if(length > 0) - list.shiftOffsetsFromIndex(index + 1, length, length); + list.shiftOffsetsFromIndex(index + 1, length, length, 0); } private ArrayList<Element> findBoxlines(Element e){ @@ -453,7 +340,7 @@ * @param boxline : Element wrapping content and representing a boxline * @param itemList : List containing opening and closing boxline */- private void removeSingleBoxline(Element boxline, ArrayList<TextMapElement> itemList){ + public void removeSingleBoxline(Element boxline, ArrayList<TextMapElement> itemList){
ArrayList<Element>sidebarList = findBoxlines(boxline); removeBoxLine(boxline, itemList); @@ -468,7 +355,7 @@/** Handles deleting a boxline when text selection occurs and one or more boxlines may be selected * @param itemList : ItemList containing text map elements in selection collected via manager's getSelected method
*/ - private void removeMultiBoxline(ArrayList<TextMapElement> itemList){ + public void removeMultiBoxline(ArrayList<TextMapElement> itemList){ clearNonBrlElements(itemList);int start = itemList.get(0).parentElement().getParent().indexOf(itemList.get(0).parentElement());
@@ -486,14 +373,14 @@ while(itemList.size() > 0){ ArrayList<TextMapElement>boxline = new ArrayList<TextMapElement>();- if(getSemanticAttribute(itemList.get(0).parentElement()).equals(BOXLINE) || getSemanticAttribute(itemList.get(0).parentElement()).equals(TOPBOX) || getSemanticAttribute(itemList.get(0).parentElement()).equals(FULLBOX)){ + if(getStyle(itemList.get(0).parentElement()).equals(BOXLINE) || getStyle(itemList.get(0).parentElement()).equals(TOPBOX) || getStyle(itemList.get(0).parentElement()).equals(FULLBOX)){
int index = getMatchingParent(itemList, 0); boxline.add(itemList.get(0)); boxline.add(itemList.get(index)); itemList.remove(0); itemList.remove(index - 1); }- else if(getSemanticAttribute(itemList.get(0).parentElement()).equals(MIDDLEBOX) | | getSemanticAttribute(itemList.get(0).parentElement()).equals(BOTTOMBOX)){ + else if(getStyle(itemList.get(0).parentElement()).equals(MIDDLEBOX) || getStyle(itemList.get(0).parentElement()).equals(BOTTOMBOX)){
boxline.add(itemList.get(0)); itemList.remove(0); } @@ -517,12 +404,12 @@ }private void removeBoxLine(Element boxline, ArrayList<TextMapElement> itemList){
- String style = getSemanticAttribute(boxline); + String style = getStyle(boxline);if(style.equals(BOXLINE) || style.equals(TOPBOX) || style.equals(FULLBOX)){
Element parent = null; removeTopBoxline((BrlOnlyMapElement)itemList.get(0)); removeBottomBoxline((BrlOnlyMapElement)itemList.get(1));- if(isBoxLine((Element)boxline.getParent()) && getSemanticAttribute((Element)boxline.getParent()).equals(FULLBOX)){ + if(isBoxLine((Element)boxline.getParent()) && getStyle((Element)boxline.getParent()).equals(FULLBOX)){
if(nestedSidebarCount((Element)boxline.getParent()) == 1) parent = (Element)boxline.getParent(); } @@ -599,7 +486,7 @@ int index = list.indexOf(b); manager.getText().replaceTextRange(b.start, (b.end + 1) - b.start, "");manager.getBraille().replaceTextRange(b.brailleList.getFirst().start, (b.brailleList.getFirst().end + 1) - b.brailleList.getFirst().start, ""); - list.shiftOffsetsFromIndex(index, -((b.end + 1) - b.start), -((b.brailleList.getFirst().end + 1) - b.brailleList.getFirst().start)); + list.shiftOffsetsFromIndex(index, -((b.end + 1) - b.start), -((b.brailleList.getFirst().end + 1) - b.brailleList.getFirst().start), 0);
list.remove(index); } @@ -610,7 +497,7 @@ int index = list.indexOf(b);manager.getText().replaceTextRange(b.start - 1, b.end - (b.start - 1), ""); manager.getBraille().replaceTextRange(b.brailleList.getFirst().start - 1, b.brailleList.getFirst().end - (b.brailleList.getFirst().start - 1), ""); - list.shiftOffsetsFromIndex(index, -(b.end - (b.start - 1)), -(b.brailleList.getFirst().end - (b.brailleList.getFirst().start - 1))); + list.shiftOffsetsFromIndex(index, -(b.end - (b.start - 1)), -(b.brailleList.getFirst().end - (b.brailleList.getFirst().start - 1)), 0);
list.remove(index); } @@ -632,6 +519,23 @@ treeView.resetTreeItem(boxline); boxline.getParent().removeChild(boxline); } + + private boolean isBoxLine(Element e){+ if(checkSemanticsAttribute(e, BOXLINE) || checkSemanticsAttribute(e, TOPBOX) || checkSemanticsAttribute(e, MIDDLEBOX) + || checkSemanticsAttribute(e, BOTTOMBOX) || checkSemanticsAttribute(e, FULLBOX))
+ return true; + else + return false; + } + + private boolean checkSemanticsAttribute(Element e, String value){ + Attribute atr = e.getAttribute("semantics"); + + if(atr == null || !atr.getValue().contains(value)) + return false; + + return true; + } private Text findText(Node n){ if(n.getChild(0) instanceof Text) @@ -659,6 +563,10 @@ m.put("action", style); manager.getDocument().applyAction(m); } + + private String getStyle(Element box){ + return box.getAttributeValue("semantics").split(",")[1]; + } private int getMatchingParent(ArrayList<TextMapElement>elList, int index){ Element parent = elList.get(index).parentElement(); @@ -678,52 +586,4 @@ } return sidebarCount; } - - /*** - * Get parent style of the current TextMapElement - * @param current - * @param message - * @return - */ - private Element parentStyle(TextMapElement current, Message message) { - Element parent;- if(current instanceof PageMapElement || current instanceof BrlOnlyMapElement)
- parent = current.parentElement(); - else - parent = document.getParent(current.n, true); -- message.put("previousStyle", styles.get(styles.getKeyFromAttribute(parent)));
- return parent; - } - - /*** - * get bounds of elements in the list based on previous and next element - * @param itemList : all selected items which we want style to be applied - * @param message : passing information regarding styles - */- private void getBounds(ArrayList<TextMapElement> itemList, Message message) {
- int start = list.indexOf(itemList.get(0)); - int end = list.indexOf(itemList.get(itemList.size() - 1)); - - if (start > 0) { - message.put("prev", list.get(start - 1).end); - message.put("braillePrev", - list.get(start - 1).brailleList.getLast().end); - } else { - message.put("prev", -1); - message.put("braillePrev", -1); - } - - if (end < list.size() - 1) { - message.put("next", list.get(end + 1).start); - message.put("brailleNext", - list.get(end + 1).brailleList.getFirst().start); - } else { - message.put("next", -1); - message.put("brailleNext", -1); - } - - text.getBounds(message, itemList); - braille.getBounds(message, itemList); - } } =======================================--- /src/main/org/brailleblaster/perspectives/braille/stylers/HideActionHandler.java Wed Jan 14 14:33:00 2015 UTC +++ /src/main/org/brailleblaster/perspectives/braille/stylers/HideActionHandler.java Mon Feb 2 17:23:00 2015 UTC
@@ -4,14 +4,15 @@ import java.util.Iterator; import java.util.Set; +import nu.xom.Attribute; import nu.xom.Element; import org.brailleblaster.BBIni; import org.brailleblaster.perspectives.braille.Manager;import org.brailleblaster.perspectives.braille.document.BBSemanticsTable.StylesType;
+import org.brailleblaster.perspectives.braille.eventQueue.Event; import org.brailleblaster.perspectives.braille.eventQueue.EventFrame; import org.brailleblaster.perspectives.braille.eventQueue.EventTypes; -import org.brailleblaster.perspectives.braille.eventQueue.ModelEvent;import org.brailleblaster.perspectives.braille.mapping.elements.BrlOnlyMapElement; import org.brailleblaster.perspectives.braille.mapping.elements.PageMapElement; import org.brailleblaster.perspectives.braille.mapping.elements.TextMapElement;
@@ -19,99 +20,90 @@ import org.brailleblaster.perspectives.braille.messages.Message; import org.brailleblaster.perspectives.braille.messages.Sender;import org.brailleblaster.perspectives.braille.viewInitializer.ViewInitializer;
+import org.brailleblaster.perspectives.braille.views.tree.BBTree; +import org.brailleblaster.perspectives.braille.views.wp.BrailleView; +import org.brailleblaster.perspectives.braille.views.wp.TextView; +import org.brailleblaster.util.Notify; -public class HideActionHandler extends Handler{ - +public class HideActionHandler { + Manager manager; + MapList list; + TextView text; + BrailleView braille; + BBTree tree; + ViewInitializer vi; EventFrame eventFrame; boolean boxlineAdded;- public HideActionHandler(Manager manager, ViewInitializer vi, MapList list){
- super(manager, vi, list);+ public HideActionHandler(Manager manager, MapList list, ViewInitializer vi){
+ this.manager = manager; + this.list = list; + this.vi = vi; + text = manager.getText(); + braille = manager.getBraille(); + tree = manager.getTreeView(); } public void hideText(){ - eventFrame = new EventFrame(); if(list.size() > 0 && text.view.getCharCount() > 0){ - if(text.isMultiSelected()){ - boolean valid = hideMultipleElements(); - if(valid) - manager.addUndoEvent(eventFrame); - } + if(text.isMultiSelected()) + hideMultipleElements(); else if(!(list.getCurrent() instanceof BrlOnlyMapElement)){ hideSingleElement(); - manager.addUndoEvent(eventFrame); } - else + else { invalidSelection(); + } } } - public void hideText(EventFrame f){ - eventFrame = new EventFrame(); - while(!f.empty() && f.peek().getEventType().equals(EventTypes.Hide)){ - ModelEvent ev = (ModelEvent)f.pop();- manager.dispatch(Message.createSetCurrentMessage(Sender.TREE, list.get(ev.getListIndex()).start, false));
+ public void hideText(Event ev){+ manager.dispatch(Message.createSetCurrentMessage(Sender.TREE, list.get(ev.getListIndex()).start, false));
- //resets selection to recreate hide event by user - if(list.getCurrent() instanceof BrlOnlyMapElement){- BrlOnlyMapElement b = list.findJoiningBoxline((BrlOnlyMapElement)list.getCurrent());
- int start =list.getCurrent().start; - int end = b.end; - text.setCurrentSelection(start, end); - } - - redoHide(); + //resets selection to recreate hide event by user + if(list.getCurrent() instanceof BrlOnlyMapElement){+ BrlOnlyMapElement b = list.findJoiningBoxline((BrlOnlyMapElement)list.getCurrent());
+ int start =list.getCurrent().start; + int end = b.end; + text.setCurrentSelection(start, end); } - manager.addUndoEvent(eventFrame); - } - - private void redoHide(){ - if(list.size() > 0 && text.view.getCharCount() > 0){ - if(text.isMultiSelected()) - hideMultipleElements(); - else if(!(list.getCurrent() instanceof BrlOnlyMapElement)) - hideSingleElement(); - else - invalidSelection(); - } + + hideText(); } private void hideSingleElement(){ text.update(false); int index = list.getCurrentIndex(); + eventFrame = new EventFrame(); boxlineAdded = false; hide(list.getCurrent()); updateCurrentElement(index); + manager.addUndoEvent(eventFrame); } - private boolean hideMultipleElements(){ + private void hideMultipleElements(){ int start=text.getSelectedText()[0]; int end=text.getSelectedText()[1]; boolean invalid = false;- Set<TextMapElement> itemSet = manager.getElementInSelectedRange(start, end);
+ Set<TextMapElement> itemSet = manager.getElementSelected(start, end); Iterator<TextMapElement> itr = itemSet.iterator(); invalid = checkSelection(itemSet, start, end); Integer index = null; if(!invalid){ itr = itemSet.iterator(); + eventFrame = new EventFrame(); boxlineAdded = false; while (itr.hasNext()) { TextMapElement tempElement= itr.next(); if(index == null) index = list.indexOf(tempElement); - if(BBIni.getPlatformName().equals("gtk")) - checkLinuxTree(tempElement); - hide(tempElement); } - text.clearSelection(); updateCurrentElement(index); - return true; + manager.addUndoEvent(eventFrame); } - - return invalid; } private void updateCurrentElement(int index){ @@ -198,7 +190,7 @@ } if(!boxlineAdded)- eventFrame.addEvent(new ModelEvent(EventTypes.Hide, parent, vi.getStartIndex(), list.indexOf(itemList.get(0)), startPos, brailleStartPos, treeIndexes)); + eventFrame.addEvent(new Event(EventTypes.Hide, parent, vi.getStartIndex(), list.indexOf(itemList.get(0)), startPos, brailleStartPos, treeIndexes));
if(parent.getLocalName().equals("sidebar")) boxlineAdded = true; @@ -212,7 +204,7 @@ vi.remove(list, list.indexOf(itemList.get(i))); } - list.shiftOffsetsFromIndex(index, -textLength, -brailleLength); + list.shiftOffsetsFromIndex(index, -textLength, -brailleLength, 0); manager.getDocument().applyAction(m); } @@ -301,7 +293,18 @@ private void invalidSelection(){ if(!BBIni.debugging())- manager.notify("In order to hide a boxline both opening and closing boxlines must be selected"); + new Notify("In order to hide a boxline both opening and closing boxlines must be selected");
+ } + + private boolean isHeading(Element e){ + Attribute atr = e.getAttribute("semantics"); + + if(atr != null){ + if(atr.getValue().contains("heading")) + return true; + } + + return false; } private boolean collapseSpaceBefore(TextMapElement t){ @@ -344,6 +347,32 @@ return false; } + + private boolean isFirstInList(int index){ + if(index == 0) + return true; + else + return false; + } + + private boolean isLastInList(int index){ + if(index == list.size() - 1) + return true; + else + return false; + } + + private String getSemanticAttribute(Element e){ + Attribute atr = e.getAttribute("semantics"); + if(atr != null){ + String val = atr.getValue(); + String[] tokens = val.split(","); + if(tokens.length > 1) + return tokens[1]; + } + + return null; + } private boolean removeParent(TextMapElement t){ if(!(t instanceof PageMapElement) && isInLine(t.parentElement())) @@ -352,10 +381,13 @@ return false; } - private void checkLinuxTree(TextMapElement t){ - if(!boxlineAdded && !(t instanceof BrlOnlyMapElement)){ - if(tree.getTree().getSelection().length == 0) - tree.setSelection(t); + private boolean isInLine(Element e){ + Attribute atr = e.getAttribute("semantics"); + if(atr != null){ + String [] tokens = atr.getValue().split(","); + if(tokens[0].equals("action")) + return true; } + return false; } } =======================================--- /src/main/org/brailleblaster/perspectives/braille/ui/BBToolBar.java Thu Dec 11 19:17:46 2014 UTC +++ /src/main/org/brailleblaster/perspectives/braille/ui/BBToolBar.java Mon Feb 2 17:23:00 2015 UTC
@@ -39,8 +39,8 @@ import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; -//import org.eclipse.swt.graphics.Font; -//import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.graphics.FontData; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.layout.FormAttachment; =======================================--- /src/main/org/brailleblaster/perspectives/braille/viewInitializer/WebInitializer.java Fri Dec 12 16:18:58 2014 UTC +++ /src/main/org/brailleblaster/perspectives/braille/viewInitializer/WebInitializer.java Mon Feb 2 17:23:00 2015 UTC
@@ -11,7 +11,6 @@ import org.brailleblaster.document.SemanticFileHandler; import org.brailleblaster.perspectives.braille.Manager; import org.brailleblaster.perspectives.braille.document.BrailleDocument;-import org.brailleblaster.perspectives.braille.mapping.elements.BrailleMapElement; import org.brailleblaster.perspectives.braille.mapping.elements.SectionElement; import org.brailleblaster.perspectives.braille.mapping.elements.TextMapElement;
import org.brailleblaster.perspectives.braille.mapping.maps.MapList; @@ -83,13 +82,8 @@SemanticFileHandler sfh = new SemanticFileHandler(m.getArchiver().getCurrentConfig()); p.addAttribute(new Attribute("semantics","styles," + sfh.getDefault("p")));
p.appendChild(new Text("")); - Element brl = new Element("brl"); - brl.appendChild(new Text("")); - p.appendChild(brl); ((Element)n.get(0)).appendChild(p);- TextMapElement t = new TextMapElement(0, 0, n.get(0).getChild(0).getChild(0));
- t.brailleList.add(new BrailleMapElement(0,0, brl.getChild(0))); - list.add(t); + list.add(new TextMapElement(0, 0, n.get(0).getChild(0).getChild(0))); } } } =======================================--- /src/main/org/brailleblaster/perspectives/braille/views/tree/TreeView.java Mon Dec 1 18:24:59 2014 UTC +++ /src/main/org/brailleblaster/perspectives/braille/views/tree/TreeView.java Mon Feb 2 17:23:00 2015 UTC
@@ -94,14 +94,13 @@ public ArrayList<Integer> getItemPath(){ ArrayList<Integer> list = new ArrayList<Integer>(); - if(tree.getSelection().length > 0){ - TreeItem item = tree.getSelection()[0]; - int first = 0; - while(item.getParentItem() != null){ - list.add(first, item.getParentItem().indexOf(item)); - item = item.getParentItem(); - } + TreeItem item = tree.getSelection()[0]; + int first = 0; + while(item.getParentItem() != null){ + list.add(first, item.getParentItem().indexOf(item)); + item = item.getParentItem(); } + return list; } } =======================================--- /src/main/org/brailleblaster/perspectives/braille/views/wp/BrailleView.java Mon Dec 22 18:32:06 2014 UTC +++ /src/main/org/brailleblaster/perspectives/braille/views/wp/BrailleView.java Mon Feb 2 17:23:00 2015 UTC
@@ -409,82 +409,82 @@ int length = 0; int spaces = 0; int offset = 0; - getBounds(m, list); + m.put("start", start); + m.put("end", end); + m.put("braillePrev", getPrev(m)); + m.put("brailleNext", getNext(m)); + m.put("offset", offset); String textBefore = ""; Styles style = (Styles)m.getValue("Style"); Styles previousStyle = (Styles)m.getValue("previousStyle"); + boolean boxline = style.getName().equals("boxline"); - setListenerLock(true);- view.setLineIndent(view.getLineAtOffset(start), getLineNumber(start, view.getTextRange(start, (end - start))), 0); - view.setLineAlignment(view.getLineAtOffset(start), getLineNumber(start, view.getTextRange(start, (end - start))), SWT.LEFT);
+ if(!boxline){ + setListenerLock(true);+ view.setLineIndent(view.getLineAtOffset(start), getLineNumber(start, view.getTextRange(start, (end - start))), 0); + view.setLineAlignment(view.getLineAtOffset(start), getLineNumber(start, view.getTextRange(start, (end - start))), SWT.LEFT);
- if(!style.contains(StylesType.linesBefore) && previousStyle.contains(StylesType.linesBefore))
- removeLinesBefore(m);+ if(!style.contains(StylesType.linesBefore) && previousStyle.contains(StylesType.linesBefore))
+ removeLinesBefore(m);- if(!style.contains(StylesType.linesAfter) && previousStyle.contains(StylesType.linesAfter))
- removeLinesAfter(m); -+ if(!style.contains(StylesType.linesAfter) && previousStyle.contains(StylesType.linesAfter))
+ removeLinesAfter(m); + } start = (Integer)m.getValue("start"); end = (Integer)m.getValue("end"); int prev = (Integer)m.getValue("braillePrev"); int next = (Integer)m.getValue("brailleNext"); - for (Entry<StylesType, Object> entry : style.getEntrySet()) { - switch(entry.getKey()){ - case linesBefore: - if(start != prev){ - view.replaceTextRange(prev, (start - prev), ""); - length = start - prev; - } + if(!boxline){ + for (Entry<StylesType, Object> entry : style.getEntrySet()) { + switch(entry.getKey()){ + case linesBefore: + if(start != prev){ + view.replaceTextRange(prev, (start - prev), ""); + length = start - prev; + } - spaces = Integer.valueOf((String)entry.getValue()); - textBefore = makeInsertionString(spaces,'\n'); - offset = spaces - length; + spaces = Integer.valueOf((String)entry.getValue()); + textBefore = makeInsertionString(spaces,'\n'); + offset = spaces - length; - insertBefore(start - (start - prev), textBefore); - start += offset; - end += offset; - if(next != -1) - next += offset; - break; - case linesAfter: - length = 0; - if(end != next && next != 0){ - view.replaceTextRange(end, (next - end), ""); - length = next - end; - } - spaces = Integer.valueOf((String)entry.getValue()); - textBefore = makeInsertionString(spaces,'\n'); - insertBefore(end, textBefore); - offset = spaces - length; - break; - case format: - setAlignment(start, end, style); - break; - case firstLineIndent:- if(Integer.valueOf((String)entry.getValue()) > 0 || style.contains(StylesType.leftMargin))
- setFirstLineIndent(start, style); - break; - case leftMargin: - if(style.contains(StylesType.firstLineIndent))- handleLineWrap(start, view.getTextRange(start, (end - start)), Integer.valueOf((String)entry.getValue()), true);
- else- handleLineWrap(start, view.getTextRange(start, (end - start)), Integer.valueOf((String)entry.getValue()), false);
- break; - default: - break; + insertBefore(start - (start - prev), textBefore); + start += offset; + end += offset; + if(next != -1) + next += offset; + break; + case linesAfter: + length = 0; + if(end != next && next != 0){ + view.replaceTextRange(end, (next - end), ""); + length = next - end; + } + spaces = Integer.valueOf((String)entry.getValue()); + textBefore = makeInsertionString(spaces,'\n'); + insertBefore(end, textBefore); + offset = spaces - length; + break; + case format: + setAlignment(start, end, style); + break; + case firstLineIndent:+ if(Integer.valueOf((String)entry.getValue()) > 0 || style.contains(StylesType.leftMargin))
+ setFirstLineIndent(start, style); + break; + case leftMargin: + if(style.contains(StylesType.firstLineIndent))+ handleLineWrap(start, view.getTextRange(start, (end - start)), Integer.valueOf((String)entry.getValue()), true);
+ else+ handleLineWrap(start, view.getTextRange(start, (end - start)), Integer.valueOf((String)entry.getValue()), false);
+ break; + default: + break; + } } + setListenerLock(false); } - setListenerLock(false); - } - - public void getBounds(Message m, ArrayList<TextMapElement>list){ - m.put("start", list.get(0).brailleList.getFirst().start); - m.put("end", list.get(list.size() - 1).brailleList.getLast().end); - m.put("braillePrev", getPrev(m)); - m.put("brailleNext", getNext(m)); - m.put("offset", 0); } private int getPrev(Message m){ @@ -717,26 +717,6 @@ setListenerLock(false); } } - - public void refreshStyle(TextMapElement t){ - Styles style = stylesTable.makeStylesElement(t.parentElement(), t.n);- String text = view.getTextRange(t.brailleList.getFirst().start, t.brailleList.getLast().end - t.brailleList.getFirst().start);
- int margin = 0; - if(style.contains(StylesType.format) && t.brailleList.size() > 0)- setAlignment(t.brailleList.getFirst().start, t.brailleList.getLast().end, style);
- - //reset margin in case it is not applied- if(t.brailleList.getFirst().start == view.getOffsetAtLine(view.getLineAtOffset(t.brailleList.getFirst().start)))
- handleLineWrap(t.brailleList.getFirst().start, text, 0, false); - - if(style.contains(StylesType.leftMargin)) { - margin = Integer.valueOf((String)style.get(StylesType.leftMargin));- handleLineWrap(t.brailleList.getFirst().start, text, margin, style.contains(StylesType.firstLineIndent));
- } -- if(isFirst(t.brailleList.getFirst().n) && style.contains(StylesType.firstLineIndent))
- setFirstLineIndent(t.brailleList.getFirst().start, style); - } public void removeMathML(TextMapElement t){ int total = t.brailleList.getLast().end - t.brailleList.getFirst().start; @@ -945,6 +925,15 @@ view.setCaretOffset(originalPosition); setListenerLock(false); } + + public void insertLineBreak(int insertPosition){ + setListenerLock(true); + int pos = view.getCaretOffset(); + view.setCaretOffset(insertPosition); + view.insert("\n"); + view.setCaretOffset(pos); + setListenerLock(false); + } @Override public void addPageNumber(PageMapElement p, boolean insert) { @@ -1057,11 +1046,7 @@ * Remove indicator at all lines except input given line */ private void removeIndicator(){ - int lineNumber; - if(currentStart > view.getCharCount()) - lineNumber = view.getLineAtOffset(view.getCharCount()); - else - lineNumber = view.getLineAtOffset(currentStart); + int lineNumber=view.getLineAtOffset(currentStart); for (int i = lineNumber; i < view.getLineCount(); i++) { // Check to find bullet which are in indication array list =======================================--- /src/main/org/brailleblaster/perspectives/braille/views/wp/TextView.java Fri Jan 23 13:35:24 2015 UTC +++ /src/main/org/brailleblaster/perspectives/braille/views/wp/TextView.java Mon Feb 2 17:23:00 2015 UTC
@@ -546,6 +546,14 @@ if(offset < currentStart || offset > currentEnd) setCurrent(view.getCaretOffset()); } + + public void setCursorNoFocus(int offset, Manager cont){ + view.setFocus(); + view.setCaretOffset(offset); + + if(offset < currentStart || offset > currentEnd) + setCurrent(view.getCaretOffset()); + } public void setText(TextMapElement t, MapList list, int index){ Styles style = stylesTable.makeStylesElement(t.parentElement(), t.n); =======================================--- /src/main/org/brailleblaster/perspectives/braille/views/wp/WPView.java Fri Dec 12 17:44:51 2014 UTC +++ /src/main/org/brailleblaster/perspectives/braille/views/wp/WPView.java Mon Feb 2 17:23:00 2015 UTC
@@ -1,7 +1,5 @@ package org.brailleblaster.perspectives.braille.views.wp; -import java.util.ArrayList; - import nu.xom.Element; import org.brailleblaster.abstractClasses.AbstractView; @@ -11,7 +9,6 @@import org.brailleblaster.perspectives.braille.document.BBSemanticsTable.Styles; import org.brailleblaster.perspectives.braille.document.BBSemanticsTable.StylesType; import org.brailleblaster.perspectives.braille.mapping.elements.PageMapElement; -import org.brailleblaster.perspectives.braille.mapping.elements.TextMapElement;
import org.brailleblaster.perspectives.braille.messages.Message; import org.brailleblaster.perspectives.braille.messages.Sender; import org.eclipse.swt.SWT; @@ -54,12 +51,9 @@ } public abstract void addPageNumber(PageMapElement p, boolean insert); - public abstract void getBounds(Message m, ArrayList<TextMapElement>list); - @Override protected abstract void setViewData(Message message); - /** finds Char width used to determine indent value * @return width of braille cell */ @@ -428,13 +422,4 @@ public int getTotal(){ return total; } - - public void insertLineBreak(int insertPosition){ - setListenerLock(true); - int pos = view.getCaretOffset(); - view.setCaretOffset(insertPosition); - view.insert("\n"); - view.setCaretOffset(pos); - setListenerLock(false); - } } =======================================--- /src/main/org/brailleblaster/search/SearchDialog.java Wed Jan 28 20:53:40 2015 UTC +++ /src/main/org/brailleblaster/search/SearchDialog.java Mon Feb 2 17:23:00 2015 UTC
@@ -1661,22 +1661,21 @@ // Make sure we aren't in an endless loop if (numberOfLoops <= 2) { - // If search wrap is on, move to other end of document, if at - // the end. - if (searchWrap == SCH_WRAP_ON) { + // If search wrap is on, move to other end of document, if at + // the end. + if (searchWrap == SCH_WRAP_ON) { + // If we're at the end, move to the other end. + while (startCharIndex < 0 || endCharIndex < 0) { + numberOfLoops++; + // Reset position. + endCharIndex = numChars; + startCharIndex = endCharIndex - findMeStr.length(); + tv.view.setCaretOffset(endCharIndex); - // If we're at the end, move to the other end. - while (startCharIndex < 0 || endCharIndex < 0) { - numberOfLoops++; - // Reset position. - endCharIndex = numChars; - startCharIndex = endCharIndex - findMeStr.length(); - tv.view.setCaretOffset(endCharIndex); + } // while( startCharIndex... - } // while( startCharIndex... - - }// if numberOfLoops + }// if numberOfLoops // Scour the view for the search string. while (startCharIndex >= 0 && endCharIndex > 0) { @@ -1733,21 +1732,22 @@ // Make sure we aren't in an endless loop if (numberOfLoops <= 2) { - // If search wrap is on, move to other end of document, if at - // the end. - if (searchWrap == SCH_WRAP_ON) { + // If search wrap is on, move to other end of document, if + // at + // the end. + if (searchWrap == SCH_WRAP_ON) { - // If we're at the end, move to the other end. - if (startCharIndex < 0 || endCharIndex < 0) { - numberOfLoops++; - // Reset position. - endCharIndex = numChars; - startCharIndex = endCharIndex - findMeStr.length(); - tv.view.setCaretOffset(endCharIndex); + // If we're at the end, move to the other end. + if (startCharIndex < 0 || endCharIndex < 0) { + numberOfLoops++; + // Reset position. + endCharIndex = numChars; + startCharIndex = endCharIndex - findMeStr.length(); + tv.view.setCaretOffset(endCharIndex); - } // if( startCharIndex... + } // if( startCharIndex... - } // if( searchWrap == SCH_WRAP_ON ) + } // if( searchWrap == SCH_WRAP_ON ) }// if numberOfLoops =======================================--- /src/main/org/brailleblaster/settings/SettingsManager.java Wed Jan 7 21:10:16 2015 UTC +++ /src/main/org/brailleblaster/settings/SettingsManager.java Mon Feb 2 17:23:00 2015 UTC
@@ -122,8 +122,6 @@ else if(tokens[0].equals("rightMargin")) outputMap.put(tokens[0], tokens[1]); else if(tokens[0].equals("leftMargin")) - outputMap.put(tokens[0], tokens[1]); - else if(tokens[0].equals("cellsPerLine")) outputMap.put(tokens[0], tokens[1]); else if(tokens[0].equals("linesPerPage")) outputMap.put(tokens[0], tokens[1]); =======================================--- /src/main/org/brailleblaster/settings/ui/PageNumbersTab.java Mon Jan 12 13:08:30 2015 UTC +++ /src/main/org/brailleblaster/settings/ui/PageNumbersTab.java Mon Feb 2 17:23:00 2015 UTC
@@ -8,6 +8,8 @@ import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Combo; @@ -26,10 +28,8 @@ LocaleHandler lh; Group ppnGroup, bpnGroup, cpGroup; Composite group; - Label cpLabel, intpLabel, ppnRngLabel, bpnLocLabel, ppnLocLabel; - //Label ppnLabel, bpnLabel, ppnlocLabel, bpnlocLabel; - Combo cpCombo, intpCombo, ppnRngCombo, bpnLocCombo, ppnLocCombo; - //Combo ppnCombo, bpnCombo, ppnlocCombo, bpnlocCombo;+ Label ppnLabel, bpnLabel, cpLabel, intpLabel, ppnlocLabel, bpnlocLabel, ppnRngLabel; + Combo ppnCombo, bpnCombo, cpCombo, intpCombo, ppnlocCombo, bpnlocCombo, ppnRngCombo;
public PageNumbersTab(TabFolder folder, final SettingsManager sm, HashMap<String, String> settingsMap) {
super(); @@ -52,6 +52,18 @@ bpnGroup.setLayout(new GridLayout(2, true)); bpnGroup.setText(lh.localValue("braille")); + bpnLabel = new Label(bpnGroup, 0); + bpnLabel.setText("Braille Page Numbers"); + setGridData(bpnLabel); + bpnCombo = new Combo(bpnGroup, SWT.READ_ONLY); + bpnCombo.add("No"); + bpnCombo.add("Yes"); + if( settingsMap.get("numberBraillePages").equals("yes") ) + bpnCombo.setText("Yes"); + else + bpnCombo.setText("No"); + setGridData(bpnCombo); + //////////// intpLabel = new Label(bpnGroup, 0); @@ -67,34 +79,18 @@ setGridData(intpCombo); /////////// - - /** - * Currently the settings have one drop down menu to select "Yes" or "No" - * and a separate settings box to select the location.- * Rather than the user having to enter two settings, this could be consolidated into
- * one drop down menu for Braille Page Numbers: Top, Bottom, None. - */ - bpnLocLabel = new Label (bpnGroup, 0); - bpnLocLabel.setText("Braille Page Number Location"); - setGridData(bpnLocLabel); - bpnLocCombo = new Combo(bpnGroup, SWT.READ_ONLY); - bpnLocCombo.add("Top"); - bpnLocCombo.add("Bottom"); - bpnLocCombo.add("None"); - - if (settingsMap.get("braillePageNumberAt").equals("top")) { - bpnLocCombo.setText("Top"); - } - else { - bpnLocCombo.setText("Bottom"); - } - - if (settingsMap.get("numberBraillePages").equals("no")) { - bpnLocCombo.setText("None"); - } - - setGridData(bpnLocCombo); + bpnlocLabel = new Label(bpnGroup, 0); + bpnlocLabel.setText("BPN Location"); + setGridData(bpnlocLabel); + bpnlocCombo = new Combo(bpnGroup, SWT.READ_ONLY); + bpnlocCombo.add("Bottom"); + bpnlocCombo.add("Top"); + if( settingsMap.get("braillePageNumberAt").equals("top") ) + bpnlocCombo.setText("Top"); + else + bpnlocCombo.setText("Bottom"); + setGridData(bpnlocCombo); ///////////////////////////////////////////////////////////// @@ -102,26 +98,32 @@ ppnGroup.setLayout(new GridLayout(2, true)); ppnGroup.setText(lh.localValue("print")); - ppnLocLabel = new Label(ppnGroup, 0); - ppnLocLabel.setText("Print Page Number Location"); - setGridData(ppnLocLabel); - ppnLocCombo = new Combo(ppnGroup, SWT.READ_ONLY); - ppnLocCombo.add("Top"); - ppnLocCombo.add("Bottom"); - ppnLocCombo.add("None"); - if (settingsMap.get("printPageNumberAt").equals("top") ) { - ppnLocCombo.setText("Top"); - } - else { - ppnLocCombo.setText("Bottom"); - } + ppnLabel = new Label(ppnGroup, 0); + ppnLabel.setText("Print Page Numbers"); + setGridData(ppnLabel); + ppnCombo = new Combo(ppnGroup, SWT.READ_ONLY); + ppnCombo.add("No"); + ppnCombo.add("Yes"); + if( settingsMap.get("printPages").equals("yes") ) + ppnCombo.setText("Yes"); + else + ppnCombo.setText("No"); + setGridData(ppnCombo); - if (settingsMap.get("printPages").equals("no")) { - ppnLocCombo.setText("None"); - } + ///////////// - setGridData(ppnLocCombo); + ppnlocLabel = new Label(ppnGroup, 0); + ppnlocLabel.setText("PPN Location"); + setGridData(ppnlocLabel); + ppnlocCombo = new Combo(ppnGroup, SWT.READ_ONLY); + ppnlocCombo.add("Bottom"); + ppnlocCombo.add("Top"); + if( settingsMap.get("printPageNumberAt").equals("top") ) + ppnlocCombo.setText("Top"); + else + ppnlocCombo.setText("Bottom"); + setGridData(ppnlocCombo); ///////////// @@ -144,7 +146,7 @@ cpGroup.setText(lh.localValue("continue")); cpLabel = new Label(cpGroup, 0); cpLabel.setText("Continue Pages"); - setGridData(ppnLocLabel); + setGridData(ppnLabel); cpCombo = new Combo(cpGroup, SWT.READ_ONLY); cpCombo.add("No"); cpCombo.add("Yes"); @@ -160,42 +162,73 @@ private void addListeners(){ - - ppnLocCombo.addSelectionListener(new SelectionAdapter(){ - @Override - public void widgetSelected(SelectionEvent e) { - int index = ppnLocCombo.getSelectionIndex(); - if (ppnLocCombo.getText().equals("None")) { - settingsMap.put("printPages", "no"); + ppnCombo.addSelectionListener(new SelectionAdapter(){ + @Override + public void widgetSelected(SelectionEvent e) { + int index = ppnCombo.getSelectionIndex(); + settingsMap.put("printPages", ppnCombo.getText().toLowerCase()); } - else {- settingsMap.put("printPageNumberAt", ppnLocCombo.getText().toLowerCase());
- settingsMap.put("printPages", "yes"); + }); + + bpnCombo.addSelectionListener(new SelectionAdapter(){ + @Override + public void widgetSelected(SelectionEvent e) { + int index = bpnCombo.getSelectionIndex();+ settingsMap.put("numberBraillePages", bpnCombo.getText().toLowerCase());
} + }); + + cpCombo.addSelectionListener(new SelectionAdapter(){ + @Override + public void widgetSelected(SelectionEvent e) { + int index = cpCombo.getSelectionIndex(); + settingsMap.put("continuePages", cpCombo.getText().toLowerCase()); } }); - bpnLocCombo.addSelectionListener(new SelectionAdapter(){ - @Override - public void widgetSelected(SelectionEvent e) { - int index = bpnLocCombo.getSelectionIndex(); - if (bpnLocCombo.getText().equals("None")) { - settingsMap.put("numberBraillePages", "no"); + intpCombo.addSelectionListener(new SelectionAdapter(){ + @Override + public void widgetSelected(SelectionEvent e) { + int index = intpCombo.getSelectionIndex(); + settingsMap.put("interpoint", intpCombo.getText().toLowerCase()); } - else {- settingsMap.put("braillePageNumberAt", bpnLocCombo.getText().toLowerCase());
- settingsMap.put("numberBraillePages", "yes"); + }); + + ppnlocCombo.addSelectionListener(new SelectionAdapter(){ + @Override + public void widgetSelected(SelectionEvent e) { + int index = ppnlocCombo.getSelectionIndex();+ settingsMap.put("printPageNumberAt", ppnlocCombo.getText().toLowerCase());
} + }); + + bpnlocCombo.addSelectionListener(new SelectionAdapter(){ + @Override + public void widgetSelected(SelectionEvent e) { + int index = bpnlocCombo.getSelectionIndex();+ settingsMap.put("braillePageNumberAt", bpnlocCombo.getText().toLowerCase());
} }); ppnRngCombo.addSelectionListener(new SelectionAdapter(){ @Override public void widgetSelected(SelectionEvent e) { + int index = ppnRngCombo.getSelectionIndex();settingsMap.put("printPageNumberRange", ppnRngCombo.getText().toLowerCase());
} }); } ++ private void setFormLayout(Control c, int left, int right, int top, int bottom){
+ FormData location = new FormData(); + + location.left = new FormAttachment(left); + location.right = new FormAttachment(right); + location.top = new FormAttachment(top); + location.bottom = new FormAttachment(bottom); + + c.setLayoutData(location); + } private void setGridData(Control c){ GridData gridData = new GridData(); =======================================--- /src/main/org/brailleblaster/settings/ui/PagePropertiesTab.java Tue Dec 30 20:12:04 2014 UTC +++ /src/main/org/brailleblaster/settings/ui/PagePropertiesTab.java Mon Feb 2 17:23:00 2015 UTC
@@ -46,42 +46,46 @@ import org.brailleblaster.util.FileUtils; public class PagePropertiesTab { - HashMap<String, String>settingsMap; + HashMap<String, String> settingsMap; SettingsManager sm; TabItem item; - Composite group; + Composite group; PropertyFileManager pfm; FileUtils fu; BBIni bbini; private static final String userSettings = BBIni.getUserSettings(); - - Group sizeGroup, marginGroup, pageGroup, buttonGroup, unitsGroup;//- Label pageSizeLabel, widthLabel, heightLabel, linesPerPageLabel, cellsPerLineLabel, marginTopLabel, marginBottomLabel, marginLeftLabel, marginRightLabel;
- + + Group sizeGroup, marginGroup, pageGroup, buttonGroup, unitsGroup;// + Label pageSizeLabel, widthLabel, heightLabel, linesPerPageLabel, + cellsPerLineLabel, marginTopLabel, marginBottomLabel, + marginLeftLabel, marginRightLabel; + Combo pageTypes;- Text widthBox, heightBox, linesBox, cellsBox, marginTopBox, marginLeftBox, marginRightBox, marginBottomBox;
+ Text widthBox, heightBox, linesBox, cellsBox, marginTopBox, marginLeftBox, + marginRightBox, marginBottomBox; Button okButton, cancelButton, regionalButton, cellsLinesButton;// - + boolean listenerLocked; LocaleHandler lh; public String currentUnits = "regional";// DecimalFormat df = new DecimalFormat("#.#"); -- PagePropertiesTab(TabFolder folder, final SettingsManager sm, HashMap<String, String>settingsMap){
- + boolean userModified; + + PagePropertiesTab(TabFolder folder, final SettingsManager sm, + HashMap<String, String> settingsMap) { lh = new LocaleHandler(); this.sm = sm; this.settingsMap = settingsMap; listenerLocked = false; - item = new TabItem(folder, 0); + item = new TabItem(folder, 0); item.setText(lh.localValue("pageProperties")); - + group = new Composite(folder, 0); group.setLayout(new FormLayout()); item.setControl(group); setFormLayout(group, 0, 100, 0, 60); - + unitsGroup = new Group(group, SWT.BORDER); unitsGroup.setText(lh.localValue("measurementUnits")); unitsGroup.setLayout(new FillLayout()); @@ -92,66 +96,66 @@ cellsLinesButton = new Button(unitsGroup, SWT.RADIO); cellsLinesButton.setText(lh.localValue("cellsLines")); - + PropertyFileManager pfm = new PropertyFileManager(userSettings); String value = pfm.getProperty("currentUnits"); if (value.equals("cellsLines")) cellsLinesButton.setSelection(true); else regionalButton.setSelection(true); - + sizeGroup = new Group(group, SWT.BORDER); sizeGroup.setText(lh.localValue("pageSize")); sizeGroup.setLayout(new FillLayout()); setFormLayout(sizeGroup, 0, 100, 20, 65); - + pageGroup = new Group(sizeGroup, 0); pageGroup.setLayout(new GridLayout(2, true)); - + pageSizeLabel = new Label(pageGroup, 0); pageSizeLabel.setText(lh.localValue("pageSize")); setGridData(pageSizeLabel); - + pageTypes = new Combo(pageGroup, SWT.NONE); setStandardPages(); setDefault(); setGridData(pageTypes); - + widthLabel = new Label(pageGroup, 0); widthLabel.setText(lh.localValue("width")); - widthBox = new Text(pageGroup, SWT.BORDER); + widthBox = new Text(pageGroup, SWT.BORDER); addDoubleListener(widthBox); setGridData(widthBox); setValue(widthBox, "paperWidth"); - + heightLabel = new Label(pageGroup, 0); heightLabel.setText(lh.localValue("height")); heightBox = new Text(pageGroup, SWT.BORDER); addDoubleListener(heightBox); setGridData(heightBox); setValue(heightBox, "paperHeight"); - + linesPerPageLabel = new Label(pageGroup, 0); linesPerPageLabel.setText(lh.localValue("linesPerPage")); - + linesBox = new Text(pageGroup, SWT.BORDER); setGridData(linesBox);- linesBox.setText((String.valueOf(calculateLinesPerPage(Double.valueOf(settingsMap.get("paperHeight"))))));
- linesBox.setEditable(false); - + linesBox.setText((String.valueOf(calculateLinesPerPage(Double + .valueOf(settingsMap.get("paperHeight")))))); + cellsPerLineLabel = new Label(pageGroup, 0); cellsPerLineLabel.setText(lh.localValue("cellsPerLine")); - + cellsBox = new Text(pageGroup, SWT.BORDER); setGridData(cellsBox);- cellsBox.setText(String.valueOf(calculateCellsPerLine(Double.valueOf(settingsMap.get("paperWidth")))));
- cellsBox.setEditable(false); - + cellsBox.setText(String.valueOf(calculateCellsPerLine(Double + .valueOf(settingsMap.get("paperWidth"))))); + marginGroup = new Group(group, SWT.BORDER); marginGroup.setLayout(new GridLayout(2, true)); marginGroup.setText(lh.localValue("margins")); setFormLayout(marginGroup, 0, 100, 65, 100); - + marginTopLabel = new Label(marginGroup, 0); marginTopLabel.setText(lh.localValue("topMargin")); marginTopBox = new Text(marginGroup, SWT.BORDER); @@ -159,7 +163,7 @@ setGridData(marginTopBox); setValueForMargins(marginTopBox, "topMargin"); addMarginListener(marginTopBox, "topMargin"); - + marginBottomLabel = new Label(marginGroup, 0); marginBottomLabel.setText(lh.localValue("bottomMargin")); marginBottomBox = new Text(marginGroup, SWT.BORDER); @@ -167,15 +171,15 @@ setGridData(marginBottomBox); setValueForMargins(marginBottomBox, "bottomMargin"); addMarginListener(marginBottomBox, "bottomMargin"); - - marginLeftLabel= new Label(marginGroup, 0); + + marginLeftLabel = new Label(marginGroup, 0); marginLeftLabel.setText(lh.localValue("leftMargin")); marginLeftBox = new Text(marginGroup, SWT.BORDER); addDoubleListener(marginLeftBox); setGridData(marginLeftBox); setValueForMargins(marginLeftBox, "leftMargin"); addMarginListener(marginLeftBox, "leftMargin"); - + marginRightLabel = new Label(marginGroup, 0); marginRightLabel.setText(lh.localValue("rightMargin")); marginRightBox = new Text(marginGroup, SWT.BORDER); @@ -183,546 +187,661 @@ setGridData(marginRightBox); setValueForMargins(marginRightBox, "rightMargin"); addMarginListener(marginRightBox, "rightMargin"); - - Control [] tabList = {sizeGroup, marginGroup, unitsGroup}; + + Control[] tabList = { sizeGroup, marginGroup, unitsGroup }; group.setTabList(tabList); - - if(widthBox.getText().length() > 0 || heightBox.getText().length() > 0) + + if (widthBox.getText().length() > 0 || heightBox.getText().length() > 0) checkStandardSizes(); - + addListeners(); } - - private void addDoubleListener(final Text t){ - t.addKeyListener(new KeyAdapter(){ + + private void addDoubleListener(final Text t) { + t.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) {- if(!Character.isDigit(e.character) && e.keyCode != SWT.BS && e.keyCode != SWT.DEL && e.keyCode != SWT.ARROW_LEFT && e.keyCode != SWT.ARROW_RIGHT){ - if(e.character != '.' || (e.character == '.' && t.getText().contains(".")))
+ if (!Character.isDigit(e.character) && e.keyCode != SWT.BS + && e.keyCode != SWT.DEL && e.keyCode != SWT.ARROW_LEFT + && e.keyCode != SWT.ARROW_RIGHT) { + if (e.character != '.' + || (e.character == '.' && t.getText().contains("."))) e.doit = false; } - } + } }); } - private void addMarginListener(final Text t, final String type){ + private void addMarginListener(final Text t, final String type) { + if (type.equals("leftMargin") || type.equals("rightMargin")) { - if(type.equals("leftMargin") || type.equals("rightMargin")){ + t.addModifyListener(new ModifyListener() { - t.addModifyListener(new ModifyListener(){ - - @Override - public void modifyText(ModifyEvent e) { + @Override + public void modifyText(ModifyEvent e) { + if (!userModified) { Double margin; if (currentUnits.equals("regional")) margin = getDoubleValue(t); - else - margin = calcWidthFromCells((int)getDoubleValue(t)); -- if(margin >= getDoubleValue(widthBox) || (getDoubleValue(marginLeftBox) + getDoubleValue(marginRightBox) >= getDoubleValue(widthBox))){
+ else + margin = calcWidthFromCells((int) getDoubleValue(t)); + + if (margin >= getDoubleValue(widthBox) + || (getDoubleValue(marginLeftBox) + + getDoubleValue(marginRightBox) >= getDoubleValue(widthBox))) { new Notify(lh.localValue("incorrectMarginWidth")); t.setText(settingsMap.get(type)); - } + }// if notCorrectValue else { - - if (listenerLocked) { - if(cellsLinesButton.getSelection()) { - settingsMap.put(type,- String.valueOf(df.format(calcWidthFromCells(Integer.valueOf((getStringValue(t)))))));
- } + + if (listenerLocked) { + if (cellsLinesButton.getSelection()) { + settingsMap.put( + type, + String.valueOf(df + .format(calcWidthFromCells(Integer + .valueOf((getStringValue(t))))))); + }// if cellsLinesButton else { settingsMap.put(type, getStringValue(t)); - } - } + }// else regionalButton + } // if listenerLocked + else { + if (regionalButton.getSelection()) { + settingsMap.put(type, getStringValue(t)); + cellsBox.setText(String + .valueOf(calculateCellsPerLine(Double + .valueOf(widthBox.getText())))); + linesBox.setText(String + .valueOf(calculateLinesPerPage(Double + .valueOf(heightBox + .getText())))); + + }// if regionalButton else { - if (regionalButton.getSelection()) { - settingsMap.put(type,getStringValue(t));- cellsBox.setText(String.valueOf(calculateCellsPerLine(Double.valueOf(widthBox.getText())))); - linesBox.setText(String.valueOf(calculateLinesPerPage(Double.valueOf(heightBox.getText()))));
- } - else { - settingsMap.put(type,- String.valueOf(df.format(calcWidthFromCells(Integer.valueOf((getStringValue(t))))))); - cellsBox.setText(String.valueOf(calculateCellsPerLine(Double.valueOf(widthBox.getText())))); - linesBox.setText(String.valueOf(calculateLinesPerPage(Double.valueOf(heightBox.getText()))));
- } - } - } - - } - }); - } - else { - t.addModifyListener(new ModifyListener(){ - @Override - public void modifyText(ModifyEvent e) { + settingsMap.put( + type, + String.valueOf(df + .format(calcWidthFromCells(Integer + .valueOf((getStringValue(t))))))); + cellsBox.setText(String + .valueOf(calculateCellsPerLine(Double + .valueOf(widthBox.getText())))); + linesBox.setText(String + .valueOf(calculateLinesPerPage(Double + .valueOf(heightBox + .getText())))); + }// else cellsLinesButton + }// else notListenerLocked + }// else correctValues + + }// modifyText + }// if not userModified + });// modifyListener right or left + }// if type equals right or left + else { + t.addModifyListener(new ModifyListener() { + @Override + public void modifyText(ModifyEvent e) { + if (!userModified) { Double margin; if (currentUnits.equals("regional")) margin = getDoubleValue(t); else margin = sm.calcHeightFromLines(getDoubleValue(t)); -- if(margin >= Double.valueOf(heightBox.getText()) || (getDoubleValue(marginTopBox) + getDoubleValue(marginBottomBox) >= getDoubleValue(widthBox))){
+ + if (margin >= Double.valueOf(heightBox.getText()) + || (getDoubleValue(marginTopBox) + + getDoubleValue(marginBottomBox) >= getDoubleValue(widthBox))) { new Notify(lh.localValue("incorectMarginHeight")); t.setText(settingsMap.get(type)); - } + }// if incorrectSettings else { - + if (listenerLocked) { - if(cellsLinesButton.getSelection()) {- settingsMap.put(type, String.valueOf(df.format(sm.calcHeightFromLines(Integer.valueOf((getStringValue(t)))))));
- } + if (cellsLinesButton.getSelection()) { + settingsMap.put( + type, + String.valueOf(df.format(sm + .calcHeightFromLines(Integer + .valueOf((getStringValue(t))))))); + }// if cellsLinesButton else { - settingsMap.put(type,(getStringValue(t))); - } - } + settingsMap.put(type, (getStringValue(t))); + }// else regionalButton + }// if listenerLocked else { - if(regionalButton.getSelection()) { - settingsMap.put(type,getStringValue(t));- cellsBox.setText(String.valueOf(calculateCellsPerLine(Double.valueOf(widthBox.getText())))); - linesBox.setText(String.valueOf(calculateLinesPerPage(Double.valueOf(heightBox.getText()))));
- } + if (regionalButton.getSelection()) { + settingsMap.put(type, getStringValue(t)); + cellsBox.setText(String + .valueOf(calculateCellsPerLine(Double + .valueOf(widthBox.getText())))); + linesBox.setText(String + .valueOf(calculateLinesPerPage(Double + .valueOf(heightBox + .getText())))); + }// if regionalButton else { - settingsMap.put(type,- String.valueOf(df.format(sm.calcHeightFromLines(Integer.valueOf((getStringValue(t))))))); - cellsBox.setText(String.valueOf(calculateCellsPerLine(Double.valueOf(widthBox.getText())))); - linesBox.setText(String.valueOf(calculateLinesPerPage(Double.valueOf(heightBox.getText()))));
- } - } - } - } - }); - } - } - - private void setStandardPages(){ - Page [] temp = sm.getStandardSizes(); - for(int i = 0; i < temp.length; i++){ - if(sm.isMetric())- pageTypes.add(temp[i].type + " (" + temp[i].mmWidth + ", " + temp[i].mmHeight + ")");
+ settingsMap.put( + type, + String.valueOf(df.format(sm + .calcHeightFromLines(Integer + .valueOf((getStringValue(t))))))); + cellsBox.setText(String + .valueOf(calculateCellsPerLine(Double + .valueOf(widthBox.getText())))); + linesBox.setText(String + .valueOf(calculateLinesPerPage(Double + .valueOf(heightBox + .getText())))); + }// else cellsLinesButton + }// else not listenerLocked + }// else correctSettings + }// userModified false + }// modify text + });// modifyListener for top or bottom + }// if type equals top or bottom + + }// addMargin Listener + + private void setStandardPages() { + Page[] temp = sm.getStandardSizes(); + for (int i = 0; i < temp.length; i++) { + if (sm.isMetric()) + pageTypes.add(temp[i].type + " (" + temp[i].mmWidth + ", " + + temp[i].mmHeight + ")"); else- pageTypes.add(temp[i].type + " (" + temp[i].width + ", " + temp[i].height + ")");
+ pageTypes.add(temp[i].type + " (" + temp[i].width + ", " + + temp[i].height + ")"); } } - - private int searchList(char c){ - for(int i = 0; i < pageTypes.getItemCount(); i++){ - if(pageTypes.getItem(i).toLowerCase().charAt(0) == c) + + private int searchList(char c) { + for (int i = 0; i < pageTypes.getItemCount(); i++) { + if (pageTypes.getItem(i).toLowerCase().charAt(0) == c) return i; } - + return -1; } - - private void setGridData(Control c){ - GridData gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.verticalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - c.setLayoutData(gridData); + + private void setGridData(Control c) { + GridData gridData = new GridData(); + gridData.horizontalAlignment = GridData.FILL; + gridData.verticalAlignment = GridData.FILL; + gridData.grabExcessHorizontalSpace = true; + c.setLayoutData(gridData); } - private void addListeners(){ - - regionalButton.addSelectionListener - (new SelectionAdapter(){ - public void widgetSelected(SelectionEvent e){ + private void addListeners() { + + regionalButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { if (regionalButton.getSelection()) { - - listenerLocked = true; - currentUnits="regional"; - saveSettings(currentUnits); - modifyMargins(); - listenerLocked = false; + listenerLocked = true; + currentUnits = "regional"; + saveSettings(currentUnits); + modifyMargins(); + listenerLocked = false; } } - }); - cellsLinesButton.addSelectionListener - (new SelectionAdapter(){ - public void widgetSelected(SelectionEvent e){ - if (cellsLinesButton.getSelection()) { - - listenerLocked = true; - currentUnits="cellsLines"; - saveSettings(currentUnits); - modifyMargins(); - listenerLocked = false; - } + }); + cellsLinesButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + if (cellsLinesButton.getSelection()) { + listenerLocked = true; + currentUnits = "cellsLines"; + saveSettings(currentUnits); + modifyMargins(); + listenerLocked = false; + } - } - }); - - widthBox.addTraverseListener(new TraverseListener(){ + } + }); + + widthBox.addTraverseListener(new TraverseListener() { @Override public void keyTraversed(TraverseEvent e) { - if(getDoubleValue(widthBox) == 0){ - if(e.keyCode == SWT.TAB){ + if (getDoubleValue(widthBox) == 0) { + if (e.keyCode == SWT.TAB) { new Notify(lh.localValue("widthZero")); e.doit = false; } } } }); - - heightBox.addTraverseListener(new TraverseListener(){ + + heightBox.addTraverseListener(new TraverseListener() { @Override public void keyTraversed(TraverseEvent e) { - if(getDoubleValue(heightBox) == 0){ - if(e.keyCode == SWT.TAB){ + if (getDoubleValue(heightBox) == 0) { + if (e.keyCode == SWT.TAB) { new Notify(lh.localValue("heightZero")); e.doit = false; } } } }); - - widthBox.addModifyListener(new ModifyListener(){ + + widthBox.addModifyListener(new ModifyListener() { @Override public void modifyText(ModifyEvent e) { - if(!listenerLocked){ + if (!listenerLocked) { settingsMap.put("paperWidth", getStringValue(widthBox)); checkStandardSizes(); } } }); - - heightBox.addModifyListener(new ModifyListener(){ + + heightBox.addModifyListener(new ModifyListener() { @Override public void modifyText(ModifyEvent e) { - if(!listenerLocked){ + if (!listenerLocked) { settingsMap.put("paperHeight", getStringValue(heightBox)); checkStandardSizes(); } } }); - - cellsBox.addModifyListener(new ModifyListener(){ + + cellsBox.addModifyListener(new ModifyListener() { @Override public void modifyText(ModifyEvent e) { - if(!listenerLocked){ + if (!listenerLocked) { settingsMap.put("cellsPerLine", getStringValue(cellsBox)); } - } + } }); - - linesBox.addModifyListener(new ModifyListener(){ + + linesBox.addModifyListener(new ModifyListener() { @Override public void modifyText(ModifyEvent e) { - if(!listenerLocked){ + if (!userModified) { + userModifiesLinesBox(); + }// call userModifiesLinesBox + + if (!listenerLocked && !userModified) { settingsMap.put("linesPerPage", getStringValue(linesBox)); - } - } - }); - - pageTypes.addSelectionListener(new SelectionAdapter(){ + }// put value in settingsMap + }// modifyText + + });// modifyListener + + pageTypes.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { Page p = sm.getStandardSizes()[pageTypes.getSelectionIndex()]; - if(sm.isMetric()){ + if (sm.isMetric()) { widthBox.setText(String.valueOf(p.mmWidth)); heightBox.setText(String.valueOf(p.mmHeight)); - cellsBox.setText(String.valueOf(calculateCellsPerLine(p.mmWidth))); - linesBox.setText(String.valueOf(calculateLinesPerPage(p.mmHeight ))); - } - else { + cellsBox.setText(String + .valueOf(calculateCellsPerLine(p.mmWidth))); + linesBox.setText(String + .valueOf(calculateLinesPerPage(p.mmHeight))); + } else { widthBox.setText(String.valueOf(p.width)); heightBox.setText(String.valueOf(p.height)); - cellsBox.setText(String.valueOf(calculateCellsPerLine(p.width))); - linesBox.setText(String.valueOf(calculateLinesPerPage(p.height))); + cellsBox.setText(String + .valueOf(calculateCellsPerLine(p.width))); + linesBox.setText(String + .valueOf(calculateLinesPerPage(p.height))); } -- if(pageTypes.getItem(pageTypes.getItemCount() - 1).equals(lh.localValue("custom")))
+ + if (pageTypes.getItem(pageTypes.getItemCount() - 1).equals( + lh.localValue("custom"))) pageTypes.remove(pageTypes.getItemCount() - 1); } }); - - pageTypes.addKeyListener(new KeyAdapter(){ + + pageTypes.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { - if(e.keyCode != SWT.ARROW_DOWN && e.keyCode != SWT.ARROW_UP){ + if (e.keyCode != SWT.ARROW_DOWN && e.keyCode != SWT.ARROW_UP) { int loc = searchList(e.character); - if(loc != -1){ + if (loc != -1) { e.doit = false; pageTypes.select(loc);- cellsBox.setText(String.valueOf(calculateCellsPerLine(Double.valueOf(sm.getStandardSizes()[loc].width)))); - linesBox.setText(String.valueOf(calculateLinesPerPage(Double.valueOf(sm.getStandardSizes()[loc].height))));
- } - else + cellsBox.setText(String.valueOf(calculateCellsPerLine(Double + .valueOf(sm.getStandardSizes()[loc].width)))); + linesBox.setText(String.valueOf(calculateLinesPerPage(Double + .valueOf(sm.getStandardSizes()[loc].height)))); + } else e.doit = false; } } }); } - private void checkStandardSizes(){ + + private void checkStandardSizes() { Double width = getDoubleValue(widthBox); Double height = getDoubleValue(heightBox); - - if(width != 0 && height != 0){ + + if (width != 0 && height != 0) { boolean found = false; - for(int i = 0; i < sm.getStandardSizes().length && !found; i++){- if(checkEqualHeight(sm.getStandardSizes()[i], height) && checkEqualWidth(sm.getStandardSizes()[i], width)){
+ for (int i = 0; i < sm.getStandardSizes().length && !found; i++) { + if (checkEqualHeight(sm.getStandardSizes()[i], height) + && checkEqualWidth(sm.getStandardSizes()[i], width)) { pageTypes.select(i); found = true; - - if(!sm.isMetric()){- cellsBox.setText(String.valueOf(calculateCellsPerLine(sm.getStandardSizes()[i].width))); - linesBox.setText(String.valueOf(calculateLinesPerPage(sm.getStandardSizes()[i].height)));
+ + if (!sm.isMetric()) { + cellsBox.setText(String + .valueOf(calculateCellsPerLine(sm + .getStandardSizes()[i].width))); + linesBox.setText(String + .valueOf(calculateLinesPerPage(sm + .getStandardSizes()[i].height))); + } else { + cellsBox.setText(String + .valueOf(calculateCellsPerLine(sm + .getStandardSizes()[i].mmWidth))); + linesBox.setText(String + .valueOf(calculateLinesPerPage(sm + .getStandardSizes()[i].mmHeight))); } - else {- cellsBox.setText(String.valueOf(calculateCellsPerLine(sm.getStandardSizes()[i].mmWidth))); - linesBox.setText(String.valueOf(calculateLinesPerPage(sm.getStandardSizes()[i].mmHeight)));
- } -- if(pageTypes.getItem(pageTypes.getItemCount() - 1).equals(lh.localValue("custom")))
+ + if (pageTypes.getItem(pageTypes.getItemCount() - 1).equals( + lh.localValue("custom"))) pageTypes.remove(pageTypes.getItemCount() - 1); - } + } } - - if(!found){ - if(pageTypes.getItemCount() == sm.getStandardSizes().length){ + + if (!found) { + if (pageTypes.getItemCount() == sm.getStandardSizes().length) { pageTypes.add(lh.localValue("custom")); pageTypes.select(pageTypes.getItemCount() - 1); - } - else + } else pageTypes.select(pageTypes.getItemCount() - 1); -- cellsBox.setText(String.valueOf(calculateCellsPerLine(Double.valueOf(widthBox.getText())))); - linesBox.setText(String.valueOf(calculateLinesPerPage(Double.valueOf(heightBox.getText()))));
+ + cellsBox.setText(String.valueOf(calculateCellsPerLine(Double + .valueOf(widthBox.getText())))); + linesBox.setText(String.valueOf(calculateLinesPerPage(Double + .valueOf(heightBox.getText())))); } } } - - + /** * @return */ - public String validate(){- if( Integer.valueOf(cellsBox.getText()) < Integer.parseInt(settingsMap.get("minCellsPerLine")) )
+ public String validate() { + if (Integer.valueOf(cellsBox.getText()) < Integer.parseInt(settingsMap + .get("minCellsPerLine"))) return "invalidSettingsCells";- else if( Integer.valueOf(linesBox.getText()) < Integer.parseInt(settingsMap.get("minLinesPerPage")) )
+ else if (Integer.valueOf(linesBox.getText()) < Integer + .parseInt(settingsMap.get("minLinesPerPage"))) return "invalidSettingsLines"; return "SUCCESS"; } - - private void setValue(Text text, String key){ - if(settingsMap.containsKey(key)) + + private void setValue(Text text, String key) { + if (settingsMap.containsKey(key)) text.setText(settingsMap.get(key)); } - - private void setValueForMargins (Text text, String key) { + + private void setValueForMargins(Text text, String key) { if (regionalButton.getSelection()) { - if(settingsMap.containsKey(key)) + if (settingsMap.containsKey(key)) text.setText(settingsMap.get(key)); - } - else { - if(key.equals("leftMargin")||key.equals("rightMargin")) { - if(settingsMap.containsKey(key))- text.setText(String.valueOf(calculateCellsPerInch(Double.valueOf(settingsMap.get(key)))));
- } - else { - if(settingsMap.containsKey(key))- text.setText(String.valueOf(calculateLinesPerInch(Double.valueOf(settingsMap.get(key)))));
+ } else { + if (key.equals("leftMargin") || key.equals("rightMargin")) { + if (settingsMap.containsKey(key)) + text.setText(String.valueOf(calculateCellsPerInch(Double + .valueOf(settingsMap.get(key))))); + } else { + if (settingsMap.containsKey(key)) + text.setText(String.valueOf(calculateLinesPerInch(Double + .valueOf(settingsMap.get(key))))); } } } - - private void setDefault(){- if(settingsMap.containsKey("paperWidth") && settingsMap.containsKey("paperHeight")){
- for(int i = 0; i < sm.getStandardSizes().length; i++){- if(checkEqualWidth(sm.getStandardSizes()[i], Double.valueOf(settingsMap.get("paperWidth"))) && checkEqualHeight(sm.getStandardSizes()[i], Double.valueOf(settingsMap.get("paperHeight")))){
+ + private void setDefault() { + if (settingsMap.containsKey("paperWidth") + && settingsMap.containsKey("paperHeight")) { + for (int i = 0; i < sm.getStandardSizes().length; i++) { + if (checkEqualWidth(sm.getStandardSizes()[i], + Double.valueOf(settingsMap.get("paperWidth"))) + && checkEqualHeight(sm.getStandardSizes()[i], + Double.valueOf(settingsMap.get("paperHeight")))) { pageTypes.select(i); break; } } } } - - public TabItem getTab(){ + + public TabItem getTab() { return item; } - - private double getDoubleValue(Text t){ - if(t.getText().length() == 0) + + private double getDoubleValue(Text t) { + if (t.getText().length() == 0) return 0.0; else return Double.valueOf(t.getText()); } - - private String getStringValue(Text t){ - if(t.getText().length() == 0) + + private String getStringValue(Text t) { + if (t.getText().length() == 0) return "0"; else return t.getText(); } - + public Boolean getRadioSelection() { Boolean isRegional = regionalButton.getSelection(); return isRegional; - + } - public void modifyMargins(){ - - Boolean isRegional = getRadioSelection(); - - if (isRegional){ - - String leftMargin = settingsMap.get("leftMargin"); - marginLeftBox.setText(leftMargin); - - String rightMargin = settingsMap.get("rightMargin"); - marginRightBox.setText(rightMargin); + public void modifyMargins() { - String topMargin = settingsMap.get("topMargin"); - marginTopBox.setText(topMargin); - - String bottomMargin = settingsMap.get("bottomMargin"); - marginBottomBox.setText(bottomMargin); + if (userModified == false) { + Boolean isRegional = getRadioSelection(); - } - - else{ - - String leftMargin = settingsMap.get("leftMargin");- String convertedLeftMargin = String.valueOf(calculateCellsPerLine(Double.valueOf(leftMargin)));
- marginLeftBox.setText(convertedLeftMargin); + if (isRegional) { - String rightMargin = settingsMap.get("rightMargin");- String convertedRightMargin =String.valueOf(calculateCellsPerLine(Double.valueOf(rightMargin)));
- marginRightBox.setText(convertedRightMargin); - - String topMargin = settingsMap.get("topMargin");- String convertedTopMargin = String.valueOf(calculateLinesPerPage(Double.valueOf(topMargin)));
- marginTopBox.setText(convertedTopMargin); - - String bottomMargin = settingsMap.get("bottomMargin");- String convertedBottomMargin = String.valueOf(calculateLinesPerPage(Double.valueOf(bottomMargin)));
- marginBottomBox.setText(convertedBottomMargin); + String leftMargin = settingsMap.get("leftMargin"); + marginLeftBox.setText(leftMargin); - + String rightMargin = settingsMap.get("rightMargin"); + marginRightBox.setText(rightMargin); + + String topMargin = settingsMap.get("topMargin"); + marginTopBox.setText(topMargin); + + String bottomMargin = settingsMap.get("bottomMargin"); + marginBottomBox.setText(bottomMargin); + } -// } - } - - public void saveSettings(String currentUnits){ + + else { + + String leftMargin = settingsMap.get("leftMargin"); + String convertedLeftMargin = String + .valueOf(calculateCellsPerLine(Double + .valueOf(leftMargin))); + marginLeftBox.setText(convertedLeftMargin); + + String rightMargin = settingsMap.get("rightMargin"); + String convertedRightMargin = String + .valueOf(calculateCellsPerLine(Double + .valueOf(rightMargin))); + marginRightBox.setText(convertedRightMargin); + + String topMargin = settingsMap.get("topMargin"); + String convertedTopMargin = String + .valueOf(calculateLinesPerPage(Double + .valueOf(topMargin))); + marginTopBox.setText(convertedTopMargin); + + String bottomMargin = settingsMap.get("bottomMargin"); + String convertedBottomMargin = String + .valueOf(calculateLinesPerPage(Double + .valueOf(bottomMargin))); + marginBottomBox.setText(convertedBottomMargin); + + }// else cellsLines + }// if userModified false + }// modify margins + + public void saveSettings(String currentUnits) { PropertyFileManager pfm = new PropertyFileManager(userSettings); pfm.save("currentUnits", currentUnits); } - private int calculateCellsPerLine(double pWidth){ - - if (!listenerLocked){ - - double cellWidth; - if(!sm.isMetric()) - cellWidth = 0.246063; - else - cellWidth = 6.25; - - if(settingsMap.containsKey("leftMargin")) - pWidth -= Double.valueOf(settingsMap.get("leftMargin")); - - if(settingsMap.containsKey("rightMargin")) - pWidth -= Double.valueOf(settingsMap.get("rightMargin")); - - return (int)(pWidth / cellWidth); - } - else{ + private int calculateCellsPerLine(double pWidth) { + + if (!listenerLocked) { + double cellWidth; - if(!sm.isMetric()) + if (!sm.isMetric()) cellWidth = 0.246063; else cellWidth = 6.25; - - return (int)(pWidth / cellWidth); + + if (settingsMap.containsKey("leftMargin")) + pWidth -= Double.valueOf(settingsMap.get("leftMargin")); + + if (settingsMap.containsKey("rightMargin")) + pWidth -= Double.valueOf(settingsMap.get("rightMargin")); + + return (int) (pWidth / cellWidth); + } else { + double cellWidth; + if (!sm.isMetric()) + cellWidth = 0.246063; + else + cellWidth = 6.25; + + return (int) (pWidth / cellWidth); } - + } - ***The diff for this file has been truncated for email.*** =======================================--- /src/main/org/brailleblaster/util/Notify.java Tue Apr 15 14:34:57 2014 UTC +++ /src/main/org/brailleblaster/util/Notify.java Mon Feb 2 17:23:00 2015 UTC
@@ -59,6 +59,7 @@ Shell shell = new Shell(WPManager.getDisplay(), SWT.DIALOG_TRIM); MessageBox mb = new MessageBox(shell, SWT.OK); mb.setMessage(realMessage); + mb.open(); shell.dispose(); } =======================================--- /src/main/org/brailleblaster/wordprocessor/RecentDocuments.java Mon Dec 1 18:24:59 2014 UTC +++ /src/main/org/brailleblaster/wordprocessor/RecentDocuments.java Mon Feb 2 17:23:00 2015 UTC
@@ -155,7 +155,7 @@ private void processDocsList() {recentDocsArr = recentDocsList.toArray(new String[recentDocsList.size()]);
boolean[] dupArr = new boolean[recentDocsArr.length]; - // for(boolean b:dupArr) b=false; + for(boolean b:dupArr) b=false; for( int i=0; (i < recentDocsArr.length-1)&&(!dupArr[i]);i++) { String s1 = recentDocsArr[i]; int index = s1.lastIndexOf(fileSep); =======================================--- /src/main/org/brailleblaster/wordprocessor/WPManager.java Fri Jan 16 12:34:32 2015 UTC +++ /src/main/org/brailleblaster/wordprocessor/WPManager.java Mon Feb 2 17:23:00 2015 UTC
@@ -152,6 +152,7 @@ display.sleep(); } } catch (Throwable e) { + e.printStackTrace(); logger.error("Uncaught exception detected", e); /* MessageBox questionBox = new MessageBox(this.shell,