Search in sources :

Example 11 with FormBuilder

use of com.jgoodies.forms.builder.FormBuilder in project jabref by JabRef.

the class IntegrityCheckAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    IntegrityCheck check = new IntegrityCheck(frame.getCurrentBasePanel().getBibDatabaseContext(), Globals.prefs.getFileDirectoryPreferences(), Globals.prefs.getBibtexKeyPatternPreferences(), Globals.journalAbbreviationLoader.getRepository(Globals.prefs.getJournalAbbreviationPreferences()));
    List<IntegrityMessage> messages = check.checkBibtexDatabase();
    if (messages.isEmpty()) {
        JOptionPane.showMessageDialog(frame.getCurrentBasePanel(), Localization.lang("No problems found."));
    } else {
        Map<String, Boolean> showMessage = new HashMap<>();
        // prepare data model
        Object[][] model = new Object[messages.size()][4];
        int i = 0;
        for (IntegrityMessage message : messages) {
            model[i][0] = message.getEntry().getId();
            model[i][1] = message.getEntry().getCiteKeyOptional().orElse("");
            model[i][2] = message.getFieldName();
            model[i][3] = message.getMessage();
            showMessage.put(message.getMessage(), true);
            i++;
        }
        // construct view
        JTable table = new JTable(model, new Object[] { "ID", Localization.lang("BibTeX key"), Localization.lang("Field"), Localization.lang("Message") });
        // hide IDs
        TableColumnModel columnModel = table.getColumnModel();
        columnModel.removeColumn(columnModel.getColumn(0));
        RowFilter<Object, Object> filter = new RowFilter<Object, Object>() {

            @Override
            public boolean include(Entry<?, ?> entry) {
                return showMessage.get(entry.getStringValue(3));
            }
        };
        TableRowSorter<TableModel> sorter = new TableRowSorter<>(table.getModel());
        sorter.setRowFilter(filter);
        table.setRowSorter(sorter);
        table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        table.setDefaultEditor(Object.class, null);
        ListSelectionModel selectionModel = table.getSelectionModel();
        selectionModel.addListSelectionListener(event -> {
            if (!event.getValueIsAdjusting()) {
                try {
                    String entryId = (String) model[table.convertRowIndexToModel(table.getSelectedRow())][0];
                    String fieldName = (String) model[table.convertRowIndexToModel(table.getSelectedRow())][2];
                    frame.getCurrentBasePanel().editEntryByIdAndFocusField(entryId, fieldName);
                } catch (ArrayIndexOutOfBoundsException exception) {
                }
            }
        });
        // BibTeX key
        table.getColumnModel().getColumn(0).setPreferredWidth(100);
        // field name
        table.getColumnModel().getColumn(1).setPreferredWidth(60);
        // message
        table.getColumnModel().getColumn(2).setPreferredWidth(400);
        table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
        JScrollPane scrollPane = new JScrollPane(table);
        String title = Localization.lang("%0 problem(s) found", String.valueOf(messages.size()));
        JDialog dialog = new JDialog(frame, title, false);
        JPopupMenu menu = new JPopupMenu();
        for (String messageString : showMessage.keySet()) {
            JCheckBoxMenuItem menuItem = new JCheckBoxMenuItem(messageString, true);
            menuItem.addActionListener(event -> {
                showMessage.put(messageString, menuItem.isSelected());
                ((AbstractTableModel) table.getModel()).fireTableDataChanged();
            });
            menu.add(menuItem);
        }
        JButton menuButton = new JButton(Localization.lang("Filter"));
        menuButton.addActionListener(entry -> menu.show(menuButton, 0, menuButton.getHeight()));
        FormBuilder builder = FormBuilder.create().layout(new FormLayout("fill:pref:grow", "fill:pref:grow, 2dlu, pref"));
        builder.add(scrollPane).xy(1, 1);
        builder.add(menuButton).xy(1, 3, "c, b");
        dialog.add(builder.getPanel());
        dialog.setSize(600, 600);
        // show view
        dialog.setVisible(true);
    }
}
Also used : HashMap(java.util.HashMap) JButton(javax.swing.JButton) TableColumnModel(javax.swing.table.TableColumnModel) IntegrityCheck(org.jabref.logic.integrity.IntegrityCheck) IntegrityMessage(org.jabref.logic.integrity.IntegrityMessage) RowFilter(javax.swing.RowFilter) TableRowSorter(javax.swing.table.TableRowSorter) JScrollPane(javax.swing.JScrollPane) FormLayout(com.jgoodies.forms.layout.FormLayout) FormBuilder(com.jgoodies.forms.builder.FormBuilder) ListSelectionModel(javax.swing.ListSelectionModel) JPopupMenu(javax.swing.JPopupMenu) JCheckBoxMenuItem(javax.swing.JCheckBoxMenuItem) JTable(javax.swing.JTable) AbstractTableModel(javax.swing.table.AbstractTableModel) AbstractTableModel(javax.swing.table.AbstractTableModel) TableModel(javax.swing.table.TableModel) JDialog(javax.swing.JDialog)

