annotate src/name/blackcap/exifwasher/WashDialog.kt @ 40:a65a8f5a9647

Remove more deadwood.
author David Barts <n5jrn@me.com>
date Fri, 01 May 2020 23:07:23 -0700
parents 3d9c36307704
children 40911898ed23
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
1 /*
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
2 * The dialog that controls washing a single file.
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
3 */
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
4 package name.blackcap.exifwasher
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
5
9
0a106e9b91b4 Fix table layout; fix "select all for deletion" feature.
David Barts <n5jrn@me.com>
parents: 8
diff changeset
6 import java.awt.Color
18
841f711c40bd Add new dialogs, and make NO the default for dangerous YES answers.
David Barts <n5jrn@me.com>
parents: 11
diff changeset
7 import java.awt.Component
5
dc1f4359659d Got it compiling.
David Barts <n5jrn@me.com>
parents: 3
diff changeset
8 import java.awt.Dimension
3
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
9 import java.awt.event.ActionEvent
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
10 import java.awt.event.ActionListener
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
11 import java.io.File
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
12 import java.io.FileInputStream
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
13 import java.io.FileOutputStream
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
14 import java.io.IOException
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
15 import java.util.logging.Level
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
16 import java.util.logging.Logger
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
17 import javax.swing.*
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
18 import javax.swing.table.DefaultTableModel
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
19 import javax.swing.table.TableColumn
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
20 import javax.swing.table.TableColumnModel
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
21
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
22 import name.blackcap.exifwasher.exiv2.*
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
23
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
24 class WashDialog : JDialog(Application.mainFrame) {
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
25 private val BW = 9
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
26 private val BW2 = BW * 2
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
27 private val WIDTH = 640
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
28 private val HEIGHT = 480
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
29
7
65d14d44bc3f Works, but the column layout numbers are WEIRD.
David Barts <n5jrn@me.com>
parents: 5
diff changeset
30 private val COLUMN_NAMES = arrayOf<String>("Delete?", "Key", "Type", "Value")
19
39b977021ea1 Tool tips in case key and type cols truncate.
David Barts <n5jrn@me.com>
parents: 18
diff changeset
31 private val myTable = JExifTable(arrayOf<Array<out Any?>>(), COLUMN_NAMES).apply {
3
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
32 autoCreateRowSorter = false
9
0a106e9b91b4 Fix table layout; fix "select all for deletion" feature.
David Barts <n5jrn@me.com>
parents: 8
diff changeset
33 border = BorderFactory.createLineBorder(Color.GRAY)
0a106e9b91b4 Fix table layout; fix "select all for deletion" feature.
David Barts <n5jrn@me.com>
parents: 8
diff changeset
34 gridColor = Color.GRAY
3
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
35 rowSorter = null
9
0a106e9b91b4 Fix table layout; fix "select all for deletion" feature.
David Barts <n5jrn@me.com>
parents: 8
diff changeset
36 setShowGrid(true)
3
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
37 }
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
38
9
0a106e9b91b4 Fix table layout; fix "select all for deletion" feature.
David Barts <n5jrn@me.com>
parents: 8
diff changeset
39 val impliedDeletions = mutableSetOf<String>()
0a106e9b91b4 Fix table layout; fix "select all for deletion" feature.
David Barts <n5jrn@me.com>
parents: 8
diff changeset
40 private val selectAll = JCheckBox("Select all for deletion", false).also {
0a106e9b91b4 Fix table layout; fix "select all for deletion" feature.
David Barts <n5jrn@me.com>
parents: 8
diff changeset
41 it.addActionListener(ActionListener { _ ->
0a106e9b91b4 Fix table layout; fix "select all for deletion" feature.
David Barts <n5jrn@me.com>
parents: 8
diff changeset
42 val limit = myTable.rowCount - 1
0a106e9b91b4 Fix table layout; fix "select all for deletion" feature.
David Barts <n5jrn@me.com>
parents: 8
diff changeset
43 if (it.isSelected()) {
0a106e9b91b4 Fix table layout; fix "select all for deletion" feature.
David Barts <n5jrn@me.com>
parents: 8
diff changeset
44 impliedDeletions.clear()
0a106e9b91b4 Fix table layout; fix "select all for deletion" feature.
David Barts <n5jrn@me.com>
parents: 8
diff changeset
45 for (i in 0 .. limit) {
0a106e9b91b4 Fix table layout; fix "select all for deletion" feature.
David Barts <n5jrn@me.com>
parents: 8
diff changeset
46 if(!(myTable.getValueAt(i, 0) as Boolean)) {
0a106e9b91b4 Fix table layout; fix "select all for deletion" feature.
David Barts <n5jrn@me.com>
parents: 8
diff changeset
47 impliedDeletions.add(myTable.getValueAt(i, 1) as String)
0a106e9b91b4 Fix table layout; fix "select all for deletion" feature.
David Barts <n5jrn@me.com>
parents: 8
diff changeset
48 myTable.setValueAt(true, i, 0)
0a106e9b91b4 Fix table layout; fix "select all for deletion" feature.
David Barts <n5jrn@me.com>
parents: 8
diff changeset
49 }
0a106e9b91b4 Fix table layout; fix "select all for deletion" feature.
David Barts <n5jrn@me.com>
parents: 8
diff changeset
50 }
0a106e9b91b4 Fix table layout; fix "select all for deletion" feature.
David Barts <n5jrn@me.com>
parents: 8
diff changeset
51 } else {
0a106e9b91b4 Fix table layout; fix "select all for deletion" feature.
David Barts <n5jrn@me.com>
parents: 8
diff changeset
52 for (i in 0 .. limit) {
0a106e9b91b4 Fix table layout; fix "select all for deletion" feature.
David Barts <n5jrn@me.com>
parents: 8
diff changeset
53 if (impliedDeletions.contains(myTable.getValueAt(i, 1) as String)) {
0a106e9b91b4 Fix table layout; fix "select all for deletion" feature.
David Barts <n5jrn@me.com>
parents: 8
diff changeset
54 myTable.setValueAt(false, i, 0)
0a106e9b91b4 Fix table layout; fix "select all for deletion" feature.
David Barts <n5jrn@me.com>
parents: 8
diff changeset
55 }
0a106e9b91b4 Fix table layout; fix "select all for deletion" feature.
David Barts <n5jrn@me.com>
parents: 8
diff changeset
56 }
0a106e9b91b4 Fix table layout; fix "select all for deletion" feature.
David Barts <n5jrn@me.com>
parents: 8
diff changeset
57 }
0a106e9b91b4 Fix table layout; fix "select all for deletion" feature.
David Barts <n5jrn@me.com>
parents: 8
diff changeset
58 })
0a106e9b91b4 Fix table layout; fix "select all for deletion" feature.
David Barts <n5jrn@me.com>
parents: 8
diff changeset
59 }
3
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
60
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
61 private val resetButton = JButton("Reset").also {
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
62 it.addActionListener(ActionListener { doReset() })
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
63 }
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
64
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
65 private val cancelButton = JButton("Cancel").also {
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
66 it.addActionListener(ActionListener { close() })
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
67 }
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
68
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
69 /* deliberately not the default action, because it changes a file */
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
70 private val washButton = JButton("Wash").also {
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
71 it.addActionListener(ActionListener { doWash() })
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
72 }
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
73
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
74 private lateinit var washing: File
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
75
18
841f711c40bd Add new dialogs, and make NO the default for dangerous YES answers.
David Barts <n5jrn@me.com>
parents: 11
diff changeset
76 /* a yes/no dialog in which NO is the default */
841f711c40bd Add new dialogs, and make NO the default for dangerous YES answers.
David Barts <n5jrn@me.com>
parents: 11
diff changeset
77 private fun noYesDialog(parent: Component, message: String, title: String): Int {
841f711c40bd Add new dialogs, and make NO the default for dangerous YES answers.
David Barts <n5jrn@me.com>
parents: 11
diff changeset
78 val options = arrayOf<String>("No", "Yes")
841f711c40bd Add new dialogs, and make NO the default for dangerous YES answers.
David Barts <n5jrn@me.com>
parents: 11
diff changeset
79 val status = JOptionPane.showOptionDialog(parent, message, title,
841f711c40bd Add new dialogs, and make NO the default for dangerous YES answers.
David Barts <n5jrn@me.com>
parents: 11
diff changeset
80 JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE,
841f711c40bd Add new dialogs, and make NO the default for dangerous YES answers.
David Barts <n5jrn@me.com>
parents: 11
diff changeset
81 null, options, options[0])
841f711c40bd Add new dialogs, and make NO the default for dangerous YES answers.
David Barts <n5jrn@me.com>
parents: 11
diff changeset
82 return if (status == 1) JOptionPane.YES_OPTION else JOptionPane.NO_OPTION
841f711c40bd Add new dialogs, and make NO the default for dangerous YES answers.
David Barts <n5jrn@me.com>
parents: 11
diff changeset
83 }
841f711c40bd Add new dialogs, and make NO the default for dangerous YES answers.
David Barts <n5jrn@me.com>
parents: 11
diff changeset
84
3
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
85 /* initiates the washing of the Exif data */
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
86 fun wash(dirty: File) {
5
dc1f4359659d Got it compiling.
David Barts <n5jrn@me.com>
parents: 3
diff changeset
87 title = "Washing: ${dirty.name}"
18
841f711c40bd Add new dialogs, and make NO the default for dangerous YES answers.
David Barts <n5jrn@me.com>
parents: 11
diff changeset
88
841f711c40bd Add new dialogs, and make NO the default for dangerous YES answers.
David Barts <n5jrn@me.com>
parents: 11
diff changeset
89 /* warn (and allow user to back out) if not a JPEG */
841f711c40bd Add new dialogs, and make NO the default for dangerous YES answers.
David Barts <n5jrn@me.com>
parents: 11
diff changeset
90 val lcext = splitext(dirty.name).second.toLowerCase()
841f711c40bd Add new dialogs, and make NO the default for dangerous YES answers.
David Barts <n5jrn@me.com>
parents: 11
diff changeset
91 if (lcext != ".jpg" && lcext != ".jpeg") {
841f711c40bd Add new dialogs, and make NO the default for dangerous YES answers.
David Barts <n5jrn@me.com>
parents: 11
diff changeset
92 val answer = noYesDialog(Application.mainFrame,
841f711c40bd Add new dialogs, and make NO the default for dangerous YES answers.
David Barts <n5jrn@me.com>
parents: 11
diff changeset
93 "File ${dirty.name} does not appear to be a JPEG image.\n"+
841f711c40bd Add new dialogs, and make NO the default for dangerous YES answers.
David Barts <n5jrn@me.com>
parents: 11
diff changeset
94 "Washing non-JPEG images may damage them. Proceed anyway?",
841f711c40bd Add new dialogs, and make NO the default for dangerous YES answers.
David Barts <n5jrn@me.com>
parents: 11
diff changeset
95 "Non-JPEG file detected")
841f711c40bd Add new dialogs, and make NO the default for dangerous YES answers.
David Barts <n5jrn@me.com>
parents: 11
diff changeset
96 if (answer != JOptionPane.YES_OPTION) {
841f711c40bd Add new dialogs, and make NO the default for dangerous YES answers.
David Barts <n5jrn@me.com>
parents: 11
diff changeset
97 close()
841f711c40bd Add new dialogs, and make NO the default for dangerous YES answers.
David Barts <n5jrn@me.com>
parents: 11
diff changeset
98 return
841f711c40bd Add new dialogs, and make NO the default for dangerous YES answers.
David Barts <n5jrn@me.com>
parents: 11
diff changeset
99 }
841f711c40bd Add new dialogs, and make NO the default for dangerous YES answers.
David Barts <n5jrn@me.com>
parents: 11
diff changeset
100 }
841f711c40bd Add new dialogs, and make NO the default for dangerous YES answers.
David Barts <n5jrn@me.com>
parents: 11
diff changeset
101
3
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
102 selectAll.setSelected(false)
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
103 washing = dirty
24
3d9c36307704 Should make the wait cursor appear, but doesn't. Java bug?
davidb
parents: 19
diff changeset
104 Application.mainFrame.useWaitCursor()
3
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
105 swingWorker<Array<Array<Any>>?> {
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
106 inBackground {
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
107 try {
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
108 val image = Image(dirty.canonicalPath)
5
dc1f4359659d Got it compiling.
David Barts <n5jrn@me.com>
parents: 3
diff changeset
109 val meta = image.metadata
3
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
110 val keys = meta.keys
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
111 keys.sort()
5
dc1f4359659d Got it compiling.
David Barts <n5jrn@me.com>
parents: 3
diff changeset
112 Array<Array<Any>>(keys.size) {
3
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
113 val key = keys[it]
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
114 val value = meta[key]
5
dc1f4359659d Got it compiling.
David Barts <n5jrn@me.com>
parents: 3
diff changeset
115 arrayOf(
dc1f4359659d Got it compiling.
David Barts <n5jrn@me.com>
parents: 3
diff changeset
116 !Application.settingsDialog.whitelist.contains(key),
dc1f4359659d Got it compiling.
David Barts <n5jrn@me.com>
parents: 3
diff changeset
117 key, value.type, value.value)
3
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
118 }
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
119 } catch (e: Exiv2Exception) {
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
120 LOGGER.log(Level.SEVERE, "unable to read metadata", e)
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
121 null
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
122 }
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
123 }
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
124 whenDone {
24
3d9c36307704 Should make the wait cursor appear, but doesn't. Java bug?
davidb
parents: 19
diff changeset
125 Application.mainFrame.useNormalCursor()
3
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
126 val tableData = get()
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
127 if (tableData == null) {
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
128 JOptionPane.showMessageDialog(Application.mainFrame,
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
129 "Unable to read metadata.",
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
130 "Error", JOptionPane.ERROR_MESSAGE)
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
131 } else {
7
65d14d44bc3f Works, but the column layout numbers are WEIRD.
David Barts <n5jrn@me.com>
parents: 5
diff changeset
132 myTable.run {
65d14d44bc3f Works, but the column layout numbers are WEIRD.
David Barts <n5jrn@me.com>
parents: 5
diff changeset
133 model = MyTableModel(tableData, COLUMN_NAMES)
8
88d02fa97d78 Got WasherDialog table laying out somewhat sanely.
David Barts <n5jrn@me.com>
parents: 7
diff changeset
134 autoResizeMode = JTable.AUTO_RESIZE_OFF
88d02fa97d78 Got WasherDialog table laying out somewhat sanely.
David Barts <n5jrn@me.com>
parents: 7
diff changeset
135 setColWidth(0, 0, COLUMN_NAMES[0])
88d02fa97d78 Got WasherDialog table laying out somewhat sanely.
David Barts <n5jrn@me.com>
parents: 7
diff changeset
136 setColWidth(1, 180, null)
88d02fa97d78 Got WasherDialog table laying out somewhat sanely.
David Barts <n5jrn@me.com>
parents: 7
diff changeset
137 setColWidth(2, 72, "Undefined")
88d02fa97d78 Got WasherDialog table laying out somewhat sanely.
David Barts <n5jrn@me.com>
parents: 7
diff changeset
138 setColWidth(3, 720, null)
88d02fa97d78 Got WasherDialog table laying out somewhat sanely.
David Barts <n5jrn@me.com>
parents: 7
diff changeset
139 setOverallWidth()
3
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
140 }
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
141 setVisible(true)
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
142 }
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
143 }
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
144 }
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
145 }
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
146
5
dc1f4359659d Got it compiling.
David Barts <n5jrn@me.com>
parents: 3
diff changeset
147 private class MyTableModel(tData: Array<Array<Any>>, cNames: Array<String>) : DefaultTableModel(tData, cNames) {
3
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
148 override fun isCellEditable(row: Int, col: Int) = col == 0
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
149 override fun getColumnClass(col: Int) = if (col == 0) {
7
65d14d44bc3f Works, but the column layout numbers are WEIRD.
David Barts <n5jrn@me.com>
parents: 5
diff changeset
150 java.lang.Boolean::class.java
3
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
151 } else {
7
65d14d44bc3f Works, but the column layout numbers are WEIRD.
David Barts <n5jrn@me.com>
parents: 5
diff changeset
152 java.lang.String::class.java
3
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
153 }
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
154 }
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
155
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
156 private fun doReset() {
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
157 myTable.model.run {
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
158 for (i in 0 .. rowCount - 1) {
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
159 val key = getValueAt(i, 1) as String
5
dc1f4359659d Got it compiling.
David Barts <n5jrn@me.com>
parents: 3
diff changeset
160 setValueAt(!Application.settingsDialog.whitelist.contains(key), i, 0)
3
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
161 }
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
162 }
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
163 myTable.validate()
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
164 }
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
165
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
166 private fun doWash() {
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
167 setVisible(false)
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
168
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
169 /* get path to the directory we create */
5
dc1f4359659d Got it compiling.
David Barts <n5jrn@me.com>
parents: 3
diff changeset
170 val outDir = if (Application.settingsDialog.outputToInputDir) {
3
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
171 washing.canonicalFile.parent
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
172 } else {
5
dc1f4359659d Got it compiling.
David Barts <n5jrn@me.com>
parents: 3
diff changeset
173 Application.settingsDialog.outputTo
3
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
174 }
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
175
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
176 /* get new file name */
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
177 val (name, ext) = splitext(washing.name)
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
178 var newFile = File(outDir, "${name}_washed${ext}")
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
179
11
e52fd1a575de Add Mac icons.
David Barts <n5jrn@me.com>
parents: 9
diff changeset
180 /* warn (and allow user to back out) if overwriting */
e52fd1a575de Add Mac icons.
David Barts <n5jrn@me.com>
parents: 9
diff changeset
181 if (newFile.exists()) {
18
841f711c40bd Add new dialogs, and make NO the default for dangerous YES answers.
David Barts <n5jrn@me.com>
parents: 11
diff changeset
182 val answer = noYesDialog(Application.mainFrame,
11
e52fd1a575de Add Mac icons.
David Barts <n5jrn@me.com>
parents: 9
diff changeset
183 "File ${newFile.name} already exists. Overwrite?",
18
841f711c40bd Add new dialogs, and make NO the default for dangerous YES answers.
David Barts <n5jrn@me.com>
parents: 11
diff changeset
184 "Confirm overwriting file")
11
e52fd1a575de Add Mac icons.
David Barts <n5jrn@me.com>
parents: 9
diff changeset
185 if (answer != JOptionPane.YES_OPTION) {
e52fd1a575de Add Mac icons.
David Barts <n5jrn@me.com>
parents: 9
diff changeset
186 close()
e52fd1a575de Add Mac icons.
David Barts <n5jrn@me.com>
parents: 9
diff changeset
187 return
e52fd1a575de Add Mac icons.
David Barts <n5jrn@me.com>
parents: 9
diff changeset
188 }
e52fd1a575de Add Mac icons.
David Barts <n5jrn@me.com>
parents: 9
diff changeset
189 }
e52fd1a575de Add Mac icons.
David Barts <n5jrn@me.com>
parents: 9
diff changeset
190
3
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
191 /* copy the file, then edit the Exif in the copy */
24
3d9c36307704 Should make the wait cursor appear, but doesn't. Java bug?
davidb
parents: 19
diff changeset
192 Application.mainFrame.useWaitCursor()
3
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
193 swingWorker<Boolean> {
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
194 inBackground {
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
195 try {
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
196 FileInputStream(washing).use { source ->
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
197 FileOutputStream(newFile).use { target ->
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
198 source.copyTo(target)
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
199 }
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
200 }
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
201 val image = Image(newFile.canonicalPath)
5
dc1f4359659d Got it compiling.
David Barts <n5jrn@me.com>
parents: 3
diff changeset
202 val meta = image.metadata
3
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
203 meta.keys.forEach {
5
dc1f4359659d Got it compiling.
David Barts <n5jrn@me.com>
parents: 3
diff changeset
204 if (!Application.settingsDialog.whitelist.contains(it)) {
3
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
205 meta.erase(it)
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
206 }
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
207 }
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
208 image.store()
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
209 true
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
210 } catch (e: IOException) {
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
211 LOGGER.log(Level.SEVERE, "unable to copy input", e)
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
212 false
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
213 } catch (e: Exiv2Exception) {
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
214 LOGGER.log(Level.SEVERE, "unable to edit metadata", e)
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
215 false
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
216 }
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
217 }
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
218 whenDone {
24
3d9c36307704 Should make the wait cursor appear, but doesn't. Java bug?
davidb
parents: 19
diff changeset
219 Application.mainFrame.useNormalCursor()
3
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
220 close()
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
221 /* if all went well, show the Exif in the new file */
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
222 if (get()) {
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
223 ShowDialog().show(newFile)
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
224 } else {
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
225 try {
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
226 if (newFile.exists()) { newFile.delete() }
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
227 } catch (e: IOException) {
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
228 LOGGER.log(Level.SEVERE, "unable to delete", e)
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
229 }
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
230 JOptionPane.showMessageDialog(Application.mainFrame,
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
231 "Error\nUnable to wash: ${washing.canonicalPath}\nTo: ${newFile.canonicalPath}",
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
232 "Error", JOptionPane.ERROR_MESSAGE)
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
233 }
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
234 }
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
235 }
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
236 }
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
237
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
238 private fun splitext(s: String): Pair<String, String> {
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
239 val pos = s.lastIndexOf('.')
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
240 if (pos == -1) {
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
241 return Pair(s, "")
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
242 }
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
243 return Pair(s.substring(0, pos), s.substring(pos))
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
244 }
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
245
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
246 init {
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
247 defaultCloseOperation = JDialog.DISPOSE_ON_CLOSE /* delete if reusing */
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
248 title = "Untitled"
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
249 contentPane.apply {
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
250 layout = BoxLayout(this, BoxLayout.Y_AXIS)
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
251 add(Box(BoxLayout.Y_AXIS).apply {
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
252 alignmentX = Box.CENTER_ALIGNMENT
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
253 border = BorderFactory.createEmptyBorder(BW, BW, BW, BW)
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
254 add(JScrollPane(myTable).apply {
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
255 alignmentX = JScrollPane.LEFT_ALIGNMENT
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
256 border = BorderFactory.createEmptyBorder(BW, BW, BW, BW)
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
257 verticalScrollBarPolicy = ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS
8
88d02fa97d78 Got WasherDialog table laying out somewhat sanely.
David Barts <n5jrn@me.com>
parents: 7
diff changeset
258 horizontalScrollBarPolicy = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS
3
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
259 preferredSize = Dimension(WIDTH, HEIGHT)
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
260 background = Application.mainFrame.background
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
261 })
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
262 add(selectAll.apply {
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
263 alignmentX = JCheckBox.LEFT_ALIGNMENT
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
264 border = BorderFactory.createEmptyBorder(BW, BW, 0, BW)
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
265 })
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
266 })
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
267 add(Box(BoxLayout.X_AXIS).apply {
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
268 alignmentX = Box.CENTER_ALIGNMENT
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
269 border = BorderFactory.createEmptyBorder(BW, BW, BW2, BW)
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
270 add(resetButton)
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
271 add(Box.createHorizontalGlue())
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
272 add(cancelButton)
8
88d02fa97d78 Got WasherDialog table laying out somewhat sanely.
David Barts <n5jrn@me.com>
parents: 7
diff changeset
273 add(Box.createHorizontalStrut(BW2))
3
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
274 add(washButton)
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
275 })
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
276 }
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
277 pack()
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
278 }
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
279 }