forked from External/mage
Big refactoring
I used Intellij IDEA to automatically refactor code to achive 3 goals. 1) get rid of anonymouse classes, and replace the with lamba to get more readeable and clean code (like in TableWaitingDialog). 2) make effectively final variables actually final to avoid inadvertent changes on it in further releases and keep objects as immutable, as possible. 3) Get rid of unused imports (most of the changes) in whole project classes.
This commit is contained in:
parent
a9f2c8c407
commit
076840df53
247 changed files with 1919 additions and 3682 deletions
|
|
@ -7,8 +7,6 @@ import java.awt.event.MouseEvent;
|
|||
import java.awt.event.MouseWheelEvent;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
|
@ -177,24 +175,21 @@ public class MageActionCallback implements ActionCallback {
|
|||
|
||||
public void showPopup(final Component popupContainer, final Component infoPane) throws InterruptedException {
|
||||
final Component c = MageFrame.getUI().getComponent(MageComponents.DESKTOP_PANE);
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!popupTextWindowOpen
|
||||
|| !enlargedWindowState.equals(EnlargedWindowState.CLOSED)) {
|
||||
return;
|
||||
}
|
||||
if (data.locationOnScreen == null) {
|
||||
data.locationOnScreen = data.component.getLocationOnScreen();
|
||||
}
|
||||
|
||||
Point location = new Point((int) data.locationOnScreen.getX() + data.popupOffsetX - 40, (int) data.locationOnScreen.getY() + data.popupOffsetY - 40);
|
||||
location = GuiDisplayUtil.keepComponentInsideParent(location, parentPoint, infoPane, parentComponent);
|
||||
location.translate(-parentPoint.x, -parentPoint.y);
|
||||
popupContainer.setLocation(location);
|
||||
popupContainer.setVisible(true);
|
||||
c.repaint();
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
if (!popupTextWindowOpen
|
||||
|| !enlargedWindowState.equals(EnlargedWindowState.CLOSED)) {
|
||||
return;
|
||||
}
|
||||
if (data.locationOnScreen == null) {
|
||||
data.locationOnScreen = data.component.getLocationOnScreen();
|
||||
}
|
||||
|
||||
Point location = new Point((int) data.locationOnScreen.getX() + data.popupOffsetX - 40, (int) data.locationOnScreen.getY() + data.popupOffsetY - 40);
|
||||
location = GuiDisplayUtil.keepComponentInsideParent(location, parentPoint, infoPane, parentComponent);
|
||||
location.translate(-parentPoint.x, -parentPoint.y);
|
||||
popupContainer.setLocation(location);
|
||||
popupContainer.setVisible(true);
|
||||
c.repaint();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
@ -257,7 +252,7 @@ public class MageActionCallback implements ActionCallback {
|
|||
if (this.startedDragging && prevCardPanel != null && card != null) {
|
||||
for (Component component : card.getCardArea().getComponents()) {
|
||||
if (component instanceof CardPanel) {
|
||||
if (cardPanels.contains((CardPanel) component)) {
|
||||
if (cardPanels.contains(component)) {
|
||||
component.setLocation(component.getLocation().x, component.getLocation().y - GO_DOWN_ON_DRAG_Y_OFFSET);
|
||||
}
|
||||
}
|
||||
|
|
@ -331,7 +326,7 @@ public class MageActionCallback implements ActionCallback {
|
|||
for (Component component : container.getComponents()) {
|
||||
if (component instanceof CardPanel) {
|
||||
if (!component.equals(card)) {
|
||||
if (!cardPanels.contains((CardPanel) component)) {
|
||||
if (!cardPanels.contains(component)) {
|
||||
component.setLocation(component.getLocation().x, component.getLocation().y + GO_DOWN_ON_DRAG_Y_OFFSET);
|
||||
}
|
||||
cardPanels.add((CardPanel) component);
|
||||
|
|
@ -347,12 +342,7 @@ public class MageActionCallback implements ActionCallback {
|
|||
private void sortLayout(List<CardPanel> cards, CardPanel source, boolean includeSource) {
|
||||
source.getLocation().x -= COMPARE_GAP_X; // this creates nice effect
|
||||
|
||||
Collections.sort(cards, new Comparator<CardPanel>() {
|
||||
@Override
|
||||
public int compare(CardPanel cp1, CardPanel cp2) {
|
||||
return Integer.valueOf(cp1.getLocation().x).compareTo(cp2.getLocation().x);
|
||||
}
|
||||
});
|
||||
cards.sort((cp1, cp2) -> Integer.valueOf(cp1.getLocation().x).compareTo(cp2.getLocation().x));
|
||||
|
||||
int dx = 0;
|
||||
boolean createdGapForSource = false;
|
||||
|
|
@ -540,78 +530,75 @@ public class MageActionCallback implements ActionCallback {
|
|||
}
|
||||
|
||||
private void displayEnlargedCard(final CardView cardView, final TransferData transferData) {
|
||||
ThreadUtils.threadPool3.submit(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (cardView == null) {
|
||||
ThreadUtils.threadPool3.submit(() -> {
|
||||
if (cardView == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
if (enlargedWindowState.equals(EnlargedWindowState.CLOSED)) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
if (enlargedWindowState.equals(EnlargedWindowState.CLOSED)) {
|
||||
return;
|
||||
|
||||
MageComponents mageComponentCardPreviewContainer;
|
||||
MageComponents mageComponentCardPreviewPane;
|
||||
if (cardView.isToRotate()) {
|
||||
if (enlargedWindowState.equals(EnlargedWindowState.NORMAL)) {
|
||||
hideEnlargedCard();
|
||||
enlargedWindowState = EnlargedWindowState.ROTATED;
|
||||
}
|
||||
|
||||
MageComponents mageComponentCardPreviewContainer;
|
||||
MageComponents mageComponentCardPreviewPane;
|
||||
if (cardView.isToRotate()) {
|
||||
if (enlargedWindowState.equals(EnlargedWindowState.NORMAL)) {
|
||||
hideEnlargedCard();
|
||||
enlargedWindowState = EnlargedWindowState.ROTATED;
|
||||
}
|
||||
mageComponentCardPreviewContainer = MageComponents.CARD_PREVIEW_CONTAINER_ROTATED;
|
||||
mageComponentCardPreviewPane = MageComponents.CARD_PREVIEW_PANE_ROTATED;
|
||||
} else {
|
||||
if (enlargedWindowState.equals(EnlargedWindowState.ROTATED)) {
|
||||
hideEnlargedCard();
|
||||
enlargedWindowState = EnlargedWindowState.NORMAL;
|
||||
}
|
||||
mageComponentCardPreviewContainer = MageComponents.CARD_PREVIEW_CONTAINER;
|
||||
mageComponentCardPreviewPane = MageComponents.CARD_PREVIEW_PANE;
|
||||
mageComponentCardPreviewContainer = MageComponents.CARD_PREVIEW_CONTAINER_ROTATED;
|
||||
mageComponentCardPreviewPane = MageComponents.CARD_PREVIEW_PANE_ROTATED;
|
||||
} else {
|
||||
if (enlargedWindowState.equals(EnlargedWindowState.ROTATED)) {
|
||||
hideEnlargedCard();
|
||||
enlargedWindowState = EnlargedWindowState.NORMAL;
|
||||
}
|
||||
final Component popupContainer = MageFrame.getUI().getComponent(mageComponentCardPreviewContainer);
|
||||
Component cardPreviewPane = MageFrame.getUI().getComponent(mageComponentCardPreviewPane);
|
||||
Component parentComponent = SwingUtilities.getRoot(transferData.component);
|
||||
if (cardPreviewPane != null && parentComponent != null) {
|
||||
Point parentPoint = parentComponent.getLocationOnScreen();
|
||||
transferData.locationOnScreen = transferData.component.getLocationOnScreen();
|
||||
Point location = new Point((int) transferData.locationOnScreen.getX() + transferData.popupOffsetX - 40, (int) transferData.locationOnScreen.getY() + transferData.popupOffsetY - 40);
|
||||
location = GuiDisplayUtil.keepComponentInsideParent(location, parentPoint, cardPreviewPane, parentComponent);
|
||||
location.translate(-parentPoint.x, -parentPoint.y);
|
||||
popupContainer.setLocation(location);
|
||||
popupContainer.setVisible(true);
|
||||
|
||||
MageCard mageCard = (MageCard) transferData.component;
|
||||
Image image = null;
|
||||
switch (enlargeMode) {
|
||||
case COPY:
|
||||
if (cardView instanceof PermanentView) {
|
||||
image = ImageCache.getImageOriginal(((PermanentView) cardView).getOriginal());
|
||||
}
|
||||
break;
|
||||
case ALTERNATE:
|
||||
if (cardView.getAlternateName() != null) {
|
||||
if (cardView instanceof PermanentView && !cardView.isFlipCard() && !cardView.canTransform() && ((PermanentView) cardView).isCopy()) {
|
||||
image = ImageCache.getImageOriginal(((PermanentView) cardView).getOriginal());
|
||||
} else {
|
||||
image = ImageCache.getImageOriginalAlternateName(cardView);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (image == null) {
|
||||
image = mageCard.getImage();
|
||||
}
|
||||
// shows the card in the popup Container
|
||||
BigCard bigCard = (BigCard) cardPreviewPane;
|
||||
displayCardInfo(mageCard, image, bigCard);
|
||||
|
||||
} else {
|
||||
LOGGER.warn("No Card preview Pane in Mage Frame defined. Card: " + cardView.getName());
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
LOGGER.warn("Problem dring display of enlarged card", e);
|
||||
mageComponentCardPreviewContainer = MageComponents.CARD_PREVIEW_CONTAINER;
|
||||
mageComponentCardPreviewPane = MageComponents.CARD_PREVIEW_PANE;
|
||||
}
|
||||
final Component popupContainer = MageFrame.getUI().getComponent(mageComponentCardPreviewContainer);
|
||||
Component cardPreviewPane = MageFrame.getUI().getComponent(mageComponentCardPreviewPane);
|
||||
Component parentComponent = SwingUtilities.getRoot(transferData.component);
|
||||
if (cardPreviewPane != null && parentComponent != null) {
|
||||
Point parentPoint = parentComponent.getLocationOnScreen();
|
||||
transferData.locationOnScreen = transferData.component.getLocationOnScreen();
|
||||
Point location = new Point((int) transferData.locationOnScreen.getX() + transferData.popupOffsetX - 40, (int) transferData.locationOnScreen.getY() + transferData.popupOffsetY - 40);
|
||||
location = GuiDisplayUtil.keepComponentInsideParent(location, parentPoint, cardPreviewPane, parentComponent);
|
||||
location.translate(-parentPoint.x, -parentPoint.y);
|
||||
popupContainer.setLocation(location);
|
||||
popupContainer.setVisible(true);
|
||||
|
||||
MageCard mageCard = (MageCard) transferData.component;
|
||||
Image image = null;
|
||||
switch (enlargeMode) {
|
||||
case COPY:
|
||||
if (cardView instanceof PermanentView) {
|
||||
image = ImageCache.getImageOriginal(((PermanentView) cardView).getOriginal());
|
||||
}
|
||||
break;
|
||||
case ALTERNATE:
|
||||
if (cardView.getAlternateName() != null) {
|
||||
if (cardView instanceof PermanentView && !cardView.isFlipCard() && !cardView.canTransform() && ((PermanentView) cardView).isCopy()) {
|
||||
image = ImageCache.getImageOriginal(((PermanentView) cardView).getOriginal());
|
||||
} else {
|
||||
image = ImageCache.getImageOriginalAlternateName(cardView);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (image == null) {
|
||||
image = mageCard.getImage();
|
||||
}
|
||||
// shows the card in the popup Container
|
||||
BigCard bigCard = (BigCard) cardPreviewPane;
|
||||
displayCardInfo(mageCard, image, bigCard);
|
||||
|
||||
} else {
|
||||
LOGGER.warn("No Card preview Pane in Mage Frame defined. Card: " + cardView.getName());
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
LOGGER.warn("Problem dring display of enlarged card", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -637,12 +624,7 @@ public class MageActionCallback implements ActionCallback {
|
|||
|
||||
private synchronized void startHideTimeout() {
|
||||
cancelTimeout();
|
||||
hideTimeout = timeoutExecutor.schedule(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
hideEnlargedCard();
|
||||
}
|
||||
}, 700, TimeUnit.MILLISECONDS);
|
||||
hideTimeout = timeoutExecutor.schedule(this::hideEnlargedCard, 700, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
private synchronized void cancelTimeout() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue