comparison src/name/blackcap/exifwasher/WashDialog.kt @ 7:65d14d44bc3f

Works, but the column layout numbers are WEIRD.
author David Barts <n5jrn@me.com>
date Fri, 10 Apr 2020 13:44:04 -0700
parents dc1f4359659d
children 88d02fa97d78
comparison
equal deleted inserted replaced
6:aafc9c127c7b 7:65d14d44bc3f
23 private val BW = 9 23 private val BW = 9
24 private val BW2 = BW * 2 24 private val BW2 = BW * 2
25 private val WIDTH = 640 25 private val WIDTH = 640
26 private val HEIGHT = 480 26 private val HEIGHT = 480
27 27
28 private val myTable = JTable().apply { 28 private val COLUMN_NAMES = arrayOf<String>("Delete?", "Key", "Type", "Value")
29 private val myTable = JTable(arrayOf<Array<Any>>(), COLUMN_NAMES).apply {
29 autoCreateRowSorter = false 30 autoCreateRowSorter = false
30 rowSorter = null 31 rowSorter = null
31 columnModel.run {
32 getColumn(0).preferredWidth = 10 /* checkbox */
33 getColumn(1).preferredWidth = 25 /* key name */
34 getColumn(2).preferredWidth = 15 /* type */
35 getColumn(3).preferredWidth = 100 /* value */
36 }
37 } 32 }
38 33
39 private val selectAll = JCheckBox("Select all for deletion", false) 34 private val selectAll = JCheckBox("Select all for deletion", false)
40 35
41 private val resetButton = JButton("Reset").also { 36 private val resetButton = JButton("Reset").also {
42 it.addActionListener(ActionListener { doReset() }) 37 it.addActionListener(ActionListener { doReset() })
43 it.border = BorderFactory.createEmptyBorder(0, BW, 0, BW)
44 } 38 }
45 39
46 private val cancelButton = JButton("Cancel").also { 40 private val cancelButton = JButton("Cancel").also {
47 it.addActionListener(ActionListener { close() }) 41 it.addActionListener(ActionListener { close() })
48 it.border = BorderFactory.createEmptyBorder(0, BW, 0, BW)
49 } 42 }
50 43
51 /* deliberately not the default action, because it changes a file */ 44 /* deliberately not the default action, because it changes a file */
52 private val washButton = JButton("Wash").also { 45 private val washButton = JButton("Wash").also {
53 it.addActionListener(ActionListener { doWash() }) 46 it.addActionListener(ActionListener { doWash() })
54 it.border = BorderFactory.createEmptyBorder(0, BW, 0, BW)
55 } 47 }
56 48
57 private lateinit var washing: File 49 private lateinit var washing: File
58 50
59 /* initiates the washing of the Exif data */ 51 /* initiates the washing of the Exif data */
87 if (tableData == null) { 79 if (tableData == null) {
88 JOptionPane.showMessageDialog(Application.mainFrame, 80 JOptionPane.showMessageDialog(Application.mainFrame,
89 "Unable to read metadata.", 81 "Unable to read metadata.",
90 "Error", JOptionPane.ERROR_MESSAGE) 82 "Error", JOptionPane.ERROR_MESSAGE)
91 } else { 83 } else {
92 val colNames = arrayOf("Delete?", "Key", "Type", "Value") 84 myTable.run {
93 myTable.apply { 85 model = MyTableModel(tableData, COLUMN_NAMES)
94 model = MyTableModel(tableData, colNames) 86 columnModel.run {
95 validate() 87 getColumn(0).run {
88 preferredWidth = 10
89 maxWidth = 850000000 /* xxx - don't ask */
90 }
91 getColumn(1).preferredWidth = 100 /* key name */
92 getColumn(2).preferredWidth = 5 /* type */
93 getColumn(3).preferredWidth = 200 /* value */
94 }
95 autoResizeMode = JTable.AUTO_RESIZE_LAST_COLUMN
96 } 96 }
97 setVisible(true) 97 setVisible(true)
98 } 98 }
99 } 99 }
100 } 100 }
101 } 101 }
102 102
103 private class MyTableModel(tData: Array<Array<Any>>, cNames: Array<String>) : DefaultTableModel(tData, cNames) { 103 private class MyTableModel(tData: Array<Array<Any>>, cNames: Array<String>) : DefaultTableModel(tData, cNames) {
104 override fun isCellEditable(row: Int, col: Int) = col == 0 104 override fun isCellEditable(row: Int, col: Int) = col == 0
105 override fun getColumnClass(col: Int) = if (col == 0) { 105 override fun getColumnClass(col: Int) = if (col == 0) {
106 Boolean::class.java 106 java.lang.Boolean::class.java
107 } else { 107 } else {
108 String::class.java 108 java.lang.String::class.java
109 } 109 }
110 } 110 }
111 111
112 private fun doReset() { 112 private fun doReset() {
113 myTable.model.run { 113 myTable.model.run {