Writer2xhtml custom config ui
git-svn-id: svn://svn.code.sf.net/p/writer2latex/code/trunk@57 f0f2a975-2e09-46c8-9428-3b39399b9f3c
This commit is contained in:
parent
7644cf2eba
commit
977a2f7d6b
22 changed files with 993 additions and 195 deletions
|
@ -20,15 +20,18 @@
|
|||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Version 1.2 (2010-03-26)
|
||||
* Version 1.2 (2010-04-12)
|
||||
*
|
||||
*/
|
||||
|
||||
package org.openoffice.da.comp.w2lcommon.filter;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.text.Collator;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
|
@ -39,6 +42,7 @@ 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.container.NoSuchElementException;
|
||||
import com.sun.star.io.NotConnectedException;
|
||||
import com.sun.star.io.XInputStream;
|
||||
import com.sun.star.io.XOutputStream;
|
||||
|
@ -55,10 +59,12 @@ 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;
|
||||
import org.openoffice.da.comp.w2lcommon.helper.FilePicker;
|
||||
import org.openoffice.da.comp.w2lcommon.helper.StyleNameProvider;
|
||||
|
||||
/** This is a base implementation of a uno component which supports several option pages
|
||||
|
@ -73,11 +79,14 @@ public abstract class ConfigurationDialogBase extends WeakBase implements XConta
|
|||
// The component context
|
||||
protected XComponentContext xContext;
|
||||
|
||||
// File picker wrapper
|
||||
private FilePicker filePicker = null;
|
||||
|
||||
// UNO simple file access service
|
||||
protected XSimpleFileAccess2 sfa2 = null;
|
||||
|
||||
// Access to display names of the styles in the current document
|
||||
protected StyleNameProvider styleNameProvider = null;
|
||||
|
||||
// UNO path substitution
|
||||
private XStringSubstitution xPathSub = null;
|
||||
|
||||
// The configuration implementation
|
||||
protected Config config;
|
||||
|
@ -99,6 +108,9 @@ public abstract class ConfigurationDialogBase extends WeakBase implements XConta
|
|||
/** Create a new <code>ConfigurationDialogBase</code> */
|
||||
public ConfigurationDialogBase(XComponentContext xContext) {
|
||||
this.xContext = xContext;
|
||||
|
||||
// Get the file picker
|
||||
filePicker = new FilePicker(xContext);
|
||||
|
||||
// Get the SimpleFileAccess service
|
||||
try {
|
||||
|
@ -111,7 +123,6 @@ public abstract class ConfigurationDialogBase extends WeakBase implements XConta
|
|||
}
|
||||
|
||||
// Create the config file name
|
||||
XStringSubstitution xPathSub = null;
|
||||
try {
|
||||
Object psObject = xContext.getServiceManager().createInstanceWithContext(
|
||||
"com.sun.star.util.PathSubstitution", xContext);
|
||||
|
@ -125,8 +136,6 @@ public abstract class ConfigurationDialogBase extends WeakBase implements XConta
|
|||
// Create the configuration
|
||||
config = ConverterFactory.createConverter(getMIMEType()).getConfig();
|
||||
|
||||
// Get the style name provider
|
||||
styleNameProvider = new StyleNameProvider(xContext);
|
||||
}
|
||||
|
||||
// Implement XContainerWindowEventHandler
|
||||
|
@ -134,7 +143,7 @@ public abstract class ConfigurationDialogBase extends WeakBase implements XConta
|
|||
throws com.sun.star.lang.WrappedTargetException {
|
||||
XDialog xDialog = (XDialog)UnoRuntime.queryInterface(XDialog.class, xWindow);
|
||||
String sTitle = xDialog.getTitle();
|
||||
|
||||
|
||||
if (!pageHandlers.containsKey(sTitle)) {
|
||||
throw new com.sun.star.lang.WrappedTargetException("Unknown dialog "+sTitle);
|
||||
}
|
||||
|
@ -245,6 +254,205 @@ public abstract class ConfigurationDialogBase extends WeakBase implements XConta
|
|||
|
||||
protected abstract boolean handleEvent(DialogAccess dlg, String sMethodName);
|
||||
|
||||
|
||||
// Methods to set and get controls based on config
|
||||
protected void checkBoxFromConfig(DialogAccess dlg, String sCheckBoxName, String sConfigName) {
|
||||
dlg.setCheckBoxStateAsBoolean(sCheckBoxName, "true".equals(config.getOption(sConfigName)));
|
||||
}
|
||||
|
||||
protected void checkBoxToConfig(DialogAccess dlg, String sCheckBoxName, String sConfigName) {
|
||||
config.setOption(sConfigName, Boolean.toString(dlg.getCheckBoxStateAsBoolean(sCheckBoxName)));
|
||||
}
|
||||
|
||||
protected void textFieldFromConfig(DialogAccess dlg, String sTextBoxName, String sConfigName) {
|
||||
dlg.setTextFieldText(sTextBoxName, config.getOption(sConfigName));
|
||||
}
|
||||
|
||||
protected void textFieldToConfig(DialogAccess dlg, String sTextBoxName, String sConfigName) {
|
||||
config.setOption(sConfigName, dlg.getTextFieldText(sTextBoxName));
|
||||
}
|
||||
|
||||
protected void listBoxFromConfig(DialogAccess dlg, String sListBoxName, String sConfigName, String[] sConfigValues, short nDefault) {
|
||||
String sCurrentValue = config.getOption(sConfigName);
|
||||
int nCount = sConfigValues.length;
|
||||
for (short i=0; i<nCount; i++) {
|
||||
if (sConfigValues[i].equals(sCurrentValue)) {
|
||||
dlg.setListBoxSelectedItem(sListBoxName, i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
dlg.setListBoxSelectedItem(sListBoxName, nDefault);
|
||||
}
|
||||
|
||||
protected void listBoxToConfig(DialogAccess dlg, String sListBoxName, String sConfigName, String[] sConfigValues) {
|
||||
config.setOption(sConfigName, sConfigValues[dlg.getListBoxSelectedItem(sListBoxName)]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected abstract class CustomFileHandler extends PageHandler {
|
||||
|
||||
// The file name
|
||||
private String sCustomFileName;
|
||||
|
||||
public CustomFileHandler() {
|
||||
super();
|
||||
try {
|
||||
sCustomFileName = xPathSub.substituteVariables("$(user)/"+getFileName(), false);
|
||||
}
|
||||
catch (NoSuchElementException e) {
|
||||
sCustomFileName = getFileName();
|
||||
}
|
||||
}
|
||||
|
||||
// The subclass must provide these
|
||||
protected abstract String getSuffix();
|
||||
|
||||
protected abstract String getFileName();
|
||||
|
||||
protected abstract void useCustomInner(DialogAccess dlg, boolean bUseCustom);
|
||||
|
||||
@Override protected void setControls(DialogAccess dlg) {
|
||||
String sText = "";
|
||||
boolean bUseCustom = false;
|
||||
if (fileExists(sCustomFileName)) {
|
||||
sText = loadFile(sCustomFileName);
|
||||
bUseCustom = true;
|
||||
}
|
||||
else if (fileExists(sCustomFileName+".bak")) {
|
||||
sText = loadFile(sCustomFileName+".bak");
|
||||
}
|
||||
// Currently ignore failure to load the file
|
||||
if (sText==null) { sText=""; }
|
||||
|
||||
dlg.setCheckBoxStateAsBoolean("UseCustom"+getSuffix(), bUseCustom);
|
||||
dlg.setTextFieldText("Custom"+getSuffix(), sText);
|
||||
|
||||
useCustomChange(dlg);
|
||||
}
|
||||
|
||||
@Override protected void getControls(DialogAccess dlg) {
|
||||
if (dlg.getCheckBoxStateAsBoolean("UseCustom"+getSuffix())) {
|
||||
saveFile(sCustomFileName,dlg.getTextFieldText("Custom"+getSuffix()));
|
||||
killFile(sCustomFileName+".bak");
|
||||
}
|
||||
else {
|
||||
saveFile(sCustomFileName+".bak",dlg.getTextFieldText("Custom"+getSuffix()));
|
||||
killFile(sCustomFileName);
|
||||
}
|
||||
}
|
||||
|
||||
@Override protected boolean handleEvent(DialogAccess dlg, String sMethod) {
|
||||
if (sMethod.equals("UseCustom"+getSuffix()+"Change")) {
|
||||
useCustomChange(dlg);
|
||||
return true;
|
||||
}
|
||||
else if (sMethod.equals("Load"+getSuffix()+"Click")) {
|
||||
loadCustomClick(dlg);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void useCustomChange(DialogAccess dlg) {
|
||||
boolean bUseCustom = dlg.getCheckBoxStateAsBoolean("UseCustom"+getSuffix());
|
||||
dlg.setControlEnabled("Custom"+getSuffix(), bUseCustom);
|
||||
dlg.setControlEnabled("Load"+getSuffix()+"Button", bUseCustom);
|
||||
useCustomInner(dlg,bUseCustom);
|
||||
}
|
||||
|
||||
private void loadCustomClick(DialogAccess dlg) {
|
||||
String sFileName=filePicker.getPath();
|
||||
if (sFileName!=null) {
|
||||
String sText = loadFile(sFileName);
|
||||
if (sText!=null) {
|
||||
dlg.setTextFieldText("Custom"+getSuffix(), sText);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Helpers for sfa2
|
||||
|
||||
// Checks that the file exists
|
||||
private boolean fileExists(String sFileName) {
|
||||
try {
|
||||
return sfa2!=null && sfa2.exists(sFileName);
|
||||
}
|
||||
catch (CommandAbortedException e) {
|
||||
}
|
||||
catch (com.sun.star.uno.Exception e) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Delete a file if it exists, return true on success
|
||||
private boolean killFile(String sFileName) {
|
||||
try {
|
||||
if (sfa2!=null && sfa2.exists(sFileName)) {
|
||||
sfa2.kill(sFileName);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (com.sun.star.uno.Exception e) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Load a text file, returns null on failure
|
||||
private String loadFile(String sFileName) {
|
||||
if (sfa2!=null) {
|
||||
try {
|
||||
XInputStream xIs = sfa2.openFileRead(sFileName);
|
||||
if (xIs!=null) {
|
||||
InputStream is = new XInputStreamToInputStreamAdapter(xIs);
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
|
||||
StringBuffer buf = new StringBuffer();
|
||||
String sLine;
|
||||
try {
|
||||
while ((sLine = reader.readLine())!=null) {
|
||||
buf.append(sLine).append('\n');
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
}
|
||||
catch (com.sun.star.uno.Exception e) {
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Save a text file, return true on success
|
||||
protected boolean saveFile(String sFileName, String sText) {
|
||||
killFile(sFileName);
|
||||
try {
|
||||
XOutputStream xOs = sfa2.openFileWrite(sFileName);
|
||||
if (xOs!=null) {
|
||||
OutputStream os = new XOutputStreamToOutputStreamAdapter(xOs);
|
||||
try {
|
||||
OutputStreamWriter osw = new OutputStreamWriter(os,"UTF-8");
|
||||
osw.write(sText);
|
||||
osw.flush();
|
||||
os.close();
|
||||
}
|
||||
catch (IOException e) {
|
||||
xOs.closeOutput();
|
||||
return false;
|
||||
}
|
||||
xOs.closeOutput();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (com.sun.star.uno.Exception e) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract class UserListPageHandler extends PageHandler {
|
||||
|
||||
// Methods to handle user controlled lists
|
||||
protected XDialog getDialog(String sDialogName) {
|
||||
XMultiComponentFactory xMCF = xContext.getServiceManager();
|
||||
|
@ -275,7 +483,7 @@ public abstract class ConfigurationDialogBase extends WeakBase implements XConta
|
|||
return false;
|
||||
}
|
||||
|
||||
private boolean deleteCurrentItem(DialogAccess dlg, String sListName) {
|
||||
protected boolean deleteCurrentItem(DialogAccess dlg, String sListName) {
|
||||
String[] sItems = dlg.getListBoxStringItemList(sListName);
|
||||
short nSelected = dlg.getListBoxSelectedItem(sListName);
|
||||
if (nSelected>=0 && deleteItem(sItems[nSelected])) {
|
||||
|
@ -318,7 +526,7 @@ public abstract class ConfigurationDialogBase extends WeakBase implements XConta
|
|||
return null;
|
||||
}
|
||||
|
||||
private String appendItem(DialogAccess dlg, String sListName, Set<String> suggestions) {
|
||||
protected String appendItem(DialogAccess dlg, String sListName, Set<String> suggestions) {
|
||||
String[] sItems = dlg.getListBoxStringItemList(sListName);
|
||||
String sNewItem = newItem(suggestions);
|
||||
if (sNewItem!=null) {
|
||||
|
@ -339,46 +547,339 @@ public abstract class ConfigurationDialogBase extends WeakBase implements XConta
|
|||
return sNewItem;
|
||||
}
|
||||
|
||||
// Utilities
|
||||
protected String[] sortStringSet(Set<String> theSet) {
|
||||
String[] theArray = new String[theSet.size()];
|
||||
int i=0;
|
||||
for (String s : theSet) {
|
||||
theArray[i++] = s;
|
||||
}
|
||||
sortStringArray(theArray);
|
||||
return theArray;
|
||||
}
|
||||
|
||||
protected void sortStringArray(String[] theArray) {
|
||||
// TODO: Get locale from OOo rather than the system
|
||||
Collator collator = Collator.getInstance();
|
||||
Arrays.sort(theArray, collator);
|
||||
}
|
||||
|
||||
// Methods to set and get controls based on config
|
||||
protected void checkBoxFromConfig(DialogAccess dlg, String sCheckBoxName, String sConfigName) {
|
||||
dlg.setCheckBoxStateAsBoolean(sCheckBoxName, "true".equals(config.getOption(sConfigName)));
|
||||
}
|
||||
|
||||
protected void checkBoxToConfig(DialogAccess dlg, String sCheckBoxName, String sConfigName) {
|
||||
config.setOption(sConfigName, Boolean.toString(dlg.getCheckBoxStateAsBoolean(sCheckBoxName)));
|
||||
}
|
||||
|
||||
protected void textFieldFromConfig(DialogAccess dlg, String sTextBoxName, String sConfigName) {
|
||||
dlg.setTextFieldText(sTextBoxName, config.getOption(sConfigName));
|
||||
}
|
||||
|
||||
protected void textFieldToConfig(DialogAccess dlg, String sTextBoxName, String sConfigName) {
|
||||
config.setOption(sConfigName, dlg.getTextFieldText(sTextBoxName));
|
||||
}
|
||||
|
||||
protected void listBoxFromConfig(DialogAccess dlg, String sListBoxName, String sConfigName, String[] sConfigValues, short nDefault) {
|
||||
String sCurrentValue = config.getOption(sConfigName);
|
||||
int nCount = sConfigValues.length;
|
||||
for (short i=0; i<nCount; i++) {
|
||||
if (sConfigValues[i].equals(sCurrentValue)) {
|
||||
dlg.setListBoxSelectedItem(sListBoxName, i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
dlg.setListBoxSelectedItem(sListBoxName, nDefault);
|
||||
}
|
||||
|
||||
protected void listBoxToConfig(DialogAccess dlg, String sListBoxName, String sConfigName, String[] sConfigValues) {
|
||||
config.setOption(sConfigName, sConfigValues[dlg.getListBoxSelectedItem(sListBoxName)]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected abstract class StylesPageHandler extends UserListPageHandler {
|
||||
// The subclass must define these
|
||||
protected String[] sFamilyNames;
|
||||
protected String[] sOOoFamilyNames;
|
||||
|
||||
// Our data
|
||||
private ComplexOption[] styleMap;
|
||||
protected short nCurrentFamily = -1;
|
||||
private String sCurrentStyleName = null;
|
||||
|
||||
// Access to display names of the styles in the current document
|
||||
private StyleNameProvider styleNameProvider = null;
|
||||
|
||||
// Some methods to be implemented by the subclass
|
||||
protected abstract String getDefaultConfigName();
|
||||
|
||||
protected abstract void getControls(DialogAccess dlg, Map<String,String> attr);
|
||||
|
||||
protected abstract void setControls(DialogAccess dlg, Map<String,String> attr);
|
||||
|
||||
protected abstract void clearControls(DialogAccess dlg);
|
||||
|
||||
protected abstract void prepareControls(DialogAccess dlg);
|
||||
|
||||
// Constructor
|
||||
protected StylesPageHandler(int nCount) {
|
||||
// Get the style name provider
|
||||
styleNameProvider = new StyleNameProvider(xContext);
|
||||
|
||||
// Reset the options
|
||||
styleMap = new ComplexOption[nCount];
|
||||
for (int i=0; i<nCount; i++) {
|
||||
styleMap[i] = new ComplexOption();
|
||||
}
|
||||
}
|
||||
|
||||
// Implement abstract methods from super
|
||||
protected void setControls(DialogAccess dlg) {
|
||||
// Load style maps from config (translating keys to display names)
|
||||
int nCount = sFamilyNames.length;
|
||||
for (int i=0; i<nCount; i++) {
|
||||
ComplexOption configMap = config.getComplexOption(sFamilyNames[i]+"-map");
|
||||
styleMap[i].clear();
|
||||
Map<String,String> displayNames = styleNameProvider.getDisplayNames(sOOoFamilyNames[i]);
|
||||
copyStyles(configMap, styleMap[i], displayNames);
|
||||
}
|
||||
|
||||
// Display paragraph maps first
|
||||
nCurrentFamily = -1;
|
||||
sCurrentStyleName = null;
|
||||
dlg.setListBoxSelectedItem("StyleFamily", (short)1);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean handleEvent(DialogAccess dlg, String sMethod) {
|
||||
if (sMethod.equals("StyleFamilyChange")) {
|
||||
styleFamilyChange(dlg);
|
||||
return true;
|
||||
}
|
||||
else if (sMethod.equals("StyleNameChange")) {
|
||||
styleNameChange(dlg);
|
||||
return true;
|
||||
}
|
||||
else if (sMethod.equals("NewStyleClick")) {
|
||||
newStyleClick(dlg);
|
||||
return true;
|
||||
}
|
||||
else if (sMethod.equals("DeleteStyleClick")) {
|
||||
deleteStyleClick(dlg);
|
||||
return true;
|
||||
}
|
||||
else if (sMethod.equals("LoadDefaultsClick")) {
|
||||
loadDefaultsClick(dlg);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Internal methods
|
||||
private void updateStyleMaps(DialogAccess dlg) {
|
||||
// Save the current style map, if any
|
||||
if (nCurrentFamily>-1 && sCurrentStyleName!=null) {
|
||||
getControls(dlg,styleMap[nCurrentFamily].get(sCurrentStyleName));
|
||||
}
|
||||
}
|
||||
|
||||
private void styleFamilyChange(DialogAccess dlg) {
|
||||
short nNewFamily = dlg.getListBoxSelectedItem("StyleFamily");
|
||||
if (nNewFamily>-1 && nNewFamily!=nCurrentFamily) {
|
||||
// The user has changed the family; load and display the corresponding style names
|
||||
updateStyleMaps(dlg);
|
||||
nCurrentFamily = nNewFamily;
|
||||
sCurrentStyleName = null;
|
||||
|
||||
String[] sStyleNames = sortStringSet(styleMap[nNewFamily].keySet());
|
||||
dlg.setListBoxStringItemList("StyleName", sStyleNames);
|
||||
if (sStyleNames.length>0) {
|
||||
dlg.setListBoxSelectedItem("StyleName", (short)0);
|
||||
}
|
||||
else {
|
||||
dlg.setListBoxSelectedItem("StyleName", (short)-1);
|
||||
}
|
||||
|
||||
updateDeleteButton(dlg);
|
||||
prepareControls(dlg);
|
||||
styleNameChange(dlg);
|
||||
}
|
||||
}
|
||||
|
||||
private void styleNameChange(DialogAccess dlg) {
|
||||
if (nCurrentFamily>-1) {
|
||||
updateStyleMaps(dlg);
|
||||
short nStyleNameItem = dlg.getListBoxSelectedItem("StyleName");
|
||||
if (nStyleNameItem>=0) {
|
||||
sCurrentStyleName = dlg.getListBoxStringItemList("StyleName")[nStyleNameItem];
|
||||
setControls(dlg,styleMap[nCurrentFamily].get(sCurrentStyleName));
|
||||
}
|
||||
else {
|
||||
sCurrentStyleName = null;
|
||||
clearControls(dlg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void newStyleClick(DialogAccess dlg) {
|
||||
if (nCurrentFamily>-1) {
|
||||
updateStyleMaps(dlg);
|
||||
String sNewName = appendItem(dlg, "StyleName",styleNameProvider.getInternalNames(sOOoFamilyNames[nCurrentFamily]).keySet());
|
||||
if (sNewName!=null) {
|
||||
styleMap[nCurrentFamily].put(sNewName, new HashMap<String,String>());
|
||||
clearControls(dlg);
|
||||
}
|
||||
updateDeleteButton(dlg);
|
||||
}
|
||||
}
|
||||
|
||||
private void deleteStyleClick(DialogAccess dlg) {
|
||||
if (nCurrentFamily>-1 && sCurrentStyleName!=null) {
|
||||
String sStyleName = sCurrentStyleName;
|
||||
if (deleteCurrentItem(dlg,"StyleName")) {
|
||||
styleMap[nCurrentFamily].remove(sStyleName);
|
||||
styleNameChange(dlg);
|
||||
}
|
||||
updateDeleteButton(dlg);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
private void updateDeleteButton(DialogAccess dlg) {
|
||||
dlg.setControlEnabled("DeleteStyleButton", dlg.getListBoxStringItemList("StyleName").length>0);
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract class AttributePageHandler extends PageHandler {
|
||||
// The subclass must define this
|
||||
protected String[] sAttributeNames;
|
||||
|
||||
// Our data
|
||||
private ComplexOption attributeMap = new ComplexOption();
|
||||
private int nCurrentAttribute = -1;
|
||||
|
||||
// Some methods to be implemented by subclass
|
||||
protected abstract void getControls(DialogAccess dlg, Map<String,String> attr);
|
||||
|
||||
protected abstract void setControls(DialogAccess dlg, Map<String,String> attr);
|
||||
|
||||
protected abstract void prepareControls(DialogAccess dlg, boolean bEnable);
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean handleEvent(DialogAccess dlg, String sMethod) {
|
||||
if (sMethod.equals("FormattingAttributeChange")) {
|
||||
formattingAttributeChange(dlg);
|
||||
return true;
|
||||
}
|
||||
else if (sMethod.equals("CustomAttributeChange")) {
|
||||
customAttributeChange(dlg);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
private void customAttributeChange(DialogAccess dlg) {
|
||||
prepareControls(dlg,dlg.getCheckBoxStateAsBoolean("CustomAttribute"));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -169,7 +169,6 @@ public class DialogAccess {
|
|||
}
|
||||
|
||||
public short getListBoxLineCount(String sControlName) {
|
||||
// Returns the first selected element in case of a multiselection
|
||||
XPropertySet xPropertySet = getControlProperties(sControlName);
|
||||
try {
|
||||
return ((Short) xPropertySet.getPropertyValue("LineCount")).shortValue();
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
/************************************************************************
|
||||
*
|
||||
* FilePicker.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-2010 by Henrik Just
|
||||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Version 1.2 (2010-04-12)
|
||||
*
|
||||
*/
|
||||
|
||||
package org.openoffice.da.comp.w2lcommon.helper;
|
||||
|
||||
import com.sun.star.lang.XComponent;
|
||||
import com.sun.star.ui.dialogs.ExecutableDialogResults;
|
||||
import com.sun.star.ui.dialogs.XExecutableDialog;
|
||||
import com.sun.star.ui.dialogs.XFilePicker;
|
||||
import com.sun.star.uno.UnoRuntime;
|
||||
import com.sun.star.uno.XComponentContext;
|
||||
|
||||
public class FilePicker {
|
||||
|
||||
private XComponentContext xContext;
|
||||
|
||||
/** Convenience wrapper class for the UNO file picker service
|
||||
*
|
||||
* @param xContext the UNO component context from which the file picker can be created
|
||||
*/
|
||||
public FilePicker(XComponentContext xContext) {
|
||||
this.xContext = xContext;
|
||||
}
|
||||
|
||||
/** Get a user selected path with a file picker
|
||||
*
|
||||
* @return the path or null if the dialog is canceled
|
||||
*/
|
||||
public String getPath() {
|
||||
// Create FilePicker
|
||||
Object filePicker = null;
|
||||
try {
|
||||
filePicker = xContext.getServiceManager().createInstanceWithContext("com.sun.star.ui.dialogs.FilePicker", xContext);
|
||||
}
|
||||
catch (com.sun.star.uno.Exception e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Display the FilePicker
|
||||
XFilePicker xFilePicker = (XFilePicker) UnoRuntime.queryInterface(XFilePicker.class, filePicker);
|
||||
XExecutableDialog xExecutable = (XExecutableDialog) UnoRuntime.queryInterface(XExecutableDialog.class, xFilePicker);
|
||||
|
||||
// Get the path
|
||||
String sPath = null;
|
||||
|
||||
if (xExecutable.execute() == ExecutableDialogResults.OK) {
|
||||
String[] sPathList = xFilePicker.getFiles();
|
||||
if (sPathList.length > 0) {
|
||||
sPath = sPathList[0];
|
||||
}
|
||||
}
|
||||
|
||||
// Dispose the file picker
|
||||
XComponent xComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, xFilePicker);
|
||||
xComponent.dispose();
|
||||
|
||||
return sPath;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
/************************************************************************
|
||||
*
|
||||
* OptionsDialogBase.java
|
||||
* MacroExpander.java
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
|
|
@ -20,11 +20,14 @@
|
|||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Version 1.2 (2010-03-26)
|
||||
* Version 1.2 (2010-04-09)
|
||||
*
|
||||
*/
|
||||
|
||||
package org.openoffice.da.comp.writer2xhtml;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.openoffice.da.comp.w2lcommon.filter.ConfigurationDialogBase;
|
||||
import org.openoffice.da.comp.w2lcommon.helper.DialogAccess;
|
||||
|
||||
|
@ -68,22 +71,28 @@ public class ConfigurationDialog extends ConfigurationDialogBase implements XSer
|
|||
super(xContext);
|
||||
|
||||
pageHandlers.put("General", new GeneralHandler());
|
||||
//pageHandlers.put("Template", new TemplateHandler());
|
||||
pageHandlers.put("Template", new TemplateHandler());
|
||||
pageHandlers.put("Stylesheets", new StylesheetsHandler());
|
||||
pageHandlers.put("Formatting", new FormattingHandler());
|
||||
//pageHandlers.put("Styles1", new StylesPartIHandler());
|
||||
//pageHandlers.put("Styles2", new StylesPartIIHandler());
|
||||
pageHandlers.put("Styles1", new Styles1Handler());
|
||||
pageHandlers.put("Styles2", new Styles2Handler());
|
||||
pageHandlers.put("Formatting", new FormattingHandler());
|
||||
pageHandlers.put("Content", new ContentHandler());
|
||||
}
|
||||
|
||||
// Implement remaining method from XContainerWindowEventHandler
|
||||
public String[] getSupportedMethodNames() {
|
||||
String[] sNames = { "EncodingChange" };
|
||||
String[] sNames = { "EncodingChange", // General
|
||||
"CustomTemplateChange", "LoadTemplateClick", // Template
|
||||
"UseCustomStylesheetChange", "IncludeCustomStylesheetClick", "LoadStylesheetClick", // Stylesheet
|
||||
"StyleFamilyChange", "StyleNameChange", "NewStyleClick", "DeleteStyleClick", "LoadDefaultsClick" // Styles1
|
||||
};
|
||||
return sNames;
|
||||
}
|
||||
|
||||
// the page handlers
|
||||
private final String[] sCharElements = { "span", "abbr", "acronym", "b", "big", "cite", "code", "del", "dfn", "em", "i",
|
||||
"ins", "kbd", "samp", "small", "strong", "sub", "sup", "tt", "var", "q" };
|
||||
|
||||
private class GeneralHandler extends PageHandler {
|
||||
private final String[] sEncodingValues = { "UTF-8", "UTF-16", "ISO-8859-1", "US-ASCII" };
|
||||
|
@ -134,20 +143,74 @@ public class ConfigurationDialog extends ConfigurationDialogBase implements XSer
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
private class TemplateHandler extends CustomFileHandler {
|
||||
|
||||
protected String getSuffix() {
|
||||
return "Template";
|
||||
}
|
||||
|
||||
protected String getFileName() {
|
||||
return "writer2xhtml-template.xhtml";
|
||||
}
|
||||
|
||||
protected void useCustomInner(DialogAccess dlg, boolean bEnable) {
|
||||
dlg.setControlEnabled("ContentIdLabel", bEnable);
|
||||
dlg.setControlEnabled("ContentId", bEnable);
|
||||
dlg.setControlEnabled("HeaderIdLabel", bEnable);
|
||||
dlg.setControlEnabled("HeaderId", bEnable);
|
||||
dlg.setControlEnabled("FooterIdLabel", bEnable);
|
||||
dlg.setControlEnabled("FooterId", bEnable);
|
||||
dlg.setControlEnabled("PanelIdLabel", bEnable);
|
||||
dlg.setControlEnabled("PanelId", bEnable);
|
||||
}
|
||||
|
||||
@Override protected void setControls(DialogAccess dlg) {
|
||||
super.setControls(dlg);
|
||||
String[] sCustomIds = config.getOption("template_ids").split(",");
|
||||
if (sCustomIds.length>0) { dlg.setComboBoxText("ContentId", sCustomIds[0]); }
|
||||
if (sCustomIds.length>1) { dlg.setComboBoxText("HeaderId", sCustomIds[1]); }
|
||||
if (sCustomIds.length>2) { dlg.setComboBoxText("FooterId", sCustomIds[2]); }
|
||||
if (sCustomIds.length>3) { dlg.setComboBoxText("PanelId", sCustomIds[3]); }
|
||||
}
|
||||
|
||||
@Override protected void getControls(DialogAccess dlg) {
|
||||
super.getControls(dlg);
|
||||
config.setOption("template_ids",
|
||||
dlg.getComboBoxText("ContentId").trim()+","+
|
||||
dlg.getComboBoxText("HeaderId").trim()+","+
|
||||
dlg.getComboBoxText("FooterId").trim()+","+
|
||||
dlg.getComboBoxText("PanelId").trim());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class StylesheetsHandler extends CustomFileHandler {
|
||||
|
||||
protected String getSuffix() {
|
||||
return "Stylesheet";
|
||||
}
|
||||
|
||||
protected String getFileName() {
|
||||
return "writer2xhtml-styles.css";
|
||||
}
|
||||
|
||||
protected void useCustomInner(DialogAccess dlg, boolean bEnable) {
|
||||
}
|
||||
|
||||
private class StylesheetsHandler extends PageHandler {
|
||||
|
||||
@Override protected void setControls(DialogAccess dlg) {
|
||||
dlg.setCheckBoxStateAsBoolean("UseCustomStylesheet", config.getOption("custom_stylesheet").length()>0);
|
||||
textFieldFromConfig(dlg, "CustomStylesheet", "custom_stylesheet");
|
||||
super.setControls(dlg);
|
||||
dlg.setCheckBoxStateAsBoolean("LinkCustomStylesheet", config.getOption("custom_stylesheet").length()>0);
|
||||
textFieldFromConfig(dlg, "CustomStylesheetURL", "custom_stylesheet");
|
||||
|
||||
useCustomStylesheetChange(dlg);
|
||||
includeCustomStylesheetChange(dlg);
|
||||
linkCustomStylesheetChange(dlg);
|
||||
}
|
||||
|
||||
@Override protected void getControls(DialogAccess dlg) {
|
||||
if (dlg.getCheckBoxStateAsBoolean("UseCustomStylesheet")) {
|
||||
textFieldToConfig(dlg, "CustomStylesheet", "custom_stylesheet");
|
||||
super.getControls(dlg);
|
||||
if (dlg.getCheckBoxStateAsBoolean("LinkCustomStylesheet")) {
|
||||
textFieldToConfig(dlg, "CustomStylesheetURL", "custom_stylesheet");
|
||||
}
|
||||
else {
|
||||
config.setOption("custom_stylesheet", "");
|
||||
|
@ -155,35 +218,133 @@ public class ConfigurationDialog extends ConfigurationDialogBase implements XSer
|
|||
}
|
||||
|
||||
@Override protected boolean handleEvent(DialogAccess dlg, String sMethod) {
|
||||
if (sMethod.equals("UseCustomStylesheetChange")) {
|
||||
useCustomStylesheetChange(dlg);
|
||||
if (super.handleEvent(dlg, sMethod)) {
|
||||
return true;
|
||||
}
|
||||
else if (sMethod.equals("IncludeCustomStylesheetChange")) {
|
||||
includeCustomStylesheetChange(dlg);
|
||||
return true;
|
||||
}
|
||||
else if (sMethod.equals("LoadButtonClick")) {
|
||||
loadButtonClick(dlg);
|
||||
if (sMethod.equals("LinkCustomStylesheetChange")) {
|
||||
linkCustomStylesheetChange(dlg);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void useCustomStylesheetChange(DialogAccess dlg) {
|
||||
boolean bUseCustomStylesheet = dlg.getCheckBoxStateAsBoolean("UseCustomStylesheet");
|
||||
dlg.setControlEnabled("CustomStylesheetLabel", bUseCustomStylesheet);
|
||||
dlg.setControlEnabled("CustomStylesheet", bUseCustomStylesheet);
|
||||
private void linkCustomStylesheetChange(DialogAccess dlg) {
|
||||
boolean bLinkCustomStylesheet = dlg.getCheckBoxStateAsBoolean("LinkCustomStylesheet");
|
||||
dlg.setControlEnabled("CustomStylesheetURLLabel", bLinkCustomStylesheet);
|
||||
dlg.setControlEnabled("CustomStylesheetURL", bLinkCustomStylesheet);
|
||||
}
|
||||
|
||||
private void includeCustomStylesheetChange(DialogAccess dlg) {
|
||||
dlg.setControlEnabled("IncludedCustomStylesheet", dlg.getCheckBoxStateAsBoolean("IncludeCustomStylesheet"));
|
||||
}
|
||||
|
||||
private class Styles1Handler extends StylesPageHandler {
|
||||
private final String[] sXhtmlFamilyNames = { "text", "paragraph", "list", "frame" };
|
||||
private final String[] sXhtmlOOoFamilyNames = { "CharacterStyles", "ParagraphStyles", "NumberingStyles", "FrameStyles" };
|
||||
|
||||
private final String[] sParElements = { "p", "h1", "h2", "h3", "h4", "h5", "h6", "address", "dd", "dt", "pre" };
|
||||
private final String[] sParBlockElements = { "div", "blockquote", "dl" };
|
||||
private final String[] sEmpty = { };
|
||||
|
||||
private String[][] sElements = new String[4][];
|
||||
private String[][] sBlockElements = new String[4][];
|
||||
|
||||
protected Styles1Handler() {
|
||||
super(4);
|
||||
sFamilyNames = sXhtmlFamilyNames;
|
||||
sOOoFamilyNames = sXhtmlOOoFamilyNames;
|
||||
|
||||
sElements[0] = sCharElements;
|
||||
sElements[1] = sParElements;
|
||||
sElements[2] = sEmpty;
|
||||
sElements[3] = sEmpty;
|
||||
|
||||
sBlockElements[0] = sEmpty;
|
||||
sBlockElements[1] = sParBlockElements;
|
||||
sBlockElements[2] = sEmpty;
|
||||
sBlockElements[3] = sEmpty;
|
||||
}
|
||||
|
||||
private void loadButtonClick(DialogAccess dlg) {
|
||||
// TODO
|
||||
protected String getDefaultConfigName() {
|
||||
return "cleanxhtml.xml";
|
||||
}
|
||||
|
||||
protected void setControls(DialogAccess dlg, Map<String,String> attr) {
|
||||
if (!attr.containsKey("element")) { attr.put("element", ""); }
|
||||
if (!attr.containsKey("css")) { attr.put("css", ""); }
|
||||
dlg.setComboBoxText("Element", attr.get("element"));
|
||||
dlg.setTextFieldText("Css", none2empty(attr.get("css")));
|
||||
if (nCurrentFamily==1) {
|
||||
if (!attr.containsKey("block-element")) { attr.put("block-element", ""); }
|
||||
if (!attr.containsKey("block-css")) { attr.put("block-css", ""); }
|
||||
dlg.setComboBoxText("BlockElement", attr.get("block-element"));
|
||||
dlg.setTextFieldText("BlockCss", none2empty(attr.get("block-css")));
|
||||
}
|
||||
else {
|
||||
dlg.setComboBoxText("BlockElement", "");
|
||||
dlg.setTextFieldText("BlockCss", "");
|
||||
}
|
||||
}
|
||||
|
||||
protected void getControls(DialogAccess dlg, Map<String,String> attr) {
|
||||
attr.put("element", dlg.getComboBoxText("Element"));
|
||||
attr.put("css", empty2none(dlg.getTextFieldText("Css")));
|
||||
if (nCurrentFamily==1) {
|
||||
attr.put("block-element", dlg.getComboBoxText("BlockElement"));
|
||||
attr.put("block-css", empty2none(dlg.getTextFieldText("BlockCss")));
|
||||
}
|
||||
}
|
||||
|
||||
protected void clearControls(DialogAccess dlg) {
|
||||
dlg.setComboBoxText("Element", "");
|
||||
dlg.setTextFieldText("Css", "");
|
||||
dlg.setComboBoxText("BlockElement", "");
|
||||
dlg.setTextFieldText("BlockCss", "");
|
||||
}
|
||||
|
||||
protected void prepareControls(DialogAccess dlg) {
|
||||
dlg.setListBoxStringItemList("Element", sElements[nCurrentFamily]);
|
||||
dlg.setListBoxStringItemList("BlockElement", sBlockElements[nCurrentFamily]);
|
||||
dlg.setControlEnabled("Element", nCurrentFamily<=1);
|
||||
dlg.setControlEnabled("BlockElement", nCurrentFamily==1);
|
||||
dlg.setControlEnabled("BlockCss", nCurrentFamily==1);
|
||||
}
|
||||
}
|
||||
|
||||
private class Styles2Handler extends AttributePageHandler {
|
||||
private String[] sXhtmlAttributeNames = { "bold", "italics", "fixed", "superscript", "subscript", "underline", "overstrike" };
|
||||
|
||||
public Styles2Handler() {
|
||||
sAttributeNames = sXhtmlAttributeNames;
|
||||
}
|
||||
|
||||
@Override public void setControls(DialogAccess dlg) {
|
||||
super.setControls(dlg);
|
||||
textFieldFromConfig(dlg,"TabstopStyle","tabstop_style");
|
||||
}
|
||||
|
||||
@Override public void getControls(DialogAccess dlg) {
|
||||
super.getControls(dlg);
|
||||
textFieldToConfig(dlg,"TabstopStyle","tabstop_style");
|
||||
}
|
||||
|
||||
protected void setControls(DialogAccess dlg, Map<String,String> attr) {
|
||||
if (!attr.containsKey("element")) { attr.put("element", ""); }
|
||||
if (!attr.containsKey("css")) { attr.put("css", ""); }
|
||||
dlg.setListBoxStringItemList("Element", sCharElements);
|
||||
dlg.setComboBoxText("Element", attr.get("element"));
|
||||
dlg.setTextFieldText("Css", none2empty(attr.get("css")));
|
||||
}
|
||||
|
||||
protected void getControls(DialogAccess dlg, Map<String,String> attr) {
|
||||
attr.put("element", dlg.getComboBoxText("Element"));
|
||||
attr.put("css", empty2none(dlg.getTextFieldText("Css")));
|
||||
}
|
||||
|
||||
protected void prepareControls(DialogAccess dlg, boolean bEnable) {
|
||||
dlg.setControlEnabled("ElementLabel", bEnable);
|
||||
dlg.setControlEnabled("Element", bEnable);
|
||||
dlg.setControlEnabled("CssLabel", bEnable);
|
||||
dlg.setControlEnabled("Css", bEnable);
|
||||
}
|
||||
}
|
||||
|
||||
private class FormattingHandler extends PageHandler {
|
||||
|
@ -203,8 +364,9 @@ public class ConfigurationDialog extends ConfigurationDialogBase implements XSer
|
|||
|
||||
checkBoxFromConfig(dlg, "IgnoreTableDimensions", "ignore_table_dimensions");
|
||||
checkBoxFromConfig(dlg, "UseListHack", "use_list_hack");
|
||||
checkBoxFromConfig(dlg, "ConvertToPx", "convert_to_px");
|
||||
checkBoxFromConfig(dlg, "SeparateStylesheet", "separate_stylesheet");
|
||||
//TODO: These have been postponed
|
||||
//checkBoxFromConfig(dlg, "ConvertToPx", "convert_to_px");
|
||||
//checkBoxFromConfig(dlg, "SeparateStylesheet", "separate_stylesheet");
|
||||
}
|
||||
|
||||
@Override protected void getControls(DialogAccess dlg) {
|
||||
|
@ -216,8 +378,9 @@ public class ConfigurationDialog extends ConfigurationDialogBase implements XSer
|
|||
|
||||
checkBoxToConfig(dlg, "IgnoreTableDimensions", "ignore_table_dimensions");
|
||||
checkBoxToConfig(dlg, "UseListHack", "use_list_hack");
|
||||
checkBoxToConfig(dlg, "ConvertToPx", "convert_to_px");
|
||||
checkBoxToConfig(dlg, "SeparateStylesheet", "separate_stylesheet");
|
||||
//TODO: These have been postponed
|
||||
//checkBoxToConfig(dlg, "ConvertToPx", "convert_to_px");
|
||||
//checkBoxToConfig(dlg, "SeparateStylesheet", "separate_stylesheet");
|
||||
}
|
||||
|
||||
@Override protected boolean handleEvent(DialogAccess dlg, String sMethod) {
|
||||
|
@ -242,6 +405,15 @@ public class ConfigurationDialog extends ConfigurationDialogBase implements XSer
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
private String none2empty(String s) {
|
||||
return s.equals("(none)") ? "" : s;
|
||||
}
|
||||
|
||||
private String empty2none(String s) {
|
||||
String t = s.trim();
|
||||
return t.length()==0 ? "(none)" : t;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -16,11 +16,11 @@
|
|||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*
|
||||
* Copyright: 2002-2008 by Henrik Just
|
||||
* Copyright: 2002-2010 by Henrik Just
|
||||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Version 1.0 (2008-11-16)
|
||||
* Version 1.2 (2010-04-11)
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -113,6 +113,8 @@ public class XhtmlOptionsDialog extends OptionsDialogBase {
|
|||
"http://www.w3.org/StyleSheets/Core/"+sCoreStyles[nConfig-1]);
|
||||
break;
|
||||
case 9: helper.put("ConfigURL","$(user)/writer2xhtml.xml");
|
||||
helper.put("TemplateURL", "$(user)/writer2xhtml-template.xhtml");
|
||||
//helper.put("StyleSheetURL", "$(user)/writer2xhtml-style.css");
|
||||
helper.put("AutoCreate","true");
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Version 1.2 (2010-03-05)
|
||||
* Version 1.2 (2010-04-12)
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -29,6 +29,7 @@ package org.openoffice.da.comp.writer4latex;
|
|||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Vector;
|
||||
|
||||
import com.sun.star.awt.XControl;
|
||||
|
@ -52,6 +53,7 @@ import com.sun.star.uno.XComponentContext;
|
|||
import com.sun.star.lib.uno.helper.WeakBase;
|
||||
|
||||
import org.openoffice.da.comp.w2lcommon.helper.DialogAccess;
|
||||
import org.openoffice.da.comp.w2lcommon.helper.FilePicker;
|
||||
|
||||
/** This class provides a uno component which implements the configuration
|
||||
* of Writer4LaTeX
|
||||
|
@ -61,6 +63,7 @@ public final class ConfigurationDialog
|
|||
implements XServiceInfo, XContainerWindowEventHandler {
|
||||
|
||||
private XComponentContext xContext;
|
||||
private FilePicker filePicker;
|
||||
|
||||
private ExternalApps externalApps;
|
||||
|
||||
|
@ -76,6 +79,7 @@ public final class ConfigurationDialog
|
|||
public ConfigurationDialog(XComponentContext xContext) {
|
||||
this.xContext = xContext;
|
||||
externalApps = new ExternalApps(xContext);
|
||||
filePicker = new FilePicker(xContext);
|
||||
}
|
||||
|
||||
// Implement XContainerWindowEventHandler
|
||||
|
@ -161,42 +165,18 @@ public final class ConfigurationDialog
|
|||
}
|
||||
|
||||
private boolean browseForExecutable(XWindow xWindow) {
|
||||
XComponent xComponent = null;
|
||||
try {
|
||||
// Create FilePicker
|
||||
Object filePicker = xContext.getServiceManager()
|
||||
.createInstanceWithContext("com.sun.star.ui.dialogs.FilePicker", xContext);
|
||||
XFilePicker xFilePicker = (XFilePicker)
|
||||
UnoRuntime.queryInterface(XFilePicker.class, filePicker);
|
||||
xComponent = (XComponent)
|
||||
UnoRuntime.queryInterface(XComponent.class, xFilePicker);
|
||||
|
||||
// Display the FilePicker
|
||||
XExecutableDialog xExecutable = (XExecutableDialog)
|
||||
UnoRuntime.queryInterface(XExecutableDialog.class, xFilePicker);
|
||||
|
||||
// Get the path
|
||||
if (xExecutable.execute() == ExecutableDialogResults.OK) {
|
||||
String[] sPathList = xFilePicker.getFiles();
|
||||
if (sPathList.length > 0) {
|
||||
setComboBoxText(xWindow, "Executable", new File(new URI(sPathList[0])).getCanonicalPath());
|
||||
updateApplication(xWindow);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (com.sun.star.uno.Exception e) {
|
||||
}
|
||||
catch (java.net.URISyntaxException e) {
|
||||
}
|
||||
catch (java.io.IOException e) {
|
||||
}
|
||||
finally{
|
||||
// Always dispose the FilePicker component
|
||||
if (xComponent!=null) {
|
||||
xComponent.dispose();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
String sPath = filePicker.getPath();
|
||||
if (sPath!=null) {
|
||||
try {
|
||||
setComboBoxText(xWindow, "Executable", new File(new URI(sPath)).getCanonicalPath());
|
||||
}
|
||||
catch (IOException e) {
|
||||
}
|
||||
catch (URISyntaxException e) {
|
||||
}
|
||||
updateApplication(xWindow);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean updateApplication(XWindow xWindow) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue