try to do fewer layout calculations when moving cards

This commit is contained in:
Peter F. Patel-Schneider
2019-02-02 16:46:23 -05:00
parent 30607291fc
commit 31bca6c614
2 changed files with 29 additions and 17 deletions

View File

@@ -291,6 +291,9 @@ public abstract class CardPanelContainer extends SkinnedPanel {
}
public final void removeCardPanel(final CardPanel fromPanel) {
removeCardPanel(fromPanel,true);
}
public final void removeCardPanel(final CardPanel fromPanel, final boolean repaint) {
FThreads.assertExecutedByEdt(true);
if (getMouseDragPanel() != null) {
CardPanel.getDragAnimationPanel().setVisible(false);
@@ -303,10 +306,12 @@ public abstract class CardPanelContainer extends SkinnedPanel {
fromPanel.dispose();
getCardPanels().remove(fromPanel);
remove(fromPanel);
if ( repaint ) {
invalidate();
repaint();
doingLayout();
}
}
public final void setCardPanels(final List<CardPanel> cardPanels) {
if (cardPanels.size() == 0) {
@@ -332,17 +337,22 @@ public abstract class CardPanelContainer extends SkinnedPanel {
}
public final void clear() {
clear(true);
}
public final void clear(final boolean repaint) {
FThreads.assertExecutedByEdt(true);
for (final CardPanel p : getCardPanels()) {
p.dispose();
}
getCardPanels().clear();
removeAll();
if ( repaint ) {
setPreferredSize(new Dimension(0, 0));
invalidate();
getParent().validate();
repaint();
}
}
public final FScrollPane getScrollPane() {
return this.scrollPane;

View File

@@ -620,11 +620,11 @@ public class PlayArea extends CardPanelContainer implements CardPanelMouseListen
toDelete.removeAll(notToDelete);
if (toDelete.size() == getCardPanels().size()) {
clear();
clear(false);
}
else {
for (final CardView card : toDelete) {
removeCardPanel(getCardPanel(card.getId()));
removeCardPanel(getCardPanel(card.getId()),false);
}
}
@@ -650,14 +650,16 @@ public class PlayArea extends CardPanelContainer implements CardPanelMouseListen
doLayout();
}
invalidate(); //pfps do the extra invalidate before any scrolling
if (!newPanels.isEmpty()) {
int i = newPanels.size();
for (final CardPanel toPanel : newPanels) {
if ( --i == 0 ) { // only scroll to last panel to be added
scrollRectToVisible(new Rectangle(toPanel.getCardX(), toPanel.getCardY(), toPanel.getCardWidth(), toPanel.getCardHeight()));
}
Animation.moveCard(toPanel);
}
}
invalidate();
repaint();
}