[svn-upgrade] new version jabref-plugin-oo (0.9+ds) upstream upstream/0.9+ds
authorgregor herrmann <gregoa@debian.org>
Tue, 29 Mar 2011 16:00:34 +0000 (16:00 -0000)
committergregor herrmann <gregoa@debian.org>
Tue, 29 Mar 2011 16:00:34 +0000 (16:00 -0000)
CHANGELOG
OOPlugin-jabref.php [deleted file]
build.xml
example_style_file.jstyle
net/sf/jabref/oo/AdvancedCiteDialog.java [new file with mode: 0644]
net/sf/jabref/oo/CitationManager.java [new file with mode: 0644]
net/sf/jabref/oo/OOBibBase.java
net/sf/jabref/oo/OOBibStyle.java
net/sf/jabref/oo/OOTestPanel.java
net/sf/jabref/oo/UndefinedCharacterFormatException.java [new file with mode: 0644]
plugin.xml

index bae3b2dcd4c937f27b45c341495435b605e6e074..a9e0b42052702396be016868600f2fa077c6d355 100755 (executable)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,18 @@
+ - Reference list is now stored in a text section called "JR_bib" instead of being delimited
+   by bookmarks. This makes it easier to control location of reference list and makes handling
+   of the list more stable.
+0.8.99 (beta):
+ - Added function for citing with extra information such as page numbers, which is appended
+   at the end of the citation marker (inside the end bracket).
+ - Added citation manager that shows list of the citations in the current document in context,
+   and allows editing of extra information for each.
+ - Formatting of citation markers is changed - it now allows the user to specify a character
+   format (with the citation property 'CitationCharacterFormat') which can be defined in
+   OpenOffice with any formatting. The character format will only be applied if the property
+   'FormatCitations' is true. The old citation formatting properties are obsoleted.
+ - Text used in author-year citations is now run through the formatter that handles LaTeX
+   special characters.
+ - Style files can now have either Unix or Dos/Windows line breaks. 
 0.8:
  - Added some explanatory text to style selection dialog.
  - Added context menu for style list that allows quickly opening a style file in an external
