view src/name/blackcap/imageprep/OutQualSpinner.kt @ 28:c310ec097194

Add Linux support.
author David Barts <n5jrn@me.com>
date Fri, 25 Dec 2020 19:07:47 -0800
parents d3979a2155a8
children
line wrap: on
line source

/*
 * A standard spinner for inputting the output quality of a JPEG image.
 */
package name.blackcap.imageprep

import java.awt.Toolkit
import javax.swing.*
import javax.swing.event.ChangeEvent
import javax.swing.event.ChangeListener
import java.util.logging.Level
import java.util.logging.Logger

/* allowable JPEG quality range */
private val MINQUAL = 0
private val MAXQUAL = 100

class OutQualSpinner(val default: Int): JSpinner(SpinnerNumberModel(default, MINQUAL, MAXQUAL, 1))
{
    init {
        editor = JSpinner.NumberEditor(this).apply {
            textField.columns = MAXQUAL.toString().length
        }
        value = default
        maximumSize = preferredSize
        addChangeListener( ChangeListener {
            val v = value as? Int
            if (v == null || v < MINQUAL || v > MAXQUAL) {
                LOGGER.log(Level.INFO, "bad output quality: $value")
                value = default
                Toolkit.getDefaultToolkit().beep()
            }
        })
    }
}