# HG changeset patch # User David Barts # Date 1580333954 28800 # Node ID f1fcc1281dade0eeae0e39d6e5d5924716110f65 # Parent 8aa2dfac27eb213d0559af9f27b3222651d0eade Use BorderFactory; clean up Find dialog. diff -r 8aa2dfac27eb -r f1fcc1281dad src/name/blackcap/clipman/Main.kt --- 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 diff -r 8aa2dfac27eb -r f1fcc1281dad src/name/blackcap/clipman/Menus.kt --- 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) diff -r 8aa2dfac27eb -r f1fcc1281dad src/name/blackcap/clipman/PasteboardView.kt --- 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 { diff -r 8aa2dfac27eb -r f1fcc1281dad src/name/blackcap/clipman/SearchDialog.kt --- 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)