Exemple #1
0
  public SimpleForm getForm() {
    if (editorForm == null) {
      ButtonBarBuilder builder = new ButtonBarBuilder();
      editorFontTextField = new JTextField(20);
      editorFontTextField.setEnabled(false);
      builder.addFixed(editorFontTextField);
      builder.addRelatedGap();
      builder.addFixed(
          new JButton(
              new AbstractAction("Select Font..") {
                public void actionPerformed(ActionEvent e) {
                  Font font =
                      JFontChooser.showDialog(
                          UISupport.getMainFrame(),
                          "Select XML Editor Font",
                          Font.decode(editorFontTextField.getText()));

                  if (font != null) {
                    editorFontTextField.setText(encodeFont(font));
                  }
                }
              }));

      editorForm = new SimpleForm();
      editorForm.addSpace(5);
      editorForm.append("Editor Font", builder.getPanel());
      editorForm.appendSeparator();
      editorForm.appendCheckBox(
          XML_LINE_NUMBERS, "Show line numbers in XML editors by default", true);
      editorForm.appendCheckBox(
          GROOVY_LINE_NUMBERS, "Show line numbers in Groovy editors by default", true);
      editorForm.appendSeparator();
      editorForm.appendCheckBox(
          NO_RESIZE_REQUEST_EDITOR, "Disables automatic resizing of Request editors", true);
      editorForm.appendCheckBox(
          START_WITH_REQUEST_TABS, "Defaults the Request editor to the tabbed layout", true);
      editorForm.appendSeparator();

      autoValidateCheckBox =
          editorForm.appendCheckBox(
              AUTO_VALIDATE_REQUEST, "Always validate request messages before they are sent", true);
      abortCheckBox =
          editorForm.appendCheckBox(ABORT_ON_INVALID_REQUEST, "Abort invalid requests", true);
      editorForm.appendCheckBox(AUTO_VALIDATE_RESPONSE, "Always validate response messages", true);

      autoValidateCheckBox.addActionListener(
          new ActionListener() {

            public void actionPerformed(ActionEvent e) {
              abortCheckBox.setEnabled(autoValidateCheckBox.isSelected());
            }
          });
    }

    return editorForm;
  }
  private void init() {
    getContentPane().setLayout(new BorderLayout());
    getContentPane().add(labelPatternPanel, BorderLayout.CENTER);

    JButton ok = new JButton(Localization.lang("Ok"));
    JButton cancel =
        new JButton(); // label of "cancel" is set later as the label is overwritten by assigning an
                       // action to the button

    JPanel lower = new JPanel();
    lower.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
    ButtonBarBuilder bb = new ButtonBarBuilder(lower);
    bb.addGlue();
    bb.addButton(ok);
    bb.addButton(cancel);
    bb.addGlue();

    getContentPane().add(lower, BorderLayout.SOUTH);

    this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    getContentPane().setPreferredSize(new Dimension(500, 600));
    pack();

    ok.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            metaData.setLabelPattern(labelPatternPanel.getLabelPatternAsDatabaseLabelPattern());
            panel.markNonUndoableBaseChanged();
            dispose();
          }
        });

    final JDialog dialog = this;

    Action cancelAction =
        new AbstractAction() {

          @Override
          public void actionPerformed(ActionEvent e) {
            dialog.dispatchEvent(new WindowEvent(dialog, WindowEvent.WINDOW_CLOSING));
          }
        };
    cancel.setAction(cancelAction);
    cancel.setText(Localization.lang("Cancel"));

    Util.bindCloseDialogKeyToCancelAction(this.getRootPane(), cancelAction);
  }
  private JPanel buildToolBar() {
    final ButtonBarBuilder builder = new ButtonBarBuilder();
    builder.addGlue();
    final GenerateSqlDialog dlg = this;

    // i18n[mssql.ok=OK]
    JButton okButton = new JButton(s_stringMgr.getString("mssql.ok"));
    okButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            _wasCompleted = true;
            dlg.setVisible(false);
          }
        });
    builder.addGridded(okButton);

    builder.addRelatedGap();

    // i18n[mssql.cancel=Cancel]
    JButton cancelButton = new JButton(s_stringMgr.getString("mssql.cancel"));
    cancelButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            _wasCompleted = false;
            dlg.setVisible(false);
          }
        });
    builder.addGridded(cancelButton);

    return builder.getPanel();
  }
 /**
  * Builds and returns a right aligned bar with help and other buttons.
  *
  * @param help the help button to add on the left side
  * @param buttons an array of buttons to add
  * @return a right aligned button bar with the given buttons
  */
 public static JPanel buildHelpBar(final JButton help, final AbstractButton... buttons) {
   ButtonBarBuilder builder = new ButtonBarBuilder();
   builder.addButton(help);
   builder.addUnrelatedGap();
   builder.addGlue();
   builder.addButton(buttons);
   return builder.getPanel();
 }
    public ContentDialog(String title, String description) throws HeadlessException {
      super(UISupport.getMainFrame());
      setTitle(title);
      setModal(true);

      getContentPane().setLayout(new BorderLayout());
      JLabel label = new JLabel(description);
      label.setBorder(BorderFactory.createEmptyBorder(10, 10, 0, 10));
      getContentPane().add(label, BorderLayout.NORTH);
      getContentPane().add(buildContent(), BorderLayout.CENTER);

      ButtonBarBuilder builder = ButtonBarBuilder.createLeftToRightBuilder();
      builder.addGlue();
      JButton closeButton = new JButton(new CloseAction());
      builder.addFixed(closeButton);

      builder.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10));
      getContentPane().add(builder.getPanel(), BorderLayout.SOUTH);

      pack();

      UISupport.initDialogActions(this, null, closeButton);
    }
  private void initLayout() {
    fieldNameField.setEnabled(false);
    fieldList.setVisibleRowCount(4);
    wordList.setVisibleRowCount(10);
    final String VAL = "Uren luren himmelturen, ja Besseggen.";
    fieldList.setPrototypeCellValue(VAL);
    wordList.setPrototypeCellValue(VAL);

    fieldPan.setBorder(
        BorderFactory.createTitledBorder(
            BorderFactory.createEtchedBorder(), Localization.lang("Field name")));
    wordPan.setBorder(
        BorderFactory.createTitledBorder(
            BorderFactory.createEtchedBorder(), Localization.lang("Keyword")));
    fieldPan.setLayout(gbl);
    wordPan.setLayout(gbl);
    con.insets = new Insets(2, 2, 2, 2);
    con.fill = GridBagConstraints.BOTH;
    con.gridwidth = 2;
    con.weightx = 1;
    con.weighty = 1;
    con.gridx = 0;
    con.gridy = 0;
    gbl.setConstraints(fPane, con);
    fieldPan.add(fPane);
    gbl.setConstraints(wPane, con);
    wordPan.add(wPane);
    con.gridwidth = 1;
    con.gridx = 2;
    // con.weightx = 0.7;
    con.gridheight = 2;
    gbl.setConstraints(fieldNamePan, con);
    fieldPan.add(fieldNamePan);
    gbl.setConstraints(wordEditPan, con);
    wordPan.add(wordEditPan);
    con.gridx = 0;
    con.gridy = 1;
    con.weightx = 0;
    con.weighty = 0;
    con.gridwidth = 1;
    con.gridheight = 1;
    con.fill = GridBagConstraints.NONE;
    con.anchor = GridBagConstraints.WEST;
    gbl.setConstraints(newField, con);
    fieldPan.add(newField);
    gbl.setConstraints(newWord, con);
    wordPan.add(newWord);
    con.gridx = 1;
    // con.anchor = GridBagConstraints.EAST;
    gbl.setConstraints(removeField, con);
    fieldPan.add(removeField);
    gbl.setConstraints(removeWord, con);
    wordPan.add(removeWord);
    con.anchor = GridBagConstraints.WEST;
    con.gridx = 0;
    con.gridy = 0;
    gbl.setConstraints(fieldNameField, con);
    fieldNamePan.add(fieldNameField);
    gbl.setConstraints(wordEditField, con);
    wordEditPan.add(wordEditField);

    // Add buttons:
    ButtonBarBuilder bsb = new ButtonBarBuilder(buttonPan);
    bsb.addGlue();
    bsb.addButton(ok);
    bsb.addButton(apply);
    bsb.addButton(cancel);
    bsb.addRelatedGap();
    bsb.addButton(new HelpAction(frame.helpDiag, GUIGlobals.contentSelectorHelp).getIconButton());
    bsb.addGlue();

    // Add panels to dialog:
    con.fill = GridBagConstraints.BOTH;
    getContentPane().setLayout(gbl);
    con.weightx = 1;
    con.weighty = 0.5;
    con.gridwidth = 1;
    con.gridheight = 1;
    con.gridx = 0;
    con.gridy = 0;
    gbl.setConstraints(fieldPan, con);
    getContentPane().add(fieldPan);
    con.gridy = 1;
    gbl.setConstraints(wordPan, con);
    getContentPane().add(wordPan);
    con.weighty = 0;
    con.gridy = 2;
    con.insets = new Insets(12, 2, 2, 2);
    gbl.setConstraints(buttonPan, con);
    getContentPane().add(buttonPan);
  }
