Exemplo n.º 1
0
 /**
  * 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();
 }
Exemplo n.º 2
0
  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 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);
  }
  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();
  }