Example 12 with FormBuilder

use of com.jgoodies.forms.builder.FormBuilder in project jabref by JabRef.

the class MassSetFieldAction method createDialog.

private void createDialog() {
    diag = new JDialog(frame, Localization.lang("Set/clear/rename fields"), true);
    field = new JComboBox<>();
    field.setEditable(true);
    text = new JTextField();
    text.setEnabled(false);
    renameTo = new JTextField();
    renameTo.setEnabled(false);
    JButton ok = new JButton(Localization.lang("OK"));
    JButton cancel = new JButton(Localization.lang("Cancel"));
    all = new JRadioButton(Localization.lang("All entries"));
    selected = new JRadioButton(Localization.lang("Selected entries"));
    clear = new JRadioButton(Localization.lang("Clear fields"));
    set = new JRadioButton(Localization.lang("Set fields"));
    rename = new JRadioButton(Localization.lang("Rename field to") + ":");
    rename.setToolTipText(Localization.lang("Move contents of a field into a field with a different name"));
    Set<String> allFields = frame.getCurrentBasePanel().getDatabase().getAllVisibleFields();
    for (String f : allFields) {
        field.addItem(f);
    }
    set.addChangeListener(e -> text.setEnabled(set.isSelected()));
    clear.addChangeListener(e -> overwrite.setEnabled(!clear.isSelected()));
    rename.addChangeListener(e -> renameTo.setEnabled(rename.isSelected()));
    overwrite = new JCheckBox(Localization.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);
    FormBuilder builder = FormBuilder.create().layout(new FormLayout("left:pref, 4dlu, fill:100dlu:grow", "pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref"));
    builder.addSeparator(Localization.lang("Field name")).xyw(1, 1, 3);
    builder.add(Localization.lang("Field name")).xy(1, 3);
    builder.add(field).xy(3, 3);
    builder.addSeparator(Localization.lang("Include entries")).xyw(1, 5, 3);
    builder.add(all).xyw(1, 7, 3);
    builder.add(selected).xyw(1, 9, 3);
    builder.addSeparator(Localization.lang("New field value")).xyw(1, 11, 3);
    builder.add(set).xy(1, 13);
    builder.add(text).xy(3, 13);
    builder.add(clear).xyw(1, 15, 3);
    builder.add(rename).xy(1, 17);
    builder.add(renameTo).xy(3, 17);
    builder.add(overwrite).xyw(1, 19, 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(e -> {
        String fieldText = (String) field.getSelectedItem();
        if ((fieldText == null) || fieldText.trim().isEmpty()) {
            JOptionPane.showMessageDialog(diag, Localization.lang("You must enter at least one field name"), "", JOptionPane.ERROR_MESSAGE);
            return;
        }
        if (rename.isSelected()) {
            String[] fields = getFieldNames(fieldText);
            if (fields.length > 1) {
                JOptionPane.showMessageDialog(diag, Localization.lang("You can only rename one field at a time"), "", JOptionPane.ERROR_MESSAGE);
                return;
            }
        }
        canceled = false;
        diag.dispose();
    });
    Action cancelAction = new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            canceled = 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.getKeyPrefs().getKey(KeyBinding.CLOSE_DIALOG), "close");
    am.put("close", cancelAction);
}
Also used : FormLayout(com.jgoodies.forms.layout.FormLayout) FormBuilder(com.jgoodies.forms.builder.FormBuilder) Action(javax.swing.Action) AbstractAction(javax.swing.AbstractAction) JRadioButton(javax.swing.JRadioButton) ActionMap(javax.swing.ActionMap) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) JTextField(javax.swing.JTextField) JCheckBox(javax.swing.JCheckBox) ButtonGroup(javax.swing.ButtonGroup) ButtonBarBuilder(com.jgoodies.forms.builder.ButtonBarBuilder) InputMap(javax.swing.InputMap) AbstractAction(javax.swing.AbstractAction) JDialog(javax.swing.JDialog)

Example 13 with FormBuilder

use of com.jgoodies.forms.builder.FormBuilder in project jabref by JabRef.

the class SaveOrderConfigDisplay method init.

