mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-15 18:28:00 +00:00
Add new shared options to show Unique Cards Only in ItemList and Image views
This commit is contained in:
@@ -28,6 +28,8 @@ import javax.swing.JPanel;
|
|||||||
import javax.swing.JViewport;
|
import javax.swing.JViewport;
|
||||||
import javax.swing.ScrollPaneConstants;
|
import javax.swing.ScrollPaneConstants;
|
||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
|
import javax.swing.event.ChangeEvent;
|
||||||
|
import javax.swing.event.ChangeListener;
|
||||||
|
|
||||||
import forge.ImageCache;
|
import forge.ImageCache;
|
||||||
import forge.assets.FSkinProp;
|
import forge.assets.FSkinProp;
|
||||||
@@ -46,15 +48,10 @@ import forge.itemmanager.SItemManagerUtil;
|
|||||||
import forge.model.FModel;
|
import forge.model.FModel;
|
||||||
import forge.properties.ForgePreferences;
|
import forge.properties.ForgePreferences;
|
||||||
import forge.screens.match.controllers.CDetailPicture;
|
import forge.screens.match.controllers.CDetailPicture;
|
||||||
import forge.toolbox.FComboBoxWrapper;
|
import forge.toolbox.*;
|
||||||
import forge.toolbox.FLabel;
|
|
||||||
import forge.toolbox.FMouseAdapter;
|
|
||||||
import forge.toolbox.FScrollPane;
|
|
||||||
import forge.toolbox.FSkin;
|
|
||||||
import forge.toolbox.FSkin.SkinColor;
|
import forge.toolbox.FSkin.SkinColor;
|
||||||
import forge.toolbox.FSkin.SkinFont;
|
import forge.toolbox.FSkin.SkinFont;
|
||||||
import forge.toolbox.FSkin.SkinImage;
|
import forge.toolbox.FSkin.SkinImage;
|
||||||
import forge.toolbox.FTextField;
|
|
||||||
import forge.toolbox.special.CardZoomer;
|
import forge.toolbox.special.CardZoomer;
|
||||||
import forge.util.Localizer;
|
import forge.util.Localizer;
|
||||||
import forge.view.arcane.CardPanel;
|
import forge.view.arcane.CardPanel;
|
||||||
@@ -84,7 +81,6 @@ public class ImageView<T extends InventoryItem> extends ItemView<T> {
|
|||||||
private ItemInfo focalItem;
|
private ItemInfo focalItem;
|
||||||
private final List<ItemInfo> orderedItems = new ArrayList<ItemInfo>();
|
private final List<ItemInfo> orderedItems = new ArrayList<ItemInfo>();
|
||||||
private final List<Group> groups = new ArrayList<Group>();
|
private final List<Group> groups = new ArrayList<Group>();
|
||||||
final Localizer localizer = Localizer.getInstance();
|
|
||||||
|
|
||||||
private static boolean isPreferenceEnabled(final ForgePreferences.FPref preferenceName) {
|
private static boolean isPreferenceEnabled(final ForgePreferences.FPref preferenceName) {
|
||||||
return FModel.getPreferences().getPrefBoolean(preferenceName);
|
return FModel.getPreferences().getPrefBoolean(preferenceName);
|
||||||
@@ -211,14 +207,6 @@ public class ImageView<T extends InventoryItem> extends ItemView<T> {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
getPnlOptions().add(btnExpandCollapseAll, "w " + FTextField.HEIGHT + "px, h " + FTextField.HEIGHT + "px");
|
|
||||||
getPnlOptions().add(new FLabel.Builder().text(localizer.getMessage("lblGroupby") +":").fontSize(12).build());
|
|
||||||
cbGroupByOptions.addTo(getPnlOptions(), "pushx, growx");
|
|
||||||
getPnlOptions().add(new FLabel.Builder().text(localizer.getMessage("lblPileby") +":").fontSize(12).build());
|
|
||||||
cbPileByOptions.addTo(getPnlOptions(), "pushx, growx");
|
|
||||||
getPnlOptions().add(new FLabel.Builder().text(localizer.getMessage("lblColumns") +":").fontSize(12).build());
|
|
||||||
cbColumnCount.addTo(getPnlOptions(), "w 38px!");
|
|
||||||
|
|
||||||
//setup display
|
//setup display
|
||||||
display = new CardViewDisplay();
|
display = new CardViewDisplay();
|
||||||
display.addMouseListener(new FMouseAdapter() {
|
display.addMouseListener(new FMouseAdapter() {
|
||||||
@@ -349,11 +337,28 @@ public class ImageView<T extends InventoryItem> extends ItemView<T> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setup(ItemManagerConfig config, Map<ColumnDef, ItemTableColumn> colOverrides) {
|
public void setup(ItemManagerConfig config, Map<ColumnDef, ItemTableColumn> colOverrides) {
|
||||||
|
setPanelOptions(config.getShowUniqueCardsOption());
|
||||||
setGroupBy(config.getGroupBy(), true);
|
setGroupBy(config.getGroupBy(), true);
|
||||||
setPileBy(config.getPileBy(), true);
|
setPileBy(config.getPileBy(), true);
|
||||||
setColumnCount(config.getImageColumnCount(), true);
|
setColumnCount(config.getImageColumnCount(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setPanelOptions(boolean showUniqueCardsOption) {
|
||||||
|
// Collapse all groups first
|
||||||
|
getPnlOptions().add(btnExpandCollapseAll, "w " + FTextField.HEIGHT + "px, h " + FTextField.HEIGHT + "px");
|
||||||
|
// Show Unique Cards Only Option
|
||||||
|
if (showUniqueCardsOption) {
|
||||||
|
setUniqueCardsOnlyFilter();
|
||||||
|
}
|
||||||
|
// GroupBy, Pile by, Columns
|
||||||
|
getPnlOptions().add(new FLabel.Builder().text(localizer.getMessage("lblGroupby") +":").fontSize(12).build());
|
||||||
|
cbGroupByOptions.addTo(getPnlOptions(), "pushx, growx");
|
||||||
|
getPnlOptions().add(new FLabel.Builder().text(localizer.getMessage("lblPileby") +":").fontSize(12).build());
|
||||||
|
cbPileByOptions.addTo(getPnlOptions(), "pushx, growx");
|
||||||
|
getPnlOptions().add(new FLabel.Builder().text(localizer.getMessage("lblColumns") +":").fontSize(12).build());
|
||||||
|
cbColumnCount.addTo(getPnlOptions(), "w 38px!");
|
||||||
|
}
|
||||||
|
|
||||||
public GroupDef getGroupBy() {
|
public GroupDef getGroupBy() {
|
||||||
return groupBy;
|
return groupBy;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -109,7 +109,6 @@ public final class ItemListView<T extends InventoryItem> extends ItemView<T> {
|
|||||||
|
|
||||||
private final ItemTable table = new ItemTable();
|
private final ItemTable table = new ItemTable();
|
||||||
private final ItemTableModel tableModel;
|
private final ItemTableModel tableModel;
|
||||||
final Localizer localizer = Localizer.getInstance();
|
|
||||||
public ItemTableModel getTableModel() {
|
public ItemTableModel getTableModel() {
|
||||||
return this.tableModel;
|
return this.tableModel;
|
||||||
}
|
}
|
||||||
@@ -177,22 +176,7 @@ public final class ItemListView<T extends InventoryItem> extends ItemView<T> {
|
|||||||
getPnlOptions().removeAll();
|
getPnlOptions().removeAll();
|
||||||
|
|
||||||
if (config.getShowUniqueCardsOption()) {
|
if (config.getShowUniqueCardsOption()) {
|
||||||
final FCheckBox chkBox = new FCheckBox(localizer.getMessage("lblUniqueCardsOnly"), this.itemManager.getWantUnique());
|
this.setUniqueCardsOnlyFilter();
|
||||||
chkBox.setFont(ROW_FONT);
|
|
||||||
chkBox.setToolTipText("Toggle whether to show unique cards only");
|
|
||||||
chkBox.addChangeListener(new ChangeListener() {
|
|
||||||
@Override public void stateChanged(final ChangeEvent arg0) {
|
|
||||||
final boolean wantUnique = chkBox.isSelected();
|
|
||||||
if (itemManager.getWantUnique() == wantUnique) { return; }
|
|
||||||
itemManager.setWantUnique(wantUnique);
|
|
||||||
itemManager.refresh();
|
|
||||||
|
|
||||||
if (itemManager.getConfig() != null) {
|
|
||||||
itemManager.getConfig().setUniqueCardsOnly(wantUnique);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
getPnlOptions().add(chkBox);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int modelIndex = 0;
|
int modelIndex = 0;
|
||||||
@@ -203,7 +187,7 @@ public final class ItemListView<T extends InventoryItem> extends ItemView<T> {
|
|||||||
if (!hideHeader) {
|
if (!hideHeader) {
|
||||||
final FCheckBox chkBox = new FCheckBox(StringUtils.isEmpty(col.getShortName()) ?
|
final FCheckBox chkBox = new FCheckBox(StringUtils.isEmpty(col.getShortName()) ?
|
||||||
col.getLongName() : col.getShortName(), col.isVisible());
|
col.getLongName() : col.getShortName(), col.isVisible());
|
||||||
chkBox.setFont(ROW_FONT);
|
chkBox.setFont(ItemView.ROW_FONT);
|
||||||
chkBox.setToolTipText(col.getLongName());
|
chkBox.setToolTipText(col.getLongName());
|
||||||
chkBox.addChangeListener(new ChangeListener() {
|
chkBox.addChangeListener(new ChangeListener() {
|
||||||
@Override public void stateChanged(final ChangeEvent arg0) {
|
@Override public void stateChanged(final ChangeEvent arg0) {
|
||||||
|
|||||||
@@ -28,9 +28,13 @@ import javax.swing.ScrollPaneConstants;
|
|||||||
import javax.swing.SwingConstants;
|
import javax.swing.SwingConstants;
|
||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
import javax.swing.Timer;
|
import javax.swing.Timer;
|
||||||
|
import javax.swing.event.ChangeEvent;
|
||||||
|
import javax.swing.event.ChangeListener;
|
||||||
import javax.swing.event.ListSelectionEvent;
|
import javax.swing.event.ListSelectionEvent;
|
||||||
import javax.swing.event.ListSelectionListener;
|
import javax.swing.event.ListSelectionListener;
|
||||||
|
|
||||||
|
import forge.toolbox.*;
|
||||||
|
import forge.util.Localizer;
|
||||||
import net.miginfocom.swing.MigLayout;
|
import net.miginfocom.swing.MigLayout;
|
||||||
|
|
||||||
import org.apache.commons.lang3.CharUtils;
|
import org.apache.commons.lang3.CharUtils;
|
||||||
@@ -41,17 +45,16 @@ import forge.itemmanager.ColumnDef;
|
|||||||
import forge.itemmanager.ItemManager;
|
import forge.itemmanager.ItemManager;
|
||||||
import forge.itemmanager.ItemManagerConfig;
|
import forge.itemmanager.ItemManagerConfig;
|
||||||
import forge.itemmanager.ItemManagerModel;
|
import forge.itemmanager.ItemManagerModel;
|
||||||
import forge.toolbox.FLabel;
|
|
||||||
import forge.toolbox.FScrollPane;
|
|
||||||
import forge.toolbox.FScrollPanel;
|
|
||||||
import forge.toolbox.FSkin;
|
|
||||||
import forge.toolbox.FSkin.SkinColor;
|
import forge.toolbox.FSkin.SkinColor;
|
||||||
import forge.toolbox.FSkin.SkinImage;
|
import forge.toolbox.FSkin.SkinImage;
|
||||||
import forge.toolbox.ToolTipListener;
|
|
||||||
|
|
||||||
public abstract class ItemView<T extends InventoryItem> {
|
public abstract class ItemView<T extends InventoryItem> {
|
||||||
private static final SkinColor BORDER_COLOR = FSkin.getColor(FSkin.Colors.CLR_TEXT);
|
private static final SkinColor BORDER_COLOR = FSkin.getColor(FSkin.Colors.CLR_TEXT);
|
||||||
|
|
||||||
|
// UniqueCards Options Added
|
||||||
|
static final FSkin.SkinFont ROW_FONT = FSkin.getFont();
|
||||||
|
protected final Localizer localizer = Localizer.getInstance();
|
||||||
|
|
||||||
protected final ItemManager<T> itemManager;
|
protected final ItemManager<T> itemManager;
|
||||||
protected final ItemManagerModel<T> model;
|
protected final ItemManagerModel<T> model;
|
||||||
private final FScrollPane scroller;
|
private final FScrollPane scroller;
|
||||||
@@ -60,6 +63,7 @@ public abstract class ItemView<T extends InventoryItem> {
|
|||||||
new MigLayout("insets 3 1 0 1, gap 3 4, hidemode 3"), true,
|
new MigLayout("insets 3 1 0 1, gap 3 4, hidemode 3"), true,
|
||||||
ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER,
|
ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER,
|
||||||
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
||||||
|
protected FCheckBox uniqueCardsOnlyChkBox;
|
||||||
|
|
||||||
private int heightBackup;
|
private int heightBackup;
|
||||||
private boolean isIncrementalSearchActive = false;
|
private boolean isIncrementalSearchActive = false;
|
||||||
@@ -88,6 +92,9 @@ public abstract class ItemView<T extends InventoryItem> {
|
|||||||
.iconScaleAuto(false)
|
.iconScaleAuto(false)
|
||||||
.tooltip(getCaption())
|
.tooltip(getCaption())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
this.uniqueCardsOnlyChkBox = new FCheckBox(localizer.getMessage("lblUniqueCardsOnly"),
|
||||||
|
this.itemManager.getWantUnique());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initialize(final int index) {
|
public void initialize(final int index) {
|
||||||
@@ -159,9 +166,31 @@ public abstract class ItemView<T extends InventoryItem> {
|
|||||||
this.model.refreshSort();
|
this.model.refreshSort();
|
||||||
onRefresh();
|
onRefresh();
|
||||||
fixSelection(itemsToSelect, backupIndexToSelect, scrollValueToRestore);
|
fixSelection(itemsToSelect, backupIndexToSelect, scrollValueToRestore);
|
||||||
|
this.uniqueCardsOnlyChkBox.setSelected(this.itemManager.getWantUnique());
|
||||||
}
|
}
|
||||||
protected abstract void onResize();
|
protected abstract void onResize();
|
||||||
protected abstract void onRefresh();
|
protected abstract void onRefresh();
|
||||||
|
/*
|
||||||
|
|
||||||
|
*/
|
||||||
|
protected void setUniqueCardsOnlyFilter() {
|
||||||
|
this.uniqueCardsOnlyChkBox.setFont(ROW_FONT);
|
||||||
|
this.uniqueCardsOnlyChkBox.setToolTipText("Toggle whether to show unique cards only");
|
||||||
|
this.uniqueCardsOnlyChkBox.addChangeListener(new ChangeListener() {
|
||||||
|
@Override public void stateChanged(final ChangeEvent arg0) {
|
||||||
|
final boolean wantUnique = uniqueCardsOnlyChkBox.isSelected();
|
||||||
|
if (itemManager.getWantUnique() == wantUnique) { return; }
|
||||||
|
itemManager.setWantUnique(wantUnique);
|
||||||
|
itemManager.refresh();
|
||||||
|
|
||||||
|
if (itemManager.getConfig() != null) {
|
||||||
|
itemManager.getConfig().setUniqueCardsOnly(wantUnique);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
getPnlOptions().add(uniqueCardsOnlyChkBox);
|
||||||
|
}
|
||||||
|
|
||||||
protected void fixSelection(final Iterable<T> itemsToSelect, final int backupIndexToSelect, final int scrollValueToRestore) {
|
protected void fixSelection(final Iterable<T> itemsToSelect, final int backupIndexToSelect, final int scrollValueToRestore) {
|
||||||
if (itemsToSelect == null) {
|
if (itemsToSelect == null) {
|
||||||
setSelectedIndex(0, false); //select first item if no items to select
|
setSelectedIndex(0, false); //select first item if no items to select
|
||||||
|
|||||||
Reference in New Issue
Block a user