Mercurial > cgi-bin > hgweb.cgi > JpegWasher
comparison src/name/blackcap/exifwasher/WashDialog.kt @ 18:841f711c40bd
Add new dialogs, and make NO the default for dangerous YES answers.
author | David Barts <n5jrn@me.com> |
---|---|
date | Sat, 11 Apr 2020 15:01:23 -0700 |
parents | e52fd1a575de |
children | 39b977021ea1 |
comparison
equal
deleted
inserted
replaced
17:0528030187e9 | 18:841f711c40bd |
---|---|
2 * The dialog that controls washing a single file. | 2 * The dialog that controls washing a single file. |
3 */ | 3 */ |
4 package name.blackcap.exifwasher | 4 package name.blackcap.exifwasher |
5 | 5 |
6 import java.awt.Color | 6 import java.awt.Color |
7 import java.awt.Component | |
7 import java.awt.Dimension | 8 import java.awt.Dimension |
8 import java.awt.event.ActionEvent | 9 import java.awt.event.ActionEvent |
9 import java.awt.event.ActionListener | 10 import java.awt.event.ActionListener |
10 import java.io.File | 11 import java.io.File |
11 import java.io.FileInputStream | 12 import java.io.FileInputStream |
70 it.addActionListener(ActionListener { doWash() }) | 71 it.addActionListener(ActionListener { doWash() }) |
71 } | 72 } |
72 | 73 |
73 private lateinit var washing: File | 74 private lateinit var washing: File |
74 | 75 |
76 /* a yes/no dialog in which NO is the default */ | |
77 private fun noYesDialog(parent: Component, message: String, title: String): Int { | |
78 val options = arrayOf<String>("No", "Yes") | |
79 val status = JOptionPane.showOptionDialog(parent, message, title, | |
80 JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, | |
81 null, options, options[0]) | |
82 return if (status == 1) JOptionPane.YES_OPTION else JOptionPane.NO_OPTION | |
83 } | |
84 | |
75 /* initiates the washing of the Exif data */ | 85 /* initiates the washing of the Exif data */ |
76 fun wash(dirty: File) { | 86 fun wash(dirty: File) { |
77 title = "Washing: ${dirty.name}" | 87 title = "Washing: ${dirty.name}" |
88 | |
89 /* warn (and allow user to back out) if not a JPEG */ | |
90 val lcext = splitext(dirty.name).second.toLowerCase() | |
91 if (lcext != ".jpg" && lcext != ".jpeg") { | |
92 val answer = noYesDialog(Application.mainFrame, | |
93 "File ${dirty.name} does not appear to be a JPEG image.\n"+ | |
94 "Washing non-JPEG images may damage them. Proceed anyway?", | |
95 "Non-JPEG file detected") | |
96 if (answer != JOptionPane.YES_OPTION) { | |
97 close() | |
98 return | |
99 } | |
100 } | |
101 | |
78 selectAll.setSelected(false) | 102 selectAll.setSelected(false) |
79 washing = dirty | 103 washing = dirty |
80 useWaitCursor() | 104 useWaitCursor() |
81 swingWorker<Array<Array<Any>>?> { | 105 swingWorker<Array<Array<Any>>?> { |
82 inBackground { | 106 inBackground { |
153 val (name, ext) = splitext(washing.name) | 177 val (name, ext) = splitext(washing.name) |
154 var newFile = File(outDir, "${name}_washed${ext}") | 178 var newFile = File(outDir, "${name}_washed${ext}") |
155 | 179 |
156 /* warn (and allow user to back out) if overwriting */ | 180 /* warn (and allow user to back out) if overwriting */ |
157 if (newFile.exists()) { | 181 if (newFile.exists()) { |
158 val answer = JOptionPane.showConfirmDialog(Application.mainFrame, | 182 val answer = noYesDialog(Application.mainFrame, |
159 "File ${newFile.name} already exists. Overwrite?", | 183 "File ${newFile.name} already exists. Overwrite?", |
160 "Confirm overwriting file", | 184 "Confirm overwriting file") |
161 JOptionPane.YES_NO_OPTION, | |
162 JOptionPane.WARNING_MESSAGE) | |
163 if (answer != JOptionPane.YES_OPTION) { | 185 if (answer != JOptionPane.YES_OPTION) { |
164 close() | 186 close() |
165 return | 187 return |
166 } | 188 } |
167 } | 189 } |