Mercurial > cgi-bin > hgweb.cgi > JpegWasher
annotate src/name/blackcap/exifwasher/Misc.kt @ 19:39b977021ea1
Tool tips in case key and type cols truncate.
author | David Barts <n5jrn@me.com> |
---|---|
date | Sat, 11 Apr 2020 16:12:59 -0700 |
parents | 0a106e9b91b4 |
children | 965435b85a69 |
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 * Miscellaneous utility stuff. |
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 |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
6 import java.awt.Component |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
7 import java.awt.Cursor |
8
88d02fa97d78
Got WasherDialog table laying out somewhat sanely.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
8 import java.awt.Dimension |
88d02fa97d78
Got WasherDialog table laying out somewhat sanely.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
9 import java.awt.Font |
88d02fa97d78
Got WasherDialog table laying out somewhat sanely.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
10 import java.awt.FontMetrics |
88d02fa97d78
Got WasherDialog table laying out somewhat sanely.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
11 import java.awt.Graphics |
19
39b977021ea1
Tool tips in case key and type cols truncate.
David Barts <n5jrn@me.com>
parents:
9
diff
changeset
|
12 import java.awt.Point |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
13 import java.awt.Toolkit |
19
39b977021ea1
Tool tips in case key and type cols truncate.
David Barts <n5jrn@me.com>
parents:
9
diff
changeset
|
14 import java.awt.event.MouseEvent |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
15 import javax.swing.* |
8
88d02fa97d78
Got WasherDialog table laying out somewhat sanely.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
16 import javax.swing.table.TableColumnModel |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
17 import kotlin.annotation.* |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
18 import kotlin.properties.ReadWriteProperty |
5 | 19 import kotlin.reflect.* |
3
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 /** |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
22 * Delegate that makes a var that can only be set once. This is commonly |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
23 * needed in Swing, because some vars inevitably need to be declared at |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
24 * outer levels but initialized in the Swing event dispatch thread. |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
25 */ |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
26 class SetOnce<T: Any>: ReadWriteProperty<Any?,T> { |
5 | 27 private var setOnceValue: T? = null |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
28 |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
29 override operator fun getValue(thisRef: Any?, property: KProperty<*>): T { |
5 | 30 if (setOnceValue == null) { |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
31 throw RuntimeException("${property.name} has not been initialized") |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
32 } else { |
5 | 33 return setOnceValue!! |
3
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 @Synchronized |
5 | 38 override operator fun setValue(thisRef: Any?, property: KProperty<*>, value: T): Unit { |
39 if (setOnceValue != null) { | |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
40 throw RuntimeException("${property.name} has already been initialized") |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
41 } |
5 | 42 setOnceValue = value |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
43 } |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
44 } |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
45 |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
46 /** |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
47 * Run something in the Swing thread, asynchronously. |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
48 * @param block lambda containing code to run |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
49 */ |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
50 fun inSwingThread(block: () -> Unit) { |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
51 SwingUtilities.invokeLater(Runnable(block)) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
52 } |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
53 |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
54 /** |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
55 * Run something in the Swing thread, synchronously. |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
56 * @param block lambda containing code to run |
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 fun inSynSwingThread(block: () -> Unit) { |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
59 SwingUtilities.invokeAndWait(Runnable(block)) |
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 |
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 * Make a shortcut for a menu item, using the standard combining key |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
64 * (control, command, etc.) for the system we're on. |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
65 * @param key KeyEvent constant describing the key |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
66 */ |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
67 fun JMenuItem.makeShortcut(key: Int): Unit { |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
68 val SC_KEY_MASK = Toolkit.getDefaultToolkit().menuShortcutKeyMask |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
69 setAccelerator(KeyStroke.getKeyStroke(key, SC_KEY_MASK)) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
70 } |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
71 |
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 * Given a MenuElement object, get the item whose text matches the |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
74 * specified text. |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
75 * @param text to match |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
76 * @return first matched element, null if no match found |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
77 */ |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
78 fun MenuElement.getItem(name: String) : JMenuItem? { |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
79 subElements.forEach { |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
80 val jMenuItem = it.component as? JMenuItem |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
81 if (jMenuItem?.text == name) { |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
82 return jMenuItem |
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 } |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
85 return null |
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 /** |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
89 * Change to the standard wait cursor. |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
90 */ |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
91 fun Component.useWaitCursor() { |
5 | 92 this.cursor = Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR) |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
93 } |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
94 |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
95 /** |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
96 * Return back to the normal cursor(). |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
97 */ |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
98 fun Component.useNormalCursor() { |
5 | 99 this.cursor = Cursor.getDefaultCursor() |
3
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 |
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 * Thrown if the programmer botches something in our DSL. |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
104 */ |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
105 class SwingWorkerException(message: String): Exception(message) { } |
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 * A simplified SwingWorker DSL. It does not support intermediate |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
109 * results. Just lets one define a background task and something |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
110 * to execute when complete. |
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 * @param T Type returned by inBackground (Java doInBackground) task. |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
113 */ |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
114 class SwingWorkerBuilder<T>: SwingWorker<T,Unit>() { |
5 | 115 private var inBackgroundLambda: (SwingWorkerBuilder<T>.() -> T)? = null |
116 private var whenDoneLambda: (SwingWorkerBuilder<T>.() -> Unit)? = null | |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
117 |
5 | 118 private fun <U> setOnce(prop: KMutableProperty0<(SwingWorkerBuilder<T>.() -> U)?>, value: SwingWorkerBuilder<T>.() -> U) { |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
119 if (prop.get() != null) { |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
120 throw SwingWorkerException(prop.name.removeSuffix("Lambda") + " already defined!") |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
121 } |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
122 prop.set(value) |
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 |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
125 /** |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
126 * Define the inBackground task. |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
127 */ |
5 | 128 fun inBackground(lambda: SwingWorkerBuilder<T>.() -> T): Unit { |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
129 setOnce<T>(::inBackgroundLambda, lambda) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
130 } |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
131 |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
132 /** |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
133 * Define the whenDone task. |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
134 */ |
5 | 135 fun whenDone(lambda: SwingWorkerBuilder<T>.() -> Unit): Unit { |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
136 setOnce<Unit>(::whenDoneLambda, lambda) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
137 } |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
138 |
5 | 139 /** |
140 * Validates we've been properly initialized. | |
141 */ | |
142 fun validate(): Unit { | |
143 if (inBackgroundLambda == null) { | |
144 throw SwingWorkerException("inBackground not defined!") | |
145 } | |
146 } | |
147 | |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
148 /* standard overrides for SwingWorker follow */ |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
149 |
5 | 150 override fun doInBackground(): T = inBackgroundLambda!!.invoke(this) |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
151 |
5 | 152 override fun done(): Unit = whenDoneLambda?.invoke(this) ?: Unit |
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 * Provides for an outer swingWorker block to contain the DSL. |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
157 */ |
5 | 158 fun <T> swingWorker(initializer: SwingWorkerBuilder<T>.() -> Unit): Unit { |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
159 SwingWorkerBuilder<T>().run { |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
160 initializer() |
5 | 161 validate() |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
162 execute() |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
163 } |
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 /** |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
167 * Close a dialog (don't just hide it). |
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 fun JDialog.close() { |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
170 setVisible(false) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
171 dispose() |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
172 } |
8
88d02fa97d78
Got WasherDialog table laying out somewhat sanely.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
173 |
88d02fa97d78
Got WasherDialog table laying out somewhat sanely.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
174 /** |
88d02fa97d78
Got WasherDialog table laying out somewhat sanely.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
175 * Set column width of a table. |
88d02fa97d78
Got WasherDialog table laying out somewhat sanely.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
176 */ |
88d02fa97d78
Got WasherDialog table laying out somewhat sanely.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
177 fun JTable.setColWidth(col: Int, width: Int, string: String?) { |
88d02fa97d78
Got WasherDialog table laying out somewhat sanely.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
178 val FUZZ = 4 |
88d02fa97d78
Got WasherDialog table laying out somewhat sanely.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
179 columnModel.getColumn(col).preferredWidth = if (string.isNullOrEmpty()) { |
9
0a106e9b91b4
Fix table layout; fix "select all for deletion" feature.
David Barts <n5jrn@me.com>
parents:
8
diff
changeset
|
180 width |
8
88d02fa97d78
Got WasherDialog table laying out somewhat sanely.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
181 } else { |
9
0a106e9b91b4
Fix table layout; fix "select all for deletion" feature.
David Barts <n5jrn@me.com>
parents:
8
diff
changeset
|
182 maxOf(width, graphics.fontMetrics.stringWidth(string) + FUZZ) |
8
88d02fa97d78
Got WasherDialog table laying out somewhat sanely.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
183 } |
88d02fa97d78
Got WasherDialog table laying out somewhat sanely.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
184 } |
88d02fa97d78
Got WasherDialog table laying out somewhat sanely.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
185 |
88d02fa97d78
Got WasherDialog table laying out somewhat sanely.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
186 /** |
88d02fa97d78
Got WasherDialog table laying out somewhat sanely.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
187 * Set overall width of a table. |
88d02fa97d78
Got WasherDialog table laying out somewhat sanely.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
188 */ |
88d02fa97d78
Got WasherDialog table laying out somewhat sanely.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
189 fun JTable.setOverallWidth() { |
88d02fa97d78
Got WasherDialog table laying out somewhat sanely.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
190 val tcm = columnModel |
9
0a106e9b91b4
Fix table layout; fix "select all for deletion" feature.
David Barts <n5jrn@me.com>
parents:
8
diff
changeset
|
191 val limit = tcm.columnCount - 1 |
8
88d02fa97d78
Got WasherDialog table laying out somewhat sanely.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
192 var total = 0 |
9
0a106e9b91b4
Fix table layout; fix "select all for deletion" feature.
David Barts <n5jrn@me.com>
parents:
8
diff
changeset
|
193 for (i in 0 .. limit) { |
8
88d02fa97d78
Got WasherDialog table laying out somewhat sanely.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
194 total += tcm.getColumn(i).preferredWidth |
88d02fa97d78
Got WasherDialog table laying out somewhat sanely.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
195 } |
88d02fa97d78
Got WasherDialog table laying out somewhat sanely.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
196 preferredSize = Dimension(total, preferredSize.height) |
88d02fa97d78
Got WasherDialog table laying out somewhat sanely.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
197 } |
19
39b977021ea1
Tool tips in case key and type cols truncate.
David Barts <n5jrn@me.com>
parents:
9
diff
changeset
|
198 |
39b977021ea1
Tool tips in case key and type cols truncate.
David Barts <n5jrn@me.com>
parents:
9
diff
changeset
|
199 /** |
39b977021ea1
Tool tips in case key and type cols truncate.
David Barts <n5jrn@me.com>
parents:
9
diff
changeset
|
200 * A JTable for displaying metadata. Columns that might get harmfully |
39b977021ea1
Tool tips in case key and type cols truncate.
David Barts <n5jrn@me.com>
parents:
9
diff
changeset
|
201 * truncated have tooltips when truncation happens. |
39b977021ea1
Tool tips in case key and type cols truncate.
David Barts <n5jrn@me.com>
parents:
9
diff
changeset
|
202 */ |
39b977021ea1
Tool tips in case key and type cols truncate.
David Barts <n5jrn@me.com>
parents:
9
diff
changeset
|
203 class JExifTable(rowData: Array<Array<out Any?>>, colNames: Array<out Any?>): JTable(rowData, colNames) { |
39b977021ea1
Tool tips in case key and type cols truncate.
David Barts <n5jrn@me.com>
parents:
9
diff
changeset
|
204 override fun getToolTipText(e: MouseEvent): String? { |
39b977021ea1
Tool tips in case key and type cols truncate.
David Barts <n5jrn@me.com>
parents:
9
diff
changeset
|
205 val pos = e.point |
39b977021ea1
Tool tips in case key and type cols truncate.
David Barts <n5jrn@me.com>
parents:
9
diff
changeset
|
206 val col = columnAtPoint(pos) |
39b977021ea1
Tool tips in case key and type cols truncate.
David Barts <n5jrn@me.com>
parents:
9
diff
changeset
|
207 if (!setOf("Key", "Type").contains(getColumnName(col))) { |
39b977021ea1
Tool tips in case key and type cols truncate.
David Barts <n5jrn@me.com>
parents:
9
diff
changeset
|
208 return null |
39b977021ea1
Tool tips in case key and type cols truncate.
David Barts <n5jrn@me.com>
parents:
9
diff
changeset
|
209 } |
39b977021ea1
Tool tips in case key and type cols truncate.
David Barts <n5jrn@me.com>
parents:
9
diff
changeset
|
210 val contents = getValueAt(rowAtPoint(pos), col) as String? |
39b977021ea1
Tool tips in case key and type cols truncate.
David Barts <n5jrn@me.com>
parents:
9
diff
changeset
|
211 if (contents == null) { |
39b977021ea1
Tool tips in case key and type cols truncate.
David Barts <n5jrn@me.com>
parents:
9
diff
changeset
|
212 return null |
39b977021ea1
Tool tips in case key and type cols truncate.
David Barts <n5jrn@me.com>
parents:
9
diff
changeset
|
213 } |
39b977021ea1
Tool tips in case key and type cols truncate.
David Barts <n5jrn@me.com>
parents:
9
diff
changeset
|
214 val needed = graphics.fontMetrics.stringWidth(contents) |
39b977021ea1
Tool tips in case key and type cols truncate.
David Barts <n5jrn@me.com>
parents:
9
diff
changeset
|
215 val actual = columnModel.getColumn(col).width |
39b977021ea1
Tool tips in case key and type cols truncate.
David Barts <n5jrn@me.com>
parents:
9
diff
changeset
|
216 return if (needed > actual) contents else null |
39b977021ea1
Tool tips in case key and type cols truncate.
David Barts <n5jrn@me.com>
parents:
9
diff
changeset
|
217 } |
39b977021ea1
Tool tips in case key and type cols truncate.
David Barts <n5jrn@me.com>
parents:
9
diff
changeset
|
218 } |
39b977021ea1
Tool tips in case key and type cols truncate.
David Barts <n5jrn@me.com>
parents:
9
diff
changeset
|
219 |