Coverage Report - net.sf.jabref.journals.ManageJournalsPanel
 
Classes in this File Line Coverage Branch Coverage Complexity
ManageJournalsPanel
88%
155/176
70%
31/44
2.474
ManageJournalsPanel$1
100%
10/10
62%
5/8
2.474
ManageJournalsPanel$2
8%
1/12
0%
0/8
2.474
ManageJournalsPanel$3
100%
5/5
100%
2/2
2.474
ManageJournalsPanel$4
100%
3/3
N/A
2.474
ManageJournalsPanel$5
25%
1/4
N/A
2.474
ManageJournalsPanel$AbbreviationsTableModel
70%
26/37
56%
9/16
2.474
ManageJournalsPanel$AbbreviationsTableModel$1
8%
1/12
0%
0/4
2.474
ManageJournalsPanel$BrowseAction
38%
5/13
0%
0/4
2.474
ManageJournalsPanel$DownloadAction
45%
10/22
50%
2/4
2.474
ManageJournalsPanel$ExternalFileEntry
85%
24/28
N/A
2.474
ManageJournalsPanel$ExternalFileEntry$1
55%
5/9
N/A
2.474
ManageJournalsPanel$ExternalFileEntry$2
100%
4/4
N/A
2.474
ManageJournalsPanel$JournalEntry
100%
6/6
N/A
2.474
 
 1  
 package net.sf.jabref.journals;
 2  
 
 3  
 import java.awt.BorderLayout;
 4  
 import java.awt.Dimension;
 5  
 import java.awt.event.*;
 6  
 import java.io.File;
 7  
 import java.io.FileNotFoundException;
 8  
 import java.io.FileWriter;
 9  
 import java.io.IOException;
 10  
 import java.net.MalformedURLException;
 11  
 import java.net.URL;
 12  
 import java.util.*;
 13  
 
 14  
 import javax.swing.*;
 15  
 import javax.swing.table.AbstractTableModel;
 16  
 
 17  
 import net.sf.jabref.GUIGlobals;
 18  
 import net.sf.jabref.Globals;
 19  
 import net.sf.jabref.HelpAction;
 20  
 import net.sf.jabref.JabRefFrame;
 21  
 import net.sf.jabref.gui.FileDialogs;
 22  
 import net.sf.jabref.net.URLDownload;
 23  
 
 24  
 import com.jgoodies.forms.builder.ButtonBarBuilder;
 25  
 import com.jgoodies.forms.builder.ButtonStackBuilder;
 26  
 import com.jgoodies.forms.builder.DefaultFormBuilder;
 27  
 import com.jgoodies.forms.layout.CellConstraints;
 28  
 import com.jgoodies.forms.layout.FormLayout;
 29  
 
 30  
 /**
 31  
  * Created by IntelliJ IDEA.
 32  
  * User: alver
 33  
  * Date: Sep 19, 2005
 34  
  * Time: 7:57:29 PM
 35  
  * To browseOld this template use File | Settings | File Templates.
 36  
  */
 37  138254263
 public class ManageJournalsPanel extends JPanel{
 38  
 
 39  
     JabRefFrame frame;
 40  1737983719
     JTextField personalFile = new JTextField();
 41  1737983719
     AbbreviationsTableModel tableModel = new AbbreviationsTableModel();
 42  
     JTable userTable; // builtInTable
 43  1737983719
     JPanel userPanel = new JPanel(),
 44  
         journalEditPanel,
 45  
         externalFilesPanel = new JPanel(),
 46  
         addExtPan = new JPanel();
 47  1737983719
     JTextField nameTf = new JTextField(),
 48  
         newNameTf = new JTextField(),
 49  
         abbrTf = new JTextField();
 50  1737983719
     List<ExternalFileEntry> externals = new ArrayList<ExternalFileEntry>(); // To hold references to external journal lists.
 51  
     JDialog dialog;
 52  1737983719
     JRadioButton newFile = new JRadioButton(Globals.lang("New file")),
 53  
         oldFile = new JRadioButton(Globals.lang("Existing file"));
 54  
 
 55  1737983719
     JButton add = new JButton(GUIGlobals.getImage("add")),
 56  
         remove = new JButton(GUIGlobals.getImage("remove")),
 57  
         ok = new JButton(Globals.lang("Ok")),
 58  
         cancel = new JButton(Globals.lang("Cancel")),
 59  
         help = new JButton(Globals.lang("Help")),
 60  
         browseOld = new JButton(Globals.lang("Browse")),
 61  
         browseNew = new JButton(Globals.lang("Browse")),
 62  
         addExt = new JButton(GUIGlobals.getImage("add"));
 63  
 
 64  
 
 65  1737983719
     public ManageJournalsPanel(final JabRefFrame frame) {
 66  1737983719
         this.frame = frame;
 67  
 
 68  1737983719
         personalFile.setEditable(false);
 69  
 
 70  1737983719
         ButtonGroup group = new ButtonGroup();
 71  1737983719
         group.add(newFile);
 72  1737983719
         group.add(oldFile);
 73  1737983719
         addExtPan.setLayout(new BorderLayout());
 74  1737983719
         addExtPan.add(addExt, BorderLayout.EAST);
 75  1737983719
         addExtPan.setToolTipText(Globals.lang("Add"));
 76  
         //addExtPan.setBorder(BorderFactory.createMatteBorder(1,1,1,1,Color.red));
 77  1737983719
         FormLayout layout = new FormLayout
 78  
                 ("1dlu, 8dlu, left:pref, 4dlu, fill:200dlu:grow, 4dlu, fill:pref", // 4dlu, left:pref, 4dlu",
 79  
                         "pref, 20dlu, 20dlu, fill:200dlu, 4dlu, pref");//150dlu");
 80  1737983719
         DefaultFormBuilder builder = new DefaultFormBuilder(layout);
 81  
 
 82  1737983719
         CellConstraints cc = new CellConstraints();
 83  
 
 84  
         /*JLabel description = new JLabel("<HTML>"+Globals.lang("JabRef can switch journal names between "
 85  
             +"abbreviated and full form. Since it knows only a limited number of journal names, "
 86  
             +"you may need to add your own definitions.")+"</HTML>");*/
 87  1737983719
         builder.addSeparator(Globals.lang("Personal journal list"), cc.xyw(2,1,6));
 88  
 
 89  
         //builder.add(description, cc.xyw(2,1,6));
 90  1737982234
         builder.add(newFile, cc.xy(3,2));
 91  1737982234
         builder.add(newNameTf, cc.xy(5,2));
 92  1737982234
         builder.add(browseNew, cc.xy(7,2));
 93  1737982234
         builder.add(oldFile, cc.xy(3,3));
 94  1737982234
         builder.add(personalFile, cc.xy(5,3));
 95  
         //BrowseAction action = new BrowseAction(personalFile, false);
 96  
         //JButton browse = new JButton(Globals.lang("Browse"));
 97  
         //browse.addActionListener(action);
 98  1737982234
         builder.add(browseOld, cc.xy(7,3));
 99  
 
 100  1737982234
         userPanel.setLayout(new BorderLayout());
 101  
         //builtInTable = new JTable(Globals.journalAbbrev.getTableModel());
 102  1737982234
         builder.add(userPanel, cc.xyw(2,4,4));
 103  1737982234
         ButtonStackBuilder butBul = new ButtonStackBuilder();
 104  1737982234
         butBul.addGridded(add);
 105  1737982234
         butBul.addGridded(remove);
 106  
 
 107  1737982234
         butBul.addGlue();
 108  1737982234
         builder.add(butBul.getPanel(), cc.xy(7,4));
 109  
 
 110  1737982234
         builder.addSeparator(Globals.lang("External files"), cc.xyw(2,6,6));
 111  1737982234
         externalFilesPanel.setLayout(new BorderLayout());
 112  
         //builder.add(/*new JScrollPane(*/externalFilesPanel/*)*/, cc.xyw(2,8,6));
 113  
 
 114  1737982234
         setLayout(new BorderLayout());
 115  1737982234
         builder.getPanel().setBorder(BorderFactory.createEmptyBorder(5,5,5,5));//createMatteBorder(1,1,1,1,Color.green));
 116  1737982234
         add(builder.getPanel(), BorderLayout.NORTH);
 117  1737982234
         add(externalFilesPanel, BorderLayout.CENTER);
 118  1737982234
         ButtonBarBuilder bb = new ButtonBarBuilder();
 119  1737982234
         bb.addGlue();
 120  1737982234
         bb.addGridded(ok);
 121  1737982234
         bb.addGridded(cancel);
 122  1737982234
         bb.addUnrelatedGap();
 123  1737982234
         bb.addGridded(help);
 124  1737982234
         bb.addGlue();
 125  1737982234
         bb.getPanel().setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
 126  1737982234
         dialog = new JDialog(frame, Globals.lang("Journal abbreviations"), false);
 127  1737982234
         dialog.getContentPane().add(this, BorderLayout.CENTER);
 128  1737982234
         dialog.getContentPane().add(bb.getPanel(), BorderLayout.SOUTH);
 129  
 
 130  
         //add(new JScrollPane(builtInTable), BorderLayout.CENTER);
 131  
 
 132  
         // Set up panel for editing a single journal, to be used in a dialog box:
 133  1737982234
         FormLayout layout2 = new FormLayout
 134  
                 ("right:pref, 4dlu, fill:180dlu", "");
 135  1737982234
         DefaultFormBuilder builder2 = new DefaultFormBuilder(layout2);
 136  1737982234
         builder2.append(Globals.lang("Journal name"));
 137  1737982234
         builder2.append(nameTf);
 138  1737982234
         builder2.nextLine();
 139  1737982234
         builder2.append(Globals.lang("ISO abbreviation"));
 140  1737982234
         builder2.append(abbrTf);
 141  1737982234
         journalEditPanel = builder2.getPanel();
 142  
 
 143  1737982234
         browseNew.addActionListener(new ActionListener() {
 144  
             public void actionPerformed(ActionEvent e) {
 145  365422852
                 File old = null;
 146  365422852
                 if (!newNameTf.getText().equals(""))
 147  1452683
                     old = new File(newNameTf.getText());
 148  365422852
                 String name = FileDialogs.getNewFile(frame, old, null, JFileChooser.SAVE_DIALOG, false);
 149  29170824
                 if (name != null) {
 150  139755
                     if ((old != null) && (tableModel.getRowCount() > 0)) {
 151  
                     }
 152  139755
                     newNameTf.setText(name);
 153  139755
                     newFile.setSelected(true);
 154  
                 }
 155  29170824
             }
 156  
         });
 157  1737982234
         browseOld.addActionListener(new ActionListener() {
 158  
             public void actionPerformed(ActionEvent e) {
 159  0
                 File old = null;
 160  0
                 if (!personalFile.getText().equals(""))
 161  0
                     old = new File(personalFile.getText());
 162  0
                 String name = FileDialogs.getNewFile(frame, old, null, JFileChooser.OPEN_DIALOG, false);
 163  0
                 if (name != null) {
 164  0
                     if ((old != null) && (tableModel.getRowCount() > 0)) {
 165  
                     }
 166  0
                     personalFile.setText(name);
 167  0
                     oldFile.setSelected(true);
 168  0
                     oldFile.setEnabled(true);
 169  0
                     setupUserTable();
 170  
                 }
 171  0
             }
 172  
         });
 173  
 
 174  
 
 175  1737982234
         ok.addActionListener(new ActionListener() {
 176  
             public void actionPerformed(ActionEvent e) {
 177  481140815
                 if (readyToClose()) {
 178  480976762
                     storeSettings();
 179  480976762
                     dialog.dispose();
 180  
                 }
 181  481140815
             }
 182  
         });
 183  1737982234
         help.addActionListener(new HelpAction(Globals.helpDiag, GUIGlobals.journalAbbrHelp));
 184  
 
 185  1737982234
         AbstractAction cancelAction = new AbstractAction() {
 186  
             public void actionPerformed(ActionEvent e) {
 187  67701377
                 dialog.dispose();
 188  67701377
             }
 189  
         };
 190  1737982234
         cancel.addActionListener(cancelAction);
 191  
 
 192  1737982234
         add.addActionListener(tableModel);
 193  1737982234
         remove.addActionListener(tableModel);
 194  1737982234
         addExt.addActionListener(new ActionListener() {
 195  
             public void actionPerformed(ActionEvent e) {
 196  0
                 externals.add(new ExternalFileEntry());
 197  0
                 buildExternalsPanel();
 198  0
             }
 199  
         });
 200  
 
 201  
         // Key bindings:
 202  1737982234
         ActionMap am = getActionMap();
 203  1737982234
         InputMap im = getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
 204  1737982234
         im.put(Globals.prefs.getKey("Close dialog"), "close");
 205  1737982234
         am.put("close", cancelAction);
 206  
 
 207  
         //dialog.pack();
 208  1737982234
         int xSize = getPreferredSize().width;
 209  1737982234
         dialog.setSize(xSize+10,700);
 210  1737982234
     }
 211  
 
 212  
     public JDialog getDialog() {
 213  3475964468
         return dialog;
 214  
     }
 215  
 
 216  
     public void setValues() {
 217  1737982234
         personalFile.setText(Globals.prefs.get("personalJournalList"));
 218  1737982234
         if (personalFile.getText().length() == 0) {
 219  1730359234
             newFile.setSelected(true);
 220  1730359234
             oldFile.setEnabled(false);
 221  
         } else {
 222  7623000
             oldFile.setSelected(true);
 223  7623000
             oldFile.setEnabled(true);
 224  
         }
 225  1737982234
         setupUserTable();
 226  1737982234
         setupExternals();
 227  1737982234
         buildExternalsPanel();
 228  
 
 229  1737982234
     }
 230  
 
 231  
     private void buildExternalsPanel() {
 232  
 
 233  1876236497
         DefaultFormBuilder builder = new DefaultFormBuilder(new FormLayout("fill:pref:grow",""));
 234  1876236497
         for (Iterator<ExternalFileEntry> i=externals.iterator(); i.hasNext();) {
 235  1737982234
             ExternalFileEntry efe = i.next();
 236  1737982234
             builder.append(efe.getPanel());
 237  1737982234
             builder.nextLine();
 238  1737982234
         }
 239  1876236497
         builder.append(Box.createVerticalGlue());
 240  1876236497
         builder.nextLine();
 241  1876236497
         builder.append(addExtPan);
 242  1876236497
         builder.nextLine();
 243  1876236497
         builder.append(Box.createVerticalGlue());
 244  
 
 245  
         //builder.getPanel().setBorder(BorderFactory.createMatteBorder(1,1,1,1,Color.green));
 246  
         //externalFilesPanel.setBorder(BorderFactory.createMatteBorder(1,1,1,1,Color.red));
 247  1876236497
         JScrollPane pane = new JScrollPane(builder.getPanel());
 248  1876236497
         pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
 249  1876236497
         externalFilesPanel.setMinimumSize(new Dimension(400,400));
 250  1876236497
         externalFilesPanel.setPreferredSize(new Dimension(400,400));
 251  1876236497
         externalFilesPanel.removeAll();
 252  1876236497
         externalFilesPanel.add(pane, BorderLayout.CENTER);
 253  1876236497
         externalFilesPanel.revalidate();
 254  1876236497
         externalFilesPanel.repaint();
 255  
 
 256  1876236497
     }
 257  
 
 258  
     private void setupExternals() {
 259  1737982234
         String[] externalFiles = Globals.prefs.getStringArray("externalJournalLists");
 260  1737982234
         if ((externalFiles == null) || (externalFiles.length == 0)) {
 261  1737982234
             ExternalFileEntry efe = new ExternalFileEntry();
 262  1737982234
             externals.add(efe);
 263  1737982234
         } else {
 264  0
             for (int i=0; i<externalFiles.length; i++) {
 265  0
                 ExternalFileEntry efe = new ExternalFileEntry(externalFiles[i]);
 266  0
                 externals.add(efe);
 267  
 
 268  
             }
 269  
 
 270  
         }
 271  
 
 272  
         //efe = new ExternalFileEntry();
 273  
         //externals.add(efe);
 274  
 
 275  1737982234
     }
 276  
 
 277  
     public void setupUserTable() {
 278  1737982234
         JournalAbbreviations userAbbr = new JournalAbbreviations();
 279  1737982234
         String filename = personalFile.getText();
 280  1737982234
         if (!filename.equals("") && (new File(filename)).exists()) {
 281  
             try {
 282  0
                 userAbbr.readJournalList(new File(filename));
 283  0
             } catch (FileNotFoundException e) {
 284  0
                 e.printStackTrace();
 285  0
             }
 286  
         }
 287  
 
 288  1737982234
         tableModel.setJournals(userAbbr.getJournals());
 289  1737982234
         userTable = new JTable(tableModel);
 290  1737982234
         userTable.addMouseListener(tableModel.getMouseListener());
 291  1737982234
         userPanel.add(new JScrollPane(userTable), BorderLayout.CENTER);
 292  1737982234
     }
 293  
 
 294  
     public boolean readyToClose() {
 295  
         File f;
 296  481140815
         if (newFile.isSelected()) {
 297  481140815
             if (newNameTf.getText().length() > 0) {
 298  25589851
                 f = new File(newNameTf.getText());
 299  25589851
                 return (!f.exists() ||
 300  
                     (JOptionPane.showConfirmDialog
 301  
                      (this, "'"+f.getName()+"' "+Globals.lang("exists. Overwrite file?"),
 302  
                       Globals.lang("Store journal abbreviations"), JOptionPane.OK_CANCEL_OPTION)
 303  
                      == JOptionPane.OK_OPTION));
 304  
             } else {
 305  455550964
                 if (tableModel.getRowCount() > 0) {
 306  164053
                     JOptionPane.showMessageDialog(this, Globals.lang("You must choose a file name to store journal abbreviations"),
 307  
                             Globals.lang("Store journal abbreviations"), JOptionPane.ERROR_MESSAGE);
 308  164053
                         return false;
 309  
                 }
 310  455386911
                 else return true;
 311  
 
 312  
             }
 313  
         }
 314  0
         return true;
 315  
     }
 316  
 
 317  
     public void storeSettings() {
 318  480976762
         File f = null;
 319  480976762
         if (newFile.isSelected()) {
 320  480976762
             if (newNameTf.getText().length() > 0) {
 321  25589851
                 f = new File(newNameTf.getText());
 322  
             }// else {
 323  
             //    return; // Nothing to do.
 324  
             //}
 325  
         } else
 326  0
             f = new File(personalFile.getText());
 327  
 
 328  480976762
         if (f != null) {
 329  25589851
             FileWriter fw = null;
 330  
             try {
 331  25589851
                 fw = new FileWriter(f, false);
 332  0
                 for (Iterator<JournalEntry> i=tableModel.getJournals().iterator(); i.hasNext();) {
 333  0
                     JournalEntry entry = i.next();
 334  0
                     fw.write(entry.name);
 335  0
                     fw.write(" = ");
 336  0
                     fw.write(entry.abbreviation);
 337  0
                     fw.write(Globals.NEWLINE);
 338  0
                 }
 339  
 
 340  25589851
             } catch (IOException e) {
 341  25589851
                 e.printStackTrace();
 342  
 
 343  
             } finally {
 344  25589851
                 if (fw != null)
 345  
                     try {
 346  0
                         fw.close();
 347  0
                     } catch (IOException e) {
 348  0
                         e.printStackTrace();
 349  0
                     }
 350  
             }
 351  
 
 352  25589851
             String filename = f.getPath();
 353  25589851
             if (filename.equals(""))
 354  0
                 filename = null;
 355  25589851
             Globals.prefs.put("personalJournalList", filename);
 356  
         }
 357  
 
 358  
         // Store the list of external files set up:
 359  480976762
         ArrayList<String> extFiles = new ArrayList<String>();
 360  480976762
         for (Iterator<ExternalFileEntry> i=externals.iterator(); i.hasNext();) {
 361  445996132
             ExternalFileEntry efe = i.next();
 362  445996132
             if (!efe.getValue().equals("")) {
 363  9573734
                 extFiles.add(efe.getValue());
 364  
             }
 365  445996132
         }
 366  480976762
         if (extFiles.size() == 0)
 367  471403028
             Globals.prefs.put("externalJournalLists", "");
 368  
         else {
 369  9573734
             String[] list = extFiles.toArray(new String[extFiles.size()]);
 370  9573734
             Globals.prefs.putStringArray("externalJournalLists", list);
 371  
         }
 372  
 
 373  
 
 374  480976762
         Globals.initializeJournalNames();
 375  
 
 376  
         // Update the autocompleter for the "journal" field in all base panels,
 377  
         // so added journal names are available:
 378  959780281
         for (int i=0; i<frame.baseCount(); i++) {
 379  478803519
             frame.baseAt(i).addJournalListToAutoCompleter();
 380  
         }
 381  
 
 382  480976762
     }
 383  
 
 384  
     class DownloadAction extends AbstractAction {
 385  
         JTextField comp;
 386  
 
 387  1737982234
         public DownloadAction(JTextField tc) {
 388  1737982234
             super(Globals.lang("Download"));
 389  1737982234
             comp = tc;
 390  1737982234
         }
 391  
 
 392  
         public void actionPerformed(ActionEvent e) {
 393  34336088
             String chosen = null;
 394  34336088
             chosen = JOptionPane.showInputDialog(Globals.lang("Choose the URL to download. The default value points to a list provided by the JabRef developers."),
 395  
                     "http://jabref.sf.net/journals/journal_abbreviations_general.txt");
 396  25604489
             if (chosen == null)
 397  363000
                 return;
 398  
             File toFile;
 399  
             try {
 400  25241489
                 URL url = new URL(chosen);
 401  25241489
                 String toName = FileDialogs.getNewFile(frame, new File(System.getProperty("user.home")),
 402  
                         null, JFileChooser.SAVE_DIALOG, false);
 403  0
                 if (toName == null)
 404  0
                     return;
 405  0
                 else toFile = new File(toName);
 406  0
                 URLDownload ud = new URLDownload(comp, url, toFile);
 407  0
                 ud.download();
 408  0
                 comp.setText(toFile.getPath());
 409  0
             } catch (MalformedURLException ex) {
 410  0
                 ex.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
 411  0
             } catch (IOException ex2) {
 412  0
                 ex2.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
 413  0
             }
 414  0
         }
 415  
     }
 416  
 
 417  
     class BrowseAction extends AbstractAction {
 418  
         JTextField comp;
 419  
         boolean dir;
 420  
 
 421  1737982234
         public BrowseAction(JTextField tc, boolean dir) {
 422  1737982234
             super(Globals.lang("Browse"));
 423  1737982234
             this.dir = dir;
 424  1737982234
             comp = tc;
 425  1737982234
         }
 426  
 
 427  
         public void actionPerformed(ActionEvent e) {
 428  0
             String chosen = null;
 429  0
             if (dir)
 430  0
                 chosen = FileDialogs.getNewDir(frame, new File(comp.getText()), Globals.NONE,
 431  
                         JFileChooser.OPEN_DIALOG, false);
 432  
             else
 433  0
                 chosen = FileDialogs.getNewFile(frame, new File(comp.getText()), Globals.NONE,
 434  
                         JFileChooser.OPEN_DIALOG, false);
 435  0
             if (chosen != null) {
 436  0
                 File newFile = new File(chosen);
 437  0
                 comp.setText(newFile.getPath());
 438  
             }
 439  0
         }
 440  
     }
 441  
 
 442  
     class AbbreviationsTableModel extends AbstractTableModel implements ActionListener {
 443  
 
 444  1737983719
         String[] names = new String[] {Globals.lang("Journal name"), Globals.lang("Abbreviation")};
 445  1737983719
         ArrayList<JournalEntry> journals = null;
 446  
 
 447  1737983719
         public AbbreviationsTableModel() {
 448  
 
 449  
 
 450  1737983719
         }
 451  
 
 452  
         public void setJournals(Map<String, String> journals) {
 453  1737982234
             this.journals = new ArrayList<JournalEntry>();
 454  1737982234
             for (Map.Entry<String, String> entry : journals.entrySet()){
 455  0
                 this.journals.add(new JournalEntry(entry.getKey(), entry.getValue()));
 456  
             }
 457  1737982234
             fireTableDataChanged();
 458  1737982234
         }
 459  
 
 460  
         public ArrayList<JournalEntry> getJournals() {
 461  0
             return journals;
 462  
         }
 463  
 
 464  
         public int getColumnCount() {
 465  5213946702
             return 2;
 466  
         }
 467  
 
 468  
         public int getRowCount() {
 469  21485142315
             return journals.size();
 470  
         }
 471  
 
 472  
         public Object getValueAt(int row, int col) {
 473  81891046
             if (col == 0)
 474  40945523
                 return journals.get(row).name;
 475  
             else
 476  40945523
                 return journals.get(row).abbreviation;
 477  
         }
 478  
 
 479  
         public void setValueAt(Object object, int row, int col) {
 480  0
             JournalEntry entry = journals.get(row);
 481  0
             if (col == 0)
 482  0
                 entry.name = (String)object;
 483  
             else
 484  0
                 entry.abbreviation = (String)object;
 485  
 
 486  0
         }
 487  
 
 488  
         public String getColumnName(int i) {
 489  3475964468
             return names[i];
 490  
         }
 491  
 
 492  
         public boolean isCellEditable(int i, int i1) {
 493  0
             return false;
 494  
         }
 495  
 
 496  
         public MouseListener getMouseListener() {
 497  1737982234
             return new MouseAdapter() {
 498  
                 public void mouseClicked(MouseEvent e) {
 499  0
                     if (e.getClickCount() == 2) {
 500  0
                         JTable table = (JTable)e.getSource();
 501  0
                         int row = table.rowAtPoint(e.getPoint());
 502  0
                         nameTf.setText((String)getValueAt(row,0));
 503  0
                         abbrTf.setText((String)getValueAt(row,1));
 504  0
                         if (JOptionPane.showConfirmDialog(dialog, journalEditPanel, Globals.lang("Edit journal"),
 505  
                             JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) {
 506  0
                             setValueAt(nameTf.getText(), row, 0);
 507  0
                             setValueAt(abbrTf.getText(), row, 1);
 508  0
                             Collections.sort(journals);
 509  0
                             fireTableDataChanged();
 510  
                         }
 511  
 
 512  
                     }
 513  0
                 }
 514  
             };
 515  
         }
 516  
 
 517  
         public void actionPerformed(ActionEvent e) {
 518  175642060
             if (e.getSource() == add) {
 519  
                 //int sel = userTable.getSelectedRow();
 520  
                 //if (sel < 0)
 521  
                 //    sel = 0;
 522  
 
 523  77583355
                 nameTf.setText("");
 524  77583355
                 abbrTf.setText("");
 525  77583355
                 if (JOptionPane.showConfirmDialog(dialog, journalEditPanel, Globals.lang("Edit journal"),
 526  
                         JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) {
 527  40789395
                     journals.add(new JournalEntry(nameTf.getText(), abbrTf.getText()));
 528  
                     //setValueAt(nameTf.getText(), sel, 0);
 529  
                     //setValueAt(abbrTf.getText(), sel, 1);
 530  40789395
                     Collections.sort(journals);
 531  40789395
                     fireTableDataChanged();
 532  
                 }
 533  
             }
 534  98058705
             else if (e.getSource() == remove) {
 535  98058705
                 int[] rows = userTable.getSelectedRows();
 536  98058705
                 if (rows.length > 0) {
 537  0
                     for (int i=rows.length-1; i>=0; i--) {
 538  0
                         journals.remove(rows[i]);
 539  
                     }
 540  0
                     fireTableDataChanged();
 541  
                 }
 542  
             }
 543  146238126
         }
 544  
     }
 545  
 
 546  111659386
     class ExternalFileEntry {
 547  
         private JPanel pan;
 548  
         private JTextField tf;
 549  1737982234
         private JButton browse = new JButton(Globals.lang("Browse")),
 550  
             view = new JButton(Globals.lang("Preview")),
 551  
             clear = new JButton(GUIGlobals.getImage("delete")),
 552  
             download = new JButton(Globals.lang("Download"));
 553  1737982234
         public ExternalFileEntry() {
 554  1737982234
             tf = new JTextField();
 555  1737982234
             setupPanel();
 556  1737982234
         }
 557  0
         public ExternalFileEntry(String filename) {
 558  0
             tf = new JTextField(filename);
 559  0
             setupPanel();
 560  0
         }
 561  
         private void setupPanel() {
 562  1737982234
             tf.setEditable(false);
 563  1737982234
             BrowseAction browseA = new BrowseAction(tf, false);
 564  1737982234
             browse.addActionListener(browseA);
 565  1737982234
             DownloadAction da = new DownloadAction(tf);
 566  1737982234
             download.addActionListener(da);
 567  1737982234
             DefaultFormBuilder builder = new DefaultFormBuilder
 568  
                     (new FormLayout("fill:pref:grow, 4dlu, fill:pref, 4dlu, fill:pref, 4dlu, fill:pref, 4dlu, fill:pref", ""));
 569  1737982234
             builder.append(tf);
 570  1737982234
             builder.append(browse);
 571  1737982234
             builder.append(download);
 572  1737982234
             builder.append(view);
 573  1737982234
             builder.append(clear);
 574  
 
 575  1737982234
             pan = builder.getPanel();
 576  
 
 577  1737982234
             view.addActionListener(new ActionListener() {
 578  
                 public void actionPerformed(ActionEvent e) {
 579  
                     try {
 580  55829693
                         JournalAbbreviations abbr = new JournalAbbreviations(new File(tf.getText()));
 581  0
                         JTable table = new JTable(abbr.getTableModel());
 582  0
                         JScrollPane pane = new JScrollPane(table);
 583  0
                         JOptionPane.showMessageDialog(null, pane, Globals.lang("Journal list preview"), JOptionPane.INFORMATION_MESSAGE);
 584  55829693
                     } catch (FileNotFoundException ex) {
 585  55829693
                         JOptionPane.showMessageDialog(null, Globals.lang("File '%0' not found", tf.getText()),
 586  
                                 Globals.lang("Error"), JOptionPane.ERROR_MESSAGE);
 587  0
                     }
 588  47479965
                 }
 589  
             });
 590  1737982234
             clear.addActionListener(new ActionListener() {
 591  
                 public void actionPerformed(ActionEvent e) {
 592  138254263
                     externals.remove(ExternalFileEntry.this);
 593  138254263
                     buildExternalsPanel();
 594  138254263
                 }
 595  
             });
 596  1737982234
             clear.setToolTipText(Globals.lang("Remove"));
 597  
 
 598  1737982234
         }
 599  1737982234
         public JPanel getPanel() { return pan; }
 600  455569866
         public String getValue() { return tf.getText(); }
 601  
     }
 602  
 
 603  156128
     class JournalEntry implements Comparable<JournalEntry> {
 604  
         String name, abbreviation;
 605  40789395
         public JournalEntry(String name, String abbreviation) {
 606  40789395
             this.name = name;
 607  40789395
             this.abbreviation = abbreviation;
 608  40789395
         }
 609  
         public int compareTo(JournalEntry other) {
 610  156128
             return this.name.compareTo(other.name);
 611  
         }
 612  
     }
 613  
 }
 614  
 
 615