/**
   * This method presents a dialog box explaining and offering to make the changes. If the user
   * confirms, the changes are performed.
   *
   * @param panel
   * @param parserResult
   */
  @Override
  public void performAction(BasePanel panel, ParserResult parserResult) {

    if (!isThereSomethingToBeDone()) {
      return; // Nothing to do, just return.
    }

    JCheckBox changeSettings =
        new JCheckBox(
            Localization.lang(
                "Change table column and General fields settings to use the new feature"),
            offerChangeSettings);
    JCheckBox changeDatabase =
        new JCheckBox(
            Localization.lang("Upgrade old external file links to use the new feature"),
            offerChangeDatabase);
    JCheckBox setFileDir =
        new JCheckBox(Localization.lang("Set main external file directory") + ":", offerSetFileDir);
    JTextField fileDir = new JTextField(30);
    JCheckBox doNotShowDialog =
        new JCheckBox(Localization.lang("Do not show these options in the future"), false);

    JPanel message = new JPanel();
    FormBuilder formBuilder = FormBuilder.create().layout(new FormLayout("left:pref", "p"));
    // Keep the formatting of these lines. Otherwise, strings have to be translated again.
    // See updated JabRef_en.properties modifications by python syncLang.py -s -u
    int row = 1;
    formBuilder
        .add(
            new JLabel(
                "<html>"
                    + Localization.lang("This database uses outdated file links.")
                    + "<br><br>"
                    + Localization.lang(
                        "JabRef no longer supports 'ps' or 'pdf' fields.<br>File links are now stored in the 'file' field and files are stored in an external file directory.<br>To make use of this feature, JabRef needs to upgrade file links.<br><br>")
                    + "<p>"
                    + Localization.lang("Do you want JabRef to do the following operations?")
                    + "</html>"))
        .xy(1, row);

    if (offerChangeSettings) {
      formBuilder.appendRows("2dlu, p");
      row += 2;
      formBuilder.add(changeSettings).xy(1, row);
    }
    if (offerChangeDatabase) {
      formBuilder.appendRows("2dlu, p");
      row += 2;
      formBuilder.add(changeDatabase).xy(1, row);
    }
    if (offerSetFileDir) {
      if (Globals.prefs.hasKey("pdfDirectory")) {
        fileDir.setText(Globals.prefs.get("pdfDirectory"));
      } else {
        fileDir.setText(Globals.prefs.get("psDirectory"));
      }
      JPanel builderPanel = new JPanel();
      builderPanel.add(setFileDir);
      builderPanel.add(fileDir);
      JButton browse = new JButton(Localization.lang("Browse"));
      browse.addActionListener(BrowseAction.buildForDir(fileDir));
      builderPanel.add(browse);
      formBuilder.appendRows("2dlu, p");
      row += 2;
      formBuilder.add(builderPanel).xy(1, row);
    }
    formBuilder.appendRows("6dlu, p");
    formBuilder.add(doNotShowDialog).xy(1, row + 2);

    message.add(formBuilder.build());

    int answer =
        JOptionPane.showConfirmDialog(
            panel.frame(), message, Localization.lang("Upgrade file"), JOptionPane.YES_NO_OPTION);
    if (doNotShowDialog.isSelected()) {
      Globals.prefs.putBoolean(JabRefPreferences.SHOW_FILE_LINKS_UPGRADE_WARNING, false);
    }

    if (answer == JOptionPane.YES_OPTION) {
      makeChanges(
          panel,
          parserResult,
          changeSettings.isSelected(),
          changeDatabase.isSelected(),
          setFileDir.isSelected() ? fileDir.getText() : null);
    }
  }
Пример #2
0
 private void initSettingsPanel() {
   settings = new JPanel();
   settings.add(new JLabel(Localization.lang("Path to LyX pipe") + ":"));
   settings.add(lyxPipe);
 }
