Mercurial > cgi-bin > hgweb.cgi > ClipMan
diff 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 |
line wrap: on
line diff
--- a/src/name/blackcap/clipman/Main.kt Tue Jan 21 23:38:10 2020 -0800 +++ b/src/name/blackcap/clipman/Main.kt Thu Jan 23 00:02:07 2020 -0800 @@ -81,7 +81,6 @@ } } - /* the updating thread */ class UpdateIt(val queue: PasteboardQueue, val interval: Int): Thread() { @Volatile var enabled = true @@ -109,10 +108,11 @@ is PasteboardItem.HTML -> Pair(null, contents.html) is PasteboardItem.RTF -> Pair(contents.plain, contents.html) } + var searchable: JTextComponent? = null if (html == null) { widget.run { add(stdLabel("Plain text")) - add(ClipText().apply { + searchable = ClipText().apply { contentType = "text/plain" text = plain font = Font(Font.MONOSPACED, Font.PLAIN, MONO_SIZE) @@ -120,7 +120,8 @@ autoSize(stdWidth) setEditable(false) alignmentX = JTextPane.LEFT_ALIGNMENT - }) + } + add(searchable) } } else { widget.run { @@ -130,17 +131,18 @@ style.addStyleSheet(defaultStyleSheet) styleSheet = style } - add(ClipText().apply { + searchable = ClipText().apply { editorKit = hek text = dhtml border = stdBorder autoSize(stdWidth) setEditable(false) alignmentX = JTextPane.LEFT_ALIGNMENT - }) + } + add(searchable) } } - queue.add(QueueItem(widget, contents)) + queue.add(QueueItem(widget, searchable!!, contents)) oldContents = contents } } @@ -181,35 +183,31 @@ fun main(args: Array<String>) { LOGGER.log(Level.INFO, "beginning execution") - setLookFeel() - val frame = JFrame(MYNAME) - val con = JPanel().apply { - layout = BoxLayout(this, BoxLayout.Y_AXIS) - border = EmptyBorder(PANEL_BORDER, PANEL_BORDER, PANEL_BORDER, PANEL_BORDER) - background = frame.background - } + var frame: JFrame? = null + var con: JPanel? = null inSynSwingThread { - frame.apply { + UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); + frame = JFrame(MYNAME) + con = JPanel().apply { + layout = BoxLayout(this, BoxLayout.Y_AXIS) + border = EmptyBorder(PANEL_BORDER, PANEL_BORDER, PANEL_BORDER, PANEL_BORDER) + background = frame!!.background + } + frame!!.apply { contentPane.add( - JScrollPane(con).apply { + JScrollPane(con!!).apply { verticalScrollBarPolicy = ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS horizontalScrollBarPolicy = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER preferredSize = Dimension(CPWIDTH, CPHEIGHT) - background = frame.background + background = frame!!.background }, BorderLayout.CENTER) pack() setVisible(true) } } - val queue = PasteboardQueue(con, 10) + val queue = PasteboardQueue(con!!, 10) val updater = UpdateIt(queue, 1000).apply { start() } - inSwingThread { frame.addWindowListener(KillIt(updater)) } -} - -fun setLookFeel() { - inSwingThread { - UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); - } + inSwingThread { frame!!.addWindowListener(KillIt(updater)) } } fun inSwingThread(block: () -> Unit) {