Mercurial > cgi-bin > hgweb.cgi > ClipMan
annotate src/name/blackcap/clipman/PasteboardView.kt @ 44:d14298ef8b0a
Fix some settings/preferences issues.
author | David Barts <n5jrn@me.com> |
---|---|
date | Sun, 09 Feb 2020 22:13:26 -0700 |
parents | 0c6c18a733b7 |
children | 19d9da731c43 |
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 */ | |
31 | 21 class ClipText(val basedOn: PasteboardItem): 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 } | |
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 = | |
28
f1fcc1281dad
Use BorderFactory; clean up Find dialog.
David Barts <n5jrn@me.com>
parents:
27
diff
changeset
|
91 BorderFactory.createMatteBorder(OUTER_BORDER_TOP, OUTER_BORDER, OUTER_BORDER, OUTER_BORDER, |
27 | 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 } |