Update legality panel to use new ICardsTableListener so that card image is displayed on selection in DecksScreen.
parent
2baa79f91e
commit
651fdd302a
|
@ -175,10 +175,6 @@ class MainViewsPanel extends JPanel
|
|||
LegalityPanel.CP_CARD_SELECTED,
|
||||
evt -> deckPanel.setSelectedCard(legalityPanel.getSelectedCard())
|
||||
);
|
||||
legalityPanel.addPropertyChangeListener(
|
||||
LegalityPanel.CP_CARD_DCLICKED,
|
||||
evt -> deckPanel.setSelectedCard(legalityPanel.getSelectedCard())
|
||||
);
|
||||
}
|
||||
|
||||
private void doAddCardToDeck(final MagicCardDefinition card) {
|
||||
|
|
|
@ -130,6 +130,7 @@ public class DeckViewsPanel extends JPanel implements IPwlWorkerListener {
|
|||
|
||||
public void setCardsTableListeners(ICardsTableListener... listeners) {
|
||||
deckPanel.setCardsTableListeners(listeners);
|
||||
legalityPanel.setCardsTableListeners(listeners);
|
||||
}
|
||||
|
||||
public void setSelectedCard(MagicCardDefinition card) {
|
||||
|
|
|
@ -8,6 +8,9 @@ import java.awt.Graphics2D;
|
|||
import java.awt.RenderingHints;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JLabel;
|
||||
|
@ -25,10 +28,11 @@ import magic.data.MagicFormat;
|
|||
import magic.data.MagicIcon;
|
||||
import magic.model.MagicCardDefinition;
|
||||
import magic.model.MagicDeck;
|
||||
import magic.ui.MagicImages;
|
||||
import magic.translate.MText;
|
||||
import magic.translate.StringContext;
|
||||
import magic.ui.FontsAndBorders;
|
||||
import magic.ui.MagicImages;
|
||||
import magic.ui.screen.decks.ICardsTableListener;
|
||||
import magic.ui.widget.M.MScrollPane;
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
|
||||
|
@ -45,8 +49,6 @@ public class CardsLegalityPanel extends JPanel {
|
|||
|
||||
// fired when selection changes.
|
||||
public static final String CP_CARD_SELECTED = "019f0246-bd63-4efd-a7cf-fefabea053e3";
|
||||
// fired on mouse event.
|
||||
public static final String CP_CARD_DCLICKED = "02bd98e4-fccf-4152-bcef-c5ea85c5313b";
|
||||
|
||||
private static final Color GRID_COLOR = new Color(194, 197, 203);
|
||||
private static final int ROW_HEIGHT = 23; //pixels
|
||||
|
@ -59,6 +61,7 @@ public class CardsLegalityPanel extends JPanel {
|
|||
private int lastSelectedRow = -1;
|
||||
private final JLabel titleLabel;
|
||||
private MagicFormat magicFormat;
|
||||
private final List<ICardsTableListener> listeners = new ArrayList<>();
|
||||
|
||||
public CardsLegalityPanel() {
|
||||
|
||||
|
@ -121,22 +124,42 @@ public class CardsLegalityPanel extends JPanel {
|
|||
public void valueChanged(ListSelectionEvent e) {
|
||||
isAdjusting = e.getValueIsAdjusting();
|
||||
if (!isAdjusting) {
|
||||
firePropertyChange(CP_CARD_SELECTED, false, true);
|
||||
lastSelectedRow = table.getSelectedRow();
|
||||
notifyCardSelected(tableModel.getCardDef(lastSelectedRow));
|
||||
firePropertyChange(CP_CARD_SELECTED, false, true);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void notifyOnLeftClick(MagicCardDefinition card) {
|
||||
for (ICardsTableListener listener : listeners) {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
listener.onLeftClick(card);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void notifyOnRightClick(MagicCardDefinition card) {
|
||||
for (ICardsTableListener listener : listeners) {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
listener.onRightClick(card);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private MouseAdapter getTableMouseAdapter() {
|
||||
return new MouseAdapter() {
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
if (!isAdjusting) {
|
||||
int mouseRow = table.rowAtPoint(e.getPoint());
|
||||
MagicCardDefinition card = tableModel.getCardDef(mouseRow);
|
||||
card = card == null ? MagicCardDefinition.UNKNOWN : card;
|
||||
if (SwingUtilities.isLeftMouseButton(e)) {
|
||||
if (hasDoubleClickListeners() && e.getClickCount() == 2) {
|
||||
firePropertyChange(CP_CARD_DCLICKED, false, true);
|
||||
}
|
||||
notifyOnLeftClick(card);
|
||||
} else if (SwingUtilities.isRightMouseButton(e)) {
|
||||
notifyOnRightClick(card);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -197,10 +220,6 @@ public class CardsLegalityPanel extends JPanel {
|
|||
}
|
||||
}
|
||||
|
||||
private boolean hasDoubleClickListeners() {
|
||||
return getPropertyChangeListeners(CP_CARD_DCLICKED).length > 0;
|
||||
}
|
||||
|
||||
private static class LegalityCellRenderer extends DefaultTableCellRenderer {
|
||||
|
||||
private static final JLabel BANNED_ICON = new JLabel(MagicImages.getIcon(MagicIcon.BANNED));
|
||||
|
@ -268,4 +287,16 @@ public class CardsLegalityPanel extends JPanel {
|
|||
}
|
||||
}
|
||||
|
||||
private void notifyCardSelected(MagicCardDefinition card) {
|
||||
for (ICardsTableListener listener : listeners) {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
listener.onCardSelected(card == null ? MagicCardDefinition.UNKNOWN : card);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void setCardsTableListeners(ICardsTableListener[] listeners) {
|
||||
this.listeners.clear();
|
||||
this.listeners.addAll(Arrays.asList(listeners));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ import magic.model.MagicDeck;
|
|||
import magic.translate.MText;
|
||||
import magic.ui.MagicImages;
|
||||
import magic.ui.screen.deck.editor.IDeckEditorView;
|
||||
import magic.ui.screen.decks.ICardsTableListener;
|
||||
import magic.ui.screen.decks.IDeckView;
|
||||
import magic.ui.screen.widget.ActionBarButton;
|
||||
import magic.ui.widget.TexturedPanel;
|
||||
|
@ -37,7 +38,6 @@ public class LegalityPanel extends JPanel
|
|||
|
||||
// fired when card selection changes
|
||||
public static final String CP_CARD_SELECTED = "c5f420c3-dc1c-4d1b-a07b-0d055716207d";
|
||||
public static final String CP_CARD_DCLICKED = "0dda4041-f44d-4980-8c87-c11cf7b1dc06";
|
||||
|
||||
private static final JPanel HELP_PANEL = new LegalityLegendPanel();
|
||||
|
||||
|
@ -67,14 +67,6 @@ public class LegalityPanel extends JPanel
|
|||
firePropertyChange(CP_CARD_SELECTED, false, true);
|
||||
}
|
||||
});
|
||||
cardsLegalityPanel.addPropertyChangeListener(
|
||||
CardsLegalityPanel.CP_CARD_DCLICKED,
|
||||
new PropertyChangeListener() {
|
||||
@Override
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
firePropertyChange(CP_CARD_DCLICKED, false, true);
|
||||
}
|
||||
});
|
||||
formatsLegalityPanel.addPropertyChangeListener(
|
||||
FormatsLegalityPanel.CP_FORMAT_SELECTED,
|
||||
new PropertyChangeListener() {
|
||||
|
@ -163,4 +155,8 @@ public class LegalityPanel extends JPanel
|
|||
|
||||
}
|
||||
|
||||
public void setCardsTableListeners(ICardsTableListener[] listeners) {
|
||||
cardsLegalityPanel.setCardsTableListeners(listeners);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue