view src/name/blackcap/exifwasher/HelpDialog.kt @ 52:39895d44a287

Get help working on Linux.
author David Barts <n5jrn@me.com>
date Thu, 07 May 2020 09:59:28 -0700
parents fb407182ba76
children 61a06e050bac
line wrap: on
line source

/*
 * The dialog that displays the Exif data in a single file (display only,
 * no changing). We do this after washing.
 */
package name.blackcap.exifwasher

import java.awt.Dimension
import java.awt.event.ActionEvent
import java.awt.event.ActionListener
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 name.blackcap.exifwasher.exiv2.*

class HelpDialog : JDialog(Application.mainFrame) {
    private val BW = 9
    private val BW2 = BW * 2
    private val WIDTH = 640
    private val HEIGHT = 480

    private val dismissButton = JButton("Dismiss").also {
        it.addActionListener(ActionListener { setVisible(false) })
    }

    private val helpPane = JScrollPane(JTextPane().also {
        it.contentType = "text/html";
        it.text = this::class.java.getResourceAsStream("help.html").bufferedReader().use { it.readText() }
    }).apply {
        alignmentX = JScrollPane.CENTER_ALIGNMENT
        border = BorderFactory.createEmptyBorder(BW2, BW2, BW, BW2)
        verticalScrollBarPolicy = ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS
        horizontalScrollBarPolicy = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER
        preferredSize = Dimension(WIDTH, HEIGHT)
        background = Application.mainFrame.background
    }

    override fun setVisible(vis: Boolean) {
        if (vis)
            helpPane.verticalScrollBar.run { value = minimum }
        super.setVisible(vis)
    }

    init {
        setVisible(false)
        title = "Help"
        contentPane.apply {
            layout = BoxLayout(this, BoxLayout.Y_AXIS)
            add(helpPane)
            add(Box(BoxLayout.X_AXIS).apply {
                alignmentX = Box.CENTER_ALIGNMENT
                border = BorderFactory.createEmptyBorder(BW, BW2, BW2, BW2)
                add(Box.createHorizontalGlue())
                add(dismissButton)
            })
        }
        pack()
    }
}