Пример #3
0
  /**
   * This method presents a dialog box explaining and offering to make the changes. If the user
   * confirms, the changes are performed.
   *
   * @param panel
   * @param pr
   */
  @Override
  public void performAction(BasePanel panel, ParserResult pr) {
    // Find out which actions should be offered:
    // Only offer to change Preferences if file column is not already visible:
    boolean offerChangeSettings =
        !Globals.prefs.getBoolean(JabRefPreferences.FILE_COLUMN) || !showsFileInGenFields();
    // Only offer to upgrade links if the pdf/ps fields are used:
    boolean offerChangeDatabase =
        linksFound(pr.getDatabase(), FileLinksUpgradeWarning.FIELDS_TO_LOOK_FOR);
    // If the "file" directory is not set, offer to migrate pdf/ps dir:
    boolean offerSetFileDir =
        !Globals.prefs.hasKey(GUIGlobals.FILE_FIELD + "Directory")
            && (Globals.prefs.hasKey("pdfDirectory") || Globals.prefs.hasKey("psDirectory"));

    if (!offerChangeDatabase && !offerChangeSettings && !offerSetFileDir) {
      return; // Nothing to do, just return.
    }

    JCheckBox changeSettings =
        new JCheckBox(
            Globals.lang("Change table column and General fields settings to use the new feature"),
            offerChangeSettings);
    JCheckBox changeDatabase =
        new JCheckBox(
            Globals.lang("Upgrade old external file links to use the new feature"),
            offerChangeDatabase);
    JCheckBox setFileDir =
        new JCheckBox(Globals.lang("Set main external file directory") + ":", offerSetFileDir);
    JTextField fileDir = new JTextField(30);
    JCheckBox doNotShowDialog =
        new JCheckBox(Globals.lang("Do not show these options in the future"), false);

    JPanel message = new JPanel();
    DefaultFormBuilder b = new DefaultFormBuilder(new FormLayout("left:pref", ""), message);
    // Keep the formatting of these lines. Otherwise, strings have to be translated again.
    // See updated JabRef_en.properties modifications by python syncLang.py -s -u
    b.append(
        new JLabel(
            "<html>"
                + Globals.lang("This database was written using an older version of JabRef.")
                + "<br>"
                + Globals.lang(
                    "The current version features a new way of handling links to external files.<br>To take advantage of this, your links must be changed into the new format, and<br>JabRef must be configured to show the new links.")
                + "<p>"
                + Globals.lang("Do you want JabRef to do the following operations?")
                + "</html>"));
    b.nextLine();
    if (offerChangeSettings) {
      b.append(changeSettings);
      b.nextLine();
    }
    if (offerChangeDatabase) {
      b.append(changeDatabase);
      b.nextLine();
    }
    if (offerSetFileDir) {
      if (Globals.prefs.hasKey("pdfDirectory")) {
        fileDir.setText(Globals.prefs.get("pdfDirectory"));
      } else {
        fileDir.setText(Globals.prefs.get("psDirectory"));
      }
      JPanel pan = new JPanel();
      pan.add(setFileDir);
      pan.add(fileDir);
      JButton browse = new JButton(Globals.lang("Browse"));
      browse.addActionListener(BrowseAction.buildForDir(fileDir));
      pan.add(browse);
      b.append(pan);
      b.nextLine();
    }
    b.append("");
    b.nextLine();
    b.append(doNotShowDialog);

    int answer =
        JOptionPane.showConfirmDialog(
            panel.frame(), message, Globals.lang("Upgrade file"), JOptionPane.YES_NO_OPTION);
    if (doNotShowDialog.isSelected()) {
      Globals.prefs.putBoolean(JabRefPreferences.SHOW_FILE_LINKS_UPGRADE_WARNING, false);
    }

    if (answer == JOptionPane.YES_OPTION) {
      makeChanges(
          panel,
          pr,
          changeSettings.isSelected(),
          changeDatabase.isSelected(),
          setFileDir.isSelected() ? fileDir.getText() : null);
    }
  }
