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