changeset 53:61a06e050bac

Fix help dialog.
author David Barts <n5jrn@me.com>
date Thu, 07 May 2020 12:33:52 -0700
parents 39895d44a287
children 40911898ed23
files src/name/blackcap/exifwasher/HelpDialog.kt
diffstat 1 files changed, 38 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/name/blackcap/exifwasher/HelpDialog.kt	Thu May 07 09:59:28 2020 -0700
+++ b/src/name/blackcap/exifwasher/HelpDialog.kt	Thu May 07 12:33:52 2020 -0700
@@ -4,17 +4,22 @@
  */
 package name.blackcap.exifwasher
 
+import java.awt.Color
 import java.awt.Dimension
+import java.awt.Font
 import java.awt.event.ActionEvent
 import java.awt.event.ActionListener
+import java.io.BufferedReader
 import java.io.File
 import java.io.IOException
-import java.io.BufferedReader
 import java.io.InputStream
 import java.io.InputStreamReader
 import java.util.logging.Level
 import java.util.logging.Logger
 import javax.swing.*
+import javax.swing.UIManager
+import javax.swing.text.html.HTMLEditorKit
+import javax.swing.text.html.StyleSheet
 
 import name.blackcap.exifwasher.exiv2.*
 
@@ -28,12 +33,42 @@
         it.addActionListener(ActionListener { setVisible(false) })
     }
 
+    /*
+     * The stock HTMLEditorKit shares all style sheet data between all its
+     * instances. How unbelievably braindamaged. Correct that.
+     */
+    private class MyEditorKit: HTMLEditorKit() {
+        private var _styleSheet: StyleSheet = defaultStyleSheet
+        override fun getStyleSheet() = _styleSheet
+        override fun setStyleSheet(value: StyleSheet) {
+            _styleSheet = value
+        }
+
+        /**
+         * Return the default style sheet that all HTMLEditorKit's come with.
+         */
+        val defaultStyleSheet: StyleSheet
+        get() {
+            return super.getStyleSheet()
+        }
+    }
+
     private val helpPane = JScrollPane(JTextPane().also {
-        it.contentType = "text/html";
+        UIManager.getFont("Panel.font")?.let { pFont ->
+            it.editorKit = MyEditorKit().also { ek ->
+                ek.styleSheet = StyleSheet().apply {
+                    addRule("body { font-family: \"${pFont.family}\"; font-size: ${pFont.size}; }")
+                    addStyleSheet(ek.defaultStyleSheet)
+                }
+            }
+        }
         it.text = this::class.java.getResourceAsStream("help.html").bufferedReader().use { it.readText() }
+        it.setEditable(false)
     }).apply {
         alignmentX = JScrollPane.CENTER_ALIGNMENT
-        border = BorderFactory.createEmptyBorder(BW2, BW2, BW, BW2)
+        border = BorderFactory.createCompoundBorder(
+            BorderFactory.createEmptyBorder(BW2, BW2, BW, BW2),
+            UIManager.getBorder("ScrollPane.border") ?: BorderFactory.createLineBorder(Color.GRAY))
         verticalScrollBarPolicy = ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS
         horizontalScrollBarPolicy = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER
         preferredSize = Dimension(WIDTH, HEIGHT)