/************************************************************************ * * ConfigurationDialog.java * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software Foundation. * * This library 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 GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA * * Copyright: 2002-2009 by Henrik Just * * All Rights Reserved. * * Version 1.2 (2009-11-02) * */ package org.openoffice.da.comp.writer2latex; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.text.Collator; import java.util.Arrays; import java.util.HashMap; import java.util.Map; import java.util.Set; import com.sun.star.awt.XContainerWindowEventHandler; import com.sun.star.awt.XDialog; import com.sun.star.awt.XDialogProvider2; import com.sun.star.awt.XWindow; import com.sun.star.io.NotConnectedException; import com.sun.star.io.XInputStream; import com.sun.star.io.XOutputStream; import com.sun.star.lang.XMultiComponentFactory; import com.sun.star.lang.XServiceInfo; import com.sun.star.ucb.CommandAbortedException; import com.sun.star.ucb.XSimpleFileAccess2; import com.sun.star.ui.dialogs.ExecutableDialogResults; import com.sun.star.uno.AnyConverter; import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.XComponentContext; import com.sun.star.util.XStringSubstitution; import com.sun.star.lib.uno.helper.WeakBase; import com.sun.star.lib.uno.adapter.XInputStreamToInputStreamAdapter; import com.sun.star.lib.uno.adapter.XOutputStreamToOutputStreamAdapter; import writer2latex.api.ComplexOption; import writer2latex.api.Config; import writer2latex.api.ConverterFactory; import org.openoffice.da.comp.w2lcommon.helper.DialogAccess; /** This class provides a uno component which implements the configuration * of Writer2LaTeX. The same component is used for all pages - using the * dialog title to distinguish between tha pages. */ public final class ConfigurationDialog extends WeakBase implements XServiceInfo, XContainerWindowEventHandler { private String[] sFamilyNames = { "text", "paragraph", "paragraph-block", "list", "listitem" }; private String[] sAttributeNames = { "bold", "italics", "small-caps", "superscript", "subscipt" }; private XComponentContext xContext; private XSimpleFileAccess2 sfa2; private String sConfigFileName = null; Config config; // Local cache of complex options ComplexOption[] styleMap; ComplexOption attributeMap; ComplexOption headingMap; ComplexOption mathSymbols; ComplexOption stringReplace; short nCurrentFamily = -1; String sCurrentStyleName = null; short nCurrentAttribute = -1; short nCurrentMaxLevel = -1; short nCurrentWriterLevel = 0; String sCurrentMathSymbol = null; String sCurrentText = null; private String sTitle = null; private DialogAccess dlg = null; /** The component will be registered under this name. */ public static String __serviceName = "org.openoffice.da.writer2latex.ConfigurationDialog"; /** The component should also have an implementation name. */ public static String __implementationName = "org.openoffice.da.comp.writer2latex.ConfigurationDialog"; /** Create a new ConfigurationDialog */ public ConfigurationDialog(XComponentContext xContext) { this.xContext = xContext; // Get the SimpleFileAccess service sfa2 = null; try { Object sfaObject = xContext.getServiceManager().createInstanceWithContext( "com.sun.star.ucb.SimpleFileAccess", xContext); sfa2 = (XSimpleFileAccess2) UnoRuntime.queryInterface(XSimpleFileAccess2.class, sfaObject); } catch (com.sun.star.uno.Exception e) { // failed to get SimpleFileAccess service (should not happen) } // Create the config file name XStringSubstitution xPathSub = null; try { Object psObject = xContext.getServiceManager().createInstanceWithContext( "com.sun.star.util.PathSubstitution", xContext); xPathSub = (XStringSubstitution) UnoRuntime.queryInterface(XStringSubstitution.class, psObject); sConfigFileName = xPathSub.substituteVariables("$(user)/writer2latex.xml", false); } catch (com.sun.star.uno.Exception e) { // failed to get PathSubstitution service (should not happen) } // Create the configuration config = ConverterFactory.createConverter("application/x-latex").getConfig(); // Initialize the local cache of complex options styleMap = new ComplexOption[5]; for (int i=0; i<5; i++) { styleMap[i]=new ComplexOption(); } attributeMap = new ComplexOption(); headingMap = new ComplexOption(); mathSymbols = new ComplexOption(); stringReplace = new ComplexOption(); } // Implement XContainerWindowEventHandler public boolean callHandlerMethod(XWindow xWindow, Object event, String sMethod) throws com.sun.star.lang.WrappedTargetException { XDialog xDialog = (XDialog)UnoRuntime.queryInterface(XDialog.class, xWindow); sTitle = xDialog.getTitle(); dlg = new DialogAccess(xDialog); try { if (sMethod.equals("external_event") ){ return handleExternalEvent(event); } // Documentclass page else if (sMethod.equals("NoPreambleChange")) { updateDocumentclassControls(); return true; } // Headings page else if (sMethod.equals("MaxLevelChange")) { saveHeadings(); updateHeadingsControls(); return true; } else if (sMethod.equals("WriterLevelChange")) { saveHeadings(); updateHeadingsControls(); return true; } else if (sMethod.equals("NoIndexChange")) { updateHeadingsControls(); return true; } // Styles page else if (sMethod.equals("StyleFamilyChange")) { saveStyles(); updateStylesControls(); return true; } else if (sMethod.equals("StyleNameChange")) { saveStyles(); updateStylesControls(); return true; } else if (sMethod.equals("NewStyleClick")) { if (nCurrentFamily>-1) { String sNewName = appendItem("StyleName"); if (sNewName!=null) { Map attr = new HashMap(); attr.put("before", ""); attr.put("after", ""); attr.put("after", ""); attr.put("verbatim", ""); attr.put("line-break",""); styleMap[nCurrentFamily].put(sNewName, attr); } saveStyles(); updateStylesControls(); } return true; } else if (sMethod.equals("DeleteStyleClick")) { if (nCurrentFamily>-1 && sCurrentStyleName!=null) { if (deleteCurrentItem("StyleName")) { styleMap[nCurrentFamily].remove(sCurrentStyleName); updateStylesControls(); } } return true; } // Characters page else if (sMethod.equals("UseSoulChange")) { updateCharactersControls(); return true; } else if (sMethod.equals("FormattingAttributeChange")) { saveCharacters(); updateCharactersControls(); return true; } else if (sMethod.equals("CustomAttributeChange")) { updateCharactersControls(); return true; } // Fonts page // Pages page else if (sMethod.equals("ExportGeometryChange")) { updatePagesControls(); return true; } else if (sMethod.equals("ExportHeaderAndFooterChange")) { updatePagesControls(); return true; } // Tables page else if (sMethod.equals("NoTablesChange")) { updateTablesControls(); return true; } else if (sMethod.equals("UseSupertabularChange")) { updateTablesControls(); return true; } else if (sMethod.equals("UseLongtableChange")) { updateTablesControls(); return true; } // Figures page else if (sMethod.equals("NoImagesChange")) { updateFiguresControls(); return true; } // Text and math page else if (sMethod.equals("MathSymbolNameChange")) { saveTextAndMath(); updateTextAndMathControls(); return true; } else if (sMethod.equals("NewSymbolClick")) { String sNewName = appendItem("MathSymbolName"); if (sNewName!=null) { Map attr = new HashMap(); attr.put("latex", ""); mathSymbols.put(sNewName, attr); } saveTextAndMath(); updateTextAndMathControls(); return true; } else if (sMethod.equals("DeleteSymbolClick")) { if (deleteCurrentItem("MathSymbolName")) { mathSymbols.remove(sCurrentMathSymbol); updateTextAndMathControls(); } return true; } else if (sMethod.equals("TextInputChange")) { saveTextAndMath(); updateTextAndMathControls(); return true; } else if (sMethod.equals("NewTextClick")) { String sNewName = appendItem("TextInput"); if (sNewName!=null) { Map attr = new HashMap(); attr.put("latex-code", ""); attr.put("fontenc", "any"); stringReplace.put(sNewName, attr); } saveTextAndMath(); updateTextAndMathControls(); return true; } else if (sMethod.equals("DeleteTextClick")) { if (deleteCurrentItem("TextInput")) { stringReplace.remove(sCurrentText); updateTextAndMathControls(); } return true; } } catch (com.sun.star.uno.RuntimeException e) { throw e; } catch (com.sun.star.uno.Exception e) { throw new com.sun.star.lang.WrappedTargetException(sMethod, this, e); } return false; } public String[] getSupportedMethodNames() { String[] sNames = { "external_event", "NoPreambleChange", // Documentclass "MaxLevelChange", "WriterLevelChange", "NoIndexChange", // Headings "StyleFamilyChange", "StyleNameChange", "NewStyleClick", "DeleteStyleClick", // Styles "UseSoulChange", "FormattingAttributeChange", "CustomAttributeChange", // Characters "ExportGeometryChange", "ExportHeaderAndFooterChange", // Pages "NoTablesChange", "UseSupertabularChange", "UseLongtableChange", // Tables "NoImagesChange", // Images "MathSymbolNameChange", "NewSymbolClick", "DeleteSymbolClick", "TextInputChange", "NewTextClick", "DeleteTextClick" // Text and Math }; return sNames; } // Implement the interface XServiceInfo public boolean supportsService(String sServiceName) { return sServiceName.equals(__serviceName); } public String getImplementationName() { return __implementationName; } public String[] getSupportedServiceNames() { String[] sSupportedServiceNames = { __serviceName }; return sSupportedServiceNames; } // Private stuff private boolean handleExternalEvent(Object aEventObject) throws com.sun.star.uno.Exception { try { String sMethod = AnyConverter.toString(aEventObject); if (sMethod.equals("ok")) { loadConfig(); getControls(); for (int i=0; i<5; i++) { config.getComplexOption(sFamilyNames[i]+"-map").clear(); config.getComplexOption(sFamilyNames[i]+"-map").copyAll(styleMap[i]); } config.getComplexOption("text-attribute-map").clear(); config.getComplexOption("text-attribute-map").copyAll(attributeMap); if (nCurrentMaxLevel>-1) { for (int i=nCurrentMaxLevel+1; i<11; i++) { headingMap.remove(Integer.toString(i)); } } config.getComplexOption("heading-map").clear(); config.getComplexOption("heading-map").copyAll(headingMap); config.getComplexOption("math-symbol-map").clear(); config.getComplexOption("math-symbol-map").copyAll(mathSymbols); config.getComplexOption("string-replace").clear(); config.getComplexOption("string-replace").copyAll(stringReplace); saveConfig(); return true; } else if (sMethod.equals("back") || sMethod.equals("initialize")) { loadConfig(); for (int i=0; i<5; i++) { styleMap[i].clear(); styleMap[i].copyAll(config.getComplexOption(sFamilyNames[i]+"-map")); } attributeMap.clear(); attributeMap.copyAll(config.getComplexOption("text-attribute-map")); headingMap.clear(); headingMap.copyAll(config.getComplexOption("heading-map")); mathSymbols.clear(); mathSymbols.copyAll(config.getComplexOption("math-symbol-map")); stringReplace.clear(); stringReplace.copyAll(config.getComplexOption("string-replace")); setControls(); return true; } } catch (com.sun.star.lang.IllegalArgumentException e) { throw new com.sun.star.lang.IllegalArgumentException( "Method external_event requires a string in the event object argument.", this,(short) -1); } return false; } // Display a dialog private XDialog getDialog(String sDialogName) { XMultiComponentFactory xMCF = xContext.getServiceManager(); try { Object provider = xMCF.createInstanceWithContext( "com.sun.star.awt.DialogProvider2", xContext); XDialogProvider2 xDialogProvider = (XDialogProvider2) UnoRuntime.queryInterface(XDialogProvider2.class, provider); String sDialogUrl = "vnd.sun.star.script:"+sDialogName+"?location=application"; return xDialogProvider.createDialogWithHandler(sDialogUrl, this); } catch (Exception e) { return null; } } private boolean deleteItem() { XDialog xDialog=getDialog("W2LDialogs2.DeleteDialog"); if (xDialog!=null) { boolean bDelete = xDialog.execute()==ExecutableDialogResults.OK; xDialog.endExecute(); return bDelete; } return false; } private boolean deleteCurrentItem(String sListName) { String[] sItems = dlg.getListBoxStringItemList(sListName); short nSelected = dlg.getListBoxSelectedItem(sListName); if (nSelected>=0 && deleteItem()) { int nOldLen = sItems.length; String[] sNewItems = new String[nOldLen-1]; if (nSelected>0) { System.arraycopy(sItems, 0, sNewItems, 0, nSelected); } if (nSelected writerLevels = headingMap.keySet(); nCurrentMaxLevel = 0; while(nCurrentMaxLevel<10 && writerLevels.contains(Integer.toString(nCurrentMaxLevel+1))) { nCurrentMaxLevel++; } dlg.setListBoxSelectedItem("MaxLevel", nCurrentMaxLevel); dlg.setCheckBoxStateAsBoolean("UseTitlesec","true".equals(config.getOption("use_titlesec"))); dlg.setCheckBoxStateAsBoolean("NoIndex","true".equals(config.getOption("no_index"))); dlg.setCheckBoxStateAsBoolean("UseTitletoc","true".equals(config.getOption("use_titletoc"))); updateHeadingsControls(); } private void saveHeadings() { // Save the current writer level in our cache if (nCurrentWriterLevel>-1) { Map attr = new HashMap(); attr.put("name", dlg.getComboBoxText("LaTeXName")); attr.put("level", dlg.getComboBoxText("LaTeXLevel")); headingMap.put(Integer.toString(nCurrentWriterLevel+1), attr); } config.setOption("use_titlesec", Boolean.toString(dlg.getCheckBoxStateAsBoolean("UseTitlesec"))); config.setOption("no_index", Boolean.toString(dlg.getCheckBoxStateAsBoolean("NoIndex"))); config.setOption("use_titletoc", Boolean.toString(dlg.getCheckBoxStateAsBoolean("UseTitletoc"))); } private void updateHeadingsControls() { // Adjust the presented writer levels to the max level nCurrentMaxLevel = dlg.getListBoxSelectedItem("MaxLevel"); nCurrentWriterLevel = dlg.getListBoxSelectedItem("WriterLevel"); String[] sWriterLevels = new String[nCurrentMaxLevel]; for (int i=0; inCurrentMaxLevel) { nCurrentWriterLevel = (short)(nCurrentMaxLevel-1); } else if (nCurrentWriterLevel<0 && nCurrentMaxLevel>0) { nCurrentWriterLevel=0; } dlg.setListBoxSelectedItem("WriterLevel", nCurrentWriterLevel); // Load the values for the current level if (nCurrentWriterLevel>-1) { String sLevel = Integer.toString(nCurrentWriterLevel+1); if (headingMap.keySet().contains(sLevel)) { Map attr = headingMap.get(sLevel); dlg.setComboBoxText("LaTeXLevel", attr.get("level")); dlg.setComboBoxText("LaTeXName", attr.get("name")); } else { dlg.setListBoxSelectedItem("LaTeXLevel", (short)2); dlg.setComboBoxText("LaTeXName", ""); } } boolean bupdate = dlg.getListBoxSelectedItem("MaxLevel")>0; dlg.setControlEnabled("WriterLevelLabel", bupdate); dlg.setControlEnabled("WriterLevel", bupdate); dlg.setControlEnabled("LaTeXLevelLabel", bupdate); dlg.setControlEnabled("LaTeXLevel", bupdate); dlg.setControlEnabled("LaTeXNameLabel", bupdate); dlg.setControlEnabled("LaTeXName", bupdate); // Until implemented: dlg.setControlEnabled("UseTitlesec", false); //dlg.setControlEnabled("UseTitlesec", bupdate); // Until implemented: dlg.setControlEnabled("UseTitletoc", false); //boolean bNoIndex = dlg.getCheckBoxStateAsBoolean("NoIndex"); //dlg.setControlEnabled("UseTitletoc", !bNoIndex); } // The page "Styles" // This page handles the various style maps as well as the options other_styles and formatting private void loadStyles() { String sFormatting = config.getOption("formatting"); if ("ignore_all".equals(sFormatting)) { dlg.setListBoxSelectedItem("Formatting", (short)0); } else if ("ignore_most".equals(sFormatting)) { dlg.setListBoxSelectedItem("Formatting", (short)1); } else if ("convert_most".equals(sFormatting)) { dlg.setListBoxSelectedItem("Formatting", (short)3); } else if ("convert_all".equals(sFormatting)) { dlg.setListBoxSelectedItem("Formatting", (short)4); } else { dlg.setListBoxSelectedItem("Formatting", (short)2); } updateStylesControls(); } private void saveStyles() { // Save the current style map, if any if (nCurrentFamily>-1 && sCurrentStyleName!=null) { Map attr=new HashMap(); attr.put("before", dlg.getTextFieldText("Before")); attr.put("after", dlg.getTextFieldText("After")); if (dlg.getControlEnabled("Next")) { attr.put("next", dlg.getTextFieldText("Next")); } if (dlg.getControlEnabled("LineBreak")) { attr.put("line-break", Boolean.toString(dlg.getCheckBoxStateAsBoolean("LineBreak"))); } if (dlg.getControlEnabled("Verbatim")) { attr.put("verbatim", Boolean.toString(dlg.getCheckBoxStateAsBoolean("Verbatim"))); } styleMap[nCurrentFamily].put(sCurrentStyleName, attr); } switch (dlg.getListBoxSelectedItem("Formatting")) { case 0: config.setOption("formatting", "ignore_all"); break; case 1: config.setOption("formatting", "ignore_most"); break; case 2: config.setOption("formatting", "convert_basic"); break; case 3: config.setOption("formatting", "convert_most"); break; case 4: config.setOption("formatting", "convert_all"); } } private void updateStylesControls() { short nNewFamily = dlg.getListBoxSelectedItem("StyleFamily"); if (nNewFamily>-1 && nNewFamily!=nCurrentFamily) { // The user has changed the family; load and display the corresponding style names Set items = styleMap[nNewFamily].keySet(); String[] sStyleNames = new String[items.size()]; int i=0; for (String s : items) { sStyleNames[i++] = s; } sortStringArray(sStyleNames); dlg.setListBoxStringItemList("StyleName", sStyleNames); dlg.setListBoxSelectedItem("StyleName", (short)Math.min(sStyleNames.length-1, 0)); dlg.setControlEnabled("NextLabel", nNewFamily==2); dlg.setControlEnabled("Next", nNewFamily==2); dlg.setControlEnabled("Verbatim", nNewFamily<2); dlg.setControlEnabled("LineBreak", nNewFamily==1); nCurrentFamily = nNewFamily; } if (nCurrentFamily>-1) { short nStyleNameItem = dlg.getListBoxSelectedItem("StyleName"); if (nStyleNameItem>=0) { sCurrentStyleName = dlg.getListBoxStringItemList("StyleName")[nStyleNameItem]; Map attr = styleMap[nCurrentFamily].get(sCurrentStyleName); dlg.setTextFieldText("Before", attr.containsKey("before") ? attr.get("before") : ""); dlg.setTextFieldText("After", attr.containsKey("after") ? attr.get("before") : ""); dlg.setTextFieldText("Next", attr.containsKey("next") ? attr.get("next") : ""); dlg.setTextFieldText("Verbatim", attr.containsKey("verbatim") ? attr.get("verbatim") : ""); dlg.setTextFieldText("LineBreak", attr.containsKey("line-break") ? attr.get("line-break") : ""); dlg.setControlEnabled("DeleteStyleButton", true); System.out.println("...OK loading style"); } else { sCurrentStyleName = null; dlg.setTextFieldText("Before", ""); dlg.setTextFieldText("After", ""); dlg.setTextFieldText("Next", ""); dlg.setCheckBoxStateAsBoolean("Verbatim", false); dlg.setCheckBoxStateAsBoolean("LineBreak", false); dlg.setControlEnabled("DeleteStyleButton", false); } } } // The page "Characters" // This page handles the options use_color, use_soul, use_ulem and use_hyperref // In addition it handles style maps for formatting attributes private void loadCharacters() { dlg.setCheckBoxStateAsBoolean("UseHyperref","true".equals(config.getOption("use_hyperref"))); dlg.setCheckBoxStateAsBoolean("UseColor","true".equals(config.getOption("use_color"))); dlg.setCheckBoxStateAsBoolean("UseSoul","true".equals(config.getOption("use_soul"))); dlg.setCheckBoxStateAsBoolean("UseUlem","true".equals(config.getOption("use_ulem"))); updateCharactersControls(); } private void saveCharacters() { // Save the current attribute map, if any if (nCurrentAttribute>-1) { if (dlg.getCheckBoxStateAsBoolean("CustomAttribute")) { HashMap attr = new HashMap(); attr.put("before", dlg.getTextFieldText("Before")); attr.put("after", dlg.getTextFieldText("After")); attributeMap.put(sAttributeNames[nCurrentAttribute], attr); } else { attributeMap.remove(sAttributeNames[nCurrentAttribute]); } } config.setOption("use_hyperref", Boolean.toString(dlg.getCheckBoxStateAsBoolean("UseHyperref"))); config.setOption("use_color", Boolean.toString(dlg.getCheckBoxStateAsBoolean("UseColor"))); config.setOption("use_soul", Boolean.toString(dlg.getCheckBoxStateAsBoolean("UseSoul"))); config.setOption("use_ulem", Boolean.toString(dlg.getCheckBoxStateAsBoolean("UseUlem"))); } private void updateCharactersControls() { short nNewAttribute = dlg.getListBoxSelectedItem("FormattingAttribute"); if (nNewAttribute>-1 && nCurrentAttribute!=nNewAttribute) { String sName = sAttributeNames[nNewAttribute]; if (attributeMap.keySet().contains(sName)) { dlg.setCheckBoxStateAsBoolean("CustomAttribute", true); dlg.setTextFieldText("Before", attributeMap.get(sName).containsKey("before") ? attributeMap.get(sName).get("before") : ""); dlg.setTextFieldText("After", attributeMap.get(sName).containsKey("after") ? attributeMap.get(sName).get("after") : ""); } else { dlg.setCheckBoxStateAsBoolean("CustomAttribute", false); dlg.setTextFieldText("Before", ""); dlg.setTextFieldText("After", ""); } nCurrentAttribute = nNewAttribute; } boolean bCustom = dlg.getCheckBoxStateAsBoolean("CustomAttribute"); dlg.setControlEnabled("Before", bCustom); dlg.setControlEnabled("After", bCustom); // Until implemented... dlg.setControlEnabled("UseSoul", false); // After which it should be... //boolean bUseSoul = dlg.getCheckBoxStateAsBoolean("UseSoul"); //dlg.setControlEnabled("UseUlem", !bUseSoul); } // The page "Fonts" // This page handles the options use_fontspec, use_pifont, use_tipa, use_eurosym, use_wasysym, // use_ifsym, use_bbding private void loadFonts() { dlg.setCheckBoxStateAsBoolean("UseFontspec","true".equals(config.getOption("use_fontspec"))); dlg.setCheckBoxStateAsBoolean("UsePifont","true".equals(config.getOption("use_pifont"))); dlg.setCheckBoxStateAsBoolean("UseTipa","true".equals(config.getOption("use_tipa"))); dlg.setCheckBoxStateAsBoolean("UseEurosym","true".equals(config.getOption("use_eurosym"))); dlg.setCheckBoxStateAsBoolean("UseWasysym","true".equals(config.getOption("use_wasysym"))); dlg.setCheckBoxStateAsBoolean("UseIfsym","true".equals(config.getOption("use_ifsym"))); dlg.setCheckBoxStateAsBoolean("UseBbding","true".equals(config.getOption("use_bbding"))); updateFontsControls(); } private void saveFonts() { config.setOption("use_fontspec", Boolean.toString(dlg.getCheckBoxStateAsBoolean("UseFontspec"))); config.setOption("use_pifont", Boolean.toString(dlg.getCheckBoxStateAsBoolean("UsePifont"))); config.setOption("use_tipa", Boolean.toString(dlg.getCheckBoxStateAsBoolean("UseTipa"))); config.setOption("use_eurosym", Boolean.toString(dlg.getCheckBoxStateAsBoolean("UseEurosym"))); config.setOption("use_wasysym", Boolean.toString(dlg.getCheckBoxStateAsBoolean("UseWasysym"))); config.setOption("use_ifsym", Boolean.toString(dlg.getCheckBoxStateAsBoolean("UseIfsym"))); config.setOption("use_bbding", Boolean.toString(dlg.getCheckBoxStateAsBoolean("UseBbding"))); } private void updateFontsControls() { // Until implemented... dlg.setControlEnabled("UseFontspec", false); // Nothing to do } // The page "Pages" // This page handles the options page_formatting, use_geometry, use_fancyhdr, use_lastpage and use_endnotes private void loadPages() { String sPageFormatting = config.getOption("page_formatting"); if ("ignore_all".equals(sPageFormatting)) { dlg.setCheckBoxStateAsBoolean("ExportGeometry", false); dlg.setCheckBoxStateAsBoolean("ExportHeaderFooter", false); } else if ("convert_geometry".equals(sPageFormatting)) { dlg.setCheckBoxStateAsBoolean("ExportGeometry", true); dlg.setCheckBoxStateAsBoolean("ExportHeaderFooter", false); } else if ("convert_header_footer".equals(sPageFormatting)) { dlg.setCheckBoxStateAsBoolean("ExportGeometry", false); dlg.setCheckBoxStateAsBoolean("ExportHeaderFooter", true); } else if ("convert_all".equals(sPageFormatting)) { dlg.setCheckBoxStateAsBoolean("ExportGeometry", true); dlg.setCheckBoxStateAsBoolean("ExportHeaderFooter", true); } dlg.setCheckBoxStateAsBoolean("UseGeometry", "true".equals(config.getOption("use_geometry"))); dlg.setCheckBoxStateAsBoolean("UseFancyhdr", "true".equals(config.getOption("use_fancyhdr"))); dlg.setCheckBoxStateAsBoolean("UseLastpage", "true".equals(config.getOption("use_lastpage"))); dlg.setCheckBoxStateAsBoolean("UseEndnotes", "true".equals(config.getOption("use_endnotes"))); updatePagesControls(); } private void savePages() { boolean bGeometry = dlg.getCheckBoxStateAsBoolean("ExportGeometry"); boolean bHeaderFooter = dlg.getCheckBoxStateAsBoolean("ExportHeaderFooter"); if (bGeometry && bHeaderFooter) { config.setOption("page_formatting", "convert_all"); } else if (bGeometry && !bHeaderFooter) { config.setOption("page_formatting", "convert_geometry"); } else if (!bGeometry && bHeaderFooter) { config.setOption("page_formatting", "convert_header_footer"); } else { config.setOption("page_formatting", "ignore_all"); } config.setOption("use_geometry", Boolean.toString(dlg.getCheckBoxStateAsBoolean("UseGeometry"))); config.setOption("use_fancyhdr", Boolean.toString(dlg.getCheckBoxStateAsBoolean("UseFancyhdr"))); config.setOption("use_lastpage", Boolean.toString(dlg.getCheckBoxStateAsBoolean("UseLastpage"))); config.setOption("use_endnotes", Boolean.toString(dlg.getCheckBoxStateAsBoolean("UseEndnotes"))); } private void updatePagesControls() { boolean bExportGeometry = dlg.getCheckBoxStateAsBoolean("ExportGeometry"); dlg.setControlEnabled("UseGeometry",bExportGeometry); boolean bExport = dlg.getCheckBoxStateAsBoolean("ExportHeaderFooter"); dlg.setControlEnabled("UseFancyhdr",bExport); } // The page "Tables" // This page handles the options table_content, use_tabulary, use_colortbl, use_multirow, use_supertabular, use_longtable, // table_first_head_style, table_head_style, table_foot_style, table_last_foot_style // Limitation: Cannot handle the values "error" and "warning" for table_content private void loadTables() { dlg.setCheckBoxStateAsBoolean("NoTables", !"accept".equals(config.getOption("table_content"))); dlg.setCheckBoxStateAsBoolean("UseColortbl","true".equals(config.getOption("use_colortbl"))); dlg.setCheckBoxStateAsBoolean("UseTabulary", "true".equals(config.getOption("use_tabulary"))); //dlg.setCheckBoxStateAsBoolean("UseMultirow", "true".equals(config.getOption("use_multirow"))); dlg.setCheckBoxStateAsBoolean("UseSupertabular","true".equals(config.getOption("use_supertabular"))); dlg.setCheckBoxStateAsBoolean("UseLongtable", "true".equals(config.getOption("use_longtable"))); dlg.setTextFieldText("TableFirstHeadStyle", config.getOption("table_first_head_style")); dlg.setTextFieldText("TableHeadStyle", config.getOption("table_head_style")); dlg.setTextFieldText("TableFootStyle", config.getOption("table_foot_style")); dlg.setTextFieldText("TableLastFootStyle", config.getOption("table_last_foot_style")); dlg.setTextFieldText("TableSequenceName", config.getOption("table_sequence_name")); updateTablesControls(); } private void saveTables() { config.setOption("table_content", dlg.getCheckBoxStateAsBoolean("NoTables") ? "ignore" : "accept"); config.setOption("use_colortbl", Boolean.toString(dlg.getCheckBoxStateAsBoolean("UseColortbl"))); config.setOption("use_tabulary", Boolean.toString(dlg.getCheckBoxStateAsBoolean("UseTabulary"))); //config.setOption("use_multirow", Boolean.toString(dlg.getCheckBoxStateAsBoolean("UseMultirow"))); config.setOption("use_supertabular", Boolean.toString(dlg.getCheckBoxStateAsBoolean("UseSupertabular"))); config.setOption("use_longtable", Boolean.toString(dlg.getCheckBoxStateAsBoolean("UseLongtable"))); config.setOption("table_first_head_style", dlg.getTextFieldText("TableFirstHeadStyle")); config.setOption("table_head_style", dlg.getTextFieldText("TableHeadStyle")); config.setOption("table_foot_style", dlg.getTextFieldText("TableFootStyle")); config.setOption("table_last_foot_style", dlg.getTextFieldText("TableLastFootStyle")); config.setOption("table_sequence_name", dlg.getTextFieldText("TableSequenceName")); } private void updateTablesControls() { boolean bNoTables = dlg.getCheckBoxStateAsBoolean("NoTables"); boolean bSupertabular = dlg.getCheckBoxStateAsBoolean("UseSupertabular"); boolean bLongtable = dlg.getCheckBoxStateAsBoolean("UseLongtable"); dlg.setControlEnabled("UseColortbl", !bNoTables); dlg.setControlEnabled("UseTabulary", !bNoTables); dlg.setControlEnabled("UseMultirow", false); dlg.setControlEnabled("UseSupertabular", !bNoTables); dlg.setControlEnabled("UseLongtable", !bNoTables && !bSupertabular); dlg.setControlEnabled("TableFirstHeadLabel", !bNoTables && (bSupertabular || bLongtable)); dlg.setControlEnabled("TableFirstHeadStyle", !bNoTables && (bSupertabular || bLongtable)); dlg.setControlEnabled("TableHeadLabel", !bNoTables && (bSupertabular || bLongtable)); dlg.setControlEnabled("TableHeadStyle", !bNoTables && (bSupertabular || bLongtable)); dlg.setControlEnabled("TableFootLabel", !bNoTables && (bSupertabular || bLongtable)); dlg.setControlEnabled("TableFootStyle", !bNoTables && (bSupertabular || bLongtable)); dlg.setControlEnabled("TableLastFootLabel", !bNoTables && (bSupertabular || bLongtable)); dlg.setControlEnabled("TableLastFootStyle", !bNoTables && (bSupertabular || bLongtable)); dlg.setControlEnabled("TableSequenceLabel", !bNoTables); dlg.setControlEnabled("TableSequenceName", !bNoTables); } // The page "Figures" // This page handles the options use_caption, align_frames, figure_sequence_name, image_content, // remove_graphics_extension and image_options // Limitation: Cannot handle the values "error" and "warning" for image_content private void loadFigures() { dlg.setCheckBoxStateAsBoolean("UseCaption", "true".equals(config.getOption("use_caption"))); dlg.setCheckBoxStateAsBoolean("AlignFrames", "true".equals(config.getOption("align_frames"))); dlg.setTextFieldText("FigureSequenceName", config.getOption("figure_sequence_name")); dlg.setCheckBoxStateAsBoolean("NoImages", !"accept".equals(config.getOption("image_content"))); dlg.setCheckBoxStateAsBoolean("RemoveGraphicsExtension", "true".equals(config.getOption("remove_graphics_extension"))); dlg.setTextFieldText("ImageOptions", config.getOption("image_options")); updateFiguresControls(); } private void saveFigures() { config.setOption("use_caption", Boolean.toString(dlg.getCheckBoxStateAsBoolean("UseCaption"))); config.setOption("align_frames", Boolean.toString(dlg.getCheckBoxStateAsBoolean("AlignFrames"))); config.setOption("figure_sequence_name", dlg.getTextFieldText("FigureSequenceName")); config.setOption("image_content", dlg.getCheckBoxStateAsBoolean("NoImages") ? "ignore" : "accept"); config.setOption("remove_graphics_extension", Boolean.toString(dlg.getCheckBoxStateAsBoolean("RemoveGraphicsExtension"))); config.setOption("image_options", dlg.getTextFieldText("ImageOptions")); } private void updateFiguresControls() { boolean bNoImages = dlg.getCheckBoxStateAsBoolean("NoImages"); dlg.setControlEnabled("RemoveGraphicsExtension", !bNoImages); dlg.setControlEnabled("ImageOptionsLabel", !bNoImages); dlg.setControlEnabled("ImageOptions", !bNoImages); } // The page "TextAndMath" // This page handles the options use_ooomath and tabstop as well as the // text replacements and math symbol definitions private void loadTextAndMath() { dlg.setCheckBoxStateAsBoolean("UseOoomath","true".equals(config.getOption("use_ooomath"))); Set symbolnames = config.getComplexOption("math-symbol-map").keySet(); String[] sSymbolNames = new String[symbolnames.size()]; int i=0; for (String s : symbolnames) { sSymbolNames[i++] = s; } sortStringArray(sSymbolNames); dlg.setListBoxStringItemList("MathSymbolName", sSymbolNames); dlg.setListBoxSelectedItem("MathSymbolName", (short)0); //sCurrentMathSymbol = symbolnames.size()>0 ? sSymbolNames[0] : null; Set names = config.getComplexOption("string-replace").keySet(); String[] sNames = new String[names.size()]; int j=0; for (String s : names) { sNames[j++] = s; } sortStringArray(sNames); dlg.setListBoxStringItemList("TextInput", sNames); dlg.setListBoxSelectedItem("TextInput", (short)0); //sCurrentText = sNames[0]; dlg.setTextFieldText("TabStopLaTeX", config.getOption("tabstop")); updateTextAndMathControls(); } private void saveTextAndMath() { config.setOption("use_ooomath", Boolean.toString(dlg.getCheckBoxStateAsBoolean("UseOoomath"))); // Save the current math symbol in our cache if (sCurrentMathSymbol!=null) { Map attr = new HashMap(); attr.put("latex", dlg.getTextFieldText("MathLaTeX")); mathSymbols.put(sCurrentMathSymbol, attr); } // Save the current string replace in our cache if (sCurrentText!=null) { Map attr = new HashMap(); attr.put("latex-code", dlg.getTextFieldText("LaTeX")); attr.put("fontenc", "any"); stringReplace.put(sCurrentText, attr); } config.setOption("tabstop", dlg.getTextFieldText("TabStopLaTeX")); } private void updateTextAndMathControls() { // Get the current math symbol, if any short nSymbolItem = dlg.getListBoxSelectedItem("MathSymbolName"); if (nSymbolItem>=0) { sCurrentMathSymbol = dlg.getListBoxStringItemList("MathSymbolName")[nSymbolItem]; Map attributes = mathSymbols.get(sCurrentMathSymbol); dlg.setTextFieldText("MathLaTeX", attributes.get("latex")); dlg.setControlEnabled("DeleteSymbolButton", true); } else { sCurrentMathSymbol = null; dlg.setTextFieldText("MathLaTeX", ""); dlg.setControlEnabled("DeleteSymbolButton", false); } // Get the current input string, if any short nItem = dlg.getListBoxSelectedItem("TextInput"); if (nItem>=0) { sCurrentText = dlg.getListBoxStringItemList("TextInput")[nItem]; Map attributes = stringReplace.get(sCurrentText); dlg.setTextFieldText("LaTeX", attributes.get("latex-code")); //dlg.setTextFieldText("Fontenc", attributes.get("fontenc")); dlg.setControlEnabled("DeleteTextButton", !"\u00A0!".equals(sCurrentText) && !"\u00A0?".equals(sCurrentText) && !"\u00A0:".equals(sCurrentText) && !"\u00A0;".equals(sCurrentText) && !"\u00A0\u2014".equals(sCurrentText)); } else { sCurrentText = null; dlg.setTextFieldText("LaTeX", ""); //dlg.setTextFieldText("Fontenc", "any"); dlg.setControlEnabled("DeleteTextButton", false); } } // Utilities private void sortStringArray(String[] theArray) { // TODO: Get locale from OOo rather than the system Collator collator = Collator.getInstance(); Arrays.sort(theArray, collator); } }