2222
2323import javax .swing .Box ;
2424import javax .swing .JButton ;
25+ import javax .swing .JCheckBox ;
2526import javax .swing .JFileChooser ;
2627import javax .swing .JFrame ;
2728import javax .swing .JLabel ;
29+ import javax .swing .JOptionPane ;
2830import javax .swing .JTextField ;
2931import javax .swing .UIManager ;
3032import javax .swing .UnsupportedLookAndFeelException ;
@@ -47,6 +49,9 @@ public class AppWindow {
4749 private Component horizontalStrut_1 ;
4850 private Component verticalStrut ;
4951 private Component horizontalStrut_2 ;
52+ private JCheckBox checkMove ;
53+ private JTextField textMove ;
54+ private JButton buttonMove ;
5055
5156 public static void run () {
5257 EventQueue .invokeLater (new Runnable () {
@@ -77,9 +82,9 @@ private void initialize() {
7782 frame .setDefaultCloseOperation (JFrame .EXIT_ON_CLOSE );
7883 GridBagLayout gridBagLayout = new GridBagLayout ();
7984 gridBagLayout .columnWidths = new int [] { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 };
80- gridBagLayout .rowHeights = new int [] { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 };
85+ gridBagLayout .rowHeights = new int [] { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 };
8186 gridBagLayout .columnWeights = new double [] { 0.0 , 0.0 , 0.0 , 0.0 , 1.0 , 0.0 , 0.0 , Double .MIN_VALUE };
82- gridBagLayout .rowWeights = new double [] { 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , Double .MIN_VALUE };
87+ gridBagLayout .rowWeights = new double [] { 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , Double .MIN_VALUE };
8388 frame .getContentPane ().setLayout (gridBagLayout );
8489
8590 verticalStrut = Box .createVerticalStrut (20 );
@@ -179,7 +184,7 @@ public void actionPerformed(ActionEvent e) {
179184 }
180185 });
181186 GridBagConstraints gbc_buttonSelect = new GridBagConstraints ();
182- gbc_buttonSelect .insets = new Insets (0 , 0 , 5 , 0 );
187+ gbc_buttonSelect .insets = new Insets (0 , 0 , 5 , 5 );
183188 gbc_buttonSelect .gridx = 5 ;
184189 gbc_buttonSelect .gridy = 1 ;
185190 frame .getContentPane ().add (buttonSelect , gbc_buttonSelect );
@@ -253,7 +258,7 @@ public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOEx
253258 labelScan = new JLabel ("Please select a folder" );
254259 GridBagConstraints gbc_labelScan = new GridBagConstraints ();
255260 gbc_labelScan .gridwidth = 2 ;
256- gbc_labelScan .insets = new Insets (0 , 0 , 5 , 0 );
261+ gbc_labelScan .insets = new Insets (0 , 0 , 5 , 5 );
257262 gbc_labelScan .gridx = 4 ;
258263 gbc_labelScan .gridy = 3 ;
259264 frame .getContentPane ().add (labelScan , gbc_labelScan );
@@ -265,14 +270,6 @@ public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOEx
265270 gbc_lblNewLabel_3 .gridy = 5 ;
266271 frame .getContentPane ().add (lblNewLabel_3 , gbc_lblNewLabel_3 );
267272
268- JButton buttonExit = new JButton ("Exit" );
269- buttonExit .addActionListener (new ActionListener () {
270- @ Override
271- public void actionPerformed (ActionEvent e ) {
272- frame .dispose ();
273- }
274- });
275-
276273 buttonCompare = new JButton ("Compare images" );
277274 buttonCompare .setEnabled (false );
278275 buttonCompare .addActionListener (new ActionListener () {
@@ -288,6 +285,14 @@ public void windowClosing(WindowEvent e1) {
288285 }
289286 });
290287 imgframe .setFiles (files );
288+ if (checkMove .isSelected ()) {
289+ File file = new File (textMove .getText ());
290+ if (file .isDirectory ()) {
291+ imgframe .setExclusionFolder (file );
292+ } else {
293+ JOptionPane .showMessageDialog (frame , file + " is not a valid folder. Moving excluded files is disabled." , "Error" , JOptionPane .WARNING_MESSAGE );
294+ }
295+ }
291296 imgframe .setVisible (true );
292297 if ((frame .getExtendedState () & JFrame .MAXIMIZED_BOTH ) != 0 ) {
293298 imgframe .setExtendedState (imgframe .getExtendedState () | JFrame .MAXIMIZED_BOTH );
@@ -303,14 +308,58 @@ public void windowClosing(WindowEvent e1) {
303308 labelCompare = new JLabel ("Please scan for images" );
304309 GridBagConstraints gbc_labelCompare = new GridBagConstraints ();
305310 gbc_labelCompare .gridwidth = 2 ;
306- gbc_labelCompare .insets = new Insets (0 , 0 , 5 , 0 );
311+ gbc_labelCompare .insets = new Insets (0 , 0 , 5 , 5 );
307312 gbc_labelCompare .gridx = 4 ;
308313 gbc_labelCompare .gridy = 5 ;
309314 frame .getContentPane ().add (labelCompare , gbc_labelCompare );
310- GridBagConstraints gbc_buttonExit = new GridBagConstraints ();
311- gbc_buttonExit .gridx = 5 ;
312- gbc_buttonExit .gridy = 7 ;
313- frame .getContentPane ().add (buttonExit , gbc_buttonExit );
315+
316+ checkMove = new JCheckBox ("Enable moving excluded files to this folder:" );
317+ GridBagConstraints gbc_checkMove = new GridBagConstraints ();
318+ gbc_checkMove .anchor = GridBagConstraints .NORTHWEST ;
319+ gbc_checkMove .gridwidth = 2 ;
320+ gbc_checkMove .insets = new Insets (0 , 0 , 5 , 5 );
321+ gbc_checkMove .gridx = 3 ;
322+ gbc_checkMove .gridy = 7 ;
323+ frame .getContentPane ().add (checkMove , gbc_checkMove );
324+
325+ textMove = new JTextField ();
326+ GridBagConstraints gbc_textMove = new GridBagConstraints ();
327+ gbc_textMove .insets = new Insets (0 , 0 , 0 , 5 );
328+ gbc_textMove .fill = GridBagConstraints .HORIZONTAL ;
329+ gbc_textMove .gridx = 4 ;
330+ gbc_textMove .gridy = 8 ;
331+ frame .getContentPane ().add (textMove , gbc_textMove );
332+ textMove .setColumns (10 );
333+
334+ buttonMove = new JButton ("Select..." );
335+ buttonMove .addActionListener (new ActionListener () {
336+ @ Override
337+ public void actionPerformed (ActionEvent e ) {
338+ JFileChooser chooser = new JFileChooser ();
339+ if (textMove .getText ().isEmpty ()) {
340+ chooser .setCurrentDirectory (new File ("." ));
341+ } else {
342+ chooser .setCurrentDirectory (new File (textMove .getText ()));
343+ }
344+ chooser .setDialogTitle ("Select folder for excluded images" );
345+ chooser .setFileSelectionMode (JFileChooser .DIRECTORIES_ONLY );
346+ chooser .setAcceptAllFileFilterUsed (false );
347+ if (chooser .showSaveDialog (frame ) == JFileChooser .APPROVE_OPTION ) {
348+ try {
349+ textMove .setText (chooser .getSelectedFile ().getCanonicalPath ().toString ());
350+ } catch (IOException e1 ) {
351+ e1 .printStackTrace ();
352+ textMove .setText (e1 .getLocalizedMessage ());
353+ checkMove .setSelected (false );
354+ }
355+ }
356+ }
357+ });
358+ GridBagConstraints gbc_buttonMove = new GridBagConstraints ();
359+ gbc_buttonMove .insets = new Insets (0 , 0 , 0 , 5 );
360+ gbc_buttonMove .gridx = 5 ;
361+ gbc_buttonMove .gridy = 8 ;
362+ frame .getContentPane ().add (buttonMove , gbc_buttonMove );
314363 }
315364
316365}
0 commit comments