3 import javax.swing.JDialog;
4 import java.awt.HeadlessException;
5 import java.awt.GridBagLayout;
6 import java.awt.GridBagConstraints;
8 import java.awt.Insets;
9 import java.awt.BorderLayout;
10 import java.awt.event.ActionListener;
11 import java.awt.event.ActionEvent;
13 import net.sf.jabref.export.*;
19 // modified : r.nagel 2.09.2004
20 // - insert close button
22 public class DuplicateResolverDialog extends JDialog {
24 public static final int
34 final Dimension DIM = new Dimension(650, 600);
38 JTabbedPane tabbed = new JTabbedPane();
39 GridBagLayout gbl = new GridBagLayout();
40 GridBagConstraints con = new GridBagConstraints();
41 JButton first, second, both,
42 cancel = new JButton(Globals.lang("Cancel"));
43 JPanel options = new JPanel(),
45 source = new JPanel();
46 int status = NOT_CHOSEN;
50 public DuplicateResolverDialog(JabRefFrame frame, BibtexEntry one, BibtexEntry two, int type) {
51 super(frame, Globals.lang("Possible duplicate entries"), true);
54 case DUPLICATE_SEARCH:
55 first = new JButton(Globals.lang("Keep upper"));
56 second = new JButton(Globals.lang("Keep lower"));
57 both = new JButton(Globals.lang("Keep both"));
60 first = new JButton(Globals.lang("Remove old entry"));
61 second = new JButton(Globals.lang("Remove entry from import"));
62 both = new JButton(Globals.lang("Keep both"));
65 first = new JButton(Globals.lang("Import and remove old entry"));
66 second = new JButton(Globals.lang("Do not import entry"));
67 both = new JButton(Globals.lang("Import and keep old entry"));
70 String layout = Globals.prefs.get("preview0");
71 p1 = new PreviewPanel(one, layout);
72 p2 = new PreviewPanel(two, layout);
73 ta1 = new JTextArea();
74 ta2 = new JTextArea();
75 ta1.setEditable(false);
76 ta2.setEditable(false);
78 //ta1.setPreferredSize(dim);
79 //ta2.setPreferredSize(dim);
81 setSourceView(one, two);
83 //getContentPane().setLayout();
85 source.setLayout(gbl);
86 con.insets = new Insets(10,10,0,10);
87 con.fill = GridBagConstraints.BOTH;
88 con.gridwidth = GridBagConstraints.REMAINDER;
91 lab = new TitleLabel(Globals.lang((type==DUPLICATE_SEARCH)?"":
92 "Entry in current database"));
93 gbl.setConstraints(lab, con);
96 con.insets = new Insets(5,10,10,10);
97 JScrollPane sp = new JScrollPane(p1);
98 gbl.setConstraints(sp, con);
101 con.insets = new Insets(10,10,0,10);
102 lab = new TitleLabel(Globals.lang((type==DUPLICATE_SEARCH)?"":
104 gbl.setConstraints(lab, con);
107 con.insets = new Insets(5,10,10,10);
108 sp = new JScrollPane(ta1);
109 gbl.setConstraints(sp, con);
111 sp = new JScrollPane(p2);
112 gbl.setConstraints(sp, con);
114 sp = new JScrollPane(ta2);
115 gbl.setConstraints(sp, con);
117 tabbed.add(Globals.lang("Short form"), main);
118 tabbed.add(Globals.lang("Complete record"), source);
122 if (type != IMPORT_CHECK) {
123 options.add(Box.createHorizontalStrut(5));
127 first.addActionListener(new ActionListener() {
128 public void actionPerformed(ActionEvent e) {
135 second.addActionListener(new ActionListener() {
136 public void actionPerformed(ActionEvent e) {
143 both.addActionListener(new ActionListener() {
144 public void actionPerformed(ActionEvent e) {
151 cancel.addActionListener(new ActionListener() {
152 public void actionPerformed(ActionEvent e) {
159 getContentPane().add(tabbed, BorderLayout.CENTER);
160 getContentPane().add(options, BorderLayout.SOUTH);
164 if (getHeight() > DIM.height) {
165 setSize(new Dimension(getWidth(), DIM.height));
167 if (getWidth() > DIM.width) {
168 setSize(new Dimension(DIM.width, getHeight()));
173 Util.placeDialog(this, frame);
176 private void setSourceView(BibtexEntry one, BibtexEntry two) {
178 StringWriter sw = new StringWriter();
179 one.write(sw, new LatexFieldFormatter(), false);
180 ta1.setText(sw.getBuffer().toString());
181 sw = new StringWriter();
182 two.write(sw, new LatexFieldFormatter(), false);
183 ta2.setText(sw.getBuffer().toString());
185 catch (IOException ex) {
191 public void setEntries(BibtexEntry newOne, BibtexEntry newTwo) {
192 setSourceView(newOne, newTwo);
201 public boolean isBlocking() {
205 public int getSelected() {
209 public static int resolveDuplicate(JabRefFrame frame, BibtexEntry one, BibtexEntry two) {
210 DuplicateResolverDialog drd = new DuplicateResolverDialog(frame, one, two,
213 return drd.getSelected();