[log] Don't draw all references on the branches panel: limit by width

Otherwise repaint is slow if there are many refs.
Pass the maximum width to the RefPainter, and don't draw if further
refs would be invisible.

The problem affects only the BranchesPanel: other RefPainter clients
draw a limited amount of refs (only refs on the given commit).
They have other problems though which will be solved later.
This commit is contained in:
Kirill Likhodedov
2013-09-28 17:00:16 +04:00
parent 8f23cf02e9
commit f32fb52280
4 changed files with 8 additions and 4 deletions
@@ -72,7 +72,7 @@ public class BranchesPanel extends JPanel {
@Override
protected void paintComponent(Graphics g) {
myRefPositions = myRefPainter.draw((Graphics2D)g, myRefs, 0);
myRefPositions = myRefPainter.draw((Graphics2D)g, myRefs, 0, getWidth());
}
public void rebuild() {
@@ -182,7 +182,8 @@ class DetailsPanel extends JPanel implements ListSelectionListener {
@Override
protected void paintComponent(Graphics g) {
myRefPainter.draw((Graphics2D)g, myRefs, 0);
// TODO when the right margin reaches, draw on the second line
myRefPainter.draw((Graphics2D)g, myRefs, 0, getWidth());
}
void setRefs(@NotNull List<VcsRef> refs) {
@@ -90,7 +90,7 @@ public class GraphCommitCellRender implements TableCellRenderer {
VirtualFile root = refs.iterator().next().getRoot(); // all refs are from the same commit => they have the same root
refs = myDataHolder.getLogProvider(root).getReferenceManager().sort(refs);
}
refPainter.draw(g2, refs, padding);
refPainter.draw(g2, refs, padding, -1); // TODO think how to behave if there are too many refs here (even if tags are collapsed)
g.drawImage(image, 0, 0, null);
}
@@ -103,7 +103,7 @@ public class RefPainter {
return Math.round(p);
}
public Map<Integer, VcsRef> draw(@NotNull Graphics2D g2, @NotNull List<VcsRef> refs, int startPadding) {
public Map<Integer, VcsRef> draw(@NotNull Graphics2D g2, @NotNull List<VcsRef> refs, int startPadding, int maxWidth) {
float currentPadding = startPadding;
g2.setFont(DEFAULT_FONT);
g2.setStroke(new BasicStroke(1.5f));
@@ -114,6 +114,9 @@ public class RefPainter {
int x = draw(g2, ref, (int)currentPadding);
positions.put(x, ref);
currentPadding += paddingStr(ref.getName(), renderContext);
if (maxWidth > 0 && x >= maxWidth) {
break;
}
}
return positions;
}