annotate src/name/blackcap/imageprep/HelpDialog.kt @ 28:c310ec097194

Add Linux support.
author David Barts <n5jrn@me.com>
date Fri, 25 Dec 2020 19:07:47 -0800
parents 0bded24f746e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
1 /*
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
2 * The dialog that displays the Exif data in a single file (display only,
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
3 * no changing). We do this after washing.
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
4 */
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
5 package name.blackcap.imageprep
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
6
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
7 import java.awt.Dimension
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
8 import java.awt.Font
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
9 import java.awt.event.ActionEvent
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
10 import java.awt.event.ActionListener
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
11 import java.io.BufferedReader
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
12 import java.io.File
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
13 import java.io.IOException
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
14 import java.io.InputStream
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
15 import java.io.InputStreamReader
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
16 import java.util.logging.Level
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
17 import java.util.logging.Logger
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
18 import javax.swing.*
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
19 import javax.swing.text.html.HTMLEditorKit
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
20 import javax.swing.text.html.StyleSheet
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
21 import kotlin.text.buildString
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
22
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
23 class HelpDialog : JDialog(Application.mainFrame) {
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
24 private val BW = 9
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
25 private val BW2 = BW * 2
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
26 private val WIDTH = 640
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
27 private val HEIGHT = 480
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
28
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
29 private val dismissButton = JButton("Dismiss").also {
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
30 it.addActionListener(ActionListener { setVisible(false) })
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
31 }
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
32
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
33 /*
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
34 * The stock HTMLEditorKit shares all style sheet data between all its
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
35 * instances. How unbelievably braindamaged. Correct that.
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
36 */
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
37 private class MyEditorKit: HTMLEditorKit() {
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
38 private var _styleSheet: StyleSheet = defaultStyleSheet
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
39 override fun getStyleSheet() = _styleSheet
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
40 override fun setStyleSheet(value: StyleSheet) {
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
41 _styleSheet = value
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
42 }
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
43
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
44 /**
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
45 * Return the default style sheet that all HTMLEditorKit's come with.
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
46 */
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
47 val defaultStyleSheet: StyleSheet
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
48 get() {
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
49 return super.getStyleSheet()
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
50 }
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
51 }
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
52
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
53 private val helpPane = JScrollPane(JTextPane().also {
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
54 it.editorKit = MyEditorKit().also { ek ->
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
55 UIManager.getFont("Panel.font")?.let { pFont ->
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
56 ek.styleSheet = StyleSheet().apply {
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
57 addRule("body { font-family: \"${pFont.family}\"; font-size: ${pFont.size}; }")
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
58 addStyleSheet(ek.defaultStyleSheet)
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
59 }
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
60 }
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
61 }
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
62 val rawText = this::class.java.getResourceAsStream("help.html").bufferedReader().use { it.readText() }
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
63 it.text = rawText.replace("%CONFIG_FILE_NAME%", buildString {
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
64 for (ch in PROP_FILE.canonicalPath) {
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
65 append(when(ch) {
1
0bded24f746e Compiles, still untested.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
66 '<' -> "&lt;"
0bded24f746e Compiles, still untested.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
67 '>' -> "&gt;"
0bded24f746e Compiles, still untested.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
68 '&' -> "&amp;"
0
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
69 else -> ch
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
70 })
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
71 }
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
72 })
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
73 it.setEditable(false)
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
74 }).apply {
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
75 alignmentX = JScrollPane.CENTER_ALIGNMENT
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
76 addBorder(BorderFactory.createEmptyBorder(BW2, BW2, BW, BW2))
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
77 verticalScrollBarPolicy = ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
78 horizontalScrollBarPolicy = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
79 preferredSize = Dimension(WIDTH, HEIGHT)
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
80 background = Application.mainFrame.background
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
81 }
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
82
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
83 override fun setVisible(vis: Boolean) {
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
84 if (vis)
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
85 helpPane.verticalScrollBar.run { value = minimum }
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
86 super.setVisible(vis)
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
87 }
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
88
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
89 init {
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
90 setVisible(false)
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
91 title = "Help"
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
92 contentPane.apply {
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
93 layout = BoxLayout(this, BoxLayout.Y_AXIS)
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
94 add(helpPane)
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
95 add(Box(BoxLayout.X_AXIS).apply {
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
96 alignmentX = Box.CENTER_ALIGNMENT
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
97 border = BorderFactory.createEmptyBorder(BW, BW2, BW2, BW2)
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
98 add(Box.createHorizontalGlue())
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
99 add(dismissButton)
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
100 })
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
101 }
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
102 pack()
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
103 }
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
104 }