|
@@ -22,11 +22,16 @@
|
22
|
22
|
|
23
|
23
|
package com.dmdirc.addons.ui_swing.textpane;
|
24
|
24
|
|
|
25
|
+import com.dmdirc.addons.ui_swing.UIUtilities;
|
|
26
|
+import com.dmdirc.addons.ui_swing.components.frames.TextFrame;
|
|
27
|
+import com.dmdirc.config.ConfigManager;
|
|
28
|
+import com.dmdirc.interfaces.ConfigChangeListener;
|
25
|
29
|
import com.dmdirc.ui.messages.IRCTextAttribute;
|
26
|
30
|
|
27
|
31
|
import java.awt.Cursor;
|
28
|
32
|
import java.awt.Graphics;
|
29
|
33
|
import java.awt.Graphics2D;
|
|
34
|
+import java.awt.Image;
|
30
|
35
|
import java.awt.Point;
|
31
|
36
|
import java.awt.Rectangle;
|
32
|
37
|
import java.awt.Shape;
|
|
@@ -52,7 +57,7 @@ import javax.swing.event.MouseInputListener;
|
52
|
57
|
|
53
|
58
|
/** Canvas object to draw text. */
|
54
|
59
|
class TextPaneCanvas extends JPanel implements MouseInputListener,
|
55
|
|
- ComponentListener, AdjustmentListener {
|
|
60
|
+ ComponentListener, AdjustmentListener, ConfigChangeListener {
|
56
|
61
|
|
57
|
62
|
/**
|
58
|
63
|
* A version number for this class. It should be changed whenever the
|
|
@@ -84,6 +89,12 @@ class TextPaneCanvas extends JPanel implements MouseInputListener,
|
84
|
89
|
private int lastVisibleLine;
|
85
|
90
|
/** Cached canvas. */
|
86
|
91
|
private BufferedImage buffer;
|
|
92
|
+ /** Background image. */
|
|
93
|
+ private Image backgroundImage;
|
|
94
|
+ /** Config Manager. */
|
|
95
|
+ private ConfigManager manager;
|
|
96
|
+ /** Config domain. */
|
|
97
|
+ private String domain;
|
87
|
98
|
|
88
|
99
|
/**
|
89
|
100
|
* Creates a new text pane canvas.
|
|
@@ -94,8 +105,11 @@ class TextPaneCanvas extends JPanel implements MouseInputListener,
|
94
|
105
|
public TextPaneCanvas(final TextPane parent, final IRCDocument document) {
|
95
|
106
|
super();
|
96
|
107
|
this.document = document;
|
97
|
|
- startLine = 0;
|
98
|
108
|
textPane = parent;
|
|
109
|
+ this.manager = parent.getWindow().getConfigManager();
|
|
110
|
+ this.domain = ((TextFrame) parent.getWindow()).getController().
|
|
111
|
+ getDomain();
|
|
112
|
+ startLine = 0;
|
99
|
113
|
setDoubleBuffered(true);
|
100
|
114
|
setOpaque(true);
|
101
|
115
|
textLayouts = new HashMap<TextLayout, LineInfo>();
|
|
@@ -104,6 +118,9 @@ class TextPaneCanvas extends JPanel implements MouseInputListener,
|
104
|
118
|
addMouseListener(this);
|
105
|
119
|
addMouseMotionListener(this);
|
106
|
120
|
addComponentListener(this);
|
|
121
|
+ manager.addChangeListener(domain, "textpanebackground", this);
|
|
122
|
+
|
|
123
|
+ updateCachedSettings();
|
107
|
124
|
}
|
108
|
125
|
|
109
|
126
|
/**
|
|
@@ -138,6 +155,36 @@ class TextPaneCanvas extends JPanel implements MouseInputListener,
|
138
|
155
|
}
|
139
|
156
|
}
|
140
|
157
|
|
|
158
|
+ /**
|
|
159
|
+ * Paints the background, either from the config setting or the background
|
|
160
|
+ * colour of the textpane.
|
|
161
|
+ *
|
|
162
|
+ * @param g Graphics object to draw onto
|
|
163
|
+ */
|
|
164
|
+ private void paintBackground(final Graphics2D g) {
|
|
165
|
+ if (backgroundImage != null) {
|
|
166
|
+ g.drawImage(backgroundImage, 0,
|
|
167
|
+ 0, getBounds().width, getBounds().height, null);
|
|
168
|
+ } else {
|
|
169
|
+ g.fill(getBounds());
|
|
170
|
+ }
|
|
171
|
+ }
|
|
172
|
+
|
|
173
|
+ private void updateCachedSettings() {
|
|
174
|
+ final String backgroundPath = manager.getOption(domain,
|
|
175
|
+ "textpanebackground");
|
|
176
|
+ UIUtilities.invokeLater(new Runnable() {
|
|
177
|
+
|
|
178
|
+ /** {@inheritDoc} */
|
|
179
|
+ @Override
|
|
180
|
+ public void run() {
|
|
181
|
+ backgroundImage = backgroundPath.isEmpty() ? null : Toolkit.
|
|
182
|
+ getDefaultToolkit().getImage(backgroundPath);
|
|
183
|
+ repaint();
|
|
184
|
+ }
|
|
185
|
+ });
|
|
186
|
+ }
|
|
187
|
+
|
141
|
188
|
/**
|
142
|
189
|
* Calculates the position of the lines and highlights.
|
143
|
190
|
*/
|
|
@@ -169,7 +216,7 @@ class TextPaneCanvas extends JPanel implements MouseInputListener,
|
169
|
216
|
LineBreakMeasurer lineMeasurer;
|
170
|
217
|
|
171
|
218
|
g.setColor(textPane.getBackground());
|
172
|
|
- g.fill(getBounds());
|
|
219
|
+ paintBackground(g);
|
173
|
220
|
|
174
|
221
|
textLayouts.clear();
|
175
|
222
|
positions.clear();
|
|
@@ -909,4 +956,10 @@ class TextPaneCanvas extends JPanel implements MouseInputListener,
|
909
|
956
|
public void componentHidden(final ComponentEvent e) {
|
910
|
957
|
//Ignore
|
911
|
958
|
}
|
|
959
|
+
|
|
960
|
+ /** {@inheritDoc} */
|
|
961
|
+ @Override
|
|
962
|
+ public void configChanged(final String domain, final String key) {
|
|
963
|
+ updateCachedSettings();
|
|
964
|
+ }
|
912
|
965
|
}
|