Revision: bbd69144acb5 Branch: default Author: Brandon Roller <brandon.r.roller@xxxxxxxxx> Date: Mon Jul 29 06:13:08 2013 Log: Created a StylePanel package http://code.google.com/p/brailleblaster/source/detail?r=bbd69144acb5&repo=newdesign Added: /src/main/org/brailleblaster/stylePanel/EditStyle.java /src/main/org/brailleblaster/stylePanel/Style.java /src/main/org/brailleblaster/stylePanel/StyleManager.java /src/main/org/brailleblaster/stylePanel/StylePanel.java /src/main/org/brailleblaster/stylePanel/StyleProperty.java Deleted: /src/main/org/brailleblaster/wordprocessor/EditStyle.java /src/main/org/brailleblaster/wordprocessor/Style.java /src/main/org/brailleblaster/wordprocessor/StyleManager.java /src/main/org/brailleblaster/wordprocessor/StylePanel.java /src/main/org/brailleblaster/wordprocessor/StyleProperty.java Modified: /src/main/org/brailleblaster/wordprocessor/WPManager.java ======================================= --- /dev/null+++ /src/main/org/brailleblaster/stylePanel/EditStyle.java Mon Jul 29 06:13:08 2013
@@ -0,0 +1,557 @@ +/* BrailleBlaster Braille Transcription Application + * + * Copyright (C) 2010, 2012 + * ViewPlus Technologies, Inc. www.viewplus.com + * and + * Abilitiessoft, Inc. www.abilitiessoft.com + * All rights reserved + * + * This file may contain code borrowed from files produced by various + * Java development teams. These are gratefully acknoledged. + * + * This file is free software; you can redistribute it and/or modify it + * under the terms of the Apache 2.0 License, as given at + * http://www.apache.org/licenses/ + * + * This file is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE + * See the Apache 2.0 License for more details. + * + * You should have received a copy of the Apache 2.0 License along with + * this program; see the file LICENSE. + * If not, see + * http://www.apache.org/licenses/ + * + * Maintained by John J. Boyer john.boyer@xxxxxxxxxxxxxxxxx + */ + +package org.brailleblaster.stylePanel; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.Hashtable; + +import org.brailleblaster.BBIni; +import org.brailleblaster.localization.LocaleHandler; +import org.brailleblaster.util.FileUtils; +import org.brailleblaster.util.Notify; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.ACC; +import org.eclipse.swt.accessibility.Accessible; +import org.eclipse.swt.events.FocusEvent; +import org.eclipse.swt.events.FocusListener; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.VerifyEvent; +import org.eclipse.swt.events.VerifyListener; +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.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Dialog; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; +import org.eclipse.swt.widgets.Widget; + +public class EditStyle extends Dialog{ + final static int PROPERTYLABELWIDTH = 125; //SWT UI setting + final static int PROPERTYTEXTWIDTH = 100; + private static LocaleHandler lh = new LocaleHandler(); + private static int num_styles = 0; + private static Label lastLabel; + final static String STRUE = lh.localValue("styleTrue"); + final static String SFALSE = lh.localValue("styleFalse"); + final static int INDEXTRUE = 0; //index of "true" in the combo + final static int INDEXFALSE = 1; + private static String fileSep; + + private StyleManager sm; + private String stylePath; + private String propExtension; + private ArrayList<String> formValues = new ArrayList<String>() ; + + private Text nameText; + private Hashtable<String, Widget> formRelTab; + //static ArrayList<String> propertiesNameList =new ArrayList<String>(); + + static int CREATE = 1; + static int MODIFY = 2; + + private static FocusListener focusListener = new FocusListener() { + public void focusGained(FocusEvent e) { + Text t = (Text) e.widget; + t.selectAll(); + } + + public void focusLost(FocusEvent e) { + final Text t = (Text) e.widget; + + if (t.getSelectionCount() > 0) { + t.clearSelection(); + } + + //FO + if(! t.getText().toString().matches("^[a-zA-Z0-9_]+$")) { + new Notify(lh.localValue("styleNotBlank")); + Display.getCurrent().asyncExec(new Runnable(){ + public void run(){ + t.setFocus(); + } + }); + } + } + }; + + public EditStyle (Shell parent, int style) { + super (parent, style); + } + + EditStyle (final StyleManager styleManager) { + this (styleManager.dm.getShell(), SWT.NONE); + this.sm = styleManager; + fileSep = BBIni.getFileSep(); + stylePath = BBIni.getStylePath(); + this.propExtension =BBIni.propExtension; + } + + private Shell initOpen(int mode){ + Shell parent = getParent(); + Shell stylePanel = new Shell(parent);+ String panelTitle = (mode == CREATE)?(lh.localValue("newStyle")):(lh.localValue("modifyStyle"));
+ stylePanel.setText(panelTitle); + FormLayout layout = new FormLayout(); + layout.marginWidth = 10; + layout.marginHeight = 10; + stylePanel.setLayout(layout); + + FormData data = new FormData();+ formRelTab = new Hashtable<String, Widget>(); //Stores the mapping rel between labels and widgets
+ + Group attributesPanel = new Group(stylePanel, SWT.NONE); + attributesPanel.setText(lh.localValue("styleAttributes")); + FormLayout ownerLayout1 = new FormLayout(); + ownerLayout1.marginWidth = 5; + ownerLayout1.marginHeight = 5; + attributesPanel.setLayout(ownerLayout1); + data.left = new FormAttachment(0, 0); + data.right = new FormAttachment(100, 0); + attributesPanel.setLayoutData(data); + + + Label name = new Label(attributesPanel, SWT.NULL); + name.setText(lh.localValue("styleName")); + data = new FormData(); + data.width = PROPERTYLABELWIDTH; + name.setLayoutData(data); + nameText = new Text(attributesPanel, SWT.SINGLE | SWT.BORDER| SWT.RIGHT); + nameText.setText("s"+ (num_styles+1)); + data = new FormData(); + data.left = new FormAttachment(name, 5); + data.right = new FormAttachment(100, 0); + data.width = PROPERTYTEXTWIDTH; + nameText.setLayoutData(data); + nameText.addFocusListener(focusListener); + Accessible accName = name.getAccessible(); + Accessible accNameText = nameText.getAccessible(); + accName.addRelation(ACC.RELATION_LABEL_FOR, accNameText); + accNameText.addRelation(ACC.RELATION_LABELLED_BY, accName); + + Group propertiesPanel = new Group(stylePanel, SWT.NONE); + propertiesPanel.setText(lh.localValue("styleProperties")); + FormLayout ownerLayout = new FormLayout(); + ownerLayout.marginWidth = 5; + ownerLayout.marginHeight = 5; + propertiesPanel.setLayout(ownerLayout); + data = new FormData(); + data.top = new FormAttachment(attributesPanel, 0); + data.left = new FormAttachment(0, 0); + data.right = new FormAttachment(100, 0); + propertiesPanel.setLayoutData(data); + + loadProperties(propertiesPanel);+ String confirmButtText = (mode == CREATE)?lh.localValue("styleCreate"):lh.localValue("styleModify");
+ addButtons(stylePanel, propertiesPanel, confirmButtText); + + formRelTab.put("styleName:", nameText); + stylePanel.pack(); + stylePanel.open(); + return stylePanel; + } + + //used to create new style + void create(String styleName){ + Shell stylePanel = initOpen(CREATE); + Shell parent = getParent(); + Display display = parent.getDisplay(); + HashMap<String, String> styleSet = new HashMap<String, String>(); + styleSet.put("styleName", styleName); + Style style = new Style(styleSet); + updateFields(style); + nameText.setEditable(false); + nameText.setEnabled(false); + while (!stylePanel.isDisposed ()) { + if (!display.readAndDispatch ()) display.sleep(); + } + stylePanel.dispose(); + } + + //used to modify existing style + void modify(Style style){ + Shell stylePanel = initOpen(MODIFY); + Shell parent = getParent(); + Display display = parent.getDisplay(); + if(style != null){ + nameText.setEditable(false); + nameText.setEnabled(false); + updateFields(style); + } + while (!stylePanel.isDisposed ()) { + if (!display.readAndDispatch ()) display.sleep(); + } + stylePanel.dispose(); + } + + //add necessary fields from enum class StyleProperty into the panel + private void loadProperties(Group propertiesPanel){ + boolean isFirstProperty = true; + Accessible accPropertiesPanel = propertiesPanel.getAccessible(); + FormData data = new FormData(); + for(StyleProperty sp :StyleProperty.values()){ + if(isFirstProperty){ + Label firstLabel = new Label(propertiesPanel, SWT.NULL); + firstLabel.setText(sp.toString()+":"); + data = new FormData(); + data.width = PROPERTYLABELWIDTH; + firstLabel.setLayoutData(data); + firstLabel.setToolTipText(sp.getToolTip());+ Text firstText = new Text(propertiesPanel, SWT.SINGLE | SWT.BORDER| SWT.RIGHT);
+ data = new FormData(); + data.left = new FormAttachment(firstLabel, 5); + data.right = new FormAttachment(100, 0); + data.width = PROPERTYTEXTWIDTH; + setNumericalValidation(firstText);// + firstText.setLayoutData(data); + firstText.setToolTipText(sp.getToolTip()); + firstText.setText(sp.getDefaultValue()); + firstText.addFocusListener(focusListener); + //add accessible + Accessible accFirstLabel = firstLabel.getAccessible(); + Accessible accFirstText = firstText.getAccessible(); + accFirstLabel.addRelation(ACC.RELATION_LABEL_FOR, accFirstText); + accFirstText.addRelation(ACC.RELATION_LABELLED_BY, accFirstLabel); + accFirstText.addRelation(ACC.RELATION_MEMBER_OF, accPropertiesPanel); + accFirstText.addRelation(ACC.RELATION_LABELLED_BY, accPropertiesPanel); + lastLabel = firstLabel; + isFirstProperty = false; + //add to table + formRelTab.put(firstLabel.getText(), firstText); + } + else{ + addFields(propertiesPanel, sp); + } + } + } ++ private void addButtons(final Shell parent ,Group propertiesPanel, String confirmText){
+ FormData data = new FormData(); + Button confirmButt = new Button(parent, SWT.PUSH); + Button cancelButt = new Button(parent, SWT.PUSH); + confirmButt.setText(confirmText); + cancelButt.setText(lh.localValue("styleCancel")); + data.top = new FormAttachment(propertiesPanel, 5); + data.right = new FormAttachment(100, -5); + cancelButt.setLayoutData(data); + data = new FormData(); + data.top = new FormAttachment(cancelButt, 0, SWT.TOP); + data.right = new FormAttachment(cancelButt, -5); + confirmButt.setLayoutData(data); + parent.setDefaultButton(confirmButt); + + cancelButt.addSelectionListener(new SelectionAdapter(){ + public void widgetSelected(SelectionEvent e) { + parent.dispose(); + } + }); + + confirmButt.addSelectionListener(new SelectionAdapter(){ + public void widgetSelected(SelectionEvent e) { + Group abs = (Group) parent.getChildren()[0]; + Control aList[] = abs.getChildren(); + for(Control c: aList){ + String s= controlToString(c); + formValues.add(s); + } + + Group pps = (Group) parent.getChildren()[1]; + Control pList[] = pps.getChildren(); + for(Control c: pList){ + String s= controlToString(c); + formValues.add(s); + } + String styleName= getStyleName(); + + //System.out.println("Style name is " + styleName); + + saveStyle(styleName); + parent.dispose(); + sm.readStyleFiles(styleName); + } + }); + + } + + + String sn = lh.localValue("styleName"); + String getStyleName(){ + for(int i = 0; i< formValues.size(); i++){ + if(formValues.get(i).equals(sn)){ + return formValues.get(i+1); + } + } + return ""; + } + + static String controlToString(Control c){ + String s = ""; + if(c instanceof Text){ + Text m = (Text)c; + s =m.getText(); + } + else if (c instanceof Label){ + Label l = (Label)c; + s = l.getText(); + } + else if (c instanceof Combo){ + Combo cb = (Combo)c; + s = cb.getText(); + } + return s; + } + + private void addFields(Group propertiesPanel, StyleProperty sp){ + Accessible accPropertiesPanel = propertiesPanel.getAccessible(); + Label l = addFieldLabel(propertiesPanel, sp.toString()+":"); + if(sp.getTypeIndex() == StyleProperty.INTEGER){+ Text t = addFieldText(propertiesPanel, sp.getDefaultValue(), sp.getToolTip());
+ Accessible accLabel = l.getAccessible(); + Accessible accText = t.getAccessible(); + accLabel.addRelation(ACC.RELATION_LABEL_FOR, accText); + accText.addRelation(ACC.RELATION_LABELLED_BY, accLabel); + accText.addRelation(ACC.RELATION_MEMBER_OF, accPropertiesPanel); + accText.addRelation(ACC.RELATION_LABELLED_BY, accPropertiesPanel); + formRelTab.put(l.getText(), t); + } + else if(sp.getTypeIndex() == StyleProperty.BOOLEAN){+ Combo c = addFieldCombo(propertiesPanel, sp.getDefaultValue(), sp.getToolTip());
+ Accessible accLabel = l.getAccessible(); + Accessible accCombo = c.getAccessible(); + accLabel.addRelation(ACC.RELATION_LABEL_FOR, accCombo); + accCombo.addRelation(ACC.RELATION_LABELLED_BY, accLabel); + accCombo.addRelation(ACC.RELATION_MEMBER_OF, accPropertiesPanel); + accCombo.addRelation(ACC.RELATION_LABELLED_BY, accPropertiesPanel); + formRelTab.put(l.getText(), c); + } + } + + private static Label addFieldLabel(Composite parent, String text){ + FormData data = new FormData(); + Label curLabel = new Label(parent, SWT.PUSH); + data.top= new FormAttachment(lastLabel, 12); + data.width = PROPERTYLABELWIDTH; + curLabel.setLayoutData(data); + curLabel.setText(text); + curLabel.setToolTipText(text); + lastLabel = curLabel; + return curLabel; + } ++ private static Text addFieldText(Composite parent, String text, String toolTip){
+ FormData data = new FormData(); + final Text curText = + new Text(parent, SWT.SINGLE | SWT.BORDER|SWT.RIGHT); + setNumericalValidation(curText); + + data.top= new FormAttachment(lastLabel, -2, SWT.TOP); + data.left = new FormAttachment(lastLabel, 5); + data.right = new FormAttachment(100, 0); + data.width = PROPERTYTEXTWIDTH; + curText.setLayoutData(data); + curText.setText(text); + curText.setToolTipText(toolTip); + curText.addFocusListener(focusListener); + return curText; + } ++ private static Combo addFieldCombo(Composite parent, String text, String toolTip){
+ FormData data = new FormData(); + Combo curText = + new Combo(parent, SWT.BORDER|SWT.RIGHT|SWT.READ_ONLY); + data.top= new FormAttachment(lastLabel, -2, SWT.TOP); + data.left = new FormAttachment(lastLabel, 5); + data.right = new FormAttachment(100, 0); + data.width = PROPERTYTEXTWIDTH; + curText.setLayoutData(data); + curText.setText(text); + curText.add(STRUE); + curText.add(SFALSE); + if(text.equals(STRUE)){ + curText.select(INDEXTRUE); + } + else{ + curText.select(INDEXFALSE); + } + curText.setToolTipText(toolTip); + return curText; + } + + private static void setNumericalValidation(final Text text){ + text.addModifyListener(new ModifyListener() { + @Override + public void modifyText(ModifyEvent event) { + String txt = ((Text) event.getSource()).getText(); + try { + // int num = Integer.parseInt(txt); + // Checks on num + } catch (NumberFormatException e) { + // Show error + new Notify(txt+ lh.localValue("styleNotValid")); + } + } + }); + + text.addVerifyListener(new VerifyListener() { + public void verifyText(VerifyEvent e) { + final String oldS = text.getText();+ final String newS = oldS.substring(0, e.start) + e.text + oldS.substring(e.end);
+ if (e.character == SWT.CR) { + e.doit = false; + } + else if(newS.equals("")){ + //only check if the string is not empty, + //focusListener handles the empty string + //do nothing + } + else{ + try { + BigDecimal bd = new BigDecimal(newS); + // value is decimal + // Test value range + } catch (final NumberFormatException numberFormatException) { + // value is not decimal + e.doit = false; + new Notify(lh.localValue("styleNumOnly")); + } + } + } + }); + } + + /**+ * Write to the properties file with the style name in the local directory;
+ * Create one if not existed yet. + * + * @param styleName + */ + private void saveStyle(String styleName){ + FileUtils fu = new FileUtils(); + String fileName = stylePath+fileSep+styleName+propExtension; + if(!fu.exists(fileName)){ + fu.create(fileName); + } + writeToFile(new File(fileName)); + } + + private void writeToFile(File file) { + BufferedWriter writer = null; + try { + writer = new BufferedWriter(new FileWriter(file)); + } catch (IOException e) { + new Notify(e.getMessage()); + } + try { + boolean isEven = false; + int i = 1; + for( String s:formValues) { + if (i++ == 1) { + s = "styleName="; + } else if (s.charAt(s.length()-1)==':'){ + s = s.substring(0,s.length()-1)+"="; + } + writer.write(s); + if(isEven){ + writer.newLine(); + } + isEven = !isEven; + } + } catch (IOException e) { + new Notify(e.getMessage()); + }finally{ + try { + writer.close(); + } catch (IOException e) { + new Notify(e.getMessage()); + } + } + } + + + /** + * This method load existing style values to the form + * @param style + */ + + void updateFields(Style style){ +// for(String s: formRelTab.keySet()){ +// System.out.println(s); +// Widget w = formRelTab.get(s); +// if(w instanceof Text){ +// System.out.println(((Text) w).getText()); +// } +// } + //style.print(); + + + for(String labelText: formRelTab.keySet()){ + Widget w = formRelTab.get(labelText); ++ String key = labelText.substring(0,labelText.length()-1);// this filters out the ':' in the label text
+ String value = style.styleSet.get(key); + + //System.out.println('+'+key + ":"+ value +", w:"+w.toString()); + if(value == null) continue; + if(w instanceof Text){ + ((Text) w).setText(value); + } + else if(w instanceof Combo){ + int i; + if(value.equals(STRUE)) { + i = INDEXTRUE; + } + else{ + i = INDEXFALSE; + } + ((Combo) w).select(i); + } + } + } + + public Hashtable<String, Widget> getFormRelTab(){ + return formRelTab; + } + +} ======================================= --- /dev/null+++ /src/main/org/brailleblaster/stylePanel/Style.java Mon Jul 29 06:13:08 2013
@@ -0,0 +1,156 @@ +/* BrailleBlaster Braille Transcription Application + * + * Copyright (C) 2010, 2012 + * ViewPlus Technologies, Inc. www.viewplus.com + * and + * Abilitiessoft, Inc. www.abilitiessoft.com + * and + * American Printing House for the Blind, Inc. www.aph.org + * + * All rights reserved + * + * This file may contain code borrowed from files produced by various + * Java development teams. These are gratefully acknoledged. + * + * This file is free software; you can redistribute it and/or modify it + * under the terms of the Apache 2.0 License, as given at + * http://www.apache.org/licenses/ + * + * This file is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE + * See the Apache 2.0 License for more details. + * + * You should have received a copy of the Apache 2.0 License along with + * this program; see the file LICENSE. + * If not, see + * http://www.apache.org/licenses/ + * + * Maintained by John J. Boyer john.boyer@xxxxxxxxxxxxxxxxx +*/ + +package org.brailleblaster.stylePanel; + +import java.util.Enumeration; +import java.util.HashMap; +import java.util.Locale; +import java.util.ResourceBundle; + +class Style { + // This maybe used if this way is overcomplicated + // int lines_before; + // int lines_after; + // /* The following are percentages.*/ + // int left_margin; + // int first_line_indent; + // int right_margin; + // /* Various controls */ + // boolean keep_with_next; + // boolean dont_split; + // int orphan_control; + // boolean newpage_before; + // boolean newpage_after; + //StyleFormat format; /*StyleFormat is an enumeration class*/ + /* used for output */ + String elementName; + String attr1Name; + String attr1Value; + String attr2Name; + String attr2Value; + String attr3Name; + String attr3Value; + String styleName;+ private boolean isBuildIn;//whether it is a buildin style, default to false
+ //this stores different properties of a style + HashMap<String, String> styleSet + = new HashMap<String, String>(); + + /** + * Useful to load the build-in style properties files. + * i.e. "dist\programData\styles\[styleName].properties" + * + * @param styleName + */ + public Style(String styleName){ + this.styleName = styleName; + ResourceBundle labels = ResourceBundle.getBundle(styleName); + Enumeration bundleKeys = labels.getKeys(); + while (bundleKeys.hasMoreElements()) { + String key = (String)bundleKeys.nextElement(); + String value = labels.getString(key); + styleSet.put(key, value); + } + this.isBuildIn = false; + } + + /**+ * Load default style setting in dist\programData\styles\default.properties
+ */ + public Style(){ + this("default"); + } + + /** + * Useful to create a new style from scratch + * + * @param styleProperties + */ + public Style(HashMap<String, String> styleProperties){ + this(); + styleSet.putAll(styleProperties); + if(styleSet.get("styleName") != null){ + this.styleName = styleSet.get("styleName"); + } + } + + + /**+ * This enables BB to load style using absolute url; useful when loading user's
+ * local properties files + * + * @param styleName + * @param loader + */ + public Style(String styleName, ClassLoader loader){ + this.styleName = styleName;+ ResourceBundle labels = ResourceBundle.getBundle(styleName, Locale.getDefault() , loader);
+ Enumeration bundleKeys = labels.getKeys(); + while (bundleKeys.hasMoreElements()) { + String key = (String)bundleKeys.nextElement(); + String value = labels.getString(key); + styleSet.put(key, value); + } + } + + public String toString(){ + return styleName; + } + + public String getName(){ + return styleName; + } + + public void setProperty(String key, String value){ + styleSet.put(key, value); + } + + public String getProperty(String key){ + return styleSet.get(key); + } + + public void setIsBuildIn(boolean b){ + this.isBuildIn = b; + } + public boolean getIsBuildIn(){ + return this.isBuildIn; + } + + + public void print(){ + System.out.println(); + for(String s:styleSet.keySet()){ + System.out.println("key = '"+s + "': '" + styleSet.get(s)+"'"); + } + System.out.println(); + } +} ======================================= --- /dev/null+++ /src/main/org/brailleblaster/stylePanel/StyleManager.java Mon Jul 29 06:13:08 2013
@@ -0,0 +1,68 @@ +/* BrailleBlaster Braille Transcription Application + * + * Copyright (C) 2010, 2012 + * ViewPlus Technologies, Inc. www.viewplus.com + * and + * Abilitiessoft, Inc. www.abilitiessoft.com + * and + * American Printing House for the Blind, Inc. www.aph.org + * + * All rights reserved + * + * This file may contain code borrowed from files produced by various + * Java development teams. These are gratefully acknoledged. + * + * This file is free software; you can redistribute it and/or modify it + * under the terms of the Apache 2.0 License, as given at + * http://www.apache.org/licenses/ + * + * This file is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE + * See the Apache 2.0 License for more details. + * + * You should have received a copy of the Apache 2.0 License along with + * this program; see the file LICENSE. + * If not, see + * http://www.apache.org/licenses/ + * + * Maintained by John J. Boyer john.boyer@xxxxxxxxxxxxxxxxx +*/ + +package org.brailleblaster.stylePanel; + +import org.brailleblaster.wordprocessor.WPManager; + +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); + } + + void createStyle(String styleName){ + EditStyle es = new EditStyle(this); + es.create(styleName); + } + + void modifyStyle(Style style){ + EditStyle es = new EditStyle(this); + es.modify(style); + } + + public void stylePanel(){ + sp.open(); + } + + void readStyleFiles(String styleName){ + sp.readStyleFiles(styleName); + } +} ======================================= --- /dev/null+++ /src/main/org/brailleblaster/stylePanel/StylePanel.java Mon Jul 29 06:13:08 2013
@@ -0,0 +1,385 @@ +/* BrailleBlaster Braille Transcription Application + * + * Copyright (C) 2010, 2012 + * ViewPlus Technologies, Inc. www.viewplus.com + * and + * Abilitiessoft, Inc. www.abilitiessoft.com + * and + * American Printing House for the Blind, Inc. www.aph.org + * + * All rights reserved + * + * This file may contain code borrowed from files produced by various + * Java development teams. These are gratefully acknoledged. + * + * This file is free software; you can redistribute it and/or modify it + * under the terms of the Apache 2.0 License, as given at + * http://www.apache.org/licenses/ + * + * This file is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE + * See the Apache 2.0 License for more details. + * + * You should have received a copy of the Apache 2.0 License along with + * this program; see the file LICENSE. + * If not, see + * http://www.apache.org/licenses/ + * + * Maintained by John J. Boyer john.boyer@xxxxxxxxxxxxxxxxx +*/ + +package org.brailleblaster.stylePanel; + +import java.io.File; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Locale; +import java.util.ResourceBundle; + +import org.brailleblaster.BBIni; +import org.brailleblaster.localization.LocaleHandler; +import org.brailleblaster.util.FileUtils; +import org.brailleblaster.util.YesNoChoice; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.ACC; +import org.eclipse.swt.accessibility.Accessible; +import org.eclipse.swt.custom.StyledText; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Dialog; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Monitor; +import org.eclipse.swt.widgets.Shell; + +/* TODO+ * 1. Can user modify build-in styles? If yes, then do we keep the original build-in properties file?
+ * 2. Delete function. Can users delete build-in styles? + * 3. Add localized strings + */ + + +public class StylePanel extends Dialog{ + static Display display; + static Shell stylePanel; + + Button delete; + Button create; + Button modify; + Button apply; + + static int propertyLabelWidth = 125; + static int propertyTextWidth = 100; + + private String fileSep; + private StyleManager sm; + private String localStylesPath; + private String buildInStylesPath; + private final String PROPEXTENSION = ".properties"; + + + private static HashMap<String, Style> styleMap + = new HashMap<String, Style>(); + + FileUtils fu = new FileUtils(); + private Combo combo; + private LocaleHandler lh = new LocaleHandler(); + ArrayList<Style> styleList;//styles + ArrayList<String> displayArr;//Styles' names for display + + public StylePanel (Shell parent, int style) { + super (parent, style); + } + +// StylePanel(StyleManager styleManager) { +// this(styleManager.dm.documentWindow, SWT.NONE); +// this.sm = styleManager; +// display = BBIni.getDisplay(); +// fileSep = BBIni.getFileSep(); +// localStylesPath = BBIni.getStylePath(); +// buildInStylesPath = BBIni.getProgramDataPath()+fileSep+"styles" ; +// readStyleFiles("default"); +// } + StylePanel(StyleManager styleManager) { + this(styleManager.dm.getShell(), SWT.NONE); + this.sm = styleManager; + display = styleManager.dm.getDisplay(); + fileSep = BBIni.getFileSep(); + localStylesPath = BBIni.getStylePath(); + buildInStylesPath = BBIni.getProgramDataPath()+fileSep+"styles" ; + readStyleFiles("default"); + } + + /**+ * Read style properties files and update the combo if it has been created;
+ * Then set the default item index of the combo to the index of styleName + * @param styleName + */ + public void readStyleFiles(String styleName){ + styleList = new ArrayList<Style>(); + readStyleFromBuildIn(); + readStyleFromLocal(); + displayArr = new ArrayList<String>(); + for(Style style: styleList){ + String displayName = style.toString();+ if(style.getIsBuildIn()) displayName += " [" + lh.localValue("styleBuildIn")+"]";
+ displayArr.add(displayName); + } + if(combo != null){+ combo.setItems((String[])displayArr.toArray(new String[displayArr.size()]));
+ int index = (styleName!=null)?displayArr.indexOf(styleName):0; + combo.select(index); + } + } + + private void readStyleFromBuildIn(){ + File dir = new File(buildInStylesPath); + if(!dir.exists()) { + //no build-in styles + return; + } + String[] children = dir.list(); + for(int curStr = 0; curStr < children.length; curStr++){ + int index = children[curStr].indexOf(PROPEXTENSION); + + // This isn't a style file. Skip it. + if(index < 0) + continue; + + String styleName = children[curStr].substring(0,index); + Style style = new Style(styleName); + style.setIsBuildIn(true); + styleList.add(style); + } + } + + private void readStyleFromLocal(){ + File dir = new File(localStylesPath); + ClassLoader loader = null; + try { + URL[] urls={ + dir.toURI().toURL() + }; + loader = new URLClassLoader(urls); + } catch (MalformedURLException e){ + e.printStackTrace(); + } + String[] children = dir.list(); + for(String s:children){ + int index = s.indexOf(PROPEXTENSION); + String styleName = s.substring(0,index); + Style style = new Style(styleName, loader); + styleList.add(style); + } + } + + void open(){ + Shell parent = getParent(); + Display display = parent.getDisplay(); + stylePanel = new Shell(parent, SWT.DIALOG_TRIM); + stylePanel.setText(lh.localValue("Style Panel")); + FormLayout layout = new FormLayout(); + layout.marginWidth = 10; + layout.marginHeight = 10; + stylePanel.setLayout(layout); + + Monitor primary = display.getPrimaryMonitor(); + Rectangle bounds = primary.getBounds(); + Rectangle rect = stylePanel.getBounds(); + int x = bounds.x + ((bounds.width - rect.width) / 2) + 10; + int y = bounds.y + ((bounds.height - rect.height) / 2) + 10; + stylePanel.setLocation (x, y); + + GridLayout gridLayout = new GridLayout (); + stylePanel.setLayout (gridLayout); + gridLayout.marginTop = 15; + gridLayout.marginBottom = 15; + gridLayout.marginLeft = 10; + gridLayout.marginRight = 10; + gridLayout.numColumns = 7; + //gridLayout.horizontalSpacing = 15; + gridLayout.makeColumnsEqualWidth =true; + + + Label name = new Label(stylePanel, SWT.HORIZONTAL); + name.setText(lh.localValue("styleName")); + + combo = new Combo (stylePanel, SWT.DROP_DOWN);+ combo.setItems((String[])displayArr.toArray(new String[displayArr.size()]));
+ combo.select(0); + GridData data = new GridData(GridData.FILL_HORIZONTAL); + data.horizontalSpan = 2; + combo.setLayoutData(data); + + Accessible accName = name.getAccessible(); + Accessible accNameCombo = combo.getAccessible(); + accName.addRelation(ACC.RELATION_LABEL_FOR, accNameCombo); + accNameCombo.addRelation(ACC.RELATION_LABELLED_BY, accName); + + create = new Button(stylePanel, SWT.PUSH); + modify = new Button(stylePanel, SWT.PUSH); + delete = new Button(stylePanel, SWT.PUSH); + apply = new Button(stylePanel, SWT.PUSH); + + delete.setText(lh.localValue("styleDelete")); + data = new GridData(GridData.FILL_HORIZONTAL); + delete.setLayoutData(data); + + create.setText(lh.localValue("styleCreate")); + create.setLayoutData(data); + + modify.setText(lh.localValue("styleModify")); + modify.setLayoutData(data); + + apply.setText(lh.localValue("styleApply"));//need to add to i18n files + apply.setLayoutData(data); + updateButtons(isExisted() >= 0); + + + combo.addModifyListener(new ModifyListener(){ + @Override + public void modifyText(ModifyEvent e) { + updateButtons(isExisted() >= 0); + } + }); + + + apply.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + int key = combo.getSelectionIndex(); + if(key != -1){ + Style style = styleList.get(key); + //printStyle(style); + apply(style); + } + stylePanel.close(); + } + }); + + modify.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + int key = combo.getSelectionIndex(); + if(key != -1){ + Style style = styleList.get(key); + modify(style); + }else{ + key = isExisted(); + if(key != -1){ + Style style = styleList.get(key); + modify(style); + }else{ + System.out.println("trying to modify a style that doesn't exsist"); + } + } + } + }); + + create.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + String styleName = combo.getText(); + create(styleName); + } + }); + + delete.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) {+ YesNoChoice prompt = new YesNoChoice(lh.localValue("styleDeleteMsg")+"\""+combo.getText()+"\"?");
+ if(prompt.result == SWT.YES){ + int key = isExisted(); + Style style = styleList.get(key); + delete(style); + } + } + }); + + // show the SWT window + stylePanel.pack(); + stylePanel.open(); + while (!stylePanel.isDisposed()) { + if (!display.readAndDispatch()) + display.sleep(); + } + // tear down the SWT window + stylePanel.dispose(); + } + + /** + * Check whether the current text in the combo field is already a style. + * return the index if exist; -1 otherwise. + */ + int isExisted(){ + String list[] = combo.getItems(); + String styleName = combo.getText(); + for(int i =0; i< list.length; i++){ + if(list[i].equals(styleName)){ + return i; + } + } + return -1; + } + + /** + * update button's enabled status based on whether the style is existed + * + * @param style + */ + + void updateButtons(boolean isExisted){ + modify.setEnabled(isExisted); + delete.setEnabled(isExisted); + apply.setEnabled(isExisted); + create.setEnabled(!isExisted); + if(isExisted){ + stylePanel.setDefaultButton(apply); + }else{ + stylePanel.setDefaultButton(create); + } + } + + + void apply(Style style){ +// if(view == null){ +// this.view = dm.daisy.view; +// } +// view.setLineIndent(1, 1, 100); + //style.print(); + } + + void create(String styleName){ + sm.createStyle(styleName); + } + + void modify(Style style){ + sm.modifyStyle(style); + } + + void delete(Style style){ + if(style.getIsBuildIn()){ + //if it is build-in style, should it be deleted? + }else{+ String fileName = localStylesPath + fileSep +style.getName() + PROPEXTENSION;
+ //System.out.println("deleting" + fileName); + if(fu.deleteFile(fileName)){ + readStyleFiles(null); + }else{ + System.out.println("fail to delete: " + fileName); + } + } + } + + void printStyle(Style style){ + style.print(); + } +} ======================================= --- /dev/null+++ /src/main/org/brailleblaster/stylePanel/StyleProperty.java Mon Jul 29 06:13:08 2013
@@ -0,0 +1,93 @@ +/* BrailleBlaster Braille Transcription Application + * + * Copyright (C) 2010, 2012 + * ViewPlus Technologies, Inc. www.viewplus.com + * and + * Abilitiessoft, Inc. www.abilitiessoft.com + * and + * American Printing House for the Blind, Inc. www.aph.org + * + * All rights reserved + * + * This file may contain code borrowed from files produced by various + * Java development teams. These are gratefully acknoledged. + * + * This file is free software; you can redistribute it and/or modify it + * under the terms of the Apache 2.0 License, as given at + * http://www.apache.org/licenses/ + * + * This file is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE + * See the Apache 2.0 License for more details. + * + * You should have received a copy of the Apache 2.0 License along with + * this program; see the file LICENSE. + * If not, see + * http://www.apache.org/licenses/ + * + * Maintained by John J. Boyer john.boyer@xxxxxxxxxxxxxxxxx +*/ + +package org.brailleblaster.stylePanel; + +public enum StyleProperty { + // Each property takes two parameters + //the first one is type index, which indicates + //the type of acceptable value of this prop, + //i.e. integer, boolean for now. The other + //is the default value displayed in the form + + linesBefore(0,1), + linesAfter(0,1), + /* The following are percentages.*/ + leftMargin(0,5), + firstLineIndent(0,2), + rightMargin(0,5), + /* Various controls */ + keepWithNext(1,true), + dontSplit(1,false), + orphanControl(1,false), + newpageBefore(1,true), + newpageAfter(1,true); + + final static int INTEGER = 0; + final static int BOOLEAN = 1; + private int typeIndex; + private int defaultInt; + private boolean defaultBool; + + StyleProperty(int index, int defaultValue){ + typeIndex = index; + defaultInt = defaultValue; + } + StyleProperty(int index, boolean defaultValue){ + typeIndex = index; + defaultBool = defaultValue; + } + + String getToolTip(){ + if(typeIndex == INTEGER){ + return this.toString()+": Please enter an integer"; + } + else if (typeIndex == BOOLEAN){ + return this.toString()+": Please select a boolean value"; + } + return ""; + } + + int getTypeIndex(){ + return typeIndex; + } + + String getDefaultValue(){ + if(typeIndex == INTEGER){ + return Integer.toString(this.defaultInt); + } + else if(typeIndex == BOOLEAN){ + if(this.defaultBool)return "True"; + else return "False"; + } + return ""; + } +} =======================================--- /src/main/org/brailleblaster/wordprocessor/EditStyle.java Thu May 23 07:16:20 2013
+++ /dev/null @@ -1,557 +0,0 @@ -/* BrailleBlaster Braille Transcription Application - * - * Copyright (C) 2010, 2012 - * ViewPlus Technologies, Inc. www.viewplus.com - * and - * Abilitiessoft, Inc. www.abilitiessoft.com - * All rights reserved - * - * This file may contain code borrowed from files produced by various - * Java development teams. These are gratefully acknoledged. - * - * This file is free software; you can redistribute it and/or modify it - * under the terms of the Apache 2.0 License, as given at - * http://www.apache.org/licenses/ - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE - * See the Apache 2.0 License for more details. - * - * You should have received a copy of the Apache 2.0 License along with - * this program; see the file LICENSE. - * If not, see - * http://www.apache.org/licenses/ - * - * Maintained by John J. Boyer john.boyer@xxxxxxxxxxxxxxxxx - */ - -package org.brailleblaster.wordprocessor; - -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.Hashtable; - -import org.brailleblaster.BBIni; -import org.brailleblaster.localization.LocaleHandler; -import org.brailleblaster.util.FileUtils; -import org.brailleblaster.util.Notify; -import org.eclipse.swt.SWT; -import org.eclipse.swt.accessibility.ACC; -import org.eclipse.swt.accessibility.Accessible; -import org.eclipse.swt.events.FocusEvent; -import org.eclipse.swt.events.FocusListener; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.VerifyEvent; -import org.eclipse.swt.events.VerifyListener; -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.Combo; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Dialog; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Group; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; -import org.eclipse.swt.widgets.Widget; - -public class EditStyle extends Dialog{ - final static int PROPERTYLABELWIDTH = 125; //SWT UI setting - final static int PROPERTYTEXTWIDTH = 100; - private static LocaleHandler lh = new LocaleHandler(); - private static int num_styles = 0; - private static Label lastLabel; - final static String STRUE = lh.localValue("styleTrue"); - final static String SFALSE = lh.localValue("styleFalse"); - final static int INDEXTRUE = 0; //index of "true" in the combo - final static int INDEXFALSE = 1; - private static String fileSep; - - private StyleManager sm; - private String stylePath; - private String propExtension; - private ArrayList<String> formValues = new ArrayList<String>() ; - - private Text nameText; - private Hashtable<String, Widget> formRelTab; - //static ArrayList<String> propertiesNameList =new ArrayList<String>(); - - static int CREATE = 1; - static int MODIFY = 2; - - private static FocusListener focusListener = new FocusListener() { - public void focusGained(FocusEvent e) { - Text t = (Text) e.widget; - t.selectAll(); - } - - public void focusLost(FocusEvent e) { - final Text t = (Text) e.widget; - - if (t.getSelectionCount() > 0) { - t.clearSelection(); - } - - //FO - if(! t.getText().toString().matches("^[a-zA-Z0-9_]+$")) { - new Notify(lh.localValue("styleNotBlank")); - Display.getCurrent().asyncExec(new Runnable(){ - public void run(){ - t.setFocus(); - } - }); - } - } - }; - - public EditStyle (Shell parent, int style) { - super (parent, style); - } - - EditStyle (final StyleManager styleManager) { - this (styleManager.dm.getShell(), SWT.NONE); - this.sm = styleManager; - fileSep = BBIni.getFileSep(); - stylePath = BBIni.getStylePath(); - this.propExtension =BBIni.propExtension; - } - - private Shell initOpen(int mode){ - Shell parent = getParent(); - Shell stylePanel = new Shell(parent);- String panelTitle = (mode == CREATE)?(lh.localValue("newStyle")):(lh.localValue("modifyStyle"));
- stylePanel.setText(panelTitle); - FormLayout layout = new FormLayout(); - layout.marginWidth = 10; - layout.marginHeight = 10; - stylePanel.setLayout(layout); - - FormData data = new FormData();- formRelTab = new Hashtable<String, Widget>(); //Stores the mapping rel between labels and widgets
- - Group attributesPanel = new Group(stylePanel, SWT.NONE); - attributesPanel.setText(lh.localValue("styleAttributes")); - FormLayout ownerLayout1 = new FormLayout(); - ownerLayout1.marginWidth = 5; - ownerLayout1.marginHeight = 5; - attributesPanel.setLayout(ownerLayout1); - data.left = new FormAttachment(0, 0); - data.right = new FormAttachment(100, 0); - attributesPanel.setLayoutData(data); - - - Label name = new Label(attributesPanel, SWT.NULL); - name.setText(lh.localValue("styleName")); - data = new FormData(); - data.width = PROPERTYLABELWIDTH; - name.setLayoutData(data); - nameText = new Text(attributesPanel, SWT.SINGLE | SWT.BORDER| SWT.RIGHT); - nameText.setText("s"+ (num_styles+1)); - data = new FormData(); - data.left = new FormAttachment(name, 5); - data.right = new FormAttachment(100, 0); - data.width = PROPERTYTEXTWIDTH; - nameText.setLayoutData(data); - nameText.addFocusListener(focusListener); - Accessible accName = name.getAccessible(); - Accessible accNameText = nameText.getAccessible(); - accName.addRelation(ACC.RELATION_LABEL_FOR, accNameText); - accNameText.addRelation(ACC.RELATION_LABELLED_BY, accName); - - Group propertiesPanel = new Group(stylePanel, SWT.NONE); - propertiesPanel.setText(lh.localValue("styleProperties")); - FormLayout ownerLayout = new FormLayout(); - ownerLayout.marginWidth = 5; - ownerLayout.marginHeight = 5; - propertiesPanel.setLayout(ownerLayout); - data = new FormData(); - data.top = new FormAttachment(attributesPanel, 0); - data.left = new FormAttachment(0, 0); - data.right = new FormAttachment(100, 0); - propertiesPanel.setLayoutData(data); - - loadProperties(propertiesPanel);- String confirmButtText = (mode == CREATE)?lh.localValue("styleCreate"):lh.localValue("styleModify");
- addButtons(stylePanel, propertiesPanel, confirmButtText); - - formRelTab.put("styleName:", nameText); - stylePanel.pack(); - stylePanel.open(); - return stylePanel; - } - - //used to create new style - void create(String styleName){ - Shell stylePanel = initOpen(CREATE); - Shell parent = getParent(); - Display display = parent.getDisplay(); - HashMap<String, String> styleSet = new HashMap<String, String>(); - styleSet.put("styleName", styleName); - Style style = new Style(styleSet); - updateFields(style); - nameText.setEditable(false); - nameText.setEnabled(false); - while (!stylePanel.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep(); - } - stylePanel.dispose(); - } - - //used to modify existing style - void modify(Style style){ - Shell stylePanel = initOpen(MODIFY); - Shell parent = getParent(); - Display display = parent.getDisplay(); - if(style != null){ - nameText.setEditable(false); - nameText.setEnabled(false); - updateFields(style); - } - while (!stylePanel.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep(); - } - stylePanel.dispose(); - } - - //add necessary fields from enum class StyleProperty into the panel - private void loadProperties(Group propertiesPanel){ - boolean isFirstProperty = true; - Accessible accPropertiesPanel = propertiesPanel.getAccessible(); - FormData data = new FormData(); - for(StyleProperty sp :StyleProperty.values()){ - if(isFirstProperty){ - Label firstLabel = new Label(propertiesPanel, SWT.NULL); - firstLabel.setText(sp.toString()+":"); - data = new FormData(); - data.width = PROPERTYLABELWIDTH; - firstLabel.setLayoutData(data); - firstLabel.setToolTipText(sp.getToolTip());- Text firstText = new Text(propertiesPanel, SWT.SINGLE | SWT.BORDER| SWT.RIGHT);
- data = new FormData(); - data.left = new FormAttachment(firstLabel, 5); - data.right = new FormAttachment(100, 0); - data.width = PROPERTYTEXTWIDTH; - setNumericalValidation(firstText);// - firstText.setLayoutData(data); - firstText.setToolTipText(sp.getToolTip()); - firstText.setText(sp.getDefaultValue()); - firstText.addFocusListener(focusListener); - //add accessible - Accessible accFirstLabel = firstLabel.getAccessible(); - Accessible accFirstText = firstText.getAccessible(); - accFirstLabel.addRelation(ACC.RELATION_LABEL_FOR, accFirstText); - accFirstText.addRelation(ACC.RELATION_LABELLED_BY, accFirstLabel); - accFirstText.addRelation(ACC.RELATION_MEMBER_OF, accPropertiesPanel); - accFirstText.addRelation(ACC.RELATION_LABELLED_BY, accPropertiesPanel); - lastLabel = firstLabel; - isFirstProperty = false; - //add to table - formRelTab.put(firstLabel.getText(), firstText); - } - else{ - addFields(propertiesPanel, sp); - } - } - } -- private void addButtons(final Shell parent ,Group propertiesPanel, String confirmText){
- FormData data = new FormData(); - Button confirmButt = new Button(parent, SWT.PUSH); - Button cancelButt = new Button(parent, SWT.PUSH); - confirmButt.setText(confirmText); - cancelButt.setText(lh.localValue("styleCancel")); - data.top = new FormAttachment(propertiesPanel, 5); - data.right = new FormAttachment(100, -5); - cancelButt.setLayoutData(data); - data = new FormData(); - data.top = new FormAttachment(cancelButt, 0, SWT.TOP); - data.right = new FormAttachment(cancelButt, -5); - confirmButt.setLayoutData(data); - parent.setDefaultButton(confirmButt); - - cancelButt.addSelectionListener(new SelectionAdapter(){ - public void widgetSelected(SelectionEvent e) { - parent.dispose(); - } - }); - - confirmButt.addSelectionListener(new SelectionAdapter(){ - public void widgetSelected(SelectionEvent e) { - Group abs = (Group) parent.getChildren()[0]; - Control aList[] = abs.getChildren(); - for(Control c: aList){ - String s= controlToString(c); - formValues.add(s); - } - - Group pps = (Group) parent.getChildren()[1]; - Control pList[] = pps.getChildren(); - for(Control c: pList){ - String s= controlToString(c); - formValues.add(s); - } - String styleName= getStyleName(); - - //System.out.println("Style name is " + styleName); - - saveStyle(styleName); - parent.dispose(); - sm.readStyleFiles(styleName); - } - }); - - } - - - String sn = lh.localValue("styleName"); - String getStyleName(){ - for(int i = 0; i< formValues.size(); i++){ - if(formValues.get(i).equals(sn)){ - return formValues.get(i+1); - } - } - return ""; - } - - static String controlToString(Control c){ - String s = ""; - if(c instanceof Text){ - Text m = (Text)c; - s =m.getText(); - } - else if (c instanceof Label){ - Label l = (Label)c; - s = l.getText(); - } - else if (c instanceof Combo){ - Combo cb = (Combo)c; - s = cb.getText(); - } - return s; - } - - private void addFields(Group propertiesPanel, StyleProperty sp){ - Accessible accPropertiesPanel = propertiesPanel.getAccessible(); - Label l = addFieldLabel(propertiesPanel, sp.toString()+":"); - if(sp.getTypeIndex() == StyleProperty.INTEGER){- Text t = addFieldText(propertiesPanel, sp.getDefaultValue(), sp.getToolTip());
- Accessible accLabel = l.getAccessible(); - Accessible accText = t.getAccessible(); - accLabel.addRelation(ACC.RELATION_LABEL_FOR, accText); - accText.addRelation(ACC.RELATION_LABELLED_BY, accLabel); - accText.addRelation(ACC.RELATION_MEMBER_OF, accPropertiesPanel); - accText.addRelation(ACC.RELATION_LABELLED_BY, accPropertiesPanel); - formRelTab.put(l.getText(), t); - } - else if(sp.getTypeIndex() == StyleProperty.BOOLEAN){- Combo c = addFieldCombo(propertiesPanel, sp.getDefaultValue(), sp.getToolTip());
- Accessible accLabel = l.getAccessible(); - Accessible accCombo = c.getAccessible(); - accLabel.addRelation(ACC.RELATION_LABEL_FOR, accCombo); - accCombo.addRelation(ACC.RELATION_LABELLED_BY, accLabel); - accCombo.addRelation(ACC.RELATION_MEMBER_OF, accPropertiesPanel); - accCombo.addRelation(ACC.RELATION_LABELLED_BY, accPropertiesPanel); - formRelTab.put(l.getText(), c); - } - } - - private static Label addFieldLabel(Composite parent, String text){ - FormData data = new FormData(); - Label curLabel = new Label(parent, SWT.PUSH); - data.top= new FormAttachment(lastLabel, 12); - data.width = PROPERTYLABELWIDTH; - curLabel.setLayoutData(data); - curLabel.setText(text); - curLabel.setToolTipText(text); - lastLabel = curLabel; - return curLabel; - } -- private static Text addFieldText(Composite parent, String text, String toolTip){
- FormData data = new FormData(); - final Text curText = - new Text(parent, SWT.SINGLE | SWT.BORDER|SWT.RIGHT); - setNumericalValidation(curText); - - data.top= new FormAttachment(lastLabel, -2, SWT.TOP); - data.left = new FormAttachment(lastLabel, 5); - data.right = new FormAttachment(100, 0); - data.width = PROPERTYTEXTWIDTH; - curText.setLayoutData(data); - curText.setText(text); - curText.setToolTipText(toolTip); - curText.addFocusListener(focusListener); - return curText; - } -- private static Combo addFieldCombo(Composite parent, String text, String toolTip){
- FormData data = new FormData(); - Combo curText = - new Combo(parent, SWT.BORDER|SWT.RIGHT|SWT.READ_ONLY); - data.top= new FormAttachment(lastLabel, -2, SWT.TOP); - data.left = new FormAttachment(lastLabel, 5); - data.right = new FormAttachment(100, 0); - data.width = PROPERTYTEXTWIDTH; - curText.setLayoutData(data); - curText.setText(text); - curText.add(STRUE); - curText.add(SFALSE); - if(text.equals(STRUE)){ - curText.select(INDEXTRUE); - } - else{ - curText.select(INDEXFALSE); - } - curText.setToolTipText(toolTip); - return curText; - } - - private static void setNumericalValidation(final Text text){ - text.addModifyListener(new ModifyListener() { - @Override - public void modifyText(ModifyEvent event) { - String txt = ((Text) event.getSource()).getText(); - try { - // int num = Integer.parseInt(txt); - // Checks on num - } catch (NumberFormatException e) { - // Show error - new Notify(txt+ lh.localValue("styleNotValid")); - } - } - }); - - text.addVerifyListener(new VerifyListener() { - public void verifyText(VerifyEvent e) { - final String oldS = text.getText();- final String newS = oldS.substring(0, e.start) + e.text + oldS.substring(e.end);
- if (e.character == SWT.CR) { - e.doit = false; - } - else if(newS.equals("")){ - //only check if the string is not empty, - //focusListener handles the empty string - //do nothing - } - else{ - try { - BigDecimal bd = new BigDecimal(newS); - // value is decimal - // Test value range - } catch (final NumberFormatException numberFormatException) { - // value is not decimal - e.doit = false; - new Notify(lh.localValue("styleNumOnly")); - } - } - } - }); - } - - /**- * Write to the properties file with the style name in the local directory;
- * Create one if not existed yet. - * - * @param styleName - */ - private void saveStyle(String styleName){ - FileUtils fu = new FileUtils(); - String fileName = stylePath+fileSep+styleName+propExtension; - if(!fu.exists(fileName)){ - fu.create(fileName); - } - writeToFile(new File(fileName)); - } - - private void writeToFile(File file) { - BufferedWriter writer = null; - try { - writer = new BufferedWriter(new FileWriter(file)); - } catch (IOException e) { - new Notify(e.getMessage()); - } - try { - boolean isEven = false; - int i = 1; - for( String s:formValues) { - if (i++ == 1) { - s = "styleName="; - } else if (s.charAt(s.length()-1)==':'){ - s = s.substring(0,s.length()-1)+"="; - } - writer.write(s); - if(isEven){ - writer.newLine(); - } - isEven = !isEven; - } - } catch (IOException e) { - new Notify(e.getMessage()); - }finally{ - try { - writer.close(); - } catch (IOException e) { - new Notify(e.getMessage()); - } - } - } - - - /** - * This method load existing style values to the form - * @param style - */ - - void updateFields(Style style){ -// for(String s: formRelTab.keySet()){ -// System.out.println(s); -// Widget w = formRelTab.get(s); -// if(w instanceof Text){ -// System.out.println(((Text) w).getText()); -// } -// } - //style.print(); - - - for(String labelText: formRelTab.keySet()){ - Widget w = formRelTab.get(labelText); -- String key = labelText.substring(0,labelText.length()-1);// this filters out the ':' in the label text
- String value = style.styleSet.get(key); - - //System.out.println('+'+key + ":"+ value +", w:"+w.toString()); - if(value == null) continue; - if(w instanceof Text){ - ((Text) w).setText(value); - } - else if(w instanceof Combo){ - int i; - if(value.equals(STRUE)) { - i = INDEXTRUE; - } - else{ - i = INDEXFALSE; - } - ((Combo) w).select(i); - } - } - } - - public Hashtable<String, Widget> getFormRelTab(){ - return formRelTab; - } - -} =======================================--- /src/main/org/brailleblaster/wordprocessor/Style.java Thu May 2 06:45:04 2013
+++ /dev/null @@ -1,156 +0,0 @@ -/* BrailleBlaster Braille Transcription Application - * - * Copyright (C) 2010, 2012 - * ViewPlus Technologies, Inc. www.viewplus.com - * and - * Abilitiessoft, Inc. www.abilitiessoft.com - * and - * American Printing House for the Blind, Inc. www.aph.org - * - * All rights reserved - * - * This file may contain code borrowed from files produced by various - * Java development teams. These are gratefully acknoledged. - * - * This file is free software; you can redistribute it and/or modify it - * under the terms of the Apache 2.0 License, as given at - * http://www.apache.org/licenses/ - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE - * See the Apache 2.0 License for more details. - * - * You should have received a copy of the Apache 2.0 License along with - * this program; see the file LICENSE. - * If not, see - * http://www.apache.org/licenses/ - * - * Maintained by John J. Boyer john.boyer@xxxxxxxxxxxxxxxxx -*/ - -package org.brailleblaster.wordprocessor; - -import java.util.Enumeration; -import java.util.HashMap; -import java.util.Locale; -import java.util.ResourceBundle; - -class Style { - // This maybe used if this way is overcomplicated - // int lines_before; - // int lines_after; - // /* The following are percentages.*/ - // int left_margin; - // int first_line_indent; - // int right_margin; - // /* Various controls */ - // boolean keep_with_next; - // boolean dont_split; - // int orphan_control; - // boolean newpage_before; - // boolean newpage_after; - //StyleFormat format; /*StyleFormat is an enumeration class*/ - /* used for output */ - String elementName; - String attr1Name; - String attr1Value; - String attr2Name; - String attr2Value; - String attr3Name; - String attr3Value; - String styleName;- private boolean isBuildIn;//whether it is a buildin style, default to false
- //this stores different properties of a style - HashMap<String, String> styleSet - = new HashMap<String, String>(); - - /** - * Useful to load the build-in style properties files. - * i.e. "dist\programData\styles\[styleName].properties" - * - * @param styleName - */ - public Style(String styleName){ - this.styleName = styleName; - ResourceBundle labels = ResourceBundle.getBundle(styleName); - Enumeration bundleKeys = labels.getKeys(); - while (bundleKeys.hasMoreElements()) { - String key = (String)bundleKeys.nextElement(); - String value = labels.getString(key); - styleSet.put(key, value); - } - this.isBuildIn = false; - } - - /**- * Load default style setting in dist\programData\styles\default.properties
- */ - public Style(){ - this("default"); - } - - /** - * Useful to create a new style from scratch - * - * @param styleProperties - */ - public Style(HashMap<String, String> styleProperties){ - this(); - styleSet.putAll(styleProperties); - if(styleSet.get("styleName") != null){ - this.styleName = styleSet.get("styleName"); - } - } - - - /**- * This enables BB to load style using absolute url; useful when loading user's
- * local properties files - * - * @param styleName - * @param loader - */ - public Style(String styleName, ClassLoader loader){ - this.styleName = styleName;- ResourceBundle labels = ResourceBundle.getBundle(styleName, Locale.getDefault() , loader);
- Enumeration bundleKeys = labels.getKeys(); - while (bundleKeys.hasMoreElements()) { - String key = (String)bundleKeys.nextElement(); - String value = labels.getString(key); - styleSet.put(key, value); - } - } - - public String toString(){ - return styleName; - } - - public String getName(){ - return styleName; - } - - public void setProperty(String key, String value){ - styleSet.put(key, value); - } - - public String getProperty(String key){ - return styleSet.get(key); - } - - public void setIsBuildIn(boolean b){ - this.isBuildIn = b; - } - public boolean getIsBuildIn(){ - return this.isBuildIn; - } - - - public void print(){ - System.out.println(); - for(String s:styleSet.keySet()){ - System.out.println("key = '"+s + "': '" + styleSet.get(s)+"'"); - } - System.out.println(); - } -} =======================================--- /src/main/org/brailleblaster/wordprocessor/StyleManager.java Wed Apr 24 13:54:19 2013
+++ /dev/null @@ -1,66 +0,0 @@ -/* BrailleBlaster Braille Transcription Application - * - * Copyright (C) 2010, 2012 - * ViewPlus Technologies, Inc. www.viewplus.com - * and - * Abilitiessoft, Inc. www.abilitiessoft.com - * and - * American Printing House for the Blind, Inc. www.aph.org - * - * All rights reserved - * - * This file may contain code borrowed from files produced by various - * Java development teams. These are gratefully acknoledged. - * - * This file is free software; you can redistribute it and/or modify it - * under the terms of the Apache 2.0 License, as given at - * http://www.apache.org/licenses/ - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE - * See the Apache 2.0 License for more details. - * - * You should have received a copy of the Apache 2.0 License along with - * this program; see the file LICENSE. - * If not, see - * http://www.apache.org/licenses/ - * - * Maintained by John J. Boyer john.boyer@xxxxxxxxxxxxxxxxx -*/ - -package org.brailleblaster.wordprocessor; - -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); - } - - void createStyle(String styleName){ - EditStyle es = new EditStyle(this); - es.create(styleName); - } - - void modifyStyle(Style style){ - EditStyle es = new EditStyle(this); - es.modify(style); - } - - void stylePanel(){ - sp.open(); - } - - void readStyleFiles(String styleName){ - sp.readStyleFiles(styleName); - } -} =======================================--- /src/main/org/brailleblaster/wordprocessor/StylePanel.java Wed Apr 24 13:54:19 2013
+++ /dev/null @@ -1,385 +0,0 @@ -/* BrailleBlaster Braille Transcription Application - * - * Copyright (C) 2010, 2012 - * ViewPlus Technologies, Inc. www.viewplus.com - * and - * Abilitiessoft, Inc. www.abilitiessoft.com - * and - * American Printing House for the Blind, Inc. www.aph.org - * - * All rights reserved - * - * This file may contain code borrowed from files produced by various - * Java development teams. These are gratefully acknoledged. - * - * This file is free software; you can redistribute it and/or modify it - * under the terms of the Apache 2.0 License, as given at - * http://www.apache.org/licenses/ - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE - * See the Apache 2.0 License for more details. - * - * You should have received a copy of the Apache 2.0 License along with - * this program; see the file LICENSE. - * If not, see - * http://www.apache.org/licenses/ - * - * Maintained by John J. Boyer john.boyer@xxxxxxxxxxxxxxxxx -*/ - -package org.brailleblaster.wordprocessor; - -import java.io.File; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Locale; -import java.util.ResourceBundle; - -import org.brailleblaster.BBIni; -import org.brailleblaster.localization.LocaleHandler; -import org.brailleblaster.util.FileUtils; -import org.brailleblaster.util.YesNoChoice; -import org.eclipse.swt.SWT; -import org.eclipse.swt.accessibility.ACC; -import org.eclipse.swt.accessibility.Accessible; -import org.eclipse.swt.custom.StyledText; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.graphics.Rectangle; -import org.eclipse.swt.layout.FormLayout; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Combo; -import org.eclipse.swt.widgets.Dialog; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Monitor; -import org.eclipse.swt.widgets.Shell; - -/* TODO- * 1. Can user modify build-in styles? If yes, then do we keep the original build-in properties file?
- * 2. Delete function. Can users delete build-in styles? - * 3. Add localized strings - */ - - -public class StylePanel extends Dialog{ - static Display display; - static Shell stylePanel; - - Button delete; - Button create; - Button modify; - Button apply; - - static int propertyLabelWidth = 125; - static int propertyTextWidth = 100; - - private String fileSep; - private StyleManager sm; - private String localStylesPath; - private String buildInStylesPath; - private final String PROPEXTENSION = ".properties"; - - - private static HashMap<String, Style> styleMap - = new HashMap<String, Style>(); - - FileUtils fu = new FileUtils(); - private Combo combo; - private LocaleHandler lh = new LocaleHandler(); - ArrayList<Style> styleList;//styles - ArrayList<String> displayArr;//Styles' names for display - - public StylePanel (Shell parent, int style) { - super (parent, style); - } - -// StylePanel(StyleManager styleManager) { -// this(styleManager.dm.documentWindow, SWT.NONE); -// this.sm = styleManager; -// display = BBIni.getDisplay(); -// fileSep = BBIni.getFileSep(); -// localStylesPath = BBIni.getStylePath(); -// buildInStylesPath = BBIni.getProgramDataPath()+fileSep+"styles" ; -// readStyleFiles("default"); -// } - StylePanel(StyleManager styleManager) { - this(styleManager.dm.getShell(), SWT.NONE); - this.sm = styleManager; - display = styleManager.dm.getDisplay(); - fileSep = BBIni.getFileSep(); - localStylesPath = BBIni.getStylePath(); - buildInStylesPath = BBIni.getProgramDataPath()+fileSep+"styles" ; - readStyleFiles("default"); - } - - /**- * Read style properties files and update the combo if it has been created;
- * Then set the default item index of the combo to the index of styleName - * @param styleName - */ - public void readStyleFiles(String styleName){ - styleList = new ArrayList<Style>(); - readStyleFromBuildIn(); - readStyleFromLocal(); - displayArr = new ArrayList<String>(); - for(Style style: styleList){ - String displayName = style.toString();- if(style.getIsBuildIn()) displayName += " [" + lh.localValue("styleBuildIn")+"]";
- displayArr.add(displayName); - } - if(combo != null){- combo.setItems((String[])displayArr.toArray(new String[displayArr.size()]));
- int index = (styleName!=null)?displayArr.indexOf(styleName):0; - combo.select(index); - } - } - - private void readStyleFromBuildIn(){ - File dir = new File(buildInStylesPath); - if(!dir.exists()) { - //no build-in styles - return; - } - String[] children = dir.list(); - for(int curStr = 0; curStr < children.length; curStr++){ - int index = children[curStr].indexOf(PROPEXTENSION); - - // This isn't a style file. Skip it. - if(index < 0) - continue; - - String styleName = children[curStr].substring(0,index); - Style style = new Style(styleName); - style.setIsBuildIn(true); - styleList.add(style); - } - } - - private void readStyleFromLocal(){ - File dir = new File(localStylesPath); - ClassLoader loader = null; - try { - URL[] urls={ - dir.toURI().toURL() - }; - loader = new URLClassLoader(urls); - } catch (MalformedURLException e){ - e.printStackTrace(); - } - String[] children = dir.list(); - for(String s:children){ - int index = s.indexOf(PROPEXTENSION); - String styleName = s.substring(0,index); - Style style = new Style(styleName, loader); - styleList.add(style); - } - } - - void open(){ - Shell parent = getParent(); - Display display = parent.getDisplay(); - stylePanel = new Shell(parent, SWT.DIALOG_TRIM); - stylePanel.setText(lh.localValue("Style Panel")); - FormLayout layout = new FormLayout(); - layout.marginWidth = 10; - layout.marginHeight = 10; - stylePanel.setLayout(layout); - - Monitor primary = display.getPrimaryMonitor(); - Rectangle bounds = primary.getBounds(); - Rectangle rect = stylePanel.getBounds(); - int x = bounds.x + ((bounds.width - rect.width) / 2) + 10; - int y = bounds.y + ((bounds.height - rect.height) / 2) + 10; - stylePanel.setLocation (x, y); - - GridLayout gridLayout = new GridLayout (); - stylePanel.setLayout (gridLayout); - gridLayout.marginTop = 15; - gridLayout.marginBottom = 15; - gridLayout.marginLeft = 10; - gridLayout.marginRight = 10; - gridLayout.numColumns = 7; - //gridLayout.horizontalSpacing = 15; - gridLayout.makeColumnsEqualWidth =true; - - - Label name = new Label(stylePanel, SWT.HORIZONTAL); - name.setText(lh.localValue("styleName")); - - combo = new Combo (stylePanel, SWT.DROP_DOWN);- combo.setItems((String[])displayArr.toArray(new String[displayArr.size()]));
- combo.select(0); - GridData data = new GridData(GridData.FILL_HORIZONTAL); - data.horizontalSpan = 2; - combo.setLayoutData(data); - - Accessible accName = name.getAccessible(); - Accessible accNameCombo = combo.getAccessible(); - accName.addRelation(ACC.RELATION_LABEL_FOR, accNameCombo); - accNameCombo.addRelation(ACC.RELATION_LABELLED_BY, accName); - - create = new Button(stylePanel, SWT.PUSH); - modify = new Button(stylePanel, SWT.PUSH); - delete = new Button(stylePanel, SWT.PUSH); - apply = new Button(stylePanel, SWT.PUSH); - - delete.setText(lh.localValue("styleDelete")); - data = new GridData(GridData.FILL_HORIZONTAL); - delete.setLayoutData(data); - - create.setText(lh.localValue("styleCreate")); - create.setLayoutData(data); - - modify.setText(lh.localValue("styleModify")); - modify.setLayoutData(data); - - apply.setText(lh.localValue("styleApply"));//need to add to i18n files - apply.setLayoutData(data); - updateButtons(isExisted() >= 0); - - - combo.addModifyListener(new ModifyListener(){ - @Override - public void modifyText(ModifyEvent e) { - updateButtons(isExisted() >= 0); - } - }); - - - apply.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - int key = combo.getSelectionIndex(); - if(key != -1){ - Style style = styleList.get(key); - //printStyle(style); - apply(style); - } - stylePanel.close(); - } - }); - - modify.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - int key = combo.getSelectionIndex(); - if(key != -1){ - Style style = styleList.get(key); - modify(style); - }else{ - key = isExisted(); - if(key != -1){ - Style style = styleList.get(key); - modify(style); - }else{ - System.out.println("trying to modify a style that doesn't exsist"); - } - } - } - }); - - create.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - String styleName = combo.getText(); - create(styleName); - } - }); - - delete.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) {- YesNoChoice prompt = new YesNoChoice(lh.localValue("styleDeleteMsg")+"\""+combo.getText()+"\"?");
- if(prompt.result == SWT.YES){ - int key = isExisted(); - Style style = styleList.get(key); - delete(style); - } - } - }); - - // show the SWT window - stylePanel.pack(); - stylePanel.open(); - while (!stylePanel.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - // tear down the SWT window - stylePanel.dispose(); - } - - /** - * Check whether the current text in the combo field is already a style. - * return the index if exist; -1 otherwise. - */ - int isExisted(){ - String list[] = combo.getItems(); - String styleName = combo.getText(); - for(int i =0; i< list.length; i++){ - if(list[i].equals(styleName)){ - return i; - } - } - return -1; - } - - /** - * update button's enabled status based on whether the style is existed - * - * @param style - */ - - void updateButtons(boolean isExisted){ - modify.setEnabled(isExisted); - delete.setEnabled(isExisted); - apply.setEnabled(isExisted); - create.setEnabled(!isExisted); - if(isExisted){ - stylePanel.setDefaultButton(apply); - }else{ - stylePanel.setDefaultButton(create); - } - } - - - void apply(Style style){ -// if(view == null){ -// this.view = dm.daisy.view; -// } -// view.setLineIndent(1, 1, 100); - //style.print(); - } - - void create(String styleName){ - sm.createStyle(styleName); - } - - void modify(Style style){ - sm.modifyStyle(style); - } - - void delete(Style style){ - if(style.getIsBuildIn()){ - //if it is build-in style, should it be deleted? - }else{- String fileName = localStylesPath + fileSep +style.getName() + PROPEXTENSION;
- //System.out.println("deleting" + fileName); - if(fu.deleteFile(fileName)){ - readStyleFiles(null); - }else{ - System.out.println("fail to delete: " + fileName); - } - } - } - - void printStyle(Style style){ - style.print(); - } -} =======================================--- /src/main/org/brailleblaster/wordprocessor/StyleProperty.java Wed Apr 24 13:54:19 2013
+++ /dev/null @@ -1,93 +0,0 @@ -/* BrailleBlaster Braille Transcription Application - * - * Copyright (C) 2010, 2012 - * ViewPlus Technologies, Inc. www.viewplus.com - * and - * Abilitiessoft, Inc. www.abilitiessoft.com - * and - * American Printing House for the Blind, Inc. www.aph.org - * - * All rights reserved - * - * This file may contain code borrowed from files produced by various - * Java development teams. These are gratefully acknoledged. - * - * This file is free software; you can redistribute it and/or modify it - * under the terms of the Apache 2.0 License, as given at - * http://www.apache.org/licenses/ - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE - * See the Apache 2.0 License for more details. - * - * You should have received a copy of the Apache 2.0 License along with - * this program; see the file LICENSE. - * If not, see - * http://www.apache.org/licenses/ - * - * Maintained by John J. Boyer john.boyer@xxxxxxxxxxxxxxxxx -*/ - -package org.brailleblaster.wordprocessor; - -public enum StyleProperty { - // Each property takes two parameters - //the first one is type index, which indicates - //the type of acceptable value of this prop, - //i.e. integer, boolean for now. The other - //is the default value displayed in the form - - linesBefore(0,1), - linesAfter(0,1), - /* The following are percentages.*/ - leftMargin(0,5), - firstLineIndent(0,2), - rightMargin(0,5), - /* Various controls */ - keepWithNext(1,true), - dontSplit(1,false), - orphanControl(1,false), - newpageBefore(1,true), - newpageAfter(1,true); - - final static int INTEGER = 0; - final static int BOOLEAN = 1; - private int typeIndex; - private int defaultInt; - private boolean defaultBool; - - StyleProperty(int index, int defaultValue){ - typeIndex = index; - defaultInt = defaultValue; - } - StyleProperty(int index, boolean defaultValue){ - typeIndex = index; - defaultBool = defaultValue; - } - - String getToolTip(){ - if(typeIndex == INTEGER){ - return this.toString()+": Please enter an integer"; - } - else if (typeIndex == BOOLEAN){ - return this.toString()+": Please select a boolean value"; - } - return ""; - } - - int getTypeIndex(){ - return typeIndex; - } - - String getDefaultValue(){ - if(typeIndex == INTEGER){ - return Integer.toString(this.defaultInt); - } - else if(typeIndex == BOOLEAN){ - if(this.defaultBool)return "True"; - else return "False"; - } - return ""; - } -} =======================================--- /src/main/org/brailleblaster/wordprocessor/WPManager.java Mon Jul 15 12:05:29 2013 +++ /src/main/org/brailleblaster/wordprocessor/WPManager.java Mon Jul 29 06:13:08 2013
@@ -44,6 +44,7 @@ import org.eclipse.swt.widgets.TabFolder; import org.brailleblaster.BBIni; import org.brailleblaster.settings.Welcome; +import org.brailleblaster.stylePanel.StyleManager; import org.brailleblaster.util.YesNoChoice; import java.util.LinkedList;