changeset 28:f1fcc1281dad

Use BorderFactory; clean up Find dialog.
author David Barts <n5jrn@me.com>
date Wed, 29 Jan 2020 13:39:14 -0800
parents 8aa2dfac27eb
children c4f53bc01732
files src/name/blackcap/clipman/Main.kt src/name/blackcap/clipman/Menus.kt src/name/blackcap/clipman/PasteboardView.kt src/name/blackcap/clipman/SearchDialog.kt
diffstat 4 files changed, 55 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/src/name/blackcap/clipman/Main.kt	Wed Jan 29 10:50:07 2020 -0800
+++ b/src/name/blackcap/clipman/Main.kt	Wed Jan 29 13:39:14 2020 -0800
@@ -16,7 +16,6 @@
 import java.util.logging.Level
 import java.util.logging.Logger
 import javax.swing.*
-import javax.swing.border.*
 import javax.swing.text.html.StyleSheet
 import kotlin.concurrent.thread
 import org.jsoup.Jsoup
@@ -166,7 +165,7 @@
         frame.v = JFrame(MYNAME)
         con = JPanel().apply {
             layout = BoxLayout(this, BoxLayout.Y_AXIS)
-            border = EmptyBorder(PANEL_BORDER, PANEL_BORDER, PANEL_BORDER, PANEL_BORDER)
+            border = BorderFactory.createEmptyBorder(PANEL_BORDER, PANEL_BORDER, PANEL_BORDER, PANEL_BORDER)
             background = frame.v.background
         }
         frame.v.jMenuBar = menuBar
