Revision: 5df8359170bd Branch: default Author: Brandon Roller <brandon.r.roller@xxxxxxxxx> Date: Wed Jul 31 11:37:51 2013 Log: Added style panel to change semantic in views http://code.google.com/p/brailleblaster/source/detail?r=5df8359170bd&repo=newdesign Added: /src/main/org/brailleblaster/stylePanel/StyleTable.java Modified: /src/main/org/brailleblaster/abstractClasses/AbstractView.java /src/main/org/brailleblaster/document/BBDocument.java /src/main/org/brailleblaster/messages/BBEvent.java /src/main/org/brailleblaster/printers/PrintPreview.java /src/main/org/brailleblaster/stylePanel/EditStyle.java /src/main/org/brailleblaster/stylePanel/StyleManager.java /src/main/org/brailleblaster/stylePanel/StylePanel.java /src/main/org/brailleblaster/util/FileUtils.java /src/main/org/brailleblaster/views/BrailleView.java /src/main/org/brailleblaster/views/TextView.java /src/main/org/brailleblaster/views/TreeView.java /src/main/org/brailleblaster/wordprocessor/BBMenu.java /src/main/org/brailleblaster/wordprocessor/DocumentManager.java /src/main/org/brailleblaster/wordprocessor/WPManager.java ======================================= --- /dev/null+++ /src/main/org/brailleblaster/stylePanel/StyleTable.java Wed Jul 31 11:37:51 2013
@@ -0,0 +1,164 @@ +package org.brailleblaster.stylePanel; + +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.brailleblaster.BBIni; +import org.brailleblaster.util.FileUtils; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableColumn; +import org.eclipse.swt.widgets.TableItem; + +public class StyleTable { + private final static int LEFT_MARGIN = 0; + private final static int RIGHT_MARGIN = 15; + private final static int TOP_MARGIN = 70; + private final static int BOTTOM_MARGIN = 100; + + private Group group; + private Table t; + private Logger logger = BBIni.getLogger(); + private FileUtils fu; + private StyleManager sm; + private Button applyButton; + + public StyleTable(StyleManager sm, Group documentWindow){ + this.fu = new FileUtils(); + this.sm = sm; + this.group = new Group(documentWindow, SWT.FILL | SWT.BORDER);+ setLayoutData(this.group, LEFT_MARGIN, RIGHT_MARGIN, TOP_MARGIN, BOTTOM_MARGIN);
+ this.group.setLayout(new FormLayout()); + this.group.setVisible(false); ++ this.t = new Table(this.group, SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION);
+ setLayoutData(this.t, 0, 100, 0, 90); + + TableColumn tc1 = new TableColumn(this.t, SWT.CENTER); + tc1.setWidth(0); + tc1.setResizable(false); + + final TableColumn tc2 = new TableColumn(this.t, SWT.CENTER); + tc2.setText("Styles"); + + this.t.setLinesVisible(true); + this.t.setHeaderVisible(true); + + // Button newButton = new Button(this.group, SWT.NONE); + // newButton.setText("New"); + // setLayoutData(newButton, 0, 50, 90, 100); + + applyButton = new Button(this.group, SWT.NONE); + applyButton.setText("Apply"); + setLayoutData(applyButton, 0, 100, 90, 100); + + group.pack(); + tc2.setWidth(group.getClientArea().width); + t.getHorizontalBar().dispose(); + + this.group.addListener(SWT.Resize, new Listener(){ + @Override + public void handleEvent(Event e) { + tc2.setWidth(group.getClientArea().width); + } + + }); + populateTable(); + initializeListeners(); + } + + private void initializeListeners(){ + applyButton.addSelectionListener(new SelectionListener(){ + @Override + public void widgetDefaultSelected(SelectionEvent e) { + // TODO Auto-generated method stub + } + + @Override + public void widgetSelected(SelectionEvent e) { + sm.apply(t.getSelection()[0].getText(1)); + } + }); + } ++ private void setLayoutData(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); + } + + public void showTable(){ + group.setVisible(true); + t.setFocus(); + t.setSelection(0); + } + + public void hideTable(){ + group.setVisible(false); + } + + private void populateTable(){ + String defaultName = BBIni.getDefaultConfigFile();+ String fullPath = fu.findInProgramData ("liblouisutdml" + BBIni.getFileSep() + "lbu_files" + BBIni.getFileSep() + defaultName);
+ String currentLine; + + try { + FileReader file = new FileReader(fullPath); + BufferedReader reader = new BufferedReader(file); + + while((currentLine = reader.readLine()) != null){ + if(currentLine.contains("style")){+ if(currentLine.length() >= 5 && currentLine.substring(0, 5).equals("style")){
+ String item = currentLine.substring(6, currentLine.length()).trim(); + if(!item.equals("document")) + addTableItem(item); + } + } + } + reader.close(); + } + catch(FileNotFoundException e){ + e.printStackTrace(); + logger.log(Level.SEVERE, "File Not Found Exception", e); + } + catch(IOException e){ + e.printStackTrace(); + logger.log(Level.SEVERE, "File Not Found Exception", e); + } + } + + private void addTableItem(String item){ + TableItem tItem = new TableItem(t, SWT.CENTER); + tItem.setText(new String[]{"", item}); + } + + public boolean isVisible(){ + return t.isVisible(); + } + + public Table getTable(){ + return t; + } + + public Group getGroup(){ + return group; + } +} =======================================--- /src/main/org/brailleblaster/abstractClasses/AbstractView.java Wed Jul 17 12:21:04 2013 +++ /src/main/org/brailleblaster/abstractClasses/AbstractView.java Wed Jul 31 11:37:51 2013
@@ -97,6 +97,7 @@ public void decrement(DocumentManager dm){ sendDecrementCurrent(dm); } + protected void sendDecrementCurrent(DocumentManager dm){ Message message = new Message(BBEvent.DECREMENT); dm.dispatch(message); @@ -199,8 +200,8 @@ view.setLineAlignment(line, 1, currentAlignment); } - protected void handleLineWrap(String text, int indent){ - int pos = this.spaceBeforeText + this.total; + protected void handleLineWrap(int pos, String text, int indent){ + // int pos = this.spaceBeforeText + this.total; int newPos; int i = 0; while( i < text.length() && text.charAt(i) == '\n'){ @@ -211,7 +212,8 @@ if(text.charAt(i) == '\n' && i != text.length() - 1){ i++; newPos = pos + i;- this.view.setLineIndent(this.view.getLineAtOffset(newPos), 1, this.view.getLineIndent(this.view.getLineAtOffset(newPos)) + (indent * this.charWidth)); + //this.view.setLineIndent(this.view.getLineAtOffset(newPos), 1, this.view.getLineIndent(this.view.getLineAtOffset(newPos)) + (indent * this.charWidth)); + this.view.setLineIndent(this.view.getLineAtOffset(newPos), 1, indent * this.charWidth);
} } } @@ -236,6 +238,13 @@ checkForLineBreak((Element)newParent.getParent(), newParent); } } + + protected int getLineNumber(int startOffset, String text){ + int startLine = view.getLineAtOffset(startOffset); + int endLine = view.getLineAtOffset(startOffset + text.length()); + + return (endLine - startLine) + 1; + } public void setcharWidth(){ this.charWidth = getFontWidth(); =======================================--- /src/main/org/brailleblaster/document/BBDocument.java Mon Jul 22 09:17:20 2013 +++ /src/main/org/brailleblaster/document/BBDocument.java Wed Jul 31 11:37:51 2013
@@ -28,8 +28,11 @@ package org.brailleblaster.document; +import java.io.BufferedReader; import java.io.File; +import java.io.FileNotFoundException; import java.io.FileOutputStream; +import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.StringReader; @@ -64,6 +67,7 @@ public class BBDocument { + private DocumentManager dm; private Document doc; private static String fileSep = BBIni.getFileSep(); private liblouisutdml lutdml = liblouisutdml.getInstance(); @@ -72,8 +76,10 @@ private ArrayList<String>missingSemanticsList; private String systemId; private String publicId; + private int idCount = 0; public BBDocument(DocumentManager dm){ + this.dm = dm; this.missingSemanticsList = new ArrayList<String>(); }public boolean startDocument (InputStream inputStream, String configFile, String configSettings) throws Exception {
@@ -93,10 +99,10 @@configFileWithPath = fu.findInProgramData ("liblouisutdml" + BBIni.getFileSep() + "lbu_files" + BBIni.getFileSep() + configFile);
if (configSettings == null) { - configWithUTD = "formatFor utd\n mode notUC\n printPages no\n";+ configWithUTD = "formatFor utd\n mode notUC\n printPages no\n" + checkForSemantics(completePath);
} else {- configWithUTD = configSettings + "formatFor utd\n mode notUC\n printPages no\n"; + configWithUTD = configSettings + "formatFor utd\n mode notUC\n printPages no\n" + checkForSemantics(completePath);
} String outFile = BBIni.getTempFilesPath() + fileSep + "outFile.utd"; String logFile = BBIni.getLogFilesPath() + fileSep + "liblouisutdml.log"; @@ -535,17 +541,20 @@ } } - public boolean createBrlFile(String filePath){ + public boolean createBrlFile(DocumentManager dm, String filePath){ Document temp = getNewXML(); String inFile = createTempFile(temp);String config = fu.findInProgramData ("liblouisutdml" + BBIni.getFileSep() + "lbu_files" + BBIni.getFileSep() + BBIni.getDefaultConfigFile()); String logFile = BBIni.getTempFilesPath() + fileSep + "liblouisutdml.log";
- + String semFile = ""; if(inFile.equals("")) return false; -- boolean result = lutdml.translateFile (config, inFile, filePath, logFile, "formatFor brf\n", 0);
++ if(fu.exists(BBIni.getTempFilesPath() + BBIni.getFileSep() + fu.getFileName(dm.getWorkingPath()) + ".sem")){ + semFile = "semanticFiles *," + BBIni.getTempFilesPath() + BBIni.getFileSep() + fu.getFileName(dm.getWorkingPath()) + ".sem" + "\n";
+ }+ boolean result = lutdml.translateFile (config, inFile, filePath, logFile, semFile + "formatFor brf\n", 0);
deleteTempFile(inFile); return result; } @@ -598,6 +607,13 @@ return false; } } + + public boolean checkAttribute(Element e, String attribute){ + if(e.getAttribute("id") != null) + return true; + else + return false; + } public void checkSemantics(Element e){ if(e.getAttributeValue("semantics") == null){ @@ -646,4 +662,105 @@ if(this.doc.getDocType() == null)d.setDocType(new DocType(this.getRootElement().getLocalName(), publicId, systemId));
} + + public void changeSemanticAction(Message m, TextMapElement t){+ org.brailleblaster.document.BBSemanticsTable.Styles style = (org.brailleblaster.document.BBSemanticsTable.Styles)m.getValue("Style");
+ String name = style.getName(); + Element e = (Element)t.n.getParent(); + Attribute attr = e.getAttribute("semantics"); + while(attr.getValue().contains("action")){ + e = (Element)e.getParent(); + attr = e.getAttribute("semantics"); + } + attr.setValue("style," + name); + if(checkAttribute(e, "id")){ + String fileName = fu.getFileName(dm.getWorkingPath());+ String file = BBIni.getTempFilesPath() + BBIni.getFileSep() + fileName + ".sem";
+ if(fu.exists(file)) + appendEntry(file, name, e.getLocalName(),e.getAttributeValue("id")); + else {+ createNewSemanticsFile(file, name, e.getLocalName(),e.getAttributeValue("id"));
+ } + } + else {+ e.addAttribute(new Attribute("id", BBIni.getInstanceID() + "_" + idCount));
+ String fileName = fu.getFileName(dm.getWorkingPath());+ String file = BBIni.getTempFilesPath() + BBIni.getFileSep() + fileName + ".sem";
+ + if(fu.exists(file))+ appendEntry(file, name, e.getLocalName(), BBIni.getInstanceID() + "_" + idCount);
+ else {+ createNewSemanticsFile(file, name, e.getLocalName(), BBIni.getInstanceID() + "_" + idCount);
+ } + + idCount++; + } + } ++ private void appendEntry(String path, String style, String element, String id){
+ String text = style + " " + element + ",id," + id + "\n"; + writeSemanticEntry(path, id, text); + } ++ private void createNewSemanticsFile(String path, String style, String element, String id){
+ String text = style + " " + element + ",id," + id + "\n"; + fu.create(path); + fu.writeToFile(path, text); + } + + private String checkForSemantics(String filePath){ + String file = filePath.substring(0, filePath.lastIndexOf(".")) + ".sem"; + String fileName = fu.getFileName(filePath) + ".sem";+ String tempFile = BBIni.getTempFilesPath() + BBIni.getFileSep() + fileName;
+ if(fu.exists(file)){ + fu.copyFile(file, tempFile); + return "semanticFiles *," + tempFile + "\n "; + } + else + return ""; + } + + private void writeSemanticEntry(String fullPath, String id, String entry){ + String currentLine; + String [] tokens; + StringBuilder sb= new StringBuilder(); + boolean found = false; + boolean entered = false; + + try { + FileReader file = new FileReader(fullPath); + BufferedReader reader = new BufferedReader(file); + while((currentLine = reader.readLine()) != null){ + tokens = currentLine.split(","); + for(int i = 0; i < tokens.length && !found; i++){ + if(tokens[i].equals(id)){ + found = true; + } + } + + if(found && !entered){ + sb.append(entry); + entered = true; + } + else { + sb.append(currentLine + "\n"); + } + + } + + if(!found){ + sb.append(entry); + } + reader.close(); + fu.writeToFile(fullPath, sb); + } + catch(FileNotFoundException e){ + e.printStackTrace(); + logger.log(Level.SEVERE, "File Not Found Exception", e); + } + catch(IOException e){ + e.printStackTrace(); + logger.log(Level.SEVERE, "IO Exception", e); + } + } } =======================================--- /src/main/org/brailleblaster/messages/BBEvent.java Wed Jul 17 12:21:04 2013 +++ /src/main/org/brailleblaster/messages/BBEvent.java Wed Jul 31 11:37:51 2013
@@ -42,5 +42,6 @@ UPDATE_STATUSBAR, UPDATE_CURSORS, UPDATE_SCROLLBAR, + UPDATE_STYLE, ADJUST_RANGE; } =======================================--- /src/main/org/brailleblaster/printers/PrintPreview.java Wed Jul 17 12:21:04 2013 +++ /src/main/org/brailleblaster/printers/PrintPreview.java Wed Jul 31 11:37:51 2013
@@ -44,9 +44,9 @@ this.view.setEditable(false); } - public void setPreviewText(BBDocument doc){ + public void setPreviewText(DocumentManager dm, BBDocument doc){String tempFilePath = BBIni.getTempFilesPath() + BBIni.getFileSep() + "tempBRF.brf";
- if(doc.createBrlFile(tempFilePath)){ + if(doc.createBrlFile(dm, tempFilePath)){ try { this.f = new File(tempFilePath); Scanner scanner = new Scanner(this.f); @@ -90,7 +90,7 @@ } } - public PrintPreview(Display display, BBDocument doc){ + public PrintPreview(Display display, BBDocument doc, DocumentManager dm){ this.doc = doc; this.shell = new Shell(display, SWT.SHELL_TRIM); @@ -127,6 +127,6 @@ } }); - this.previewText.setPreviewText(this.doc); + this.previewText.setPreviewText(dm, this.doc); } } =======================================--- /src/main/org/brailleblaster/stylePanel/EditStyle.java Mon Jul 29 06:13:08 2013 +++ /src/main/org/brailleblaster/stylePanel/EditStyle.java Wed Jul 31 11:37:51 2013
@@ -122,7 +122,7 @@ } EditStyle (final StyleManager styleManager) { - this (styleManager.dm.getShell(), SWT.NONE); + this (styleManager.dm.getWPManager().getShell(), SWT.NONE); this.sm = styleManager; fileSep = BBIni.getFileSep(); stylePath = BBIni.getStylePath(); =======================================--- /src/main/org/brailleblaster/stylePanel/StyleManager.java Mon Jul 29 06:13:08 2013 +++ /src/main/org/brailleblaster/stylePanel/StyleManager.java Wed Jul 31 11:37:51 2013
@@ -31,21 +31,31 @@ package org.brailleblaster.stylePanel; -import org.brailleblaster.wordprocessor.WPManager; +import java.util.logging.Logger; + +import org.brailleblaster.BBIni; +import org.brailleblaster.document.BBSemanticsTable; +import org.brailleblaster.document.BBSemanticsTable.Styles; +import org.brailleblaster.messages.BBEvent; +import org.brailleblaster.messages.Message; +import org.brailleblaster.views.PropertyView; +import org.brailleblaster.wordprocessor.DocumentManager; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Table; public class StyleManager{ StylePanel sp; - WPManager dm; - -// public StyleManager(DocumentManager dm){ -// this.dm = dm; -// sp = new StylePanel(this); -// } - - public StyleManager(WPManager wpManager) { - this.dm = wpManager; - sp = new StylePanel(this); + StyleTable table; + PropertyView propView; + DocumentManager dm; + Logger logger = BBIni.getLogger(); + private BBSemanticsTable semanticsTable; + + public StyleManager(DocumentManager dm) { + this.dm = dm; + this.table = new StyleTable(this, dm.getGroup()); + this.semanticsTable = new BBSemanticsTable(); } void createStyle(String styleName){ @@ -65,4 +75,33 @@ void readStyleFiles(String styleName){ sp.readStyleFiles(styleName); } + + public void displayTable(){ + table.showTable(); + } + + public void apply(String item){ + Message m = new Message(BBEvent.UPDATE_STYLE); + Styles style = semanticsTable.get(item); + if(style != null){ + m.put("Style", style); + dm.dispatch(m); + } + } + + public boolean tableIsVisible(){ + return table.isVisible(); + } + + public Table getTable(){ + return table.getTable(); + } + + public Group getGroup(){ + return table.getGroup(); + } + + public void hideTable(){ + table.hideTable(); + } } =======================================--- /src/main/org/brailleblaster/stylePanel/StylePanel.java Mon Jul 29 06:13:08 2013 +++ /src/main/org/brailleblaster/stylePanel/StylePanel.java Wed Jul 31 11:37:51 2013
@@ -113,7 +113,7 @@ // readStyleFiles("default"); // } StylePanel(StyleManager styleManager) { - this(styleManager.dm.getShell(), SWT.NONE); + this(styleManager.dm.getWPManager().getShell(), SWT.NONE); this.sm = styleManager; display = styleManager.dm.getDisplay(); fileSep = BBIni.getFileSep(); =======================================--- /src/main/org/brailleblaster/util/FileUtils.java Tue Feb 5 20:32:57 2013 +++ /src/main/org/brailleblaster/util/FileUtils.java Wed Jul 31 11:37:51 2013
@@ -31,9 +31,11 @@ package org.brailleblaster.util; +import java.io.BufferedWriter; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; +import java.io.FileWriter; import java.io.IOException; import java.io.FileNotFoundException; import org.brailleblaster.BBIni; @@ -184,6 +186,52 @@ public boolean writeToUserProgrramData (String partialPath) { return true; } +/* +public void appendToFile(String path, String text){ + File f = new File(path); + if(f.exists()){ + try { + FileWriter out = new FileWriter(f, true); + out.write(text); + out.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } +} +*/ +public void writeToFile(String path, String text){ + FileWriter fw; + try { + fw = new FileWriter(new File(path)); + BufferedWriter writer = new BufferedWriter(fw); + writer.write(text); + writer.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } +} +public void writeToFile(String path, StringBuilder sb){ + FileWriter fw; + try { + fw = new FileWriter(new File(path)); + BufferedWriter writer = new BufferedWriter(fw); + writer.append(sb); + writer.close(); + } catch (IOException e) { + e.printStackTrace(); + } +} + +//Returns file name minus path and extension +public String getFileName(String path){+ return path.substring(path.lastIndexOf(BBIni.getFileSep()) + 1, path.lastIndexOf("."));
+} + +public String getPath(String path){ + return path.substring(0, path.lastIndexOf(BBIni.getFileSep())); +} } =======================================--- /src/main/org/brailleblaster/views/BrailleView.java Tue Jul 30 09:24:22 2013 +++ /src/main/org/brailleblaster/views/BrailleView.java Wed Jul 31 11:37:51 2013
@@ -81,7 +81,7 @@ private SelectionListener selectionListener; public BrailleView(Group documentWindow, BBSemanticsTable table) { - super(documentWindow, 58, 100, 0, 100);+ super(documentWindow, LEFT_MARGIN, RIGHT_MARGIN, TOP_MARGIN, BOTTOM_MARGIN);
this.total = 0; this.spaceBeforeText = 0; this.spaceAfterText = 0; @@ -242,7 +242,7 @@ String textBefore = ""; String text = n.getValue(); int textLength = text.length(); - + if(insertNewLine(n)){ // view.append("\n"); // this.total++; @@ -315,7 +315,8 @@ break; case leftMargin: if(!isFirst(n) && followsNewLine(n))- this.view.setLineIndent(this.view.getLineAtOffset(this.spaceBeforeText + this.total), 1, this.view.getLineIndent(this.view.getLineAtOffset(this.spaceBeforeText + this.total))+ (Integer.valueOf(entry.getValue()) * getFontWidth())); + //this.view.setLineIndent(this.view.getLineAtOffset(this.spaceBeforeText + this.total), 1, this.view.getLineIndent(this.view.getLineAtOffset(this.spaceBeforeText + this.total))+ (Integer.valueOf(entry.getValue()) * getFontWidth())); + this.view.setLineIndent(this.view.getLineAtOffset(this.spaceBeforeText + this.total), 1, (Integer.valueOf(entry.getValue()) * this.charWidth));
break; default: System.out.println(entry.getKey()); @@ -323,6 +324,136 @@ } } + public void adjustStyle(DocumentManager dm, Message m, TextMapElement t){ + int length = 0; + int spaces = 0; + int offset = 0; + int indent = 0; + int prev = 0; + int next = 0; + String textBefore = ""; + Styles style = (Styles)m.getValue("Style"); + + setListenerLock(true); + view.setRedraw(false); ++ view.setLineIndent(view.getLineAtOffset(currentStart), getLineNumber(currentStart, view.getTextRange(currentStart, (currentEnd - currentStart))), 0); + view.setLineAlignment(view.getLineAtOffset(currentStart), getLineNumber(currentStart, view.getTextRange(currentStart, (currentEnd - currentStart))), SWT.LEFT);
+ + for (Entry<StylesType, String> entry : style.getEntrySet()) { + switch(entry.getKey()){ + case linesBefore: + saveStyleState(currentStart); + if(-1 != previousEnd){ + prev = previousEnd; + } + + indent = view.getLineIndent(view.getLineAtOffset(currentStart)); + if(currentStart != prev){ + view.replaceTextRange(prev, (currentStart - prev), ""); + length = currentStart - prev; + } + spaces = Integer.valueOf(entry.getValue()); + if(previousEnd == -1){ + textBefore = makeInsertionString(spaces,'\n'); + offset = spaces - length; + } + else { + textBefore = makeInsertionString(spaces + 1,'\n'); + offset = (spaces + 1) - length; + } + insertBefore(currentStart - (currentStart - prev), textBefore); + currentStart += offset; + currentEnd += offset; + nextStart += offset;+ this.view.setLineIndent(view.getLineAtOffset(currentStart), 1, indent);
+ restoreStyleState(currentStart); + break; + case linesAfter: + if(-1 != nextStart){ + next = nextStart; + indent = view.getLineIndent(view.getLineAtOffset(next)); + saveStyleState(currentStart); + } + else { + nextStart = currentEnd; + } + + if(currentEnd != next && next != 0){ + view.replaceTextRange(currentEnd, (next - currentEnd), ""); + length = next - currentEnd; + } + spaces = Integer.valueOf(entry.getValue()); + textBefore = makeInsertionString(spaces + 1,'\n'); + insertBefore(currentEnd, textBefore); + offset = (spaces + 1) - length; + nextStart += offset; + if(nextStart != -1){ + this.view.setLineIndent(view.getLineAtOffset(nextStart), 1, indent); + restoreStyleState(currentStart); + } + break; + case format:+ this.view.setLineAlignment(this.view.getLineAtOffset(currentStart), getLineNumber(currentStart, view.getTextRange(currentStart, (currentEnd - currentStart))), Integer.valueOf(entry.getValue()));
+ break; + case firstLineIndent:+ this.view.setLineIndent(view.getLineAtOffset(currentStart), 1, Integer.valueOf(entry.getValue()) * this.charWidth);
+ break; + case leftMargin:+ handleLineWrap(currentStart, view.getTextRange(currentStart, (currentEnd - currentStart)), Integer.valueOf(entry.getValue()));
+ break; + default: + break; + } + } + + if(!style.contains(StylesType.linesBefore)){ + if(-1 != previousEnd){ + prev = previousEnd; + } + + if(currentStart != prev){ + indent = view.getLineIndent(view.getLineAtOffset(currentStart)); + view.replaceTextRange(prev, (currentStart - prev), ""); + length = currentStart - prev; + } + if(isFirst(t.brailleList.getFirst().n)){ + spaces = 1; + textBefore = makeInsertionString(spaces,'\n'); + offset = spaces - length; + + insertBefore(currentStart - (currentStart - prev), textBefore); + m.put("linesBeforeOffset", offset); + currentStart += offset; + currentEnd += offset; + nextStart += offset; + this.view.setLineIndent(view.getLineAtOffset(currentStart), 1, indent); + } + } + + if(!style.contains(StylesType.linesAfter)){ + if(currentEnd != nextStart && nextStart != -1){ + indent = view.getLineIndent(view.getLineAtOffset(nextStart)); + view.replaceTextRange(currentEnd, (nextStart - currentEnd), ""); + length = nextStart - currentEnd; + } + + if(isLast(t.brailleList.getLast().n)){ + spaces = 1; + textBefore = makeInsertionString(1,'\n'); + insertBefore(currentEnd, textBefore); + offset = spaces - length; + m.put("linesAfterOffset", offset); + nextStart += offset; + if(nextStart != -1) + this.view.setLineIndent(view.getLineAtOffset(nextStart), 1, indent); + } + } + view.setRedraw(true); + setListenerLock(false); + } + + private boolean followsNewLine(Node n){ Element parent = (Element)n.getParent(); int index = parent.indexOf(n); @@ -374,7 +505,8 @@ private boolean isFirstElement(Element child){ Element parent = (Element)child.getParent();- while(!this.stylesTable.getKeyFromAttribute(parent).equals("para") && !this.stylesTable.getKeyFromAttribute(parent).equals("list")){ + //while(!this.stylesTable.getKeyFromAttribute(parent).equals("para") && !this.stylesTable.getKeyFromAttribute(parent).equals("list")){
+ while(parent.getAttributeValue("semantics").contains("action")){ if(parent.indexOf(child) != 0) return false; =======================================--- /src/main/org/brailleblaster/views/TextView.java Tue Jul 23 08:38:11 2013 +++ /src/main/org/brailleblaster/views/TextView.java Wed Jul 31 11:37:51 2013
@@ -605,20 +605,13 @@setFontRange(this.total, this.spaceBeforeText + viewText.length(), Integer.valueOf(entry.getValue()));
break; case leftMargin: - handleLineWrap( viewText, Integer.valueOf(entry.getValue()));+ handleLineWrap(this.spaceBeforeText + this.total, viewText, Integer.valueOf(entry.getValue()));
break; default: System.out.println(entry.getKey()); } } } - - private int getLineNumber(int startOffset, String text){ - int startLine = view.getLineAtOffset(startOffset); - int endLine = view.getLineAtOffset(startOffset + text.length()); - - return (endLine - startLine) + 1; - } private void handleTextEdit(DocumentManager dm, ExtendedModifyEvent e){ int changes = e.length; @@ -862,7 +855,8 @@ private boolean isFirstElement(Element child){ Element parent = (Element)child.getParent();- while(!this.stylesTable.getKeyFromAttribute(parent).equals("para") && !this.stylesTable.getKeyFromAttribute(parent).equals("list")){ + //while(!this.stylesTable.getKeyFromAttribute(parent).equals("para") && !this.stylesTable.getKeyFromAttribute(parent).equals("list")){
+ while(parent.getAttributeValue("semantics").contains("action")){ if(parent.indexOf(child) != 0) return false; @@ -1013,6 +1007,137 @@ selectionStart = start; selectionLength = length; } + + public void adjustStyle(DocumentManager dm, Message m, Node n){ + int length = 0; + int spaces = 0; + int offset = 0; + int indent = 0; + int prev = 0; + int next = 0; + String textBefore = ""; + Styles style = (Styles)m.getValue("Style"); ++ view.setLineIndent(view.getLineAtOffset(currentStart), getLineNumber(currentStart, view.getTextRange(currentStart, (currentEnd - currentStart))), 0); + view.setLineAlignment(view.getLineAtOffset(currentStart), getLineNumber(currentStart, view.getTextRange(currentStart, (currentEnd - currentStart))), SWT.LEFT);
+ + setListenerLock(true); + view.setRedraw(false); + + for (Entry<StylesType, String> entry : style.getEntrySet()) { + switch(entry.getKey()){ + case linesBefore: + saveStyleState(currentStart); + if(-1 != previousEnd){ + prev = previousEnd; + } + indent = view.getLineIndent(view.getLineAtOffset(currentStart)); + if(currentStart != prev){ + view.replaceTextRange(prev, (currentStart - prev), ""); + length = currentStart - prev; + } + spaces = Integer.valueOf(entry.getValue()); + if(previousEnd == -1){ + textBefore = makeInsertionString(spaces,'\n'); + offset = spaces - length; + } + else { + textBefore = makeInsertionString(spaces + 1,'\n'); + offset = (spaces + 1) - length; + } + insertBefore(currentStart - (currentStart - prev), textBefore); + m.put("linesBeforeOffset", offset); + currentStart += offset; + currentEnd += offset; + nextStart += offset;+ this.view.setLineIndent(view.getLineAtOffset(currentStart), 1, indent);
+ restoreStyleState(currentStart); + break; + case linesAfter: + if(-1 != nextStart){ + next = nextStart; + saveStyleState(currentStart); + indent = view.getLineIndent(view.getLineAtOffset(next)); + } + else { + next = currentEnd; + } + + if(currentEnd != next && next != 0){ + view.replaceTextRange(currentEnd, (next - currentEnd), ""); + length = next - currentEnd; + } + spaces = Integer.valueOf(entry.getValue()); + textBefore = makeInsertionString(spaces + 1,'\n'); + insertBefore(currentEnd, textBefore); + offset = (spaces + 1) - length; + m.put("linesAfterOffset", offset); + nextStart += offset; + if(nextStart != -1){ + this.view.setLineIndent(view.getLineAtOffset(nextStart), 1, indent); + restoreStyleState(currentStart); + } + break; + case format:+ this.view.setLineAlignment(this.view.getLineAtOffset(currentStart), getLineNumber(currentStart, view.getTextRange(currentStart, (currentEnd - currentStart))), Integer.valueOf(entry.getValue()));
+ break; + case firstLineIndent:+ this.view.setLineIndent(view.getLineAtOffset(currentStart), 1, Integer.valueOf(entry.getValue()) * this.charWidth);
+ break; + case leftMargin:+ handleLineWrap(currentStart, view.getTextRange(currentStart, (currentEnd - currentStart)), Integer.valueOf(entry.getValue()));
+ break; + default: + break; + } + } + + if(!style.contains(StylesType.linesBefore)){ + if(-1 != previousEnd){ + prev = previousEnd; + } + + if(currentStart != prev){ + indent = view.getLineIndent(view.getLineAtOffset(currentStart)); + view.replaceTextRange(prev, (currentStart - prev), ""); + length = currentStart - prev; + } + if(isFirst(n)){ + spaces = 1; + textBefore = makeInsertionString(spaces,'\n'); + offset = spaces - length; + + insertBefore(currentStart - (currentStart - prev), textBefore); + m.put("linesBeforeOffset", offset); + currentStart += offset; + currentEnd += offset; + nextStart += offset; + this.view.setLineIndent(view.getLineAtOffset(currentStart), 1, indent); + } + } + + if(!style.contains(StylesType.linesAfter)){ + if(currentEnd != nextStart && nextStart != -1){ + indent = view.getLineIndent(view.getLineAtOffset(nextStart)); + view.replaceTextRange(currentEnd, (nextStart - currentEnd), ""); + length = nextStart - currentEnd; + } + + if(isLast(n)){ + spaces = 1; + textBefore = makeInsertionString(1,'\n'); + insertBefore(currentEnd, textBefore); + offset = spaces - length; + m.put("linesAfterOffset", offset); + nextStart += offset; + if(nextStart != -1) + this.view.setLineIndent(view.getLineAtOffset(nextStart), 1, indent); + } + } + + view.setRedraw(true); + setListenerLock(false); + } public void resetView(Group group) { =======================================--- /src/main/org/brailleblaster/views/TreeView.java Mon Jul 22 12:05:58 2013 +++ /src/main/org/brailleblaster/views/TreeView.java Wed Jul 31 11:37:51 2013
@@ -47,12 +47,16 @@ import org.eclipse.swt.SWT; import org.eclipse.swt.events.FocusEvent; import org.eclipse.swt.events.FocusListener; +import org.eclipse.swt.events.MenuEvent; +import org.eclipse.swt.events.MenuListener; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.events.TraverseEvent; import org.eclipse.swt.events.TraverseListener; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.MenuItem; import org.eclipse.swt.widgets.Tree; import org.eclipse.swt.widgets.TreeItem; @@ -72,18 +76,41 @@ private final static int RIGHT_MARGIN = 15; private final static int TOP_MARGIN = 0; private final static int BOTTOM_MARGIN = 100; + private final static int ADJUSTED_BOTTOM_MARGIN = 69; public Tree tree; private TreeItem root, previousItem; + private Menu menu; private FocusListener treeFocusListener; private SelectionListener selectionListener; private TraverseListener traverseListener; + private Group group; public TreeView(final DocumentManager dm, Group documentWindow){super(documentWindow, LEFT_MARGIN, RIGHT_MARGIN, TOP_MARGIN, BOTTOM_MARGIN);
+ this.group = documentWindow; this.tree = new Tree(view, SWT.VIRTUAL | SWT.NONE); + this.menu = new Menu(tree); + MenuItem item = new MenuItem(menu, SWT.NONE); + item.setText("Edit Element Style"); + + item.addSelectionListener(new SelectionListener(){ + @Override + public void widgetDefaultSelected(SelectionEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void widgetSelected(SelectionEvent e) { + dm.toggleAttributeEditor(); + } + }); + + this.tree.setMenu(this.menu); + view.setLayout(new FillLayout()); view.getVerticalBar().dispose(); view.getHorizontalBar().dispose(); @@ -98,6 +125,7 @@ } }); + this.tree.pack(); } @@ -541,4 +569,13 @@ this.previousItem = null; setListenerLock(false); } + + public void adjustLayout(boolean fullSize){ + if(fullSize) + setLayout(LEFT_MARGIN, RIGHT_MARGIN, TOP_MARGIN, BOTTOM_MARGIN); + else+ setLayout(LEFT_MARGIN, RIGHT_MARGIN, TOP_MARGIN, ADJUSTED_BOTTOM_MARGIN);
+ + group.layout(); + } } =======================================--- /src/main/org/brailleblaster/wordprocessor/BBMenu.java Mon Jul 22 09:17:20 2013 +++ /src/main/org/brailleblaster/wordprocessor/BBMenu.java Wed Jul 31 11:37:51 2013
@@ -491,19 +491,19 @@ stylePanelItem.setText(lh.localValue("&StylePanel")); stylePanelItem.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { -// dm.getStyleManager().stylePanel(); if (BBIni.debugging()) { } else { - wp.getStyleManager().stylePanel(); + int index= wp.getFolder().getSelectionIndex(); + if(index != -1){ + wp.getList().get(index).toggleAttributeEditor(); + } } - -// System.out.println("Empty method"); - System.out.println("Open Style Panel"); } }); -assocSelectionItem = new MenuItem(editMenu, SWT.PUSH); + + assocSelectionItem = new MenuItem(editMenu, SWT.PUSH); assocSelectionItem.setText(lh.localValue("&AssocSelection")); assocSelectionItem.setEnabled(false); assocSelectionItem.addSelectionListener(new SelectionAdapter() { =======================================--- /src/main/org/brailleblaster/wordprocessor/DocumentManager.java Tue Jul 30 08:31:56 2013 +++ /src/main/org/brailleblaster/wordprocessor/DocumentManager.java Wed Jul 31 11:37:51 2013
@@ -59,6 +59,8 @@ import org.brailleblaster.messages.Message; import org.brailleblaster.printers.PrintPreview; import org.brailleblaster.printers.PrintersManager; +import org.brailleblaster.stylePanel.StyleManager; +import org.brailleblaster.util.FileUtils; import org.brailleblaster.util.Notify; import org.brailleblaster.util.YesNoChoice; import org.brailleblaster.util.Zipper; @@ -86,6 +88,7 @@ TreeView treeView; TextView text; BrailleView braille; + StyleManager sm; FormLayout layout; Control [] tabList; BBSemanticsTable styles; @@ -102,16 +105,19 @@ MapList list; String zippedPath; String workingFilePath; + FileUtils fu; //Constructor that sets things up for a new document. DocumentManager(WPManager wp, String docName) { + this.fu = new FileUtils(); this.styles = new BBSemanticsTable(); this.documentName = docName; this.list = new MapList(this); this.wp = wp; this.item = new TabItem(wp.getFolder(), 0); this.group = new Group(wp.getFolder(),SWT.NONE); - this.group.setLayout(new FormLayout()); + this.group.setLayout(new FormLayout()); + this.sm = new StyleManager(this); this.treeView = new TreeView(this, this.group); this.text = new TextView(this.group, this.styles); this.braille = new BrailleView(this.group, this.styles); @@ -134,10 +140,19 @@ private void initializeDocumentTab(){ FontManager.setShellFonts(this.wp.getShell(), this);- this.tabList = new Control[]{this.treeView.view, this.text.view, this.braille.view};
- this.group.setTabList(this.tabList); + setTabList(); wp.getShell().layout(); } + + private void setTabList(){ + if(sm.tableIsVisible()){+ this.tabList = new Control[]{this.treeView.view, this.sm.getGroup(), this.text.view, this.braille.view};
+ } + else {+ this.tabList = new Control[]{this.treeView.view, this.text.view, this.braille.view};
+ } + this.group.setTabList(this.tabList); + } public void fileSave(){ // Borrowed from Save As function. Different document types require @@ -145,6 +160,10 @@ try { if(workingFilePath.endsWith("xml")){ createXMLFile(workingFilePath);+ String tempSemFile = BBIni.getTempFilesPath() + BBIni.getFileSep() + fu.getFileName(workingFilePath) + ".sem";
+ if(fu.exists(tempSemFile)){+ fu.copyFile(tempSemFile, fu.getPath(workingFilePath) + BBIni.getFileSep() + fu.getFileName(workingFilePath) + ".sem");
+ } } else if(workingFilePath.endsWith("utd")) { this.document.setOriginalDocType(this.document.getDOM()); @@ -154,7 +173,7 @@ os.close(); } else if(workingFilePath.endsWith("brf")){ - if(!this.document.createBrlFile(workingFilePath)){ + if(!this.document.createBrlFile(this, workingFilePath)){new Notify("An error has occurred. Please check your original document");
} } @@ -254,12 +273,12 @@ // Zip and Recent Files. //////////////////////// - initializeAllViews(fileName, workingFilePath); + initializeAllViews(fileName, workingFilePath, null); } - private void initializeAllViews(String fileName, String filePath){+ private void initializeAllViews(String fileName, String filePath, String configSettings){
try{- if(this.document.startDocument(filePath, BBIni.getDefaultConfigFile(), null)){ + if(this.document.startDocument(filePath, BBIni.getDefaultConfigFile(), configSettings)){
this.group.setRedraw(false); this.text.view.setWordWrap(false); this.braille.view.setWordWrap(false); @@ -394,6 +413,7 @@ list.getCurrentNodeData(message); this.treeView.setSelection(list.getCurrent(), message, this); } + // propertyView.populateView(list.getCurrent().n); resetCursorData(); } break; @@ -461,6 +481,20 @@ index = list.findClosest(message, 0, list.size() - 1); this.braille.positionScrollbar(this.text.view.getTopIndex()); } + break; + case UPDATE_STYLE: + if(this.document.getDOM() != null){ + this.text.adjustStyle(this, message, list.getCurrent().n); + this.braille.adjustStyle(this, message, list.getCurrent()); + if(message.contains("linesBeforeOffset")){+ list.shiftOffsetsFromIndex(list.getCurrentIndex(), (Integer)message.getValue("linesBeforeOffset"));
+ } + + if(message.contains("linesAfterOffset")){+ list.shiftOffsetsFromIndex(list.getCurrentIndex() + 1, (Integer)message.getValue("linesAfterOffset"));
+ } + this.document.changeSemanticAction(message, list.getCurrent()); + } break; default: break; @@ -486,7 +520,7 @@ String ext = getFileExt(filePath); try { if(ext.equals("brf")){ - if(!this.document.createBrlFile(filePath)){ + if(!this.document.createBrlFile(this, filePath)){new Notify("An error has occurred. Please check your original document");
} } @@ -494,6 +528,15 @@ createXMLFile(filePath); setTabTitle(filePath); this.documentName = filePath;+ String tempSemFile = BBIni.getTempFilesPath() + BBIni.getFileSep() + fu.getFileName(workingFilePath) + ".sem";
+ if(fu.exists(tempSemFile)){+ fu.copyFile(tempSemFile, fu.getPath(filePath) + BBIni.getFileSep() + fu.getFileName(filePath) + ".sem");
+ } + workingFilePath = filePath;+ if(fu.exists(fu.getPath(filePath) + BBIni.getFileSep() + fu.getFileName(filePath) + ".sem")){ + fu.copyFile(tempSemFile, BBIni.getTempFilesPath() + BBIni.getFileSep() + fu.getFileName(filePath) + ".sem");
+ } + } else if(ext.equals("utd")) { this.document.setOriginalDocType(this.document.getDOM()); @@ -503,6 +546,14 @@ os.close(); setTabTitle(filePath); this.documentName = filePath;+ String tempSemFile = BBIni.getTempFilesPath() + BBIni.getFileSep() + fu.getFileName(workingFilePath) + ".sem";
+ if(fu.exists(tempSemFile)){+ fu.copyFile(tempSemFile, fu.getPath(filePath) + BBIni.getFileSep() + fu.getFileName(filePath) + ".sem");
+ } + workingFilePath = filePath;+ if(fu.exists(fu.getPath(filePath) + BBIni.getFileSep() + fu.getFileName(filePath) + ".sem")){ + fu.copyFile(tempSemFile, BBIni.getTempFilesPath() + BBIni.getFileSep() + fu.getFileName(filePath) + ".sem");
+ } } } catch (IOException e) { @@ -601,7 +652,7 @@ }String filePath = BBIni.getTempFilesPath() + BBIni.getFileSep() + "tempBRF.brf";
- if(this.document.createBrlFile(filePath)){ + if(this.document.createBrlFile(this, filePath)){ File translatedFile = new File(filePath); PrinterDevice embosserDevice; try { @@ -617,7 +668,7 @@ public void printPreview(){ if(this.braille.view.getCharCount() > 0){ - new PrintPreview(this.getDisplay(), this.document); + new PrintPreview(this.getDisplay(), this.document, this); } } @@ -696,7 +747,10 @@ this.text.words = 0; updateTempFile(); this.document.deleteDOM(); - initializeAllViews(this.documentName, path);+ if(fu.exists(BBIni.getTempFilesPath() + BBIni.getFileSep() + fu.getFileName(workingFilePath) + ".sem")) + initializeAllViews(this.documentName, path, "semanticFiles *," + BBIni.getTempFilesPath() + BBIni.getFileSep() + fu.getFileName(workingFilePath) + ".sem\n");
+ else + initializeAllViews(this.documentName, path, null); f.delete(); } catch (IOException e) { @@ -758,6 +812,21 @@ return false; } + + public void toggleAttributeEditor(){ + if(!sm.tableIsVisible()){ + this.treeView.adjustLayout(false); + this.sm.displayTable(); + setTabList(); + } + else { + this.treeView.adjustLayout(true); + this.sm.hideTable(); + setTabList(); + } + // this.propertyView.populateView(list.getCurrent().n); + // this.propertyView.setFocus(); + } public void toggleBrailleFont(){ FontManager.toggleBrailleFont(this.wp, this); @@ -778,6 +847,14 @@ public WPManager getWPManager(){ return this.wp; } + + public Group getGroup(){ + return this.group; + } + + public String getDocumentName(){ + return this.documentName; + } public String getWorkingPath(){ return this.workingFilePath; =======================================--- /src/main/org/brailleblaster/wordprocessor/WPManager.java Mon Jul 29 06:13:08 2013 +++ /src/main/org/brailleblaster/wordprocessor/WPManager.java Wed Jul 31 11:37:51 2013
@@ -31,7 +31,6 @@ import org.eclipse.swt.*; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.graphics.DeviceData; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.layout.FormAttachment; import org.eclipse.swt.layout.FormData; @@ -47,6 +46,7 @@ import org.brailleblaster.stylePanel.StyleManager; import org.brailleblaster.util.YesNoChoice; + import java.util.LinkedList; public class WPManager { @@ -64,7 +64,6 @@ private BBProgressBar pb; private BBToolBar toolBar; private LinkedList<DocumentManager> managerList; - private StyleManager sm;private static final int MAX_NUM_DOCS = 4;//the max limit of total number of docs can have at the same time
//This constructor is the entry point to the word processor. It gets things set up, handles multiple documents, etc.
@@ -88,8 +87,6 @@ this.pb = new BBProgressBar(this.shell); this.bbMenu = new BBMenu(this); - this.sm = new StyleManager(this); - // Toolbar. toolBar = new BBToolBar(shell, this); @@ -221,8 +218,4 @@ public BBProgressBar getProgressBar(){ return this.pb; } - - public StyleManager getStyleManager() { - return sm; - } }