|
@@ -86,6 +86,8 @@ class TextPaneCanvas extends JPanel implements MouseInputListener,
|
86
|
86
|
private final Map<Rectangle, TextLayout> positions;
|
87
|
87
|
/** TextLayout -> Line numbers. */
|
88
|
88
|
private final Map<TextLayout, LineInfo> textLayouts;
|
|
89
|
+ /** Saved positions. */
|
|
90
|
+ private final Map<TextLayout, Point> savedPositions;
|
89
|
91
|
/** Start line. */
|
90
|
92
|
private int startLine;
|
91
|
93
|
/** Selection. */
|
|
@@ -106,6 +108,8 @@ class TextPaneCanvas extends JPanel implements MouseInputListener,
|
106
|
108
|
private boolean quickCopy;
|
107
|
109
|
/** Mouse click listeners. */
|
108
|
110
|
private final ListenerList listeners = new ListenerList();
|
|
111
|
+ /** Is cache stale? */
|
|
112
|
+ private boolean staleCache = true;
|
109
|
113
|
|
110
|
114
|
/**
|
111
|
115
|
* Creates a new text pane canvas.
|
|
@@ -125,6 +129,7 @@ class TextPaneCanvas extends JPanel implements MouseInputListener,
|
125
|
129
|
setOpaque(true);
|
126
|
130
|
textLayouts = new HashMap<TextLayout, LineInfo>();
|
127
|
131
|
positions = new HashMap<Rectangle, TextLayout>();
|
|
132
|
+ savedPositions = new HashMap<TextLayout, Point>();
|
128
|
133
|
selection = new LinePosition(-1, -1, -1, -1);
|
129
|
134
|
addMouseListener(this);
|
130
|
135
|
addMouseMotionListener(this);
|
|
@@ -154,16 +159,25 @@ class TextPaneCanvas extends JPanel implements MouseInputListener,
|
154
|
159
|
g.fill(g.getClipBounds());
|
155
|
160
|
UIUtilities.paintBackground(g, getBounds(), backgroundImage,
|
156
|
161
|
backgroundOption);
|
157
|
|
- paintOntoGraphics(g);
|
|
162
|
+ if (staleCache) {
|
|
163
|
+ paintOntoGraphics(g);
|
|
164
|
+ staleCache = false;
|
|
165
|
+ } else {
|
|
166
|
+ for (Map.Entry<TextLayout, Point> entry : savedPositions
|
|
167
|
+ .entrySet()) {
|
|
168
|
+ g.setColor(textPane.getForeground());
|
|
169
|
+ entry.getKey().draw(g, (float) entry.getValue().getX(),
|
|
170
|
+ (float) entry.getValue().getY());
|
|
171
|
+ }
|
|
172
|
+ }
|
158
|
173
|
}
|
159
|
174
|
|
160
|
175
|
/**
|
161
|
176
|
* Re calculates positions of lines and repaints if required.
|
162
|
177
|
*/
|
163
|
178
|
protected void recalc() {
|
164
|
|
- if (isVisible()) {
|
165
|
|
- repaint();
|
166
|
|
- }
|
|
179
|
+ staleCache = true;
|
|
180
|
+ repaint();
|
167
|
181
|
}
|
168
|
182
|
|
169
|
183
|
/**
|
|
@@ -206,6 +220,7 @@ class TextPaneCanvas extends JPanel implements MouseInputListener,
|
206
|
220
|
|
207
|
221
|
textLayouts.clear();
|
208
|
222
|
positions.clear();
|
|
223
|
+ savedPositions.clear();
|
209
|
224
|
|
210
|
225
|
//check theres something to draw and theres some space to draw in
|
211
|
226
|
if (document.getNumLines() == 0 || formatWidth < 1) {
|
|
@@ -277,6 +292,8 @@ class TextPaneCanvas extends JPanel implements MouseInputListener,
|
277
|
292
|
g.setColor(textPane.getForeground());
|
278
|
293
|
|
279
|
294
|
layout.draw(g, drawPosX, drawPosY + layout.getDescent());
|
|
295
|
+ savedPositions.put(layout, new Point((int) drawPosX,
|
|
296
|
+ (int) (drawPosY + layout.getDescent())));
|
280
|
297
|
doHighlight(line, chars, layout, g, drawPosY, drawPosX);
|
281
|
298
|
firstVisibleLine = line;
|
282
|
299
|
textLayouts.put(layout, new LineInfo(line, numberOfWraps));
|