--- a/src/name/blackcap/clipman/Menus.kt	Wed Jan 29 10:50:07 2020 -0800
+++ b/src/name/blackcap/clipman/Menus.kt	Wed Jan 29 13:39:14 2020 -0800
@@ -88,7 +88,6 @@
                 makeShortcut(KeyEvent.VK_F)
             })
             add(JMenuItem("Find Again").apply {
-                setEnabled(false)
                 actionCommand = "Edit.FindAgain"
                 addActionListener(menuItemListener)
                 makeShortcut(KeyEvent.VK_G)
--- a/src/name/blackcap/clipman/PasteboardView.kt	Wed Jan 29 10:50:07 2020 -0800
+++ b/src/name/blackcap/clipman/PasteboardView.kt	Wed Jan 29 13:39:14 2020 -0800
@@ -6,7 +6,6 @@
 import java.awt.Color
 import java.awt.Dimension
 import javax.swing.*
-import javax.swing.border.*
 import javax.swing.text.html.StyleSheet
 import javax.swing.text.html.HTMLEditorKit
 
@@ -20,10 +19,12 @@
  * What we use to display the text that is or was in the clipboard.
  */
 class ClipText: JTextPane() {
-    private val normalBorder = CompoundBorder(LineBorder(Color.GRAY, INNER_BORDER),
-            EmptyBorder(MARGIN_BORDER, MARGIN_BORDER, MARGIN_BORDER, MARGIN_BORDER))
-    private val selectedBorder = CompoundBorder(LineBorder(Color.BLACK, INNER_BORDER+1),
-            EmptyBorder(MARGIN_BORDER-1, MARGIN_BORDER-1, MARGIN_BORDER-1, MARGIN_BORDER-1))
+    private val normalBorder = BorderFactory.createCompoundBorder(
+            BorderFactory.createLineBorder(Color.GRAY, INNER_BORDER),
+            BorderFactory.createEmptyBorder(MARGIN_BORDER, MARGIN_BORDER, MARGIN_BORDER, MARGIN_BORDER))
+    private val selectedBorder = BorderFactory.createCompoundBorder(
+            BorderFactory.createLineBorder(Color.BLACK, INNER_BORDER+1),
+            BorderFactory.createEmptyBorder(MARGIN_BORDER-1, MARGIN_BORDER-1, MARGIN_BORDER-1, MARGIN_BORDER-1))
     init {
         border = normalBorder
         setEditable(false)
@@ -88,7 +89,7 @@
  */
 class PasteboardItemView(label: String, val searchable: ClipText) {
     private val outerBorder =
-        MatteBorder(OUTER_BORDER_TOP, OUTER_BORDER, OUTER_BORDER, OUTER_BORDER,
+        BorderFactory.createMatteBorder(OUTER_BORDER_TOP, OUTER_BORDER, OUTER_BORDER, OUTER_BORDER,
             queue.v.parent.background)
 
     val contents = JPanel().apply {
--- a/src/name/blackcap/clipman/SearchDialog.kt	Wed Jan 29 10:50:07 2020 -0800
+++ b/src/name/blackcap/clipman/SearchDialog.kt	Wed Jan 29 13:39:14 2020 -0800
@@ -14,8 +14,8 @@
 
 class SearchDialog: JDialog(frame.v), ActionListener, DocumentListener {
     /* the search term */
-    private val _searchFor = JTextField(50).also {
-        it.border = LineBorder(Color.GRAY, 1)
+    private val _searchFor = JTextField(25).also {
+        it.border = BorderFactory.createLineBorder(Color.GRAY, 1)
         it.horizontalAlignment = JTextField.LEFT
         it.alignmentX = JTextField.LEFT_ALIGNMENT
         it.text = ""
@@ -58,6 +58,10 @@
         throw RuntimeException("impossible button state!")
     }
 
+    /* standard spacing between elements (18 pixels = 1/4") and half that */
+    private val BW = 9
+    private val BW2 = 2 * BW
+
     /* where to begin searching from. unlike the other properties, this
        one is read/write. null means to start from the beginning on
        forward searches, and from the end on backward searches (i.e.
@@ -69,38 +73,69 @@
         it.addActionListener(this)
     }
 
+    private val _cancel = JButton("Cancel").also {
+        it.actionCommand = "Cancel"
+        it.addActionListener(this)
+    }
+
     /* initializer */
     init {
         title = "Find"
         contentPane.apply {
             add(Box(BoxLayout.Y_AXIS).apply {
                 add(Box(BoxLayout.Y_AXIS).apply {
-                    add(JLabel("Search for").apply {
+                    add(JLabel("Search for:").apply {
                         horizontalAlignment = JLabel.LEFT
                         alignmentX = JLabel.LEFT_ALIGNMENT
                     })
                     add(_searchFor)
+                    alignmentX = Box.CENTER_ALIGNMENT
+                    border = BorderFactory.createEmptyBorder(BW2, BW2, BW, BW2)
                 })
                 add(Box(BoxLayout.X_AXIS).apply {
+                    add(Box.createGlue())
                     add(Box(BoxLayout.Y_AXIS).apply {
+                        add(JLabel("Settings:").apply {
+                            horizontalAlignment = JLabel.CENTER
+                            alignmentX = JLabel.LEFT_ALIGNMENT
+                        })
                         add(_ignoreCase)
                         add(_autoWrap)
                     })
+                    add(Box.createGlue())
                     add(Box(BoxLayout.Y_AXIS).apply {
+                        add(JLabel("Direction:").apply {
+                            horizontalAlignment = JLabel.CENTER
+                            alignmentX = JLabel.LEFT_ALIGNMENT
+                        })
                         add(_forwards)
                         add(_backwards)
                     })
+                    add(Box.createGlue())
+                    alignmentX = Box.CENTER_ALIGNMENT
+                    border = BorderFactory.createEmptyBorder(BW, BW2, BW, BW2)
                 })
-                add(_find)
+                add(Box(BoxLayout.X_AXIS).apply {
+                    add(Box.createGlue())
+                    add(_cancel)
+                    add(Box.createGlue())
+                    add(_find)
+                    add(Box.createGlue())
+                    border = BorderFactory.createEmptyBorder(BW, BW2, BW2, BW2)
+                })
             })
         }
         rootPane.setDefaultButton(_find)
+        pack()
     }
 
     override fun actionPerformed(e: ActionEvent) {
-        if (e.actionCommand == "Find") {
-            setVisible(false)
-            find()
+        when (e.actionCommand) {
+            "Find" -> {
+                setVisible(false)
+                find()
+            }
+            "Cancel" -> setVisible(false)
         }
     }
 
@@ -115,6 +150,11 @@
     }
 
     fun find(): Unit {
+        if (searchFor.isEmpty()) {
+            Toolkit.getDefaultToolkit().beep()
+            origin = null
+            return
+        }
         fun doFind(o: PasteboardQueue.Offset?) = queue.v.find(searchFor,
             direction = direction, foldCase = ignoreCase, origin = o)
         var result = doFind(origin)