mirror of
https://github.com/correl/mage.git
synced 2024-12-24 11:50:45 +00:00
UI: added card viewer update on server connection (on new release);
This commit is contained in:
parent
f778d95f54
commit
264d81305e
1 changed files with 34 additions and 24 deletions
|
@ -1,27 +1,19 @@
|
|||
|
||||
package mage.client.deckeditor.collection.viewer;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.GridBagLayout;
|
||||
import javax.swing.Box;
|
||||
import javax.swing.BoxLayout;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JScrollPane;
|
||||
import mage.cards.repository.ExpansionRepository;
|
||||
import mage.cards.repository.RepositoryEvent;
|
||||
import mage.client.MageFrame;
|
||||
import mage.client.cards.BigCard;
|
||||
import mage.client.dialog.PreferencesDialog;
|
||||
import mage.client.plugins.impl.Plugins;
|
||||
import mage.client.util.gui.FastSearchUtil;
|
||||
import mage.client.util.sets.ConstructedFormats;
|
||||
import mage.game.events.Listener;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* Pane with big card and mage book.
|
||||
*
|
||||
|
@ -33,6 +25,7 @@ public final class CollectionViewerPanel extends JPanel {
|
|||
|
||||
protected static final String LAYOYT_CONFIG_KEY = "collectionViewerLayoutConfig";
|
||||
private static final String FORMAT_CONFIG_KEY = "collectionViewerFormat";
|
||||
private static Listener<RepositoryEvent> setsDbListener = null;
|
||||
|
||||
public CollectionViewerPanel() {
|
||||
initComponents();
|
||||
|
@ -49,6 +42,12 @@ public final class CollectionViewerPanel extends JPanel {
|
|||
this.bigCard = null;
|
||||
}
|
||||
|
||||
private void reloadFormatCombobox() {
|
||||
DefaultComboBoxModel model = new DefaultComboBoxModel<>(ConstructedFormats.getTypes());
|
||||
formats.setModel(model);
|
||||
formats.setSelectedItem(ConstructedFormats.getDefault());
|
||||
}
|
||||
|
||||
public void initComponents() {
|
||||
buttonsPanel = new javax.swing.JPanel();
|
||||
buttonsPanel.setOpaque(false);
|
||||
|
@ -74,8 +73,27 @@ public final class CollectionViewerPanel extends JPanel {
|
|||
setPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
|
||||
buttonsPanel.add(setPanel);
|
||||
// combo set
|
||||
formats = new JComboBox<>(ConstructedFormats.getTypes());
|
||||
formats.setSelectedItem(ConstructedFormats.getDefault());
|
||||
formats = new JComboBox<>();
|
||||
reloadFormatCombobox();
|
||||
// auto-update sets list on changes
|
||||
setsDbListener = new Listener<RepositoryEvent>() {
|
||||
@Override
|
||||
public void event(RepositoryEvent event) {
|
||||
if (event.getEventType().equals(RepositoryEvent.RepositoryEventType.DB_UPDATED)) {
|
||||
reloadFormatCombobox();
|
||||
}
|
||||
}
|
||||
};
|
||||
ExpansionRepository.instance.subscribe(setsDbListener);
|
||||
// update cards on format combobox changes
|
||||
formats.addActionListener(e -> {
|
||||
if (mageBook != null) {
|
||||
String format = (String) formats.getSelectedItem();
|
||||
MageFrame.getPreferences().put(CollectionViewerPanel.FORMAT_CONFIG_KEY, format);
|
||||
mageBook.updateDispayedSets(format);
|
||||
}
|
||||
});
|
||||
|
||||
formats.setAlignmentX(0.0F);
|
||||
formats.setMinimumSize(new Dimension(50, 25));
|
||||
formats.setPreferredSize(new Dimension(50, 25));
|
||||
|
@ -155,14 +173,6 @@ public final class CollectionViewerPanel extends JPanel {
|
|||
cardsOrTokens.addActionListener(e -> mageBook.cardsOrTokens(cardsOrTokens.isSelected()));
|
||||
buttonsPanel.add(cardsOrTokens);
|
||||
|
||||
formats.addActionListener(e -> {
|
||||
if (mageBook != null) {
|
||||
String format = (String) formats.getSelectedItem();
|
||||
MageFrame.getPreferences().put(CollectionViewerPanel.FORMAT_CONFIG_KEY, format);
|
||||
mageBook.updateDispayedSets(format);
|
||||
}
|
||||
});
|
||||
|
||||
buttonsPanel.add(Box.createVerticalGlue());
|
||||
|
||||
bigCard.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
|
||||
|
|
Loading…
Reference in a new issue