Exemple #7
0
  /**
   * @param groupsRoot The original set of groups, which is required as undo information when all
   *     groups are cleared.
   */
  public AutoGroupDialog(
      JabRefFrame jabrefFrame,
      BasePanel basePanel,
      GroupSelector groupSelector,
      GroupTreeNode groupsRoot,
      String defaultField,
      String defaultRemove,
      String defaultDeliminator) {
    super(jabrefFrame, Localization.lang("Automatically create groups"), true);
    frame = jabrefFrame;
    gs = groupSelector;
    panel = basePanel;
    m_groupsRoot = groupsRoot;
    field.setText(defaultField);
    remove.setText(defaultRemove);
    deliminator.setText(defaultDeliminator);
    nd.setSelected(true);
    ActionListener okListener =
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            dispose();

            GroupTreeNode autoGroupsRoot =
                new GroupTreeNode(
                    new ExplicitGroup(
                        Localization.lang("Automatically created groups"),
                        GroupHierarchyType.INCLUDING));
            Set<String> hs = null;
            String fieldText = field.getText();
            if (keywords.isSelected()) {
              if (nd.isSelected()) {
                hs =
                    Util.findDeliminatedWordsInField(
                        panel.getDatabase(),
                        field.getText().toLowerCase().trim(),
                        deliminator.getText());
              } else {
                hs =
                    Util.findAllWordsInField(
                        panel.getDatabase(),
                        field.getText().toLowerCase().trim(),
                        remove.getText());
              }
            } else if (authors.isSelected()) {
              List<String> fields = new ArrayList<>(2);
              fields.add("author");
              hs = Util.findAuthorLastNames(panel.getDatabase(), fields);
              fieldText = "author";
            } else if (editors.isSelected()) {
              List<String> fields = new ArrayList<>(2);
              fields.add("editor");
              hs = Util.findAuthorLastNames(panel.getDatabase(), fields);
              fieldText = "editor";
            }

            for (String keyword : hs) {
              KeywordGroup group =
                  new KeywordGroup(
                      keyword, fieldText, keyword, false, false, GroupHierarchyType.INDEPENDENT);
              autoGroupsRoot.add(new GroupTreeNode(group));
            }

            m_groupsRoot.add(autoGroupsRoot);
            NamedCompound ce = new NamedCompound(Localization.lang("Autogenerate groups"));
            UndoableAddOrRemoveGroup undo =
                new UndoableAddOrRemoveGroup(
                    gs, m_groupsRoot, autoGroupsRoot, UndoableAddOrRemoveGroup.ADD_NODE);
            undo.setRevalidate(true);
            ce.addEdit(undo);

            panel.markBaseChanged(); // a change always occurs
            gs.revalidateGroups();
            frame.output(Localization.lang("Created groups."));
            ce.end();
            panel.undoManager.addEdit(ce);
          }
        };
    remove.addActionListener(okListener);
    field.addActionListener(okListener);
    field.addCaretListener(this);
    AbstractAction cancelAction =
        new AbstractAction() {

          @Override
          public void actionPerformed(ActionEvent e) {
            dispose();
          }
        };
    JButton cancel = new JButton(Localization.lang("Cancel"));
    cancel.addActionListener(cancelAction);
    ok.addActionListener(okListener);
    // Key bindings:
    JPanel main = new JPanel();
    ActionMap am = main.getActionMap();
    InputMap im = main.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    im.put(frame.prefs().getKey(KeyBinds.CLOSE_DIALOG), "close");
    am.put("close", cancelAction);

    ButtonGroup bg = new ButtonGroup();
    bg.add(keywords);
    bg.add(authors);
    bg.add(editors);
    keywords.setSelected(true);

    FormBuilder b = FormBuilder.create();
    b.layout(
        new FormLayout(
            "left:20dlu, 4dlu, left:pref, 4dlu, fill:60dlu",
            "p, 2dlu, p, 2dlu, p, 2dlu, p, 2dlu, p, 2dlu, p"));
    b.add(keywords).xyw(1, 1, 5);
    b.add(Localization.lang("Field to group by") + ":").xy(3, 3);
    b.add(field).xy(5, 3);
    b.add(Localization.lang("Characters to ignore") + ":").xy(3, 5);
    b.add(remove).xy(5, 5);
    b.add(nd).xy(3, 7);
    b.add(deliminator).xy(5, 7);
    b.add(authors).xyw(1, 9, 5);
    b.add(editors).xyw(1, 11, 5);
    b.build();
    b.border(BorderFactory.createEmptyBorder(5, 5, 5, 5));

    JPanel opt = new JPanel();
    ButtonBarBuilder bb = new ButtonBarBuilder(opt);
    bb.addGlue();
    bb.addButton(ok);
    bb.addButton(cancel);
    bb.addGlue();

    main.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    opt.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    getContentPane().add(main, BorderLayout.CENTER);
    getContentPane().add(b.getPanel(), BorderLayout.CENTER);
    getContentPane().add(opt, BorderLayout.SOUTH);

    updateComponents();
    pack();
    PositionWindow.placeDialog(this, frame);
  }
  private void init(ExternalFileType entry) {
    this.entry = entry;
    icon.setText(null);

    ButtonGroup bg = new ButtonGroup();
    bg.add(useDefault);
    bg.add(other);

    FormBuilder builder = FormBuilder.create();
    builder.layout(
        new FormLayout(
            "left:pref, 4dlu, fill:150dlu, 4dlu, fill:pref",
            "p, 2dlu, p, 2dlu, p, 2dlu, p, 2dlu, p, 2dlu, p"));
    builder.add(Localization.lang("Icon")).xy(1, 1);
    builder.add(icon).xy(3, 1);
    builder.add(Localization.lang("Name")).xy(1, 3);
    builder.add(name).xy(3, 3);
    builder.add(Localization.lang("Extension")).xy(1, 5);
    builder.add(extension).xy(3, 5);
    builder.add(Localization.lang("MIME type")).xy(1, 7);
    builder.add(mimeType).xy(3, 7);
    builder.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    builder.add(Localization.lang("Application")).xy(1, 9);
    JButton browseBut = new JButton(Localization.lang("Browse"));
    if (OS.WINDOWS) {
      builder.add(useDefault).xy(3, 9);
      builder.appendRows("2dlu, p");
      JPanel p1 = new JPanel();
      builder.add(p1).xy(1, 11);
      JPanel p2 = new JPanel();
      application.setPreferredSize(new Dimension(300, application.getPreferredSize().height));
      BorderLayout bl = new BorderLayout();
      bl.setHgap(4);
      p2.setLayout(bl);
      p2.add(other, BorderLayout.WEST);
      p2.add(application, BorderLayout.CENTER);
      builder.add(p2).xy(3, 11);
      builder.add(browseBut).xy(5, 11);
    } else {
      builder.add(application).xy(3, 9);
      builder.add(browseBut).xy(5, 9);
    }
    ButtonBarBuilder bb = new ButtonBarBuilder();
    bb.addGlue();
    bb.addButton(ok);
    bb.addButton(cancel);
    bb.addGlue();

    ok.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            okPressed = true;
            storeSettings(ExternalFileTypeEntryEditor.this.entry);
            diag.dispose();
          }
        });
    cancel.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            diag.dispose();
          }
        });

    icon.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent actionEvent) {
            String initSel = ExternalFileTypeEntryEditor.this.entry.getIconName();
            if (selectedIcon != null) {
              initSel = selectedIcon;
            }
            IconSelection ic = new IconSelection(diag, initSel);
            ic.setVisible(true);
            if (ic.isOkPressed()) {
              selectedIcon = ic.getSelectedIconKey();
              icon.setIcon(IconTheme.getImage(selectedIcon));
            }
            // JOptionPane.showMessageDialog(null, "Sorry, the icon can unfortunately not be changed
            // in this version of JabRef");
          }
        });

    if (OS.WINDOWS) {
      application
          .getDocument()
          .addDocumentListener(
              new DocumentListener() {

                private void handle(DocumentEvent e) {
                  if (application.getText().isEmpty()) {
                    useDefault.setSelected(true);
                  } else {
                    other.setSelected(true);
                  }
                }

                @Override
                public void insertUpdate(DocumentEvent e) {
                  handle(e);
                }

                @Override
                public void removeUpdate(DocumentEvent documentEvent) {
                  handle(documentEvent);
                }

                @Override
                public void changedUpdate(DocumentEvent documentEvent) {
                  handle(documentEvent);
                }
              });
    }

    String title = editFileTitle;

    if (entry.getName().isEmpty()) {
      title = newFileTitle;
    }

    if (dParent != null) {
      diag = new JDialog(dParent, title, true);
    } else {
      diag = new JDialog(fParent, title, true);
    }
    diag.getContentPane().add(builder.getPanel(), BorderLayout.CENTER);
    diag.getContentPane().add(bb.getPanel(), BorderLayout.SOUTH);
    diag.pack();

    BrowseListener browse = new BrowseListener(diag, application);
    browseBut.addActionListener(browse);

    if (dParent != null) {
      diag.setLocationRelativeTo(dParent);
    } else {
      diag.setLocationRelativeTo(fParent);
      // Util.placeDialog(diag, parent);
    }

    setValues(entry);
  }
  public ImportDialog(boolean targetIsARow, String fileName) {
    Boolean targetIsARow1 = targetIsARow;
    contentPane = new JPanel();
    contentPane.setLayout(new BorderLayout());
    setContentPane(contentPane);
    JPanel panel3 = new JPanel();
    panel3.setBackground(new Color(-1643275));
    JLabel labelHeadline = new JLabel(Localization.lang("Import_Metadata_from:"));
    labelHeadline.setFont(new Font(labelHeadline.getFont().getName(), Font.BOLD, 14));
    JLabel labelSubHeadline =
        new JLabel(Localization.lang("Choose_the_source_for_the_metadata_import"));
    labelSubHeadline.setFont(
        new Font(labelSubHeadline.getFont().getName(), labelSubHeadline.getFont().getStyle(), 13));
    JLabel labelFileName = new JLabel();
    labelFileName.setFont(new Font(labelHeadline.getFont().getName(), Font.BOLD, 14));
    JPanel headLinePanel = new JPanel();
    headLinePanel.add(labelHeadline);
    headLinePanel.add(labelFileName);
    headLinePanel.setBackground(new Color(-1643275));
    GridLayout gl = new GridLayout(2, 1);
    gl.setVgap(10);
    gl.setHgap(10);
    panel3.setLayout(gl);
    panel3.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    panel3.add(headLinePanel);
    panel3.add(labelSubHeadline);
    radioButtonNoMeta = new JRadioButton(Localization.lang("Create_blank_entry_linking_the_PDF"));
    radioButtonXmp = new JRadioButton(Localization.lang("Create_entry_based_on_XMP_data"));
    radioButtonPDFcontent = new JRadioButton(Localization.lang("Create_entry_based_on_content"));
    radioButtononlyAttachPDF = new JRadioButton(Localization.lang("Only_attach_PDF"));
    JButton buttonOK = new JButton(Localization.lang("Ok"));
    JButton buttonCancel = new JButton(Localization.lang("Cancel"));
    checkBoxDoNotShowAgain =
        new JCheckBox(Localization.lang("Do not show this box again for this import"));
    useDefaultPDFImportStyle =
        new JCheckBox(
            Localization.lang("Always use this PDF import style (and do not ask for each import)"));
    DefaultFormBuilder b =
        new DefaultFormBuilder(new FormLayout("left:pref, 5dlu, left:pref:grow", ""));
    b.appendSeparator(Localization.lang("Create New Entry"));
    b.append(radioButtonNoMeta, 3);
    b.append(radioButtonXmp, 3);
    b.append(radioButtonPDFcontent, 3);
    b.appendSeparator(Localization.lang("Update_Existing_Entry"));
    b.append(radioButtononlyAttachPDF, 3);
    b.nextLine();
    b.append(checkBoxDoNotShowAgain);
    b.append(useDefaultPDFImportStyle);
    b.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    ButtonBarBuilder bb = new ButtonBarBuilder();
    bb.addGlue();
    bb.addButton(buttonOK);
    bb.addButton(buttonCancel);
    bb.addGlue();
    bb.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

    contentPane.add(panel3, BorderLayout.NORTH);
    contentPane.add(b.getPanel(), BorderLayout.CENTER);
    contentPane.add(bb.getPanel(), BorderLayout.SOUTH);

    if (!targetIsARow1) {
      this.radioButtononlyAttachPDF.setEnabled(false);
    }
    String name = new File(fileName).getName();
    if (name.length() < 34) {
      labelFileName.setText(name);
    } else {
      labelFileName.setText(new File(fileName).getName().substring(0, 33) + "...");
    }
    this.setTitle(Localization.lang("Import_Metadata_From_PDF"));

    setModal(true);
    getRootPane().setDefaultButton(buttonOK);

    // only one of the radio buttons may be selected.
    ButtonGroup bg = new ButtonGroup();
    bg.add(radioButtonNoMeta);
    bg.add(radioButtonXmp);
    bg.add(radioButtonPDFcontent);
    bg.add(radioButtononlyAttachPDF);

    buttonOK.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            onOK();
          }
        });

    buttonCancel.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            onCancel();
          }
        });

    setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    addWindowListener(
        new WindowAdapter() {

          @Override
          public void windowClosing(WindowEvent e) {
            onCancel();
          }
        });

    contentPane.registerKeyboardAction(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            onCancel();
          }
        },
        KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
        JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

    switch (Globals.prefs.getInt(ImportSettingsTab.PREF_IMPORT_DEFAULT_PDF_IMPORT_STYLE)) {
      case NOMETA:
        radioButtonNoMeta.setSelected(true);
        break;
      case XMP:
        radioButtonXmp.setSelected(true);
        break;
      case CONTENT:
        radioButtonPDFcontent.setSelected(true);
        break;
      case ONLYATTACH:
        radioButtononlyAttachPDF.setSelected(true);
        break;
      default:
        // fallback
        radioButtonPDFcontent.setSelected(true);
        break;
    }

    this.setSize(555, 371);
  }
  private void buildDialog() {
    Window window = SwingUtilities.windowForComponent(target.getEditComponent());

    dialog = new JDialog(window, "Find / Replace");
    dialog.setModal(false);

    JPanel panel = new JPanel(new BorderLayout());
    findCombo = new JComboBox();
    findCombo.setEditable(true);
    replaceCombo = new JComboBox();
    replaceCombo.setEditable(true);

    // create inputs
    GridLayout gridLayout = new GridLayout(2, 2);
    gridLayout.setVgap(5);
    JPanel inputPanel = new JPanel(gridLayout);
    inputPanel.add(new JLabel("Find:"));
    inputPanel.add(findCombo);
    inputPanel.add(new JLabel("Replace with:"));
    inputPanel.add(replaceCombo);
    inputPanel.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));

    // create direction panel
    ButtonGroup directionGroup = new ButtonGroup();
    forwardButton = new JRadioButton("Forward", true);
    forwardButton.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
    directionGroup.add(forwardButton);
    backwardButton = new JRadioButton("Backward");
    backwardButton.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
    directionGroup.add(backwardButton);

    JPanel directionPanel = new JPanel(new GridLayout(2, 1));
    directionPanel.add(forwardButton);
    directionPanel.add(backwardButton);
    directionPanel.setBorder(BorderFactory.createTitledBorder("Direction"));

    // create scope panel
    ButtonGroup scopeGroup = new ButtonGroup();
    allButton = new JRadioButton("All", true);
    allButton.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
    selectedLinesButton = new JRadioButton("Selected Lines");
    selectedLinesButton.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
    scopeGroup.add(allButton);
    scopeGroup.add(selectedLinesButton);

    JPanel scopePanel = new JPanel(new GridLayout(2, 1));
    scopePanel.add(allButton);
    scopePanel.add(selectedLinesButton);
    scopePanel.setBorder(BorderFactory.createTitledBorder("Scope"));

    // create options
    caseCheck = new JCheckBox("Case Sensitive");
    caseCheck.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
    wholeWordCheck = new JCheckBox("Whole Word");
    wholeWordCheck.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
    wrapCheck = new JCheckBox("Wrap Search");
    wrapCheck.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
    JPanel optionsPanel = new JPanel(new GridLayout(3, 1));
    optionsPanel.add(caseCheck);
    optionsPanel.add(wholeWordCheck);
    optionsPanel.add(wrapCheck);
    optionsPanel.setBorder(BorderFactory.createTitledBorder("Options"));

    // create panel with options
    JPanel options = new JPanel(new GridLayout(1, 2));

    JPanel radios = new JPanel(new GridLayout(2, 1));
    radios.add(directionPanel);
    radios.add(scopePanel);

    options.add(optionsPanel);
    options.add(radios);
    options.setBorder(BorderFactory.createEmptyBorder(0, 8, 0, 8));

    // create buttons
    ButtonBarBuilder builder = new ButtonBarBuilder();
    findButton = new JButton(new FindAction());
    builder.addFixed(findButton);
    builder.addRelatedGap();
    replaceButton = new JButton(new ReplaceAction());
    builder.addFixed(replaceButton);
    builder.addRelatedGap();
    replaceAllButton = new JButton(new ReplaceAllAction());
    builder.addFixed(replaceAllButton);
    builder.addUnrelatedGap();
    builder.addFixed(new JButton(new CloseAction()));
    builder.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));

    // tie it up!
    panel.add(inputPanel, BorderLayout.NORTH);
    panel.add(options, BorderLayout.CENTER);
    panel.add(builder.getPanel(), BorderLayout.SOUTH);

    dialog.getContentPane().add(panel);
    dialog.pack();
    UISupport.initDialogActions(dialog, null, findButton);
  }
    public OptionsDialog(JFrame parent, BibDatabaseContext databaseContext) {
      super(parent, Localization.lang("Synchronize file links"), true);
      this.databaseContext = databaseContext;
      ok.addActionListener(
          e -> {
            canceled = false;
            dispose();
          });

      Action closeAction =
          new AbstractAction() {

            @Override
            public void actionPerformed(ActionEvent e) {
              dispose();
            }
          };

      cancel.addActionListener(closeAction);

      InputMap im = cancel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
      ActionMap am = cancel.getActionMap();
      im.put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DIALOG), "close");
      am.put("close", closeAction);

      ButtonGroup bg = new ButtonGroup();
      bg.add(autoSetUnset);
      bg.add(autoSetNone);
      bg.add(autoSetAll);

      FormLayout layout =
          new FormLayout(
              "fill:pref",
              "pref, 2dlu, pref, 2dlu, pref, pref, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref");
      FormBuilder builder = FormBuilder.create().layout(layout);
      JLabel description =
          new JLabel(
              "<HTML>"
                  + Localization.lang(
                      "Attempt to automatically set file links for your entries. Automatically setting works if "
                          + "a file in your file directory<BR>or a subdirectory is named identically to an entry's BibTeX key, plus extension.")
                  + "</HTML>");

      builder.addSeparator(Localization.lang("Automatically set file links")).xy(1, 1);
      builder.add(description).xy(1, 3);
      builder.add(autoSetUnset).xy(1, 5);
      builder.add(autoSetAll).xy(1, 6);
      builder.add(autoSetNone).xy(1, 7);
      builder.addSeparator(Localization.lang("Check links")).xy(1, 9);

      description =
          new JLabel(
              "<HTML>"
                  + Localization.lang(
                      "This makes JabRef look up each file link and check if the file exists. If not, you will be given options<BR>to resolve the problem.")
                  + "</HTML>");
      builder.add(description).xy(1, 11);
      builder.add(checkLinks).xy(1, 13);
      builder.addSeparator("").xy(1, 15);

      JPanel main = builder.getPanel();
      main.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

      ButtonBarBuilder bb = new ButtonBarBuilder();
      bb.addGlue();
      bb.addButton(ok);
      bb.addButton(cancel);
      bb.addGlue();
      getContentPane().add(main, BorderLayout.CENTER);
      getContentPane().add(bb.getPanel(), BorderLayout.SOUTH);

      pack();
    }
