comparison src/name/blackcap/exifwasher/WashDialog.kt @ 5:dc1f4359659d

Got it compiling.
author David Barts <n5jrn@me.com>
date Thu, 09 Apr 2020 18:20:34 -0700
parents 19c381c536ec
children 65d14d44bc3f
comparison
equal deleted inserted replaced
4:ba5dc14652da 5:dc1f4359659d
1 /* 1 /*
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.Dimension
6 import java.awt.event.ActionEvent 7 import java.awt.event.ActionEvent
7 import java.awt.event.ActionListener 8 import java.awt.event.ActionListener
8 import java.io.File 9 import java.io.File
9 import java.io.FileInputStream 10 import java.io.FileInputStream
10 import java.io.FileOutputStream 11 import java.io.FileOutputStream
55 56
56 private lateinit var washing: File 57 private lateinit var washing: File
57 58
58 /* initiates the washing of the Exif data */ 59 /* initiates the washing of the Exif data */
59 fun wash(dirty: File) { 60 fun wash(dirty: File) {
60 title = "Washing: ${image.name}" 61 title = "Washing: ${dirty.name}"
61 selectAll.setSelected(false) 62 selectAll.setSelected(false)
62 washing = dirty 63 washing = dirty
63 useWaitCursor() 64 useWaitCursor()
64 swingWorker<Array<Array<Any>>?> { 65 swingWorker<Array<Array<Any>>?> {
65 inBackground { 66 inBackground {
66 try { 67 try {
67 val image = Image(dirty.canonicalPath) 68 val image = Image(dirty.canonicalPath)
68 val meta = image.meta 69 val meta = image.metadata
69 val keys = meta.keys 70 val keys = meta.keys
70 keys.sort() 71 keys.sort()
71 Array<Array<String>>(keys.size) { 72 Array<Array<Any>>(keys.size) {
72 val key = keys[it] 73 val key = keys[it]
73 val value = meta[key] 74 val value = meta[key]
74 arrayOf(!settingsDialog.whitelist.contains(key), key, value.type, value.value) 75 arrayOf(
76 !Application.settingsDialog.whitelist.contains(key),
77 key, value.type, value.value)
75 } 78 }
76 } catch (e: Exiv2Exception) { 79 } catch (e: Exiv2Exception) {
77 LOGGER.log(Level.SEVERE, "unable to read metadata", e) 80 LOGGER.log(Level.SEVERE, "unable to read metadata", e)
78 null 81 null
79 } 82 }
95 } 98 }
96 } 99 }
97 } 100 }
98 } 101 }
99 102
100 private class MyTableModel : DefaultTableModel { 103 private class MyTableModel(tData: Array<Array<Any>>, cNames: Array<String>) : DefaultTableModel(tData, cNames) {
101 override fun isCellEditable(row: Int, col: Int) = col == 0 104 override fun isCellEditable(row: Int, col: Int) = col == 0
102 override fun getColumnClass(col: Int) = if (col == 0) { 105 override fun getColumnClass(col: Int) = if (col == 0) {
103 Boolean 106 Boolean::class.java
104 } else { 107 } else {
105 String 108 String::class.java
106 } 109 }
107 } 110 }
108 111
109 private fun doReset() { 112 private fun doReset() {
110 myTable.model.run { 113 myTable.model.run {
111 for (i in 0 .. rowCount - 1) { 114 for (i in 0 .. rowCount - 1) {
112 val key = getValueAt(i, 1) as String 115 val key = getValueAt(i, 1) as String
113 setValueAt(!settingsDialog.whitelist.contains(key), i, 0) 116 setValueAt(!Application.settingsDialog.whitelist.contains(key), i, 0)
114 } 117 }
115 } 118 }
116 myTable.validate() 119 myTable.validate()
117 } 120 }
118 121
119 private fun doWash() { 122 private fun doWash() {
120 setVisible(false) 123 setVisible(false)
121 124
122 /* get path to the directory we create */ 125 /* get path to the directory we create */
123 val outDir = if (settingsDialog.outputToInputDir) { 126 val outDir = if (Application.settingsDialog.outputToInputDir) {
124 washing.canonicalFile.parent 127 washing.canonicalFile.parent
125 } else { 128 } else {
126 settingsDialog.outputTo 129 Application.settingsDialog.outputTo
127 } 130 }
128 131
129 /* get new file name */ 132 /* get new file name */
130 val (name, ext) = splitext(washing.name) 133 val (name, ext) = splitext(washing.name)
131 var newFile = File(outDir, "${name}_washed${ext}") 134 var newFile = File(outDir, "${name}_washed${ext}")
139 FileOutputStream(newFile).use { target -> 142 FileOutputStream(newFile).use { target ->
140 source.copyTo(target) 143 source.copyTo(target)
141 } 144 }
142 } 145 }
143 val image = Image(newFile.canonicalPath) 146 val image = Image(newFile.canonicalPath)
144 val meta = image.meta 147 val meta = image.metadata
145 meta.keys.forEach { 148 meta.keys.forEach {
146 if (!settingsDialog.whitelist.contains(it)) { 149 if (!Application.settingsDialog.whitelist.contains(it)) {
147 meta.erase(it) 150 meta.erase(it)
148 } 151 }
149 } 152 }
150 image.store() 153 image.store()
151 true 154 true