mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 12:18:00 +00:00
Add view options panel to ItemManager
This commit is contained in:
@@ -53,6 +53,7 @@ import forge.gui.GuiUtils;
|
||||
import forge.gui.toolbox.ContextMenuBuilder;
|
||||
import forge.gui.toolbox.FLabel;
|
||||
import forge.gui.toolbox.FSkin;
|
||||
import forge.gui.toolbox.FSkin.SkinIcon;
|
||||
import forge.gui.toolbox.FSkin.SkinnedCheckBox;
|
||||
import forge.gui.toolbox.FSkin.SkinnedPanel;
|
||||
import forge.gui.toolbox.FTextField;
|
||||
@@ -121,6 +122,13 @@ public abstract class ItemManager<T extends InventoryItem> extends JPanel {
|
||||
.fontSize(12)
|
||||
.build();
|
||||
|
||||
private static final SkinIcon VIEW_OPTIONS_ICON = FSkin.getIcon(FSkin.DockIcons.ICO_SETTINGS).resize(20, 20);
|
||||
private final FLabel btnViewOptions = new FLabel.Builder()
|
||||
.hoverable().selectable(true)
|
||||
.icon(VIEW_OPTIONS_ICON).iconScaleAuto(false)
|
||||
.tooltip("Toggle to show/hide options for current view")
|
||||
.build();
|
||||
|
||||
private final List<ItemView<T>> views = new ArrayList<ItemView<T>>();
|
||||
private final ItemListView<T> listView;
|
||||
private final ImageView<T> imageView;
|
||||
@@ -200,6 +208,9 @@ public abstract class ItemManager<T extends InventoryItem> extends JPanel {
|
||||
this.add(view.getButton());
|
||||
view.getButton().setSelected(view == this.currentView);
|
||||
}
|
||||
this.add(this.btnViewOptions);
|
||||
this.btnViewOptions.setSelected(this.currentView.getPnlOptions().isVisible());
|
||||
this.add(this.currentView.getPnlOptions());
|
||||
this.add(this.currentView.getScroller());
|
||||
|
||||
final Runnable cmdAddCurrentSearch = new Runnable() {
|
||||
@@ -280,6 +291,14 @@ public abstract class ItemManager<T extends InventoryItem> extends JPanel {
|
||||
this.btnFilters.setCommand(cmdBuildFilterMenu);
|
||||
this.btnFilters.setRightClickCommand(cmdBuildFilterMenu); //show menu on right-click too
|
||||
|
||||
this.btnViewOptions.setCommand(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
currentView.getPnlOptions().setVisible(!currentView.getPnlOptions().isVisible());
|
||||
revalidate();
|
||||
}
|
||||
});
|
||||
|
||||
//setup initial filters
|
||||
addDefaultFilters();
|
||||
|
||||
@@ -316,13 +335,17 @@ public abstract class ItemManager<T extends InventoryItem> extends JPanel {
|
||||
}
|
||||
|
||||
this.currentView.getButton().setSelected(false);
|
||||
this.remove(this.currentView.getPnlOptions());
|
||||
this.remove(this.currentView.getScroller());
|
||||
|
||||
this.currentView = view;
|
||||
this.currentView.getButton().setSelected(true);
|
||||
this.currentView.refresh(itemsToSelect, backupIndexToSelect, 0);
|
||||
|
||||
this.add(currentView.getScroller());
|
||||
this.btnViewOptions.setSelected(view.getPnlOptions().isVisible());
|
||||
view.getButton().setSelected(true);
|
||||
view.refresh(itemsToSelect, backupIndexToSelect, 0);
|
||||
|
||||
this.add(view.getPnlOptions());
|
||||
this.add(view.getScroller());
|
||||
this.revalidate();
|
||||
this.repaint();
|
||||
this.focus();
|
||||
@@ -370,7 +393,8 @@ public abstract class ItemManager<T extends InventoryItem> extends JPanel {
|
||||
int captionWidth = this.lblCaption.getAutoSizeWidth();
|
||||
int ratioWidth = this.lblRatio.getAutoSizeWidth();
|
||||
int viewButtonWidth = FTextField.HEIGHT;
|
||||
int availableCaptionWidth = helper.getParentWidth() - viewButtonWidth * this.views.size() - ratioWidth - helper.getX() - (this.views.size() + 2) * helper.getGapX();
|
||||
int viewButtonCount = this.views.size() + 1;
|
||||
int availableCaptionWidth = helper.getParentWidth() - viewButtonWidth * viewButtonCount - ratioWidth - helper.getX() - (viewButtonCount + 2) * helper.getGapX();
|
||||
if (captionWidth > availableCaptionWidth) { //truncate caption if not enough room for it
|
||||
this.lblCaption.setToolTipText(this.lblCaption.getText());
|
||||
captionWidth = availableCaptionWidth;
|
||||
@@ -379,11 +403,16 @@ public abstract class ItemManager<T extends InventoryItem> extends JPanel {
|
||||
this.lblCaption.setToolTipText(null);
|
||||
}
|
||||
helper.include(this.lblCaption, captionWidth, FTextField.HEIGHT);
|
||||
helper.fillLine(this.lblRatio, FTextField.HEIGHT, (viewButtonWidth + helper.getGapX()) * this.views.size() - 1); //leave room for view buttons
|
||||
helper.fillLine(this.lblRatio, FTextField.HEIGHT, (viewButtonWidth + helper.getGapX()) * viewButtonCount - viewButtonCount + 1); //leave room for view buttons
|
||||
for (ItemView<T> view : this.views) {
|
||||
helper.include(view.getButton(), viewButtonWidth, FTextField.HEIGHT);
|
||||
helper.offset(-1, 0);
|
||||
}
|
||||
helper.include(this.btnViewOptions, viewButtonWidth, FTextField.HEIGHT);
|
||||
helper.newLine(-1);
|
||||
if (this.currentView.getPnlOptions().isVisible()) {
|
||||
helper.fillLine(this.currentView.getPnlOptions(), FTextField.HEIGHT + helper.getGapY());
|
||||
}
|
||||
helper.fill(this.currentView.getScroller());
|
||||
}
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ public class ImageView<T extends InventoryItem> extends ItemView<T> {
|
||||
private static final int IMAGE_SIZE_STEP = (MAX_IMAGE_SIZE - MIN_IMAGE_SIZE) / IMAGE_SIZE_OPTION_COUNT;
|
||||
|
||||
private final CardViewDisplay display;
|
||||
private List<Integer> selectedIndices = new ArrayList<Integer>();
|
||||
private final List<Integer> selectedIndices = new ArrayList<Integer>();
|
||||
private int imageSizeOption = 4;
|
||||
private boolean allowMultipleSelections;
|
||||
private ColumnDef pileBy = null;
|
||||
@@ -69,8 +69,8 @@ public class ImageView<T extends InventoryItem> extends ItemView<T> {
|
||||
private Point hoverScrollPos;
|
||||
private ItemInfo hoveredItem;
|
||||
private ItemInfo focalItem;
|
||||
private ArrayList<ItemInfo> orderedItems = new ArrayList<ItemInfo>();
|
||||
private ArrayList<Group> groups = new ArrayList<Group>();
|
||||
private final ArrayList<ItemInfo> orderedItems = new ArrayList<ItemInfo>();
|
||||
private final ArrayList<Group> groups = new ArrayList<Group>();
|
||||
|
||||
public ImageView(ItemManager<T> itemManager0, ItemManagerModel<T> model0) {
|
||||
super(itemManager0, model0);
|
||||
|
||||
@@ -105,6 +105,7 @@ public final class ItemListView<T extends InventoryItem> extends ItemView<T> {
|
||||
super(itemManager0, model0);
|
||||
this.tableModel = new ItemTableModel(model0);
|
||||
this.setAllowMultipleSelections(false);
|
||||
this.getPnlOptions().setVisible(false); //hide options panel by default
|
||||
|
||||
// use different selection highlight colors for focused vs. unfocused tables
|
||||
this.table.addMouseListener(new FMouseAdapter() {
|
||||
|
||||
@@ -28,6 +28,8 @@ import javax.swing.Timer;
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
import javax.swing.event.ListSelectionListener;
|
||||
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
|
||||
import org.apache.commons.lang3.CharUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
@@ -36,6 +38,7 @@ import forge.gui.toolbox.FScrollPane;
|
||||
import forge.gui.toolbox.FSkin;
|
||||
import forge.gui.toolbox.FSkin.SkinColor;
|
||||
import forge.gui.toolbox.FSkin.SkinImage;
|
||||
import forge.gui.toolbox.FSkin.SkinnedPanel;
|
||||
import forge.gui.toolbox.ToolTipListener;
|
||||
import forge.gui.toolbox.itemmanager.ItemManager;
|
||||
import forge.gui.toolbox.itemmanager.ItemManagerModel;
|
||||
@@ -48,6 +51,7 @@ public abstract class ItemView<T extends InventoryItem> {
|
||||
protected final ItemManagerModel<T> model;
|
||||
private final FScrollPane scroller;
|
||||
private final FLabel button;
|
||||
private final SkinnedPanel pnlOptions = new SkinnedPanel(new MigLayout("insets 0, gap 0, hidemode 3"));
|
||||
private int heightBackup;
|
||||
private boolean isIncrementalSearchActive = false;
|
||||
|
||||
@@ -65,6 +69,8 @@ public abstract class ItemView<T extends InventoryItem> {
|
||||
super.processMouseWheelEvent(e);
|
||||
}
|
||||
};
|
||||
this.pnlOptions.setOpaque(false);
|
||||
this.pnlOptions.setBorder(new FSkin.MatteSkinBorder(1, 0, 0, 0, BORDER_COLOR));
|
||||
this.scroller.setBorder(new FSkin.LineSkinBorder(BORDER_COLOR));
|
||||
this.button = new FLabel.Builder().hoverable().selectable(true)
|
||||
.icon(getIcon()).iconScaleAuto(false)
|
||||
@@ -115,6 +121,10 @@ public abstract class ItemView<T extends InventoryItem> {
|
||||
return this.scroller;
|
||||
}
|
||||
|
||||
public SkinnedPanel getPnlOptions() {
|
||||
return pnlOptions;
|
||||
}
|
||||
|
||||
public int getScrollValue() {
|
||||
return scroller.getVerticalScrollBar().getValue();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user