comparison src/name/blackcap/clipman/Main.kt @ 21:c10a447b9e1b

Add some searching hooks.
author David Barts <n5jrn@me.com>
date Thu, 23 Jan 2020 00:02:07 -0800
parents 17296054c103
children dac8dfb4b549
comparison
equal deleted inserted replaced
20:17296054c103 21:c10a447b9e1b
79 get() { 79 get() {
80 return super.getStyleSheet() 80 return super.getStyleSheet()
81 } 81 }
82 } 82 }
83 83
84
85 /* the updating thread */ 84 /* the updating thread */
86 class UpdateIt(val queue: PasteboardQueue, val interval: Int): Thread() { 85 class UpdateIt(val queue: PasteboardQueue, val interval: Int): Thread() {
87 @Volatile var enabled = true 86 @Volatile var enabled = true
88 private val outerBorder = 87 private val outerBorder =
89 MatteBorder(OUTER_BORDER_TOP, OUTER_BORDER, OUTER_BORDER, OUTER_BORDER, 88 MatteBorder(OUTER_BORDER_TOP, OUTER_BORDER, OUTER_BORDER, OUTER_BORDER,
107 val (plain, html) = when(contents) { 106 val (plain, html) = when(contents) {
108 is PasteboardItem.Plain -> Pair(contents.plain, null) 107 is PasteboardItem.Plain -> Pair(contents.plain, null)
109 is PasteboardItem.HTML -> Pair(null, contents.html) 108 is PasteboardItem.HTML -> Pair(null, contents.html)
110 is PasteboardItem.RTF -> Pair(contents.plain, contents.html) 109 is PasteboardItem.RTF -> Pair(contents.plain, contents.html)
111 } 110 }
111 var searchable: JTextComponent? = null
112 if (html == null) { 112 if (html == null) {
113 widget.run { 113 widget.run {
114 add(stdLabel("Plain text")) 114 add(stdLabel("Plain text"))
115 add(ClipText().apply { 115 searchable = ClipText().apply {
116 contentType = "text/plain" 116 contentType = "text/plain"
117 text = plain 117 text = plain
118 font = Font(Font.MONOSPACED, Font.PLAIN, MONO_SIZE) 118 font = Font(Font.MONOSPACED, Font.PLAIN, MONO_SIZE)
119 border = stdBorder 119 border = stdBorder
120 autoSize(stdWidth) 120 autoSize(stdWidth)
121 setEditable(false) 121 setEditable(false)
122 alignmentX = JTextPane.LEFT_ALIGNMENT 122 alignmentX = JTextPane.LEFT_ALIGNMENT
123 }) 123 }
124 add(searchable)
124 } 125 }
125 } else { 126 } else {
126 widget.run { 127 widget.run {
127 add(stdLabel("Styled text")) 128 add(stdLabel("Styled text"))
128 val (dhtml, style) = preproc(html) 129 val (dhtml, style) = preproc(html)
129 val hek = MyEditorKit().apply { 130 val hek = MyEditorKit().apply {
130 style.addStyleSheet(defaultStyleSheet) 131 style.addStyleSheet(defaultStyleSheet)
131 styleSheet = style 132 styleSheet = style
132 } 133 }
133 add(ClipText().apply { 134 searchable = ClipText().apply {
134 editorKit = hek 135 editorKit = hek
135 text = dhtml 136 text = dhtml
136 border = stdBorder 137 border = stdBorder
137 autoSize(stdWidth) 138 autoSize(stdWidth)
138 setEditable(false) 139 setEditable(false)
139 alignmentX = JTextPane.LEFT_ALIGNMENT 140 alignmentX = JTextPane.LEFT_ALIGNMENT
140 }) 141 }
142 add(searchable)
141 } 143 }
142 } 144 }
143 queue.add(QueueItem(widget, contents)) 145 queue.add(QueueItem(widget, searchable!!, contents))
144 oldContents = contents 146 oldContents = contents
145 } 147 }
146 } 148 }
147 if (Thread.interrupted()) { 149 if (Thread.interrupted()) {
148 return 150 return
179 } 181 }
180 } 182 }
181 183
182 fun main(args: Array<String>) { 184 fun main(args: Array<String>) {
183 LOGGER.log(Level.INFO, "beginning execution") 185 LOGGER.log(Level.INFO, "beginning execution")
184 setLookFeel() 186 var frame: JFrame? = null
185 val frame = JFrame(MYNAME) 187 var con: JPanel? = null
186 val con = JPanel().apply {
187 layout = BoxLayout(this, BoxLayout.Y_AXIS)
188 border = EmptyBorder(PANEL_BORDER, PANEL_BORDER, PANEL_BORDER, PANEL_BORDER)
189 background = frame.background
190 }
191 inSynSwingThread { 188 inSynSwingThread {
192 frame.apply { 189 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
190 frame = JFrame(MYNAME)
191 con = JPanel().apply {
192 layout = BoxLayout(this, BoxLayout.Y_AXIS)
193 border = EmptyBorder(PANEL_BORDER, PANEL_BORDER, PANEL_BORDER, PANEL_BORDER)
194 background = frame!!.background
195 }
196 frame!!.apply {
193 contentPane.add( 197 contentPane.add(
194 JScrollPane(con).apply { 198 JScrollPane(con!!).apply {
195 verticalScrollBarPolicy = ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS 199 verticalScrollBarPolicy = ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS
196 horizontalScrollBarPolicy = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER 200 horizontalScrollBarPolicy = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER
197 preferredSize = Dimension(CPWIDTH, CPHEIGHT) 201 preferredSize = Dimension(CPWIDTH, CPHEIGHT)
198 background = frame.background 202 background = frame!!.background
199 }, BorderLayout.CENTER) 203 }, BorderLayout.CENTER)
200 pack() 204 pack()
201 setVisible(true) 205 setVisible(true)
202 } 206 }
203 } 207 }
204 val queue = PasteboardQueue(con, 10) 208 val queue = PasteboardQueue(con!!, 10)
205 val updater = UpdateIt(queue, 1000).apply { start() } 209 val updater = UpdateIt(queue, 1000).apply { start() }
206 inSwingThread { frame.addWindowListener(KillIt(updater)) } 210 inSwingThread { frame!!.addWindowListener(KillIt(updater)) }
207 }
208
209 fun setLookFeel() {
210 inSwingThread {
211 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
212 }
213 } 211 }
214 212
215 fun inSwingThread(block: () -> Unit) { 213 fun inSwingThread(block: () -> Unit) {
216 SwingUtilities.invokeLater(Runnable(block)) 214 SwingUtilities.invokeLater(Runnable(block))
217 } 215 }