Пример #4
0
    public OptionsDialog(JFrame parent) {
      super(parent, Globals.lang("Writing XMP metadata for selected entries..."), false);
      okButton.setEnabled(false);

      okButton.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              dispose();
            }
          });

      AbstractAction cancel =
          new AbstractAction() {
            private static final long serialVersionUID = -338601477652815366L;

            public void actionPerformed(ActionEvent e) {
              canceled = true;
            }
          };
      cancelButton.addActionListener(cancel);

      InputMap im = cancelButton.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
      ActionMap am = cancelButton.getActionMap();
      im.put(Globals.prefs.getKey("Close dialog"), "close");
      am.put("close", cancel);

      progressArea = new JTextArea(15, 60);

      JScrollPane scrollPane =
          new JScrollPane(
              progressArea,
              JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
              JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
      Dimension d = progressArea.getPreferredSize();
      d.height += scrollPane.getHorizontalScrollBar().getHeight() + 15;
      d.width += scrollPane.getVerticalScrollBar().getWidth() + 15;

      panel.setSize(d);

      progressArea.setBackground(Color.WHITE);
      progressArea.setEditable(false);
      progressArea.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
      progressArea.setText("");

      JPanel panel = new JPanel();
      panel.setBorder(BorderFactory.createEmptyBorder(3, 2, 3, 2));
      panel.add(scrollPane);

      // progressArea.setPreferredSize(new Dimension(300, 300));

      ButtonBarBuilder bb = new ButtonBarBuilder();
      bb.addGlue();
      bb.addGridded(okButton);
      bb.addRelatedGap();
      bb.addGridded(cancelButton);
      bb.addGlue();
      JPanel bbPanel = bb.getPanel();
      bbPanel.setBorder(BorderFactory.createEmptyBorder(0, 3, 3, 3));
      getContentPane().add(panel, BorderLayout.CENTER);
      getContentPane().add(bbPanel, BorderLayout.SOUTH);

      pack();
      this.setResizable(false);
    }
  private void initGui() {
    Container pane = getContentPane();
    pane.setLayout(new BorderLayout());

    biblatexMode = Globals.prefs.getBoolean("biblatexMode");

    JPanel main = new JPanel(), buttons = new JPanel(), right = new JPanel();
    main.setLayout(new BorderLayout());
    right.setLayout(new GridLayout(biblatexMode ? 2 : 1, 2));

    java.util.List<String> entryTypes = new ArrayList<String>();
    for (String s : BibtexEntryType.ALL_TYPES.keySet()) {
      entryTypes.add(s);
    }

    typeComp = new EntryTypeList(entryTypes);
    typeComp.addListSelectionListener(this);
    typeComp.addAdditionActionListener(this);
    typeComp.addDefaultActionListener(new DefaultListener());
    typeComp.setListSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    // typeComp.setEnabled(false);
    reqComp =
        new FieldSetComponent(
            Globals.lang("Required fields"), new ArrayList<String>(), preset, true, true);
    reqComp.setEnabled(false);
    reqComp.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
    ListDataListener dataListener = new DataListener();
    reqComp.addListDataListener(dataListener);
    optComp =
        new FieldSetComponent(
            Globals.lang("Optional fields"), new ArrayList<String>(), preset, true, true);
    optComp.setEnabled(false);
    optComp.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
    optComp.addListDataListener(dataListener);
    right.add(reqComp);
    right.add(optComp);

    if (biblatexMode) {
      optComp2 =
          new FieldSetComponent(
              Globals.lang("Optional fields") + " 2", new ArrayList<String>(), preset, true, true);
      optComp2.setEnabled(false);
      optComp2.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
      optComp2.addListDataListener(dataListener);
      right.add(new JPanel());
      right.add(optComp2);
    }

    // right.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),
    // Globals.lang("Fields")));
    right.setBorder(BorderFactory.createEtchedBorder());
    ok = new JButton("Ok");
    cancel = new JButton(Globals.lang("Cancel"));
    apply = new JButton(Globals.lang("Apply"));
    ok.addActionListener(this);
    apply.addActionListener(this);
    cancel.addActionListener(this);
    ButtonBarBuilder bb = new ButtonBarBuilder(buttons);
    buttons.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
    bb.addGlue();
    bb.addButton(ok);
    bb.addButton(apply);
    bb.addButton(cancel);
    bb.addGlue();

    AbstractAction closeAction =
        new AbstractAction() {

          @Override
          public void actionPerformed(ActionEvent e) {
            dispose();
          }
        };
    ActionMap am = main.getActionMap();
    InputMap im = main.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    im.put(Globals.prefs.getKey("Close dialog"), "close");
    am.put("close", closeAction);

    // con.fill = GridBagConstraints.BOTH;
    // con.weightx = 0.3;
    // con.weighty = 1;
    // gbl.setConstraints(typeComp, con);
    main.add(typeComp, BorderLayout.WEST);
    main.add(right, BorderLayout.CENTER);
    main.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    pane.add(main, BorderLayout.CENTER);
    pane.add(buttons, BorderLayout.SOUTH);
    pack();
  }
