mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 20:28:00 +00:00
Add combo box as way to change column count in addition to Ctrl+MouseWheel
This commit is contained in:
@@ -30,101 +30,105 @@ public class FComboBoxWrapper<E> {
|
|||||||
|
|
||||||
private FComboBox<E> comboBox;
|
private FComboBox<E> comboBox;
|
||||||
private Object constraints;
|
private Object constraints;
|
||||||
|
|
||||||
public FComboBoxWrapper() {
|
public FComboBoxWrapper() {
|
||||||
super();
|
super();
|
||||||
this.comboBox = new FComboBox<E>();
|
this.comboBox = new FComboBox<E>();
|
||||||
allWrappers.add(this);
|
allWrappers.add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public FComboBoxWrapper(E[] items) {
|
public FComboBoxWrapper(E[] items) {
|
||||||
super();
|
super();
|
||||||
this.comboBox = new FComboBox<E>(items);
|
this.comboBox = new FComboBox<E>(items);
|
||||||
allWrappers.add(this);
|
allWrappers.add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public FComboBoxWrapper(Vector<E> items) {
|
public FComboBoxWrapper(Vector<E> items) {
|
||||||
super();
|
super();
|
||||||
this.comboBox = new FComboBox<E>(items);
|
this.comboBox = new FComboBox<E>(items);
|
||||||
allWrappers.add(this);
|
allWrappers.add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public FComboBoxWrapper(ComboBoxModel<E> aModel) {
|
public FComboBoxWrapper(ComboBoxModel<E> aModel) {
|
||||||
super();
|
super();
|
||||||
this.comboBox = new FComboBox<E>(aModel);
|
this.comboBox = new FComboBox<E>(aModel);
|
||||||
allWrappers.add(this);
|
allWrappers.add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addItem(E item) {
|
public void addItem(E item) {
|
||||||
this.comboBox.addItem(item);
|
this.comboBox.addItem(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeItem(E item) {
|
public void removeItem(E item) {
|
||||||
this.comboBox.removeItem(item);
|
this.comboBox.removeItem(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeAllItems() {
|
public void removeAllItems() {
|
||||||
this.comboBox.removeAllItems();
|
this.comboBox.removeAllItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public E getSelectedItem() {
|
public E getSelectedItem() {
|
||||||
Object res = this.comboBox.getSelectedItem();
|
Object res = this.comboBox.getSelectedItem();
|
||||||
return res == null ? null : (E) res;
|
return res == null ? null : (E) res;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSelectedItem(Object item) {
|
public void setSelectedItem(Object item) {
|
||||||
this.comboBox.setSelectedItem(item);
|
this.comboBox.setSelectedItem(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSelectedIndex() {
|
public int getSelectedIndex() {
|
||||||
return this.comboBox.getSelectedIndex();
|
return this.comboBox.getSelectedIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSelectedIndex(int index) {
|
public void setSelectedIndex(int index) {
|
||||||
this.comboBox.setSelectedIndex(index);
|
this.comboBox.setSelectedIndex(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setMaximumRowCount(int count) {
|
||||||
|
this.comboBox.setMaximumRowCount(count);
|
||||||
|
}
|
||||||
|
|
||||||
public int getItemCount() {
|
public int getItemCount() {
|
||||||
return this.comboBox.getItemCount();
|
return this.comboBox.getItemCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
public E getItemAt(int index) {
|
public E getItemAt(int index) {
|
||||||
return this.comboBox.getItemAt(index);
|
return this.comboBox.getItemAt(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addActionListener(ActionListener l) {
|
public void addActionListener(ActionListener l) {
|
||||||
this.comboBox.addActionListener(l);
|
this.comboBox.addActionListener(l);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addItemListener(ItemListener l) {
|
public void addItemListener(ItemListener l) {
|
||||||
this.comboBox.addItemListener(l);
|
this.comboBox.addItemListener(l);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addKeyListener(KeyListener l) {
|
public void addKeyListener(KeyListener l) {
|
||||||
this.comboBox.addKeyListener(l);
|
this.comboBox.addKeyListener(l);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRenderer(ListCellRenderer<? super E> aRenderer) {
|
public void setRenderer(ListCellRenderer<? super E> aRenderer) {
|
||||||
this.comboBox.setRenderer(aRenderer);
|
this.comboBox.setRenderer(aRenderer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setModel(ComboBoxModel<E> aModel) {
|
public void setModel(ComboBoxModel<E> aModel) {
|
||||||
this.comboBox.setModel(aModel);
|
this.comboBox.setModel(aModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTextAlignment(TextAlignment align) {
|
public void setTextAlignment(TextAlignment align) {
|
||||||
this.comboBox.setTextAlignment(align);
|
this.comboBox.setTextAlignment(align);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSkinFont(SkinFont skinFont) {
|
public void setSkinFont(SkinFont skinFont) {
|
||||||
this.comboBox.setSkinFont(skinFont);
|
this.comboBox.setSkinFont(skinFont);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setVisible(boolean aFlag) {
|
public void setVisible(boolean aFlag) {
|
||||||
this.comboBox.setVisible(aFlag);
|
this.comboBox.setVisible(aFlag);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setEnabled(boolean aFlag) {
|
public void setEnabled(boolean aFlag) {
|
||||||
this.comboBox.setEnabled(aFlag);
|
this.comboBox.setEnabled(aFlag);
|
||||||
}
|
}
|
||||||
@@ -146,11 +150,11 @@ public class FComboBoxWrapper<E> {
|
|||||||
public JComponent getComponent() {
|
public JComponent getComponent() {
|
||||||
return this.comboBox;
|
return this.comboBox;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void refreshSkin() {
|
private void refreshSkin() {
|
||||||
this.comboBox = refreshComboBoxSkin(this.comboBox, this.constraints);
|
this.comboBox = refreshComboBoxSkin(this.comboBox, this.constraints);
|
||||||
}
|
}
|
||||||
|
|
||||||
//refresh combo box skin by replacing it with a copy of itself
|
//refresh combo box skin by replacing it with a copy of itself
|
||||||
//TODO: Figure out if there's a better way, as calling updateUI doesn't seem to work
|
//TODO: Figure out if there's a better way, as calling updateUI doesn't seem to work
|
||||||
public static <E> FComboBox<E> refreshComboBoxSkin(FComboBox<E> comboBox) {
|
public static <E> FComboBox<E> refreshComboBoxSkin(FComboBox<E> comboBox) {
|
||||||
@@ -167,14 +171,14 @@ public class FComboBoxWrapper<E> {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//create copy of combo box
|
//create copy of combo box
|
||||||
FComboBox<E> newComboBox = new FComboBox<E>();
|
FComboBox<E> newComboBox = new FComboBox<E>();
|
||||||
for (int i = 0; i < comboBox.getItemCount(); i++) {
|
for (int i = 0; i < comboBox.getItemCount(); i++) {
|
||||||
newComboBox.addItem(comboBox.getItemAt(i));
|
newComboBox.addItem(comboBox.getItemAt(i));
|
||||||
}
|
}
|
||||||
newComboBox.setSelectedIndex(comboBox.getSelectedIndex());
|
newComboBox.setSelectedIndex(comboBox.getSelectedIndex());
|
||||||
|
|
||||||
ActionListener[] actionListeners = newComboBox.getActionListeners();
|
ActionListener[] actionListeners = newComboBox.getActionListeners();
|
||||||
for (ActionListener l : actionListeners) {
|
for (ActionListener l : actionListeners) {
|
||||||
newComboBox.removeActionListener(l); //remove default action listeners to prevent duplicates
|
newComboBox.removeActionListener(l); //remove default action listeners to prevent duplicates
|
||||||
|
|||||||
@@ -79,6 +79,7 @@ public class ImageView<T extends InventoryItem> extends ItemView<T> {
|
|||||||
private final ArrayList<Group> groups = new ArrayList<Group>();
|
private final ArrayList<Group> groups = new ArrayList<Group>();
|
||||||
private final FComboBoxWrapper<Object> cbGroupByOptions = new FComboBoxWrapper<Object>();
|
private final FComboBoxWrapper<Object> cbGroupByOptions = new FComboBoxWrapper<Object>();
|
||||||
private final FComboBoxWrapper<Object> cbPileByOptions = new FComboBoxWrapper<Object>();
|
private final FComboBoxWrapper<Object> cbPileByOptions = new FComboBoxWrapper<Object>();
|
||||||
|
private final FComboBoxWrapper<Integer> cbColumnCount = new FComboBoxWrapper<Integer>();
|
||||||
|
|
||||||
public ImageView(ItemManager<T> itemManager0, ItemManagerModel<T> model0) {
|
public ImageView(ItemManager<T> itemManager0, ItemManagerModel<T> model0) {
|
||||||
super(itemManager0, model0);
|
super(itemManager0, model0);
|
||||||
@@ -94,8 +95,15 @@ public class ImageView<T extends InventoryItem> extends ItemView<T> {
|
|||||||
for (ColumnDef option : pileByOptions) {
|
for (ColumnDef option : pileByOptions) {
|
||||||
cbPileByOptions.addItem(option);
|
cbPileByOptions.addItem(option);
|
||||||
}
|
}
|
||||||
|
for (Integer i = MIN_COLUMN_COUNT; i <= MAX_COLUMN_COUNT; i++) {
|
||||||
|
cbColumnCount.addItem(i);
|
||||||
|
}
|
||||||
|
cbGroupByOptions.setMaximumRowCount(cbGroupByOptions.getItemCount());
|
||||||
|
cbPileByOptions.setMaximumRowCount(cbPileByOptions.getItemCount());
|
||||||
|
cbColumnCount.setMaximumRowCount(cbColumnCount.getItemCount());
|
||||||
cbGroupByOptions.setSelectedIndex(0);
|
cbGroupByOptions.setSelectedIndex(0);
|
||||||
cbPileByOptions.setSelectedIndex(0);
|
cbPileByOptions.setSelectedIndex(0);
|
||||||
|
cbColumnCount.setSelectedIndex(columnCount - MIN_COLUMN_COUNT);
|
||||||
|
|
||||||
cbGroupByOptions.addActionListener(new ActionListener() {
|
cbGroupByOptions.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
@@ -121,11 +129,20 @@ public class ImageView<T extends InventoryItem> extends ItemView<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
cbColumnCount.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
focus();
|
||||||
|
setColumnCount(cbColumnCount.getSelectedItem());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
getPnlOptions().add(new FLabel.Builder().text("Group by:").fontSize(12).build());
|
getPnlOptions().add(new FLabel.Builder().text("Group by:").fontSize(12).build());
|
||||||
cbGroupByOptions.addTo(getPnlOptions(), "pushx, growx");
|
cbGroupByOptions.addTo(getPnlOptions(), "pushx, growx");
|
||||||
getPnlOptions().add(new FLabel.Builder().text("Pile by:").fontSize(12).build());
|
getPnlOptions().add(new FLabel.Builder().text("Pile by:").fontSize(12).build());
|
||||||
cbPileByOptions.addTo(getPnlOptions(), "pushx, growx");
|
cbPileByOptions.addTo(getPnlOptions(), "pushx, growx");
|
||||||
|
getPnlOptions().add(new FLabel.Builder().text("Columns:").fontSize(12).build());
|
||||||
|
cbColumnCount.addTo(getPnlOptions(), "w 38px!");
|
||||||
|
|
||||||
//setup display
|
//setup display
|
||||||
display = new CardViewDisplay();
|
display = new CardViewDisplay();
|
||||||
@@ -335,6 +352,7 @@ public class ImageView<T extends InventoryItem> extends ItemView<T> {
|
|||||||
}
|
}
|
||||||
if (columnCount == columnCount0) { return; }
|
if (columnCount == columnCount0) { return; }
|
||||||
columnCount = columnCount0;
|
columnCount = columnCount0;
|
||||||
|
cbColumnCount.setSelectedIndex(columnCount - MIN_COLUMN_COUNT);
|
||||||
|
|
||||||
//determine item to retain scroll position of following column count change
|
//determine item to retain scroll position of following column count change
|
||||||
ItemInfo focalItem0 = getFocalItem();
|
ItemInfo focalItem0 = getFocalItem();
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ public abstract class ItemView<T extends InventoryItem> {
|
|||||||
protected final ItemManagerModel<T> model;
|
protected final ItemManagerModel<T> model;
|
||||||
private final FScrollPane scroller;
|
private final FScrollPane scroller;
|
||||||
private final FLabel button;
|
private final FLabel button;
|
||||||
private final SkinnedPanel pnlOptions = new SkinnedPanel(new MigLayout("insets 3 1 0 1, gap 3, hidemode 3"));
|
private final SkinnedPanel pnlOptions = new SkinnedPanel(new MigLayout("insets 3 1 0 1, gap 3 4, hidemode 3"));
|
||||||
private int heightBackup;
|
private int heightBackup;
|
||||||
private boolean isIncrementalSearchActive = false;
|
private boolean isIncrementalSearchActive = false;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user