annotate src/name/blackcap/exifwasher/ShowDialog.kt @ 6:aafc9c127c7b

Fix many bugs; get settings (apparently) working.
author David Barts <n5jrn@me.com>
date Thu, 09 Apr 2020 22:29:48 -0700
parents dc1f4359659d
children 65d14d44bc3f
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 displays the Exif data in a single file (display only,
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
3 * no changing). We do this after washing.
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
4 */
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
5 package name.blackcap.exifwasher
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
6
5
dc1f4359659d Got it compiling.
David Barts <n5jrn@me.com>
parents: 3
diff changeset
7 import java.awt.Dimension
3
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
8 import java.awt.event.ActionEvent
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
9 import java.awt.event.ActionListener
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
10 import java.io.File
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
11 import java.io.IOException
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
12 import java.util.logging.Level
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
13 import java.util.logging.Logger
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
14 import javax.swing.*
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
15 import javax.swing.table.DefaultTableModel
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
16 import javax.swing.table.TableColumn
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
17 import javax.swing.table.TableColumnModel
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
18
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
19 import name.blackcap.exifwasher.exiv2.*
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
20
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
21 class ShowDialog : JDialog(Application.mainFrame) {
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
22 private val BW = 9
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
23 private val BW2 = BW * 2
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
24 private val WIDTH = 640
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
25 private val HEIGHT = 480
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
26
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
27 private val myTable = JTable().apply {
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
28 autoCreateRowSorter = false
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
29 rowSorter = null
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
30 columnModel.run {
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
31 getColumn(0).preferredWidth = 25 /* key name */
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
32 getColumn(1).preferredWidth = 15 /* type */
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
33 getColumn(2).preferredWidth = 100 /* value */
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
34 }
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
35 }
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
36
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
37 /* deliberately not the default, because this changes a file */
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
38 private val dismissButton = JButton("Dismiss").also {
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
39 it.addActionListener(ActionListener { close() })
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
40 it.border = BorderFactory.createEmptyBorder(0, BW, 0, BW)
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
41 }
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
42
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
43 /* controls 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
44 fun show(image: File) {
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
45 title = "Washed: ${image.name}"
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
46 useWaitCursor()
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
47 swingWorker<Array<Array<String>>?> {
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
48 inBackground {
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
49 try {
5
dc1f4359659d Got it compiling.
David Barts <n5jrn@me.com>
parents: 3
diff changeset
50 val openedImage = Image(image.absolutePath)
dc1f4359659d Got it compiling.
David Barts <n5jrn@me.com>
parents: 3
diff changeset
51 val meta = openedImage.metadata
3
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
52 val keys = meta.keys
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
53 keys.sort()
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
54 Array<Array<String>>(keys.size) {
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
55 val key = keys[it]
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
56 val value = meta[key]
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
57 arrayOf<String>(key, value.type, value.value)
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
58 }
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
59 } catch (e: Exiv2Exception) {
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
60 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
61 null
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
62 }
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 whenDone {
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
65 useNormalCursor()
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
66 val tableData = get()
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
67 if (tableData == null) {
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
68 JOptionPane.showMessageDialog(Application.mainFrame,
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
69 "Unable to read metadata.",
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
70 "Error", JOptionPane.ERROR_MESSAGE)
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
71 } else {
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
72 val colNames = arrayOf("Key", "Type", "Value")
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
73 myTable.apply {
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
74 model = MyTableModel(tableData, colNames)
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
75 validate()
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
76 }
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
77 setVisible(true)
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
78 }
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
79 }
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
80 }
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
81 }
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
82
5
dc1f4359659d Got it compiling.
David Barts <n5jrn@me.com>
parents: 3
diff changeset
83 private class MyTableModel(tData: Array<Array<String>>, 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
84 override fun isCellEditable(row: Int, col: Int) = false
5
dc1f4359659d Got it compiling.
David Barts <n5jrn@me.com>
parents: 3
diff changeset
85 override fun getColumnClass(col: Int) = String::class.java
3
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
86 }
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
87
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
88 init {
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
89 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
90 title = "Untitled"
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
91 contentPane.apply {
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
92 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
93 add(JScrollPane(myTable).apply {
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
94 alignmentX = JScrollPane.CENTER_ALIGNMENT
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
95 border = BorderFactory.createEmptyBorder(BW2, BW2, BW, BW2)
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
96 verticalScrollBarPolicy = ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
97 horizontalScrollBarPolicy = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
98 preferredSize = Dimension(WIDTH, HEIGHT)
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
99 background = Application.mainFrame.background
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
100 })
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
101 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
102 alignmentX = Box.CENTER_ALIGNMENT
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
103 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
104 add(Box.createHorizontalGlue())
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
105 add(dismissButton)
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
106 })
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
107 }
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
108 pack()
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
109 }
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
110 }