Преглед на файлове

Cache positions of lines for faster repaints.

Change-Id: I1b40e3d6c48bf245a00b895ccd82ed16a1b849bf
Reviewed-on: http://gerrit.dmdirc.com/1512
Reviewed-by: Chris Smith <chris@dmdirc.com>
Automatic-Compile: Gregory Holmes <greg@dmdirc.com>
tags/0.6.5
Greg Holmes преди 13 години
родител
ревизия
0601199033
променени са 1 файла, в които са добавени 21 реда и са изтрити 4 реда
  1. 21
    4
      src/com/dmdirc/addons/ui_swing/textpane/TextPaneCanvas.java

+ 21
- 4
src/com/dmdirc/addons/ui_swing/textpane/TextPaneCanvas.java Целия файл

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

Loading…
Отказ
Запис