Exemple #12
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);
    }
 /**
  * Builds and returns a right aligned button bar with the given buttons.
  *
  * @param buttons an array of buttons to add
  * @return a right aligned button bar with the given buttons
  */
 public static JPanel buildRightAlignedBar(final AbstractButton... buttons) {
   ButtonBarBuilder builder = new ButtonBarBuilder();
   builder.addGlue();
   builder.addButton(buttons);
   return builder.getPanel();
 }
  public PreferencesDialog(JabRefFrame parent) {
    super(parent, Localization.lang("JabRef preferences"), false);
    JabRefPreferences prefs = JabRefPreferences.getInstance();
    frame = parent;

    main = new JPanel();
    JPanel mainPanel = new JPanel();
    JPanel lower = new JPanel();

    getContentPane().setLayout(new BorderLayout());
    getContentPane().add(mainPanel, BorderLayout.CENTER);
    getContentPane().add(lower, BorderLayout.SOUTH);

    final CardLayout cardLayout = new CardLayout();
    main.setLayout(cardLayout);

    List<PrefsTab> tabs = new ArrayList<>();
    tabs.add(new GeneralTab(prefs));
    tabs.add(new NetworkTab(prefs));
    tabs.add(new FileTab(frame, prefs));
    tabs.add(new FileSortTab(prefs));
    tabs.add(new EntryEditorPrefsTab(frame, prefs));
    tabs.add(new GroupsPrefsTab(prefs));
    tabs.add(new AppearancePrefsTab(prefs));
    tabs.add(new ExternalTab(frame, this, prefs));
    tabs.add(new TablePrefsTab(prefs));
    tabs.add(new TableColumnsTab(prefs, parent));
    tabs.add(new BibtexKeyPatternPrefTab(prefs, parent.getCurrentBasePanel()));
    tabs.add(new PreviewPrefsTab(prefs));
    tabs.add(new NameFormatterTab(prefs));
    tabs.add(new ImportSettingsTab(prefs));
    tabs.add(new XmpPrefsTab(prefs));
    tabs.add(new AdvancedTab(prefs));

    // add all tabs
    tabs.forEach(tab -> main.add((Component) tab, tab.getTabName()));

    mainPanel.setBorder(BorderFactory.createEtchedBorder());

    String[] tabNames = tabs.stream().map(PrefsTab::getTabName).toArray(String[]::new);
    JList<String> chooser = new JList<>(tabNames);
    chooser.setBorder(BorderFactory.createEtchedBorder());
    // Set a prototype value to control the width of the list:
    chooser.setPrototypeCellValue("This should be wide enough");
    chooser.setSelectedIndex(0);
    chooser.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    // Add the selection listener that will show the correct panel when
    // selection changes:
    chooser.addListSelectionListener(
        e -> {
          if (e.getValueIsAdjusting()) {
            return;
          }
          String o = chooser.getSelectedValue();
          cardLayout.show(main, o);
        });

    JPanel buttons = new JPanel();
    buttons.setLayout(new GridLayout(4, 1));
    buttons.add(importPreferences, 0);
    buttons.add(exportPreferences, 1);
    buttons.add(showPreferences, 2);
    buttons.add(resetPreferences, 3);

    JPanel westPanel = new JPanel();
    westPanel.setLayout(new BorderLayout());
    westPanel.add(chooser, BorderLayout.CENTER);
    westPanel.add(buttons, BorderLayout.SOUTH);
    mainPanel.setLayout(new BorderLayout());
    mainPanel.add(main, BorderLayout.CENTER);
    mainPanel.add(westPanel, BorderLayout.WEST);

    JButton ok = new JButton(Localization.lang("OK"));
    JButton cancel = new JButton(Localization.lang("Cancel"));
    ok.addActionListener(new OkAction());
    CancelAction cancelAction = new CancelAction();
    cancel.addActionListener(cancelAction);
    lower.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
    ButtonBarBuilder buttonBarBuilder = new ButtonBarBuilder(lower);
    buttonBarBuilder.addGlue();
    buttonBarBuilder.addButton(ok);
    buttonBarBuilder.addButton(cancel);
    buttonBarBuilder.addGlue();

    // Key bindings:
    KeyBinder.bindCloseDialogKeyToCancelAction(this.getRootPane(), cancelAction);

    // Import and export actions:
    exportPreferences.setToolTipText(Localization.lang("Export preferences to file"));
    exportPreferences.addActionListener(
        e -> {
          Optional<Path> path =
              new NewFileDialogs(frame, System.getProperty("user.home"))
                  .withExtension(FileExtensions.XML)
                  .saveNewFile();
          path.ifPresent(
              exportFile -> {
                try {
                  prefs.exportPreferences(exportFile.toString());
                } catch (JabRefException ex) {
                  LOGGER.warn(ex.getMessage(), ex);
                  JOptionPane.showMessageDialog(
                      PreferencesDialog.this,
                      ex.getLocalizedMessage(),
                      Localization.lang("Export preferences"),
                      JOptionPane.ERROR_MESSAGE);
                }
              });
        });

    importPreferences.setToolTipText(Localization.lang("Import preferences from file"));
    importPreferences.addActionListener(
        e -> {
          Optional<Path> fileName =
              new NewFileDialogs(frame, System.getProperty("user.home"))
                  .withExtension(FileExtensions.XML)
                  .openDlgAndGetSelectedFile();

          if (fileName.isPresent()) {
            try {
              prefs.importPreferences(fileName.get().toString());
              updateAfterPreferenceChanges();
              JOptionPane.showMessageDialog(
                  PreferencesDialog.this,
                  Localization.lang("You must restart JabRef for this to come into effect."),
                  Localization.lang("Import preferences"),
                  JOptionPane.WARNING_MESSAGE);
            } catch (JabRefException ex) {
              LOGGER.warn(ex.getMessage(), ex);
              JOptionPane.showMessageDialog(
                  PreferencesDialog.this,
                  ex.getLocalizedMessage(),
                  Localization.lang("Import preferences"),
                  JOptionPane.ERROR_MESSAGE);
            }
          }
        });

    showPreferences.addActionListener(
        e ->
            new PreferencesFilterDialog(new JabRefPreferencesFilter(Globals.prefs), frame)
                .setVisible(true));
    resetPreferences.addActionListener(
        e -> {
          if (JOptionPane.showConfirmDialog(
                  PreferencesDialog.this,
                  Localization.lang(
                      "Are you sure you want to reset all settings to default values?"),
                  Localization.lang("Reset preferences"),
                  JOptionPane.OK_CANCEL_OPTION)
              == JOptionPane.OK_OPTION) {
            try {
              prefs.clear();
              JOptionPane.showMessageDialog(
                  PreferencesDialog.this,
                  Localization.lang("You must restart JabRef for this to come into effect."),
                  Localization.lang("Reset preferences"),
                  JOptionPane.WARNING_MESSAGE);
            } catch (BackingStoreException ex) {
              LOGGER.warn(ex.getMessage(), ex);
              JOptionPane.showMessageDialog(
                  PreferencesDialog.this,
                  ex.getLocalizedMessage(),
                  Localization.lang("Reset preferences"),
                  JOptionPane.ERROR_MESSAGE);
            }
            updateAfterPreferenceChanges();
          }
        });

    setValues();

    pack();
  }
  private void init() {

    ok.addActionListener(
        e -> {
          storeSettings();
          dispose();
        });
    Action cancelAction =
        new AbstractAction() {

          @Override
          public void actionPerformed(ActionEvent e) {
            dispose();
          }
        };
    cancel.addActionListener(cancelAction);
    // The toDefaults resets the entire list to its default values.
    toDefaults.addActionListener(
        e -> {
          /*int reply = JOptionPane.showConfirmDialog(ExternalFileTypeEditor.this,
          Globals.lang("All custom file types will be lost. Proceed?"),
          Globals.lang("Reset file type definitions"), JOptionPane.YES_NO_OPTION,
          JOptionPane.QUESTION_MESSAGE);*/
          // if (reply == JOptionPane.YES_OPTION) {
          List<ExternalFileType> list = ExternalFileTypes.getDefaultExternalFileTypes();
          fileTypes.clear();
          fileTypes.addAll(list);
          Collections.sort(fileTypes);
          // Globals.prefs.resetExternalFileTypesToDefault();
          // setValues();
          tableModel.fireTableDataChanged();
          // }
        });

    add.addActionListener(
        e -> {
          // Generate a new file type:
          ExternalFileType type =
              new ExternalFileType("", "", "", "", "new", IconTheme.JabRefIcon.FILE.getSmallIcon());
          // Show the file type editor:
          getEditor(type).setVisible(true);
          if (entryEditor.okPressed()) {
            // Ok was pressed. Add the new file type and update the table:
            fileTypes.add(type);
            tableModel.fireTableDataChanged();
          }
        });

    remove.addActionListener(
        e -> {
          int[] rows = table.getSelectedRows();
          if (rows.length == 0) {
            return;
          }
          for (int i = rows.length - 1; i >= 0; i--) {
            fileTypes.remove(rows[i]);
          }
          tableModel.fireTableDataChanged();
          if (!fileTypes.isEmpty()) {
            int row = Math.min(rows[0], fileTypes.size() - 1);
            table.setRowSelectionInterval(row, row);
          }
        });

    edit.addActionListener(editListener);
    fileTypes = new ArrayList<>();
    setValues();

    tableModel = new FileTypeTableModel();
    table = new JTable(tableModel);
    table.setDefaultRenderer(ImageIcon.class, new IconRenderer());
    table.addMouseListener(new TableClickListener());

    table.getColumnModel().getColumn(0).setMaxWidth(24);
    table.getColumnModel().getColumn(0).setMinWidth(24);
    table.getColumnModel().getColumn(1).setMinWidth(170);
    table.getColumnModel().getColumn(2).setMinWidth(60);
    table.getColumnModel().getColumn(3).setMinWidth(100);
    table.getColumnModel().getColumn(0).setResizable(false);

    GUIUtil.correctRowHeight(table);

    JScrollPane sp = new JScrollPane(table);

    JPanel upper = new JPanel();
    upper.setLayout(new BorderLayout());
    upper.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    upper.add(sp, BorderLayout.CENTER);
    getContentPane().add(upper, BorderLayout.CENTER);

    ButtonStackBuilder bs = new ButtonStackBuilder();
    bs.addButton(add);
    bs.addButton(remove);
    bs.addButton(edit);
    bs.addRelatedGap();
    bs.addButton(toDefaults);
    upper.add(bs.getPanel(), BorderLayout.EAST);

    ButtonBarBuilder bb = new ButtonBarBuilder();
    bb.addGlue();
    bb.addButton(ok);
    bb.addButton(cancel);
    bb.addGlue();
    bb.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    getContentPane().add(bb.getPanel(), BorderLayout.SOUTH);
    pack();

    // Key bindings:
    ActionMap am = upper.getActionMap();
    InputMap im = upper.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    im.put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DIALOG), "close");
    am.put("close", cancelAction);
    am = bb.getPanel().getActionMap();
    im = bb.getPanel().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    im.put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DIALOG), "close");
    am.put("close", cancelAction);

    if (frame == null) {
      setLocationRelativeTo(dialog);
    } else {
      setLocationRelativeTo(frame);
    }
  }
  private void createDialog() {
    diag = new JDialog(frame, Globals.lang("Set/clear/rename fields"), true);

    field = new JTextField();
    text = new JTextField();
    text.setEnabled(false);
    renameTo = new JTextField();
    renameTo.setEnabled(false);

    JButton ok = new JButton(Globals.lang("Ok"));
    JButton cancel = new JButton(Globals.lang("Cancel"));

    all = new JRadioButton(Globals.lang("All entries"));
    selected = new JRadioButton(Globals.lang("Selected entries"));
    clear = new JRadioButton(Globals.lang("Clear fields"));
    set = new JRadioButton(Globals.lang("Set fields"));
    rename = new JRadioButton(Globals.lang("Rename field to:"));
    rename.setToolTipText(
        Globals.lang("Move contents of a field into a field with a different name"));
    set.addChangeListener(
        new ChangeListener() {

          @Override
          public void stateChanged(ChangeEvent e) {
            // Entering a text is only relevant if we are setting, not clearing:
            text.setEnabled(set.isSelected());
          }
        });
    clear.addChangeListener(
        new ChangeListener() {

          @Override
          public void stateChanged(ChangeEvent event) {
            // Overwrite protection makes no sense if we are clearing the field:
            overwrite.setEnabled(!clear.isSelected());
          }
        });
    rename.addChangeListener(
        new ChangeListener() {

          @Override
          public void stateChanged(ChangeEvent e) {
            // Entering a text is only relevant if we are renaming
            renameTo.setEnabled(rename.isSelected());
          }
        });
    overwrite = new JCheckBox(Globals.lang("Overwrite existing field values"), true);
    ButtonGroup bg = new ButtonGroup();
    bg.add(all);
    bg.add(selected);
    bg = new ButtonGroup();
    bg.add(clear);
    bg.add(set);
    bg.add(rename);
    DefaultFormBuilder builder =
        new DefaultFormBuilder(new FormLayout("left:pref, 4dlu, fill:100dlu", ""));
    builder.appendSeparator(Globals.lang("Field name"));
    builder.append(Globals.lang("Field name"));
    builder.append(field);
    builder.nextLine();
    builder.appendSeparator(Globals.lang("Include entries"));
    builder.append(all, 3);
    builder.nextLine();
    builder.append(selected, 3);
    builder.nextLine();
    builder.appendSeparator(Globals.lang("New field value"));
    builder.append(set);
    builder.append(text);
    builder.nextLine();
    builder.append(clear);
    builder.nextLine();
    builder.append(rename);
    builder.append(renameTo);
    builder.nextLine();
    builder.append(overwrite, 3);

    ButtonBarBuilder bb = new ButtonBarBuilder();
    bb.addGlue();
    bb.addButton(ok);
    bb.addButton(cancel);
    bb.addGlue();
    builder.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    bb.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    diag.getContentPane().add(builder.getPanel(), BorderLayout.CENTER);
    diag.getContentPane().add(bb.getPanel(), BorderLayout.SOUTH);
    diag.pack();

    ok.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            // Check if the user tries to rename multiple fields:
            if (rename.isSelected()) {
              String[] fields = getFieldNames(field.getText());
              if (fields.length > 1) {
                JOptionPane.showMessageDialog(
                    diag,
                    Globals.lang("You can only rename one field at a time"),
                    "",
                    JOptionPane.ERROR_MESSAGE);
                return; // Do not close the dialog.
              }
            }
            cancelled = false;
            diag.dispose();
          }
        });

    AbstractAction cancelAction =
        new AbstractAction() {

          @Override
          public void actionPerformed(ActionEvent e) {
            cancelled = true;
            diag.dispose();
          }
        };
    cancel.addActionListener(cancelAction);

    // Key bindings:
    ActionMap am = builder.getPanel().getActionMap();
    InputMap im = builder.getPanel().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    im.put(Globals.prefs.getKey("Close dialog"), "close");
    am.put("close", cancelAction);
  }
  public ManageJournalsPanel(final JabRefFrame frame) {
    this.frame = frame;

    personalFile.setEditable(false);

    ButtonGroup group = new ButtonGroup();
    group.add(newFile);
    group.add(oldFile);
    addExtPan.setLayout(new BorderLayout());
    JButton addExt = new JButton(IconTheme.JabRefIcon.ADD.getIcon());
    addExtPan.add(addExt, BorderLayout.EAST);
    addExtPan.setToolTipText(Localization.lang("Add"));
    // addExtPan.setBorder(BorderFactory.createMatteBorder(1,1,1,1,Color.red));
    FormLayout layout =
        new FormLayout(
            "1dlu, 8dlu, left:pref, 4dlu, fill:200dlu:grow, 4dlu, fill:pref", // 4dlu, left:pref,
                                                                              // 4dlu",
            "pref, pref, pref, 20dlu, 20dlu, fill:200dlu, 4dlu, pref"); // 150dlu");
    FormBuilder builder = FormBuilder.create().layout(layout);

    /*JLabel description = new JLabel("<HTML>"+Glbals.lang("JabRef can switch journal names between "
    +"abbreviated and full form. Since it knows only a limited number of journal names, "
    +"you may need to add your own definitions.")+"</HTML>");*/
    builder.addSeparator(Localization.lang("Built-in journal list")).xyw(2, 1, 6);
    JLabel description =
        new JLabel(
            "<HTML>"
                + Localization.lang("JabRef includes a built-in list of journal abbreviations.")
                + "<br>"
                + Localization.lang(
                    "You can add additional journal names by setting up a personal journal list,<br>as "
                        + "well as linking to external journal lists.")
                + "</HTML>");
    description.setBorder(BorderFactory.createEmptyBorder(5, 0, 5, 0));
    builder.add(description).xyw(2, 2, 6);
    JButton viewBuiltin = new JButton(Localization.lang("View"));
    builder.add(viewBuiltin).xy(7, 2);
    builder.addSeparator(Localization.lang("Personal journal list")).xyw(2, 3, 6);

    // builder.add(description).xyw(2,1,6));
    builder.add(newFile).xy(3, 4);
    builder.add(newNameTf).xy(5, 4);
    JButton browseNew = new JButton(Localization.lang("Browse"));
    builder.add(browseNew).xy(7, 4);
    builder.add(oldFile).xy(3, 5);
    builder.add(personalFile).xy(5, 5);
    // BrowseAction action = new BrowseAction(personalFile, false);
    // JButton browse = new JButton(Globals.lang("Browse"));
    // browse.addActionListener(action);
    JButton browseOld = new JButton(Localization.lang("Browse"));
    builder.add(browseOld).xy(7, 5);

    userPanel.setLayout(new BorderLayout());
    // builtInTable = new JTable(Globals.journalAbbrev.getTableModel());
    builder.add(userPanel).xyw(2, 6, 4);
    ButtonStackBuilder butBul = new ButtonStackBuilder();
    butBul.addButton(add);
    butBul.addButton(remove);

    butBul.addGlue();
    builder.add(butBul.getPanel()).xy(7, 6);

    builder.addSeparator(Localization.lang("External files")).xyw(2, 8, 6);
    externalFilesPanel.setLayout(new BorderLayout());
    // builder.add(/*new JScrollPane(*/externalFilesPanel/*)*/).xyw(2,8,6);

    setLayout(new BorderLayout());
    builder
        .getPanel()
        .setBorder(
            BorderFactory.createEmptyBorder(
                5, 5, 5, 5)); // createMatteBorder(1,1,1,1,Color.green));
    add(builder.getPanel(), BorderLayout.NORTH);
    add(externalFilesPanel, BorderLayout.CENTER);
    ButtonBarBuilder bb = new ButtonBarBuilder();
    bb.addGlue();
    JButton ok = new JButton(Localization.lang("OK"));
    bb.addButton(ok);
    JButton cancel = new JButton(Localization.lang("Cancel"));
    bb.addButton(cancel);
    bb.addUnrelatedGap();

    JButton help = new HelpAction(HelpFiles.journalAbbrHelp).getHelpButton();
    bb.addButton(help);
    bb.addGlue();
    bb.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    dialog = new JDialog(frame, Localization.lang("Journal abbreviations"), false);
    dialog.getContentPane().add(this, BorderLayout.CENTER);
    dialog.getContentPane().add(bb.getPanel(), BorderLayout.SOUTH);

    // add(new JScrollPane(builtInTable), BorderLayout.CENTER);

    // Set up panel for editing a single journal, to be used in a dialog box:
    FormLayout layout2 = new FormLayout("right:pref, 4dlu, fill:180dlu", "p, 2dlu, p");
    FormBuilder builder2 = FormBuilder.create().layout(layout2);
    builder2.add(Localization.lang("Journal name")).xy(1, 1);
    builder2.add(nameTf).xy(3, 1);
    builder2.add(Localization.lang("ISO abbreviation")).xy(1, 3);
    builder2.add(abbrTf).xy(3, 3);
    journalEditPanel = builder2.getPanel();

    viewBuiltin.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            JournalAbbreviationRepository abbr = new JournalAbbreviationRepository();
            abbr.readJournalListFromResource(Abbreviations.JOURNALS_FILE_BUILTIN);
            JTable table =
                new JTable(JournalAbbreviationsUtil.getTableModel(Abbreviations.journalAbbrev));
            JScrollPane pane = new JScrollPane(table);
            JOptionPane.showMessageDialog(
                null,
                pane,
                Localization.lang("Journal list preview"),
                JOptionPane.INFORMATION_MESSAGE);
          }
        });

    browseNew.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            File old = null;
            if (!"".equals(newNameTf.getText())) {
              old = new File(newNameTf.getText());
            }
            String name = FileDialogs.getNewFile(frame, old, null, JFileChooser.SAVE_DIALOG, false);
            if (name != null) {
              newNameTf.setText(name);
              newFile.setSelected(true);
            }
          }
        });
    browseOld.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            File old = null;
            if (!"".equals(personalFile.getText())) {
              old = new File(personalFile.getText());
            }
            String name = FileDialogs.getNewFile(frame, old, null, JFileChooser.OPEN_DIALOG, false);
            if (name != null) {
              personalFile.setText(name);
              oldFile.setSelected(true);
              oldFile.setEnabled(true);
              setupUserTable();
            }
          }
        });

    ok.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            if (readyToClose()) {
              try {
                storeSettings();
                dialog.dispose();
              } catch (FileNotFoundException ex) {
                JOptionPane.showMessageDialog(
                    null,
                    Localization.lang("Error opening file") + ": " + ex.getMessage(),
                    Localization.lang("Error opening file"),
                    JOptionPane.ERROR_MESSAGE);
              }
            }
          }
        });

    AbstractAction cancelAction =
        new AbstractAction() {

          @Override
          public void actionPerformed(ActionEvent e) {
            dialog.dispose();
          }
        };
    cancel.addActionListener(cancelAction);

    add.addActionListener(tableModel);
    remove.addActionListener(tableModel);
    addExt.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            externals.add(new ExternalFileEntry());
            buildExternalsPanel();
          }
        });

    // Key bindings:
    ActionMap am = getActionMap();
    InputMap im = getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    im.put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DIALOG), "close");
    am.put("close", cancelAction);

    // dialog.pack();
    int xSize = getPreferredSize().width;
    dialog.setSize(xSize + 10, 700);
  }
  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();
  }
  public ImportCustomizationDialog(final JabRefFrame frame) {
    super(frame, Localization.lang("Manage custom imports"), false);

    ImportTableModel tableModel = new ImportTableModel();
    customImporterTable = new JTable(tableModel);
    TableColumnModel cm = customImporterTable.getColumnModel();
    cm.getColumn(0).setPreferredWidth(COL_0_WIDTH);
    cm.getColumn(1).setPreferredWidth(COL_1_WIDTH);
    cm.getColumn(2).setPreferredWidth(COL_2_WIDTH);
    cm.getColumn(3).setPreferredWidth(COL_3_WIDTH);
    JScrollPane sp =
        new JScrollPane(
            customImporterTable,
            ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    customImporterTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    customImporterTable.setPreferredScrollableViewportSize(getSize());
    if (customImporterTable.getRowCount() > 0) {
      customImporterTable.setRowSelectionInterval(0, 0);
    }

    JButton addFromFolderButton = new JButton(Localization.lang("Add from folder"));
    addFromFolderButton.addActionListener(
        e -> {
          FileDialog dialog = new FileDialog(frame).withExtension(FileExtensions.CLASS);
          dialog.setDefaultExtension(FileExtensions.CLASS);
          Optional<Path> selectedFile = dialog.showDialogAndGetSelectedFile();

          if (selectedFile.isPresent() && (selectedFile.get().getParent() != null)) {
            String chosenFileStr = selectedFile.get().toString();

            try {
              String basePath = selectedFile.get().getParent().toString();
              String className = pathToClass(basePath, new File(chosenFileStr));
              CustomImporter importer = new CustomImporter(basePath, className);

              addOrReplaceImporter(importer);
              customImporterTable.revalidate();
              customImporterTable.repaint();
            } catch (Exception exc) {
              JOptionPane.showMessageDialog(
                  frame, Localization.lang("Could not instantiate %0", chosenFileStr));
            } catch (NoClassDefFoundError exc) {
              JOptionPane.showMessageDialog(
                  frame,
                  Localization.lang(
                      "Could not instantiate %0. Have you chosen the correct package path?",
                      chosenFileStr));
            }
          }
        });
    addFromFolderButton.setToolTipText(
        Localization.lang("Add a (compiled) custom Importer class from a class path.")
            + "\n"
            + Localization.lang("The path need not be on the classpath of JabRef."));

    JButton addFromJarButton = new JButton(Localization.lang("Add from JAR"));
    addFromJarButton.addActionListener(
        e -> {
          FileDialog dialog =
              new FileDialog(frame)
                  .withExtensions(EnumSet.of(FileExtensions.ZIP, FileExtensions.JAR));
          dialog.setDefaultExtension(FileExtensions.JAR);
          Optional<Path> jarZipFile = dialog.showDialogAndGetSelectedFile();

          if (jarZipFile.isPresent()) {
            try (ZipFile zipFile = new ZipFile(jarZipFile.get().toFile(), ZipFile.OPEN_READ)) {
              ZipFileChooser zipFileChooser = new ZipFileChooser(this, zipFile);
              zipFileChooser.setVisible(true);
              customImporterTable.revalidate();
              customImporterTable.repaint(10);
            } catch (IOException exc) {
              LOGGER.info("Could not open ZIP-archive.", exc);
              JOptionPane.showMessageDialog(
                  frame,
                  Localization.lang("Could not open %0", jarZipFile.get().toString())
                      + "\n"
                      + Localization.lang("Have you chosen the correct package path?"));
            } catch (NoClassDefFoundError exc) {
              LOGGER.info("Could not instantiate ZIP-archive reader.", exc);
              JOptionPane.showMessageDialog(
                  frame,
                  Localization.lang("Could not instantiate %0", jarZipFile.get().toString())
                      + "\n"
                      + Localization.lang("Have you chosen the correct package path?"));
            }
          }
        });
    addFromJarButton.setToolTipText(
        Localization.lang("Add a (compiled) custom Importer class from a ZIP-archive.")
            + "\n"
            + Localization.lang("The ZIP-archive need not be on the classpath of JabRef."));

    JButton showDescButton = new JButton(Localization.lang("Show description"));
    showDescButton.addActionListener(
        e -> {
          int row = customImporterTable.getSelectedRow();
          if (row == -1) {
            JOptionPane.showMessageDialog(frame, Localization.lang("Please select an importer."));
          } else {
            CustomImporter importer =
                ((ImportTableModel) customImporterTable.getModel()).getImporter(row);
            JOptionPane.showMessageDialog(frame, importer.getDescription());
          }
        });

    JButton removeButton = new JButton(Localization.lang("Remove"));
    removeButton.addActionListener(
        e -> {
          int row = customImporterTable.getSelectedRow();
          if (row == -1) {
            JOptionPane.showMessageDialog(frame, Localization.lang("Please select an importer."));
          } else {
            customImporterTable.removeRowSelectionInterval(row, row);
            Globals.prefs.customImports.remove(
                ((ImportTableModel) customImporterTable.getModel()).getImporter(row));
            Globals.IMPORT_FORMAT_READER.resetImportFormats(
                Globals.prefs.getImportFormatPreferences(), Globals.prefs.getXMPPreferences());
            customImporterTable.revalidate();
            customImporterTable.repaint();
          }
        });

    Action closeAction =
        new AbstractAction() {

          @Override
          public void actionPerformed(ActionEvent e) {
            dispose();
          }
        };

    JButton closeButton = new JButton(Localization.lang("Close"));
    closeButton.addActionListener(closeAction);

    JButton helpButton = new HelpAction(HelpFile.CUSTOM_IMPORTS).getHelpButton();

    // Key bindings:
    JPanel mainPanel = new JPanel();
    ActionMap am = mainPanel.getActionMap();
    InputMap im = mainPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    im.put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DIALOG), "close");
    am.put("close", closeAction);
    mainPanel.setLayout(new BorderLayout());
    mainPanel.add(sp, BorderLayout.CENTER);
    JPanel buttons = new JPanel();
    ButtonBarBuilder bb = new ButtonBarBuilder(buttons);
    buttons.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
    bb.addGlue();
    bb.addButton(addFromFolderButton);
    bb.addButton(addFromJarButton);
    bb.addButton(showDescButton);
    bb.addButton(removeButton);
    bb.addButton(closeButton);
    bb.addUnrelatedGap();
    bb.addButton(helpButton);
    bb.addGlue();

    getContentPane().add(mainPanel, BorderLayout.CENTER);
    getContentPane().add(buttons, BorderLayout.SOUTH);
    this.setSize(getSize());
    pack();
    this.setLocationRelativeTo(frame);
    customImporterTable.requestFocus();
  }