use of org.jabref.gui.util.component.DiffHighlightingTextPane 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;
}
use of org.jabref.gui.util.component.DiffHighlightingTextPane in project jabref by JabRef.
the class MergeEntries method setupEntryTypeRow.
private void setupEntryTypeRow(JPanel mergePanel) {
// Start with entry type
mergePanel.add(boldFontLabel(Localization.lang("Entry type")), CELL_CONSTRAINTS.xy(1, 1));
JTextPane leftTypeDisplay = new DiffHighlightingTextPane();
leftTypeDisplay.setText(DiffHighlighting.HTML_START + leftEntry.getType() + DiffHighlighting.HTML_END);
mergePanel.add(leftTypeDisplay, CELL_CONSTRAINTS.xy(3, 1));
if (leftEntry.getType().equals(rightEntry.getType())) {
identicalTypes = true;
} else {
identicalTypes = false;
ButtonGroup group = new ButtonGroup();
typeRadioButtons = new ArrayList<>(2);
for (int k = 0; k < 3; k += 2) {
JRadioButton button = new JRadioButton();
typeRadioButtons.add(button);
group.add(button);
mergePanel.add(button, CELL_CONSTRAINTS.xy(5 + (k * 2), 1));
button.addChangeListener(e -> updateAll());
}
typeRadioButtons.get(0).setSelected(true);
}
JTextPane rightTypeDisplay = new DiffHighlightingTextPane();
rightTypeDisplay.setText(DiffHighlighting.HTML_START + rightEntry.getType() + DiffHighlighting.HTML_END);
mergePanel.add(rightTypeDisplay, CELL_CONSTRAINTS.xy(11, 1));
}
Aggregations