diff --git a/OOPlugin-jabref.php b/OOPlugin-jabref.php
deleted file mode 100644 (file)
index 1d9a794..0000000
+++ /dev/null
@@ -1,472 +0,0 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-
-<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
-<head>
-  <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
-  <title>OpenOffice plugin for JabRef</title>
-  <link href="css/style.css" rel="stylesheet" type="text/css" />
-</head>
-
-<body>
-  <div id="main">
-    <div id="container">
-
-      <?php include("navigation.php"); ?>
-
-      <h1>OpenOffice plugin for JabRef</h1>
-
-      <h2>Introduction</h2>
-
-      <p>This plugin offers an interface for inserting citations and formatting a Bibliography in an OpenOffice writer document from JabRef.</p>
-
-      <h2>How to use the plugin</h2>
-
-      <p>The plugin can be used with JabRef 2.4 or newer. If your JabRef version doesn't have a plugin manager (versions 2.4.x), you need to put the plugin jar file in a directory named <code>plugins</code> below the directory where the JabRef jar file is installed (typically under <code>C:\Program files\Jabref 2.x</code> if you are running under Windows). The plugin should be loaded next time you start JabRef, and an item named <b>OpenOffice.org panel</b> should appear in JabRef's <b>Plugins</b> menu.</p>
-
-      <p>The plugin should work with OpenOffice versions 2.4.x and 3.x, provided it is installed with Java support (this is usually the case on Windows, while in some Linux distributions you need to install a separate package named <code>openoffice.org-java-common</code> or something similar).</p>
-
-      <h2>Updates</h2>
-      <ul>
-       <li>2010-06-03: Version 0.8: Style file format now allows optional double quotes aroung property values.</li>
-        <li>2010-05-12: Version 0.7.4: Added a couple of new citation properties: AuthorLastSeparatorInText and MultiCiteChronological</li>
-        <li>2010-03-04: Version 0.7.3: Added support for &lt;smallcaps&gt; tag to indicate small caps in reference list. Several bug fixes.</li>
-        <li>2010-02-02: Version 0.7.2: Added MaxAuthorsFirst property to override MaxAuthors the first time each citation appears.</li>
-        <li>2009-10-07: Version 0.7.1: Several important bug fixes.</li>
-        <li>2009-08-26: Version 0.7: BibTeX fields are now preprocessed to handle LaTeX \textit and \textbf commands and character sequences. <b>NOTE: it is no longer necessary to run FormatChars on fields.</b></li>
-        <li>2009-08-23: Version 0.6: Improved handling of undefined BibTeX keys. Added option to not sync automatically when adding citation.</li>
-        <li>2009-08-05: Version 0.5: Fixed connection problem on Mac. Fixed bug in merge function.</li>
-        <li>2009-06-03: Version 0.4: Added support for superscript/subscript tags in reference list, subscripted citations and different brackets for numbering in the reference list.</li>
-        <li>2009-05-17: Version 0.3: Added MinimumGroupingCount property. Some GUI changes.</li>
-        <li>2009-04-02: Version 0.2.1: Fixed bug in sorting of reference list.</li>
-        <li>2009-03-01: Version 0.2: Better sorting of citations in captions, tables and footnotes.</li>
-        <li>2009-02-25: Version 0.1.9: Added support for bold/italic citation markers, and for citations in table cells and footnotes.</li>
-        <li>2008-12-21: Version 0.1.2: Added invisible citations. Merged citations are now sorted.</li>
-        <li>2008-11-19: Version 0.1.1: Improved handling of OpenOffice shutdown and reconnect.</li>
-        <li>2008-10-25: Version 0.1: User interface improvements. Can now select which Writer document to work with.</li>
-        <li>2008-10-19: Version 0.0.9: Enabled connection to OpenOffice.org 3. Streamlined connection process.</li>
-        <li>2008-09-03: Version 0.0.8: No major changes, but packaged with JabRef 2.4.</li>
-        <li>2008-02-20: Version 0.0.7: New interface for style selection. Styles can now specify paragraph format.</li>
-        <li>2008-02-13: Version 0.0.6: Sorting and grouping of number citation markers.</li>
-        <li>2008-02-06: Version 0.0.5: Modified style file format. Fixed bug in handling names with elements like "van der".</li>
-        <li>2008-01-09: Version 0.0.4: Style file is now automatically reloaded if modified.</li>
-        <li>2007-12-17: Version 0.0.3: From this version, we bypass OO's built-in bibliographic system.</li>
-        <li>2007-12-04: Version 0.0.2</li>
-        <li>2007-12-01: Version 0.0.1</li>
-      </ul>
-
-      <h2>Downloads</h2>
-
-      <p><a href="plugins/net.sf.jabref.oo.ooplugin-0.8.jar">The plugin.</a></p>
-
-      <p><a href="plugins/JabRef-oo-0.8-src.zip">Plugin source code.</a> The source code tree includes four OpenOffice.org jars and JabRef 2.6. The plugin is built using an included Ant build file.</p>
-
-      <p><a href="plugins/example_style_file.jstyle">Example style file</a></p>
-
-      <p>The plugin is distributed under the terms of the GNU <a href="http://www.gnu.org/licenses/old-licenses/gpl-2.0.html">General Public License</a>, version 2 or later.</p>
-
-      <h2>Using the OpenOffice interface</h2>
-
-      <p>To communicate with OpenOffice, the OO plugin must first connect to a running OpenOffice instance. You need to start OpenOffice and enter your document before connecting from JabRef. The plugin needs to know the location of your OpenOffice executable (<b>soffice.exe</b> on Windows, and <b>soffice</b> on other platforms), and the directory where several OpenOffice jar files reside. If you connect by clicking the <b>Connect</b> button, the plugin will try to automatically determine these locations. If this does not work, you need to connect using the <b>Manual connect</b> button, which will open a window asking you for the needed locations.</p>
-
-      <p>After the connection has been established, you can insert citations by selecting one or more entries in JabRef and using the <b>Push to OpenOffice</b> button in the dropdown menu of JabRef's toolbar, or by using the appropriate button in the OpenOffice plugin panel in the side pane. This will insert citations for the selected entries at the current cursor position in the OpenOffice document, and update the bibliography to contain the full reference.</p>
-
-      <p><b>Note:</b> JabRef does not use OpenOffice's built-in bibliography system, because of the limitations of that system. A document containing citations inserted from JabRef will not generally be compatible with other reference managers such as Bibus and Zotero.</p>
-
-      <p>Two different types of citations can be inserted - either a citation in parenthesis, "(Author 2007)", or an in-text citation, "Author (2007)". This distinction is only meaningful if author-year citations are used instead of numbered citations, but the distinction will be preserved if you switch between the two styles.</p>
-
-      <p>If you modify entries in JabRef after inserting their citations into OpenOffice, you will need to synchronize the bibliography. The <b>Sync OO bibliography</b> button will update all entries of the bibliography, provided their BibTeX keys have not been altered (JabRef encodes the BibTeX key into the reference name for each citation to keep track of which BibTeX key the original JabRef entry has).</p>
-
-      <h2>The style file</h2>
-
-      <p>You need to select a style file before connecting to OpenOffice - an external file which is selected using a standard file dialog. The style file defines the format of citations and the format of the bibliography. You can use standard JabRef export formatters to process entry fields before they are sent to OpenOffice. Through the style file, the intention is to give as much flexibility in citation styles as possible.</p>
-
-      <p>Here is an example style file:</p>
-<pre>
-NAME
-Example style file for JabRef-oo plugin.
-
-JOURNALS
-Journal name 1
-Journal name 2
-
-PROPERTIES
-Title="References"
-IsSortByPosition="false"
-IsNumberEntries="false"
-ReferenceParagraphFormat="Default"
-ReferenceHeaderParagraphFormat="Heading 1"
-
-CITATION
-AuthorField="author/editor"
-YearField="year"
-MaxAuthors="3"
-MaxAuthorsFirst="3"
-AuthorSeparator=", "
-AuthorLastSeparator=" &amp; "
-EtAlString=" et al."
-YearSeparator=" "
-InTextYearSeparator=" "
-BracketBefore="["
-BracketAfter="]"
-BracketBeforeInList="["
-BracketAfterInList="]"
-CitationSeparator="; "
-UniquefierSeparator=","
-GroupedNumbersSeparator="-"
-MinimumGroupingCount="3"
-FormatCitations="false"
-ItalicCitations="false"
-BoldCitations="false"
-SuperscriptCitations="false"
-SubscriptCitations="false"
-MultiCiteChronological="false"
-
-LAYOUT
-article=\format[AuthorLastFirst,AuthorAbbreviator,AuthorAndsReplacer]{\author}
-(&lt;b&gt;\year\uniq&lt;/b&gt;). &lt;i&gt;\title&lt;/i&gt;, \journal \volume\begin{pages} :
-\format[FormatPagesForHTML]{\pages}\end{pages}.
-
-book=\format[AuthorLastFirst,AuthorAbbreviator,AuthorAndsReplacer]{\author}\begin{editor}
-\format[AuthorLastFirst,AuthorAbbreviator,AuthorAndsReplacer]{\editor} (Ed.)\end{editor},
-&lt;b&gt;\year\uniq&lt;/b&gt;. &lt;i&gt;\title&lt;/i&gt;. \publisher, \address.
-
-incollection=\format[AuthorLastFirst,AuthorAbbreviator,AuthorAndsReplacer]{\author}
-(&lt;b&gt;\year\uniq&lt;/b&gt;). &lt;i&gt;\title&lt;/i&gt;. In: \format[AuthorLastFirst,
-AuthorAbbreviator,AuthorAndsReplacer]{\editor} (Ed.), &lt;i&gt;\booktitle&lt;/i&gt;, \publisher.
-
-inbook=\format[AuthorLastFirst,AuthorAbbreviator,AuthorAndsReplacer]{\author}
-(&lt;b&gt;\year\uniq&lt;/b&gt;). &lt;i&gt;\chapter&lt;/i&gt;. In: \format[AuthorLastFirst,
-AuthorAbbreviator,AuthorAndsReplacer]{\editor} (Ed.), &lt;i&gt;\title&lt;/i&gt;, \publisher.
-
-phdthesis=\format[AuthorLastFirst,AuthorAbbreviator,AuthorAndsReplacer]{\author}
-(&lt;b&gt;\year\uniq&lt;/b&gt;). &lt;i&gt;\title&lt;/i&gt;, \school.
-
-default=\format[AuthorLastFirst,AuthorAbbreviator,AuthorAndsReplacer]{\author}
-(&lt;b&gt;\year\uniq&lt;/b&gt;). &lt;i&gt;\title&lt;/i&gt;, \journal \volume\begin{pages} :
-\format[FormatPagesForHTML]{\pages}\end{pages}.
-
-</pre>
-
-        <p>(Note that the layout for each entry type must be constrained to a single line in the style file - above, the lines are broken up to improve readability.)</p>
-
-                       <h3>Global properties</h3>
-
-        <p>The <b>PROPERTIES</b> section describes global properties for the bibliography.
-        The following table describes the available properties:
-
-                       <table border=1 rules=none>
-                       <tr>
-                       <td><b>Property</b></td>
-                       <td><b>Type</b></td>
-                       <td><b>Default value</b></td>
-                       <td><b>Description</b></td>
-                       </tr>
-                       <tr>
-                       <td>IsNumberEntries</td>
-                       <td>boolean</td>
-                       <td><code>false</code></td>
-                       <td>Determines the type of citations to use. If <code>true</code>, number citations will be
-                       used. If <code>false</code>, author-year citations will be used.</td>
-                       </tr>
-                       <tr>
-                       <td>IsSortByPosition</td>
-                       <td>boolean</td>
-                       <td><code>false</code></td>
-                       <td>Determines how the bibliography is sorted. If true, the entries
-          will be sorted according to the order in which they are cited. If false, the entries will be
-         sorted alphabetically by authors.</td>
-                       </tr>
-                       <tr>
-                       <td>ReferenceParagraphFormat</td>
-                       <td>string</td>
-                       <td><code>Default</code></td>
-                       <td>Gives the name of the paragraph format to be used for the reference list. This format
-                       must be defined in your OpenOffice document.</td>
-                       </tr>
-                       <tr>
-                       <td>ReferenceHeaderParagraphFormat</td>
-                       <td>string</td>
-                       <td><code>Heading 1</code></td>
-                       <td>Gives the name of the paragraph format to be used for the headline of the reference list. 
-                       This format must be defined in your OpenOffice document.</td>
-                       </tr>
-                       <tr>
-                       <td>Title</td>
-                       <td>string</td>
-                       <td><code>Bibliography</code></td>
-                       <td>The text to enter as the headline of the reference list.</td>
-                       </tr>
-                       </table></p>
-                       
-                       <h3>Citation properties</h3>
-
-        <p>The <b>CITATION</b> section describes the format of the citation markers inserted into the text.
-        
-        <p>The following table gives a brief description of all the available citation properties. Properties that are not
-                 given in the style file will keep their default value.
-                 
-                 <table border=1 rules=none>
-                       <tr>
-                       <td><b>Property</b></td>
-                       <td><b>Type</b></td>
-                       <td><b>Default value</b></td>
-                       <td><b>Description</b></td>
-                       </tr>
-                       <tr>
-                       <td>AuthorField</td>
-                       <td>string</td>
-                       <td><code>author/editor</code></td>
-                       <td>BibTeX field containing author names. Can specify fallback field, e.g. <code>author/editor</code></td>
-                       </tr>
-                       <tr>
-                       <td>AuthorLastSeparator</td>
-                       <td>string</td>
-                       <td><code> & </code></td>
-                       <td>Text inserted between the two last author names.</td>
-                       </tr>
-                       <tr>
-                       <td>AuthorLastSeparatorInText</td>
-                       <td>string</td>
-                       <td>&nbsp;</td>
-                       <td>If specified, this propery overrides <code>AuthorLastSeparator</code> for in-text citations such as
-                       <code>Smith & Jones (2001)</code>.</td>
-                       </tr>
-                       <tr>
-                       <td>AuthorSeparator</td>
-                       <td>string</td>
-                       <td><code>, </code></td>
-                       <td>Text inserted between author names except the last two.</td>
-                       </tr>
-                       <tr>
-                       <td>BoldCitations</td>
-                       <td>boolean</td>
-                       <td><code>false</code></td>
-                       <td>If <code>FormatCitations</code> is on, controls whether citations should be bold.</td>
-                       </tr>
-                       <tr>
-                       <td>BracketAfter</td>
-                       <td>string</td>
-                       <td><code>]</code></td>
-                       <td>The closing bracket of citations.</td>
-                       </tr>
-                       <tr>
-                       <td>BracketAfterInList</td>
-                       <td>string</td>
-                       <td>]</td>
-                       <td>The closing bracket for citation numbering in the reference list.</td>
-                       </tr>
-                       <tr>
-                       <td>BracketBefore</td>
-                       <td>string</td>
-                       <td><code>[</code></td>
-                       <td>The opening bracket of citations</td>
-                       </tr>
-                       <tr>
-                       <td>BracketBeforeInList</td>
-                       <td>string</td>
-                       <td>[</td>
-                       <td>The opening bracket for citation numbering in the reference list.</td>
-                       </tr>
-                       <tr>
-                       <td>CitationSeparator</td>
-                       <td>string</td>
-                       <td><code>; </code></td>
-                       <td>Text inserter between items when a citation contains multiple entries, e.g. <code>[Smith 2001; Jones 2002]</code></td>
-                       </tr>
-                       <tr>
-                       <td>EtAlString</td>
-                       <td>string</td>
-                       <td><code> et al. </code></td>
-                       <td>Text inserted after author names when not all authors are listed, e.g. <code>[Smith et al. 2001]</code></td>
-                       </tr>
-                       <tr>
-                       <td>FormatCitations</td>
-                       <td>boolean</td>
-                       <td><code>false</code></td>
-                       <td>Determines whether formatting should be applied to citations. If true, formatting is controlled by
-                       properties like <code>BoldCitations</code>, <code>ItalicCitations</code>, <code>SubscriptCitations</code> 
-                       and <code>SuperscriptCitations</code>.</td>
-                       </tr>
-                       <tr>
-                       <td>GroupedNumbersSeparator</td>
-                       <td>string</td>
-                       <td><code>-</code></td>
-                       <td>Text inserted between numbers when numbered citations are grouped, e.g. <code>[4-6]</code></td>
-                       </tr>
-                       <tr>
-                       <td>InTextYearSeparator</td>
-                       <td>string</td>
-                       <td><code> </code></td>
-                       <td>Text inserted between author names and starting bracket before year in in-text citations.</td>
-                       </tr>
-                       <tr>
-                       <td>ItalicCitations</td>
-                       <td>boolean</td>
-                       <td><code>false</code></td>
-                       <td>If <code>FormatCitations</code> is on, controls whether citations should be in italics.</td>
-                       </tr>
-                       <tr>
-                       <td>MaxAuthors</td>
-                       <td>integer</td>
-                       <td><code>3</code></td>
-                       <td>The maximum number of authors to list in a citation that has appeared earlier in the document.</td>
-                       </tr>
-                       <tr>
-                       <td>MaxAuthorsFirst</td>
-                       <td>integer</td>
-                       <td><code>3</code></td>
-                       <td>The maximum number of authors to list in a citation when appearing for the first time.</td>
-                       </tr>
-                       <tr>
-                       <td>MinimumGroupingCount</td>
-                       <td>integer</td>
-                       <td><code>3</code></td>
-                       <td>The minimum number of consecutive entries a citation should contain before the numbers are grouped, 
-                       e.g. <code>[4-6]</code> vs. <code>[4; 5; 6]</code>.</td>
-                       </tr>
-                       <tr>
-                       <td>MultiCiteChronological</td>
-                       <td>boolean</td>
-                       <td><code>true</code></td>
-                       <td>If <code>true</code>, multiple entries in the same citation are sorted chronologically, otherwise
-                       they are sorted alphabetically.</td>
-                       </tr>
-                       <td>SubscriptCitations</td>
-                       <td>boolean</td>
-                       <td><code>false</code></td>
-                       <td>If <code>FormatCitations</code> is on, controls whether citations should be in subscript.</td>
-                       </tr>
-                       <td>SuperscriptCitations</td>
-                       <td>boolean</td>
-                       <td><code>false</code></td>
-                       <td>If <code>FormatCitations</code> is on, controls whether citations should be in superscript.</td>
-                       </tr>
-                       <tr>
-                       <td>UniquefierSeparator</td>
-                       <td>string</td>
-                       <td><code>, </code></td>
-                       <td>Text inserted between letters used to differentiate citations with similar authors and year. E.g.
-                       the text between <code>a</code> and <code>b</code> in <code>[Smith 2001a, b]</code>.</td>
-                       </tr>
-                       <tr>
-                       <td>YearField</td>
-                       <td>string</td>
-                       <td><code>year</code></td>
-                       <td>The BibTeX field to get publication year from.</td>
-                       </tr>
-                       <tr>
-                       <td>YearSeparator</td>
-                       <td>string</td>
-                       <td><code> </code></td>
-                       <td>Text inserted between author names and year in parenthesis citations such as <code>[Smith 2001]</code>.</td>
-                       </tr>
-                       
-                       </table></p>
-
-        If numbered entries are used, the <code>BracketBefore</code> and <code>BracketAfter</code> properties
-        are the most important - they define which characters the citation number is wrapped in. The citation is composed
-        as follows:<br />
-            <code>[BracketBefore][Number][BracketAfter]</code><br />
-        where [Number] is the number of the citation, determined according to the ordering of the bibliography and/or
-        the position of the citation in the text. If a citation refers to several entries, these will be separated
-        by the string given in the property <code>CitationSeparator</code> (for instance, if <code>CitationSeparator</code>=;,
-        the citation could look like <code>[2;4;6]</code>). If two or more of the entries have a series of consecutive
-        numbers, the numbers can be grouped (for instance <code>[2-4]</code> for 2, 3 and 4 or <code>[2;5-7]</code> for
-        2, 5, 6 and 7). The property <code>GroupedNumbersSeparator</code> (default <code>-</code>) determines which string separates the first and last
-        of the grouped numbers. The integer property <code>MinimumGroupingCount</code> (default 3) determines what number of
-        consecutive numbers are required before entries are grouped. If <code>MinimumGroupingCount</code>=3, the numbers
-        2 and 3 will not be grouped, while 2, 3, 4 will be. If <code>MinimumGroupingCount</code>=0, no grouping will be
-        done regardless of the number of consecutive numbers.
-        </p>
-        <p>If numbered entries are not used, author-year citations will be created based on the citation properties.
-        A parenthesis citation is composed as follows:<br />
-            <code>[BracketBefore][Author][YearSeparator][Year][BracketAfter]</code><br />
-        where [Author] is the result of looking up the field or fields given in the <code>AuthorField</code> property,
-        and formatting a list of authors. The list can contain up to <code>MaxAuthors</code> names - if more are present,
-        the list will be composed as the first author plus the text specified in the property <code>EtAlString</code>.
-       If the property <code>MaxAuthorsFirst</code> is given, it overrides <code>MaxAuthors</code> the first time each
-        citation appears in the text.</p>
-       <p>If several, slash-separated, fields are given in the <code>AuthorField</code> property, they will be looked up
-        successively if the first field is empty for the given BibTeX entry. In the example above, the "author" field will
-        be used, but if empty, the "editor" field will be used as a backup.</p>
-        <p>The names in the author list will be separated by the text given by the <code>AuthorSeparator</code>
-        property, except for the last two names, which will be separated by the text given by <code>AuthorLastSeparator</code>.
-       If the property <code>AuthorLastSeparatorInText</code> is given, it overrides the former for citations of the in-text
-        type. This makes it possible to get citations like <code>(Olsen &amp; Jensen, 2008)</code> and <code>Olsen and Jensen (2008)</code>
-        for the same style.
-        </p>
-        <p>[Year] is the result of looking up the field or fields given in the [YearField] property.</p>
-        <p>An in-text citation is composed as follows:<br />
-            <code>[Author][InTextYearSeparator][BracketBefore][Year][BracketAfter]</code><br />
-        where [Author] and [Year] are resolved in exactly the same way as for the parenthesis citations.
-        </p>
-        <p>If two different cited sources have the same authors and publication year, and author-year citations are used,
-        their markers will need modification in order to be distinguishable. This is done automatically by appending a
-        letter after the year for
-        each of the publications; 'a' for the first cited reference, 'b' for the next, and so on.
-        For instance, if the author "Olsen" has two cited papers from 2005, the citation markers will be modified to
-        <code>(Olsen, 2005a)</code> and <code>(Olsen, 2005b)</code>. In the bibliography
-        layout, the placement of the "uniquefier" letter is indicated explicitly by inserting the virtual field
-        <code>uniq</code>.</p>
-        <p>If several entries that have been "uniquefied" are cited together, they will be grouped in the citation
-        marker. For instance, of the two entries in the example above are cited together, the citation marker will
-        be <code>(Olsen, 2005a, b)</code> rather than <code>Olsen, 2005a; Olsen, 2005b)</code>. The grouped uniquefier
-        letters (a and b in our example) will be separated by the string specified by the <code>UniquefierSeparator</code>
-        property.
-        </p>
-       <p>Author-year citations referring more than one entry will by default be sorted chronologically. If you wish them
-       to be sorted alphabetically, the citation property <code>MultiCiteChronological</code> should be set to <code>false.</code>.</p>
-        <p>The property <code>FormatCitations</code> determines whether the citation markers should be formatted with
-        regards to italics, boldness, superscript and subscript. If <code>FormatCitations</code> is false, no such formatting
-        will be done. If true, the citations will be italicized or not depending on the <code>ItalicCitations</code> property, set to bold
-        or not depending on the <code>BoldCitations</code> property, and similar for the <code>SuperscriptCitations</code> and
-        <code>SubscriptCitations</code> properties.</p>
-
-                         
-        <h3>Reference list layout</h3>
-        
-        <p>The <b>LAYOUT</b> section describes how the bibliography entry for each entry type in JabRef
-        should appear. Each line should start with either the name of a BibTeX entry type, or the word
-        <code>default</code>, followed by a '='. The <code>default</code> layout will be used for all
-        entry types for which an explicit layout hasn't been given.</p>
-        <p>The remainder of each line defines the layout, with normal text and spaces appearing literally
-        in the bibliography entry. Information from the BibTeX entry is inserted by adding <code>\field</code> markers
-        with the appropriate field name (e.g. <code>\author</code> for inserting the author names). Formatting
-        information for the field can be included here, following JabRef's standard export layout syntax.
-        Refer to <a href="http://jabref.sourceforge.net/help/CustomExports.php">JabRef's documentation on custom export filters</a>
-        for more information about which formatters are available.</p>
-        <p>If author-year citations are used, you have to explicitly specify the position of the "uniquefier" letter
-        that is added to distinguish similar-looking citations. This is done by including a marker for the virtual field
-        <code>uniq</code>, typically right after the year (as shown in the example style file). The <code>uniq</code>
-        field is automatically set correctly for each entry before its reference text is laid out.
-        </p>
-        <p>To indicate formatting in the bibliography, you can use the HTML-like tag pairs &lt;b&gt; &lt;/b&gt;,
-         &lt;i&gt; &lt;/i&gt;,  &lt;sup&gt; &lt;/sup&gt; and  &lt;sub&gt; &lt;/sub&gt; to specify bold text,
-         italic text, superscript and subscript, respectively.</p>
-        <p>If you are using numbered citations, the number for each entry will be automatically inserted at the start
-        of each entry in the reference list. By default, the numbers will be enclosed in the same brackets defined for
-        citations. The optional citation properties <code>BracketBeforeInList</code> and
-        <code>BracketAfterInList</code> override <code>BracketBefore</code> and <code>BracketAfter</code> if set. These
-        can be used if you want different types of brackets (or no brackets) in the reference list. Note that these need
-        not be brackets as such - they can be any combination of characters.</p>
-
-      <h2>Known issues</h2>
-
-      <ul>
-        <li>When running with JabRef versions older than 2.6, institutional authors wrapped in braces, e.g. <code>{World Bank}</code>, are handled as if no braces were added. This happens because the OO-specific formatter, which removes the braces, can only be run after (instead of before) all other formatters in JabRef 2.6 or newer.</li>
-        <li>Make sure to save your Writer document in OpenDocument format (odt). Saving to Word format will lose your reference marks.</li>
-        <li>There is currently no support for footnote based citations.</li>
-        <li>The cursor may be poorly positioned after inserting a citation.</li>
-        <li>Copy-pasting the example style file directly from this page can give an unparseable file. To avoid this, instead download the example file from the link in the download section.</li>
-      </ul>
-
-      <h2>Contact</h2>
-
-      <p>If you have tested this plugin, and want to give your feedback, or if you want to contribute to the development of the plugin, please contact me at the e-mail address mortenalver at users.sourceforge.net.</p>
-
-    </div>
-    <?php include("footer.php"); ?>
-  </div>
-
-</body>
-</html>
index 307b830b9594185f34273f6c0cf3e8b688e0e1a1..e86bab4ac769455ccf429bf1bb48c838c77ede6e 100755 (executable)
--- a/build.xml
+++ b/build.xml
@@ -12,7 +12,7 @@
 <project name="net.sf.jabref.oo.ooplugin" default="jar" basedir=".">
 
        <!-- Properties -->
-       <property name="version" value="0.8" />
+       <property name="version" value="0.9" />
        <property name="build.classes" value="classes" />
        <property name="jabref.build.dir" value="lib" />
     <property name="jar.dir" value="dist" />
index dfe93ad39b231d595a90b5de288385f2776db99c..29ed29ca078aab8116154eb937d9714b2b64d105 100755 (executable)
@@ -13,6 +13,7 @@ ReferenceParagraphFormat="Text body"
 ReferenceHeaderParagraphFormat="Heading 2"
 
 CITATION
+BibtexKeyCitations=false
 AuthorField="author/editor"
 YearField="year"
 MaxAuthors="2"
@@ -32,10 +33,7 @@ UniquefierSeparator=","
 GroupedNumbersSeparator="-"
 MinimumGroupingCount="3"
 FormatCitations="false"
-ItalicCitations="false"
-BoldCitations="false"
-SuperscriptCitations="false"
-SubscriptCitations="false"
+CitationCharacterFormat="Default"
 MultiCiteChronological="true"
 
 LAYOUT
diff --git a/net/sf/jabref/oo/AdvancedCiteDialog.java b/net/sf/jabref/oo/AdvancedCiteDialog.java
new file mode 100644 (file)
index 0000000..37ebcdb
--- /dev/null
@@ -0,0 +1,109 @@
+package net.sf.jabref.oo;
+
+import com.jgoodies.forms.builder.ButtonBarBuilder;
+import com.jgoodies.forms.builder.DefaultFormBuilder;
+import com.jgoodies.forms.layout.FormLayout;
+import net.sf.jabref.Globals;
+import net.sf.jabref.JabRefFrame;
+
+import javax.swing.*;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+import java.awt.*;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+
+/**
+ * Dialog for adding citation with page number info.
+ */
+public class AdvancedCiteDialog {
+
+    static boolean defaultInPar = true;
+    boolean okPressed = false;
+    JDialog diag;
+    JRadioButton inPar = new JRadioButton(Globals.lang("Cite selected entries")),
+        inText = new JRadioButton(Globals.lang("Cite selected entries with in-text citation"));
+    JTextField pageInfo = new JTextField(15);
+    JButton ok = new JButton(Globals.lang("Ok")),
+        cancel = new JButton(Globals.lang("Cancel"));
+
+    public AdvancedCiteDialog(JabRefFrame parent) {
+        diag = new JDialog(parent, Globals.lang("Cite special"), true);
+        ButtonGroup bg = new ButtonGroup();
+        bg.add(inPar);
+        bg.add(inText);
+        if (defaultInPar)
+            inPar.setSelected(true);
+        else
+            inText.setSelected(true);
+        
+        inPar.addChangeListener(new ChangeListener() {
+            public void stateChanged(ChangeEvent changeEvent) {
+                defaultInPar = inPar.isSelected();
+            }
+        });
+        
+        DefaultFormBuilder b = new DefaultFormBuilder
+                (new FormLayout("left:pref, 4dlu, fill:pref", ""));
+        b.append(inPar, 3);
+        b.nextLine();
+        b.append(inText, 3);
+        b.nextLine();
+        b.append(Globals.lang("Extra information (e.g. page number)")+":");
+        b.append(pageInfo);
+
+        b.getPanel().setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
+        diag.getContentPane().add(b.getPanel(), BorderLayout.CENTER);
+
+        ButtonBarBuilder bb = new ButtonBarBuilder();
+        bb.addGlue();
+        bb.addGridded(ok);
+        bb.addGridded(cancel);
+        bb.addGlue();
+        bb.getPanel().setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
+        diag.getContentPane().add(bb.getPanel(), BorderLayout.SOUTH);
+
+        diag.pack();
+
+        Action okAction = new AbstractAction() {
+            public void actionPerformed(ActionEvent actionEvent) {
+                okPressed = true;
+                diag.dispose();
+            }
+        };
+        ok.addActionListener(okAction);
+        pageInfo.addActionListener(okAction);
+        inPar.addActionListener(okAction);
+        inText.addActionListener(okAction);
+        Action cancelAction = new AbstractAction() {
+            public void actionPerformed(ActionEvent actionEvent) {
+                okPressed = false;
+                diag.dispose();
+            }
+        };
+        cancel.addActionListener(cancelAction);
+        b.getPanel().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
+                .put(Globals.prefs.getKey("Close dialog"), "close");
+        b.getPanel().getActionMap().put("close", cancelAction);
+        
+    }
+
+    public void showDialog() {
+        diag.setLocationRelativeTo(diag.getParent());
+        diag.setVisible(true);
+    }
+
+    public boolean cancelled() {
+        return !okPressed;
+    }
+
+    public String getPageInfo() {
+        return pageInfo.getText().trim();
+    }
+
+    public boolean isInParenthesisCite() {
+        return inPar.isSelected();
+    }
+}
diff --git a/net/sf/jabref/oo/CitationManager.java b/net/sf/jabref/oo/CitationManager.java
new file mode 100644 (file)
index 0000000..1ba0fb8
--- /dev/null
@@ -0,0 +1,245 @@
+package net.sf.jabref.oo;
+
+import ca.odell.glazedlists.BasicEventList;
+import ca.odell.glazedlists.EventList;
+import ca.odell.glazedlists.SortedList;
+import ca.odell.glazedlists.gui.TableFormat;
+import ca.odell.glazedlists.swing.EventTableModel;
+import com.jgoodies.forms.builder.ButtonBarBuilder;
+import com.jgoodies.forms.builder.DefaultFormBuilder;
+import com.jgoodies.forms.layout.FormLayout;
+import com.sun.star.container.XNameAccess;
+import net.sf.jabref.Globals;
+import net.sf.jabref.JabRefFrame;
+import net.sf.jabref.gui.FileListEntry;
+
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.ActionEvent;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.util.List;
+
+/**
+ * Dialog for modifying existing citations.
+ */
+public class CitationManager {
+
+    OOBibBase ooBase;
+    JDialog diag;
+    EventList<CitEntry> list;
+    JTable table;
+    EventTableModel tableModel;
+    JButton ok = new JButton(Globals.lang("Ok")),
+        cancel = new JButton(Globals.lang("Cancel"));
+
+    public CitationManager(final JabRefFrame frame, OOBibBase ooBase) throws Exception {
+        diag = new JDialog(frame, Globals.lang("Manage citations"), true);
+        this.ooBase = ooBase;
+
+        list = new BasicEventList<CitEntry>();
+        XNameAccess nameAccess = ooBase.getReferenceMarks();
+        String[] names = ooBase.getJabRefReferenceMarks(nameAccess);
+        for (int i=0; i<names.length; i++) {
+            String name = names[i];
+            List<String> keys = ooBase.parseRefMarkName(name);
+            list.add(new CitEntry(name, keys,
+                    "<html>..."+ooBase.getCitationContext(nameAccess, name, 30, 30, true)+"...</html>",
+                    ooBase.getCustomProperty(name)));
+        }
+        tableModel = new EventTableModel(list, new CitEntryFormat());
+        table = new JTable(tableModel);
+        diag.add(new JScrollPane(table), BorderLayout.CENTER);
+
+        ButtonBarBuilder bb = new ButtonBarBuilder();
+        bb.addGlue();
+        bb.addGridded(ok);
+        bb.addGridded(cancel);
+        bb.addGlue();
+        bb.getPanel().setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
+        diag.add(bb.getPanel(), BorderLayout.SOUTH);
+
+        diag.pack();
+        diag.setSize(700, 400);
+
+        Action okAction = new AbstractAction() {
+            public void actionPerformed(ActionEvent actionEvent) {
+                try {
+                    storeSettings();
+                } catch (Exception ex) {
+                    ex.printStackTrace();
+                    JOptionPane.showMessageDialog(frame, Globals.lang("Problem modifying citation"));
+                }
+                diag.dispose();
+            }
+        };
+        ok.addActionListener(okAction);
+
+        Action cancelAction = new AbstractAction() {
+            public void actionPerformed(ActionEvent actionEvent) {
+                diag.dispose();
+            }
+        };
+        cancel.addActionListener(cancelAction);
+
+        bb.getPanel().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put
+                (Globals.prefs.getKey("Close dialog"), "close");
+        bb.getPanel().getActionMap().put("close", cancelAction);
+
+        table.getColumnModel().getColumn(0).setPreferredWidth(600);
+        table.getColumnModel().getColumn(1).setPreferredWidth(90);
+        table.setPreferredScrollableViewportSize(new Dimension(700, 500));
+        table.addMouseListener(new TableClickListener());
+    }
+
+    private void storeSettings() throws Exception {
+        for (CitEntry entry : list) {
+            if (entry.pageInfoChanged()) {
+                ooBase.setCustomProperty(entry.refMarkName, entry.pageInfo);
+            }
+        }
+    }
+
+    public void showDialog() {
+        diag.setLocationRelativeTo(diag.getParent());
+        diag.setVisible(true);
+    }
+
+    class CitEntry implements Comparable {
+        String refMarkName, pageInfo, keyString, context, origPageInfo;
+        List<String> keys;
+
+        public CitEntry(String refMarkName, List<String> keys, String context, String pageInfo) {
+            this.refMarkName = refMarkName;
+            this.keys = keys;
+            this.context = context;
+            this.pageInfo = pageInfo;
+            this.origPageInfo = pageInfo;
+            StringBuilder sb = new StringBuilder();
+            for (int j=0; j<keys.size(); j++) {
+                sb.append(keys.get(j));
+                if (j < keys.size()-1)
+                    sb.append(", ");
+            }
+            keyString = sb.toString();
+        }
+
+        public boolean pageInfoChanged() {
+            if (((pageInfo != null) && (origPageInfo == null))
+                || ((pageInfo == null) && (origPageInfo != null)))
+                return true;
+            if (pageInfo != null)
+                return pageInfo.compareTo(origPageInfo) != 0;
+            else return false;
+        }
+
+        public int compareTo(Object o) {
+            CitEntry other = (CitEntry)o;
+            return this.refMarkName.compareTo(other.refMarkName);
+        }
+    }
+
+    class CitEntryFormat implements TableFormat<CitEntry> {
+
+        public int getColumnCount() {
+            return 2;
+        }
+
+        public String getColumnName(int i) {
+            switch (i) {
+                case 0: return Globals.lang("Citation");
+                //case 1: return Globals.lang("Context");
+                default: return Globals.lang("Extra information");
+            }
+        }
+
+        public Object getColumnValue(CitEntry citEntry, int i) {
+            switch (i) {
+                //case 0: return citEntry.keyString;
+                case 0: return citEntry.context;
+                default: return citEntry.pageInfo != null ? citEntry.pageInfo : "";
+            }
+        }
+    }
+
+    class TableClickListener extends MouseAdapter {
+
+        public void mouseClicked(MouseEvent e) {
+            if ((e.getButton() == MouseEvent.BUTTON1) && (e.getClickCount() == 2)) {
+                int row = table.rowAtPoint(e.getPoint());
+                if (row >= 0) {
+                    SingleCitDialog scd = new SingleCitDialog(list.get(row));
+                    scd.showDialog();
+                }
+            }
+            //else if (e.isPopupTrigger())
+            //    processPopupTrigger(e);
+        }
+    }
+
+    class SingleCitDialog {
+        JDialog diag;
+        JTextField pageInfo = new JTextField(20);
+        JLabel title;
+        JButton ok = new JButton(Globals.lang("Ok")),
+                cancel = new JButton(Globals.lang("Cancel"));
+        CitEntry _entry;
+
+        public SingleCitDialog(CitEntry entry) {
+            this._entry = entry;
+            title = new JLabel(entry.context);
+            pageInfo.setText(entry.pageInfo);
+
+            diag = new JDialog(CitationManager.this.diag, Globals.lang("Citation"), true);
+
+            DefaultFormBuilder b = new DefaultFormBuilder(
+                    new FormLayout("left:pref, 4dlu, left:150dlu", ""));
+            b.append(title, 3);
+            b.nextLine();
+            b.append(Globals.lang("Extra information (e.g. page number)"));
+            b.append(pageInfo);
+            b.getPanel().setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
+            diag.getContentPane().add(b.getPanel(), BorderLayout.CENTER);
+
+            ButtonBarBuilder bb = new ButtonBarBuilder();
+            bb.addGlue();
+            bb.addGridded(ok);
+            bb.addGridded(cancel);
+            bb.addGlue();
+            bb.getPanel().setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
+            diag.add(bb.getPanel(), BorderLayout.SOUTH);
+
+
+            Action okAction = new AbstractAction() {
+                public void actionPerformed(ActionEvent actionEvent) {
+                    if (pageInfo.getText().trim().length() > 0) {
+                        _entry.pageInfo = pageInfo.getText().trim();
+                    }
+                    else
+                        _entry.pageInfo = null;
+                    tableModel.fireTableDataChanged();
+                    diag.dispose();
+                }
+            };
+            ok.addActionListener(okAction);
+
+            Action cancelAction = new AbstractAction() {
+                public void actionPerformed(ActionEvent actionEvent) {
+                    diag.dispose();
+                }
+            };
+            cancel.addActionListener(cancelAction);
+
+            b.getPanel().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put
+                    (Globals.prefs.getKey("Close dialog"), "close");
+            b.getPanel().getActionMap().put("close", cancelAction);
+
+        }
+
+        public void showDialog() {
+            diag.pack();
+            diag.setLocationRelativeTo(diag.getParent());
+            diag.setVisible(true);
+        }
+    }
+}
index dffa92391c1dbec7b2645e7694be3d8a3fabce60..81153df6a63a9eed03c98e9bf76dff0647e2b6c6 100755 (executable)
@@ -2,14 +2,21 @@ package net.sf.jabref.oo;
 
 import com.sun.star.awt.Point;
 import com.sun.star.awt.XWindow;
+import com.sun.star.beans.XPropertyContainer;
 import com.sun.star.beans.XPropertySet;
 import com.sun.star.beans.PropertyValue;
+import com.sun.star.beans.XPropertySetInfo;
 import com.sun.star.comp.helper.Bootstrap;
 import com.sun.star.container.*;
+import com.sun.star.container.NoSuchElementException;
+import com.sun.star.document.XDocumentProperties;
+import com.sun.star.document.XDocumentPropertiesSupplier;
 import com.sun.star.frame.*;
 import com.sun.star.lang.*;
 import com.sun.star.lang.Locale;
 import com.sun.star.text.*;
+import com.sun.star.uno.Any;
+import com.sun.star.uno.Type;
 import com.sun.star.uno.UnoRuntime;
 import com.sun.star.uno.XComponentContext;
 import net.sf.jabref.*;
@@ -34,7 +41,7 @@ public class OOBibBase {
     final static String BIB_SECTION_NAME = "JR_bib";
     final static String BIB_SECTION_END_NAME = "JR_bib_end";
     final static String BIB_CITATION = "JR_cite";
-    final Pattern citePattern = Pattern.compile(BIB_CITATION+"\\d*_(\\d*)_(.*)");
+    public final Pattern citePattern = Pattern.compile(BIB_CITATION+"\\d*_(\\d*)_(.*)");
 
     final static int
         AUTHORYEAR_PAR = 1,
@@ -55,6 +62,9 @@ public class OOBibBase {
     XTextViewCursorSupplier xViewCursorSupplier = null;
     XComponent xCurrentComponent = null;
     XComponentLoader xComponentLoader = null;
+    XPropertyContainer userProperties = null;
+    XPropertySet propertySet = null;
+
     private boolean atEnd;
     private AlphanumericComparator entryComparator = new AlphanumericComparator();
     private YearComparator yearComparator = new YearComparator();
@@ -128,6 +138,12 @@ public class OOBibBase {
         // Access the text document's multi service factory:
         mxDocFactory = (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, mxDoc);
 
+
+        XDocumentPropertiesSupplier supp =
+                UnoRuntime.queryInterface(XDocumentPropertiesSupplier.class, mxDoc);
+        userProperties = supp.getDocumentProperties().getUserDefinedProperties();
+        propertySet = UnoRuntime.queryInterface(XPropertySet.class, userProperties);
+
     }
 
     public XDesktop simpleBootstrap(String pathToExecutable) throws Exception {
@@ -190,6 +206,34 @@ public class OOBibBase {
          return res;
      }
 
+    public void testCustomProperties() throws Exception {
+        XDocumentPropertiesSupplier supp = (XDocumentPropertiesSupplier)UnoRuntime.queryInterface(
+                XDocumentPropertiesSupplier.class, mxDoc);
+        XPropertyContainer cont = supp.getDocumentProperties().getUserDefinedProperties();
+        XPropertySet set = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, cont);
+        try {
+            cont.addProperty("JR_cite_1_Danielsen1987", (short)0, new Any(Type.STRING, "Brum"));
+        } catch (Exception ex) {
+            System.out.println("property already exists");
+        }
+        System.out.println(set.getPropertyValue("Test").toString());
+
+    }
+
+    public void setCustomProperty(String property, String value) throws Exception {
+        if (propertySet.getPropertySetInfo().hasPropertyByName(property))
+            userProperties.removeProperty(property);
+        if (value != null)
+            userProperties.addProperty(property, com.sun.star.beans.PropertyAttribute.REMOVEABLE,
+                   new Any(Type.STRING, value));
+    }
+    
+    public String getCustomProperty(String property) throws Exception {
+        if (propertySet.getPropertySetInfo().hasPropertyByName(property))
+            return propertySet.getPropertyValue(property).toString();
+        else return null;
+
+    }
 
      public void updateSortedReferenceMarks() throws Exception {
          XReferenceMarksSupplier supplier = (XReferenceMarksSupplier) UnoRuntime.queryInterface(
@@ -213,9 +257,11 @@ public class OOBibBase {
      * @throws Exception
      */
     public void insertEntry(BibtexEntry[] entries, BibtexDatabase database, OOBibStyle style,
-                            boolean inParenthesis, boolean withText, boolean sync) throws Exception {
+                            boolean inParenthesis, boolean withText, String pageInfo,
+                            boolean sync) throws Exception {
 
         try {
+
             XTextViewCursor xViewCursor = xViewCursorSupplier.getViewCursor();
 
             if (entries.length > 1) {
@@ -238,11 +284,32 @@ public class OOBibBase {
                     withText ? (inParenthesis ? AUTHORYEAR_PAR : AUTHORYEAR_INTEXT) : INVISIBLE_CIT);
             //XTextContent content = insertBookMark(bName, xViewCursor);
 
+            // If we should store metadata for page info, do that now:
+            if (pageInfo != null) {
+                System.out.println("Storing page info: "+pageInfo);
+                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 = (XPropertySet) UnoRuntime.queryInterface(
+                                    XPropertySet.class, xViewCursor);
+                String charStyle = style.getCitationCharacterFormat();
+                try {
+                    xCursorProps.setPropertyValue("CharStyleName", charStyle);
+                } catch (Throwable ex) {
+                    // Setting the character format failed, so we throw an exception that
+                    // will result in an error message for the user. Before that,
+                    // delete the space we inserted:
+                    xViewCursor.goLeft((short)1,true);
+                    xViewCursor.setString("");
+                    throw new UndefinedCharacterFormatException(charStyle);
+                }
+            }
             xViewCursor.goLeft((short)1,false);
             insertReferenceMark(bName, citeText, xViewCursor, withText, style);
             //xViewCursor.collapseToEnd();
@@ -281,11 +348,10 @@ public class OOBibBase {
      * @param database The database to get entries from.
      * @param style The bibliography style to use.
      * @return A list of those referenced BibTeX keys that could not be resolved.
-     * @throws UndefinedParagraphFormatException
      * @throws Exception
      */
     public List<String> refreshCiteMarkers(BibtexDatabase database, OOBibStyle style) throws
-            UndefinedParagraphFormatException, Exception {
+            Exception {
         try {
             return refreshCiteMarkersInternal(database, style);
         } catch (DisposedException ex) {
@@ -296,16 +362,32 @@ public class OOBibBase {
         }
     }
 
+    public XNameAccess getReferenceMarks() {
+        XReferenceMarksSupplier supplier = (XReferenceMarksSupplier) UnoRuntime.queryInterface(
+                XReferenceMarksSupplier.class, xCurrentComponent);
+        return supplier.getReferenceMarks();
+    }
+
+    public String[] getJabRefReferenceMarks(XNameAccess nameAccess) {
+        String[] names = nameAccess.getElementNames();
+        // Remove all reference marks that don't look like JabRef citations:
+        ArrayList<String> tmp = new ArrayList<String>();
+        for (int i = 0; i < names.length; i++) {
+            if (citePattern.matcher(names[i]).find())
+                tmp.add(names[i]);
+        }
+        names = tmp.toArray(new String[tmp.size()]);
+        return names;
+    }
+
     private List<String> refreshCiteMarkersInternal(BibtexDatabase database, OOBibStyle style) throws
-            UndefinedParagraphFormatException, Exception {
+            Exception {
 
         List<String> cited = findCitedKeys();
         List<BibtexEntry> entries = findCitedEntries(database, cited);
 
-        XReferenceMarksSupplier supplier = (XReferenceMarksSupplier) UnoRuntime.queryInterface(
-                XReferenceMarksSupplier.class, xCurrentComponent);
-        XNameAccess nameAccess = supplier.getReferenceMarks();
-        
+        XNameAccess nameAccess = getReferenceMarks();
+
         String[] names;
         if (style.isSortByPosition()) {
             // We need to sort the reference marks according to their order of appearance:
@@ -371,7 +453,18 @@ public class OOBibBase {
 
                 String[] normCitMarker = new String[keys.length];
                 String citationMarker;
-                if (style.isNumberEntries()) {
+                if (style.isBibtexKeyCiteMarkers()) {
+                    StringBuilder sb = new StringBuilder();
+                    normCitMarkers[i] = new String[keys.length];
+                    for (int j=0; j<keys.length; j++) {
+                        normCitMarkers[i][j] = cEntries[j].getCiteKey();
+                        sb.append(cEntries[j].getCiteKey());
+                        if (j < keys.length-1)
+                            sb.append(",");
+                    }
+                    citationMarker = sb.toString();
+                }
+                else if (style.isNumberEntries()) {
                     if (style.isSortByPosition()) {
                         // We have sorted the citation markers according to their order of appearance,
                         // so we simply count up for each marker referring to a new entry:
@@ -441,7 +534,7 @@ public class OOBibBase {
         }
 
         uniquefiers.clear();
-        if (!style.isNumberEntries()) {
+        if (!style.isBibtexKeyCiteMarkers() && !style.isNumberEntries()) {
             // See if there are duplicate citations marks referring to different entries. If so, we need to
             // use uniquefiers:
             HashMap<String,List<String>> refKeys = new HashMap<String, List<String>>();
@@ -523,13 +616,34 @@ public class OOBibBase {
 
         // Refresh all reference marks with the citation markers we computed:
         boolean hadBibSection = getBookmarkRange(BIB_SECTION_NAME) != null;
+        // Check if we are supposed to set a character format for citations:
+        boolean mustTestCharFormat = style.isFormatCitations();
         for (int i = 0; i < names.length; i++) {
             Object o = nameAccess.getByName(names[i]);
             XTextContent bm = (XTextContent) UnoRuntime.queryInterface
                     (XTextContent.class, o);
 
             XTextCursor cursor = bm.getAnchor().getText().createTextCursorByRange(bm.getAnchor());
+
+            if (mustTestCharFormat) {
+                // If we are supposed to set character format for citations, must run a test before we
+                // delete old citation markers. Otherwise, if the specified character format doesn't
+                // exist, we end up deleting the markers before the process crashes due to a the missing
+                // format, with catastrophic consequences for the user.
+                mustTestCharFormat = false; // need to do this only once
+                XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(
+                                    XPropertySet.class, cursor);
+                String charStyle = style.getCitationCharacterFormat();
+                try {
+                    xCursorProps.setPropertyValue("CharStyleName", charStyle);
+                } catch (Throwable ex) {
+                    throw new UndefinedCharacterFormatException(charStyle);
+                }
+            }
+
+
             text.removeTextContent(bm);
+
             insertReferenceMark(names[i], citMarkers[i], cursor, types[i] != INVISIBLE_CIT, style);
             if (hadBibSection && (getBookmarkRange(BIB_SECTION_NAME) == null)) {
                 // We have overwritten the marker for the start of the reference list.
@@ -671,6 +785,7 @@ public class OOBibBase {
         List<BibtexEntry> entries = findCitedEntries(database, cited);
         
         String[] names = sortedReferenceMarks;
+        
         if (style.isSortByPosition()) {
             // We need to sort the entries according to their order of appearance:
            entries = getSortedEntriesFromSortedRefMarks(names, database, entries);
@@ -678,8 +793,7 @@ public class OOBibBase {
         else {
             Collections.sort(entries, entryComparator);
         }
-        
-        clearBibTextSectionContent();
+        clearBibTextSectionContent2();
         populateBibTextSection(database, entries, style);
     }
 
@@ -814,6 +928,48 @@ public class OOBibBase {
             return null;
     }
 
+    public String getCitationContext(XNameAccess nameAccess, String refMarkName,
+                                     int charBefore, int charAfter,
+                                     boolean htmlMarkup) throws Exception {
+        Object o = nameAccess.getByName(refMarkName);
+        XTextContent bm = (XTextContent) UnoRuntime.queryInterface
+                (XTextContent.class, o);
+
+        XTextCursor cursor = bm.getAnchor().getText().createTextCursorByRange(bm.getAnchor());
+        String citPart = cursor.getString();
+        int flex = 8;
+        for (int i=0; i<charBefore; i++) {
+            try {
+                cursor.goLeft((short)1, true);
+                if ((i >= charBefore-flex) && Character.isWhitespace(cursor.getString().charAt(0)))
+                    break;
+            } catch (Exception ex) {
+                ex.printStackTrace();
+            }
+        }
+        int length = cursor.getString().length();
+        int added = length - citPart.length();
+        cursor.collapseToStart();
+        for (int i=0; i<charAfter+length; i++) {
+            try {
+                cursor.goRight((short)1, true);
+                if (i >= charAfter+length-flex) {
+                    String strNow = cursor.getString();
+                    if (Character.isWhitespace(strNow.charAt(strNow.length()-1)))
+                        break;
+                }
+            } catch (Exception ex) {
+                ex.printStackTrace();
+            }
+        }
+
+        String result = cursor.getString();
+        if (htmlMarkup) {
+            result = result.substring(0, added)+"<b>"+citPart+
+                    "</b>"+result.substring(length);
+        }
+        return result.trim();
+    }
 
     public void insertFullReferenceAtCursor(XTextCursor cursor, BibtexDatabase database,
                                             List<BibtexEntry> entries,
@@ -883,14 +1039,53 @@ public class OOBibBase {
         return false;
     }
 
+    public void createBibTextSection2(boolean end) throws Exception {
+
+        XTextCursor mxDocCursor = text.createTextCursor();
+        if (end)
+            mxDocCursor.gotoEnd(false);
+        OOUtil.insertParagraphBreak(text, mxDocCursor);
+        // Create a new TextSection from the document factory and access it's XNamed interface
+        XNamed xChildNamed = UnoRuntime.queryInterface(
+          XNamed.class, mxDocFactory.createInstance("com.sun.star.text.TextSection"));
+        // Set the new sections name to 'Child_Section'
+        xChildNamed.setName(BIB_SECTION_NAME);
+        // Access the Child_Section's XTextContent interface and insert it into the document
+         XTextContent xChildSection = (XTextContent) UnoRuntime.queryInterface(
+             XTextContent.class, xChildNamed);
+         text.insertTextContent (mxDocCursor, xChildSection, false);
+        
+    }
+
+    public void clearBibTextSectionContent2() throws Exception {
+
+        // Check if the section exists:
+        boolean exists = false;
+        XTextSectionsSupplier supp = UnoRuntime.queryInterface(
+                XTextSectionsSupplier.class, mxDoc);
+        try {
+            XTextSection section = (XTextSection)((Any)supp.getTextSections().getByName(BIB_SECTION_NAME)).getObject();
+            // Clear it:
+            XTextCursor cursor = text.createTextCursorByRange(section.getAnchor());
+            cursor.gotoRange(section.getAnchor(), false);
+            cursor.setString("");
+
+        } catch (NoSuchElementException ex) {
+            createBibTextSection2(atEnd);
+        }
+    }
+
     public void clearBibTextSectionContent() throws Exception {
         // Get a range comparator:
         XTextRangeCompare compare = (XTextRangeCompare) UnoRuntime.queryInterface
                 (XTextRangeCompare.class, text);
         // Find the bookmarks for the bibliography:
         XTextRange range = getBookmarkRange(BIB_SECTION_NAME);
-        if (range == null)
+        if (range == null) {
             createBibTextSection(atEnd);
+        }
+
+
         XTextRange rangeEnd = getBookmarkRange(BIB_SECTION_END_NAME);
         if (rangeEnd == null) {
             // No end bookmark. This means that there is no bibliography.
@@ -916,8 +1111,10 @@ public class OOBibBase {
     public void populateBibTextSection(BibtexDatabase database, List<BibtexEntry> entries,
                                        OOBibStyle style)
             throws UndefinedParagraphFormatException, Exception {
-        XTextRange range = getBookmarkRange(BIB_SECTION_NAME);
-        XTextCursor cursor = text.createTextCursorByRange(range.getEnd());
+        XTextSectionsSupplier supp = UnoRuntime.queryInterface(XTextSectionsSupplier.class, mxDoc);
+        XTextSection section = (XTextSection)((Any)supp.getTextSections().getByName(BIB_SECTION_NAME))
+                    .getObject();
+        XTextCursor cursor = text.createTextCursorByRange(section.getAnchor());
         OOUtil.insertTextAtCurrentLocation(text, cursor, (String)style.getProperty("Title"),
                 (String)style.getProperty("ReferenceHeaderParagraphFormat"));
         insertFullReferenceAtCursor(cursor, database, entries, style,
@@ -944,6 +1141,14 @@ public class OOBibBase {
     public void insertReferenceMark(String name, String citText, XTextCursor position, boolean withText,
                                OOBibStyle style)
             throws Exception {
+
+        // Check if there is "page info" stored for this citation. If so, insert it into 
+        // the citation text before inserting the citation:
+        String pageInfo = getCustomProperty(name);
+        if (pageInfo != null) {
+            citText = style.insertPageInfo(citText, pageInfo);
+        }
+
         Object bookmark = mxDocFactory.createInstance("com.sun.star.text.ReferenceMark");
         // Name the reference
         XNamed xNamed = (XNamed) UnoRuntime.queryInterface(
@@ -958,11 +1163,19 @@ public class OOBibBase {
                 position.setString(citText);
                 XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(
                     XPropertySet.class, position);
+
                 // Set language to [None]:
                 xCursorProps.setPropertyValue("CharLocale", new Locale("zxx", "", ""));
-
-                // See if we should format the citation marker or not:
                 if (style.isFormatCitations()) {
+                    String charStyle = style.getCitationCharacterFormat();
+                    try {
+                        xCursorProps.setPropertyValue("CharStyleName", charStyle);
+                    } catch (Throwable ex) {
+                        throw new UndefinedCharacterFormatException(charStyle);
+                    }
+                }
+                // See if we should format the citation marker or not:
+                /*if (style.isFormatCitations()) {
 
                     if (style.getBooleanCitProperty("SuperscriptCitations")) {
                         xCursorProps.setPropertyValue("CharEscapement",
@@ -990,7 +1203,7 @@ public class OOBibBase {
                             style.isBoldCitations() ? com.sun.star.awt.FontWeight.BOLD :
                                 com.sun.star.awt.FontWeight.NORMAL);
                     
-                }
+                } */
             }
             else
                 position.setString("");
@@ -1117,6 +1330,23 @@ public class OOBibBase {
             String text = mxDocCursor.getString();
             // Check if the string contains no line breaks and only whitespace:
             if ((text.indexOf('\n') == -1) && (text.trim().length() == 0)) {
+
+                // If we are supposed to set character format for citations, test this before
+                // making any changes. This way we can throw an exception before any reference
+                // marks are removed, preventing damage to the user's document:
+                if (style.isFormatCitations()) {
+                    XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(
+                                        XPropertySet.class, mxDocCursor);
+                    String charStyle = style.getCitationCharacterFormat();
+                    try {
+                        xCursorProps.setPropertyValue("CharStyleName", charStyle);
+                    } catch (Throwable ex) {
+                        // Setting the character format failed, so we throw an exception that
+                        // will result in an error message for the user:
+                        throw new UndefinedCharacterFormatException(charStyle);
+                    }
+                }
+
                 List<String> keys = parseRefMarkName(names[piv]);
                 keys.addAll(parseRefMarkName(names[piv+1]));
                 removeReferenceMark(names[piv]);
index 4ee62a6e4d75b4c4b16a57311ec0b5af3b0bb733..3b992f43e0d83b6b72268b833d0ff217e933b2b0 100755 (executable)
@@ -34,11 +34,11 @@ public class OOBibStyle implements Comparable {
     String name = null;
     SortedSet<String> journals = new TreeSet<String>();
 
+    // Formatter to be run on fields before they are used as part of citation marker:
+    LayoutFormatter fieldFormatter = new OOPreFormatter();
+
     Layout defaultBibLayout;
-    // formatters mapped from field names. Each field can have no mapping, or a set of formatters:
-    HashMap formatters = new HashMap();
-    // 0-n formatters applied to all fields before field-speficic formatters:
-    LayoutFormatter[] allBeforeFormat, allAfterFormat;
+
     // reference layout mapped from entry type number:
     HashMap<String, Layout> bibLayout = new HashMap<String, Layout>();
 
@@ -97,14 +97,17 @@ public class OOBibStyle implements Comparable {
         citProperties.put("BracketBefore", "(");
         citProperties.put("BracketAfter", ")");
         citProperties.put("CitationSeparator", "; ");
+        citProperties.put("PageInfoSeparator", "; ");
         citProperties.put("GroupedNumbersSeparator", "-");
         citProperties.put("MinimumGroupingCount", 3);
         citProperties.put("FormatCitations", Boolean.FALSE);
+        citProperties.put("CitationCharacterFormat", "Default");
         citProperties.put("ItalicCitations", Boolean.FALSE);
         citProperties.put("BoldCitations", Boolean.FALSE);
         citProperties.put("SuperscriptCitations", Boolean.FALSE);
         citProperties.put("SubscriptCitations", Boolean.FALSE);
         citProperties.put("MultiCiteChronological", Boolean.TRUE);
+        citProperties.put("BibtexKeyCitations", Boolean.FALSE);
 
         initialize(in);
 
@@ -126,7 +129,6 @@ public class OOBibStyle implements Comparable {
     private void initialize(Reader in) throws IOException {
         name = null;
         readFormatFile(in);
-        allBeforeFormat = new LayoutFormatter[] {new RemoveLatexCommands()};
     }
 
     /**
@@ -177,6 +179,8 @@ public class OOBibStyle implements Comparable {
 
         for (int i = 0; i < lines.length; i++) {
             String line = lines[i];
+            if ((line.length() > 0) && (line.charAt(line.length()-1) == '\r'))
+                line = line.substring(0, line.length()-1);
             // Check for empty line or comment:
             if ((line.trim().length() == 0) || (line.charAt(0) == '#'))
                 continue;
@@ -325,36 +329,6 @@ public class OOBibStyle implements Comparable {
             return defaultBibLayout;
     }*/
 
-    /**
-     * Format the given field value based on the rules of this bib style.
-     * @param field The name of the field.
-     * @param content The unformatted field content.
-     * @return The formatted field value.
-     */
-    public String formatField(String field, String content) {
-        if (allBeforeFormat != null)
-            for (int i = 0; i < allBeforeFormat.length; i++) {
-                LayoutFormatter formatter = allBeforeFormat[i];
-                content = formatter.format(content);
-            }
-
-        Object o = formatters.get(field);
-        if (o == null)
-            return content;
-        LayoutFormatter[] form = (LayoutFormatter[])o;
-        for (int i = 0; i < form.length; i++) {
-            LayoutFormatter formatter = form[i];
-            content = formatter.format(content);
-        }
-
-        if (allAfterFormat != null)
-            for (int i = 0; i < allAfterFormat.length; i++) {
-                LayoutFormatter formatter = allAfterFormat[i];
-                content = formatter.format(content);
-            }
-
-        return content;
-    }
 
     /**
      * Format a number-based citation marker for the given number.
@@ -735,8 +709,11 @@ public class OOBibStyle implements Comparable {
         for (int i = 0; i < fields.length; i++) {
             String s = fields[i];
             String content = BibtexDatabase.getResolvedField(s, entry, database);
-            if ((content != null) && (content.trim().length() > 0))
+            if ((content != null) && (content.trim().length() > 0)) {
+                if (fieldFormatter != null)
+                    content = fieldFormatter.format(content);
                 return content;
+            }
         }
         // No luck? Return an empty string:
         return "";
@@ -767,6 +744,22 @@ public class OOBibStyle implements Comparable {
         return sb.toString();
     }
 
+    /**
+     * Take a finished citation and insert a string at the end (but inside the end bracket)
+     * separated by "PageInfoSeparator"
+     * @param citation
+     * @param pageInfo
+     * @return
+     */
+    public String insertPageInfo(String citation, String pageInfo) {
+        String bracketAfter = getStringCitProperty("BracketAfter");
+        if (citation.endsWith(bracketAfter)) {
+            String first = citation.substring(0, citation.length()-bracketAfter.length());
+            return first+getStringCitProperty("PageInfoSeparator")+pageInfo+bracketAfter;
+        }
+        else return citation+getStringCitProperty("PageInfoSeparator")+pageInfo;
+    }
+
     /**
      * Convenience method for checking the property for whether we use number citations or
      * author-year citations.
@@ -813,6 +806,10 @@ public class OOBibStyle implements Comparable {
         return (Boolean)citProperties.get("FormatCitations");
     }
 
+    public boolean isBibtexKeyCiteMarkers() {
+        return (Boolean)citProperties.get("BibtexKeyCitations");
+    }
+    
     /**
      * Get boolean property.
      * @param key The property key
@@ -825,6 +822,14 @@ public class OOBibStyle implements Comparable {
     public int getIntCitProperty(String key) {
         return (Integer)citProperties.get(key);
     }
+
+    public String getStringCitProperty(String key) {
+        return (String)citProperties.get(key);
+    }
+
+    public String getCitationCharacterFormat() {
+        return (String)citProperties.get("CitationCharacterFormat");
+    }
     /**
      * Get a style property.
      * @param name The property name.
index 3b30b3374229fd45450af798a982b127813821e1..d33b9226fca3bd8f8c0af5e5a2de9f22d24908ef 100755 (executable)
@@ -58,6 +58,7 @@ public class OOTestPanel extends AbstractWorker implements SidePanePlugin, PushT
         pushEntries = new JButton(Globals.lang("Cite")),
         pushEntriesInt = new JButton(Globals.lang("Cite in-text")),
         pushEntriesEmpty = new JButton(Globals.lang("Insert empty citation")),
+        pushEntriesAdvanced = new JButton(Globals.lang("Cite special")),
         focus = new JButton("Focus OO document"),
         update,
         insertFullRef = new JButton("Insert reference text"),
@@ -111,9 +112,11 @@ public class OOTestPanel extends AbstractWorker implements SidePanePlugin, PushT
         Globals.prefs.putDefaultValue("ooInParCitation", true);
         Globals.prefs.putDefaultValue("syncOOWhenCiting", false);
 
+        Globals.prefs.putDefaultValue("showOOPanel", true);
         
         styleFile = Globals.prefs.get("ooBibliographyStyleFile");
 
+
     }
 
     public SidePaneComponent getSidePaneComponent() {
@@ -133,6 +136,8 @@ public class OOTestPanel extends AbstractWorker implements SidePanePlugin, PushT
     }
 
     public JMenuItem getMenuItem() {
+        if (Globals.prefs.getBoolean("showOOPanel"))
+            manager.show(getName());
         JMenuItem item = new JMenuItem("OpenOffice.org panel", GUIGlobals.getImage("openoffice"));
         item.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent event) {
@@ -149,11 +154,13 @@ public class OOTestPanel extends AbstractWorker implements SidePanePlugin, PushT
 
     private void initPanel() throws Exception {
 
-        connect.addActionListener(new ActionListener() {
+        Action al = new AbstractAction() {
             public void actionPerformed(ActionEvent e) {
                 connect(true);
             }
-        });
+        };
+        connect.addActionListener(al);
+
         manualConnect.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent event) {
                 connect(false);
@@ -191,19 +198,25 @@ public class OOTestPanel extends AbstractWorker implements SidePanePlugin, PushT
         pushEntries.setToolTipText(Globals.lang("Cite selected entries"));
         pushEntries.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
-                pushEntries(true, true);
+                pushEntries(true, true, false);
             }
         });
         pushEntries.setToolTipText(Globals.lang("Cite selected entries with in-text citation"));
         pushEntriesInt.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
-                pushEntries(false, true);
+                pushEntries(false, true, false);
             }
         });
         pushEntriesEmpty.setToolTipText(Globals.lang("Insert a citation without text (the entry will appear in the reference list)"));
         pushEntriesEmpty.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent event) {
-                pushEntries(false, false);
+                pushEntries(false, false, false);
+            }
+        });
+        pushEntriesAdvanced.setToolTipText(Globals.lang("Cite selected entries with extra information"));
+        pushEntriesAdvanced.addActionListener(new ActionListener() {
+            public void actionPerformed(ActionEvent event) {
+                pushEntries(false, true, true);
             }
         });
 
@@ -213,7 +226,7 @@ public class OOTestPanel extends AbstractWorker implements SidePanePlugin, PushT
             }
         });
         update.setToolTipText(Globals.lang("Ensure that the bibliography is up-to-date"));
-        update.addActionListener(new ActionListener() {
+        Action updateAction = new AbstractAction() {
             public void actionPerformed(ActionEvent e) {
                 try {
                     style.ensureUpToDate();
@@ -226,6 +239,8 @@ public class OOTestPanel extends AbstractWorker implements SidePanePlugin, PushT
                         JOptionPane.showMessageDialog(frame, Globals.lang("Your OpenOffice document references the BibTeX key '%0', which could not be found in your current database.",
                             unresolvedKeys.get(0)), Globals.lang("Unable to synchronize bibliography"), JOptionPane.ERROR_MESSAGE);
                     }
+                } catch (UndefinedCharacterFormatException ex) {
+                    reportUndefinedCharacterFormat(ex);
                 } catch (UndefinedParagraphFormatException ex) {
                     reportUndefinedParagraphFormat(ex);
                 } catch (ConnectionLostException ex) {
@@ -238,7 +253,8 @@ public class OOTestPanel extends AbstractWorker implements SidePanePlugin, PushT
                     e1.printStackTrace();
                 }
             }
-        });
+        };
+        update.addActionListener(updateAction);
 
         insertFullRef.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent event) {
@@ -255,6 +271,8 @@ public class OOTestPanel extends AbstractWorker implements SidePanePlugin, PushT
             public void actionPerformed(ActionEvent event) {
                 try {
                     ooBase.combineCiteMarkers(frame.basePanel().database(), style);
+                } catch (UndefinedCharacterFormatException e) {
+                    reportUndefinedCharacterFormat(e);
                 } catch (Exception e) {
                     e.printStackTrace();
                 }
@@ -271,7 +289,12 @@ public class OOTestPanel extends AbstractWorker implements SidePanePlugin, PushT
         test.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent event) {
                 try {
-                    ooBase.testFrameHandling();
+                    CitationManager cm = new CitationManager(frame, ooBase);
+                    cm.showDialog();
+                    //pushEntries(false, true, true);
+
+                    //ooBase.testFrameHandling();
+
                     //ooBase.combineCiteMarkers(frame.basePanel().database(), style);
                     //insertUsingBST();
                     //ooBase.testFootnote();
@@ -289,6 +312,7 @@ public class OOTestPanel extends AbstractWorker implements SidePanePlugin, PushT
         pushEntries.setEnabled(false);
         pushEntriesInt.setEnabled(false);
         pushEntriesEmpty.setEnabled(false);
+        pushEntriesAdvanced.setEnabled(false);
         focus.setEnabled(false);
         update.setEnabled(false);
         insertFullRef.setEnabled(false);
@@ -316,6 +340,7 @@ public class OOTestPanel extends AbstractWorker implements SidePanePlugin, PushT
         b.append(setStyleFile);
         b.append(pushEntries);
         b.append(pushEntriesInt);
+        b.append(pushEntriesAdvanced);
         b.append(pushEntriesEmpty);
         b.append(merge);
         b.append(settingsB);
@@ -330,7 +355,12 @@ public class OOTestPanel extends AbstractWorker implements SidePanePlugin, PushT
         comp.setContent(content);
         content.setLayout(new BorderLayout());
         content.add(b.getPanel(), BorderLayout.CENTER);
-        
+
+        System.out.println("Adding shortcuts");
+        frame.getTabbedPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
+                .put(Globals.prefs.getKey("Refresh OO"), "Refresh OO");
+        frame.getTabbedPane().getActionMap().put("Refresh OO", updateAction);
+
         //diag.pack();
         //diag.setVisible(true);
     }
@@ -384,44 +414,31 @@ public class OOTestPanel extends AbstractWorker implements SidePanePlugin, PushT
             String ooJars = Globals.prefs.get("ooJarsPath");
             sOffice = Globals.prefs.get("ooExecutablePath");
 
-            boolean openOffice3 = Globals.prefs.getBoolean("connectToOO3");
+            boolean openOffice3 = true;//Globals.prefs.getBoolean("connectToOO3");
             if (Globals.ON_WIN) {
-                if (openOffice3) {
+                //if (openOffice3) {
                     unoilDir = ooPath+"\\Basis\\program\\classes";
                     ooBaseDirectory = ooPath+"\\URE\\java";
                     sOffice = ooPath+"\\program\\soffice.exe";
-                }
-                else {
-                    unoilDir = ooPath+"\\program\\classes";
-                    ooBaseDirectory = unoilDir;
-                    sOffice = ooPath+"\\program\\soffice.exe";
-                }
-
+                //}
+                
             }
             else if (Globals.ON_MAC) {
-                if (openOffice3) {
+                //if (openOffice3) {
                     sOffice = ooPath+"/Contents/MacOS/soffice.bin";
                     ooBaseDirectory = ooPath+"/Contents/basis-link/ure-link/share/java";
                     unoilDir = ooPath+"/Contents/basis-link/program/classes"; 
-                }
-                else {
-                    sOffice = ooPath+"/Contents/MacOS/soffice.bin";
-                    ooBaseDirectory = ooPath+"/Contents/MacOS/classes";
-                    unoilDir = ooPath+"/Contents/MacOS/classes";
-                }
+                //}
+
             }
             else {
                 // Linux:
-                if (openOffice3) {
+                //if (openOffice3) {
                     unoilDir = ooJars+"/program/classes";
                     ooBaseDirectory = ooJars+"/ure-link/share/java";
                     //sOffice = ooPath+"/program/soffice";
-                }
-                else {
-                    unoilDir = ooJars;
-                    ooBaseDirectory = ooJars;
+                //}
 
-                }
             }
         }
 
@@ -432,18 +449,18 @@ public class OOTestPanel extends AbstractWorker implements SidePanePlugin, PushT
 
         // Add OO jars to the classpath:
         try {
-            URL[] jarList = new URL[] {
-                new File(unoilDir, "unoil.jar").toURI().toURL(),
-                new File(ooBaseDirectory, "jurt.jar").toURI().toURL(),
-                new File(ooBaseDirectory, "juh.jar").toURI().toURL(),
-                new File(ooBaseDirectory, "ridl.jar").toURI().toURL(),
-            };
+            File[] jarFiles = new File[] {
+                    new File(unoilDir, "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())
+                    throw new Exception(Globals.lang("File not found")+": "+jarFiles[i].getPath());
+                jarList[i] = jarFiles[i].toURI().toURL();
+            }
             addURL(jarList);
-            /*ClassLoader aCL = Thread.currentThread().getContextClassLoader();
-            loader = new URLClassLoader(jarList, aCL);
-            Thread.currentThread().setContextClassLoader(aUrlCL);
-            loader = new URLClassLoader(jarList);
-            */
 
             if (styleFile == null) {
                 JOptionPane.showMessageDialog(diag, "You must choose a style file before you can connect.", "No style file selected", JOptionPane.ERROR_MESSAGE);
@@ -471,6 +488,7 @@ public class OOTestPanel extends AbstractWorker implements SidePanePlugin, PushT
             pushEntries.setEnabled(true);
             pushEntriesInt.setEnabled(true);
             pushEntriesEmpty.setEnabled(true);
+            pushEntriesAdvanced.setEnabled(true);
             focus.setEnabled(true);
             update.setEnabled(true);
             insertFullRef.setEnabled(true);
@@ -479,10 +497,11 @@ public class OOTestPanel extends AbstractWorker implements SidePanePlugin, PushT
 
         } catch (Exception e) {
             e.printStackTrace();
-            
+
             JOptionPane.showMessageDialog(frame, Globals.lang("Could not connect to running OpenOffice.\n"
-                +"Make sure you have the UNO jars (unoil.jar, juh.jar, jurt.jar and ridl.jar) on your classpath,\n"
-                +"as well as the OpenOffice bin directory.\nError message: "+e.getMessage()));
+                +"Make sure you have installed OpenOffice with Java support.\nIf connecting manually, please verify program and library paths.\n"
+                +"\nError message: "+e.getMessage()));
+
         }
     }
 
@@ -564,11 +583,6 @@ public class OOTestPanel extends AbstractWorker implements SidePanePlugin, PushT
         browseOOJars.addActionListener(new BrowseAction(null, ooJars, true));
         ooExec.setText(Globals.prefs.get("ooExecutablePath"));
         ooJars.setText(Globals.prefs.get("ooJarsPath"));
-        final JRadioButton oo2 = new JRadioButton("OpenOffice.org 2.x", !Globals.prefs.getBoolean("connectToOO3"));
-        final JRadioButton oo3 = new JRadioButton("OpenOffice.org 3.x", Globals.prefs.getBoolean("connectToOO3"));
-        ButtonGroup bg = new ButtonGroup();
-        bg.add(oo2);
-        bg.add(oo3);
         DefaultFormBuilder builder = new DefaultFormBuilder(new FormLayout("left:pref, 4dlu, fill:pref:grow, 4dlu, fill:pref", ""));
         if (Globals.ON_WIN || Globals.ON_MAC) {
             builder.append(Globals.lang("Path to OpenOffice directory"));
@@ -587,10 +601,6 @@ public class OOTestPanel extends AbstractWorker implements SidePanePlugin, PushT
             builder.append(browseOOJars);
             builder.nextLine();
         }
-        builder.append(Globals.lang("Program version"));
-        builder.append(oo2); builder.nextLine();
-        builder.append(new JPanel());
-        builder.append(oo3); builder.nextLine();
 
         ButtonBarBuilder bb = new ButtonBarBuilder();
         JButton ok = new JButton(Globals.lang("Ok"));
@@ -599,7 +609,7 @@ public class OOTestPanel extends AbstractWorker implements SidePanePlugin, PushT
         ActionListener tfListener = new ActionListener() {
             public void actionPerformed(ActionEvent event) {
                 updateConnectionParams(ooPath.getText(), ooExec.getText(), ooJars.getText(),
-                        oo3.isSelected());
+                        true);
                 diag.dispose();
             }
         };
@@ -610,7 +620,7 @@ public class OOTestPanel extends AbstractWorker implements SidePanePlugin, PushT
         ok.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent event) {
                 updateConnectionParams(ooPath.getText(), ooExec.getText(), ooJars.getText(),
-                        oo3.isSelected());
+                        true);
                 dialogOkPressed = true;
                 diag.dispose();
             }
@@ -637,13 +647,27 @@ public class OOTestPanel extends AbstractWorker implements SidePanePlugin, PushT
 
 
 
-    public void pushEntries(boolean inParenthesis, boolean withText) {
+    public void pushEntries(boolean inParenthesis, boolean withText, boolean addPageInfo) {
         if (!ooBase.isConnectedToDocument()) {
             JOptionPane.showMessageDialog(frame, Globals.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."),
                     Globals.lang("Error"), JOptionPane.ERROR_MESSAGE);
             return;
         }
+
+        String pageInfo = null;
+        if (addPageInfo) {
+            AdvancedCiteDialog acd = new AdvancedCiteDialog(frame);
+            acd.showDialog();
+            if (acd.cancelled())
+                return;
+            if (acd.getPageInfo().length() > 0)
+                pageInfo = acd.getPageInfo();
+            inParenthesis = acd.isInParenthesisCite();
+
+        }
+
+
         BasePanel panel =frame.basePanel();
         final BibtexDatabase database = panel.database();
         if (panel != null) {
@@ -651,9 +675,11 @@ public class OOTestPanel extends AbstractWorker implements SidePanePlugin, PushT
             if (entries.length > 0) {
                 try {
                     ooBase.insertEntry(entries, database, style, inParenthesis, withText,
-                            Globals.prefs.getBoolean("syncOOWhenCiting"));
+                            pageInfo, Globals.prefs.getBoolean("syncOOWhenCiting"));
                 } catch (ConnectionLostException ex) {
                     showConnectionLostErrorMessage();
+                } catch (UndefinedCharacterFormatException ex) {
+                    reportUndefinedCharacterFormat(ex);
                 } catch (UndefinedParagraphFormatException ex) {
                    reportUndefinedParagraphFormat(ex);
                 } catch (Exception ex) {
@@ -705,6 +731,13 @@ public class OOTestPanel extends AbstractWorker implements SidePanePlugin, PushT
             Globals.lang(""), JOptionPane.ERROR_MESSAGE);
     }
 
+    private void reportUndefinedCharacterFormat(UndefinedCharacterFormatException ex) {
+        JOptionPane.showMessageDialog(frame, "<html>"+Globals.lang("Your style file specifies the character format '%0', "
+            +"which is undefined in your current OpenOffice document.", ex.getFormatName())+"<br>"
+            +Globals.lang("The character format is controlled by the citation property 'CitationCharacterFormat' in the style file.")
+            +"</html>",
+            Globals.lang(""), JOptionPane.ERROR_MESSAGE);
+    }
 
     public void insertUsingBST() {
         try {
@@ -750,11 +783,27 @@ public class OOTestPanel extends AbstractWorker implements SidePanePlugin, PushT
     public void pushEntries(boolean inParenthesis, BibtexEntry[] entries) {
         final BibtexDatabase database = frame.basePanel().database();
         if (entries.length > 0) {
+
+            String pageInfo = null;
+            //if (addPageInfo) {
+                AdvancedCiteDialog acd = new AdvancedCiteDialog(frame);
+                acd.showDialog();
+                if (acd.cancelled())
+                    return;
+                if (acd.getPageInfo().length() > 0)
+                    pageInfo = acd.getPageInfo();
+                inParenthesis = acd.isInParenthesisCite();
+
+            //}
+
+
             try {
                 ooBase.insertEntry(entries, database, style, inParenthesis, true,
-                    Globals.prefs.getBoolean("syncOOWhenCiting"));
+                    pageInfo, Globals.prefs.getBoolean("syncOOWhenCiting"));
             } catch (ConnectionLostException ex) {
                 showConnectionLostErrorMessage();
+            } catch (UndefinedCharacterFormatException ex) {
+                reportUndefinedCharacterFormat(ex);
             } catch (UndefinedParagraphFormatException ex) {
                reportUndefinedParagraphFormat(ex);
             } catch (Exception ex) {
@@ -784,9 +833,10 @@ public class OOTestPanel extends AbstractWorker implements SidePanePlugin, PushT
     }
 
     public JPanel getSettingsPanel() {
-        if (settings == null)
+        return null;
+        /*if (settings == null)
             initSettingsPanel();
-        return settings;
+        return settings;*/
     }
 
     private void initSettingsPanel() {
@@ -811,6 +861,7 @@ public class OOTestPanel extends AbstractWorker implements SidePanePlugin, PushT
             connect(true);
         }
         if (ooBase != null) {
+
             pushEntries(Globals.prefs.getBoolean("ooInParCitation"), entries);
         }
     }
@@ -832,6 +883,16 @@ public class OOTestPanel extends AbstractWorker implements SidePanePlugin, PushT
         public String getName() {
             return OOTestPanel.this.getName();
         }
+
+        @Override
+        public void componentClosing() {
+            Globals.prefs.putBoolean("showOOPanel", false);
+        }
+
+        @Override
+        public void componentOpening() {
+            Globals.prefs.putBoolean("showOOPanel", true);
+        }
     }
 
 
diff --git a/net/sf/jabref/oo/UndefinedCharacterFormatException.java b/net/sf/jabref/oo/UndefinedCharacterFormatException.java
new file mode 100644 (file)
index 0000000..a510f26
--- /dev/null
@@ -0,0 +1,19 @@
+package net.sf.jabref.oo;
+
+/**
+ * Exception used to indicate that the plugin attempted to set a character format that is
+ * not defined in the current OpenOffice document.
+ */
+public class UndefinedCharacterFormatException extends Exception {
+
+    String formatName;
+
+    public UndefinedCharacterFormatException(String formatName) {
+        super();
+        this.formatName = formatName;
+    }
+
+    public String getFormatName() {
+        return formatName;
+    }
+}
index ca356dca79e78c5d5ceb3f0075c3cbb16747047d..8588acdf74625eaa0b900e054278c5412c8e5531 100755 (executable)
@@ -1,6 +1,6 @@
 <?xml version="1.0" ?>
 <!DOCTYPE plugin PUBLIC "-//JPF//Java Plug-in Manifest 1.0" "http://jpf.sourceforge.net/plugin_1_0.dtd">
-<plugin id="net.sf.jabref.oo.ooplugin" version="0.8">
+<plugin id="net.sf.jabref.oo.ooplugin" version="0.9">
 
        <requires>
                <import plugin-id="net.sf.jabref.core"/>