private void init() {
    List<String> fieldNames = InternalBibtexFields.getAllPublicFieldNames();
    fieldNames.add(BibEntry.KEY_FIELD);
    Collections.sort(fieldNames);
    String[] allPlusKey = fieldNames.toArray(new String[fieldNames.size()]);
    savePriSort = new JComboBox<>(allPlusKey);
    savePriSort.setEditable(true);
    saveSecSort = new JComboBox<>(allPlusKey);
    saveSecSort.setEditable(true);
    saveTerSort = new JComboBox<>(allPlusKey);
    saveTerSort.setEditable(true);
    savePriDesc = new JCheckBox(Localization.lang("Descending"));
    saveSecDesc = new JCheckBox(Localization.lang("Descending"));
    saveTerDesc = new JCheckBox(Localization.lang("Descending"));
    FormLayout layout = new FormLayout("right:pref, 8dlu, fill:pref, 4dlu, fill:60dlu, 4dlu, left:pref", "pref, 2dlu, pref, 2dlu, pref");
    FormBuilder builder = FormBuilder.create().layout(layout);
    builder.add(Localization.lang("Primary sort criterion")).xy(1, 1);
    builder.add(savePriSort).xy(3, 1);
    builder.add(savePriDesc).xy(5, 1);
    builder.add(Localization.lang("Secondary sort criterion")).xy(1, 3);
    builder.add(saveSecSort).xy(3, 3);
    builder.add(saveSecDesc).xy(5, 3);
    builder.add(Localization.lang("Tertiary sort criterion")).xy(1, 5);
    builder.add(saveTerSort).xy(3, 5);
    builder.add(saveTerDesc).xy(5, 5);
    panel = builder.build();
}
Also used : JCheckBox(javax.swing.JCheckBox) FormLayout(com.jgoodies.forms.layout.FormLayout) FormBuilder(com.jgoodies.forms.builder.FormBuilder)

Example 14 with FormBuilder

use of com.jgoodies.forms.builder.FormBuilder in project jabref by JabRef.

the class FieldFormatterCleanupsPanel method getSelectorPanel.

/**
     * This panel contains the two comboboxes and the Add button
     * @return Returns the created JPanel
     */
private JPanel getSelectorPanel() {
    FormBuilder builder = FormBuilder.create().layout(new FormLayout("left:pref:grow, 4dlu, left:pref:grow, 4dlu, fill:pref:grow, 4dlu, right:pref", "fill:pref:grow, 2dlu, pref, 2dlu"));
    List<String> fieldNames = InternalBibtexFields.getAllPublicAndInternalFieldNames();
    fieldNames.add(BibEntry.KEY_FIELD);
    Collections.sort(fieldNames);
    String[] allPlusKey = fieldNames.toArray(new String[fieldNames.size()]);
    selectFieldCombobox = new JComboBox<>(allPlusKey);
    selectFieldCombobox.setEditable(true);
    builder.add(selectFieldCombobox).xy(1, 1);
    List<String> formatterNames = Cleanups.getAvailableFormatters().stream().map(Formatter::getName).collect(Collectors.toList());
    List<String> formatterDescriptions = Cleanups.getAvailableFormatters().stream().map(Formatter::getDescription).collect(Collectors.toList());
    formattersCombobox = new JComboBox<>(formatterNames.toArray());
    formattersCombobox.setRenderer(new DefaultListCellRenderer() {

        @Override
        public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            if ((-1 < index) && (index < formatterDescriptions.size()) && (value != null)) {
                setToolTipText(formatterDescriptions.get(index));
            }
            return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
        }
    });
    formattersCombobox.addItemListener(e -> updateDescription());
    builder.add(formattersCombobox).xy(3, 1);
    addButton = new JButton(Localization.lang("Add"));
    addButton.addActionListener(e -> {
        FieldFormatterCleanup newAction = getFieldFormatterCleanup();
        if (newAction == null) {
            return;
        }
        ((CleanupActionsListModel) actionsList.getModel()).addCleanupAction(newAction);
    });
    builder.add(addButton).xy(5, 1);
    return builder.getPanel();
}
Also used : FormLayout(com.jgoodies.forms.layout.FormLayout) FormBuilder(com.jgoodies.forms.builder.FormBuilder) JButton(javax.swing.JButton) DefaultListCellRenderer(javax.swing.DefaultListCellRenderer) FieldFormatterCleanup(org.jabref.model.cleanup.FieldFormatterCleanup) Component(java.awt.Component)

Example 15 with FormBuilder

use of com.jgoodies.forms.builder.FormBuilder in project jabref by JabRef.

the class CleanupPresetPanel method init.

private void init() {
    cleanUpDOI = new JCheckBox(Localization.lang("Move DOIs from note and URL field to DOI field and remove http prefix"));
    cleanUpISSN = new JCheckBox(Localization.lang("Reformat ISSN"));
    Optional<Path> firstExistingDir = databaseContext.getFirstExistingFileDir(JabRefPreferences.getInstance().getFileDirectoryPreferences());
    if (firstExistingDir.isPresent()) {
        cleanUpMovePDF = new JCheckBox(Localization.lang("Move linked files to default file directory %0", firstExistingDir.get().toString()));
    } else {
        cleanUpMovePDF = new JCheckBox(Localization.lang("Move linked files to default file directory %0", "..."));
        cleanUpMovePDF.setEnabled(false);
        cleanUpMovePDF.setSelected(false);
    }
    cleanUpMakePathsRelative = new JCheckBox(Localization.lang("Make paths of linked files relative (if possible)"));
    cleanUpRenamePDF = new JCheckBox(Localization.lang("Rename PDFs to given filename format pattern"));
    cleanUpRenamePDF.addChangeListener(event -> cleanUpRenamePDFonlyRelativePaths.setEnabled(cleanUpRenamePDF.isSelected()));
    cleanUpRenamePDFonlyRelativePaths = new JCheckBox(Localization.lang("Rename only PDFs having a relative path"));
    cleanUpUpgradeExternalLinks = new JCheckBox(Localization.lang("Upgrade external PDF/PS links to use the '%0' field.", FieldName.FILE));
    cleanUpBiblatex = new JCheckBox(Localization.lang("Convert to biblatex format (for example, move the value of the 'journal' field to 'journaltitle')"));
    cleanUpFormatters = new FieldFormatterCleanupsPanel(Localization.lang("Run field formatter:"), Cleanups.DEFAULT_SAVE_ACTIONS);
    updateDisplay(cleanupPreset);
    FormLayout layout = new FormLayout("left:15dlu, fill:pref:grow", "pref, pref, pref, pref, pref, fill:pref:grow, pref,pref, pref,190dlu, fill:pref:grow,");
    FormBuilder builder = FormBuilder.create().layout(layout);
    builder.add(cleanUpDOI).xyw(1, 1, 2);
    builder.add(cleanUpUpgradeExternalLinks).xyw(1, 2, 2);
    builder.add(cleanUpMovePDF).xyw(1, 3, 2);
    builder.add(cleanUpMakePathsRelative).xyw(1, 4, 2);
    builder.add(cleanUpRenamePDF).xyw(1, 5, 2);
    String currentPattern = Localization.lang("Filename format pattern").concat(": ");
    currentPattern = currentPattern.concat(Globals.prefs.get(JabRefPreferences.IMPORT_FILENAMEPATTERN));
    builder.add(new JLabel(currentPattern)).xy(2, 6);
    builder.add(cleanUpRenamePDFonlyRelativePaths).xy(2, 7);
    builder.add(cleanUpBiblatex).xyw(1, 8, 2);
    builder.add(cleanUpISSN).xyw(1, 9, 2);
    builder.add(cleanUpFormatters).xyw(1, 10, 2);
    panel = builder.build();
    scrollPane = new JScrollPane(panel);
    scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
    scrollPane.setVisible(true);
    scrollPane.setBorder(null);
}
Also used : JCheckBox(javax.swing.JCheckBox) Path(java.nio.file.Path) FormLayout(com.jgoodies.forms.layout.FormLayout) JScrollPane(javax.swing.JScrollPane) FormBuilder(com.jgoodies.forms.builder.FormBuilder) JLabel(javax.swing.JLabel)

Aggregations

FormBuilder (com.jgoodies.forms.builder.FormBuilder)19 FormLayout (com.jgoodies.forms.layout.FormLayout)19 JButton (javax.swing.JButton)11 ButtonBarBuilder (com.jgoodies.forms.builder.ButtonBarBuilder)8 ActionEvent (java.awt.event.ActionEvent)8 AbstractAction (javax.swing.AbstractAction)8 JDialog (javax.swing.JDialog)8 Action (javax.swing.Action)7 BorderLayout (java.awt.BorderLayout)6 JTextField (javax.swing.JTextField)6 ButtonGroup (javax.swing.ButtonGroup)5 JPanel (javax.swing.JPanel)5 Path (java.nio.file.Path)4 ActionMap (javax.swing.ActionMap)4 InputMap (javax.swing.InputMap)4 JCheckBox (javax.swing.JCheckBox)4 JScrollPane (javax.swing.JScrollPane)4 DialogService (org.jabref.gui.DialogService)4 FXDialogService (org.jabref.gui.FXDialogService)4 FileDialogConfiguration (org.jabref.gui.util.FileDialogConfiguration)4