annotate src/name/blackcap/exifwasher/HelpDialog.kt @ 59:4997ae108653

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