├── LICENSE.md ├── README.md ├── fetchArxiv ├── build.xml ├── fetchArxiv.1.0.jar └── src │ ├── fetchArxiv │ ├── Actions.java │ ├── FetchArxivPanel.java │ └── FetchArxivPlugin.java │ └── plugin.xml └── renamefile ├── README.md ├── build.xml ├── lib └── grouplayout.jar └── src ├── about.txt ├── plugin.xml └── renamefile ├── OptionsDialog.java ├── RenameDialog.java ├── RenameFilePanel.java ├── RenameFilePlugin.java └── Utils.java /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Sergey Kor 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Jabref-plugins 2 | 3 | This is a small collection of plugins for the BibTex editor [JabRef](http://jabref.sourceforge.net/). 4 | Currently it contains plugins: 5 | 6 | * fetchArxiv 7 | * renamefile 8 | 9 | In order to install any plugin one has to 10 | 11 | 1. download the jar file for the plugin 12 | 2. go to Plugins/Manage plugins/Install plugin in JabRef 13 | 3. install the downloaded file 14 | 15 | 16 | ### fetchArxiv 17 | This plugin can be used to download a preprint information from arxiv.org by 18 | providing its arXiv ID. The ID is saved in the BibTex entry field "eprint". 19 | 20 | ### renamefile 21 | This plugin can be used to rename/copy/delete files attached to BibTex entries. 22 | The file information is stored in the entry field "file". Files can be renamed 23 | according to their BibTeX entry. The rename pattern uses an extended syntax of 24 | the [BibTeX key generator](http://jabref.sourceforge.net/help/LabelPatterns.php) of JabRef. 25 | For more infromation and examples see the help page of the plugin. 26 | 27 | The newest versions can be found [here](https://github.com/korv/Jabref-plugins/releases). 28 | The older versions can be found [here](https://github.com/korv/Jabref-plugins/downloads). 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /fetchArxiv/build.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /fetchArxiv/fetchArxiv.1.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/korv/Jabref-plugins/d47bc3e980768ac33a9aced1bc9a02c64a4f17f4/fetchArxiv/fetchArxiv.1.0.jar -------------------------------------------------------------------------------- /fetchArxiv/src/fetchArxiv/Actions.java: -------------------------------------------------------------------------------- 1 | package fetchArxiv; 2 | 3 | 4 | import javax.swing.JOptionPane; 5 | 6 | import net.sf.jabref.*; 7 | import net.sf.jabref.imports.OAI2Fetcher; 8 | 9 | public class Actions { 10 | private BasePanel panel; 11 | private JabRefFrame frame; 12 | 13 | public Actions(JabRefFrame frame){ 14 | this.frame=frame; 15 | panel=frame.basePanel(); 16 | } 17 | 18 | public void actionNew(){ 19 | getInfo(null); 20 | } 21 | 22 | public void actionInfo(){ 23 | BibtexEntry[] bes = panel.mainTable.getSelectedEntries(); 24 | for(BibtexEntry b:bes) 25 | getInfo(b); 26 | } 27 | 28 | public void actionId(){ 29 | BibtexEntry[] bes = panel.mainTable.getSelectedEntries(); 30 | for(BibtexEntry b:bes) 31 | getId(b); 32 | } 33 | 34 | private void getInfo(BibtexEntry b){ 35 | String key; 36 | if(b!=null) { 37 | key=b.getField("eprint"); 38 | key = (String)JOptionPane.showInputDialog(frame, 39 | "author: "+b.getField("author")+"\n" 40 | +"title: "+b.getField("title")+"\n"+ 41 | "Please specify the ArXiv id:", "Get Info", 42 | JOptionPane.PLAIN_MESSAGE,null,null,key); 43 | } else { 44 | key = (String)JOptionPane.showInputDialog(frame, 45 | "Please specify the ArXiv id:", "New Entry", 46 | JOptionPane.PLAIN_MESSAGE,null,null,""); 47 | 48 | } 49 | if(key==null || key.isEmpty()) { 50 | return; 51 | } 52 | key=key.trim(); 53 | OAI2Fetcher f = new OAI2Fetcher(); 54 | // f.status=frame; 55 | BibtexEntry e = f.importOai2Entry(key); 56 | if(e==null || e.getField("author")==null) { 57 | frame.showMessage("Key: "+key+"not found"); 58 | return; 59 | } 60 | if(b==null) 61 | b=panel.newEntry(BibtexEntryType.MISC); 62 | String[] fields={"author","title","eprint"}; 63 | for(String s:fields) 64 | b.setField(s,e.getField(s)); 65 | b.setField("year",getYearFromId(key)); 66 | panel.markBaseChanged(); 67 | // panel.highlightEntry(b); 68 | panel.showEntry(b); 69 | } 70 | 71 | private String getYearFromId(String key){ 72 | // Id has the form math/1109267 or 1109.0267 (September 2011) 73 | int n=key.lastIndexOf("/"); 74 | String y=key.substring(n+1,n+3); 75 | if(Integer.parseInt(y)>90) 76 | return "19" + y; 77 | else 78 | return "20" + y; 79 | } 80 | 81 | private void getId(BibtexEntry b){ 82 | String key=b.getField("eprint"); 83 | key = (String)JOptionPane.showInputDialog(frame, 84 | "author: "+b.getField("author")+"\n" 85 | +"title: "+b.getField("title")+"\n"+ 86 | "Please specify the ArXiv id:", "Set id", 87 | JOptionPane.PLAIN_MESSAGE,null,null,key); 88 | if(key==null || key.isEmpty()) 89 | return; 90 | b.setField("eprint",key); 91 | panel.markBaseChanged(); 92 | } 93 | 94 | } 95 | -------------------------------------------------------------------------------- /fetchArxiv/src/fetchArxiv/FetchArxivPanel.java: -------------------------------------------------------------------------------- 1 | package fetchArxiv; 2 | 3 | 4 | import java.awt.event.ActionEvent; 5 | import java.awt.event.ActionListener; 6 | 7 | import javax.swing.*; 8 | 9 | import net.sf.jabref.*; 10 | 11 | @SuppressWarnings("serial") 12 | class FetchArxivPanel extends SidePaneComponent implements ActionListener { 13 | 14 | private JButton btnNew,btnInfo,btnId; 15 | private Actions actions; 16 | 17 | public FetchArxivPanel(SidePaneManager manager,JabRefFrame frame,JMenuItem menu) { 18 | super(manager, GUIGlobals.getIconUrl("openUrl"), "Fetch arXiv"); 19 | this.manager = manager; 20 | setActiveBasePanel(frame.basePanel()); 21 | actions = new Actions(frame); 22 | 23 | btnNew=getButton("New Entry","Create entry from an arXiv eprint",""); 24 | btnInfo=getButton("Get Info","Fetch entry information from an arXiv eprint",""); 25 | btnId=getButton("Set Id","Set eprint Id",""); 26 | 27 | JPanel split = new JPanel(); 28 | split.setLayout(new BoxLayout(split, BoxLayout.LINE_AXIS)); 29 | split.add(btnNew); 30 | split.add(btnInfo); 31 | split.add(btnId); 32 | 33 | setContent(split); 34 | setName("fetchArxiv"); 35 | } 36 | 37 | private JButton getButton(String title,String tip,String icon){ 38 | JButton btn=new JButton(GUIGlobals.getImage(icon)); 39 | btn.addActionListener(this); 40 | btn.setText(title); 41 | btn.setToolTipText(tip); 42 | return btn; 43 | } 44 | 45 | public void actionPerformed(ActionEvent e) { 46 | if (e.getSource() == btnNew) 47 | actions.actionNew(); 48 | else if (e.getSource() == btnInfo) 49 | actions.actionInfo(); 50 | else if (e.getSource() == btnId) 51 | actions.actionId(); 52 | } 53 | 54 | public void componentOpening() { 55 | Globals.prefs.putBoolean("FAShow",true); 56 | } 57 | 58 | public void componentClosing() { 59 | Globals.prefs.putBoolean("FAShow",false); 60 | } 61 | 62 | 63 | } -------------------------------------------------------------------------------- /fetchArxiv/src/fetchArxiv/FetchArxivPlugin.java: -------------------------------------------------------------------------------- 1 | package fetchArxiv; 2 | 3 | 4 | import net.sf.jabref.*; 5 | import net.sf.jabref.plugin.*; 6 | 7 | import javax.swing.*; 8 | 9 | import java.awt.event.*; 10 | 11 | 12 | public class FetchArxivPlugin implements SidePanePlugin, ActionListener { 13 | 14 | private JabRefFrame frame; 15 | protected SidePaneManager manager; 16 | private JMenuItem toggleMenu; 17 | private FetchArxivPanel comp; 18 | 19 | public void init(JabRefFrame frame, SidePaneManager manager) { 20 | this.manager = manager; 21 | this.frame = frame; 22 | toggleMenu = new JMenuItem("Toggle fetch arXiv panel",new ImageIcon(GUIGlobals.getIconUrl("openUrl"))); 23 | toggleMenu.setMnemonic(KeyEvent.VK_F); 24 | toggleMenu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, ActionEvent.CTRL_MASK+ActionEvent.ALT_MASK)); 25 | toggleMenu.addActionListener(this); 26 | Globals.prefs.defaults.put("FAShow",true); 27 | } 28 | 29 | public SidePaneComponent getSidePaneComponent() { 30 | if (comp == null) 31 | comp = new FetchArxivPanel(manager,frame,toggleMenu); 32 | return comp; 33 | } 34 | 35 | public JMenuItem getMenuItem() { 36 | if (Globals.prefs.getBoolean("FAShow")) 37 | manager.show("fetchArxiv"); 38 | return toggleMenu; 39 | } 40 | 41 | public String getShortcutKey() { 42 | return null; 43 | } 44 | 45 | public void actionPerformed(ActionEvent e) { 46 | if (e.getSource() == toggleMenu) 47 | manager.toggle("fetchArxiv"); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /fetchArxiv/src/plugin.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /renamefile/README.md: -------------------------------------------------------------------------------- 1 | # Renamefile 2 | 3 | This is a plugin for the BibTex editor [Jabref](http://jabref.sourceforge.net/). 4 | It can be used to rename/copy/delete files attached to BibTex entries. 5 | The file information is stored in the entry field "file". 6 | Files can be renamed according to their BibTeX entry. The rename pattern uses an extended syntax of 7 | the [BibTeX key generator](http://jabref.sourceforge.net/help/LabelPatterns.php) of JabRef. 8 | For more infromation and examples see the help page of the plugin. 9 | 10 | The newest versions can be found [here](https://github.com/korv/Jabref-plugins/releases). 11 | The older versions can be found [here](https://github.com/korv/Jabref-plugins/downloads). 12 | 13 | In order to install this plugin one has to 14 | 15 | 1. download the jar file for the plugin 16 | 2. go to Plugins/Manage plugins/Install plugin in JabRef 17 | 3. install the downloaded file 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /renamefile/build.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /renamefile/lib/grouplayout.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/korv/Jabref-plugins/d47bc3e980768ac33a9aced1bc9a02c64a4f17f4/renamefile/lib/grouplayout.jar -------------------------------------------------------------------------------- /renamefile/src/about.txt: -------------------------------------------------------------------------------- 1 | Rename file plugin v1.6.2. 2 | 3 | This plugin can be used to rename/copy/delete files attached 4 | to the BibTex entries (stored in the field "file"). 5 | 6 | 1. Name patterns 7 | 8 | Files can be renamed according to their BibTeX entry. 9 | The rename pattern uses the same syntax as the BibTeX 10 | key generator of JabRef. For more details see 11 | http://jabref.sourceforge.net/help/LabelPatterns.php 12 | 13 | Additionally to the existing keys there is a key [type] 14 | for an entry type. 15 | 16 | Additionally to the existing modifiers (:lower, :upper, :abbr) 17 | there is a modifier :regex:str1:str2 that replaces string str1 18 | by string str2. One can apply several modifiers to one field. 19 | 20 | Some examples of name patterns: 21 | [bibtexkey] 22 | folder/subfolder/[auth]. [shorttitle] 23 | [type]/[auth]-[year]-[title] 24 | [authors]. [title] 25 | [auth]-[year]-[shorttitle] 26 | [auth:lower]_[veryshorttitle:lower]_[year] 27 | [auth]_[title:regex: :_] - replaces spaces by underscores 28 | [authors:regex:':] - removes ' from all names 29 | 30 | 31 | 2. Folders 32 | 33 | 2.1. One can move files relative to their current position: 34 | Uncheck "Use folder". 35 | 36 | 2.2 One can move files relative to the file directory: 37 | Check "Use folder" and specify the relative folder. 38 | Example: folder/subfolder or folder\subfolder. 39 | 40 | The file directory should be defined in 41 | Options/Preferences/External programs/Main file directory 42 | If it is empty, then the location of the bib file is used. 43 | 44 | 2.3 One can move files using absolute paths: 45 | Check "Use folder" and specify the absolute folder. 46 | Example c:\folder\subfolder. 47 | 48 | 3. Several files in one entry 49 | If there are several files attached to one entry, then 50 | numbers are added at the end of file names. 51 | 52 | 53 | History 54 | 55 | Version 1.6.2 (Jul 2014) 56 | * Substitution for \ss, \aa, \AA, \o, \i, \l, \L 57 | * Remove accents \", \', \^, \v, \H, etc. 58 | * Remove all latex commands like \mathrm, \mathbb, etc. 59 | 60 | Version 1.6.1 (Jul 2014) 61 | * Bug fixes 62 | * Added modifier :regex:str1:str2 63 | * Compatibilty with JabRef 2.10. 64 | 65 | Version 1.5 (Feb 2014) 66 | * Added key [type] for an entry type. 67 | * Remove symbols \,/,<,>,?,{,},$,",:,\n from file names 68 | 69 | Version 1.4 (Jul 2012) 70 | * Help is added 71 | * Compatibility with JabRef 2.6 72 | * Dialog if file can not be deleted 73 | * Add numbers at the end of file names (with a confirmation 74 | dialog) if files to be created already exist. 75 | * No base change mark after copying of files. 76 | 77 | Version 1.3 (Jul 2012) 78 | * Compatibility with JabRef 2.8.1 79 | * Update entry editor after renaming of files. 80 | 81 | Version 1.2 (Sep 2011) 82 | * Remove some symbols from filenames. 83 | 84 | Version 1.1 (Nov 2010) 85 | * Rename/Copy/Delete implementation 86 | -------------------------------------------------------------------------------- /renamefile/src/plugin.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /renamefile/src/renamefile/OptionsDialog.java: -------------------------------------------------------------------------------- 1 | package renamefile; 2 | 3 | 4 | 5 | 6 | import java.awt.*; 7 | import java.awt.event.*; 8 | 9 | import javax.swing.*; 10 | 11 | import net.sf.jabref.Globals; 12 | 13 | import org.dyno.visual.swing.layouts.*; 14 | import org.dyno.visual.swing.layouts.GroupLayout; 15 | 16 | public class OptionsDialog extends JDialog implements ActionListener{ 17 | private static final long serialVersionUID = 1L; 18 | private JCheckBox cbName,cbDir; 19 | private JTextField tfDir,tfPattern; 20 | private JButton btnOk,btnCancel; 21 | 22 | public void mess(String s){ 23 | JOptionPane.showMessageDialog (this,s, "Message", JOptionPane.INFORMATION_MESSAGE); 24 | } 25 | 26 | public OptionsDialog(Frame parent) { 27 | super(parent); 28 | initComponents(); 29 | } 30 | 31 | 32 | private void initComponents() { 33 | initElements(); 34 | readValues(); 35 | JPanel p,p1; 36 | 37 | JPanel panel=new JPanel(); 38 | panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); 39 | add(panel); 40 | 41 | p=new JPanel(); 42 | p.setLayout(new GroupLayout()); 43 | p.add(cbDir, new Constraints(new Leading(10, 150, 8, 8), new Leading(10, 10, 10))); 44 | p.add(cbName, new Constraints(new Leading(10, 150, 8, 8), new Leading(38, 8, 8))); 45 | p.add(tfDir, new Constraints(new Bilateral(170, 12, 4), new Leading(12, 12, 12))); 46 | p.add(tfPattern, new Constraints(new Bilateral(170, 12, 4), new Leading(40, 12, 12))); 47 | 48 | p1=new JPanel(); 49 | p1.setLayout(new BoxLayout(p1, BoxLayout.X_AXIS)); 50 | p1.add(p); 51 | panel.add(p1); 52 | 53 | p=new JPanel(); 54 | p.add(btnOk); 55 | p.add(btnCancel); 56 | p1=new JPanel(); 57 | p1.setLayout(new BoxLayout(p1,BoxLayout.X_AXIS)); 58 | p1.add(p); 59 | panel.add(p1); 60 | 61 | setSize(800, 120); 62 | setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); 63 | setTitle("Options"); 64 | setLocationRelativeTo(null); 65 | getContentPane().setPreferredSize(getSize()); 66 | pack(); 67 | setVisible(true); 68 | } 69 | 70 | private void initElements(){ 71 | cbDir = new JCheckBox(); 72 | cbDir.setText("Use folder:"); 73 | cbName = new JCheckBox(); 74 | cbName.setText("Use name pattern:"); 75 | tfDir = new JTextField(); 76 | tfDir.addActionListener(this); 77 | tfPattern = new JTextField(); 78 | btnOk = new JButton(); 79 | btnOk.setText("Ok"); 80 | btnOk.addActionListener(this); 81 | btnOk.setPreferredSize(new Dimension(100, 26)); 82 | btnCancel = new JButton(); 83 | btnCancel.setText("Cancel"); 84 | btnCancel.addActionListener(this); 85 | btnCancel.setPreferredSize(new Dimension(100, 26)); 86 | } 87 | 88 | @Override 89 | public void actionPerformed(ActionEvent e) { 90 | Object o=e.getSource(); 91 | if(o==btnOk) { 92 | saveValues(); 93 | dispose(); 94 | } else if(o==btnCancel) 95 | dispose(); 96 | } 97 | 98 | private void readValues(){ 99 | cbDir.setSelected(!Globals.prefs.getBoolean("SameFolder")); 100 | cbName.setSelected(!Globals.prefs.getBoolean("SameName")); 101 | tfDir.setText(Globals.prefs.get("MoveFolder")); 102 | tfPattern.setText(Globals.prefs.get("RenamePattern")); 103 | } 104 | private void saveValues(){ 105 | Globals.prefs.putBoolean("SameFolder",!cbDir.isSelected()); 106 | Globals.prefs.putBoolean("SameName",!cbName.isSelected()); 107 | Globals.prefs.put("MoveFolder",tfDir.getText()); 108 | Globals.prefs.put("RenamePattern",tfPattern.getText()); 109 | } 110 | 111 | } 112 | -------------------------------------------------------------------------------- /renamefile/src/renamefile/RenameDialog.java: -------------------------------------------------------------------------------- 1 | package renamefile; 2 | 3 | 4 | import javax.swing.*; 5 | import javax.swing.table.*; 6 | 7 | import org.dyno.visual.swing.layouts.Bilateral; 8 | import org.dyno.visual.swing.layouts.Constraints; 9 | import org.dyno.visual.swing.layouts.GroupLayout; 10 | import org.dyno.visual.swing.layouts.Leading; 11 | 12 | import java.awt.*; 13 | import java.awt.event.*; 14 | import java.io.File; 15 | import java.io.IOException; 16 | import java.util.HashMap; 17 | import java.util.ArrayList; 18 | import net.sf.jabref.*; 19 | import net.sf.jabref.gui.*; 20 | 21 | public class RenameDialog extends JDialog implements ActionListener, FocusListener{ 22 | private static final long serialVersionUID = 1L; 23 | private final int[] renWidth={10,100,100,300,300,300}; 24 | private final int[] delWidth={10,100,100,300,300}; 25 | private JabRefFrame frame; 26 | private BibtexEntry[] bes; 27 | private int mode; 28 | 29 | 30 | private FLTableModel tm; 31 | private JTable table; 32 | private JPanel panel; 33 | private JCheckBox cbName,cbDir; 34 | private JTextField tfDir,tfPattern; 35 | private JButton btnOk,btnCancel; 36 | 37 | private final String[] titleString={"Rename/move files","Copy files","Delete files"}; 38 | 39 | public RenameDialog(JabRefFrame frame,BibtexEntry[] bes ) { 40 | this(frame,bes,0); 41 | } 42 | 43 | public RenameDialog(JabRefFrame frame,BibtexEntry[] bes, int mode) { 44 | super(frame); 45 | this.frame=frame; 46 | this.bes=bes; 47 | this.mode=mode; 48 | initElements(); 49 | 50 | JPanel p,p1; 51 | panel=new JPanel(); 52 | panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); 53 | add(panel); 54 | 55 | p = new JPanel(); 56 | p.setLayout(new BoxLayout(p, BoxLayout.PAGE_AXIS)); 57 | p.add(new JScrollPane(table)); 58 | p.setBorder(BorderFactory.createEmptyBorder(10,10,10,10)); 59 | panel.add(p); 60 | 61 | if(mode!=2){ 62 | p=new JPanel(); 63 | p.setLayout(new GroupLayout()); 64 | p.add(cbDir, new Constraints(new Leading(10, 150, 8, 8), new Leading(10, 10, 10))); 65 | p.add(cbName, new Constraints(new Leading(10, 150, 8, 8), new Leading(38, 8, 8))); 66 | p.add(tfDir, new Constraints(new Bilateral(170, 12, 4), new Leading(12, 12, 12))); 67 | p.add(tfPattern, new Constraints(new Bilateral(170, 12, 4), new Leading(40, 12, 12))); 68 | 69 | p1=new JPanel(); 70 | p1.setLayout(new BoxLayout(p1, BoxLayout.X_AXIS)); 71 | p1.add(p); 72 | panel.add(p1); 73 | } 74 | 75 | p=new JPanel(); 76 | p.add(btnOk); 77 | p.add(btnCancel); 78 | p1=new JPanel(); 79 | p1.setLayout(new BoxLayout(p1,BoxLayout.X_AXIS)); 80 | p1.add(p); 81 | panel.add(p1); 82 | 83 | setTitle(titleString[mode]); 84 | setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); 85 | getRootPane().setDefaultButton(btnOk); 86 | pack(); 87 | setLocationRelativeTo(null); 88 | setVisible(true); 89 | } 90 | 91 | private void initElements(){ 92 | if(mode!=2){ 93 | cbDir = new JCheckBox(); 94 | cbDir.setText("Use folder:"); 95 | cbDir.addActionListener(this); 96 | cbName = new JCheckBox(); 97 | cbName.setText("Use name pattern:"); 98 | cbName.addActionListener(this); 99 | tfDir = new JTextField(); 100 | tfDir.addFocusListener(this); 101 | tfDir.addActionListener(this); 102 | tfPattern = new JTextField(); 103 | tfPattern.addFocusListener(this); 104 | tfPattern.addActionListener(this); 105 | readValues(); 106 | } 107 | btnOk = new JButton(); 108 | btnOk.setText("Ok"); 109 | btnOk.addActionListener(this); 110 | btnOk.setPreferredSize(new Dimension(100, 26)); 111 | btnCancel = new JButton(); 112 | btnCancel.setText("Cancel"); 113 | btnCancel.addActionListener(this); 114 | btnCancel.setPreferredSize(new Dimension(100, 26)); 115 | tm = new FLTableModel(bes,mode); 116 | table = new JTable(tm); 117 | table.setPreferredScrollableViewportSize(new Dimension(800, 200)); 118 | table.setFillsViewportHeight(true); 119 | // table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); 120 | int[] width = mode==2 ? delWidth : renWidth; 121 | for(int i=0;i> data; 132 | private int mode; 133 | 134 | public FLTableModel(BibtexEntry[] b,int mode) { 135 | this.mode=mode; 136 | columnNames = mode==2 ? delNames : renNames; 137 | setData(b); 138 | } 139 | 140 | public void setData(BibtexEntry[] b){ 141 | data = new ArrayList>(); 142 | FileListTableModel m; 143 | for (BibtexEntry e:b) { 144 | m = new FileListTableModel(); 145 | m.setContent(e.getField("file")); 146 | for (int j=0;j r= new HashMap(); 149 | r.put(0,new Boolean(true)); 150 | r.put(1,tostr(e.getField(BibtexFields.KEY_FIELD))); 151 | r.put(2,tostr(e.getField("author"))); 152 | r.put(3,tostr(e.getField("title"))); 153 | r.put(4,f.getLink()); 154 | r.put("fe",f); //FileListEntry 155 | r.put("be",e); //BibtexEntry 156 | if(mode!=2) 157 | r.put(5,getNewFileName(f.getLink(),e)); 158 | data.add(r); 159 | } 160 | } 161 | } 162 | private Object tostr(Object s){ 163 | return s==null ? "" : s; 164 | } 165 | 166 | public void changeData(BibtexEntry[] b){ 167 | setData(b); 168 | fireTableDataChanged(); 169 | } 170 | 171 | public int getColumnCount() { 172 | return columnNames.length; 173 | } 174 | 175 | public int getRowCount() { 176 | return data.size(); 177 | } 178 | 179 | public String getColumnName(int col) { 180 | return columnNames[col]; 181 | } 182 | 183 | public Object getValueAt(int row, int col) { 184 | return data.get(row).get(col); 185 | } 186 | 187 | public Class getColumnClass(int c) { 188 | return getValueAt(0, c).getClass(); 189 | } 190 | 191 | public boolean isCellEditable(int row, int col) { 192 | if (col < 1) { 193 | return true; 194 | } else { 195 | return false; 196 | } 197 | } 198 | 199 | public void setValueAt(Object value, int row, int col) { 200 | data.get(row).put(col,value); 201 | fireTableCellUpdated(row, col); 202 | } 203 | 204 | public HashMap getRow(int row){ 205 | return data.get(row); 206 | } 207 | } 208 | 209 | private void readValues(){ 210 | cbDir.setSelected(!Globals.prefs.getBoolean("SameFolder")); 211 | cbName.setSelected(!Globals.prefs.getBoolean("SameName")); 212 | tfDir.setText(Globals.prefs.get("MoveFolder")); 213 | tfPattern.setText(Globals.prefs.get("RenamePattern")); 214 | } 215 | private void saveValues(){ 216 | Globals.prefs.putBoolean("SameFolder",!cbDir.isSelected()); 217 | Globals.prefs.putBoolean("SameName",!cbName.isSelected()); 218 | Globals.prefs.put("MoveFolder",tfDir.getText()); 219 | Globals.prefs.put("RenamePattern",tfPattern.getText()); 220 | } 221 | 222 | public void actionPerformed(ActionEvent evt) { 223 | Object s=evt.getSource(); 224 | if (s == btnOk) { 225 | if(mode!=2) 226 | saveValues(); 227 | for (int i = 0;i < tm.getRowCount();i++) { 228 | HashMap r=tm.getRow(i); 229 | Boolean sel = (Boolean)r.get(0); 230 | if (sel) { 231 | BibtexEntry b=(BibtexEntry)r.get("be"); 232 | String of = ((FileListEntry)r.get("fe")).getLink(); 233 | switch(mode){ 234 | case 0: renameFile(b,of,this); break; 235 | case 1: copyFile(b,of,this); break; 236 | case 2: removeFile(b,of,this); break; 237 | } 238 | } 239 | } 240 | dispose(); 241 | if(mode!=1){ 242 | frame.basePanel().markBaseChanged(); 243 | frame.basePanel().updateEntryEditorIfShowing(); 244 | } 245 | } else if (s == btnCancel) { 246 | dispose(); 247 | } else if (mode!=2 && (s==cbDir || s==cbName || s==tfDir || s==tfPattern)) 248 | tm.changeData(bes); 249 | } 250 | 251 | public void focusLost(FocusEvent e) { 252 | tm.changeData(bes); 253 | } 254 | 255 | public String getNewFileName(String ofn,BibtexEntry b){ 256 | boolean sameDir=!cbDir.isSelected(); 257 | boolean sameName=!cbName.isSelected(); 258 | String dir=tfDir.getText(); 259 | String pattern=tfPattern.getText(); 260 | return Utils.getNewFileName(ofn, b,sameDir, sameName, dir, pattern); 261 | } 262 | 263 | @Override 264 | public void focusGained(FocusEvent arg0) { 265 | // TODO Auto-generated method stub 266 | 267 | } 268 | 269 | private String changeFileName(String f, int n){ 270 | if(n==0) 271 | return f; 272 | int m=f.lastIndexOf('.'); 273 | if(m==-1) 274 | return f+n; 275 | return f.substring(0,m)+n+'.'+f.substring(m+1); 276 | } 277 | 278 | public void renameFile(BibtexEntry b,String ofn, Component comp){ 279 | String dir = Utils.getFileDir(); 280 | File of = Util.expandFilename(ofn, dir); //null if file does not exist 281 | if (of == null || !of.exists()) 282 | return; 283 | String fn1= Utils.getNewFileName(ofn,b); 284 | for(int n=0;;){ 285 | String fn=changeFileName(fn1,n); 286 | File file = new File(fn); 287 | if(!file.isAbsolute()) 288 | file=new File(dir,fn); 289 | try { 290 | if(file.getCanonicalPath().equals(of.getCanonicalPath())){ 291 | Utils.removeFileEntry(b,ofn); 292 | Utils.addFileEntry(b,fn); 293 | return; 294 | } 295 | } catch (IOException e) { 296 | e.printStackTrace(); 297 | return; 298 | } 299 | if(file.exists()){ 300 | n++; 301 | continue; 302 | } 303 | if(n!=0){ 304 | String k = (String)JOptionPane.showInputDialog(comp, 305 | "The file\n" 306 | +ofn+"\n will be renamed to", 307 | "New filename", 308 | JOptionPane.PLAIN_MESSAGE,null,null,fn); 309 | if(k == null) 310 | return; 311 | if(!k.equals(fn)){ 312 | if(Utils.haveSameExtensions(k,ofn)){ 313 | n=0; 314 | fn1=k; 315 | } 316 | continue; 317 | } 318 | } 319 | File par=file.getParentFile(); 320 | if(par!=null) 321 | par.mkdirs(); 322 | if (!of.renameTo(file)){ 323 | String k = (String)JOptionPane.showInputDialog(comp,"Can not rename the file\n" + ofn 324 | +"\n Close the file or specify a different filename", 325 | "New filename", 326 | JOptionPane.PLAIN_MESSAGE,null,null,fn); 327 | if (k == null) 328 | return; 329 | if(!k.equals(fn) && Utils.haveSameExtensions(k,ofn)){ 330 | n=0; 331 | fn1=k; 332 | } 333 | continue; 334 | } 335 | Utils.removeFileEntry(b,ofn); 336 | Utils.addFileEntry(b,fn); 337 | break; 338 | } 339 | } 340 | 341 | public void copyFile(BibtexEntry b,String ofn, Component comp){ 342 | String dir = Utils.getFileDir(); 343 | File of = Util.expandFilename(ofn, dir); //null if file does not exist 344 | if (of == null || !of.exists()) 345 | return; 346 | String fn1= Utils.getNewFileName(ofn,b); 347 | for(int n=0;;){ 348 | String fn=changeFileName(fn1,n); 349 | File file = new File(fn); 350 | if(!file.isAbsolute()) 351 | file=new File(dir,fn); 352 | try { 353 | if(file.getCanonicalPath().equals(of.getCanonicalPath())) 354 | return; 355 | } catch (IOException e) { 356 | e.printStackTrace(); 357 | return; 358 | } 359 | if(file.exists()){ 360 | n++; 361 | continue; 362 | } 363 | if(n!=0){ 364 | String k = (String)JOptionPane.showInputDialog(comp, 365 | "The file\n" 366 | +ofn+"\n will be copied to", 367 | "New filename", 368 | JOptionPane.PLAIN_MESSAGE,null,null,fn); 369 | if(k == null) 370 | return; 371 | if(!k.equals(fn)){ 372 | if(Utils.haveSameExtensions(k,ofn)){ 373 | n=0; 374 | fn1=k; 375 | } 376 | continue; 377 | } 378 | } 379 | File par=file.getParentFile(); 380 | if(par!=null) 381 | par.mkdirs(); 382 | if (!Utils.copyFile(of,file)){ 383 | String k = (String)JOptionPane.showInputDialog(comp,"Can not copy the file\n" + ofn 384 | +"\n Specify a different filename", 385 | "New filename", 386 | JOptionPane.PLAIN_MESSAGE,null,null,fn); 387 | if (k == null) 388 | return; 389 | if(!k.equals(fn) && Utils.haveSameExtensions(k,ofn)){ 390 | n=0; 391 | fn1=k; 392 | } 393 | continue; 394 | } 395 | break; 396 | } 397 | } 398 | 399 | private void removeFile(BibtexEntry b, String fn, Component comp) { 400 | if(!Utils.hasFile(b,fn)) 401 | return; 402 | String dir = Utils.getFileDir(); 403 | File f=Util.expandFilename(fn,dir); //null if file does not exist 404 | if(f==null || !f.exists()){ 405 | Utils.removeFileEntry(b,fn); 406 | return; 407 | } 408 | while(!f.delete()){ 409 | int k = JOptionPane.showConfirmDialog(comp, 410 | "Close the file\n"+fn, 411 | "Delete file", 412 | JOptionPane.OK_CANCEL_OPTION); 413 | if(k!=JOptionPane.OK_OPTION) 414 | return; 415 | } 416 | Utils.removeFileEntry(b,fn); 417 | } 418 | 419 | 420 | } 421 | -------------------------------------------------------------------------------- /renamefile/src/renamefile/RenameFilePanel.java: -------------------------------------------------------------------------------- 1 | package renamefile; 2 | 3 | 4 | import java.awt.GridBagConstraints; 5 | import java.awt.GridBagLayout; 6 | import java.awt.event.ActionEvent; 7 | import java.awt.event.ActionListener; 8 | 9 | import javax.swing.*; 10 | 11 | import net.sf.jabref.*; 12 | 13 | @SuppressWarnings("serial") 14 | class RenameFilePanel extends SidePaneComponent implements ActionListener { 15 | 16 | private JButton btnMove,btnCopy,btnDelete,btnSettings,btnHelp; 17 | private JabRefFrame frame; 18 | 19 | public RenameFilePanel(SidePaneManager manager,JabRefFrame frame,JMenuItem menu) { 20 | super(manager, GUIGlobals.getIconUrl("openUrl"), "Rename file"); 21 | this.manager = manager; 22 | this.frame = frame; 23 | setActiveBasePanel(frame.basePanel()); 24 | 25 | btnMove=getButton("Rename","Rename/move file(s).",""); 26 | btnCopy=getButton("Copy","Copy file(s).",""); 27 | btnDelete=getButton("Delete","Detach the local pdf from the " + 28 | "BibTeX entry and delete the local pdf from the filesystem.",""); 29 | btnSettings=getButton("","Settings","preferences"); 30 | btnHelp=getButton("","Help","help"); 31 | JPanel p = new JPanel(); 32 | p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS)); 33 | JPanel p1 = new JPanel(new GridBagLayout()); 34 | JPanel p2 = new JPanel(new GridBagLayout()); 35 | GridBagConstraints c = new GridBagConstraints(); 36 | c.fill = GridBagConstraints.HORIZONTAL; 37 | c.weightx = .5; 38 | p1.add(btnMove,c); 39 | c.gridx = 1; 40 | p1.add(btnDelete,c); 41 | c.gridx=0; 42 | p2.add(btnCopy,c); 43 | c.gridx=1; 44 | p2.add(btnSettings,c); 45 | c.gridx=2; 46 | p2.add(btnHelp,c); 47 | p.add(p1); 48 | p.add(p2); 49 | setContent(p); 50 | setName("renamefile"); 51 | } 52 | 53 | private JButton getButton(String title,String tip,String icon){ 54 | JButton btn=new JButton(GUIGlobals.getImage(icon)); 55 | btn.addActionListener(this); 56 | btn.setText(title); 57 | btn.setToolTipText(tip); 58 | return btn; 59 | } 60 | 61 | public void actionPerformed(ActionEvent e) { 62 | if (e.getSource() == btnSettings) { 63 | new OptionsDialog(frame); 64 | } else if (e.getSource() == btnMove) { 65 | BibtexEntry[] bes = panel.mainTable.getSelectedEntries(); 66 | new RenameDialog(frame,bes); 67 | } else if (e.getSource() == btnCopy) { 68 | BibtexEntry[] bes = panel.mainTable.getSelectedEntries(); 69 | new RenameDialog(frame,bes,1); 70 | } else if (e.getSource() == btnDelete) { 71 | BibtexEntry[] bes = panel.mainTable.getSelectedEntries(); 72 | new RenameDialog(frame,bes,2); 73 | } else if (e.getSource() == btnHelp){ 74 | Utils.displayAbout(frame); 75 | } 76 | } 77 | 78 | public void componentOpening() { 79 | Globals.prefs.putBoolean("renamefileShow",true); 80 | } 81 | 82 | public void componentClosing() { 83 | Globals.prefs.putBoolean("renamefileShow",false); 84 | } 85 | 86 | } 87 | 88 | 89 | 90 | -------------------------------------------------------------------------------- /renamefile/src/renamefile/RenameFilePlugin.java: -------------------------------------------------------------------------------- 1 | package renamefile; 2 | 3 | 4 | import net.sf.jabref.*; 5 | import net.sf.jabref.plugin.*; 6 | 7 | import javax.swing.*; 8 | 9 | import java.awt.event.*; 10 | 11 | 12 | public class RenameFilePlugin implements SidePanePlugin, ActionListener { 13 | 14 | protected SidePaneManager manager; 15 | private JMenuItem toggleMenu; 16 | private JabRefFrame frame; 17 | private RenameFilePanel comp = null; 18 | 19 | public void init(JabRefFrame frame, SidePaneManager manager) { 20 | this.manager = manager; 21 | this.frame = frame; 22 | 23 | toggleMenu = new JMenuItem("Toggle rename file panel",new ImageIcon(GUIGlobals.getIconUrl("openUrl"))); 24 | // toggleMenu.setMnemonic(KeyEvent.VK_R); 25 | toggleMenu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, ActionEvent.ALT_MASK+ActionEvent.CTRL_MASK)); 26 | toggleMenu.addActionListener(this); 27 | 28 | Globals.prefs.defaults.put("renamefileShow",true); 29 | Globals.prefs.putDefaultValue("SameFolder",true);//move to the same folder, the new path is relative/absolute depending on the old path 30 | Globals.prefs.putDefaultValue("SameName",false); 31 | Globals.prefs.putDefaultValue("MoveFolder",""); // relative/absolute folder 32 | Globals.prefs.putDefaultValue("RenamePattern","[auth:lower]_[veryshorttitle:lower]_[year]"); 33 | Utils.init(frame); 34 | } 35 | 36 | public SidePaneComponent getSidePaneComponent() { 37 | if(comp==null) 38 | comp = new RenameFilePanel(manager,frame,toggleMenu); 39 | return comp; 40 | } 41 | 42 | public JMenuItem getMenuItem() { 43 | if (Globals.prefs.getBoolean("renamefileShow")) 44 | manager.show("renamefile"); 45 | return toggleMenu; 46 | } 47 | 48 | public String getShortcutKey() { 49 | return null; 50 | } 51 | 52 | public void actionPerformed(ActionEvent e) { 53 | if (e.getSource() == toggleMenu) 54 | manager.toggle("renamefile"); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /renamefile/src/renamefile/Utils.java: -------------------------------------------------------------------------------- 1 | package renamefile; 2 | 3 | 4 | import java.awt.*; 5 | import java.io.*; 6 | import java.lang.reflect.Method; 7 | import java.util.*; 8 | import java.util.List; 9 | 10 | import javax.swing.*; 11 | 12 | import net.sf.jabref.*; 13 | import net.sf.jabref.external.ExternalFileType; 14 | import net.sf.jabref.gui.FileListEntry; 15 | import net.sf.jabref.gui.FileListTableModel; 16 | import net.sf.jabref.labelPattern.LabelPatternUtil; 17 | 18 | public class Utils { 19 | private static JabRefFrame frame; 20 | private static Method setDataBase = null; 21 | 22 | public static void init(JabRefFrame f){ 23 | frame=f; 24 | Class c; 25 | try { 26 | c = Class.forName("net.sf.jabref.labelPattern.LabelPatternUtil"); 27 | Method[] methods = c.getMethods(); 28 | for (Method m : methods) 29 | if (m.getName().equals("setDataBase")) 30 | setDataBase = m; 31 | } 32 | catch (Exception e) {} 33 | } 34 | 35 | private static BasePanel panel(){ 36 | return frame.basePanel(); 37 | } 38 | public static void addFileEntry(BibtexEntry b, String fn) { 39 | if (!hasFile(b,fn)) { 40 | FileListTableModel m = new FileListTableModel(); 41 | m.setContent(b.getField("file")); 42 | ExternalFileType type = getExternalFileTypeForName(fn); 43 | //2.6 ExternalFileType type = Globals.prefs.getExternalFileTypeByName(getExt(fn)); 44 | FileListEntry e = new FileListEntry("",fn,type); 45 | m.addEntry(m.getRowCount(),e); 46 | b.setField("file",m.getStringRepresentation()); 47 | } 48 | } 49 | 50 | private static ExternalFileType getExternalFileTypeForName(String filename) { 51 | // Code from Global.prefs.getExternalFileTypeForName() in JabRef 2.7+ 52 | ExternalFileType[] types=Globals.prefs.getExternalFileTypeSelection(); 53 | int longestFound = -1; 54 | ExternalFileType foundType = null; 55 | for (ExternalFileType type:types){ 56 | if ((type.getExtension() != null) && filename.toLowerCase(). 57 | endsWith(type.getExtension().toLowerCase())) { 58 | if (type.getExtension().length() > longestFound) { 59 | longestFound = type.getExtension().length(); 60 | foundType = type; 61 | } 62 | } 63 | } 64 | return foundType; 65 | } 66 | 67 | public static boolean hasFile(BibtexEntry b, String fn) { 68 | FileListTableModel m = new FileListTableModel(); 69 | m.setContent(b.getField("file")); 70 | for (int j=0;j=0;j--) { 82 | FileListEntry f = m.getEntry(j); 83 | if (f.getLink().equals(fn)) 84 | m.removeEntry(j); 85 | } 86 | b.setField("file",m.getStringRepresentation()); 87 | } 88 | 89 | // code from Metadata.getFileDirectory 90 | public static String getFileDir() { 91 | if(panel()==null || panel().metaData()==null) 92 | return null; 93 | MetaData md=panel().metaData(); 94 | File file = md.getFile(); //bib file 95 | // Check if the bib file location is set and primary: 96 | if (Globals.prefs.getBoolean("bibLocationAsFileDir") 97 | && Globals.prefs.getBoolean("bibLocAsPrimaryDir") 98 | && file != null) { 99 | return file.getParent(); 100 | } 101 | String dir; 102 | String key = Globals.prefs.get("userFileDirIndividual"); 103 | Vector vec = md.getData(key); 104 | if (vec == null) { 105 | key = Globals.prefs.get("userFileDir"); 106 | vec = md.getData(key); 107 | } 108 | if (vec == null) 109 | vec = md.getData("fileDirectory"); //2.6? 110 | if ((vec != null) && (vec.size() > 0)) 111 | dir = vec.get(0); 112 | else 113 | //This is a global file directory 114 | //In the original code it is called by get(field+"Directory") 115 | dir = Globals.prefs.get("fileDirectory"); 116 | if (dir==null) 117 | dir=""; 118 | // If this directory is relative, we try to interpret it as relative to 119 | // the file path of this bib file: 120 | if (!(new File(dir)).isAbsolute() && (file != null)) { 121 | String relDir; 122 | if (dir.equals(".")) { 123 | relDir = file.getParent(); 124 | } else { 125 | relDir = new StringBuffer(file.getParent()). 126 | append(System.getProperty("file.separator")). 127 | append(dir).toString(); 128 | } 129 | // If this directory actually exists, it is very likely that the 130 | // user wants us to use it: 131 | if ((new File(relDir)).exists()) 132 | dir = relDir; 133 | } 134 | return dir; 135 | } 136 | 137 | 138 | public static String getNewFileName(String ofn,BibtexEntry b){ 139 | boolean sameDir=Globals.prefs.getBoolean("SameFolder"); 140 | boolean sameName=Globals.prefs.getBoolean("SameName"); 141 | String dir=Globals.prefs.get("MoveFolder"); 142 | String pattern=Globals.prefs.get("RenamePattern"); 143 | return getNewFileName(ofn, b, sameDir, sameName, dir, pattern); 144 | } 145 | 146 | public static String getNewFileName(String ofn,BibtexEntry b,boolean sameDir,boolean sameName, 147 | String dir,String pattern){ 148 | final String s = System.getProperty("file.separator"); 149 | String fn; 150 | if(sameName) { 151 | if(sameDir) 152 | return ofn; 153 | else 154 | fn=ofn.substring(ofn.lastIndexOf(s)+1,ofn.length()); 155 | } else 156 | fn=makeLabel(pattern,b)+"."+getExt(ofn); 157 | if(sameDir) 158 | return fixSlash(ofn.substring(0,ofn.lastIndexOf(s)+1)+fn); 159 | if(dir.isEmpty()) 160 | return fixSlash(fn); 161 | if (dir.endsWith(s)) 162 | return fixSlash(dir + fn); 163 | else 164 | return fixSlash(dir+s+fn); 165 | } 166 | 167 | private static String fixSlash(String s){ 168 | if (Globals.ON_WIN) 169 | s = s.replaceAll("/", "\\\\"); 170 | else 171 | s = s.replaceAll("\\\\", "/"); 172 | return s; 173 | } 174 | 175 | private static String getExt(String f){ 176 | return f.substring(f.lastIndexOf('.')+1); 177 | } 178 | 179 | public static boolean haveSameExtensions(String f1,String f2){ 180 | return getExt(f1).equalsIgnoreCase(getExt(f2)); 181 | } 182 | 183 | public static String makeLabel(String pattern, BibtexEntry _entry) { 184 | // Needed only in 2.10+ as LabelPatternUtil.makeLabel uses the DataBase (private var _db) starting from 2.10: 185 | // The public method setDataBase() is defined only starting from 2.10 186 | // We look for setDataBase during the initialization 187 | try { 188 | if (setDataBase!=null) 189 | setDataBase.invoke(null, new Object[] {panel().database()}); 190 | } 191 | catch (Exception e) {} 192 | 193 | final String[] subst = { 194 | "\\\\([oilL])[\\s\\}]+", "\\\\a(a)[\\s\\}]+", "\\\\A(A)[\\s\\}]+", "\\\\(ss)[\\s\\}]+", //symbols 195 | "\\\\[a-zA-Z]+[\\s\\{\\}\\\\]+()", //latex commands 196 | "\\\\[^\\w][\\s\\{]*([a-zA-z])" //accents 197 | }; 198 | final String[] bad_chars = {"\\\\","/","<",">","\\?","\\{","\\}","\\$","\"","\n",":"}; 199 | StringBuffer sb = new StringBuffer(); 200 | String label; 201 | boolean field = false; 202 | ArrayList lst=LabelPatternUtil.split(pattern); 203 | for (int i=1; i 0){ 266 | out.write(buf, 0, len); 267 | } 268 | in.close(); 269 | out.close(); 270 | } catch (FileNotFoundException e) { 271 | e.printStackTrace(); 272 | return false; 273 | } catch (IOException e) { 274 | e.printStackTrace(); 275 | return false; 276 | } 277 | return true; 278 | } 279 | 280 | public static void displayAbout(JFrame parent) { 281 | InputStream stream = Utils.class.getResourceAsStream("/about.txt"); 282 | String text=streamToString(stream); 283 | JTextArea ta = new JTextArea(text); 284 | ta.setEditable(false); 285 | ta.setBackground(Color.white); 286 | JScrollPane sp = new JScrollPane(ta); 287 | sp.setPreferredSize(new Dimension(620,500)); 288 | JOptionPane.showMessageDialog(parent,sp, 289 | "About Renamefile plugin",JOptionPane.PLAIN_MESSAGE); 290 | } 291 | 292 | public static String streamToString(InputStream is) { 293 | final int len=0x10000; 294 | final char[] buffer = new char[len]; 295 | StringBuilder out = new StringBuilder(); 296 | try{ 297 | Reader in = new InputStreamReader(is,"UTF-8"); 298 | int read; 299 | while((read=in.read(buffer,0,len))!=-1) 300 | out.append(buffer,0,read); 301 | in.close(); 302 | } catch (IOException e) { 303 | e.printStackTrace(); 304 | } 305 | return out.toString(); 306 | } 307 | 308 | } 309 | --------------------------------------------------------------------------------