changeset 21:0f3634a0816d

De-uglify SettingsDialog.
author David Barts <n5jrn@me.com>
date Sat, 21 Nov 2020 21:25:05 -0800
parents 71029c9bf7cd
children d3979a2155a8
files src/name/blackcap/imageprep/MaxDimSpinner.kt src/name/blackcap/imageprep/OutQualSpinner.kt src/name/blackcap/imageprep/SettingsDialog.kt
diffstat 3 files changed, 32 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/name/blackcap/imageprep/MaxDimSpinner.kt	Sat Nov 21 10:15:35 2020 -0800
+++ b/src/name/blackcap/imageprep/MaxDimSpinner.kt	Sat Nov 21 21:25:05 2020 -0800
@@ -3,6 +3,7 @@
  */
 package name.blackcap.imageprep
 
+import java.awt.Dimension
 import java.awt.Toolkit
 import javax.swing.*
 import javax.swing.event.ChangeEvent
@@ -19,9 +20,11 @@
 class MaxDimSpinner(val default: Int): JSpinner(SpinnerListModel(STDDIMS))
 {
     init {
-        editor = JSpinner.ListEditor(this)
+        editor = JSpinner.ListEditor(this).apply {
+            textField.columns = STDDIMS.map { it.toString().length }.max() ?: 1
+        }
         value = default
-        noTaller()
+        maximumSize = preferredSize
         addChangeListener( ChangeListener {
             val v = value as? Int ?: (value as? String)?.toIntOrNull()
             if ( v == null || v < 1 || v > MAXDIM ) {
--- a/src/name/blackcap/imageprep/OutQualSpinner.kt	Sat Nov 21 10:15:35 2020 -0800
+++ b/src/name/blackcap/imageprep/OutQualSpinner.kt	Sat Nov 21 21:25:05 2020 -0800
@@ -3,6 +3,7 @@
  */
 package name.blackcap.imageprep
 
+import java.awt.Dimension
 import java.awt.Toolkit
 import javax.swing.*
 import javax.swing.event.ChangeEvent
@@ -17,9 +18,11 @@
 class OutQualSpinner(val default: Int): JSpinner(SpinnerNumberModel(default, MINQUAL, MAXQUAL, 1))
 {
     init {
-        editor = JSpinner.NumberEditor(this)
+        editor = JSpinner.NumberEditor(this).apply {
+            textField.columns = MAXQUAL.toString().length
+        }
         value = default
-        noTaller()
+        maximumSize = preferredSize
         addChangeListener( ChangeListener {
             val v = value as? Int
             if (v == null || v < MINQUAL || v > MAXQUAL) {
--- a/src/name/blackcap/imageprep/SettingsDialog.kt	Sat Nov 21 10:15:35 2020 -0800
+++ b/src/name/blackcap/imageprep/SettingsDialog.kt	Sat Nov 21 21:25:05 2020 -0800
@@ -52,14 +52,18 @@
     
     /* output to input dir? */
     private val otid = _PROPS.getBoolean("outputToInputDir")
-    private val outputToInputButton = JRadioButton("Create output file in same folder as input.", otid)
+    private val outputToInputButton = JRadioButton("Create output file in same folder as input.", otid).apply {
+        alignmentX = LEFT_ALIGNMENT
+    }
     val outputToInputDir: Boolean
     get() {
         return outputToInputButton.isSelected()
     }
     
     /* output to some other directory */
-    private val outputToButton = JRadioButton("Create output file in:", !otid)
+    private val outputToButton = JRadioButton("Create output file in:", !otid).apply {
+        alignmentX = LEFT_ALIGNMENT
+    }
     
     /* name of the other directory */
     private val oto = _getOutputTo()
@@ -124,33 +128,41 @@
         contentPane.apply {
             layout = BoxLayout(this, BoxLayout.Y_AXIS)
             add(Box(BoxLayout.X_AXIS).apply {
+                alignmentX = LEFT_ALIGNMENT
                 border = BorderFactory.createEmptyBorder(BW2, BW2, BW, BW2)
-                add(leftLabel("Maximum dimension:"))
+                add(leftLabel("Maximum dimension: "))
                 add(_maxDimension)
                 add(Box.createGlue())
-                add(leftLabel("Output quality:"))
+                add(leftLabel("Output quality: "))
                 add(_outputQuality)
             })
             add(Box(BoxLayout.X_AXIS).apply {
+                alignmentX = LEFT_ALIGNMENT
                 border = BorderFactory.createEmptyBorder(BW, BW2, BW, BW2)
-                add(leftLabel("Output filename suffix:"))
+                add(leftLabel("Output filename suffix: "))
                 add(_outputSuffix)
                 add(Box.createGlue())
             })
             add(Box(BoxLayout.Y_AXIS).apply {
-                border = BorderFactory.createEmptyBorder(BW, BW2, BW2, BW2)
+                alignmentX = LEFT_ALIGNMENT
+                border = BorderFactory.createEmptyBorder(BW, BW2, BW, BW2)
                 add(outputToInputButton)
                 add(outputToButton)
                 add(Box(BoxLayout.X_AXIS).apply {
+                    alignmentX = LEFT_ALIGNMENT
                     add(outputToText)
                     add(changeOutputTo)
                     add(Box.createGlue())
                 })
             })
             add(Box(BoxLayout.X_AXIS).apply {
+                alignmentX = LEFT_ALIGNMENT
+                border = BorderFactory.createEmptyBorder(BW, BW2, BW2, BW2)
+                add(Box.createGlue())
                 add(_cancel)
                 add(Box.createGlue())
                 add(_ok)
+                add(Box.createGlue())
             })
         }
         rootPane.setDefaultButton(_ok)
@@ -199,7 +211,10 @@
         }
     }
     
-    private fun _getOutputTo(): String = _PROPS.getProperty("outputTo") ?: System.getProperty("user.dir")
+    private fun _getOutputTo(): String {
+        val p = _PROPS.getProperty("outputTo")
+        return if (p != null) tilde(p) else System.getProperty("user.dir")
+    }
 }
 
 fun Properties.getString(key: String): String = getProperty(key) as String