PageRenderTime 43ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 1ms

/jabref-2.8/src/java/net/sf/jabref/ExternalTab.java

#
Java | 257 lines | 196 code | 37 blank | 24 comment | 4 complexity | 94743b97c13d81e22d77a51e664e2cab MD5 | raw file
  1. /* Copyright (C) 2003-2011 JabRef contributors.
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation; either version 2 of the License, or
  5. (at your option) any later version.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License along
  11. with this program; if not, write to the Free Software Foundation, Inc.,
  12. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  13. */
  14. package net.sf.jabref;
  15. import java.awt.BorderLayout;
  16. import java.awt.event.ItemEvent;
  17. import java.awt.event.ItemListener;
  18. import java.awt.event.ActionListener;
  19. import java.awt.event.ActionEvent;
  20. import javax.swing.*;
  21. import javax.swing.event.ChangeEvent;
  22. import javax.swing.event.ChangeListener;
  23. import net.sf.jabref.external.*;
  24. import net.sf.jabref.plugin.core.JabRefPlugin;
  25. import com.jgoodies.forms.builder.DefaultFormBuilder;
  26. import com.jgoodies.forms.layout.FormLayout;
  27. public class ExternalTab extends JPanel implements PrefsTab {
  28. JabRefPreferences _prefs;
  29. JabRefFrame _frame;
  30. JTextField pdfDir, regExpTextField, fileDir, psDir, emailSubject;
  31. JCheckBox bibLocationAsFileDir, bibLocAsPrimaryDir, runAutoFileSearch,
  32. allowFileAutoOpenBrowse, openFoldersOfAttachedFiles;
  33. JButton editFileTypes;
  34. ItemListener regExpListener;
  35. JRadioButton useRegExpComboBox;
  36. JRadioButton matchExactKeyOnly = new JRadioButton(Globals.lang("Autolink only files that match the BibTeX key")),
  37. matchStartsWithKey = new JRadioButton(Globals.lang("Autolink files with names starting with the BibTeX key"));
  38. public ExternalTab(JabRefFrame frame, PrefsDialog3 prefsDiag, JabRefPreferences prefs,
  39. HelpDialog helpDialog) {
  40. _prefs = prefs;
  41. _frame = frame;
  42. setLayout(new BorderLayout());
  43. psDir = new JTextField(25);
  44. pdfDir = new JTextField(25);
  45. fileDir = new JTextField(25);
  46. bibLocationAsFileDir = new JCheckBox(Globals.lang("Allow file links relative to each bib file's location"));
  47. bibLocAsPrimaryDir = new JCheckBox(Globals.lang("Use the bib file location as primary file directory"));
  48. bibLocAsPrimaryDir.setToolTipText(Globals.lang("When downloading files, or moving linked files to the "
  49. +"file directory, prefer the bib file location rather than the file directory set above"));
  50. bibLocationAsFileDir.addChangeListener(new ChangeListener() {
  51. public void stateChanged(ChangeEvent changeEvent) {
  52. bibLocAsPrimaryDir.setEnabled(bibLocationAsFileDir.isSelected());
  53. }
  54. });
  55. editFileTypes = new JButton(Globals.lang("Manage external file types"));
  56. runAutoFileSearch = new JCheckBox(Globals.lang("When opening file link, search for matching file if no link is defined"));
  57. allowFileAutoOpenBrowse = new JCheckBox(Globals.lang("Automatically open browse dialog when creating new file link"));
  58. regExpTextField = new JTextField(25);
  59. useRegExpComboBox = new JRadioButton(Globals.lang("Use Regular Expression Search"));
  60. regExpListener = new ItemListener() {
  61. public void itemStateChanged(ItemEvent e) {
  62. regExpTextField.setEditable(useRegExpComboBox.isSelected());
  63. }
  64. };
  65. useRegExpComboBox.addItemListener(regExpListener);
  66. editFileTypes.addActionListener(ExternalFileTypeEditor.getAction(prefsDiag));
  67. ButtonGroup bg = new ButtonGroup();
  68. bg.add(matchExactKeyOnly);
  69. bg.add(matchStartsWithKey);
  70. bg.add(useRegExpComboBox);
  71. BrowseAction browse;
  72. FormLayout layout = new FormLayout(
  73. "1dlu, 8dlu, left:pref, 4dlu, fill:150dlu, 4dlu, fill:pref","");
  74. DefaultFormBuilder builder = new DefaultFormBuilder(layout);
  75. builder.appendSeparator(Globals.lang("External file links"));
  76. JPanel pan = new JPanel();
  77. builder.append(pan);
  78. /**
  79. * Fix for [ 1749613 ] About translation
  80. *
  81. * https://sourceforge.net/tracker/index.php?func=detail&aid=1749613&group_id=92314&atid=600306
  82. *
  83. * Cannot really use %0 to refer to the file type, since this ruins translation.
  84. */
  85. JLabel lab = new JLabel(Globals.lang("Main file directory") + ":");
  86. builder.append(lab);
  87. builder.append(fileDir);
  88. browse = new BrowseAction(_frame, fileDir, true);
  89. builder.append(new JButton(browse));
  90. builder.nextLine();
  91. builder.append(new JPanel());
  92. builder.append(bibLocationAsFileDir, 3);
  93. builder.nextLine();
  94. builder.append(new JPanel());
  95. builder.append(bibLocAsPrimaryDir, 3);
  96. builder.nextLine();
  97. builder.append(new JPanel());
  98. builder.append(matchStartsWithKey, 3);
  99. builder.nextLine();
  100. builder.append(new JPanel());
  101. builder.append(matchExactKeyOnly, 3);
  102. builder.nextLine();
  103. builder.append(new JPanel());
  104. builder.append(useRegExpComboBox);
  105. builder.append(regExpTextField);
  106. HelpAction helpAction = new HelpAction(helpDialog, GUIGlobals.regularExpressionSearchHelp,
  107. Globals.lang("Help on Regular Expression Search"), GUIGlobals.getIconUrl("helpSmall"));
  108. builder.append(helpAction.getIconButton());
  109. builder.nextLine();
  110. builder.append(new JPanel());
  111. builder.append(runAutoFileSearch, 3);
  112. builder.nextLine();
  113. builder.append(new JPanel());
  114. builder.append(allowFileAutoOpenBrowse);
  115. builder.nextLine();
  116. builder.appendSeparator(Globals.lang("Sending of emails"));
  117. builder.append(new JPanel());
  118. lab = new JLabel(Globals.lang("Subject for sending an email with references").concat(":"));
  119. builder.append(lab);
  120. emailSubject = new JTextField(25);
  121. builder.append(emailSubject);
  122. builder.nextLine();
  123. builder.append(new JPanel());
  124. openFoldersOfAttachedFiles = new JCheckBox(Globals.lang("Automatically open folders of attached files"));
  125. builder.append(openFoldersOfAttachedFiles);
  126. builder.nextLine();
  127. builder.appendSeparator(Globals.lang("Legacy file fields"));
  128. pan = new JPanel();
  129. builder.append(pan);
  130. builder.append(new JLabel("<html>"+Globals.lang("Note that these settings are used for the legacy "
  131. +"<b>pdf</b> and <b>ps</b> fields only.<br>For most users, setting the <b>Main file directory</b> "
  132. +"above should be sufficient.")+"</html>"), 5);
  133. builder.nextLine();
  134. pan = new JPanel();
  135. builder.append(pan);
  136. lab = new JLabel(Globals.lang("Main PDF directory") + ":");
  137. builder.append(lab);
  138. builder.append(pdfDir);
  139. browse = new BrowseAction(_frame, pdfDir, true);
  140. builder.append(new JButton(browse));
  141. builder.nextLine();
  142. pan = new JPanel();
  143. builder.append(pan);
  144. lab = new JLabel(Globals.lang("Main PS directory") + ":");
  145. builder.append(lab);
  146. builder.append(psDir);
  147. browse = new BrowseAction(_frame, psDir, true);
  148. builder.append(new JButton(browse));
  149. builder.nextLine();
  150. builder.appendSeparator(Globals.lang("External programs"));
  151. builder.nextLine();
  152. addSettingsButton(new PushToLyx(), builder);
  153. addSettingsButton(new PushToEmacs(), builder);
  154. addSettingsButton(new PushToWinEdt(), builder);
  155. addSettingsButton(new PushToVim(), builder);
  156. addSettingsButton(new PushToLatexEditor(), builder);
  157. //builder.nextLine();
  158. builder.append(pan);
  159. builder.append(editFileTypes);
  160. pan = builder.getPanel();
  161. pan.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
  162. add(pan, BorderLayout.CENTER);
  163. }
  164. private void addSettingsButton(final PushToApplication pt, DefaultFormBuilder b) {
  165. b.append(new JPanel());
  166. b.append(Globals.lang("Settings for %0", pt.getName())+":");
  167. JButton button = new JButton(pt.getIcon());
  168. button.addActionListener(new ActionListener() {
  169. public void actionPerformed(ActionEvent event) {
  170. PushToApplicationButton.showSettingsDialog(_frame, pt, pt.getSettingsPanel());
  171. }
  172. });
  173. b.append(button);
  174. b.nextLine();
  175. }
  176. public void setValues() {
  177. pdfDir.setText(_prefs.get("pdfDirectory"));
  178. psDir.setText(_prefs.get("psDirectory"));
  179. fileDir.setText(_prefs.get(GUIGlobals.FILE_FIELD+"Directory"));
  180. bibLocationAsFileDir.setSelected(_prefs.getBoolean("bibLocationAsFileDir"));
  181. bibLocAsPrimaryDir.setSelected(_prefs.getBoolean("bibLocAsPrimaryDir"));
  182. bibLocAsPrimaryDir.setEnabled(bibLocationAsFileDir.isSelected());
  183. runAutoFileSearch.setSelected(_prefs.getBoolean("runAutomaticFileSearch"));
  184. regExpTextField.setText(_prefs.get(JabRefPreferences.REG_EXP_SEARCH_EXPRESSION_KEY));
  185. allowFileAutoOpenBrowse.setSelected(_prefs.getBoolean("allowFileAutoOpenBrowse"));
  186. emailSubject.setText(_prefs.get(JabRefPreferences.EMAIL_SUBJECT));
  187. openFoldersOfAttachedFiles.setSelected(_prefs.getBoolean(JabRefPreferences.OPEN_FOLDERS_OF_ATTACHED_FILES));
  188. if (_prefs.getBoolean(JabRefPreferences.USE_REG_EXP_SEARCH_KEY))
  189. useRegExpComboBox.setSelected(true);
  190. else if (_prefs.getBoolean("autolinkExactKeyOnly"))
  191. matchExactKeyOnly.setSelected(true);
  192. else
  193. matchStartsWithKey.setSelected(true);
  194. }
  195. public void storeSettings() {
  196. _prefs.putBoolean(JabRefPreferences.USE_REG_EXP_SEARCH_KEY, useRegExpComboBox.isSelected());
  197. if (useRegExpComboBox.isSelected()) {
  198. _prefs.put(JabRefPreferences.REG_EXP_SEARCH_EXPRESSION_KEY, regExpTextField.getText());
  199. }
  200. // We should maybe do some checking on the validity of the contents?
  201. _prefs.put("pdfDirectory", pdfDir.getText());
  202. _prefs.put("psDirectory", psDir.getText());
  203. _prefs.put(GUIGlobals.FILE_FIELD+"Directory", fileDir.getText());
  204. _prefs.putBoolean("bibLocationAsFileDir", bibLocationAsFileDir.isSelected());
  205. _prefs.putBoolean("bibLocAsPrimaryDir", bibLocAsPrimaryDir.isSelected());
  206. _prefs.putBoolean("autolinkExactKeyOnly", matchExactKeyOnly.isSelected());
  207. _prefs.putBoolean("runAutomaticFileSearch", runAutoFileSearch.isSelected());
  208. _prefs.putBoolean("allowFileAutoOpenBrowse", allowFileAutoOpenBrowse.isSelected());
  209. _prefs.put(JabRefPreferences.EMAIL_SUBJECT, emailSubject.getText());
  210. _prefs.putBoolean(JabRefPreferences.OPEN_FOLDERS_OF_ATTACHED_FILES, openFoldersOfAttachedFiles.isSelected());
  211. }
  212. public boolean readyToClose() {
  213. return true;
  214. }
  215. public String getTabName() {
  216. return Globals.lang("External programs");
  217. }
  218. }