annotate src/name/blackcap/clipman/SearchDialog.kt @ 54:a9d5c94a177c

Add README file.
author David Barts <n5jrn@me.com>
date Tue, 13 Apr 2021 10:33:33 -0700
parents 19d9da731c43
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
1 /*
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
2 * The dialog that controls a search.
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
3 */
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
4 package name.blackcap.clipman
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
5
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
6 import java.awt.Color
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
7 import java.awt.Toolkit
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
8 import java.awt.event.ActionEvent
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
9 import java.awt.event.ActionListener
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
10 import javax.swing.*
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
11 import javax.swing.event.DocumentEvent
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
12 import javax.swing.event.DocumentListener
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
13
47
19d9da731c43 Recoded; cleaned up root namespace, removed race conditions.
David Barts <n5jrn@me.com>
parents: 38
diff changeset
14 class SearchDialog: JDialog(Application.frame), ActionListener, DocumentListener {
27
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
15 /* the search term */
28
f1fcc1281dad Use BorderFactory; clean up Find dialog.
David Barts <n5jrn@me.com>
parents: 27
diff changeset
16 private val _searchFor = JTextField(25).also {
f1fcc1281dad Use BorderFactory; clean up Find dialog.
David Barts <n5jrn@me.com>
parents: 27
diff changeset
17 it.border = BorderFactory.createLineBorder(Color.GRAY, 1)
27
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
18 it.horizontalAlignment = JTextField.LEFT
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
19 it.alignmentX = JTextField.LEFT_ALIGNMENT
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
20 it.text = ""
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
21 it.document.addDocumentListener(this)
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
22 }
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
23 val searchFor: String
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
24 get() {
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
25 return _searchFor.text
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
26 }
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
27
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
28 /* whether or not we should ignore case */
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
29 private val _ignoreCase = JCheckBox("Ignore case", true)
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
30 val ignoreCase: Boolean
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
31 get() {
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
32 return _ignoreCase.isSelected()
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
33 }
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
34
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
35 /* whether or not searches should wrap around */
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
36 private val _autoWrap = JCheckBox("Auto wrap", false)
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
37 val autoWrap: Boolean
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
38 get() {
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
39 return _autoWrap.isSelected()
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
40 }
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
41
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
42 /* which direction to search */
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
43 private val _forwards = JRadioButton("Forward", true)
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
44 private val _backwards = JRadioButton("Backward", false)
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
45 private val _direction = ButtonGroup().apply {
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
46 add(_forwards)
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
47 add(_backwards)
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
48 }
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
49 val direction: PasteboardQueue.Direction
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
50 get() {
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
51 if (_forwards.isSelected()) {
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
52 return PasteboardQueue.Direction.FORWARDS
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
53 }
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
54 if (_backwards.isSelected()) {
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
55 return PasteboardQueue.Direction.BACKWARDS
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
56 }
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
57 throw RuntimeException("impossible button state!")
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
58 }
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
59
31
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents: 29
diff changeset
60 /* standard spacing between elements (10 pixels ≅ 1/7") and half that */
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents: 29
diff changeset
61 private val BW = 5
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents: 29
diff changeset
62 private val BW2 = 10
28
f1fcc1281dad Use BorderFactory; clean up Find dialog.
David Barts <n5jrn@me.com>
parents: 27
diff changeset
63
27
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
64 /* where to begin searching from. unlike the other properties, this
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
65 one is read/write. null means to start from the beginning on
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
66 forward searches, and from the end on backward searches (i.e.
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
67 search everything) */
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
68 var origin: PasteboardQueue.Offset? = null
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
69
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
70 private val _find = JButton("Find").also {
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
71 it.actionCommand = "Find"
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
72 it.addActionListener(this)
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
73 }
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
74
28
f1fcc1281dad Use BorderFactory; clean up Find dialog.
David Barts <n5jrn@me.com>
parents: 27
diff changeset
75 private val _cancel = JButton("Cancel").also {
f1fcc1281dad Use BorderFactory; clean up Find dialog.
David Barts <n5jrn@me.com>
parents: 27
diff changeset
76 it.actionCommand = "Cancel"
f1fcc1281dad Use BorderFactory; clean up Find dialog.
David Barts <n5jrn@me.com>
parents: 27
diff changeset
77 it.addActionListener(this)
f1fcc1281dad Use BorderFactory; clean up Find dialog.
David Barts <n5jrn@me.com>
parents: 27
diff changeset
78 }
f1fcc1281dad Use BorderFactory; clean up Find dialog.
David Barts <n5jrn@me.com>
parents: 27
diff changeset
79
27
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
80 /* initializer */
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
81 init {
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
82 title = "Find"
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
83 contentPane.apply {
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
84 add(Box(BoxLayout.Y_AXIS).apply {
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
85 add(Box(BoxLayout.Y_AXIS).apply {
28
f1fcc1281dad Use BorderFactory; clean up Find dialog.
David Barts <n5jrn@me.com>
parents: 27
diff changeset
86 add(JLabel("Search for:").apply {
27
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
87 horizontalAlignment = JLabel.LEFT
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
88 alignmentX = JLabel.LEFT_ALIGNMENT
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
89 })
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
90 add(_searchFor)
28
f1fcc1281dad Use BorderFactory; clean up Find dialog.
David Barts <n5jrn@me.com>
parents: 27
diff changeset
91 alignmentX = Box.CENTER_ALIGNMENT
f1fcc1281dad Use BorderFactory; clean up Find dialog.
David Barts <n5jrn@me.com>
parents: 27
diff changeset
92 border = BorderFactory.createEmptyBorder(BW2, BW2, BW, BW2)
27
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
93 })
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
94 add(Box(BoxLayout.X_AXIS).apply {
28
f1fcc1281dad Use BorderFactory; clean up Find dialog.
David Barts <n5jrn@me.com>
parents: 27
diff changeset
95 add(Box.createGlue())
27
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
96 add(Box(BoxLayout.Y_AXIS).apply {
28
f1fcc1281dad Use BorderFactory; clean up Find dialog.
David Barts <n5jrn@me.com>
parents: 27
diff changeset
97 add(JLabel("Settings:").apply {
f1fcc1281dad Use BorderFactory; clean up Find dialog.
David Barts <n5jrn@me.com>
parents: 27
diff changeset
98 horizontalAlignment = JLabel.CENTER
f1fcc1281dad Use BorderFactory; clean up Find dialog.
David Barts <n5jrn@me.com>
parents: 27
diff changeset
99 alignmentX = JLabel.LEFT_ALIGNMENT
f1fcc1281dad Use BorderFactory; clean up Find dialog.
David Barts <n5jrn@me.com>
parents: 27
diff changeset
100 })
27
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
101 add(_ignoreCase)
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
102 add(_autoWrap)
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
103 })
28
f1fcc1281dad Use BorderFactory; clean up Find dialog.
David Barts <n5jrn@me.com>
parents: 27
diff changeset
104 add(Box.createGlue())
27
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
105 add(Box(BoxLayout.Y_AXIS).apply {
28
f1fcc1281dad Use BorderFactory; clean up Find dialog.
David Barts <n5jrn@me.com>
parents: 27
diff changeset
106 add(JLabel("Direction:").apply {
f1fcc1281dad Use BorderFactory; clean up Find dialog.
David Barts <n5jrn@me.com>
parents: 27
diff changeset
107 horizontalAlignment = JLabel.CENTER
f1fcc1281dad Use BorderFactory; clean up Find dialog.
David Barts <n5jrn@me.com>
parents: 27
diff changeset
108 alignmentX = JLabel.LEFT_ALIGNMENT
f1fcc1281dad Use BorderFactory; clean up Find dialog.
David Barts <n5jrn@me.com>
parents: 27
diff changeset
109 })
27
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
110 add(_forwards)
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
111 add(_backwards)
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
112 })
28
f1fcc1281dad Use BorderFactory; clean up Find dialog.
David Barts <n5jrn@me.com>
parents: 27
diff changeset
113 add(Box.createGlue())
f1fcc1281dad Use BorderFactory; clean up Find dialog.
David Barts <n5jrn@me.com>
parents: 27
diff changeset
114 alignmentX = Box.CENTER_ALIGNMENT
f1fcc1281dad Use BorderFactory; clean up Find dialog.
David Barts <n5jrn@me.com>
parents: 27
diff changeset
115 border = BorderFactory.createEmptyBorder(BW, BW2, BW, BW2)
27
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
116 })
28
f1fcc1281dad Use BorderFactory; clean up Find dialog.
David Barts <n5jrn@me.com>
parents: 27
diff changeset
117 add(Box(BoxLayout.X_AXIS).apply {
f1fcc1281dad Use BorderFactory; clean up Find dialog.
David Barts <n5jrn@me.com>
parents: 27
diff changeset
118 add(Box.createGlue())
f1fcc1281dad Use BorderFactory; clean up Find dialog.
David Barts <n5jrn@me.com>
parents: 27
diff changeset
119 add(_cancel)
f1fcc1281dad Use BorderFactory; clean up Find dialog.
David Barts <n5jrn@me.com>
parents: 27
diff changeset
120 add(Box.createGlue())
f1fcc1281dad Use BorderFactory; clean up Find dialog.
David Barts <n5jrn@me.com>
parents: 27
diff changeset
121 add(_find)
f1fcc1281dad Use BorderFactory; clean up Find dialog.
David Barts <n5jrn@me.com>
parents: 27
diff changeset
122 add(Box.createGlue())
f1fcc1281dad Use BorderFactory; clean up Find dialog.
David Barts <n5jrn@me.com>
parents: 27
diff changeset
123 border = BorderFactory.createEmptyBorder(BW, BW2, BW2, BW2)
f1fcc1281dad Use BorderFactory; clean up Find dialog.
David Barts <n5jrn@me.com>
parents: 27
diff changeset
124 })
27
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
125 })
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
126 }
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
127 rootPane.setDefaultButton(_find)
28
f1fcc1281dad Use BorderFactory; clean up Find dialog.
David Barts <n5jrn@me.com>
parents: 27
diff changeset
128 pack()
38
08eaae2aaf76 Stop dialog resizing, fix detection of bad font sizes.
David Barts <n5jrn@me.com>
parents: 31
diff changeset
129 setResizable(false)
27
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
130 }
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
131
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
132 override fun actionPerformed(e: ActionEvent) {
28
f1fcc1281dad Use BorderFactory; clean up Find dialog.
David Barts <n5jrn@me.com>
parents: 27
diff changeset
133 when (e.actionCommand) {
f1fcc1281dad Use BorderFactory; clean up Find dialog.
David Barts <n5jrn@me.com>
parents: 27
diff changeset
134 "Find" -> {
f1fcc1281dad Use BorderFactory; clean up Find dialog.
David Barts <n5jrn@me.com>
parents: 27
diff changeset
135 setVisible(false)
f1fcc1281dad Use BorderFactory; clean up Find dialog.
David Barts <n5jrn@me.com>
parents: 27
diff changeset
136 find()
f1fcc1281dad Use BorderFactory; clean up Find dialog.
David Barts <n5jrn@me.com>
parents: 27
diff changeset
137 }
f1fcc1281dad Use BorderFactory; clean up Find dialog.
David Barts <n5jrn@me.com>
parents: 27
diff changeset
138 "Cancel" -> setVisible(false)
27
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
139 }
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
140 }
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
141
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
142 override fun setVisible(visible: Boolean) {
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
143 if (visible) {
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
144 _searchFor.run {
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
145 requestFocusInWindow()
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
146 selectAll()
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
147 }
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
148 }
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
149 super.setVisible(visible)
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
150 }
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
151
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
152 fun find(): Unit {
28
f1fcc1281dad Use BorderFactory; clean up Find dialog.
David Barts <n5jrn@me.com>
parents: 27
diff changeset
153 if (searchFor.isEmpty()) {
f1fcc1281dad Use BorderFactory; clean up Find dialog.
David Barts <n5jrn@me.com>
parents: 27
diff changeset
154 Toolkit.getDefaultToolkit().beep()
f1fcc1281dad Use BorderFactory; clean up Find dialog.
David Barts <n5jrn@me.com>
parents: 27
diff changeset
155 origin = null
f1fcc1281dad Use BorderFactory; clean up Find dialog.
David Barts <n5jrn@me.com>
parents: 27
diff changeset
156 return
f1fcc1281dad Use BorderFactory; clean up Find dialog.
David Barts <n5jrn@me.com>
parents: 27
diff changeset
157 }
47
19d9da731c43 Recoded; cleaned up root namespace, removed race conditions.
David Barts <n5jrn@me.com>
parents: 38
diff changeset
158 fun doFind(o: PasteboardQueue.Offset?) = Application.queue.find(searchFor,
27
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
159 direction = direction, foldCase = ignoreCase, origin = o)
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
160 var result = doFind(origin)
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
161 if (result == null && origin != null && autoWrap) {
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
162 result = doFind(null)
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
163 }
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
164 if (result == null) {
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
165 Toolkit.getDefaultToolkit().beep()
29
c4f53bc01732 Fix searching (and main display).
David Barts <n5jrn@me.com>
parents: 28
diff changeset
166 origin = null
c4f53bc01732 Fix searching (and main display).
David Barts <n5jrn@me.com>
parents: 28
diff changeset
167 } else {
c4f53bc01732 Fix searching (and main display).
David Barts <n5jrn@me.com>
parents: 28
diff changeset
168 origin = when(direction) {
c4f53bc01732 Fix searching (and main display).
David Barts <n5jrn@me.com>
parents: 28
diff changeset
169 PasteboardQueue.Direction.FORWARDS ->
c4f53bc01732 Fix searching (and main display).
David Barts <n5jrn@me.com>
parents: 28
diff changeset
170 PasteboardQueue.Offset(result.inQueue, result.inItem + 1)
c4f53bc01732 Fix searching (and main display).
David Barts <n5jrn@me.com>
parents: 28
diff changeset
171 PasteboardQueue.Direction.BACKWARDS ->
c4f53bc01732 Fix searching (and main display).
David Barts <n5jrn@me.com>
parents: 28
diff changeset
172 if (result.inItem == 0) {
c4f53bc01732 Fix searching (and main display).
David Barts <n5jrn@me.com>
parents: 28
diff changeset
173 if (result.inQueue == 0) null else PasteboardQueue.Offset(result.inQueue - 1, -1)
c4f53bc01732 Fix searching (and main display).
David Barts <n5jrn@me.com>
parents: 28
diff changeset
174 } else {
c4f53bc01732 Fix searching (and main display).
David Barts <n5jrn@me.com>
parents: 28
diff changeset
175 PasteboardQueue.Offset(result.inQueue, result.inItem - 1)
c4f53bc01732 Fix searching (and main display).
David Barts <n5jrn@me.com>
parents: 28
diff changeset
176 }
c4f53bc01732 Fix searching (and main display).
David Barts <n5jrn@me.com>
parents: 28
diff changeset
177 }
27
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
178 }
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
179 }
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
180
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
181 /* changing the search string resets the search origin */
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
182 override fun changedUpdate(e: DocumentEvent) {
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
183 if (e.document === _searchFor.document) {
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
184 origin = null
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
185 }
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
186 }
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
187 override fun insertUpdate(e: DocumentEvent) = changedUpdate(e)
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
188 override fun removeUpdate(e: DocumentEvent) = changedUpdate(e)
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents:
diff changeset
189 }