Пример #6
0
  public PreviewPrefsTab(JabRefPreferences prefs) {
    this.prefs = prefs;

    JPanel firstPanel = new JPanel();
    GridBagLayout layout = new GridBagLayout();
    firstPanel.setLayout(layout);
    JPanel secondPanel = new JPanel();
    secondPanel.setLayout(layout);

    setLayout(layout);
    JLabel lab;
    lab = new JLabel(Globals.lang("Preview") + " 1");
    GridBagConstraints layoutConstraints = new GridBagConstraints();
    layoutConstraints.anchor = GridBagConstraints.WEST;
    layoutConstraints.gridwidth = GridBagConstraints.REMAINDER;
    layoutConstraints.fill = GridBagConstraints.BOTH;
    layoutConstraints.weightx = 1;
    layoutConstraints.weighty = 0;
    layoutConstraints.insets = new Insets(2, 2, 2, 2);
    layout.setConstraints(lab, layoutConstraints);
    layoutConstraints.weighty = 1;
    JScrollPane firstScrollPane = new JScrollPane(layout1);
    layout.setConstraints(firstScrollPane, layoutConstraints);
    firstPanel.add(firstScrollPane);
    layoutConstraints.weighty = 0;
    layoutConstraints.gridwidth = 1;
    layoutConstraints.weightx = 0;
    layoutConstraints.fill = GridBagConstraints.NONE;
    layoutConstraints.anchor = GridBagConstraints.WEST;
    JButton testButton = new JButton(Globals.lang("Test"));
    layout.setConstraints(testButton, layoutConstraints);
    firstPanel.add(testButton);
    JButton defaultButton = new JButton(Globals.lang("Default"));
    layout.setConstraints(defaultButton, layoutConstraints);
    firstPanel.add(defaultButton);
    layoutConstraints.gridwidth = GridBagConstraints.REMAINDER;
    JPanel pan = new JPanel();
    layoutConstraints.weightx = 1;
    layout.setConstraints(pan, layoutConstraints);
    firstPanel.add(pan);
    lab = new JLabel(Globals.lang("Preview") + " 2");
    layout.setConstraints(lab, layoutConstraints);
    // p2.add(lab);
    layoutConstraints.weighty = 1;
    layoutConstraints.fill = GridBagConstraints.BOTH;
    JScrollPane secondScrollPane = new JScrollPane(layout2);
    layout.setConstraints(secondScrollPane, layoutConstraints);
    secondPanel.add(secondScrollPane);
    layoutConstraints.weighty = 0;
    layoutConstraints.weightx = 0;
    layoutConstraints.fill = GridBagConstraints.NONE;
    layoutConstraints.gridwidth = 1;
    JButton testButton2 = new JButton(Globals.lang("Test"));
    layout.setConstraints(testButton2, layoutConstraints);
    secondPanel.add(testButton2);
    JButton defaultButton2 = new JButton(Globals.lang("Default"));
    layout.setConstraints(defaultButton2, layoutConstraints);
    secondPanel.add(defaultButton2);
    layoutConstraints.gridwidth = 1;
    pan = new JPanel();
    layoutConstraints.weightx = 1;
    layout.setConstraints(pan, layoutConstraints);
    secondPanel.add(pan);

    layoutConstraints.weightx = 1;
    layoutConstraints.weighty = 0;
    layoutConstraints.fill = GridBagConstraints.BOTH;
    layoutConstraints.gridwidth = GridBagConstraints.REMAINDER;
    lab = new JLabel(Globals.lang("Preview") + " 1");
    layout.setConstraints(lab, layoutConstraints);
    add(lab);
    layoutConstraints.weighty = 1;
    layout.setConstraints(firstPanel, layoutConstraints);
    add(firstPanel);
    lab = new JLabel(Globals.lang("Preview") + " 2");
    layoutConstraints.weighty = 0;
    JSeparator sep = new JSeparator(SwingConstants.HORIZONTAL);
    layout.setConstraints(sep, layoutConstraints);
    add(sep);
    layout.setConstraints(lab, layoutConstraints);
    add(lab);
    layoutConstraints.weighty = 1;
    layout.setConstraints(secondPanel, layoutConstraints);
    add(secondPanel);

    // PDF Preview button
    JPanel pdfPreviewPanel = new JPanel(new BorderLayout());
    pdfPreviewPanel.add(pdfPreview, BorderLayout.WEST);

    { // Help Button
      HelpAction helpAction =
          new HelpAction(
              Globals.helpDiag,
              GUIGlobals.previewHelp,
              Globals.lang("Help on Preview Settings"),
              GUIGlobals.getIconUrl("helpSmall"));
      JButton help = helpAction.getIconButton();
      pdfPreviewPanel.add(help, BorderLayout.EAST);
    }

    layoutConstraints.weighty = 0;
    layout.setConstraints(pdfPreviewPanel, layoutConstraints);
    add(pdfPreviewPanel);

    defaultButton.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            String tmp = layout1.getText().replaceAll("\n", "__NEWLINE__");
            PreviewPrefsTab.this.prefs.remove(JabRefPreferences.PREVIEW_0);
            layout1.setText(
                PreviewPrefsTab.this
                    .prefs
                    .get(JabRefPreferences.PREVIEW_0)
                    .replaceAll("__NEWLINE__", "\n"));
            PreviewPrefsTab.this.prefs.put(JabRefPreferences.PREVIEW_0, tmp);
          }
        });
    defaultButton2.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            String tmp = layout2.getText().replaceAll("\n", "__NEWLINE__");
            PreviewPrefsTab.this.prefs.remove(JabRefPreferences.PREVIEW_1);
            layout2.setText(
                PreviewPrefsTab.this
                    .prefs
                    .get(JabRefPreferences.PREVIEW_1)
                    .replaceAll("__NEWLINE__", "\n"));
            PreviewPrefsTab.this.prefs.put(JabRefPreferences.PREVIEW_1, tmp);
          }
        });

    testButton.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            PreviewPrefsTab.getTestEntry();
            try {
              PreviewPanel testPanel =
                  new PreviewPanel(
                      null, PreviewPrefsTab.entry, null, new MetaData(), layout1.getText());
              testPanel.setPreferredSize(new Dimension(800, 350));
              JOptionPane.showMessageDialog(
                  null, testPanel, Globals.lang("Preview"), JOptionPane.PLAIN_MESSAGE);
            } catch (StringIndexOutOfBoundsException ex) {
              ex.printStackTrace();
              JOptionPane.showMessageDialog(
                  null,
                  Globals.lang("Parsing error")
                      + ": "
                      + Globals.lang("illegal backslash expression")
                      + ".\n"
                      + ex.getMessage()
                      + '\n'
                      + Globals.lang("Look at stderr for details")
                      + '.',
                  Globals.lang("Parsing error"),
                  JOptionPane.ERROR_MESSAGE);
            }
          }
        });

    testButton2.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            PreviewPrefsTab.getTestEntry();
            try {
              PreviewPanel testPanel =
                  new PreviewPanel(
                      null, PreviewPrefsTab.entry, null, new MetaData(), layout2.getText());
              testPanel.setPreferredSize(new Dimension(800, 350));
              JOptionPane.showMessageDialog(
                  null,
                  new JScrollPane(testPanel),
                  Globals.lang("Preview"),
                  JOptionPane.PLAIN_MESSAGE);
            } catch (StringIndexOutOfBoundsException ex) {
              ex.printStackTrace();
              JOptionPane.showMessageDialog(
                  null,
                  "Parsing error: illegal backslash expression.\n"
                      + ex.getMessage()
                      + "\nLook at stderr for details.",
                  "Parsing error",
                  JOptionPane.ERROR_MESSAGE);
            }
          }
        });
  }