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