3333import javax .swing .event .DocumentEvent ;
3434import javax .swing .event .DocumentListener ;
3535
36+ import info .loenwind .compare .tools .FileIdReader ;
37+ import info .loenwind .compare .tools .Settings ;
38+
3639public class AppWindow {
3740
3841 private JFrame frame ;
@@ -52,6 +55,12 @@ public class AppWindow {
5255 private JCheckBox checkMove ;
5356 private JTextField textMove ;
5457 private JButton buttonMove ;
58+ private JLabel lblNewLabel_4 ;
59+
60+ private final Settings settings = new Settings ();
61+ private JCheckBox checkSuddenDeath ;
62+ private Component verticalStrut_1 ;
63+ private Component verticalStrut_2 ;
5564
5665 public static void run () {
5766 EventQueue .invokeLater (new Runnable () {
@@ -77,14 +86,14 @@ private void initialize() {
7786 } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e2 ) {
7887 e2 .printStackTrace ();
7988 }
80- frame = new JFrame ("Image Voter" );
89+ frame = new JFrame (Main . APP_NAME );
8190 frame .setBounds (100 , 100 , 640 , 320 );
8291 frame .setDefaultCloseOperation (JFrame .EXIT_ON_CLOSE );
8392 GridBagLayout gridBagLayout = new GridBagLayout ();
8493 gridBagLayout .columnWidths = new int [] { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 };
85- gridBagLayout .rowHeights = new int [] { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 };
94+ gridBagLayout .rowHeights = new int [] { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 };
8695 gridBagLayout .columnWeights = new double [] { 0.0 , 0.0 , 0.0 , 0.0 , 1.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 };
96+ gridBagLayout .rowWeights = new double [] { 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , Double .MIN_VALUE };
8897 frame .getContentPane ().setLayout (gridBagLayout );
8998
9099 verticalStrut = Box .createVerticalStrut (20 );
@@ -123,6 +132,7 @@ private void initialize() {
123132 frame .getContentPane ().add (horizontalStrut , gbc_horizontalStrut );
124133
125134 JLabel lblNewLabel = new JLabel ("Source folder:" );
135+ lblNewLabel .setToolTipText ("This folder and all its sub-folders will be scanned for PNG and JPG images." );
126136 GridBagConstraints gbc_lblNewLabel = new GridBagConstraints ();
127137 gbc_lblNewLabel .anchor = GridBagConstraints .EAST ;
128138 gbc_lblNewLabel .insets = new Insets (0 , 0 , 5 , 5 );
@@ -131,6 +141,7 @@ private void initialize() {
131141 frame .getContentPane ().add (lblNewLabel , gbc_lblNewLabel );
132142
133143 textField = new JTextField ();
144+ lblNewLabel .setLabelFor (textField );
134145 textField .getDocument ().addDocumentListener (new DocumentListener () {
135146
136147 @ Override
@@ -189,11 +200,68 @@ public void actionPerformed(ActionEvent e) {
189200 gbc_buttonSelect .gridy = 1 ;
190201 frame .getContentPane ().add (buttonSelect , gbc_buttonSelect );
191202
203+ lblNewLabel_4 = new JLabel ("Target folder:" );
204+ lblNewLabel_4 .setToolTipText (
205+ "(optional)\n A folder to move images to when you're done with them.\n Sub-folders will be created here depending on the type of images you move (excluded/winners/rated)." );
206+ GridBagConstraints gbc_lblNewLabel_4 = new GridBagConstraints ();
207+ gbc_lblNewLabel_4 .anchor = GridBagConstraints .EAST ;
208+ gbc_lblNewLabel_4 .insets = new Insets (0 , 0 , 5 , 5 );
209+ gbc_lblNewLabel_4 .gridx = 3 ;
210+ gbc_lblNewLabel_4 .gridy = 2 ;
211+ frame .getContentPane ().add (lblNewLabel_4 , gbc_lblNewLabel_4 );
212+
213+ textMove = new JTextField ();
214+ lblNewLabel_4 .setLabelFor (textMove );
215+ GridBagConstraints gbc_textMove = new GridBagConstraints ();
216+ gbc_textMove .insets = new Insets (0 , 0 , 5 , 5 );
217+ gbc_textMove .fill = GridBagConstraints .HORIZONTAL ;
218+ gbc_textMove .gridx = 4 ;
219+ gbc_textMove .gridy = 2 ;
220+ frame .getContentPane ().add (textMove , gbc_textMove );
221+ textMove .setColumns (10 );
222+
223+ buttonMove = new JButton ("Select..." );
224+ buttonMove .addActionListener (new ActionListener () {
225+ @ Override
226+ public void actionPerformed (ActionEvent e ) {
227+ JFileChooser chooser = new JFileChooser ();
228+ if (textMove .getText ().isEmpty ()) {
229+ chooser .setCurrentDirectory (new File ("." ));
230+ } else {
231+ chooser .setCurrentDirectory (new File (textMove .getText ()));
232+ }
233+ chooser .setDialogTitle ("Select folder for excluded images" );
234+ chooser .setFileSelectionMode (JFileChooser .DIRECTORIES_ONLY );
235+ chooser .setAcceptAllFileFilterUsed (false );
236+ if (chooser .showSaveDialog (frame ) == JFileChooser .APPROVE_OPTION ) {
237+ try {
238+ textMove .setText (chooser .getSelectedFile ().getCanonicalPath ().toString ());
239+ } catch (IOException e1 ) {
240+ e1 .printStackTrace ();
241+ textMove .setText (e1 .getLocalizedMessage ());
242+ checkMove .setSelected (false );
243+ }
244+ }
245+ }
246+ });
247+ GridBagConstraints gbc_buttonMove = new GridBagConstraints ();
248+ gbc_buttonMove .insets = new Insets (0 , 0 , 5 , 5 );
249+ gbc_buttonMove .gridx = 5 ;
250+ gbc_buttonMove .gridy = 2 ;
251+ frame .getContentPane ().add (buttonMove , gbc_buttonMove );
252+
253+ verticalStrut_1 = Box .createVerticalStrut (20 );
254+ GridBagConstraints gbc_verticalStrut_1 = new GridBagConstraints ();
255+ gbc_verticalStrut_1 .insets = new Insets (0 , 0 , 5 , 5 );
256+ gbc_verticalStrut_1 .gridx = 2 ;
257+ gbc_verticalStrut_1 .gridy = 3 ;
258+ frame .getContentPane ().add (verticalStrut_1 , gbc_verticalStrut_1 );
259+
192260 lblNewLabel_2 = new JLabel ("Step 2:" );
193261 GridBagConstraints gbc_lblNewLabel_2 = new GridBagConstraints ();
194262 gbc_lblNewLabel_2 .insets = new Insets (0 , 0 , 5 , 5 );
195263 gbc_lblNewLabel_2 .gridx = 1 ;
196- gbc_lblNewLabel_2 .gridy = 3 ;
264+ gbc_lblNewLabel_2 .gridy = 4 ;
197265 frame .getContentPane ().add (lblNewLabel_2 , gbc_lblNewLabel_2 );
198266
199267 buttonScan = new JButton ("Scan for images" );
@@ -224,6 +292,9 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
224292 if (file .toString ().toLowerCase (Locale .ENGLISH ).endsWith (".png" ) || file .toString ().toLowerCase (Locale .ENGLISH ).endsWith (".jpg" )) {
225293 files .add (file .toFile ());
226294 }
295+ if (file .getFileName ().toString ().toLowerCase (Locale .ENGLISH ).equals ("files.bbs" )) {
296+ FileIdReader .read (settings , file .toFile ());
297+ }
227298 return FileVisitResult .CONTINUE ;
228299 }
229300
@@ -252,31 +323,61 @@ public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOEx
252323 GridBagConstraints gbc_btnNewButton_1 = new GridBagConstraints ();
253324 gbc_btnNewButton_1 .insets = new Insets (0 , 0 , 5 , 5 );
254325 gbc_btnNewButton_1 .gridx = 3 ;
255- gbc_btnNewButton_1 .gridy = 3 ;
326+ gbc_btnNewButton_1 .gridy = 4 ;
256327 frame .getContentPane ().add (buttonScan , gbc_btnNewButton_1 );
257328
258329 labelScan = new JLabel ("Please select a folder" );
259330 GridBagConstraints gbc_labelScan = new GridBagConstraints ();
260331 gbc_labelScan .gridwidth = 2 ;
261332 gbc_labelScan .insets = new Insets (0 , 0 , 5 , 5 );
262333 gbc_labelScan .gridx = 4 ;
263- gbc_labelScan .gridy = 3 ;
334+ gbc_labelScan .gridy = 4 ;
264335 frame .getContentPane ().add (labelScan , gbc_labelScan );
265336
337+ verticalStrut_2 = Box .createVerticalStrut (20 );
338+ GridBagConstraints gbc_verticalStrut_2 = new GridBagConstraints ();
339+ gbc_verticalStrut_2 .insets = new Insets (0 , 0 , 5 , 5 );
340+ gbc_verticalStrut_2 .gridx = 2 ;
341+ gbc_verticalStrut_2 .gridy = 5 ;
342+ frame .getContentPane ().add (verticalStrut_2 , gbc_verticalStrut_2 );
343+
266344 lblNewLabel_3 = new JLabel ("Step 3:" );
267345 GridBagConstraints gbc_lblNewLabel_3 = new GridBagConstraints ();
268346 gbc_lblNewLabel_3 .insets = new Insets (0 , 0 , 5 , 5 );
269347 gbc_lblNewLabel_3 .gridx = 1 ;
270- gbc_lblNewLabel_3 .gridy = 5 ;
348+ gbc_lblNewLabel_3 .gridy = 6 ;
271349 frame .getContentPane ().add (lblNewLabel_3 , gbc_lblNewLabel_3 );
272350
273- buttonCompare = new JButton ("Compare images" );
351+ buttonCompare = new JButton ("Compare images... " );
274352 buttonCompare .setEnabled (false );
275353 buttonCompare .addActionListener (new ActionListener () {
276354 @ Override
277355 public void actionPerformed (ActionEvent e ) {
356+ settings .setAutoTrashingEnabled (checkMove .isSelected ());
357+ settings .setSuddenDeathEnabled (checkSuddenDeath .isSelected ());
358+ settings .setTargetFolder (new File (textMove .getText ()));
359+ settings .setTargetFolderValid (settings .getTargetFolder ().isDirectory ());
360+ if (settings .isAutoTrashingEnabled () && !settings .isTargetFolderValid ()) {
361+ JOptionPane .showMessageDialog (frame , settings .getTargetFolder () + " is not a valid folder. Moving/copying files is disabled." , "Error" ,
362+ JOptionPane .WARNING_MESSAGE );
363+ }
364+ settings .setTrashFolder (new File (settings .getTargetFolder (), "excluded" ));
365+ if (settings .isAutoTrashingEnabled () && settings .isTargetFolderValid ()) {
366+ int rollingPostfix = 0 ;
367+ while (settings .getTrashFolder ().exists () && !settings .getTrashFolder ().isDirectory ()) {
368+ settings .setTrashFolder (new File (settings .getTargetFolder (), "excluded_" + (rollingPostfix ++)));
369+ }
370+ if (!settings .getTrashFolder ().exists () && !settings .getTrashFolder ().mkdir ()) {
371+ JOptionPane .showMessageDialog (frame , settings .getTrashFolder () + " could not be created. Moving excluded files is disabled." , "Error" ,
372+ JOptionPane .WARNING_MESSAGE );
373+ settings .setTrashFolderValid (false );
374+ } else {
375+ settings .setTrashFolderValid (true );
376+ }
377+ }
378+
278379 frame .setVisible (false );
279- ImgWindow imgframe = new ImgWindow ();
380+ ImgWindow imgframe = new ImgWindow (settings );
280381 imgframe .addWindowListener (new WindowAdapter () {
281382 @ Override
282383 public void windowClosing (WindowEvent e1 ) {
@@ -285,15 +386,8 @@ public void windowClosing(WindowEvent e1) {
285386 }
286387 });
287388 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- }
296389 imgframe .setVisible (true );
390+
297391 if ((frame .getExtendedState () & JFrame .MAXIMIZED_BOTH ) != 0 ) {
298392 imgframe .setExtendedState (imgframe .getExtendedState () | JFrame .MAXIMIZED_BOTH );
299393 }
@@ -302,18 +396,19 @@ public void windowClosing(WindowEvent e1) {
302396 GridBagConstraints gbc_btnNewButton_2 = new GridBagConstraints ();
303397 gbc_btnNewButton_2 .insets = new Insets (0 , 0 , 5 , 5 );
304398 gbc_btnNewButton_2 .gridx = 3 ;
305- gbc_btnNewButton_2 .gridy = 5 ;
399+ gbc_btnNewButton_2 .gridy = 6 ;
306400 frame .getContentPane ().add (buttonCompare , gbc_btnNewButton_2 );
307401
308402 labelCompare = new JLabel ("Please scan for images" );
309403 GridBagConstraints gbc_labelCompare = new GridBagConstraints ();
310404 gbc_labelCompare .gridwidth = 2 ;
311405 gbc_labelCompare .insets = new Insets (0 , 0 , 5 , 5 );
312406 gbc_labelCompare .gridx = 4 ;
313- gbc_labelCompare .gridy = 5 ;
407+ gbc_labelCompare .gridy = 6 ;
314408 frame .getContentPane ().add (labelCompare , gbc_labelCompare );
315409
316- checkMove = new JCheckBox ("Enable moving excluded files to this folder:" );
410+ checkMove = new JCheckBox ("Automatically move excluded files" );
411+ checkMove .setToolTipText ("If enabled, images you \" exclude\" will automatically be moved to a subfolder \" excluded\" in the target folder." );
317412 GridBagConstraints gbc_checkMove = new GridBagConstraints ();
318413 gbc_checkMove .anchor = GridBagConstraints .NORTHWEST ;
319414 gbc_checkMove .gridwidth = 2 ;
@@ -322,44 +417,15 @@ public void windowClosing(WindowEvent e1) {
322417 gbc_checkMove .gridy = 7 ;
323418 frame .getContentPane ().add (checkMove , gbc_checkMove );
324419
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 );
420+ checkSuddenDeath = new JCheckBox ("Use \" Sudden Death\" voting" );
421+ checkSuddenDeath .setToolTipText ("Images that are not given a \" like\" are eliminated from the competition. (Note that they are not \" excluded\" .)" );
422+ GridBagConstraints gbc_checkSuddenDeath = new GridBagConstraints ();
423+ gbc_checkSuddenDeath .anchor = GridBagConstraints .WEST ;
424+ gbc_checkSuddenDeath .gridwidth = 2 ;
425+ gbc_checkSuddenDeath .insets = new Insets (0 , 0 , 5 , 5 );
426+ gbc_checkSuddenDeath .gridx = 3 ;
427+ gbc_checkSuddenDeath .gridy = 8 ;
428+ frame .getContentPane ().add (checkSuddenDeath , gbc_checkSuddenDeath );
363429 }
364430
365431}
0 commit comments