// Implement abstract methods from our super protected void setControls(DialogAccess dlg) { // Load attribute maps from config attributeMap.clear(); attributeMap.copyAll(config.getComplexOption("text-attribute-map")); // Update the dialog nCurrentAttribute = -1; dlg.setListBoxSelectedItem("FormattingAttribute", (short) 0); formattingAttributeChange(dlg); }
private void copyStyles( ComplexOption source, ComplexOption target, Map<String, String> nameTranslation) { for (String sName : source.keySet()) { String sNewName = sName; if (nameTranslation != null && nameTranslation.containsKey(sName)) { sNewName = nameTranslation.get(sName); } target.copy(sNewName, source.get(sName)); } }
private void loadDefaultsClick(DialogAccess dlg) { updateStyleMaps(dlg); // Count styles that we will overwrite Config clean = ConverterFactory.createConverter(getMIMEType()).getConfig(); clean.readDefaultConfig(getDefaultConfigName()); int nCount = 0; int nFamilyCount = sFamilyNames.length; for (int i = 0; i < nFamilyCount; i++) { ComplexOption cleanMap = clean.getComplexOption(sFamilyNames[i] + "-map"); Map<String, String> displayNames = styleNameProvider.getDisplayNames(sOOoFamilyNames[i]); for (String sName : cleanMap.keySet()) { String sDisplayName = (displayNames != null && displayNames.containsKey(sName)) ? displayNames.get(sName) : ""; if (styleMap[i].containsKey(sDisplayName)) { nCount++; } } } // Display confirmation dialog boolean bConfirm = false; XDialog xDialog = getDialog(getDialogLibraryName() + ".LoadDefaults"); if (xDialog != null) { DialogAccess ldlg = new DialogAccess(xDialog); if (nCount > 0) { String sLabel = ldlg.getLabelText("OverwriteLabel"); sLabel = sLabel.replaceAll("%s", Integer.toString(nCount)); ldlg.setLabelText("OverwriteLabel", sLabel); } else { ldlg.setLabelText("OverwriteLabel", ""); } bConfirm = xDialog.execute() == ExecutableDialogResults.OK; xDialog.endExecute(); } // Do the replacement if (bConfirm) { for (int i = 0; i < nFamilyCount; i++) { ComplexOption cleanMap = clean.getComplexOption(sFamilyNames[i] + "-map"); Map<String, String> displayNames = styleNameProvider.getDisplayNames(sOOoFamilyNames[i]); copyStyles(cleanMap, styleMap[i], displayNames); } } // Force update of the user interface nCurrentFamily = -1; sCurrentStyleName = null; styleFamilyChange(dlg); }
protected void getControls(DialogAccess dlg) { updateStyleMaps(dlg); // Save style maps to config (translating keys back to internal names) int nCount = sFamilyNames.length; for (int i = 0; i < nCount; i++) { ComplexOption configMap = config.getComplexOption(sFamilyNames[i] + "-map"); configMap.clear(); Map<String, String> internalNames = styleNameProvider.getInternalNames(sOOoFamilyNames[i]); copyStyles(styleMap[i], configMap, internalNames); } }
// Internal methods private void updateAttributeMaps(DialogAccess dlg) { // Save the current attribute map, if any if (nCurrentAttribute > -1) { String sName = sAttributeNames[nCurrentAttribute]; if (!attributeMap.containsKey(sName)) { attributeMap.put(sName, new HashMap<String, String>()); } Map<String, String> attr = attributeMap.get(sName); attr.put("deleted", Boolean.toString(!dlg.getCheckBoxStateAsBoolean("CustomAttribute"))); getControls(dlg, attr); attributeMap.put(sName, attr); } }
protected void getControls(DialogAccess dlg) { updateAttributeMaps(dlg); // Save attribute maps to config ComplexOption configMap = config.getComplexOption("text-attribute-map"); configMap.clear(); for (String s : attributeMap.keySet()) { Map<String, String> attr = attributeMap.get(s); if (!attr.containsKey("deleted") || attr.get("deleted").equals("false")) { configMap.copy(s, attr); } } }
private void formattingAttributeChange(DialogAccess dlg) { updateAttributeMaps(dlg); short nNewAttribute = dlg.getListBoxSelectedItem("FormattingAttribute"); if (nNewAttribute > -1 && nNewAttribute != nCurrentAttribute) { nCurrentAttribute = nNewAttribute; String sName = sAttributeNames[nCurrentAttribute]; if (!attributeMap.containsKey(sName)) { attributeMap.put(sName, new HashMap<String, String>()); attributeMap.get(sName).put("deleted", "true"); } Map<String, String> attr = attributeMap.get(sName); dlg.setCheckBoxStateAsBoolean( "CustomAttribute", !attr.containsKey("deleted") || attr.get("deleted").equals("false")); customAttributeChange(dlg); setControls(dlg, attr); } }