1
1
package org .jabref .gui ;
2
2
3
- import java .awt .BorderLayout ;
4
- import java .awt .event .WindowAdapter ;
5
- import java .awt .event .WindowEvent ;
3
+ import javafx .scene .control .Button ;
4
+ import javafx .scene .control .ButtonBar ;
5
+ import javafx .scene .control .ButtonBar .ButtonData ;
6
+ import javafx .scene .control .ButtonType ;
7
+ import javafx .scene .layout .BorderPane ;
6
8
7
- import javax .swing .Box ;
8
- import javax .swing .JButton ;
9
- import javax .swing .JPanel ;
10
-
11
- import javafx .scene .Scene ;
12
-
13
- import org .jabref .gui .customjfx .CustomJFXPanel ;
9
+ import org .jabref .gui .DuplicateResolverDialog .DuplicateResolverResult ;
14
10
import org .jabref .gui .help .HelpAction ;
15
- import org .jabref .gui .importer .ImportInspectionDialog ;
16
11
import org .jabref .gui .mergeentries .MergeEntries ;
17
- import org .jabref .gui .util .WindowLocation ;
12
+ import org .jabref .gui .util .BaseDialog ;
18
13
import org .jabref .logic .help .HelpFile ;
19
14
import org .jabref .logic .l10n .Localization ;
20
15
import org .jabref .model .entry .BibEntry ;
21
- import org .jabref .preferences .JabRefPreferences ;
22
16
23
- public class DuplicateResolverDialog extends JabRefDialog {
17
+ public class DuplicateResolverDialog extends BaseDialog < DuplicateResolverResult > {
24
18
25
19
public enum DuplicateResolverType {
26
20
DUPLICATE_SEARCH ,
@@ -30,7 +24,6 @@ public enum DuplicateResolverType {
30
24
}
31
25
32
26
public enum DuplicateResolverResult {
33
- NOT_CHOSEN ,
34
27
KEEP_BOTH ,
35
28
KEEP_LEFT ,
36
29
KEEP_RIGHT ,
@@ -39,108 +32,89 @@ public enum DuplicateResolverResult {
39
32
BREAK
40
33
}
41
34
42
- JButton helpButton = new HelpAction (Localization .lang ("Help" ), HelpFile .FIND_DUPLICATES ).getHelpButton ();
43
- private final JButton cancel = new JButton (Localization .lang ("Cancel" ));
44
- private final JButton merge = new JButton (Localization .lang ("Keep merged entry only" ));
45
35
private final JabRefFrame frame ;
46
- private final JPanel options = new JPanel ();
47
- private DuplicateResolverResult status = DuplicateResolverResult .NOT_CHOSEN ;
48
36
private MergeEntries me ;
49
37
50
38
public DuplicateResolverDialog (JabRefFrame frame , BibEntry one , BibEntry two , DuplicateResolverType type ) {
51
- super (Localization .lang ("Possible duplicate entries" ), true , DuplicateResolverDialog .class );
52
39
this .frame = frame ;
53
- init (one , two , type );
54
- }
55
-
56
- public DuplicateResolverDialog (ImportInspectionDialog dialog , BibEntry one , BibEntry two ,
57
- DuplicateResolverType type ) {
58
- super (dialog , Localization .lang ("Possible duplicate entries" ), true , DuplicateResolverDialog .class );
59
- this .frame = dialog .getFrame ();
40
+ this .setTitle (Localization .lang ("Possible duplicate entries" ));
60
41
init (one , two , type );
61
42
}
62
43
63
44
private void init (BibEntry one , BibEntry two , DuplicateResolverType type ) {
64
- JButton both ;
65
- JButton second ;
66
- JButton first ;
67
- JButton removeExact = null ;
68
- switch (type ) {
69
- case DUPLICATE_SEARCH :
70
- first = new JButton (Localization .lang ("Keep left" ));
71
- second = new JButton (Localization .lang ("Keep right" ));
72
- both = new JButton (Localization .lang ("Keep both" ));
73
- me = new MergeEntries (one , two , frame .getCurrentBasePanel ().getBibDatabaseContext ().getMode ());
74
- break ;
75
- case INSPECTION :
76
- first = new JButton (Localization .lang ("Remove old entry" ));
77
- second = new JButton (Localization .lang ("Remove entry from import" ));
78
- both = new JButton (Localization .lang ("Keep both" ));
79
- me = new MergeEntries (one , two , Localization .lang ("Old entry" ),
80
- Localization .lang ("From import" ), frame .getCurrentBasePanel ().getBibDatabaseContext ().getMode ());
81
- break ;
82
- case DUPLICATE_SEARCH_WITH_EXACT :
83
- first = new JButton (Localization .lang ("Keep left" ));
84
- second = new JButton (Localization .lang ("Keep right" ));
85
- both = new JButton (Localization .lang ("Keep both" ));
86
- removeExact = new JButton (Localization .lang ("Automatically remove exact duplicates" ));
87
- me = new MergeEntries (one , two , frame .getCurrentBasePanel ().getBibDatabaseContext ().getMode ());
88
- break ;
89
- default :
90
- first = new JButton (Localization .lang ("Import and remove old entry" ));
91
- second = new JButton (Localization .lang ("Do not import entry" ));
92
- both = new JButton (Localization .lang ("Import and keep old entry" ));
93
- me = new MergeEntries (one , two , Localization .lang ("Old entry" ),
94
- Localization .lang ("From import" ), frame .getCurrentBasePanel ().getBibDatabaseContext ().getMode ());
95
- break ;
96
- }
97
45
98
- if (removeExact != null ) {
99
- options .add (removeExact );
46
+ HelpAction helpCommand = new HelpAction (HelpFile .FIND_DUPLICATES );
47
+ ButtonType help = new ButtonType (Localization .lang ("Help" ), ButtonData .HELP );
48
+
49
+ ButtonType cancel = ButtonType .CANCEL ;
50
+ ButtonType merge = new ButtonType (Localization .lang ("Keep merged entry only" ), ButtonData .APPLY );
51
+
52
+ ButtonBar options = new ButtonBar ();
53
+ ButtonType both ;
54
+ ButtonType second ;
55
+ ButtonType first ;
56
+ ButtonType removeExact = new ButtonType (Localization .lang ("Automatically remove exact duplicates" ), ButtonData .APPLY );
57
+ boolean removeExactVisible = false ;
58
+
59
+ switch (type ) {
60
+ case DUPLICATE_SEARCH :
61
+ first = new ButtonType (Localization .lang ("Keep left" ), ButtonData .APPLY );
62
+ second = new ButtonType (Localization .lang ("Keep right" ), ButtonData .APPLY );
63
+ both = new ButtonType (Localization .lang ("Keep both" ), ButtonData .APPLY );
64
+ me = new MergeEntries (one , two , frame .getCurrentBasePanel ().getBibDatabaseContext ().getMode ());
65
+ break ;
66
+ case INSPECTION :
67
+ first = new ButtonType (Localization .lang ("Remove old entry" ), ButtonData .APPLY );
68
+ second = new ButtonType (Localization .lang ("Remove entry from import" ), ButtonData .APPLY );
69
+ both = new ButtonType (Localization .lang ("Keep both" ), ButtonData .APPLY );
70
+ me = new MergeEntries (one , two , Localization .lang ("Old entry" ),
71
+ Localization .lang ("From import" ), frame .getCurrentBasePanel ().getBibDatabaseContext ().getMode ());
72
+ break ;
73
+ case DUPLICATE_SEARCH_WITH_EXACT :
74
+ first = new ButtonType (Localization .lang ("Keep left" ), ButtonData .APPLY );
75
+ second = new ButtonType (Localization .lang ("Keep right" ), ButtonData .APPLY );
76
+ both = new ButtonType (Localization .lang ("Keep both" ), ButtonData .APPLY );
77
+
78
+ removeExactVisible = true ;
79
+
80
+ me = new MergeEntries (one , two , frame .getCurrentBasePanel ().getBibDatabaseContext ().getMode ());
81
+ break ;
82
+ default :
83
+ first = new ButtonType (Localization .lang ("Import and remove old entry" ), ButtonData .APPLY );
84
+ second = new ButtonType (Localization .lang ("Do not import entry" ), ButtonData .APPLY );
85
+ both = new ButtonType (Localization .lang ("Import and keep old entry" ), ButtonData .APPLY );
86
+ me = new MergeEntries (one , two , Localization .lang ("Old entry" ),
87
+ Localization .lang ("From import" ), frame .getCurrentBasePanel ().getBibDatabaseContext ().getMode ());
88
+ break ;
100
89
}
101
- options .add (first );
102
- options .add (second );
103
- options .add (both );
104
- options .add (merge );
105
- options .add (Box .createHorizontalStrut (5 ));
106
- options .add (cancel );
107
- options .add (helpButton );
108
-
109
- first .addActionListener (e -> buttonPressed (DuplicateResolverResult .KEEP_LEFT ));
110
- second .addActionListener (e -> buttonPressed (DuplicateResolverResult .KEEP_RIGHT ));
111
- both .addActionListener (e -> buttonPressed (DuplicateResolverResult .KEEP_BOTH ));
112
- merge .addActionListener (e -> buttonPressed (DuplicateResolverResult .KEEP_MERGE ));
113
- if (removeExact != null ) {
114
- removeExact .addActionListener (e -> buttonPressed (DuplicateResolverResult .AUTOREMOVE_EXACT ));
90
+ if (removeExactVisible ) {
91
+ this .getDialogPane ().getButtonTypes ().add (removeExact );
115
92
}
116
93
117
- cancel .addActionListener (e -> buttonPressed (DuplicateResolverResult .BREAK ));
118
- addWindowListener (new WindowAdapter () {
119
- @ Override
120
- public void windowClosing (WindowEvent e ) {
121
- buttonPressed (DuplicateResolverResult .BREAK );
122
- }
123
- });
94
+ this .getDialogPane ().getButtonTypes ().addAll (first , second , both , merge , cancel , help );
124
95
125
- getContentPane ().add (CustomJFXPanel .wrap (new Scene (me )));
126
- getContentPane ().add (options , BorderLayout .SOUTH );
127
- pack ();
96
+ BorderPane borderPane = new BorderPane (me );
97
+ borderPane .setBottom (options );
128
98
129
- WindowLocation pw = new WindowLocation (this , JabRefPreferences .DUPLICATES_POS_X ,
130
- JabRefPreferences .DUPLICATES_POS_Y , JabRefPreferences .DUPLICATES_SIZE_X ,
131
- JabRefPreferences .DUPLICATES_SIZE_Y );
132
- pw .displayWindowAtStoredLocation ();
99
+ this .setResultConverter (button -> {
133
100
134
- both .requestFocus ();
135
- }
136
-
137
- private void buttonPressed (DuplicateResolverResult result ) {
138
- status = result ;
139
- dispose ();
140
- }
101
+ if (button .equals (first )) {
102
+ return DuplicateResolverResult .KEEP_LEFT ;
103
+ } else if (button .equals (second )) {
104
+ return DuplicateResolverResult .KEEP_RIGHT ;
105
+ } else if (button .equals (both )) {
106
+ return DuplicateResolverResult .KEEP_BOTH ;
107
+ } else if (button .equals (merge )) {
108
+ return DuplicateResolverResult .KEEP_MERGE ;
109
+ } else if (button .equals (removeExact )) {
110
+ return DuplicateResolverResult .AUTOREMOVE_EXACT ;
111
+ }
112
+ return null ;
113
+ });
141
114
142
- public DuplicateResolverResult getSelected () {
143
- return status ;
115
+ getDialogPane ().setContent (borderPane );
116
+ Button helpButton = (Button ) this .getDialogPane ().lookupButton (help );
117
+ helpButton .setOnAction (evt -> helpCommand .getCommand ().execute ());
144
118
}
145
119
146
120
public BibEntry getMergedEntry () {
0 commit comments