comparison src/name/blackcap/clipman/PasteboardView.kt @ 27:8aa2dfac27eb

Big reorg; compiled but untested.
author David Barts <n5jrn@me.com>
date Wed, 29 Jan 2020 10:50:07 -0800
parents
children f1fcc1281dad
comparison
equal deleted inserted replaced
26:ff35fabaea3a 27:8aa2dfac27eb
1 /*
2 * View-related pasteboard stuff.
3 */
4 package name.blackcap.clipman
5
6 import java.awt.Color
7 import java.awt.Dimension
8 import javax.swing.*
9 import javax.swing.border.*
10 import javax.swing.text.html.StyleSheet
11 import javax.swing.text.html.HTMLEditorKit
12
13 /* border widths */
14 val OUTER_BORDER_TOP = 3
15 val OUTER_BORDER = 9
16 val INNER_BORDER = 1
17 val MARGIN_BORDER = 3
18
19 /**
20 * What we use to display the text that is or was in the clipboard.
21 */
22 class ClipText: JTextPane() {
23 private val normalBorder = CompoundBorder(LineBorder(Color.GRAY, INNER_BORDER),
24 EmptyBorder(MARGIN_BORDER, MARGIN_BORDER, MARGIN_BORDER, MARGIN_BORDER))
25 private val selectedBorder = CompoundBorder(LineBorder(Color.BLACK, INNER_BORDER+1),
26 EmptyBorder(MARGIN_BORDER-1, MARGIN_BORDER-1, MARGIN_BORDER-1, MARGIN_BORDER-1))
27 init {
28 border = normalBorder
29 setEditable(false)
30 alignmentX = JTextPane.LEFT_ALIGNMENT
31 resize()
32 }
33
34 /**
35 * We allow the text to be considered "selected;" such text is used
36 * as the target for any subsequent editing operation.
37 */
38 var selected: Boolean
39 get() {
40 return border === selectedBorder
41 }
42 set(value) {
43 border = if (value) { selectedBorder } else { normalBorder }
44 }
45
46 /**
47 * Refuse to fill the window in the vertical dimension, because doing
48 * so leads to a misleading display of the clipboard contents, falsely
49 * implying the existence of a bunch of trailing whitespace.
50 */
51 override fun getMaximumSize(): Dimension {
52 return Dimension(Int.MAX_VALUE, preferredSize.height)
53 }
54
55 /**
56 * Dynamically size or resize this view.
57 */
58 fun resize() {
59 autoSize(queue.v.parent.size.width -
60 2 * (PANEL_BORDER + OUTER_BORDER + INNER_BORDER + MARGIN_BORDER))
61 }
62 }
63
64
65 /**
66 * The stock HTMLEditorKit shares all style sheet data between all its
67 * instances. How unbelievably braindamaged. Correct that.
68 */
69 class MyEditorKit: HTMLEditorKit() {
70 private var _styleSheet = defaultStyleSheet
71 override fun getStyleSheet() = _styleSheet
72 override fun setStyleSheet(value: StyleSheet) {
73 _styleSheet = value
74 }
75
76 /**
77 * Return the default style sheet that all HTMLEditorKit's come with.
78 */
79 val defaultStyleSheet: StyleSheet
80 get() {
81 return super.getStyleSheet()
82 }
83 }
84
85 /**
86 * Views are based on a JLabel and a ClipText (which we use for searching),
87 * wrapped in a JPanel that we use to display both.
88 */
89 class PasteboardItemView(label: String, val searchable: ClipText) {
90 private val outerBorder =
91 MatteBorder(OUTER_BORDER_TOP, OUTER_BORDER, OUTER_BORDER, OUTER_BORDER,
92 queue.v.parent.background)
93
94 val contents = JPanel().apply {
95 layout = BoxLayout(this, BoxLayout.Y_AXIS)
96 background = queue.v.parent.background
97 border = outerBorder
98 add(JLabel(label).apply {
99 horizontalAlignment = JLabel.LEFT
100 alignmentX = JLabel.LEFT_ALIGNMENT
101 })
102 add(searchable)
103 }
104 }