From 861951daa646b20ccae10671ffa6e3723ef36703 Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson Date: Sun, 27 Dec 2015 12:55:23 +0100 Subject: [PATCH] Solved #593 and cleaned up the OO-code a bit --- CHANGELOG.md | 1 + .../java/net/sf/jabref/JabRefPreferences.java | 15 + .../sf/jabref/openoffice/AutoDetectPaths.java | 73 +-- .../net/sf/jabref/openoffice/BstWrapper.java | 7 +- .../sf/jabref/openoffice/CitationManager.java | 32 +- .../sf/jabref/openoffice/ComparableMark.java | 6 +- .../net/sf/jabref/openoffice/OOBibBase.java | 49 +- .../net/sf/jabref/openoffice/OOBibStyle.java | 34 +- .../java/net/sf/jabref/openoffice/OOUtil.java | 32 +- .../sf/jabref/openoffice/OpenOfficePanel.java | 467 +++++++++--------- .../jabref/openoffice/StyleSelectDialog.java | 48 +- 11 files changed, 363 insertions(+), 401 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ee93f08649d..71aa151d152 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ to [sourceforge feature requests](https://sourceforge.net/p/jabref/features/) by ### Fixed - Changes in customized entry types are now directly reflected in the table when clicking "Apply" or "OK" +- Reference list generation works for OpenOffice/LibreOffice again, fixes #593 ### Removed diff --git a/src/main/java/net/sf/jabref/JabRefPreferences.java b/src/main/java/net/sf/jabref/JabRefPreferences.java index 8b99913e338..f67dc4cf64d 100644 --- a/src/main/java/net/sf/jabref/JabRefPreferences.java +++ b/src/main/java/net/sf/jabref/JabRefPreferences.java @@ -313,6 +313,21 @@ public class JabRefPreferences { public static final String PUSH_TO_APPLICATION = "pushToApplication"; + // OpenOffice/LibreOffice preferences + public static final String OO_EXECUTABLE_PATH = "ooExecutablePath"; + public static final String OO_PATH = "ooPath"; + public static final String OO_JARS_PATH = "ooJarsPath"; + public static final String SHOW_OO_PANEL = "showOOPanel"; + public static final String SYNC_OO_WHEN_CITING = "syncOOWhenCiting"; + public static final String USE_ALL_OPEN_BASES = "useAllOpenBases"; + public static final String OO_IN_PAR_CITATION = "ooInParCitation"; + public static final String OO_BIBLIOGRAPHY_STYLE_FILE = "ooBibliographyStyleFile"; + public static final String OO_USE_DEFAULT_AUTHORYEAR_STYLE = "ooUseDefaultAuthoryearStyle"; + public static final String OO_USE_DEFAULT_NUMERICAL_STYLE = "ooUseDefaultNumericalStyle"; + public static final String OO_CHOOSE_STYLE_DIRECTLY = "ooChooseStyleDirectly"; + public static final String OO_DIRECT_FILE = "ooDirectFile"; + public static final String OO_STYLE_DIRECTORY = "ooStyleDirectory"; + //non-default preferences private static final String CUSTOM_TYPE_NAME = "customTypeName_"; private static final String CUSTOM_TYPE_REQ = "customTypeReq_"; diff --git a/src/main/java/net/sf/jabref/openoffice/AutoDetectPaths.java b/src/main/java/net/sf/jabref/openoffice/AutoDetectPaths.java index e31431141ea..411aa341d12 100644 --- a/src/main/java/net/sf/jabref/openoffice/AutoDetectPaths.java +++ b/src/main/java/net/sf/jabref/openoffice/AutoDetectPaths.java @@ -16,6 +16,7 @@ package net.sf.jabref.openoffice; import net.sf.jabref.Globals; +import net.sf.jabref.JabRefPreferences; import net.sf.jabref.gui.worker.AbstractWorker; import javax.swing.*; @@ -66,10 +67,6 @@ public void run() { foundPaths = autoDetectPaths(); } - public boolean getResult() { - return foundPaths; - } - public boolean cancelled() { return fileSearchCancelled; } @@ -88,11 +85,11 @@ public void update() { private boolean autoDetectPaths() { if (OS.WINDOWS) { - List progFiles = AutoDetectPaths.findProgramFilesDir(); - File sOffice = null; + List progFiles = findProgramFilesDir(); if (fileSearchCancelled) { return false; } + File sOffice = null; List sofficeFiles = new ArrayList<>(); for (File dir : progFiles) { sOffice = findFileDir(dir, "soffice.exe"); @@ -156,18 +153,13 @@ public String getDescription() { } else { sOffice = sofficeFiles.get(0); } - Globals.prefs.put("ooExecutablePath", new File(sOffice, "soffice.exe").getPath()); - File unoil = findFileDir(sOffice.getParentFile(), "unoil.jar"); - if (fileSearchCancelled) { - return false; - } + Globals.prefs.put(JabRefPreferences.OO_EXECUTABLE_PATH, new File(sOffice, "soffice.exe").getPath()); File jurt = findFileDir(sOffice.getParentFile(), "jurt.jar"); if (fileSearchCancelled) { return false; } - if ((unoil != null) && (jurt != null)) { - Globals.prefs.put("ooUnoilPath", unoil.getPath()); - Globals.prefs.put("ooJurtPath", jurt.getPath()); + if (jurt != null) { + Globals.prefs.put(JabRefPreferences.OO_JARS_PATH, jurt.getPath()); return true; } else { return false; @@ -181,34 +173,22 @@ else if (OS.OS_X) { for (File file : files) { if (file.isDirectory() && "OpenOffice.org.app".equals(file.getName())) { rootDir = file; - //System.out.println("Setting starting dir to: "+file.getPath()); break; } } } - //System.out.println("Searching for soffice.bin"); File sOffice = findFileDir(rootDir, "soffice.bin"); - //System.out.println("Found: "+(sOffice != null ? sOffice.getPath() : "-")); if (fileSearchCancelled) { return false; } if (sOffice != null) { - Globals.prefs.put("ooExecutablePath", new File(sOffice, "soffice.bin").getPath()); - //System.out.println("Searching for unoil.jar"); - File unoil = findFileDir(rootDir, "unoil.jar"); - //System.out.println("Found: "+(unoil != null ? unoil.getPath(): "-")); - if (fileSearchCancelled) { - return false; - } - //System.out.println("Searching for jurt.jar"); + Globals.prefs.put(JabRefPreferences.OO_EXECUTABLE_PATH, new File(sOffice, "soffice.bin").getPath()); File jurt = findFileDir(rootDir, "jurt.jar"); - //System.out.println("Found: "+(jurt != null ? jurt.getPath(): "-")); if (fileSearchCancelled) { return false; } - if ((unoil != null) && (jurt != null)) { - Globals.prefs.put("ooUnoilPath", unoil.getPath()); - Globals.prefs.put("ooJurtPath", jurt.getPath()); + if (jurt != null) { + Globals.prefs.put(JabRefPreferences.OO_JARS_PATH, jurt.getPath()); return true; } else { return false; @@ -220,7 +200,7 @@ else if (OS.OS_X) { else { // Linux: String usrRoot = "/usr/lib"; - File inUsr = findFileDir(new File("/usr/lib"), "soffice"); + File inUsr = findFileDir(new File(usrRoot), "soffice"); if (fileSearchCancelled) { return false; } @@ -242,12 +222,10 @@ else if (OS.OS_X) { return setupPreferencesForOO(usrRoot, inUsr); } else if ((inOpt != null) && (inUsr == null)) { - Globals.prefs.put("ooExecutablePath", new File(inOpt, "soffice.bin").getPath()); - File unoil = findFileDir(new File("/opt"), "unoil.jar"); + Globals.prefs.put(JabRefPreferences.OO_EXECUTABLE_PATH, new File(inOpt, "soffice.bin").getPath()); File jurt = findFileDir(new File("/opt"), "jurt.jar"); - if ((unoil != null) && (jurt != null)) { - Globals.prefs.put("ooUnoilPath", unoil.getPath()); - Globals.prefs.put("ooJurtPath", jurt.getPath()); + if (jurt != null) { + Globals.prefs.put(JabRefPreferences.OO_JARS_PATH, jurt.getPath()); return true; } else { return false; @@ -288,18 +266,13 @@ else if (inOpt != null) { // Found both } private boolean setupPreferencesForOO(String usrRoot, File inUsr) { - Globals.prefs.put("ooExecutablePath", new File(inUsr, "soffice.bin").getPath()); - File unoil = findFileDir(new File(usrRoot), "unoil.jar"); - if (fileSearchCancelled) { - return false; - } + Globals.prefs.put(JabRefPreferences.OO_EXECUTABLE_PATH, new File(inUsr, "soffice.bin").getPath()); File jurt = findFileDir(new File(usrRoot), "jurt.jar"); if (fileSearchCancelled) { return false; } - if ((unoil != null) && (jurt != null)) { - Globals.prefs.put("ooUnoilPath", unoil.getPath()); - Globals.prefs.put("ooJurtPath", jurt.getPath()); + if (jurt != null) { + Globals.prefs.put(JabRefPreferences.OO_JARS_PATH, jurt.getPath()); return true; } else { return false; @@ -312,7 +285,7 @@ private boolean setupPreferencesForOO(String usrRoot, File inUsr) { * Since we are not including a library for Windows integration, this method can't * find the Program files dir in localized Windows installations. */ - private static java.util.List findProgramFilesDir() { + private static List findProgramFilesDir() { List sourceList = new ArrayList<>(); List dirList = new ArrayList<>(); @@ -340,11 +313,10 @@ private static java.util.List findProgramFilesDir() { private static boolean checkAutoDetectedPaths() { - if (Globals.prefs.hasKey("ooUnoilPath") && Globals.prefs.hasKey("ooJurtPath") - && Globals.prefs.hasKey("ooExecutablePath")) { - return new File(Globals.prefs.get("ooUnoilPath"), "unoil.jar").exists() - && new File(Globals.prefs.get("ooJurtPath"), "jurt.jar").exists() - && new File(Globals.prefs.get("ooExecutablePath")).exists(); + if (Globals.prefs.hasKey(JabRefPreferences.OO_JARS_PATH) + && Globals.prefs.hasKey(JabRefPreferences.OO_EXECUTABLE_PATH)) { + return new File(Globals.prefs.get(JabRefPreferences.OO_JARS_PATH), "jurt.jar").exists() + && new File(Globals.prefs.get(JabRefPreferences.OO_EXECUTABLE_PATH)).exists(); } else { return false; } @@ -384,7 +356,6 @@ private File findFileDir(File startDir, String filename) { public JDialog showProgressDialog(JDialog progressParent, String title, String message, boolean includeCancelButton) { fileSearchCancelled = false; - final JDialog progressDialog; JProgressBar bar = new JProgressBar(SwingConstants.HORIZONTAL); JButton cancel = new JButton(Localization.lang("Cancel")); cancel.addActionListener(new ActionListener() { @@ -395,7 +366,7 @@ public void actionPerformed(ActionEvent event) { ((JButton) event.getSource()).setEnabled(false); } }); - progressDialog = new JDialog(progressParent, title, false); + final JDialog progressDialog = new JDialog(progressParent, title, false); bar.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); bar.setIndeterminate(true); if (includeCancelButton) { diff --git a/src/main/java/net/sf/jabref/openoffice/BstWrapper.java b/src/main/java/net/sf/jabref/openoffice/BstWrapper.java index d0b6e9e5853..a0c7fa71b8a 100644 --- a/src/main/java/net/sf/jabref/openoffice/BstWrapper.java +++ b/src/main/java/net/sf/jabref/openoffice/BstWrapper.java @@ -44,6 +44,9 @@ class BstWrapper { private static final Log LOGGER = LogFactory.getLog(BstWrapper.class); + private static final Pattern BIB_ITEM_TAG = Pattern.compile("\\\\[a-zA-Z]*item\\{.*\\}"); + + public BstWrapper() { } @@ -74,13 +77,11 @@ public Map processEntries(Collection entries, BibDatab } - private static final Pattern bibitemTag = Pattern.compile("\\\\[a-zA-Z]*item\\{.*\\}"); - private Map parseResult(String result) { Map map = new HashMap<>(); // Look through for instances of \bibitem : - Matcher m = BstWrapper.bibitemTag.matcher(result); + Matcher m = BstWrapper.BIB_ITEM_TAG.matcher(result); ArrayList indices = new ArrayList<>(); ArrayList endIndices = new ArrayList<>(); ArrayList keys = new ArrayList<>(); diff --git a/src/main/java/net/sf/jabref/openoffice/CitationManager.java b/src/main/java/net/sf/jabref/openoffice/CitationManager.java index 9d12556ba7a..616dc4f2bb2 100644 --- a/src/main/java/net/sf/jabref/openoffice/CitationManager.java +++ b/src/main/java/net/sf/jabref/openoffice/CitationManager.java @@ -129,10 +129,10 @@ static class CitEntry implements Comparable { final String refMarkName; String pageInfo; - final String keyString; + private final String keyString; final String context; - final String origPageInfo; - final List keys; + private final String origPageInfo; + private final List keys; public CitEntry(String refMarkName, List keys, String context, String pageInfo) { @@ -156,10 +156,10 @@ public boolean pageInfoChanged() { || ((pageInfo == null) && (origPageInfo != null))) { return true; } - if (pageInfo != null) { - return pageInfo.compareTo(origPageInfo) != 0; - } else { + if (pageInfo == null) { return false; + } else { + return pageInfo.compareTo(origPageInfo) != 0; } } @@ -194,7 +194,7 @@ public Object getColumnValue(CitEntry citEntry, int i) { case 0: return citEntry.context; default: - return citEntry.pageInfo != null ? citEntry.pageInfo : ""; + return citEntry.pageInfo == null ? "" : citEntry.pageInfo; } } } @@ -217,12 +217,12 @@ public void mouseClicked(MouseEvent e) { class SingleCitDialog { - final JDialog singleCiteDialog; - final JTextField pageInfo = new JTextField(20); - final JLabel title; - final JButton okButton = new JButton(Localization.lang("OK")); - final JButton cancelButton = new JButton(Localization.lang("Cancel")); - final CitEntry _entry; + private final JDialog singleCiteDialog; + private final JTextField pageInfo = new JTextField(20); + private final JLabel title; + private final JButton okButton = new JButton(Localization.lang("OK")); + private final JButton cancelButton = new JButton(Localization.lang("Cancel")); + private final CitEntry _entry; public SingleCitDialog(CitEntry entry) { @@ -253,10 +253,10 @@ public SingleCitDialog(CitEntry entry) { @Override public void actionPerformed(ActionEvent actionEvent) { - if (!pageInfo.getText().trim().isEmpty()) { - _entry.pageInfo = pageInfo.getText().trim(); - } else { + if (pageInfo.getText().trim().isEmpty()) { _entry.pageInfo = null; + } else { + _entry.pageInfo = pageInfo.getText().trim(); } tableModel.fireTableDataChanged(); singleCiteDialog.dispose(); diff --git a/src/main/java/net/sf/jabref/openoffice/ComparableMark.java b/src/main/java/net/sf/jabref/openoffice/ComparableMark.java index 50555c67ef8..b273163e483 100644 --- a/src/main/java/net/sf/jabref/openoffice/ComparableMark.java +++ b/src/main/java/net/sf/jabref/openoffice/ComparableMark.java @@ -33,10 +33,10 @@ public ComparableMark(String name, Point position) { @Override public int compareTo(ComparableMark other) { - if (position.Y != other.position.Y) { - return position.Y - other.position.Y; - } else { + if (position.Y == other.position.Y) { return position.X - other.position.X; + } else { + return position.Y - other.position.Y; } } diff --git a/src/main/java/net/sf/jabref/openoffice/OOBibBase.java b/src/main/java/net/sf/jabref/openoffice/OOBibBase.java index 9418a300728..2e9210bce57 100644 --- a/src/main/java/net/sf/jabref/openoffice/OOBibBase.java +++ b/src/main/java/net/sf/jabref/openoffice/OOBibBase.java @@ -62,17 +62,10 @@ class OOBibBase { private static final String BIB_CITATION = "JR_cite"; private final Pattern citePattern = Pattern.compile(OOBibBase.BIB_CITATION + "\\d*_(\\d*)_(.*)"); - private static final int - AUTHORYEAR_PAR = 1; + private static final int AUTHORYEAR_PAR = 1; private static final int AUTHORYEAR_INTEXT = 2; private static final int INVISIBLE_CIT = 3; - static final String DEFAULT_CONNECTION_STRING = "uno:socket,host=localhost,port=2002;urp;StarOffice.ServiceManager"; - final String[] BIB_TYPES = new String[] {"ARTICLE", "BOOK", "BOOKLET", "CONFERENCE", - "INBOOK", "INCOLLECTION", "INPROCEEDINGS", "JOURNAL", "MANUAL", "MASTERTHESIS", - "MISC", "PHDTHESIS", "PROCEEDINGS", "TECHREPORT", "UNPUBLISHED", "EMAIL", "WWW", - "CUSTOM1", "CUSTOM2", "CUSTOM3", "CUSTOM4", "CUSTOM5"}; - private XMultiServiceFactory mxDocFactory; private XTextDocument mxDoc; private XText text; @@ -87,7 +80,7 @@ class OOBibBase { private final AuthorYearTitleComparator entryComparator = new AuthorYearTitleComparator(); private final YearAuthorTitleComparator yearAuthorTitleComparator = new YearAuthorTitleComparator(); - private final HashMap uniquefiers = new HashMap<>(); + private final Map uniquefiers = new HashMap<>(); private String[] sortedReferenceMarks; @@ -138,7 +131,7 @@ else if (ls.size() > 1) { XComponent.class, selected); mxDoc = selected; - com.sun.star.text.XDocumentIndexesSupplier indexesSupp = UnoRuntime.queryInterface( + XDocumentIndexesSupplier indexesSupp = UnoRuntime.queryInterface( XDocumentIndexesSupplier.class, xCurrentComponent); XModel xModel = UnoRuntime.queryInterface(XModel.class, xCurrentComponent); @@ -305,9 +298,7 @@ public void insertEntry(BibEntry[] entries, BibDatabase database, setCustomProperty(bName, pageInfo); } - String citeText = style.isNumberEntries() ? "-" : style.getCitationMarker(entries, database, inParenthesis, null, null); - //System.out.println(text+" / "+xViewCursor.getText()); xViewCursor.getText().insertString(xViewCursor, " ", false); if (style.isFormatCitations()) { XPropertySet xCursorProps = UnoRuntime.queryInterface( @@ -325,6 +316,8 @@ public void insertEntry(BibEntry[] entries, BibDatabase database, } } xViewCursor.goLeft((short) 1, false); + String citeText = style.isNumberEntries() ? "-" : style.getCitationMarker(entries, database, inParenthesis, + null, null); insertReferenceMark(bName, citeText, xViewCursor, withText, style); //xViewCursor.collapseToEnd(); @@ -457,7 +450,7 @@ else if (style.isNumberEntries()) { if (m.find()) { String typeStr = m.group(1); int type = Integer.parseInt(typeStr); - types[i] = type; // Remember the type in case we need to uniqiefy. + types[i] = type; // Remember the type in case we need to uniquefy. String[] keys = m.group(2).split(","); bibtexKeys[i] = keys; BibEntry[] cEntries = new BibEntry[keys.length]; @@ -855,10 +848,10 @@ private String getUniqueReferenceMarkName(String bibtexKey, int type) { return name; } - private LinkedHashMap findCitedEntries + private Map findCitedEntries (List databases, List keys, - HashMap linkSourceBase) { - LinkedHashMap entries = new LinkedHashMap<>(); + Map linkSourceBase) { + Map entries = new LinkedHashMap<>(); for (String key : keys) { boolean found = false; for (BibDatabase database : databases) { @@ -878,7 +871,7 @@ private String getUniqueReferenceMarkName(String bibtexKey, int type) { return entries; } - private List findCitedKeys() throws com.sun.star.container.NoSuchElementException, WrappedTargetException { + private List findCitedKeys() throws NoSuchElementException, WrappedTargetException { XReferenceMarksSupplier supplier = UnoRuntime.queryInterface( XReferenceMarksSupplier.class, xCurrentComponent); @@ -901,14 +894,12 @@ private List findCitedKeys() throws com.sun.star.container.NoSuchElement return keys; } - private LinkedHashMap getSortedEntriesFromSortedRefMarks - (String[] names, - Map entries, - HashMap linkSourceBase) + private Map getSortedEntriesFromSortedRefMarks(String[] names, + Map entries, Map linkSourceBase) throws BibtexEntryNotFoundException { - LinkedHashMap newList = new LinkedHashMap<>(); - HashMap adaptedEntries = new HashMap<>(); + Map newList = new LinkedHashMap<>(); + Map adaptedEntries = new HashMap<>(); for (String name : names) { Matcher m = citePattern.matcher(name); if (m.find()) { @@ -1058,7 +1049,7 @@ private void insertFullReferenceAtCursor(XTextCursor cursor, Map { private Layout defaultBibLayout; // reference layout mapped from entry type number: - private final HashMap bibLayout = new HashMap<>(); + private final Map bibLayout = new HashMap<>(); - private final HashMap properties = new HashMap<>(); - private final HashMap citProperties = new HashMap<>(); + private final Map properties = new HashMap<>(); + private final Map citProperties = new HashMap<>(); private final Pattern numPattern = Pattern.compile("-?\\d+"); @@ -186,10 +186,10 @@ private void reload() throws Exception { * @return true if the file has not been modified, false otherwise. */ private boolean isUpToDate() { - if (styleFile != null) { - return styleFile.lastModified() == OOBibStyle.styleFileModificationTime; - } else { + if (styleFile == null) { return true; + } else { + return styleFile.lastModified() == OOBibStyle.styleFileModificationTime; } } @@ -277,7 +277,7 @@ public boolean isValid() { * @throws IOException */ private void handleStructureLine(String line) { - int index = line.indexOf("="); + int index = line.indexOf('='); if ((index > 0) && (index < (line.length() - 1))) { String formatString = line.substring(index + 1); //System.out.println("'"+line.substring(0, index)+"' : '"+formatString+"'"); @@ -308,8 +308,8 @@ private void handleStructureLine(String line) { * @param line The line containing the formatter names. * @throws IOException */ - private void handlePropertiesLine(String line, HashMap map) { - int index = line.indexOf("="); + private void handlePropertiesLine(String line, Map map) { + int index = line.indexOf('='); if ((index > 0) && (index <= (line.length() - 1))) { String propertyName = line.substring(0, index).trim(); String value = line.substring(index + 1); @@ -342,10 +342,10 @@ private void handleJournalsLine(String line) { public Layout getReferenceFormat(String type) { Layout l = bibLayout.get(type.toLowerCase()); - if (l != null) { - return l; - } else { + if (l == null) { return defaultBibLayout; + } else { + return l; } } @@ -618,7 +618,7 @@ private String getAuthorYearParenthesisMarker(BibEntry[] entries, BibDatabase da StringBuffer sb = new StringBuffer(startBrace); for (int j = 0; j < entries.length; j++) { - int unlimA = unlimAuthors != null ? unlimAuthors[j] : -1; + int unlimA = unlimAuthors == null ? -1 : unlimAuthors[j]; int maxAuthors = unlimA > 0 ? unlimA : maxA; BibEntry entry = entries[j]; @@ -690,7 +690,7 @@ private String getAuthorYearInTextMarker(BibEntry[] entries, BibDatabase databas StringBuffer sb = new StringBuffer(); for (int i = 0; i < entries.length; i++) { - int unlimA = unlimAuthors != null ? unlimAuthors[i] : -1; + int unlimA = unlimAuthors == null ? -1 : unlimAuthors[i]; int maxAuthors = unlimA > 0 ? unlimA : maxA; // Check if this entry has been nulled due to grouping with the previous entry(ies): @@ -898,10 +898,10 @@ public int compareTo(OOBibStyle other) { @Override public boolean equals(Object o) { - if (o != null) { - return styleFile.equals(((OOBibStyle) o).styleFile); - } else { + if (o == null) { return false; + } else { + return styleFile.equals(((OOBibStyle) o).styleFile); } } diff --git a/src/main/java/net/sf/jabref/openoffice/OOUtil.java b/src/main/java/net/sf/jabref/openoffice/OOUtil.java index f3f17878567..d7eff939f6f 100644 --- a/src/main/java/net/sf/jabref/openoffice/OOUtil.java +++ b/src/main/java/net/sf/jabref/openoffice/OOUtil.java @@ -45,9 +45,12 @@ */ class OOUtil { - private static final Pattern htmlTag = Pattern.compile(""); + private static final Pattern HTML_TAG = Pattern.compile(""); + + static final OOPreFormatter POSTFORMATTER = new OOPreFormatter(); + + private static final String UNIQUEFIER_FIELD = "uniq"; - static final OOPreFormatter postformatter = new OOPreFormatter(); /** @@ -65,19 +68,26 @@ public static void insertFullReferenceAtCurrentLocation(XText text, XTextCursor Layout layout, String parStyle, BibEntry entry, BibDatabase database, String uniquefier) throws Exception { - final String UNIQUEFIER_FIELD = "uniq"; - // Backup the value of the uniq field, just in case the entry already has it: String oldUniqVal = entry.getField(UNIQUEFIER_FIELD); + // Set the uniq field with the supplied uniquefier: - entry.setField(UNIQUEFIER_FIELD, uniquefier); + if (uniquefier == null) { + entry.clearField(UNIQUEFIER_FIELD); + } else { + entry.setField(UNIQUEFIER_FIELD, uniquefier); + } // Do the layout for this entry: String lText = layout.doLayout(entry, database); // Afterwards, reset the old value: - entry.setField(UNIQUEFIER_FIELD, oldUniqVal); + if (oldUniqVal == null) { + entry.clearField(UNIQUEFIER_FIELD); + } else { + entry.setField(UNIQUEFIER_FIELD, oldUniqVal); + } // Insert the formatted text: OOUtil.insertOOFormattedTextAtCurrentLocation(text, cursor, lText, parStyle); @@ -117,11 +127,11 @@ public static void insertOOFormattedTextAtCurrentLocation(XText text, XTextCurso //insertTextAtCurrentLocation(text, cursor, "_", // false, false, false, false, false, false); //cursor.goLeft((short)1, true); - Matcher m = OOUtil.htmlTag.matcher(lText); + Matcher m = OOUtil.HTML_TAG.matcher(lText); while (m.find()) { String ss = lText.substring(piv, m.start()); if (!ss.isEmpty()) { - OOUtil.insertTextAtCurrentLocation(text, cursor, ss, bold % 2 > 0, italic % 2 > 0, + OOUtil.insertTextAtCurrentLocation(text, cursor, ss, (bold % 2) > 0, (italic % 2) > 0, mono > 0, smallCaps > 0, sup > 0, sub > 0); } String tag = m.group(); @@ -158,7 +168,7 @@ public static void insertOOFormattedTextAtCurrentLocation(XText text, XTextCurso if (piv < lText.length()) { OOUtil.insertTextAtCurrentLocation(text, cursor, lText.substring(piv), - bold % 2 > 0, italic % 2 > 0, mono > 0, smallCaps > 0, sup > 0, sub > 0); + (bold % 2) > 0, (italic % 2) > 0, mono > 0, smallCaps > 0, sup > 0, sub > 0); } cursor.collapseToEnd(); @@ -307,8 +317,8 @@ public static BibEntry createAdaptedEntry(BibEntry entry) { String value = e.getField(field); // If the running JabRef version doesn't support post-processing in Layout, // preprocess fields instead: - if (!OpenOfficePanel.postLayoutSupported && value != null) { - e.setField(field, OOUtil.postformatter.format(value)); + if (!OpenOfficePanel.postLayoutSupported && (value != null)) { + e.setField(field, OOUtil.POSTFORMATTER.format(value)); } } return e; diff --git a/src/main/java/net/sf/jabref/openoffice/OpenOfficePanel.java b/src/main/java/net/sf/jabref/openoffice/OpenOfficePanel.java index f0e976c50a9..e08a88ab2d0 100644 --- a/src/main/java/net/sf/jabref/openoffice/OpenOfficePanel.java +++ b/src/main/java/net/sf/jabref/openoffice/OpenOfficePanel.java @@ -52,20 +52,20 @@ */ public class OpenOfficePanel extends AbstractWorker implements PushToApplication { - public static final String defaultAuthorYearStylePath = "/resource/openoffice/default_authoryear.jstyle"; - public static final String defaultNumericalStylePath = "/resource/openoffice/default_numerical.jstyle"; + public static final String DEFAULT_AUTHORYEAR_STYLE_PATH = "/resource/openoffice/default_authoryear.jstyle"; + public static final String DEFAULT_NUMERICAL_STYLE_PATH = "/resource/openoffice/default_numerical.jstyle"; // This field indicates whether the running JabRef supports post formatters in Layout: public static boolean postLayoutSupported; static { - OpenOfficePanel.postLayoutSupported = true; + postLayoutSupported = true; try { Layout l = new LayoutHelper(new StringReader("")). getLayoutFromText(Globals.FORMATTER_PACKAGE); l.setPostFormatter(null); } catch (NoSuchMethodError ex) { - OpenOfficePanel.postLayoutSupported = false; + postLayoutSupported = false; } catch (Exception ignore) { // Ignored } @@ -74,33 +74,32 @@ public class OpenOfficePanel extends AbstractWorker implements PushToApplication private OOPanel comp; private JDialog diag; - private static JButton - connect; - private static JButton manualConnect; - private static JButton selectDocument; - private static final JButton setStyleFile = new JButton(Localization.lang("Select style")); - private static final JButton pushEntries = new JButton(Localization.lang("Cite")); - private static final JButton pushEntriesInt = new JButton(Localization.lang("Cite in-text")); - private static final JButton pushEntriesEmpty = new JButton(Localization.lang("Insert empty citation")); - private static final JButton pushEntriesAdvanced = new JButton(Localization.lang("Cite special")); - private static final JButton focus = new JButton("Focus OO document"); - private static JButton update; - private static final JButton insertFullRef = new JButton("Insert reference text"); - private static final JButton merge = new JButton(Localization.lang("Merge citations")); - private static final JButton manageCitations = new JButton(Localization.lang("Manage citations")); - private static final JButton settingsB = new JButton(Localization.lang("Settings")); - private static final JButton help = new HelpAction(GUIGlobals.helpDiag, "OpenOfficeIntegration.html").getIconButton(); - private static final JButton test = new JButton("Test"); + private final JButton connect; + private final JButton manualConnect; + private final JButton selectDocument; + private final JButton setStyleFile = new JButton(Localization.lang("Select style")); + private final JButton pushEntries = new JButton(Localization.lang("Cite")); + private final JButton pushEntriesInt = new JButton(Localization.lang("Cite in-text")); + private final JButton pushEntriesEmpty = new JButton(Localization.lang("Insert empty citation")); + private final JButton pushEntriesAdvanced = new JButton(Localization.lang("Cite special")); + private final JButton focus = new JButton("Focus OO document"); + private final JButton update; + private final JButton insertFullRef = new JButton("Insert reference text"); + private final JButton merge = new JButton(Localization.lang("Merge citations")); + private final JButton manageCitations = new JButton(Localization.lang("Manage citations")); + private final JButton settingsB = new JButton(Localization.lang("Settings")); + private final JButton help = new HelpAction(GUIGlobals.helpDiag, "OpenOfficeIntegration.html").getIconButton(); + private final JButton test = new JButton("Test"); private JRadioButton inPar; private JRadioButton inText; private JPanel settings; - private static String styleFile; - private static OOBibBase ooBase; - private static JabRefFrame frame; + private String styleFile; + private OOBibBase ooBase; + private JabRefFrame frame; private SidePaneManager manager; - private static OOBibStyle style; - private static boolean useDefaultAuthoryearStyle; - private static boolean useDefaultNumericalStyle; + private OOBibStyle style; + private boolean useDefaultAuthoryearStyle; + private boolean useDefaultNumericalStyle; private StyleSelectDialog styleDialog; private boolean dialogOkPressed; private boolean autoDetected; @@ -120,44 +119,41 @@ public static OpenOfficePanel getInstance() { private OpenOfficePanel() { Icon connectImage = IconTheme.JabRefIcon.CONNECT_OPEN_OFFICE.getSmallIcon(); - OpenOfficePanel.connect = new JButton(connectImage); - OpenOfficePanel.manualConnect = new JButton(connectImage); - OpenOfficePanel.connect.setToolTipText(Localization.lang("Connect")); - OpenOfficePanel.manualConnect.setToolTipText(Localization.lang("Manual connect")); - OpenOfficePanel.selectDocument = new JButton(IconTheme.JabRefIcon.OPEN.getSmallIcon()); - OpenOfficePanel.selectDocument.setToolTipText(Localization.lang("Select Writer document")); - OpenOfficePanel.update = new JButton(IconTheme.JabRefIcon.REFRESH.getSmallIcon()); - OpenOfficePanel.update.setToolTipText(Localization.lang("Sync OO bibliography")); + connect = new JButton(connectImage); + manualConnect = new JButton(connectImage); + connect.setToolTipText(Localization.lang("Connect")); + manualConnect.setToolTipText(Localization.lang("Manual connect")); + selectDocument = new JButton(IconTheme.JabRefIcon.OPEN.getSmallIcon()); + selectDocument.setToolTipText(Localization.lang("Select Writer document")); + update = new JButton(IconTheme.JabRefIcon.REFRESH.getSmallIcon()); + update.setToolTipText(Localization.lang("Sync OO bibliography")); if (OS.WINDOWS) { - Globals.prefs.putDefaultValue("ooPath", "C:\\Program Files\\OpenOffice.org 4"); - Globals.prefs.putDefaultValue("ooExecutablePath", + Globals.prefs.putDefaultValue(JabRefPreferences.OO_PATH, "C:\\Program Files\\OpenOffice.org 4"); + Globals.prefs.putDefaultValue(JabRefPreferences.OO_EXECUTABLE_PATH, "C:\\Program Files\\OpenOffice.org 4\\program\\soffice.exe"); - Globals.prefs.putDefaultValue("ooJarsPath", "C:\\Program Files\\OpenOffice.org 4\\program\\classes"); + Globals.prefs.putDefaultValue(JabRefPreferences.OO_JARS_PATH, "C:\\Program Files\\OpenOffice.org 4\\program\\classes"); } else if (OS.OS_X) { - Globals.prefs.putDefaultValue("ooExecutablePath", "/Applications/OpenOffice.org.app/Contents/MacOS/soffice.bin"); - Globals.prefs.putDefaultValue("ooPath", "/Applications/OpenOffice.org.app"); - Globals.prefs.putDefaultValue("ooJarsPath", "/Applications/OpenOffice.org.app/Contents/basis-link"); + Globals.prefs.putDefaultValue(JabRefPreferences.OO_EXECUTABLE_PATH, "/Applications/OpenOffice.org.app/Contents/MacOS/soffice.bin"); + Globals.prefs.putDefaultValue(JabRefPreferences.OO_PATH, "/Applications/OpenOffice.org.app"); + Globals.prefs.putDefaultValue(JabRefPreferences.OO_JARS_PATH, "/Applications/OpenOffice.org.app/Contents/basis-link"); } else { // Linux - //Globals.prefs.putDefaultValue("ooPath", "/usr/lib/openoffice"); - Globals.prefs.putDefaultValue("ooPath", "/opt/openoffice.org3"); - Globals.prefs.putDefaultValue("ooExecutablePath", "/usr/lib/openoffice/program/soffice"); - //Globals.prefs.putDefaultValue("ooJarsPath", "/usr/share/java/openoffice"); - Globals.prefs.putDefaultValue("ooJarsPath", "/opt/openoffice.org/basis3.0"); + Globals.prefs.putDefaultValue(JabRefPreferences.OO_PATH, "/opt/openoffice.org3"); + Globals.prefs.putDefaultValue(JabRefPreferences.OO_EXECUTABLE_PATH, "/usr/lib/openoffice/program/soffice"); + Globals.prefs.putDefaultValue(JabRefPreferences.OO_JARS_PATH, "/opt/openoffice.org/basis3.0"); } - Globals.prefs.putDefaultValue("connectToOO3", Boolean.TRUE); //Globals.prefs.putDefaultValue("ooStyleFileDirectories", System.getProperty("user.home")+";false"); Globals.prefs.putDefaultValue("ooStyleFileLastDir", System.getProperty("user.home")); - Globals.prefs.putDefaultValue("ooInParCitation", true); - Globals.prefs.putDefaultValue("syncOOWhenCiting", false); - Globals.prefs.putDefaultValue("showOOPanel", false); - Globals.prefs.putDefaultValue("useAllOpenBases", true); - Globals.prefs.putDefaultValue("ooUseDefaultAuthoryearStyle", true); - Globals.prefs.putDefaultValue("ooUseDefaultNumericalStyle", false); - Globals.prefs.putDefaultValue("ooChooseStyleDirectly", false); - Globals.prefs.putDefaultValue("ooDirectFile", ""); - Globals.prefs.putDefaultValue("ooStyleDirectory", ""); - OpenOfficePanel.styleFile = Globals.prefs.get("ooBibliographyStyleFile"); + Globals.prefs.putDefaultValue(JabRefPreferences.OO_IN_PAR_CITATION, true); + Globals.prefs.putDefaultValue(JabRefPreferences.SYNC_OO_WHEN_CITING, false); + Globals.prefs.putDefaultValue(JabRefPreferences.SHOW_OO_PANEL, false); + Globals.prefs.putDefaultValue(JabRefPreferences.USE_ALL_OPEN_BASES, true); + Globals.prefs.putDefaultValue(JabRefPreferences.OO_USE_DEFAULT_AUTHORYEAR_STYLE, true); + Globals.prefs.putDefaultValue(JabRefPreferences.OO_USE_DEFAULT_NUMERICAL_STYLE, false); + Globals.prefs.putDefaultValue(JabRefPreferences.OO_CHOOSE_STYLE_DIRECTLY, false); + Globals.prefs.putDefaultValue(JabRefPreferences.OO_DIRECT_FILE, ""); + Globals.prefs.putDefaultValue(JabRefPreferences.OO_STYLE_DIRECTORY, ""); + styleFile = Globals.prefs.get(JabRefPreferences.OO_BIBLIOGRAPHY_STYLE_FILE); } @@ -166,7 +162,7 @@ public SidePaneComponent getSidePaneComponent() { } public void init(JabRefFrame jrFrame, SidePaneManager spManager) { - OpenOfficePanel.frame = jrFrame; + frame = jrFrame; this.manager = spManager; comp = new OOPanel(spManager, IconTheme.getImage("openoffice"), Localization.lang("OpenOffice")); try { @@ -178,7 +174,7 @@ public void init(JabRefFrame jrFrame, SidePaneManager spManager) { } public JMenuItem getMenuItem() { - if (Globals.prefs.getBoolean("showOOPanel")) { + if (Globals.prefs.getBoolean(JabRefPreferences.SHOW_OO_PANEL)) { manager.show(getName()); } JMenuItem item = new JMenuItem(Localization.lang("OpenOffice/LibreOffice connection"), @@ -199,8 +195,8 @@ public String getShortcutKey() { private void initPanel() { - OpenOfficePanel.useDefaultAuthoryearStyle = Globals.prefs.getBoolean("ooUseDefaultAuthoryearStyle"); - OpenOfficePanel.useDefaultNumericalStyle = Globals.prefs.getBoolean("ooUseDefaultNumericalStyle"); + useDefaultAuthoryearStyle = Globals.prefs.getBoolean(JabRefPreferences.OO_USE_DEFAULT_AUTHORYEAR_STYLE); + useDefaultNumericalStyle = Globals.prefs.getBoolean(JabRefPreferences.OO_USE_DEFAULT_NUMERICAL_STYLE); Action al = new AbstractAction() { @Override @@ -208,42 +204,42 @@ public void actionPerformed(ActionEvent e) { connect(true); } }; - OpenOfficePanel.connect.addActionListener(al); + connect.addActionListener(al); - OpenOfficePanel.manualConnect.addActionListener(new ActionListener() { + manualConnect.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { connect(false); } }); - OpenOfficePanel.selectDocument.setToolTipText(Localization.lang("Select which open Writer document to work on")); - OpenOfficePanel.selectDocument.addActionListener(new ActionListener() { + selectDocument.setToolTipText(Localization.lang("Select which open Writer document to work on")); + selectDocument.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { try { - OpenOfficePanel.ooBase.selectDocument(); - OpenOfficePanel.frame.output(Localization.lang("Connected to document") + ": " + OpenOfficePanel.ooBase.getCurrentDocumentTitle()); + ooBase.selectDocument(); + frame.output(Localization.lang("Connected to document") + ": " + ooBase.getCurrentDocumentTitle()); } catch (Exception ex) { - JOptionPane.showMessageDialog(OpenOfficePanel.frame, ex.getMessage(), Localization.lang("Error"), + JOptionPane.showMessageDialog(frame, ex.getMessage(), Localization.lang("Error"), JOptionPane.ERROR_MESSAGE); } } }); - OpenOfficePanel.setStyleFile.addActionListener(new ActionListener() { + setStyleFile.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (styleDialog == null) { - styleDialog = new StyleSelectDialog(OpenOfficePanel.frame, OpenOfficePanel.styleFile); + styleDialog = new StyleSelectDialog(frame, styleFile); } styleDialog.setVisible(true); if (styleDialog.isOkPressed()) { - OpenOfficePanel.useDefaultAuthoryearStyle = Globals.prefs.getBoolean("ooUseDefaultAuthoryearStyle"); - OpenOfficePanel.useDefaultNumericalStyle = Globals.prefs.getBoolean("ooUseDefaultNumericalStyle"); - OpenOfficePanel.styleFile = Globals.prefs.get("ooBibliographyStyleFile"); + useDefaultAuthoryearStyle = Globals.prefs.getBoolean(JabRefPreferences.OO_USE_DEFAULT_AUTHORYEAR_STYLE); + useDefaultNumericalStyle = Globals.prefs.getBoolean(JabRefPreferences.OO_USE_DEFAULT_NUMERICAL_STYLE); + styleFile = Globals.prefs.get(JabRefPreferences.OO_BIBLIOGRAPHY_STYLE_FILE); try { readStyleFile(); } catch (Exception ex) { @@ -253,32 +249,32 @@ public void actionPerformed(ActionEvent e) { } }); - OpenOfficePanel.pushEntries.setToolTipText(Localization.lang("Cite selected entries between parenthesis")); - OpenOfficePanel.pushEntries.addActionListener(new ActionListener() { + pushEntries.setToolTipText(Localization.lang("Cite selected entries between parenthesis")); + pushEntries.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { pushEntries(true, true, false); } }); - OpenOfficePanel.pushEntriesInt.setToolTipText(Localization.lang("Cite selected entries with in-text citation")); - OpenOfficePanel.pushEntriesInt.addActionListener(new ActionListener() { + pushEntriesInt.setToolTipText(Localization.lang("Cite selected entries with in-text citation")); + pushEntriesInt.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { pushEntries(false, true, false); } }); - OpenOfficePanel.pushEntriesEmpty.setToolTipText(Localization.lang("Insert a citation without text (the entry will appear in the reference list)")); - OpenOfficePanel.pushEntriesEmpty.addActionListener(new ActionListener() { + pushEntriesEmpty.setToolTipText(Localization.lang("Insert a citation without text (the entry will appear in the reference list)")); + pushEntriesEmpty.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { pushEntries(false, false, false); } }); - OpenOfficePanel.pushEntriesAdvanced.setToolTipText(Localization.lang("Cite selected entries with extra information")); - OpenOfficePanel.pushEntriesAdvanced.addActionListener(new ActionListener() { + pushEntriesAdvanced.setToolTipText(Localization.lang("Cite selected entries with extra information")); + pushEntriesAdvanced.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { @@ -286,40 +282,40 @@ public void actionPerformed(ActionEvent event) { } }); - OpenOfficePanel.focus.addActionListener(new ActionListener() { + focus.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - OpenOfficePanel.ooBase.setFocus(); + ooBase.setFocus(); } }); - OpenOfficePanel.update.setToolTipText(Localization.lang("Ensure that the bibliography is up-to-date")); + update.setToolTipText(Localization.lang("Ensure that the bibliography is up-to-date")); Action updateAction = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { try { try { - if (OpenOfficePanel.style == null) { + if (style == null) { readStyleFile(); } else { - OpenOfficePanel.style.ensureUpToDate(); + style.ensureUpToDate(); } } catch (Throwable ex) { - JOptionPane.showMessageDialog(OpenOfficePanel.frame, Localization.lang("You must select either a valid style file, or use one of the default styles."), + JOptionPane.showMessageDialog(frame, Localization.lang("You must select either a valid style file, or use one of the default styles."), Localization.lang("No valid style file defined"), JOptionPane.ERROR_MESSAGE); return; } - OpenOfficePanel.ooBase.updateSortedReferenceMarks(); + ooBase.updateSortedReferenceMarks(); java.util.List databases = getBaseList(); - java.util.List unresolvedKeys = OpenOfficePanel.ooBase.refreshCiteMarkers - (databases, OpenOfficePanel.style); - OpenOfficePanel.ooBase.rebuildBibTextSection(databases, OpenOfficePanel.style); + java.util.List unresolvedKeys = ooBase.refreshCiteMarkers + (databases, style); + ooBase.rebuildBibTextSection(databases, style); //ooBase.sync(frame.getCurrentBasePanel().database(), style); if (!unresolvedKeys.isEmpty()) { - JOptionPane.showMessageDialog(OpenOfficePanel.frame, Localization.lang("Your OpenOffice document references the BibTeX key '%0', which could not be found in your current database.", + JOptionPane.showMessageDialog(frame, Localization.lang("Your OpenOffice document references the BibTeX key '%0', which could not be found in your current database.", unresolvedKeys.get(0)), Localization.lang("Unable to synchronize bibliography"), JOptionPane.ERROR_MESSAGE); } } catch (UndefinedCharacterFormatException ex) { @@ -329,7 +325,7 @@ public void actionPerformed(ActionEvent e) { } catch (ConnectionLostException ex) { showConnectionLostErrorMessage(); } catch (BibtexEntryNotFoundException ex) { - JOptionPane.showMessageDialog(OpenOfficePanel.frame, Localization.lang("Your OpenOffice document references the BibTeX key '%0', which could not be found in your current database.", + JOptionPane.showMessageDialog(frame, Localization.lang("Your OpenOffice document references the BibTeX key '%0', which could not be found in your current database.", ex.getBibtexKey()), Localization.lang("Unable to synchronize bibliography"), JOptionPane.ERROR_MESSAGE); } catch (Exception e1) { @@ -337,9 +333,9 @@ public void actionPerformed(ActionEvent e) { } } }; - OpenOfficePanel.update.addActionListener(updateAction); + update.addActionListener(updateAction); - OpenOfficePanel.insertFullRef.addActionListener(new ActionListener() { + insertFullRef.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { @@ -351,13 +347,13 @@ public void actionPerformed(ActionEvent event) { } }); - OpenOfficePanel.merge.setToolTipText(Localization.lang("Combine pairs of citations that are separated by spaces only")); - OpenOfficePanel.merge.addActionListener(new ActionListener() { + merge.setToolTipText(Localization.lang("Combine pairs of citations that are separated by spaces only")); + merge.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { try { - OpenOfficePanel.ooBase.combineCiteMarkers(getBaseList(), OpenOfficePanel.style); + ooBase.combineCiteMarkers(getBaseList(), style); } catch (UndefinedCharacterFormatException e) { reportUndefinedCharacterFormat(e); } catch (Exception e) { @@ -367,7 +363,7 @@ public void actionPerformed(ActionEvent event) { } }); - OpenOfficePanel.settingsB.addActionListener(new ActionListener() { + settingsB.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { @@ -375,12 +371,12 @@ public void actionPerformed(ActionEvent actionEvent) { } }); - OpenOfficePanel.manageCitations.addActionListener(new ActionListener() { + manageCitations.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { try { - CitationManager cm = new CitationManager(OpenOfficePanel.frame, OpenOfficePanel.ooBase); + CitationManager cm = new CitationManager(frame, ooBase); cm.showDialog(); } catch (Exception e) { e.printStackTrace(); @@ -388,7 +384,7 @@ public void actionPerformed(ActionEvent event) { } }); - OpenOfficePanel.test.addActionListener(new ActionListener() { + test.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { @@ -410,17 +406,17 @@ public void actionPerformed(ActionEvent event) { } }); - OpenOfficePanel.selectDocument.setEnabled(false); - OpenOfficePanel.pushEntries.setEnabled(false); - OpenOfficePanel.pushEntriesInt.setEnabled(false); - OpenOfficePanel.pushEntriesEmpty.setEnabled(false); - OpenOfficePanel.pushEntriesAdvanced.setEnabled(false); - OpenOfficePanel.focus.setEnabled(false); - OpenOfficePanel.update.setEnabled(false); - OpenOfficePanel.insertFullRef.setEnabled(false); - OpenOfficePanel.merge.setEnabled(false); - OpenOfficePanel.manageCitations.setEnabled(false); - OpenOfficePanel.test.setEnabled(false); + selectDocument.setEnabled(false); + pushEntries.setEnabled(false); + pushEntriesInt.setEnabled(false); + pushEntriesEmpty.setEnabled(false); + pushEntriesAdvanced.setEnabled(false); + focus.setEnabled(false); + update.setEnabled(false); + insertFullRef.setEnabled(false); + merge.setEnabled(false); + manageCitations.setEnabled(false); + test.setEnabled(false); diag = new JDialog((JFrame) null, "OpenOffice panel", false); DefaultFormBuilder b = new DefaultFormBuilder(new FormLayout("fill:pref:grow", @@ -431,24 +427,24 @@ public void actionPerformed(ActionEvent event) { DefaultFormBuilder bb = new DefaultFormBuilder(new FormLayout ("fill:pref:grow, 1dlu, fill:pref:grow, 1dlu, fill:pref:grow, " + "1dlu, fill:pref:grow, 1dlu, fill:pref:grow", "")); - bb.append(OpenOfficePanel.connect); - bb.append(OpenOfficePanel.manualConnect); - bb.append(OpenOfficePanel.selectDocument); - bb.append(OpenOfficePanel.update); - bb.append(OpenOfficePanel.help); + bb.append(connect); + bb.append(manualConnect); + bb.append(selectDocument); + bb.append(update); + bb.append(help); //b.append(connect); //b.append(manualConnect); //b.append(selectDocument); b.append(bb.getPanel()); - b.append(OpenOfficePanel.setStyleFile); - b.append(OpenOfficePanel.pushEntries); - b.append(OpenOfficePanel.pushEntriesInt); - b.append(OpenOfficePanel.pushEntriesAdvanced); - b.append(OpenOfficePanel.pushEntriesEmpty); - b.append(OpenOfficePanel.merge); - b.append(OpenOfficePanel.manageCitations); - b.append(OpenOfficePanel.settingsB); + b.append(setStyleFile); + b.append(pushEntries); + b.append(pushEntriesInt); + b.append(pushEntriesAdvanced); + b.append(pushEntriesEmpty); + b.append(merge); + b.append(manageCitations); + b.append(settingsB); //b.append(focus); //b.append(update); @@ -461,9 +457,9 @@ public void actionPerformed(ActionEvent event) { content.setLayout(new BorderLayout()); content.add(b.getPanel(), BorderLayout.CENTER); - OpenOfficePanel.frame.getTabbedPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW) + frame.getTabbedPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW) .put(Globals.getKeyPrefs().getKey(KeyBinding.REFRESH_OO), "Refresh OO"); - OpenOfficePanel.frame.getTabbedPane().getActionMap().put("Refresh OO", updateAction); + frame.getTabbedPane().getActionMap().put("Refresh OO", updateAction); //diag.pack(); //diag.setVisible(true); @@ -471,12 +467,12 @@ public void actionPerformed(ActionEvent event) { private java.util.List getBaseList() { java.util.List databases = new ArrayList<>(); - if (Globals.prefs.getBoolean("useAllOpenBases")) { - for (int i = 0; i < OpenOfficePanel.frame.getBasePanelCount(); i++) { - databases.add(OpenOfficePanel.frame.getBasePanelAt(i).database()); + if (Globals.prefs.getBoolean(JabRefPreferences.USE_ALL_OPEN_BASES)) { + for (int i = 0; i < frame.getBasePanelCount(); i++) { + databases.add(frame.getBasePanelAt(i).database()); } } else { - databases.add(OpenOfficePanel.frame.getCurrentBasePanel().database()); + databases.add(frame.getCurrentBasePanel().database()); } return databases; @@ -493,7 +489,6 @@ private void connect(boolean auto) { return; }*/ - String unoilDir; String ooBaseDirectory; if (auto) { AutoDetectPaths adp = new AutoDetectPaths(diag); @@ -511,15 +506,8 @@ private void connect(boolean auto) { return; } - // User clicked Auto, and the system successfully detected paths: - unoilDir = Globals.prefs.get("ooUnoilPath"); - ooBaseDirectory = Globals.prefs.get("ooJurtPath"); - sOffice = Globals.prefs.get("ooExecutablePath"); - - //System.out.println("unoilDir: "+unoilDir); - //System.out.println("ooBaseDir: "+ooBaseDirectory); - //System.out.println("soffice: "+sOffice); - + ooBaseDirectory = Globals.prefs.get(JabRefPreferences.OO_JARS_PATH); + sOffice = Globals.prefs.get(JabRefPreferences.OO_EXECUTABLE_PATH); } else { // Manual connect @@ -528,34 +516,28 @@ private void connect(boolean auto) { return; } - String ooPath = Globals.prefs.get("ooPath"); - String ooJars = Globals.prefs.get("ooJarsPath"); - sOffice = Globals.prefs.get("ooExecutablePath"); + String ooPath = Globals.prefs.get(JabRefPreferences.OO_PATH); + String ooJars = Globals.prefs.get(JabRefPreferences.OO_JARS_PATH); + sOffice = Globals.prefs.get(JabRefPreferences.OO_EXECUTABLE_PATH); if (OS.WINDOWS) { - unoilDir = ooPath + "\\program\\classes"; ooBaseDirectory = ooPath + "\\program\\classes"; sOffice = ooPath + "\\program\\soffice.exe"; } else if (OS.OS_X) { sOffice = ooPath + "/Contents/MacOS/soffice.bin"; ooBaseDirectory = ooPath + "/Contents/basis-link/program/classes"; - unoilDir = ooPath + "/Contents/basis-link/program/classes"; } else { // Linux: - unoilDir = ooJars + "/program/classes"; ooBaseDirectory = ooJars + "/program/classes"; } } // Add OO jars to the classpath: try { - File[] jarFiles = new File[] { - new File(unoilDir, "unoil.jar"), - new File(ooBaseDirectory, "jurt.jar"), - new File(ooBaseDirectory, "juh.jar"), - new File(ooBaseDirectory, "ridl.jar")}; + File[] jarFiles = new File[] {new File(ooBaseDirectory, "unoil.jar"), new File(ooBaseDirectory, "jurt.jar"), + new File(ooBaseDirectory, "juh.jar"), new File(ooBaseDirectory, "ridl.jar")}; URL[] jarList = new URL[jarFiles.length]; for (int i = 0; i < jarList.length; i++) { if (!jarFiles[i].exists()) { @@ -563,7 +545,7 @@ else if (OS.OS_X) { } jarList[i] = jarFiles[i].toURI().toURL(); } - OpenOfficePanel.addURL(jarList); + addURL(jarList); // Show progress dialog: final JDialog progDiag = new AutoDetectPaths(diag).showProgressDialog(diag, Localization.lang("Connecting"), @@ -571,36 +553,36 @@ else if (OS.OS_X) { getWorker().run(); // Do the actual connection, using Spin to get off the EDT. progDiag.dispose(); diag.dispose(); - if (OpenOfficePanel.ooBase == null) { + if (ooBase == null) { throw connectException; } - if (OpenOfficePanel.ooBase.isConnectedToDocument()) { - OpenOfficePanel.frame.output(Localization.lang("Connected to document") + ": " + OpenOfficePanel.ooBase.getCurrentDocumentTitle()); + if (ooBase.isConnectedToDocument()) { + frame.output(Localization.lang("Connected to document") + ": " + ooBase.getCurrentDocumentTitle()); } // Enable actions that depend on Connect: - OpenOfficePanel.selectDocument.setEnabled(true); - OpenOfficePanel.pushEntries.setEnabled(true); - OpenOfficePanel.pushEntriesInt.setEnabled(true); - OpenOfficePanel.pushEntriesEmpty.setEnabled(true); - OpenOfficePanel.pushEntriesAdvanced.setEnabled(true); - OpenOfficePanel.focus.setEnabled(true); - OpenOfficePanel.update.setEnabled(true); - OpenOfficePanel.insertFullRef.setEnabled(true); - OpenOfficePanel.merge.setEnabled(true); - OpenOfficePanel.manageCitations.setEnabled(true); - OpenOfficePanel.test.setEnabled(true); - + selectDocument.setEnabled(true); + pushEntries.setEnabled(true); + pushEntriesInt.setEnabled(true); + pushEntriesEmpty.setEnabled(true); + pushEntriesAdvanced.setEnabled(true); + focus.setEnabled(true); + update.setEnabled(true); + insertFullRef.setEnabled(true); + merge.setEnabled(true); + manageCitations.setEnabled(true); + test.setEnabled(true); + + } catch (UnsatisfiedLinkError e) { + e.printStackTrace(); + JOptionPane.showMessageDialog(frame, + Localization.lang("Unable to connect. One possible reason is that JabRef " + + "and OpenOffice/LibreOffice are not both running in either 32 bit mode or 64 bit mode.")); } catch (Throwable e) { e.printStackTrace(); - if (e instanceof UnsatisfiedLinkError) { - JOptionPane.showMessageDialog(OpenOfficePanel.frame, Localization.lang("Unable to connect. One possible reason is that JabRef " - + "and OpenOffice/LibreOffice are not both running in either 32 bit mode or 64 bit mode.")); - - } - else { - JOptionPane.showMessageDialog(OpenOfficePanel.frame, Localization.lang("Could not connect to running OpenOffice.") + JOptionPane.showMessageDialog(frame, + Localization.lang("Could not connect to running OpenOffice.") + "\n" + Localization.lang("Make sure you have installed OpenOffice with Java support.") + "\n" @@ -610,15 +592,14 @@ else if (OS.OS_X) { + Localization.lang("Error message:") + " " + e.getMessage()); } } - } @Override public void run() { try { // Connect: - OpenOfficePanel.ooBase = new OOBibBase(sOffice, true); + ooBase = new OOBibBase(sOffice, true); } catch (Throwable e) { - OpenOfficePanel.ooBase = null; + ooBase = null; connectException = e; //JOptionPane.showMessageDialog(frame, Globals.lang("Unable to connect")); } @@ -629,18 +610,18 @@ public void run() { * @throws Exception */ private void readStyleFile() throws Exception { - if (OpenOfficePanel.useDefaultAuthoryearStyle) { - URL defPath = JabRef.class.getResource(OpenOfficePanel.defaultAuthorYearStylePath); + if (useDefaultAuthoryearStyle) { + URL defPath = JabRef.class.getResource(DEFAULT_AUTHORYEAR_STYLE_PATH); Reader r = new InputStreamReader(defPath.openStream()); - OpenOfficePanel.style = new OOBibStyle(r); + style = new OOBibStyle(r); } - else if (OpenOfficePanel.useDefaultNumericalStyle) { - URL defPath = JabRef.class.getResource(OpenOfficePanel.defaultNumericalStylePath); + else if (useDefaultNumericalStyle) { + URL defPath = JabRef.class.getResource(DEFAULT_NUMERICAL_STYLE_PATH); Reader r = new InputStreamReader(defPath.openStream()); - OpenOfficePanel.style = new OOBibStyle(r); + style = new OOBibStyle(r); } else { - OpenOfficePanel.style = new OOBibStyle(new File(OpenOfficePanel.styleFile)); + style = new OOBibStyle(new File(styleFile)); } } @@ -655,7 +636,7 @@ private static void addURL(URL[] u) throws IOException { Class sysclass = URLClassLoader.class; try { - Method method = sysclass.getDeclaredMethod("addURL", OpenOfficePanel.parameters); + Method method = sysclass.getDeclaredMethod("addURL", parameters); method.setAccessible(true); for (URL anU : u) { method.invoke(sysloader, anU); @@ -666,27 +647,26 @@ private static void addURL(URL[] u) throws IOException { } } - private void updateConnectionParams(String ooPath, String ooExec, String ooJars, boolean oo3) { - Globals.prefs.put("ooPath", ooPath); - Globals.prefs.put("ooExecutablePath", ooExec); - Globals.prefs.put("ooJarsPath", ooJars); - Globals.prefs.putBoolean("connectToOO3", oo3); + private void updateConnectionParams(String ooPath, String ooExec, String ooJars) { + Globals.prefs.put(JabRefPreferences.OO_PATH, ooPath); + Globals.prefs.put(JabRefPreferences.OO_EXECUTABLE_PATH, ooExec); + Globals.prefs.put(JabRefPreferences.OO_JARS_PATH, ooJars); } private void showConnectDialog() { dialogOkPressed = false; - final JDialog cDiag = new JDialog(OpenOfficePanel.frame, Localization.lang("Set connection parameters"), true); + final JDialog cDiag = new JDialog(frame, Localization.lang("Set connection parameters"), true); final JTextField ooPath = new JTextField(30); JButton browseOOPath = new JButton(Localization.lang("Browse")); - ooPath.setText(Globals.prefs.get("ooPath")); + ooPath.setText(Globals.prefs.get(JabRefPreferences.OO_PATH)); final JTextField ooExec = new JTextField(30); JButton browseOOExec = new JButton(Localization.lang("Browse")); browseOOExec.addActionListener(BrowseAction.buildForFile(ooExec)); final JTextField ooJars = new JTextField(30); JButton browseOOJars = new JButton(Localization.lang("Browse")); browseOOJars.addActionListener(BrowseAction.buildForDir(ooJars)); - ooExec.setText(Globals.prefs.get("ooExecutablePath")); - ooJars.setText(Globals.prefs.get("ooJarsPath")); + ooExec.setText(Globals.prefs.get(JabRefPreferences.OO_EXECUTABLE_PATH)); + ooJars.setText(Globals.prefs.get(JabRefPreferences.OO_JARS_PATH)); DefaultFormBuilder builder = new DefaultFormBuilder(new FormLayout("left:pref, 4dlu, fill:pref:grow, 4dlu, fill:pref", "")); if (OS.WINDOWS || OS.OS_X) { builder.append(Localization.lang("Path to OpenOffice directory")); @@ -709,13 +689,11 @@ private void showConnectDialog() { ButtonBarBuilder bb = new ButtonBarBuilder(); JButton ok = new JButton(Localization.lang("OK")); JButton cancel = new JButton(Localization.lang("Cancel")); - //JButton auto = new JButton(Globals.lang("Autodetect")); ActionListener tfListener = new ActionListener() { @Override public void actionPerformed(ActionEvent event) { - updateConnectionParams(ooPath.getText(), ooExec.getText(), ooJars.getText(), - true); + updateConnectionParams(ooPath.getText(), ooExec.getText(), ooJars.getText()); cDiag.dispose(); } }; @@ -727,8 +705,7 @@ public void actionPerformed(ActionEvent event) { @Override public void actionPerformed(ActionEvent event) { - updateConnectionParams(ooPath.getText(), ooExec.getText(), ooJars.getText(), - true); + updateConnectionParams(ooPath.getText(), ooExec.getText(), ooJars.getText()); dialogOkPressed = true; cDiag.dispose(); } @@ -750,14 +727,14 @@ public void actionPerformed(ActionEvent event) { cDiag.getContentPane().add(builder.getPanel(), BorderLayout.CENTER); cDiag.getContentPane().add(bb.getPanel(), BorderLayout.SOUTH); cDiag.pack(); - cDiag.setLocationRelativeTo(OpenOfficePanel.frame); + cDiag.setLocationRelativeTo(frame); cDiag.setVisible(true); } private void pushEntries(boolean inParenthesis, boolean withText, boolean addPageInfo) { - if (!OpenOfficePanel.ooBase.isConnectedToDocument()) { - JOptionPane.showMessageDialog(OpenOfficePanel.frame, Localization.lang("Not connected to any Writer document. Please" + if (!ooBase.isConnectedToDocument()) { + JOptionPane.showMessageDialog(frame, Localization.lang("Not connected to any Writer document. Please" + " make sure a document is open, and use the 'Select Writer document' button to connect to it."), Localization.lang("Error"), JOptionPane.ERROR_MESSAGE); return; @@ -765,7 +742,7 @@ private void pushEntries(boolean inParenthesis, boolean withText, boolean addPag String pageInfo = null; if (addPageInfo) { - AdvancedCiteDialog acd = new AdvancedCiteDialog(OpenOfficePanel.frame); + AdvancedCiteDialog acd = new AdvancedCiteDialog(frame); acd.showDialog(); if (acd.cancelled()) { return; @@ -777,19 +754,19 @@ private void pushEntries(boolean inParenthesis, boolean withText, boolean addPag } - BasePanel panel = OpenOfficePanel.frame.getCurrentBasePanel(); + BasePanel panel = frame.getCurrentBasePanel(); if (panel != null) { final BibDatabase database = panel.database(); BibEntry[] entries = panel.getSelectedEntries(); if (entries.length > 0) { try { - if (OpenOfficePanel.style == null) { + if (style == null) { readStyleFile(); } - OpenOfficePanel.ooBase.insertEntry(entries, database, getBaseList(), OpenOfficePanel.style, inParenthesis, withText, - pageInfo, Globals.prefs.getBoolean("syncOOWhenCiting")); + ooBase.insertEntry(entries, database, getBaseList(), style, inParenthesis, withText, + pageInfo, Globals.prefs.getBoolean(JabRefPreferences.SYNC_OO_WHEN_CITING)); } catch (FileNotFoundException ex) { - JOptionPane.showMessageDialog(OpenOfficePanel.frame, Localization.lang("You must select either a valid style file, or use one of the default styles."), + JOptionPane.showMessageDialog(frame, Localization.lang("You must select either a valid style file, or use one of the default styles."), Localization.lang("No valid style file defined"), JOptionPane.ERROR_MESSAGE); } catch (ConnectionLostException ex) { showConnectionLostErrorMessage(); @@ -807,7 +784,7 @@ private void pushEntries(boolean inParenthesis, boolean withText, boolean addPag } private void showConnectionLostErrorMessage() { - JOptionPane.showMessageDialog(OpenOfficePanel.frame, Localization.lang("Connection to OpenOffice has been lost. " + JOptionPane.showMessageDialog(frame, Localization.lang("Connection to OpenOffice has been lost. " + "Please make sure OpenOffice is running, and try to reconnect."), Localization.lang("Connection lost"), JOptionPane.ERROR_MESSAGE); } @@ -819,7 +796,7 @@ private void insertFullRefs() { if (hadBib) ooBase.clearBibTextSectionContent(); */ - BasePanel panel = OpenOfficePanel.frame.getCurrentBasePanel(); + BasePanel panel = frame.getCurrentBasePanel(); Map entries = new LinkedHashMap<>(); if (panel != null) { final BibDatabase database = panel.database(); @@ -828,7 +805,7 @@ private void insertFullRefs() { entries.put(anE, database); } - OpenOfficePanel.ooBase.insertFullReferenceAtViewCursor(entries, OpenOfficePanel.style, "Default"); + ooBase.insertFullReferenceAtViewCursor(entries, style, "Default"); } } catch (UndefinedParagraphFormatException ex) { reportUndefinedParagraphFormat(ex); @@ -839,7 +816,7 @@ private void insertFullRefs() { } private void reportUndefinedParagraphFormat(UndefinedParagraphFormatException ex) { - JOptionPane.showMessageDialog(OpenOfficePanel.frame, "" + Localization.lang("Your style file specifies the paragraph format '%0', " + JOptionPane.showMessageDialog(frame, "" + Localization.lang("Your style file specifies the paragraph format '%0', " + "which is undefined in your current OpenOffice document.", ex.getFormatName()) + "
" + Localization.lang("The paragraph format is controlled by the property 'ReferenceParagraphFormat' or 'ReferenceHeaderParagraphFormat' in the style file.") + "", @@ -847,7 +824,7 @@ private void reportUndefinedParagraphFormat(UndefinedParagraphFormatException ex } private void reportUndefinedCharacterFormat(UndefinedCharacterFormatException ex) { - JOptionPane.showMessageDialog(OpenOfficePanel.frame, "" + Localization.lang("Your style file specifies the character format '%0', " + JOptionPane.showMessageDialog(frame, "" + Localization.lang("Your style file specifies the character format '%0', " + "which is undefined in your current OpenOffice document.", ex.getFormatName()) + "
" + Localization.lang("The character format is controlled by the citation property 'CitationCharacterFormat' in the style file.") + "", @@ -856,7 +833,7 @@ private void reportUndefinedCharacterFormat(UndefinedCharacterFormatException ex public void insertUsingBST() { try { - BasePanel panel = OpenOfficePanel.frame.getCurrentBasePanel(); + BasePanel panel = frame.getCurrentBasePanel(); if (panel != null) { final BibDatabase database = panel.database(); BibEntry[] entries = panel.getSelectedEntries(); @@ -870,7 +847,7 @@ public void insertUsingBST() { for (String key : result.keySet()) { System.out.println("Key: " + key); System.out.println("Entry: " + result.get(key)); - OpenOfficePanel.ooBase.insertMarkedUpTextAtViewCursor(result.get(key), "Default"); + ooBase.insertMarkedUpTextAtViewCursor(result.get(key), "Default"); } //System.out.println(result); } @@ -883,7 +860,7 @@ private void showSettingsPopup() { JPopupMenu menu = new JPopupMenu(); final JCheckBoxMenuItem autoSync = new JCheckBoxMenuItem( Localization.lang("Automatically sync bibliography when inserting citations"), - Globals.prefs.getBoolean("syncOOWhenCiting")); + Globals.prefs.getBoolean(JabRefPreferences.SYNC_OO_WHEN_CITING)); final JRadioButtonMenuItem useActiveBase = new JRadioButtonMenuItem (Localization.lang("Look up BibTeX entries in the active tab only")); final JRadioButtonMenuItem useAllBases = new JRadioButtonMenuItem @@ -893,7 +870,7 @@ private void showSettingsPopup() { ButtonGroup bg = new ButtonGroup(); bg.add(useActiveBase); bg.add(useAllBases); - if (Globals.prefs.getBoolean("useAllOpenBases")) { + if (Globals.prefs.getBoolean(JabRefPreferences.USE_ALL_OPEN_BASES)) { useAllBases.setSelected(true); } else { useActiveBase.setSelected(true); @@ -903,34 +880,32 @@ private void showSettingsPopup() { @Override public void actionPerformed(ActionEvent actionEvent) { - Globals.prefs.putBoolean("syncOOWhenCiting", autoSync.isSelected()); + Globals.prefs.putBoolean(JabRefPreferences.SYNC_OO_WHEN_CITING, autoSync.isSelected()); } }); useAllBases.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { - Globals.prefs.putBoolean("useAllOpenBases", useAllBases.isSelected()); + Globals.prefs.putBoolean(JabRefPreferences.USE_ALL_OPEN_BASES, useAllBases.isSelected()); } }); useActiveBase.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { - Globals.prefs.putBoolean("useAllOpenBases", !useActiveBase.isSelected()); + Globals.prefs.putBoolean(JabRefPreferences.USE_ALL_OPEN_BASES, !useActiveBase.isSelected()); } }); clearConnectionSettings.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { - Globals.prefs.clear("ooPAth"); - Globals.prefs.clear("ooExecutablePath"); - Globals.prefs.clear("ooJarsPath"); - Globals.prefs.clear("connectToOO3"); - Globals.prefs.clear("ooUnoilPath"); - Globals.prefs.clear("ooJurtPath"); - OpenOfficePanel.frame.output(Localization.lang("Cleared connection settings.")); + Globals.prefs.clear(JabRefPreferences.OO_PATH); + Globals.prefs.clear(JabRefPreferences.OO_EXECUTABLE_PATH); + Globals.prefs.clear(JabRefPreferences.OO_JARS_PATH); + Globals.prefs.clear(JabRefPreferences.OO_JARS_PATH); + frame.output(Localization.lang("Cleared connection settings.")); } }); @@ -940,31 +915,29 @@ public void actionPerformed(ActionEvent actionEvent) { menu.add(useAllBases); menu.addSeparator(); menu.add(clearConnectionSettings); - menu.show(OpenOfficePanel.settingsB, 0, OpenOfficePanel.settingsB.getHeight()); + menu.show(settingsB, 0, settingsB.getHeight()); } private void pushEntries(boolean inParenthesis, BibEntry[] entries) { - final BibDatabase database = OpenOfficePanel.frame.getCurrentBasePanel().database(); + final BibDatabase database = frame.getCurrentBasePanel().database(); if (entries.length > 0) { - String pageInfo = null; - //if (addPageInfo) { - AdvancedCiteDialog acd = new AdvancedCiteDialog(OpenOfficePanel.frame); + AdvancedCiteDialog acd = new AdvancedCiteDialog(frame); acd.showDialog(); if (acd.cancelled()) { return; } + String pageInfo = null; if (!acd.getPageInfo().isEmpty()) { pageInfo = acd.getPageInfo(); } inParenthesis = acd.isInParenthesisCite(); - //} try { - OpenOfficePanel.ooBase.insertEntry(entries, database, getBaseList(), OpenOfficePanel.style, inParenthesis, true, - pageInfo, Globals.prefs.getBoolean("syncOOWhenCiting")); + ooBase.insertEntry(entries, database, getBaseList(), style, inParenthesis, true, + pageInfo, Globals.prefs.getBoolean(JabRefPreferences.SYNC_OO_WHEN_CITING)); } catch (ConnectionLostException ex) { showConnectionLostErrorMessage(); } catch (UndefinedCharacterFormatException ex) { @@ -1006,7 +979,7 @@ public JPanel getSettingsPanel() { } private void initSettingsPanel() { - boolean inParen = Globals.prefs.getBoolean("ooInParCitation"); + boolean inParen = Globals.prefs.getBoolean(JabRefPreferences.OO_IN_PAR_CITATION); inPar = new JRadioButton(Localization.lang("Use in-parenthesis citation"), inParen); inText = new JRadioButton(Localization.lang("Use in-text citation"), !inParen); ButtonGroup bg = new ButtonGroup(); @@ -1020,25 +993,25 @@ private void initSettingsPanel() { @Override public void storeSettings() { - Globals.prefs.putBoolean("ooInParCitation", inPar.isSelected()); + Globals.prefs.putBoolean(JabRefPreferences.OO_IN_PAR_CITATION, inPar.isSelected()); } @Override public void pushEntries(BibDatabase bibDatabase, BibEntry[] entries, String s, MetaData metaData) { - if (OpenOfficePanel.ooBase == null) { + if (ooBase == null) { connect(true); } - if (OpenOfficePanel.ooBase != null) { + if (ooBase != null) { try { - if (OpenOfficePanel.style == null) { + if (style == null) { readStyleFile(); } } catch (Exception ex) { - JOptionPane.showMessageDialog(OpenOfficePanel.frame, Localization.lang("You must select either a valid style file, or use one of the default styles."), + JOptionPane.showMessageDialog(frame, Localization.lang("You must select either a valid style file, or use one of the default styles."), Localization.lang("No valid style file defined"), JOptionPane.ERROR_MESSAGE); return; } - pushEntries(Globals.prefs.getBoolean("ooInParCitation"), entries); + pushEntries(Globals.prefs.getBoolean(JabRefPreferences.OO_IN_PAR_CITATION), entries); } } @@ -1061,17 +1034,17 @@ public OOPanel(SidePaneManager sidePaneManager, Icon url, String s) { @Override public String getName() { - return OpenOfficePanel.this.getName(); + return this.getName(); } @Override public void componentClosing() { - Globals.prefs.putBoolean("showOOPanel", false); + Globals.prefs.putBoolean(JabRefPreferences.SHOW_OO_PANEL, false); } @Override public void componentOpening() { - Globals.prefs.putBoolean("showOOPanel", true); + Globals.prefs.putBoolean(JabRefPreferences.SHOW_OO_PANEL, true); } } diff --git a/src/main/java/net/sf/jabref/openoffice/StyleSelectDialog.java b/src/main/java/net/sf/jabref/openoffice/StyleSelectDialog.java index 77f1be8b25b..cb480e339c9 100644 --- a/src/main/java/net/sf/jabref/openoffice/StyleSelectDialog.java +++ b/src/main/java/net/sf/jabref/openoffice/StyleSelectDialog.java @@ -62,6 +62,7 @@ import net.sf.jabref.Globals; import net.sf.jabref.model.entry.IdGenerator; import net.sf.jabref.JabRef; +import net.sf.jabref.JabRefPreferences; import net.sf.jabref.gui.JabRefFrame; import net.sf.jabref.MetaData; import net.sf.jabref.gui.PreviewPanel; @@ -135,20 +136,20 @@ private void init(String inSelection) { bg.add(useDefaultNumerical); bg.add(chooseDirectly); bg.add(setDirectory); - if (Globals.prefs.getBoolean("ooUseDefaultAuthoryearStyle")) { + if (Globals.prefs.getBoolean(JabRefPreferences.OO_USE_DEFAULT_AUTHORYEAR_STYLE)) { useDefaultAuthoryear.setSelected(true); - } else if (Globals.prefs.getBoolean("ooUseDefaultNumericalStyle")) { + } else if (Globals.prefs.getBoolean(JabRefPreferences.OO_USE_DEFAULT_NUMERICAL_STYLE)) { useDefaultNumerical.setSelected(true); } else { - if (Globals.prefs.getBoolean("ooChooseStyleDirectly")) { + if (Globals.prefs.getBoolean(JabRefPreferences.OO_CHOOSE_STYLE_DIRECTLY)) { chooseDirectly.setSelected(true); } else { setDirectory.setSelected(true); } } - directFile.setText(Globals.prefs.get("ooDirectFile")); - styleDir.setText(Globals.prefs.get("ooStyleDirectory")); + directFile.setText(Globals.prefs.get(JabRefPreferences.OO_DIRECT_FILE)); + styleDir.setText(Globals.prefs.get(JabRefPreferences.OO_STYLE_DIRECTORY)); directFile.setEditable(false); styleDir.setEditable(false); @@ -186,11 +187,11 @@ public void actionPerformed(ActionEvent actionEvent) { ExternalFileType type = Globals.prefs.getExternalFileTypeByExt("jstyle"); String link = tableModel.getElementAt(i).getFile().getPath(); try { - if (type != null) { - JabRefDesktop.openExternalFileAnyFormat(new MetaData(), link, type); - } else { + if (type == null) { JabRefDesktop.openExternalFileUnknown(frame, null, new MetaData(), link, new UnknownExternalFileType("jstyle")); + } else { + JabRefDesktop.openExternalFileAnyFormat(new MetaData(), link, type); } } catch (IOException e) { e.printStackTrace(); @@ -402,7 +403,11 @@ private void readStyles() { */ private void selectLastUsed() { // Set the initial selection of the table: - if (initSelection != null) { + if (initSelection == null) { + if (table.getRowCount() > 0) { + table.setRowSelectionInterval(0, 0); + } + } else { boolean found = false; for (int i = 0; i < table.getRowCount(); i++) { if (tableModel.getElementAt(i).getFile().getPath(). @@ -416,11 +421,6 @@ private void selectLastUsed() { table.setRowSelectionInterval(0, 0); } } - else { - if (table.getRowCount() > 0) { - table.setRowSelectionInterval(0, 0); - } - } } /** @@ -473,16 +473,16 @@ private void addSingleFile(File file) { private void storeSettings() { OOBibStyle selected = getSelectedStyle(); - Globals.prefs.putBoolean("ooUseDefaultAuthoryearStyle", useDefaultAuthoryear.isSelected()); - Globals.prefs.putBoolean("ooUseDefaultNumericalStyle", useDefaultNumerical.isSelected()); - Globals.prefs.putBoolean("ooChooseStyleDirectly", chooseDirectly.isSelected()); - Globals.prefs.put("ooDirectFile", directFile.getText()); - Globals.prefs.put("ooStyleDirectory", styleDir.getText()); + Globals.prefs.putBoolean(JabRefPreferences.OO_USE_DEFAULT_AUTHORYEAR_STYLE, useDefaultAuthoryear.isSelected()); + Globals.prefs.putBoolean(JabRefPreferences.OO_USE_DEFAULT_NUMERICAL_STYLE, useDefaultNumerical.isSelected()); + Globals.prefs.putBoolean(JabRefPreferences.OO_CHOOSE_STYLE_DIRECTLY, chooseDirectly.isSelected()); + Globals.prefs.put(JabRefPreferences.OO_DIRECT_FILE, directFile.getText()); + Globals.prefs.put(JabRefPreferences.OO_STYLE_DIRECTORY, styleDir.getText()); if (chooseDirectly.isSelected()) { - Globals.prefs.put("ooBibliographyStyleFile", directFile.getText()); + Globals.prefs.put(JabRefPreferences.OO_BIBLIOGRAPHY_STYLE_FILE, directFile.getText()); } else if (setDirectory.isSelected() && (selected != null)) { - Globals.prefs.put("ooBibliographyStyleFile", selected.getFile().getPath()); + Globals.prefs.put(JabRefPreferences.OO_BIBLIOGRAPHY_STYLE_FILE, selected.getFile().getPath()); } } @@ -570,14 +570,14 @@ private void tablePopup(MouseEvent e) { private void displayDefaultStyle(boolean authoryear) { try { // Read the contents of the default style file: - URL defPath = authoryear ? JabRef.class.getResource(OpenOfficePanel.defaultAuthorYearStylePath) : - JabRef.class.getResource(OpenOfficePanel.defaultNumericalStylePath); + URL defPath = authoryear ? JabRef.class.getResource(OpenOfficePanel.DEFAULT_AUTHORYEAR_STYLE_PATH) : + JabRef.class.getResource(OpenOfficePanel.DEFAULT_NUMERICAL_STYLE_PATH); BufferedReader r = new BufferedReader(new InputStreamReader(defPath.openStream())); String line; StringBuilder sb = new StringBuilder(); while ((line = r.readLine()) != null) { sb.append(line); - sb.append("\n"); + sb.append('\n'); } // Make a dialog box to display the contents: