Search in sources :

Example 1 with SentenceCaseFormatter

use of org.jabref.logic.formatter.casechanger.SentenceCaseFormatter in project jabref by JabRef.

the class MergeEntries method setupFieldRows.

private int setupFieldRows(JPanel mergePanel) {
    // For all fields in joint add a row and possibly radio buttons
    int row = 2;
    int maxLabelWidth = -1;
    for (String field : allFields) {
        JLabel label = boldFontLabel(new SentenceCaseFormatter().format(field));
        mergePanel.add(label, CELL_CONSTRAINTS.xy(1, (2 * row) - 1, "left, top"));
        Optional<String> leftString = leftEntry.getField(field);
        Optional<String> rightString = rightEntry.getField(field);
        if (leftString.equals(rightString)) {
            identicalFields.add(field);
        } else {
            differentFields.add(field);
        }
        maxLabelWidth = Math.max(maxLabelWidth, label.getPreferredSize().width);
        // Left text pane
        if (leftString.isPresent()) {
            JTextPane tf = new DiffHighlightingTextPane();
            mergePanel.add(tf, CELL_CONSTRAINTS.xy(3, (2 * row) - 1, "f, f"));
            leftTextPanes.put(field, tf);
        }
        // Add radio buttons if the two entries do not have identical fields
        if (identicalFields.contains(field)) {
            // Will only happen if both entries have the field and the content is identical
            mergedEntry.setField(field, leftString.get());
        } else {
            ButtonGroup group = new ButtonGroup();
            List<JRadioButton> list = new ArrayList<>(3);
            for (int k = 0; k < 3; k++) {
                JRadioButton button = new JRadioButton();
                group.add(button);
                mergePanel.add(button, CELL_CONSTRAINTS.xy(5 + (k * 2), (2 * row) - 1));
                button.addChangeListener(e -> updateAll());
                list.add(button);
            }
            radioButtons.put(field, list);
            if (leftString.isPresent()) {
                list.get(0).setSelected(true);
                if (!rightString.isPresent()) {
                    list.get(2).setEnabled(false);
                }
            } else {
                list.get(0).setEnabled(false);
                list.get(2).setSelected(true);
            }
        }
        // Right text pane
        if (rightString.isPresent()) {
            JTextPane tf = new DiffHighlightingTextPane();
            mergePanel.add(tf, CELL_CONSTRAINTS.xy(11, (2 * row) - 1, "f, f"));
            rightTextPanes.put(field, tf);
        }
        row++;
    }
    return maxLabelWidth;
}
Also used : JTextPane(javax.swing.JTextPane) JRadioButton(javax.swing.JRadioButton) ButtonGroup(javax.swing.ButtonGroup) DiffHighlightingTextPane(org.jabref.gui.util.component.DiffHighlightingTextPane) ArrayList(java.util.ArrayList) JLabel(javax.swing.JLabel) SentenceCaseFormatter(org.jabref.logic.formatter.casechanger.SentenceCaseFormatter)

Aggregations

ArrayList (java.util.ArrayList)1 ButtonGroup (javax.swing.ButtonGroup)1 JLabel (javax.swing.JLabel)1 JRadioButton (javax.swing.JRadioButton)1 JTextPane (javax.swing.JTextPane)1 DiffHighlightingTextPane (org.jabref.gui.util.component.DiffHighlightingTextPane)1 SentenceCaseFormatter (org.jabref.logic.formatter.casechanger.SentenceCaseFormatter)1