Mercurial > cgi-bin > hgweb.cgi > JpegWasher
annotate src/name/blackcap/exifwasher/ShowDialog.kt @ 10:9bbe6d803eba
Fixed ShowDialog.
author | David Barts <n5jrn@me.com> |
---|---|
date | Fri, 10 Apr 2020 19:29:58 -0700 |
parents | 0a106e9b91b4 |
children | 39b977021ea1 |
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 |
10 | 7 import java.awt.Color |
5 | 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.IOException |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
13 import java.util.logging.Level |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
14 import java.util.logging.Logger |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
15 import javax.swing.* |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
16 import javax.swing.table.DefaultTableModel |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
17 import javax.swing.table.TableColumn |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
18 import javax.swing.table.TableColumnModel |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
19 |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
20 import name.blackcap.exifwasher.exiv2.* |
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 class ShowDialog : JDialog(Application.mainFrame) { |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
23 private val BW = 9 |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
24 private val BW2 = BW * 2 |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
25 private val WIDTH = 640 |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
26 private val HEIGHT = 480 |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
27 |
7
65d14d44bc3f
Works, but the column layout numbers are WEIRD.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
28 private val COLUMN_NAMES = arrayOf<String>("Key", "Type", "Value") |
65d14d44bc3f
Works, but the column layout numbers are WEIRD.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
29 private val myTable = JTable(arrayOf<Array<Any>>(), COLUMN_NAMES).apply { |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
30 autoCreateRowSorter = false |
10 | 31 border = BorderFactory.createLineBorder(Color.GRAY) |
32 gridColor = Color.GRAY | |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
33 rowSorter = null |
10 | 34 setShowGrid(true) |
3
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 } |
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 /* 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
|
43 fun show(image: File) { |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
44 title = "Washed: ${image.name}" |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
45 useWaitCursor() |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
46 swingWorker<Array<Array<String>>?> { |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
47 inBackground { |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
48 try { |
5 | 49 val openedImage = Image(image.absolutePath) |
50 val meta = openedImage.metadata | |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
51 val keys = meta.keys |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
52 keys.sort() |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
53 Array<Array<String>>(keys.size) { |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
54 val key = keys[it] |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
55 val value = meta[key] |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
56 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
|
57 } |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
58 } catch (e: Exiv2Exception) { |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
59 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
|
60 null |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
61 } |
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 whenDone { |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
64 useNormalCursor() |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
65 val tableData = get() |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
66 if (tableData == null) { |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
67 JOptionPane.showMessageDialog(Application.mainFrame, |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
68 "Unable to read metadata.", |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
69 "Error", JOptionPane.ERROR_MESSAGE) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
70 } else { |
9
0a106e9b91b4
Fix table layout; fix "select all for deletion" feature.
David Barts <n5jrn@me.com>
parents:
7
diff
changeset
|
71 myTable.run { |
0a106e9b91b4
Fix table layout; fix "select all for deletion" feature.
David Barts <n5jrn@me.com>
parents:
7
diff
changeset
|
72 model = MyTableModel(tableData, COLUMN_NAMES) |
0a106e9b91b4
Fix table layout; fix "select all for deletion" feature.
David Barts <n5jrn@me.com>
parents:
7
diff
changeset
|
73 autoResizeMode = JTable.AUTO_RESIZE_OFF |
0a106e9b91b4
Fix table layout; fix "select all for deletion" feature.
David Barts <n5jrn@me.com>
parents:
7
diff
changeset
|
74 setColWidth(0, 180, null) |
0a106e9b91b4
Fix table layout; fix "select all for deletion" feature.
David Barts <n5jrn@me.com>
parents:
7
diff
changeset
|
75 setColWidth(1, 72, "Undefined") |
0a106e9b91b4
Fix table layout; fix "select all for deletion" feature.
David Barts <n5jrn@me.com>
parents:
7
diff
changeset
|
76 setColWidth(2, 720, null) |
0a106e9b91b4
Fix table layout; fix "select all for deletion" feature.
David Barts <n5jrn@me.com>
parents:
7
diff
changeset
|
77 setOverallWidth() |
0a106e9b91b4
Fix table layout; fix "select all for deletion" feature.
David Barts <n5jrn@me.com>
parents:
7
diff
changeset
|
78 } |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
79 setVisible(true) |
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 } |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
83 } |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
84 |
5 | 85 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
|
86 override fun isCellEditable(row: Int, col: Int) = false |
7
65d14d44bc3f
Works, but the column layout numbers are WEIRD.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
87 override fun getColumnClass(col: Int) = 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
|
88 } |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
89 |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
90 init { |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
91 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
|
92 title = "Untitled" |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
93 contentPane.apply { |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
94 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
|
95 add(JScrollPane(myTable).apply { |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
96 alignmentX = JScrollPane.CENTER_ALIGNMENT |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
97 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
|
98 verticalScrollBarPolicy = ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
99 horizontalScrollBarPolicy = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
100 preferredSize = Dimension(WIDTH, HEIGHT) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
101 background = Application.mainFrame.background |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
102 }) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
103 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
|
104 alignmentX = Box.CENTER_ALIGNMENT |
10 | 105 border = BorderFactory.createEmptyBorder(BW, BW2, BW2, BW2) |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
106 add(Box.createHorizontalGlue()) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
107 add(dismissButton) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
108 }) |
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 pack() |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
111 } |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
112 } |