5 new revisions: Revision: 3fe39147b0bb Branch: rt2165-styleDefsTab Author: Leon Blakey <lblakey@xxxxxxx> Date: Thu Mar 12 13:31:50 2015 UTC Log: Updated loading XMLConfigHandler with changes in UTD https://code.google.com/p/brailleblaster/source/detail?r=3fe39147b0bb Revision: 469cf0cb56c5 Branch: rt2165-styleDefsTab Author: Leon Blakey <lblakey@xxxxxxx> Date: Thu Mar 12 14:41:42 2015 UTC Log: Rewrote PageProperties tab porting to UTD https://code.google.com/p/brailleblaster/source/detail?r=469cf0cb56c5 Revision: 6ed629be29a3 Branch: rt2165-styleDefsTab Author: Leon Blakey <lblakey@xxxxxxx> Date: Thu Mar 12 16:28:36 2015 UTCLog: Auto size Braille Settings dialog based on widget requirements instead...
https://code.google.com/p/brailleblaster/source/detail?r=6ed629be29a3 Revision: 4a2a39a8f55d Branch: rt2165-styleDefsTab Author: Leon Blakey <lblakey@xxxxxxx> Date: Thu Mar 12 16:39:08 2015 UTC Log: Removed ugly border around several setting tab's content https://code.google.com/p/brailleblaster/source/detail?r=4a2a39a8f55d Revision: 91ec9f23efb2 Branch: rt2165-styleDefsTab Author: Leon Blakey <lblakey@xxxxxxx> Date: Thu Mar 12 18:17:22 2015 UTC Log: Ported PageNumberTab in Settings dialog to UTD https://code.google.com/p/brailleblaster/source/detail?r=91ec9f23efb2 ============================================================================== Revision: 3fe39147b0bb Branch: rt2165-styleDefsTab Author: Leon Blakey <lblakey@xxxxxxx> Date: Thu Mar 12 13:31:50 2015 UTC Log: Updated loading XMLConfigHandler with changes in UTD https://code.google.com/p/brailleblaster/source/detail?r=3fe39147b0bb Modified: /src/main/org/brailleblaster/document/BBDocument.java =======================================--- /src/main/org/brailleblaster/document/BBDocument.java Fri Mar 6 21:31:05 2015 UTC +++ /src/main/org/brailleblaster/document/BBDocument.java Thu Mar 12 13:31:50 2015 UTC
@@ -99,12 +99,11 @@ this.dm = dm; try { - engine = new UTDTranslationEngine(); //Style TODO: Somehow automagically load the correct config- utdConfig = new XMLConfigHandler(new File("utd-config"), "nimas", new File("utd-config/styleDefs.xml"));
- engine.setActionMap(utdConfig.loadActions()); - engine.setStyleDefinitions(utdConfig.loadStyleDefinitions()); - engine.setStyleMap(utdConfig.loadStyle(engine.getStyleDefinitions())); + utdConfig = new XMLConfigHandler(); + engine = utdConfig.loadEngine(new File("utd-config/utdengine.xml"));+ engine.setStyleDefinitions(utdConfig.loadStyleDefinitions(new File("utd-config/styleDefs.xml")));
+ utdConfig.loadMappings(engine, new File("utd-config"), "nimas"); } catch(Exception e) { throw new RuntimeException("Could not initialize UTD", e); } ============================================================================== Revision: 469cf0cb56c5 Branch: rt2165-styleDefsTab Author: Leon Blakey <lblakey@xxxxxxx> Date: Thu Mar 12 14:41:42 2015 UTC Log: Rewrote PageProperties tab porting to UTD https://code.google.com/p/brailleblaster/source/detail?r=469cf0cb56c5 Modified: /src/main/org/brailleblaster/settings/SettingsManager.java /src/main/org/brailleblaster/settings/ui/ConfigPanel.java /src/main/org/brailleblaster/settings/ui/Page.java /src/main/org/brailleblaster/settings/ui/PagePropertiesTab.java =======================================--- /src/main/org/brailleblaster/settings/SettingsManager.java Wed Feb 18 20:25:00 2015 UTC +++ /src/main/org/brailleblaster/settings/SettingsManager.java Thu Mar 12 14:41:42 2015 UTC
@@ -22,8 +22,6 @@private static final String USER_SETTINGS = BBIni.getUserProgramDataPath() + BBIni.getFileSep() + "liblouisutdml" + BBIni.getFileSep() + "lbu_files" + BBIni.getFileSep() + "utdmlSettings.properties";
private boolean isMetric;- private final Page [] standardPages = {new Page("Standard",11.5 ,11),new Page("Letter",8.5 ,11), new Page("Legal", 8.5, 14), new Page("A3", 11.69, 16.54),
- new Page("A4",8.27,11.69), new Page("A5", 5.83, 8.27)}; private ConfigPanel configPanel; private HashMap<String, String>outputMap; @@ -179,10 +177,6 @@ } return settingsString; } - - public Page[] getStandardSizes(){ - return standardPages; - } public void saveConfiguration(HashMap<String, String>map){ outputMap.clear(); =======================================--- /src/main/org/brailleblaster/settings/ui/ConfigPanel.java Fri Mar 6 21:31:05 2015 UTC +++ /src/main/org/brailleblaster/settings/ui/ConfigPanel.java Thu Mar 12 14:41:42 2015 UTC
@@ -45,7 +45,7 @@ setFormLayout(folder, 0, 100, 0, 94); final HashMap<String, String> settingsCopy = sm.getMapClone(); - pageProperties = new PagePropertiesTab(folder, sm, settingsCopy);+ pageProperties = new PagePropertiesTab(folder, m.getDocument().getEngine().getPageSettings()); translationSettings = new TranslationSettingsTab(folder, sm, settingsCopy);
pageNumTab = new PageNumbersTab(folder, sm, settingsCopy); styleDefsTab = new StyleDefinitionsTab(folder, m); =======================================--- /src/main/org/brailleblaster/settings/ui/Page.java Mon May 12 19:44:36 2014 UTC +++ /src/main/org/brailleblaster/settings/ui/Page.java Thu Mar 12 14:41:42 2015 UTC
@@ -1,19 +1,19 @@ package org.brailleblaster.settings.ui; +import org.brailleblaster.utd.utils.PageUnitConverter; + public class Page { String type; double width, height, mmWidth, mmHeight; - public Page(String type, double width, double height){+ public Page(String type, double width, double height, boolean convertToMM){
this.type = type; - this.width = width; - this.height = height; - this.mmWidth = inchesToMM(width); - this.mmHeight = inchesToMM(height); + this.width = convertToMM ? PageUnitConverter.inchesToMM(width) : width;+ this.height = convertToMM ? PageUnitConverter.inchesToMM(height) : height;
} - private double inchesToMM(double inches){ - double denominator = 0.039370; - return Math.round((inches / denominator) * 10.0) / 10.0; + @Override + public String toString() { + return type + " (" + width + ", " + height + ")"; } } =======================================--- /src/main/org/brailleblaster/settings/ui/PagePropertiesTab.java Wed Feb 11 17:55:48 2015 UTC +++ /src/main/org/brailleblaster/settings/ui/PagePropertiesTab.java Thu Mar 12 14:41:42 2015 UTC
@@ -1,876 +1,458 @@ package org.brailleblaster.settings.ui; -import java.awt.Event; -import java.io.File; -import java.io.IOException; import java.text.DecimalFormat; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.Map.Entry; -import java.util.Properties; - -import org.brailleblaster.BBIni; +import java.util.Arrays; +import java.util.List; +import java.util.Optional; +import java.util.function.Consumer; +import java.util.function.DoubleUnaryOperator; +import java.util.function.Supplier; import org.brailleblaster.localization.LocaleHandler; -import org.brailleblaster.settings.SettingsManager; -import org.brailleblaster.util.Notify; +import org.brailleblaster.utd.PageSettings; +import org.brailleblaster.utd.UTDTranslationEngine; +import org.brailleblaster.utd.utils.PageUnitConverter; import org.eclipse.swt.SWT; import org.eclipse.swt.events.KeyAdapter; import org.eclipse.swt.events.KeyEvent; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.KeyListener; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.events.TraverseEvent; -import org.eclipse.swt.events.TraverseListener; -import org.eclipse.swt.events.VerifyEvent; -import org.eclipse.swt.events.VerifyListener; -import org.eclipse.swt.layout.FillLayout; -import org.eclipse.swt.layout.FormAttachment; -import org.eclipse.swt.layout.FormData; -import org.eclipse.swt.layout.FormLayout; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.layout.RowLayout; 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.Group; import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.TabFolder; import org.eclipse.swt.widgets.TabItem; import org.eclipse.swt.widgets.Text; -import org.eclipse.swt.widgets.Display;//rl -import org.brailleblaster.util.PropertyFileManager; -import org.brailleblaster.settings.ui.ConfigPanel; -import org.brailleblaster.util.FileUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; -public class PagePropertiesTab<heightWidthMod> { - HashMap<String, String> settingsMap; - SettingsManager sm; - TabItem item; - Composite group; - PropertyFileManager pfm; - FileUtils fu; - BBIni bbini; - private static final String userSettings = BBIni.getUserSettings(); - - Group sizeGroup, marginGroup, pageGroup, buttonGroup, unitsGroup; - Label pageSizeLabel, widthLabel, heightLabel, linesPerPageLabel, - cellsPerLineLabel, marginTopLabel, marginBottomLabel, - marginLeftLabel, marginRightLabel; - - Combo pageTypes; - Text widthBox, heightBox, linesBox, cellsBox, marginTopBox, marginLeftBox, +/** + * + * @author lblakey + */ +public class PagePropertiesTab {+ private static final Logger log = LoggerFactory.getLogger(PagePropertiesTab.class); + private static final DecimalFormat NUMBER_FORMATTER = new DecimalFormat("###.##");
+ private final List<Page> standardPages; + private final PageUnitConverter unitConverter; + private final LocaleHandler lh = new LocaleHandler();+ private final Text widthBox, heightBox, linesBox, cellsBox, marginTopBox, marginLeftBox,
marginRightBox, marginBottomBox; - Button okButton, cancelButton, regionalButton, cellsLinesButton;+ private final Label marginTopLabel, marginBottomLabel, marginLeftLabel, marginRightLabel;
+ private final Combo pageTypes; + private final Button regionalButton, cellsLinesButton; + private final String unitName, unitSuffix; + private boolean marginLocalUnit = true; + /** + * Internal representation always in local units (inch/mm). + */+ private double pageHeight, pageWidth, pageCells, pageLines, marginTop, marginBottom, marginLeft, marginRight;
- boolean listenerLocked; - LocaleHandler lh; - public String currentUnits = "regional"; - DecimalFormat df = new DecimalFormat("#.#"); - boolean userModified; - protected boolean heightWidthMod; + public PagePropertiesTab(TabFolder folder, PageSettings pageSettings) { + //---Init--- + this.unitConverter = pageSettings.getUnitConverter(); + boolean metric = unitConverter.isMetric(); + unitName = metric ? "mm" : "in"; + unitSuffix = " (" + unitName + ")"; + standardPages = Arrays.asList( + new Page("Standard", 11.5, 11, metric), + new Page("Letter", 8.5, 11, metric), + new Page("Legal", 8.5, 14, metric), + new Page("A3", 11.69, 16.54, metric), + new Page("A4", 8.27, 11.69, metric), + new Page("A5", 5.83, 8.27, metric) + ); - PagePropertiesTab(TabFolder folder, final SettingsManager sm, - HashMap<String, String> settingsMap) { + //---Add widgets to tab--- + TabItem tab = new TabItem(folder, 0); + tab.setText(lh.localValue("pageProperties")); - lh = new LocaleHandler(); - this.sm = sm; - this.settingsMap = settingsMap; - listenerLocked = false; - item = new TabItem(folder, 0); - item.setText(lh.localValue("pageProperties")); + Composite parent = new Composite(folder, 0); + parent.setLayout(new GridLayout(1, true)); + tab.setControl(parent); - group = new Composite(folder, 0); - group.setLayout(new FormLayout()); - item.setControl(group); - setFormLayout(group, 0, 100, 0, 60); - - unitsGroup = new Group(group, SWT.BORDER); - unitsGroup.setText(lh.localValue("measurementUnits")); - unitsGroup.setLayout(new FillLayout()); - setFormLayout(unitsGroup, 0, 100, 0, 20); - - regionalButton = new Button(unitsGroup, SWT.RADIO); - regionalButton.setText(lh.localValue("regional")); - - cellsLinesButton = new Button(unitsGroup, SWT.RADIO); - cellsLinesButton.setText(lh.localValue("cellsLines")); - - PropertyFileManager pfm = new PropertyFileManager(userSettings); - String value = pfm.getProperty("currentUnits"); - if (value.equals("cellsLines")) - cellsLinesButton.setSelection(true); - else - regionalButton.setSelection(true); - - sizeGroup = new Group(group, SWT.BORDER); - sizeGroup.setText(lh.localValue("pageSize")); - sizeGroup.setLayout(new FillLayout()); - setFormLayout(sizeGroup, 0, 100, 20, 65); - - pageGroup = new Group(sizeGroup, 0); + //Group page size + Group pageGroup = new Group(parent, 0); + pageGroup.setText(lh.localValue("pageSize")); pageGroup.setLayout(new GridLayout(2, true)); + setGridData(pageGroup); - pageSizeLabel = new Label(pageGroup, 0); - pageSizeLabel.setText(lh.localValue("pageSize")); - setGridData(pageSizeLabel); - + addLabel(pageGroup, lh.localValue("pageSize")); pageTypes = new Combo(pageGroup, SWT.NONE); - setStandardPages(); - setDefault(); setGridData(pageTypes); - widthLabel = new Label(pageGroup, 0); - widthLabel.setText(lh.localValue("width")); + addLabel(pageGroup, lh.localValue("width") + unitSuffix); widthBox = new Text(pageGroup, SWT.BORDER); - addDoubleListener(widthBox); + addDoubleFilter(widthBox, false); setGridData(widthBox); - setValue(widthBox, "paperWidth"); - heightLabel = new Label(pageGroup, 0); - heightLabel.setText(lh.localValue("height")); + addLabel(pageGroup, lh.localValue("height") + unitSuffix); heightBox = new Text(pageGroup, SWT.BORDER); - addDoubleListener(heightBox); + addDoubleFilter(heightBox, false); setGridData(heightBox); - setValue(heightBox, "paperHeight"); - linesPerPageLabel = new Label(pageGroup, 0); - linesPerPageLabel.setText(lh.localValue("linesPerPage")); - + addLabel(pageGroup, lh.localValue("linesPerPage")); linesBox = new Text(pageGroup, SWT.BORDER); setGridData(linesBox); - linesBox.setText((String.valueOf(calculateLinesPerPage(Double - .valueOf(settingsMap.get("paperHeight")))))); - addDoubleListener(linesBox); - setValue(linesBox,"linesPerPage"); + addDoubleFilter(linesBox, true); - cellsPerLineLabel = new Label(pageGroup, 0); - cellsPerLineLabel.setText(lh.localValue("cellsPerLine")); - + addLabel(pageGroup, lh.localValue("cellsPerLine")); cellsBox = new Text(pageGroup, SWT.BORDER); setGridData(cellsBox); - cellsBox.setText(String.valueOf(calculateCellsPerLine(Double - .valueOf(settingsMap.get("paperWidth"))))); - addDoubleListener(cellsBox); - setValue(cellsBox,"cellsPerLine"); + addDoubleFilter(cellsBox, true); - marginGroup = new Group(group, SWT.BORDER); + //Margin group + Group marginGroup = new Group(parent, 0); marginGroup.setLayout(new GridLayout(2, true)); marginGroup.setText(lh.localValue("margins")); - setFormLayout(marginGroup, 0, 100, 65, 100); + setGridData(marginGroup); - marginTopLabel = new Label(marginGroup, 0); - marginTopLabel.setText(lh.localValue("topMargin")); + //Units subgroup + addLabel(marginGroup, lh.localValue("measurementUnits")); + Composite unitsGroup = new Composite(marginGroup, 0); + unitsGroup.setLayout(new GridLayout(2, true)); + regionalButton = new Button(unitsGroup, SWT.RADIO); + regionalButton.setText(unitName); + regionalButton.setSelection(true); + setGridData(regionalButton); + cellsLinesButton = new Button(unitsGroup, SWT.RADIO); + cellsLinesButton.setText(lh.localValue("cellsLines")); + setGridData(cellsLinesButton); + + //All other margins+ marginTopLabel = addLabel(marginGroup, lh.localValue("topMargin") + unitSuffix);
marginTopBox = new Text(marginGroup, SWT.BORDER); - addDoubleListener(marginTopBox); + addDoubleFilter(marginTopBox, false); setGridData(marginTopBox); - setValueForMargins(marginTopBox, "topMargin"); - addMarginListener(marginTopBox, "topMargin"); - marginBottomLabel = new Label(marginGroup, 0); - marginBottomLabel.setText(lh.localValue("bottomMargin"));+ marginBottomLabel = addLabel(marginGroup, lh.localValue("bottomMargin") + unitSuffix);
marginBottomBox = new Text(marginGroup, SWT.BORDER); - addDoubleListener(marginBottomBox); + addDoubleFilter(marginBottomBox, false); setGridData(marginBottomBox); - setValueForMargins(marginBottomBox, "bottomMargin"); - addMarginListener(marginBottomBox, "bottomMargin"); - marginLeftLabel = new Label(marginGroup, 0); - marginLeftLabel.setText(lh.localValue("leftMargin"));+ marginLeftLabel = addLabel(marginGroup, lh.localValue("leftMargin") + unitSuffix);
marginLeftBox = new Text(marginGroup, SWT.BORDER); - addDoubleListener(marginLeftBox); + addDoubleFilter(marginLeftBox, false); setGridData(marginLeftBox); - setValueForMargins(marginLeftBox, "leftMargin"); - addMarginListener(marginLeftBox, "leftMargin"); - marginRightLabel = new Label(marginGroup, 0); - marginRightLabel.setText(lh.localValue("rightMargin"));+ marginRightLabel = addLabel(marginGroup, lh.localValue("rightMargin") + unitSuffix);
marginRightBox = new Text(marginGroup, SWT.BORDER); - addDoubleListener(marginRightBox); + addDoubleFilter(marginRightBox, false); setGridData(marginRightBox); - setValueForMargins(marginRightBox, "rightMargin"); - addMarginListener(marginRightBox, "rightMargin"); - Control[] tabList = { sizeGroup, marginGroup, unitsGroup }; - group.setTabList(tabList); + //----Add listeners----+ //When the user selects a page from the drop down, fill out the width, height, cells, and lines boxes + pageTypes.addSelectionListener(makeSelectedListener((e) -> onStandardPageSelected()));
- if (widthBox.getText().length() > 0 || heightBox.getText().length() > 0) - checkStandardSizes(); + //Size fields + //When a user types a digit, adjust cells, lines and page combo + widthBox.addKeyListener(makeFieldListener(+ () -> widthBox.getText(), (v) -> pageWidth = v, (e) -> calculateCellsLinesAndUpdate()));
+ heightBox.addKeyListener(makeFieldListener(+ () -> heightBox.getText(), (v) -> pageHeight = v, (e) -> calculateCellsLinesAndUpdate()));
- addListeners(); - } + //Cell fields + cellsBox.addKeyListener(makeFieldListener(+ () -> cellsBox.getText(), (v) -> pageCells = v, (e) -> onCellLinesChange()));
+ linesBox.addKeyListener(makeFieldListener(+ () -> linesBox.getText(), (v) -> pageLines = v, (e) -> onCellLinesChange()));
- private void addDoubleListener(final Text t) { - t.addKeyListener(new KeyAdapter() { - @Override - public void keyPressed(KeyEvent e) { - if (!Character.isDigit(e.character) && e.keyCode != SWT.BS - && e.keyCode != SWT.DEL && e.keyCode != SWT.ARROW_LEFT - && e.keyCode != SWT.ARROW_RIGHT) { - if (e.character != '.' - || (e.character == '.' && t.getText().contains("."))) - e.doit = false; - } - } - }); - } + //Update cells/line and lines/page when margins change+ DoubleUnaryOperator marginHeight = (v) -> marginLocalUnit ? v : unitConverter.calculateLinesHeight(v); + DoubleUnaryOperator marginWidth = (v) -> marginLocalUnit ? v : unitConverter.calculateCellsWidth(v);
+ marginTopBox.addKeyListener(makeFieldListener(+ () -> marginTopBox.getText(), marginHeight.andThen((v) -> marginTop = v), (e) -> calculateCellsLinesAndUpdate()));
+ marginBottomBox.addKeyListener(makeFieldListener(+ () -> marginBottomBox.getText(), marginHeight.andThen((v) -> marginBottom = v), (e) -> calculateCellsLinesAndUpdate()));
+ marginLeftBox.addKeyListener(makeFieldListener(+ () -> marginLeftBox.getText(), marginWidth.andThen((v) -> marginLeft = v), (e) -> calculateCellsLinesAndUpdate()));
+ marginRightBox.addKeyListener(makeFieldListener(+ () -> marginRightBox.getText(), marginWidth.andThen((v) -> marginRight = v), (e) -> calculateCellsLinesAndUpdate()));
- private void addMarginListener(final Text t, final String type) { + //Margin unit suffixes+ SelectionListener marginUnitChangedListener = makeSelectedListener((e) -> onMarginUnitSelected());
+ regionalButton.addSelectionListener(marginUnitChangedListener); + cellsLinesButton.addSelectionListener(marginUnitChangedListener); - if (type.equals("leftMargin") || type.equals("rightMargin")) { + //---Set field default values--- + //Pages drop down box + for (Page curPage : standardPages) + pageTypes.add(curPage.toString()); - t.addModifyListener(new ModifyListener() { + //Page size+ if (pageSettings.getPaperHeight() != 0 && pageSettings.getPaperWidth() != 0) {
+ //User has set their own settings + pageHeight = pageSettings.getPaperHeight(); + pageWidth = pageSettings.getPaperWidth(); - @Override - public void modifyText(ModifyEvent e) { - if (!userModified) { - if (listenerLocked) { - if (cellsLinesButton.getSelection()) { -// settingsMap.put( -// type, -// String.valueOf(df -// .format(calcWidthFromCells(getDoubleValue((t)))))); - }// if cellsLinesButton - else { - settingsMap.put(type, getStringValue(t)); - }// else regionalButton - } // if listenerLocked - else { - if (regionalButton.getSelection()) { - settingsMap.put(type, getStringValue(t)); - cellsBox.setText(String - .valueOf(calculateCellsPerLine(getDoubleValue(widthBox)))); - linesBox.setText(String - .valueOf(calculateLinesPerPage(getDoubleValue(heightBox)))); - - }// if regionalButton - else { - settingsMap.put( - type, - String.valueOf(df - .format(calcWidthFromCells(getDoubleValue(t))))); - cellsBox.setText(String - .valueOf(calculateCellsPerLine(getDoubleValue(widthBox)))); - linesBox.setText(String - .valueOf(calculateLinesPerPage(getDoubleValue(heightBox)))); - }// else cellsLinesButton - }// else notListenerLocked - }// modifyText - }// if not userModified - });// modifyListener right or left - }// if type equals right or left - else { - t.addModifyListener(new ModifyListener() { - @Override - public void modifyText(ModifyEvent e) { - - if (!userModified) { - if (listenerLocked) { - if (cellsLinesButton.getSelection()) { -// settingsMap.put( -// type, -// String.valueOf(df.format(sm -// .calcHeightFromLines(getDoubleValue(t))))); - }// if cellsLinesButton - else { - - settingsMap.put(type, (getStringValue(t))); - }// else regionalButton - }// if listenerLocked - else { - if (regionalButton.getSelection()) { - settingsMap.put(type, getStringValue(t)); - cellsBox.setText(String - .valueOf(calculateCellsPerLine(getDoubleValue(widthBox)))); - linesBox.setText(String - .valueOf(calculateLinesPerPage(getDoubleValue(heightBox)))); - }// if regionalButton - else { - settingsMap.put( - type, - String.valueOf(df.format(sm - .calcHeightFromLines(getDoubleValue(t))))); - cellsBox.setText(String - .valueOf(calculateCellsPerLine(getDoubleValue(widthBox)))); - linesBox.setText(String - .valueOf(calculateLinesPerPage(getDoubleValue(heightBox)))); - }// else cellsLinesButton - }// else not listenerLocked - }// userModified false - }// modify text - });// modifyListener for top or bottom - }// if type equals top or bottom - - }// addMargin Listener - - private void setStandardPages() { - Page[] temp = sm.getStandardSizes(); - for (int i = 0; i < temp.length; i++) { - if (sm.isMetric()) - pageTypes.add(temp[i].type + " (" + temp[i].mmWidth + ", " - + temp[i].mmHeight + ")"); - else - pageTypes.add(temp[i].type + " (" + temp[i].width + ", " - + temp[i].height + ")"); + } else { + //TODO: assume the first one? + Page defaultPage = standardPages.get(0); + pageHeight = defaultPage.height; + pageWidth = defaultPage.width; } - } - private int searchList(char c) { - for (int i = 0; i < pageTypes.getItemCount(); i++) { - if (pageTypes.getItem(i).toLowerCase().charAt(0) == c) - return i; - } + marginTop = pageSettings.getTopMargin(); + marginBottom = pageSettings.getBottomMargin(); + marginLeft = pageSettings.getLeftMargin(); + marginRight = pageSettings.getRightMargin(); - return -1; + calculateCellsLinesAndUpdate(); } - private void setGridData(Control c) { - GridData gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.verticalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - c.setLayoutData(gridData); - } + /** + * Update UI with internally stored values + */ + private void updateFields() { + Optional<Page> matchedPage = standardPages.stream() + .filter((p) -> p.height == pageHeight && p.width == pageWidth) + .findFirst(); + if (matchedPage.isPresent()) + pageTypes.select(pageTypes.indexOf(matchedPage.get().toString())); + else if (pageTypes.getItemCount() == standardPages.size()) { + pageTypes.add(lh.localValue("custom")); + pageTypes.select(pageTypes.getItemCount() - 1); + } else + pageTypes.select(pageTypes.getItemCount() - 1); - private void addListeners() { + setTextIfDifferent(widthBox, pageWidth); + setTextIfDifferent(heightBox, pageHeight); - regionalButton.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { + setTextIfDifferent(linesBox, pageLines); + setTextIfDifferent(cellsBox, pageCells); - if (regionalButton.getSelection()) { - listenerLocked = true; - currentUnits = "regional"; - saveSettings(currentUnits); - modifyMargins(); - listenerLocked = false; - } - } - }); - cellsLinesButton.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - if (cellsLinesButton.getSelection()) { - listenerLocked = true; - currentUnits = "cellsLines"; - saveSettings(currentUnits); - modifyMargins(); - listenerLocked = false; - } - - } - }); - - widthBox.addModifyListener(new ModifyListener() { - @Override - public void modifyText(ModifyEvent e) { - - if (!listenerLocked) { - settingsMap.put("paperWidth", getStringValue(widthBox)); - checkStandardSizes(); - } - - } - }); - - heightBox.addModifyListener(new ModifyListener() { - @Override - public void modifyText(ModifyEvent e) { - - if (!listenerLocked) { - settingsMap.put("paperHeight", getStringValue(heightBox)); - checkStandardSizes(); - } - - } - }); - - cellsBox.addModifyListener(new ModifyListener() { - @Override - public void modifyText(ModifyEvent e) { - if (!userModified) - userModifiesCellsBox(); - - if (!listenerLocked&&!userModified) - settingsMap.put("cellsPerLine", getStringValue(cellsBox)); - - } - }); - - linesBox.addModifyListener(new ModifyListener() { - @Override - public void modifyText(ModifyEvent e) { - - if (!userModified) - userModifiesLinesBox(); - - if (!listenerLocked&&!userModified) - settingsMap.put("linesPerPage", getStringValue(linesBox)); - - }// modifyText - - });// modifyListener - - pageTypes.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - Page p = sm.getStandardSizes()[pageTypes.getSelectionIndex()]; - if (sm.isMetric()) { - widthBox.setText(String.valueOf(p.mmWidth)); - heightBox.setText(String.valueOf(p.mmHeight)); - cellsBox.setText(String - .valueOf(calculateCellsPerLine(p.mmWidth))); - linesBox.setText(String - .valueOf(calculateLinesPerPage(p.mmHeight))); - } else { - widthBox.setText(String.valueOf(p.width)); - heightBox.setText(String.valueOf(p.height)); - cellsBox.setText(String - .valueOf(calculateCellsPerLine(p.width))); - linesBox.setText(String - .valueOf(calculateLinesPerPage(p.height))); - } - - if (pageTypes.getItem(pageTypes.getItemCount() - 1).equals( - lh.localValue("custom"))) - pageTypes.remove(pageTypes.getItemCount() - 1); - } - }); - - pageTypes.addKeyListener(new KeyAdapter() { - @Override - public void keyPressed(KeyEvent e) { - if (e.keyCode != SWT.ARROW_DOWN && e.keyCode != SWT.ARROW_UP) { - int loc = searchList(e.character); - if (loc != -1) { - e.doit = false; - pageTypes.select(loc); - cellsBox.setText(String.valueOf(calculateCellsPerLine(Double - .valueOf(sm.getStandardSizes()[loc].width)))); - linesBox.setText(String.valueOf(calculateLinesPerPage(Double - .valueOf(sm.getStandardSizes()[loc].height)))); - } else - e.doit = false; - } - } - });+ setTextIfDifferent(marginTopBox, marginLocalUnit ? marginTop : unitConverter.calculateLinesInHeight(marginTop)); + setTextIfDifferent(marginBottomBox, marginLocalUnit ? marginBottom : unitConverter.calculateLinesInHeight(marginBottom)); + setTextIfDifferent(marginLeftBox, marginLocalUnit ? marginLeft : unitConverter.calculateCellsInWidth(marginLeft)); + setTextIfDifferent(marginRightBox, marginLocalUnit ? marginRight : unitConverter.calculateCellsInWidth(marginRight));
} - private void checkStandardSizes() { - Double width = getDoubleValue(widthBox); - Double height = getDoubleValue(heightBox); - - if (width != 0 && height != 0) { - boolean found = false; - for (int i = 0; i < sm.getStandardSizes().length && !found; i++) { - if (checkEqualHeight(sm.getStandardSizes()[i], height) - && checkEqualWidth(sm.getStandardSizes()[i], width)) { - pageTypes.select(i); - found = true; - - if (!sm.isMetric()) { - cellsBox.setText(String - .valueOf(calculateCellsPerLine(sm - .getStandardSizes()[i].width))); - linesBox.setText(String - .valueOf(calculateLinesPerPage(sm - .getStandardSizes()[i].height))); - } else { - cellsBox.setText(String - .valueOf(calculateCellsPerLine(sm - .getStandardSizes()[i].mmWidth))); - linesBox.setText(String - .valueOf(calculateLinesPerPage(sm - .getStandardSizes()[i].mmHeight))); - } - - if (pageTypes.getItem(pageTypes.getItemCount() - 1).equals( - lh.localValue("custom"))) - pageTypes.remove(pageTypes.getItemCount() - 1); - } - } - - if (!found) { - if (pageTypes.getItemCount() == sm.getStandardSizes().length) { - pageTypes.add(lh.localValue("custom")); - pageTypes.select(pageTypes.getItemCount() - 1); - } else - pageTypes.select(pageTypes.getItemCount() - 1); - - cellsBox.setText(String.valueOf(calculateCellsPerLine(Double - .valueOf(widthBox.getText())))); - linesBox.setText(String.valueOf(calculateLinesPerPage(Double - .valueOf(heightBox.getText())))); - } + /** + * Update UI field if needed + * + * @param box + * @param number + */ + private void setTextIfDifferent(Text box, double number) { + String given = box.getText(); + String expected = NUMBER_FORMATTER.format(number); + //Reset if number is different + if (!(!given.isEmpty() && Double.parseDouble(given) == number)) { + box.setText(expected); } } /** - * @return + * Recalculate page cells and page lines */ - public String validate() { - if (Integer.valueOf(cellsBox.getText()) < Integer.parseInt(settingsMap - .get("minCellsPerLine"))) - return "invalidSettingsCells"; - else if (Integer.valueOf(linesBox.getText()) < Integer - .parseInt(settingsMap.get("minLinesPerPage"))) - return "invalidSettingsLines";- else if (!cellsLinesButton.getSelection()&&(getDoubleValue(marginRightBox)+getDoubleValue
- (marginLeftBox)+(calcWidthFromCells(getDoubleValue(cellsBox))))>= - (Double.valueOf(settingsMap.get("paperWidth")))) - return "incorrectMarginWidth"; - else if (!cellsLinesButton.getSelection()&&(getDoubleValue(marginTopBox)+- getDoubleValue(marginBottomBox)+(sm.calcHeightFromLines(getDoubleValue(linesBox))))>=
- (Double.valueOf(settingsMap.get("paperHeight")))) - return "incorrectMarginHeight";- else if (!regionalButton.getSelection()&&((sm.calcHeightFromLines(getDoubleValue(linesBox)))+ - (sm.calcHeightFromLines(getDoubleValue(marginTopBox)))+(sm.calcHeightFromLines
- (getDoubleValue(marginBottomBox)))>=(Double.valueOf(settingsMap.get - ("paperHeight"))))) - return "incorrectMarginHeight";- else if (!regionalButton.getSelection()&&((calcWidthFromCells(getDoubleValue(cellsBox)))+ - (calcWidthFromCells(getDoubleValue(marginLeftBox)))+(calcWidthFromCells(getDoubleValue
- (marginRightBox))))>=(Double.valueOf(settingsMap.get("paperWidth")))) - return "incorrectMarginWidth";- else if (getDoubleValue(marginRightBox)<0|| getDoubleValue(marginLeftBox)<0||getDoubleValue(marginTopBox)<0|| getDoubleValue - (marginBottomBox)<0||getDoubleValue(linesBox)<=0|| getDoubleValue(cellsBox)<=0||getDoubleValue(widthBox)<=0||
- getDoubleValue(heightBox)<=0) - return "settingsBelowZero"; - else - return "SUCCESS"; + private void calculateCellsLinesAndUpdate() {+ pageCells = unitConverter.calculateCellsPerLine(pageWidth, marginLeft, marginRight); + pageLines = unitConverter.calculateLinesPerPage(pageHeight, marginTop, marginBottom);
+ updateFields(); } - private void setValue(Text text, String key) { - if (settingsMap.containsKey(key)) - text.setText(settingsMap.get(key)); - } + /**+ * When the user selects a standard page size, update width, height, cells, lines fields
+ */ + private void onStandardPageSelected() { + Page p = standardPages.get(pageTypes.getSelectionIndex()); + pageHeight = p.height; + pageWidth = p.width; + calculateCellsLinesAndUpdate(); - private void setValueForMargins(Text text, String key) { - if (regionalButton.getSelection()) { - if (settingsMap.containsKey(key)) - text.setText(settingsMap.get(key)); - } else { - if (key.equals("leftMargin") || key.equals("rightMargin")) { - if (settingsMap.containsKey(key)) - text.setText(String.valueOf(calculateCellsPerInch(Double - .valueOf(settingsMap.get(key))))); - } else { - if (settingsMap.containsKey(key)) - text.setText(String.valueOf(calculateLinesPerInch(Double - .valueOf(settingsMap.get(key))))); - } - }+ if (pageTypes.getItem(pageTypes.getItemCount() - 1).equals(lh.localValue("custom")))
+ pageTypes.remove(pageTypes.getItemCount() - 1); } - private void setDefault() { - if (settingsMap.containsKey("paperWidth") - && settingsMap.containsKey("paperHeight")) { - for (int i = 0; i < sm.getStandardSizes().length; i++) { - if (checkEqualWidth(sm.getStandardSizes()[i], - Double.valueOf(settingsMap.get("paperWidth"))) - && checkEqualHeight(sm.getStandardSizes()[i], - Double.valueOf(settingsMap.get("paperHeight")))) { - pageTypes.select(i); - break; - } - } - } + /**+ * When cells or lines change, adjust bottom and right margins to make room
+ */ + private void onCellLinesChange() {+ marginBottom = pageHeight - marginTop - unitConverter.calculateLinesHeight(pageLines); + marginRight = pageWidth - marginLeft - unitConverter.calculateCellsWidth(pageCells);
+ updateFields(); } - public TabItem getTab() { - return item; - } - - private double getDoubleValue(Text t) { - try { - if (t.getText().length() == 0) - return 0.0; - else - return Double.valueOf(t.getText()); - } - catch (NumberFormatException e) { - if (t.getText().contains("-")) - t.setText(t.getText().replaceAll("-", "")); - if (t.getText().length() == 0) - return 0.0; - else - return Double.valueOf(t.getText()); - } - } - - private String getStringValue(Text t) { - if (t.getText().length() == 0) - return "0"; - else - return t.getText(); - } - - public void modifyMargins() { - - if (!userModified) { - - if (regionalButton.getSelection()) { - - String leftMargin = settingsMap.get("leftMargin"); - marginLeftBox.setText(df.format(Double.valueOf(leftMargin))); - - String rightMargin = settingsMap.get("rightMargin"); - marginRightBox.setText(df.format(Double.valueOf(rightMargin))); - - String topMargin = settingsMap.get("topMargin"); - marginTopBox.setText(df.format(Double.valueOf(topMargin))); - - String bottomMargin = settingsMap.get("bottomMargin"); - marginBottomBox - .setText(df.format(Double.valueOf(bottomMargin))); - - } - - else { - - String leftMargin = settingsMap.get("leftMargin"); - String convertedLeftMargin = String - .valueOf(calculateCellsPerLine(Double - .valueOf(leftMargin))); - marginLeftBox.setText(convertedLeftMargin); - - String rightMargin = settingsMap.get("rightMargin"); - String convertedRightMargin = String - .valueOf(calculateCellsPerLine(Double - .valueOf(rightMargin))); - marginRightBox.setText(convertedRightMargin); - - String topMargin = settingsMap.get("topMargin"); - String convertedTopMargin = String - .valueOf(calculateLinesPerPage(Double - .valueOf(topMargin))); - marginTopBox.setText(convertedTopMargin); - - String bottomMargin = settingsMap.get("bottomMargin"); - String convertedBottomMargin = String - .valueOf(calculateLinesPerPage(Double - .valueOf(bottomMargin))); - marginBottomBox.setText(convertedBottomMargin); - - }// else cellsLines - }// if userModified false - }// modify margins - - public void saveSettings(String currentUnits) { - PropertyFileManager pfm = new PropertyFileManager(userSettings); - pfm.save("currentUnits", currentUnits); - } - - private int calculateCellsPerLine(double pWidth) { - - if (!listenerLocked) { - - double cellWidth; - if (!sm.isMetric()) - cellWidth = 0.246063; - else - cellWidth = 6.25; - - if (settingsMap.containsKey("leftMargin")) - pWidth -= Double.valueOf(settingsMap.get("leftMargin")); - - if (settingsMap.containsKey("rightMargin")) - pWidth -= Double.valueOf(settingsMap.get("rightMargin")); - - return (int) (pWidth / cellWidth); + /** + * When the user switches between displaying margins as inch/mm or cells, + * update label suffix and convert fields to new unit + */ + private void onMarginUnitSelected() {+ if (isAnyFieldEmpty() || marginLocalUnit == regionalButton.getSelection())
+ return; + if (regionalButton.getSelection()) { + marginLocalUnit = true; + marginTopLabel.setText(replaceOldUnitLabel(marginTopLabel, unitName));+ marginBottomLabel.setText(replaceOldUnitLabel(marginBottomLabel, unitName));
+ marginLeftLabel.setText(replaceOldUnitLabel(marginLeftLabel, unitName));+ marginRightLabel.setText(replaceOldUnitLabel(marginRightLabel, unitName));
+ regionalButton.setSelection(true); + cellsLinesButton.setSelection(false); } else { - double cellWidth; - if (!sm.isMetric()) - cellWidth = 0.246063; - else - cellWidth = 6.25; - - return (int) (pWidth / cellWidth); + marginLocalUnit = false; + marginTopLabel.setText(replaceOldUnitLabel(marginTopLabel, "lines"));+ marginBottomLabel.setText(replaceOldUnitLabel(marginBottomLabel, "lines"));
+ marginLeftLabel.setText(replaceOldUnitLabel(marginLeftLabel, "cells"));+ marginRightLabel.setText(replaceOldUnitLabel(marginRightLabel, "cells"));
+ regionalButton.setSelection(false); + cellsLinesButton.setSelection(true); } - + updateFields(); } - private int calculateLinesPerInch(double inches) { - double cellHeight; - if (!sm.isMetric()) - cellHeight = 0.393701; - else - cellHeight = 10; - return (int) (inches / cellHeight); + private String replaceOldUnitLabel(Label label, String newUnit) { + //Replace the last word with the new unit + String text = label.getText(); + text = text.substring(0, text.lastIndexOf(" ")); + return text + " (" + newUnit + ")"; } - private int calculateLinesPerPage(double pHeight) { - - if (!listenerLocked) { - - double cellHeight; - if (!sm.isMetric()) - cellHeight = 0.393701; - else - cellHeight = 10; - - if (settingsMap.containsKey("topMargin")) - pHeight -= Double.valueOf(settingsMap.get("topMargin")); - - if (settingsMap.containsKey("bottomMargin")) - pHeight -= Double.valueOf(settingsMap.get("bottomMargin")); - - return (int) (pHeight / cellHeight); - } else { - double cellHeight; - if (!sm.isMetric()) - cellHeight = 0.393701; - else - cellHeight = 10; - - return (int) (pHeight / cellHeight); - } + /** + * If this is false the user cleared out a field + * + * @return + */ + private boolean isAnyFieldEmpty() { + return widthBox.getText().isEmpty() + || heightBox.getText().isEmpty() + || linesBox.getText().isEmpty() + || cellsBox.getText().isEmpty() + || marginTopBox.getText().isEmpty() + || marginLeftBox.getText().isEmpty() + || marginRightBox.getText().isEmpty() + || marginBottomBox.getText().isEmpty(); } - public int calculateCellsPerInch(double inches) { - double cellWidth; - if (!sm.isMetric()) - cellWidth = 0.246063; - else - cellWidth = 6.25; - - return (int) (inches / cellWidth); + public String validate() { + //TODO: This is set in the advanced tab+// if (Integer.valueOf(cellsBox.getText()) < Integer.parseInt(settingsMap.get("minCellsPerLine")))
+// return "invalidSettingsCells";+// else if (Integer.valueOf(linesBox.getText()) < Integer.parseInt(settingsMap.get("minLinesPerPage")))
+// return "invalidSettingsLines";+ if (marginRight + marginLeft + unitConverter.calculateCellsWidth(pageCells) >= pageWidth)
+ return "incorrectMarginWidth";+ if (marginTop + marginBottom + unitConverter.calculateLinesHeight(pageLines) >= pageHeight)
+ return "incorrectMarginHeight"; + if (pageHeight < 0 || pageWidth < 0 || pageLines < 0 || pageCells < 0+ || marginTop < 0 || marginBottom < 0 || marginLeft < 0 || marginRight < 0)
+ return "settingsBelowZero"; + return "SUCCESS"; } - private double calcWidthFromCells(int numberOfCells) { - double cellWidth; - if (!sm.isMetric()) - cellWidth = 0.246063; - else - cellWidth = 6.25; + /** + * When all data is validated, this is called to change the actual values ***The diff for this file has been truncated for email.*** ============================================================================== Revision: 6ed629be29a3 Branch: rt2165-styleDefsTab Author: Leon Blakey <lblakey@xxxxxxx> Date: Thu Mar 12 16:28:36 2015 UTCLog: Auto size Braille Settings dialog based on widget requirements instead of hardcoded guessing
https://code.google.com/p/brailleblaster/source/detail?r=6ed629be29a3 Modified: /src/main/org/brailleblaster/settings/ui/ConfigPanel.java =======================================--- /src/main/org/brailleblaster/settings/ui/ConfigPanel.java Thu Mar 12 14:41:42 2015 UTC +++ /src/main/org/brailleblaster/settings/ui/ConfigPanel.java Thu Mar 12 16:28:36 2015 UTC
@@ -11,7 +11,7 @@ import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.TraverseEvent; import org.eclipse.swt.events.TraverseListener; -import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.graphics.Point; import org.eclipse.swt.layout.FormAttachment; import org.eclipse.swt.layout.FormData; import org.eclipse.swt.layout.FormLayout; @@ -20,7 +20,6 @@ import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Listener; -import org.eclipse.swt.widgets.Monitor; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.TabFolder; @@ -39,7 +38,6 @@shell = new Shell(Display.getDefault(), SWT.APPLICATION_MODAL | SWT.RESIZE | SWT.CLOSE | SWT.TITLE | SWT.MIN);
shell.setText( lh.localValue("settings") ); shell.setLayout(new FormLayout()); - setPanelSize(); folder = new TabFolder(shell, SWT.NONE); setFormLayout(folder, 0, 100, 0, 94); @@ -96,17 +94,13 @@ } }); + //Autosize shell based on what the internal elements require + Point size = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT); + shell.setSize(size); + + //Show the window shell.open(); } - - private void setPanelSize(){ - Monitor primary = shell.getDisplay().getPrimaryMonitor(); - Rectangle bounds = primary.getBounds(); - int x = (bounds.width / 2) - ((bounds.width / 6) / 2); - int y = (bounds.height / 2) - ((bounds.height / 2) / 2); - shell.setSize(bounds.width / 3, (int) (bounds.height/1.5) ); - shell.setLocation(x, y); - }private void setFormLayout(Control c, int left, int right, int top, int bottom){
FormData location = new FormData(); ============================================================================== Revision: 4a2a39a8f55d Branch: rt2165-styleDefsTab Author: Leon Blakey <lblakey@xxxxxxx> Date: Thu Mar 12 16:39:08 2015 UTC Log: Removed ugly border around several setting tab's content https://code.google.com/p/brailleblaster/source/detail?r=4a2a39a8f55d Modified: /src/main/org/brailleblaster/settings/ui/PageNumbersTab.java /src/main/org/brailleblaster/settings/ui/StyleDefinitionsTab.java /src/main/org/brailleblaster/settings/ui/TranslationSettingsTab.java =======================================--- /src/main/org/brailleblaster/settings/ui/PageNumbersTab.java Fri Mar 6 21:31:05 2015 UTC +++ /src/main/org/brailleblaster/settings/ui/PageNumbersTab.java Thu Mar 12 16:39:08 2015 UTC
@@ -44,7 +44,7 @@ // item.setControl(group); // setFormLayout(group, 0, 100, 0, 60); - group = new Composite(folder, SWT.BORDER); + group = new Composite(folder, 0); group.setLayout(new FillLayout(SWT.VERTICAL)); item.setControl(group); =======================================--- /src/main/org/brailleblaster/settings/ui/StyleDefinitionsTab.java Mon Mar 9 13:32:16 2015 UTC +++ /src/main/org/brailleblaster/settings/ui/StyleDefinitionsTab.java Thu Mar 12 16:39:08 2015 UTC
@@ -25,7 +25,6 @@ import org.eclipse.swt.events.DisposeListener; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; @@ -73,10 +72,9 @@ TabItem item = new TabItem(folder, 0); item.setText(lh.localValue("styleDefsTab")); - parent = new Composite(folder, SWT.BORDER); + parent = new Composite(folder, 0); parent.setLayout(new GridLayout(1, true)); item.setControl(parent); - setGridData(parent); //Top part where user selects which style and/or style stack groupSelect = new Group(parent, 0); @@ -124,14 +122,6 @@ styleFieldToControlMap.put(curField, fieldControl); } setStyleFieldsEnabled(false); - - parent.addDisposeListener(new DisposeListener() { - @Override - public void widgetDisposed(DisposeEvent de) { - //TODO: Save StyleDefinitions to disk here - log.warn("Disposed!"); - } - }); } private void setStyleFieldsEnabled(boolean enabled) { =======================================--- /src/main/org/brailleblaster/settings/ui/TranslationSettingsTab.java Wed May 21 15:59:22 2014 UTC +++ /src/main/org/brailleblaster/settings/ui/TranslationSettingsTab.java Thu Mar 12 16:39:08 2015 UTC
@@ -50,7 +50,7 @@ item = new TabItem(folder, 0); item.setText(lh.localValue("translationSettings")); - composite = new Composite(folder, SWT.BORDER); + composite = new Composite(folder, 0); composite.setLayout(new FillLayout(SWT.VERTICAL)); item.setControl(composite); ============================================================================== Revision: 91ec9f23efb2 Branch: rt2165-styleDefsTab Author: Leon Blakey <lblakey@xxxxxxx> Date: Thu Mar 12 18:17:22 2015 UTC Log: Ported PageNumberTab in Settings dialog to UTD https://code.google.com/p/brailleblaster/source/detail?r=91ec9f23efb2 Modified: /src/main/org/brailleblaster/settings/ui/ConfigPanel.java /src/main/org/brailleblaster/settings/ui/PageNumbersTab.java =======================================--- /src/main/org/brailleblaster/settings/ui/ConfigPanel.java Thu Mar 12 16:28:36 2015 UTC +++ /src/main/org/brailleblaster/settings/ui/ConfigPanel.java Thu Mar 12 18:17:22 2015 UTC
@@ -5,6 +5,7 @@ import org.brailleblaster.localization.LocaleHandler; import org.brailleblaster.perspectives.braille.Manager; import org.brailleblaster.settings.SettingsManager; +import org.brailleblaster.utd.PageSettings; import org.brailleblaster.util.Notify; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; @@ -43,9 +44,10 @@ setFormLayout(folder, 0, 100, 0, 94); final HashMap<String, String> settingsCopy = sm.getMapClone();- pageProperties = new PagePropertiesTab(folder, m.getDocument().getEngine().getPageSettings()); + PageSettings currentPageSettings = m.getDocument().getEngine().getPageSettings();
+ pageProperties = new PagePropertiesTab(folder, currentPageSettings);translationSettings = new TranslationSettingsTab(folder, sm, settingsCopy);
- pageNumTab = new PageNumbersTab(folder, sm, settingsCopy); + pageNumTab = new PageNumbersTab(folder, currentPageSettings); styleDefsTab = new StyleDefinitionsTab(folder, m); advTab = new AdvancedTab(folder, sm, settingsCopy); =======================================--- /src/main/org/brailleblaster/settings/ui/PageNumbersTab.java Thu Mar 12 16:39:08 2015 UTC +++ /src/main/org/brailleblaster/settings/ui/PageNumbersTab.java Thu Mar 12 18:17:22 2015 UTC
@@ -1,12 +1,9 @@ package org.brailleblaster.settings.ui; -import java.util.HashMap; - import org.brailleblaster.localization.LocaleHandler; -import org.brailleblaster.settings.SettingsManager; +import org.brailleblaster.utd.PageSettings; +import org.brailleblaster.utd.PageSettings.NumberLocation; import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; @@ -19,205 +16,87 @@ import org.eclipse.swt.widgets.TabItem; public class PageNumbersTab { - - HashMap<String, String> settingsMap; - SettingsManager sm; - TabItem item; - LocaleHandler lh; - Group ppnGroup, bpnGroup, cpGroup; - Composite group; - Label cpLabel, intpLabel, ppnRngLabel, bpnLocLabel, ppnLocLabel; - //Label ppnLabel, bpnLabel, ppnlocLabel, bpnlocLabel; - Combo cpCombo, intpCombo, ppnRngCombo, bpnLocCombo, ppnLocCombo; - //Combo ppnCombo, bpnCombo, ppnlocCombo, bpnlocCombo; -- public PageNumbersTab(TabFolder folder, final SettingsManager sm, HashMap<String, String> settingsMap) {
+ private final LocaleHandler lh = new LocaleHandler(); + private final Combo continueCombo, interpointCombo, printCombo; ++ public PageNumbersTab(TabFolder folder, PageSettings pageSettingsDefault) {
super(); - lh = new LocaleHandler(); - this.sm = sm; - this.settingsMap = settingsMap; - item = new TabItem(folder, 0); + TabItem item = new TabItem(folder, 0); item.setText(lh.localValue("pageNumbers")); - -// group = new Composite(folder, 0); -// group.setLayout(new FormLayout()); -// item.setControl(group); -// setFormLayout(group, 0, 100, 0, 60); - - group = new Composite(folder, 0); - group.setLayout(new FillLayout(SWT.VERTICAL)); - item.setControl(group); - - bpnGroup = new Group(group, 0); - bpnGroup.setLayout(new GridLayout(2, true)); - bpnGroup.setText(lh.localValue("braille")); - - //////////// - - intpLabel = new Label(bpnGroup, 0); - intpLabel.setText("Interpoint"); - setGridData(intpLabel); - intpCombo = new Combo(bpnGroup, SWT.READ_ONLY); - intpCombo.add("No"); - intpCombo.add("Yes"); - if( settingsMap.get("interpoint").equals("yes") ) - intpCombo.setText("Yes"); - else - intpCombo.setText("No"); - setGridData(intpCombo); - - /////////// - - /** - * Currently the settings have one drop down menu to select "Yes" or "No" - * and a separate settings box to select the location.- * Rather than the user having to enter two settings, this could be consolidated into
- * one drop down menu for Braille Page Numbers: Top, Bottom, None. - */ - - bpnLocLabel = new Label (bpnGroup, 0); - bpnLocLabel.setText("Braille Page Number Location"); - setGridData(bpnLocLabel); - bpnLocCombo = new Combo(bpnGroup, SWT.READ_ONLY); - bpnLocCombo.add("Top Left"); - bpnLocCombo.add("Bottom Left"); - bpnLocCombo.add("Top Right"); - bpnLocCombo.add("Bottom Right"); - bpnLocCombo.add("None"); - //TODO: This defeats the purpose of i18n - if (settingsMap.get("braillePageNumberAt").equals("Top Left")) { - bpnLocCombo.setText("Top Left"); - } - else if (settingsMap.get("braillePageNumberAt").equals("Bottom Left")) { - bpnLocCombo.setText("Bottom Left"); - } - else if (settingsMap.get("braillePageNumberAt").equals("Top Right")) { - bpnLocCombo.setText("Top Right"); - } - else { - bpnLocCombo.setText("Bottom Right"); - } - - if (settingsMap.get("numberBraillePages").equals("no")) { - bpnLocCombo.setText("None"); - } - - setGridData(bpnLocCombo); - - ///////////////////////////////////////////////////////////// - - ppnGroup = new Group(group, 0); - ppnGroup.setLayout(new GridLayout(2, true)); - ppnGroup.setText(lh.localValue("print")); - - ppnLocLabel = new Label(ppnGroup, 0); - ppnLocLabel.setText("Print Page Number Location"); - setGridData(ppnLocLabel); - ppnLocCombo = new Combo(ppnGroup, SWT.READ_ONLY); - ppnLocCombo.add("Top Left"); - ppnLocCombo.add("Bottom Left"); - ppnLocCombo.add("Top Right"); - ppnLocCombo.add("Bottom Right"); - ppnLocCombo.add("None"); - - if (settingsMap.get("printPageNumberAt").equals("Top Left") ) { - ppnLocCombo.setText("Top Left"); - } - else if (settingsMap.get("printPageNumberAt").equals("Bottom Left")) { - ppnLocCombo.setText("Bottom Left"); - } - else if (settingsMap.get("printPageNumberAt").equals("Top Right")) { - ppnLocCombo.setText("Top Right"); - } - else { - ppnLocCombo.setText("Bottom Right"); - } - - if (settingsMap.get("printPages").equals("no")) { - ppnLocCombo.setText("None"); - } - - setGridData(ppnLocCombo); - - ///////////// - - ppnRngLabel = new Label(ppnGroup, 0); - ppnRngLabel.setText("Continuation Symbols For Print Pages"); - setGridData(ppnRngLabel); - ppnRngCombo = new Combo(ppnGroup, SWT.READ_ONLY); - ppnRngCombo.add("No"); - ppnRngCombo.add("Yes"); - if( settingsMap.get("printPageNumberRange").equals("yes") ) - ppnRngCombo.setText("Yes"); - else - ppnRngCombo.setText("No"); - setGridData(ppnRngCombo); - - ////////////////////////////////////////////////////////// - - cpGroup = new Group(group, 0); + + //----Setup UI---- + Composite parent = new Composite(folder, 0); + parent.setLayout(new GridLayout(1, true)); + item.setControl(parent); + + //Braille interpoint and continuation symbols + Group pageNumGroup = new Group(parent, 0); + pageNumGroup.setLayout(new GridLayout(2, true)); + pageNumGroup.setText("Page Numbers"); + setGridDataGroup(pageNumGroup); + + addLabel(pageNumGroup, "Braille Interpoint Page Number Location");+ interpointCombo = makeNumberPositionCombo(pageNumGroup, pageSettingsDefault.getInterpoint());
++ addLabel(pageNumGroup, "Continuation Symbols Print Page Number Location"); + printCombo = makeNumberPositionCombo(pageNumGroup, pageSettingsDefault.getPrintPages());
+ + //Continue pages + Group cpGroup = new Group(parent, 0); cpGroup.setLayout(new GridLayout(2, true)); cpGroup.setText(lh.localValue("continue")); - cpLabel = new Label(cpGroup, 0); - cpLabel.setText("Continue Pages"); - setGridData(ppnLocLabel); - cpCombo = new Combo(cpGroup, SWT.READ_ONLY); - cpCombo.add("No"); - cpCombo.add("Yes"); - if( settingsMap.get("continuePages").equals("yes") ) - cpCombo.setText("Yes"); - else - cpCombo.setText("No"); - setGridData(cpCombo); + setGridDataGroup(cpGroup); - - addListeners(); + addLabel(cpGroup, "Continue Pages"); + continueCombo = new Combo(cpGroup, SWT.READ_ONLY); + continueCombo.add("No"); + continueCombo.add("Yes"); + if (pageSettingsDefault.isContinuePages()) + continueCombo.setText("Yes"); + else + continueCombo.setText("No"); + setGridData(continueCombo); } - private void addListeners(){ + public void updateEngine(PageSettings pageSettingsNew) {+ NumberLocation interpoint = NumberLocation.valueOf(interpointCombo.getText());
+ pageSettingsNew.setInterpoint(interpoint); + NumberLocation print = NumberLocation.valueOf(printCombo.getText()); + pageSettingsNew.setPrintPages(print); + + boolean continueVal = continueCombo.getText().equals("Yes"); + pageSettingsNew.setContinuePages(continueVal); + } - ppnLocCombo.addSelectionListener(new SelectionAdapter(){ - @Override - public void widgetSelected(SelectionEvent e) {+ private static Combo makeNumberPositionCombo(Composite parent, NumberLocation defaultValue) {
+ Combo combo = new Combo(parent, SWT.READ_ONLY); - if (ppnLocCombo.getText().equals("None")) { - settingsMap.put("printPages", "no"); - } - else { - settingsMap.put("printPageNumberAt", ppnLocCombo.getText()); - settingsMap.put("printPages", "yes"); - } - } - }); - - bpnLocCombo.addSelectionListener(new SelectionAdapter(){ - @Override - public void widgetSelected(SelectionEvent e) { - int index = bpnLocCombo.getSelectionIndex(); - if (bpnLocCombo.getText().equals("None")) { - settingsMap.put("numberBraillePages", "no"); - } - else { - settingsMap.put("braillePageNumberAt", bpnLocCombo.getText()); - settingsMap.put("numberBraillePages", "yes"); - } - } - }); - - ppnRngCombo.addSelectionListener(new SelectionAdapter(){ - @Override - public void widgetSelected(SelectionEvent e) {- settingsMap.put("printPageNumberRange", ppnRngCombo.getText().toLowerCase());
- } - }); + for (NumberLocation curLoc : NumberLocation.values()) + combo.add(curLoc.name()); + combo.setText(defaultValue.name()); + + setGridData(combo); + return combo; } - - private void setGridData(Control c){ + + private static Label addLabel(Composite parent, String text) { + Label label = new Label(parent, 0); + label.setText(text); + setGridData(label); + return label; + } + + private static void setGridData(Control c) { GridData gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.verticalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - c.setLayoutData(gridData); + gridData.horizontalAlignment = GridData.FILL; + gridData.verticalAlignment = GridData.FILL; + gridData.grabExcessHorizontalSpace = true; + c.setLayoutData(gridData); + } + + private static void setGridDataGroup(Group group) { + setGridData(group); + ((GridData)group.getLayoutData()).grabExcessVerticalSpace = true; } }