comparison src/name/blackcap/exifwasher/HelpDialog.kt @ 53:61a06e050bac

Fix help dialog.
author David Barts <n5jrn@me.com>
date Thu, 07 May 2020 12:33:52 -0700
parents 39895d44a287
children 40911898ed23
comparison
equal deleted inserted replaced
52:39895d44a287 53:61a06e050bac
2 * The dialog that displays the Exif data in a single file (display only, 2 * The dialog that displays the Exif data in a single file (display only,
3 * no changing). We do this after washing. 3 * no changing). We do this after washing.
4 */ 4 */
5 package name.blackcap.exifwasher 5 package name.blackcap.exifwasher
6 6
7 import java.awt.Color
7 import java.awt.Dimension 8 import java.awt.Dimension
9 import java.awt.Font
8 import java.awt.event.ActionEvent 10 import java.awt.event.ActionEvent
9 import java.awt.event.ActionListener 11 import java.awt.event.ActionListener
12 import java.io.BufferedReader
10 import java.io.File 13 import java.io.File
11 import java.io.IOException 14 import java.io.IOException
12 import java.io.BufferedReader
13 import java.io.InputStream 15 import java.io.InputStream
14 import java.io.InputStreamReader 16 import java.io.InputStreamReader
15 import java.util.logging.Level 17 import java.util.logging.Level
16 import java.util.logging.Logger 18 import java.util.logging.Logger
17 import javax.swing.* 19 import javax.swing.*
20 import javax.swing.UIManager
21 import javax.swing.text.html.HTMLEditorKit
22 import javax.swing.text.html.StyleSheet
18 23
19 import name.blackcap.exifwasher.exiv2.* 24 import name.blackcap.exifwasher.exiv2.*
20 25
21 class HelpDialog : JDialog(Application.mainFrame) { 26 class HelpDialog : JDialog(Application.mainFrame) {
22 private val BW = 9 27 private val BW = 9
26 31
27 private val dismissButton = JButton("Dismiss").also { 32 private val dismissButton = JButton("Dismiss").also {
28 it.addActionListener(ActionListener { setVisible(false) }) 33 it.addActionListener(ActionListener { setVisible(false) })
29 } 34 }
30 35
36 /*
37 * The stock HTMLEditorKit shares all style sheet data between all its
38 * instances. How unbelievably braindamaged. Correct that.
39 */
40 private class MyEditorKit: HTMLEditorKit() {
41 private var _styleSheet: StyleSheet = defaultStyleSheet
42 override fun getStyleSheet() = _styleSheet
43 override fun setStyleSheet(value: StyleSheet) {
44 _styleSheet = value
45 }
46
47 /**
48 * Return the default style sheet that all HTMLEditorKit's come with.
49 */
50 val defaultStyleSheet: StyleSheet
51 get() {
52 return super.getStyleSheet()
53 }
54 }
55
31 private val helpPane = JScrollPane(JTextPane().also { 56 private val helpPane = JScrollPane(JTextPane().also {
32 it.contentType = "text/html"; 57 UIManager.getFont("Panel.font")?.let { pFont ->
58 it.editorKit = MyEditorKit().also { ek ->
59 ek.styleSheet = StyleSheet().apply {
60 addRule("body { font-family: \"${pFont.family}\"; font-size: ${pFont.size}; }")
61 addStyleSheet(ek.defaultStyleSheet)
62 }
63 }
64 }
33 it.text = this::class.java.getResourceAsStream("help.html").bufferedReader().use { it.readText() } 65 it.text = this::class.java.getResourceAsStream("help.html").bufferedReader().use { it.readText() }
66 it.setEditable(false)
34 }).apply { 67 }).apply {
35 alignmentX = JScrollPane.CENTER_ALIGNMENT 68 alignmentX = JScrollPane.CENTER_ALIGNMENT
36 border = BorderFactory.createEmptyBorder(BW2, BW2, BW, BW2) 69 border = BorderFactory.createCompoundBorder(
70 BorderFactory.createEmptyBorder(BW2, BW2, BW, BW2),
71 UIManager.getBorder("ScrollPane.border") ?: BorderFactory.createLineBorder(Color.GRAY))
37 verticalScrollBarPolicy = ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS 72 verticalScrollBarPolicy = ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS
38 horizontalScrollBarPolicy = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER 73 horizontalScrollBarPolicy = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER
39 preferredSize = Dimension(WIDTH, HEIGHT) 74 preferredSize = Dimension(WIDTH, HEIGHT)
40 background = Application.mainFrame.background 75 background = Application.mainFrame.background
41 } 76 }