Mercurial > cgi-bin > hgweb.cgi > ClipMan
comparison src/name/blackcap/clipman/SearchDialog.kt @ 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 |
comparison
equal
deleted
inserted
replaced
27:8aa2dfac27eb | 28:f1fcc1281dad |
---|---|
12 import javax.swing.event.DocumentEvent | 12 import javax.swing.event.DocumentEvent |
13 import javax.swing.event.DocumentListener | 13 import javax.swing.event.DocumentListener |
14 | 14 |
15 class SearchDialog: JDialog(frame.v), ActionListener, DocumentListener { | 15 class SearchDialog: JDialog(frame.v), ActionListener, DocumentListener { |
16 /* the search term */ | 16 /* the search term */ |
17 private val _searchFor = JTextField(50).also { | 17 private val _searchFor = JTextField(25).also { |
18 it.border = LineBorder(Color.GRAY, 1) | 18 it.border = BorderFactory.createLineBorder(Color.GRAY, 1) |
19 it.horizontalAlignment = JTextField.LEFT | 19 it.horizontalAlignment = JTextField.LEFT |
20 it.alignmentX = JTextField.LEFT_ALIGNMENT | 20 it.alignmentX = JTextField.LEFT_ALIGNMENT |
21 it.text = "" | 21 it.text = "" |
22 it.document.addDocumentListener(this) | 22 it.document.addDocumentListener(this) |
23 } | 23 } |
56 return PasteboardQueue.Direction.BACKWARDS | 56 return PasteboardQueue.Direction.BACKWARDS |
57 } | 57 } |
58 throw RuntimeException("impossible button state!") | 58 throw RuntimeException("impossible button state!") |
59 } | 59 } |
60 | 60 |
61 /* standard spacing between elements (18 pixels = 1/4") and half that */ | |
62 private val BW = 9 | |
63 private val BW2 = 2 * BW | |
64 | |
61 /* where to begin searching from. unlike the other properties, this | 65 /* where to begin searching from. unlike the other properties, this |
62 one is read/write. null means to start from the beginning on | 66 one is read/write. null means to start from the beginning on |
63 forward searches, and from the end on backward searches (i.e. | 67 forward searches, and from the end on backward searches (i.e. |
64 search everything) */ | 68 search everything) */ |
65 var origin: PasteboardQueue.Offset? = null | 69 var origin: PasteboardQueue.Offset? = null |
67 private val _find = JButton("Find").also { | 71 private val _find = JButton("Find").also { |
68 it.actionCommand = "Find" | 72 it.actionCommand = "Find" |
69 it.addActionListener(this) | 73 it.addActionListener(this) |
70 } | 74 } |
71 | 75 |
76 private val _cancel = JButton("Cancel").also { | |
77 it.actionCommand = "Cancel" | |
78 it.addActionListener(this) | |
79 } | |
80 | |
72 /* initializer */ | 81 /* initializer */ |
73 init { | 82 init { |
74 title = "Find" | 83 title = "Find" |
75 contentPane.apply { | 84 contentPane.apply { |
76 add(Box(BoxLayout.Y_AXIS).apply { | 85 add(Box(BoxLayout.Y_AXIS).apply { |
77 add(Box(BoxLayout.Y_AXIS).apply { | 86 add(Box(BoxLayout.Y_AXIS).apply { |
78 add(JLabel("Search for").apply { | 87 add(JLabel("Search for:").apply { |
79 horizontalAlignment = JLabel.LEFT | 88 horizontalAlignment = JLabel.LEFT |
80 alignmentX = JLabel.LEFT_ALIGNMENT | 89 alignmentX = JLabel.LEFT_ALIGNMENT |
81 }) | 90 }) |
82 add(_searchFor) | 91 add(_searchFor) |
92 alignmentX = Box.CENTER_ALIGNMENT | |
93 border = BorderFactory.createEmptyBorder(BW2, BW2, BW, BW2) | |
83 }) | 94 }) |
84 add(Box(BoxLayout.X_AXIS).apply { | 95 add(Box(BoxLayout.X_AXIS).apply { |
96 add(Box.createGlue()) | |
85 add(Box(BoxLayout.Y_AXIS).apply { | 97 add(Box(BoxLayout.Y_AXIS).apply { |
98 add(JLabel("Settings:").apply { | |
99 horizontalAlignment = JLabel.CENTER | |
100 alignmentX = JLabel.LEFT_ALIGNMENT | |
101 }) | |
86 add(_ignoreCase) | 102 add(_ignoreCase) |
87 add(_autoWrap) | 103 add(_autoWrap) |
88 }) | 104 }) |
105 add(Box.createGlue()) | |
89 add(Box(BoxLayout.Y_AXIS).apply { | 106 add(Box(BoxLayout.Y_AXIS).apply { |
107 add(JLabel("Direction:").apply { | |
108 horizontalAlignment = JLabel.CENTER | |
109 alignmentX = JLabel.LEFT_ALIGNMENT | |
110 }) | |
90 add(_forwards) | 111 add(_forwards) |
91 add(_backwards) | 112 add(_backwards) |
92 }) | 113 }) |
114 add(Box.createGlue()) | |
115 alignmentX = Box.CENTER_ALIGNMENT | |
116 border = BorderFactory.createEmptyBorder(BW, BW2, BW, BW2) | |
93 }) | 117 }) |
94 add(_find) | 118 add(Box(BoxLayout.X_AXIS).apply { |
119 add(Box.createGlue()) | |
120 add(_cancel) | |
121 add(Box.createGlue()) | |
122 add(_find) | |
123 add(Box.createGlue()) | |
124 border = BorderFactory.createEmptyBorder(BW, BW2, BW2, BW2) | |
125 }) | |
95 }) | 126 }) |
96 } | 127 } |
97 rootPane.setDefaultButton(_find) | 128 rootPane.setDefaultButton(_find) |
129 pack() | |
98 } | 130 } |
99 | 131 |
100 override fun actionPerformed(e: ActionEvent) { | 132 override fun actionPerformed(e: ActionEvent) { |
101 if (e.actionCommand == "Find") { | 133 when (e.actionCommand) { |
102 setVisible(false) | 134 "Find" -> { |
103 find() | 135 setVisible(false) |
136 find() | |
137 } | |
138 "Cancel" -> setVisible(false) | |
104 } | 139 } |
105 } | 140 } |
106 | 141 |
107 override fun setVisible(visible: Boolean) { | 142 override fun setVisible(visible: Boolean) { |
108 if (visible) { | 143 if (visible) { |
113 } | 148 } |
114 super.setVisible(visible) | 149 super.setVisible(visible) |
115 } | 150 } |
116 | 151 |
117 fun find(): Unit { | 152 fun find(): Unit { |
153 if (searchFor.isEmpty()) { | |
154 Toolkit.getDefaultToolkit().beep() | |
155 origin = null | |
156 return | |
157 } | |
118 fun doFind(o: PasteboardQueue.Offset?) = queue.v.find(searchFor, | 158 fun doFind(o: PasteboardQueue.Offset?) = queue.v.find(searchFor, |
119 direction = direction, foldCase = ignoreCase, origin = o) | 159 direction = direction, foldCase = ignoreCase, origin = o) |
120 var result = doFind(origin) | 160 var result = doFind(origin) |
121 if (result == null && origin != null && autoWrap) { | 161 if (result == null && origin != null && autoWrap) { |
122 result = doFind(null) | 162 result = doFind(null) |