Make options panel work for image view

This commit is contained in:
drdev
2014-05-19 17:07:40 +00:00
parent 04b67d9b1c
commit 5c95d2f5db
5 changed files with 61 additions and 24 deletions

View File

@@ -15,6 +15,7 @@ import forge.itemmanager.ItemColumn;
import forge.itemmanager.ItemManager;
import forge.itemmanager.ItemManagerConfig;
import forge.itemmanager.ItemManagerModel;
import forge.itemmanager.filters.ItemFilter;
import forge.toolbox.FCardPanel;
import forge.toolbox.FComboBox;
import forge.toolbox.FDisplayObject;
@@ -35,7 +36,8 @@ public class ImageView<T extends InventoryItem> extends ItemView<T> {
private static final float PADDING = Utils.scaleMin(5);
private static final float PILE_SPACING_Y = 0.1f;
private static final FSkinColor GROUP_HEADER_FORE_COLOR = FSkinColor.get(Colors.CLR_TEXT);
private static final FSkinColor GROUP_HEADER_LINE_COLOR = GROUP_HEADER_FORE_COLOR.alphaColor(120);
private static final FSkinColor OPTION_LABEL_COLOR = GROUP_HEADER_FORE_COLOR.alphaColor(0.7f);
private static final FSkinColor GROUP_HEADER_LINE_COLOR = GROUP_HEADER_FORE_COLOR.alphaColor(0.5f);
private static final FSkinFont GROUP_HEADER_FONT = FSkinFont.get(12);
private static final float GROUP_HEADER_HEIGHT = Utils.scaleY(19);
private static final float GROUP_HEADER_GLYPH_WIDTH = Utils.scaleX(6);
@@ -122,10 +124,10 @@ public class ImageView<T extends InventoryItem> extends ItemView<T> {
}
}
private final ExpandCollapseButton btnExpandCollapseAll = new ExpandCollapseButton();
private final FLabel lblGroupBy = new FLabel.Builder().text("Group:").fontSize(12).textColor(OPTION_LABEL_COLOR).build();
private final FComboBox<Object> cbGroupByOptions = new FComboBox<Object>();
private final FLabel lblPileBy = new FLabel.Builder().text("Pile:").fontSize(12).textColor(OPTION_LABEL_COLOR).build();
private final FComboBox<Object> cbPileByOptions = new FComboBox<Object>();
private final FComboBox<Integer> cbColumnCount = new FComboBox<Integer>();
public ImageView(ItemManager<T> itemManager0, ItemManagerModel<T> model0) {
super(itemManager0, model0);
@@ -141,12 +143,8 @@ public class ImageView<T extends InventoryItem> extends ItemView<T> {
for (ColumnDef option : pileByOptions) {
cbPileByOptions.addItem(option);
}
for (Integer i = MIN_COLUMN_COUNT; i <= MAX_COLUMN_COUNT; i++) {
cbColumnCount.addItem(i);
}
cbGroupByOptions.setSelectedIndex(0);
cbPileByOptions.setSelectedIndex(0);
cbColumnCount.setSelectedIndex(columnCount - MIN_COLUMN_COUNT);
cbGroupByOptions.setChangedHandler(new FEventHandler() {
@Override
@@ -170,23 +168,17 @@ public class ImageView<T extends InventoryItem> extends ItemView<T> {
}
}
});
cbColumnCount.setChangedHandler(new FEventHandler() {
@Override
public void handleEvent(FEvent e) {
setColumnCount(cbColumnCount.getSelectedItem());
}
});
cbGroupByOptions.setFontSize(12);
cbPileByOptions.setFontSize(12);
getPnlOptions().add(btnExpandCollapseAll);
getPnlOptions().add(new FLabel.Builder().text("Group by:").fontSize(12).build());
getPnlOptions().add(lblGroupBy);
getPnlOptions().add(cbGroupByOptions);
getPnlOptions().add(new FLabel.Builder().text("Pile by:").fontSize(12).build());
getPnlOptions().add(lblPileBy);
getPnlOptions().add(cbPileByOptions);
getPnlOptions().add(new FLabel.Builder().text("Columns:").fontSize(12).build());
getPnlOptions().add(cbColumnCount);
//setup display
display = new CardViewDisplay();
display = getScroller().add(new CardViewDisplay());
/*display.addMouseListener(new FMouseAdapter() {
@Override
public void onLeftMouseDown(MouseEvent e) {
@@ -416,8 +408,7 @@ public class ImageView<T extends InventoryItem> extends ItemView<T> {
}
if (columnCount == columnCount0) { return; }
columnCount = columnCount0;
cbColumnCount.setSelectedIndex(columnCount - MIN_COLUMN_COUNT);
if (!forSetup) {
if (itemManager.getConfig() != null) {
itemManager.getConfig().setImageColumnCount(columnCount);
@@ -517,6 +508,33 @@ public class ImageView<T extends InventoryItem> extends ItemView<T> {
updateLayout(true);
}
@Override
protected float layoutOptionsPanel(float visibleWidth, float height) {
float padding = ItemFilter.PADDING;
float x = 0;
float y = padding;
float h = height - 2 * y;
btnExpandCollapseAll.setBounds(x, y, h, h);
x += h + padding;
lblGroupBy.setBounds(x, y, lblGroupBy.getAutoSizeBounds().width, h);
x += lblGroupBy.getWidth();
//determine width of combo boxes based on available width versus auto-size widths
float lblPileByWidth = lblPileBy.getAutoSizeBounds().width;
float availableComboBoxWidth = visibleWidth - x - lblPileByWidth - padding;
float groupByWidth = availableComboBoxWidth * 0.66f;
float pileByWidth = availableComboBoxWidth - groupByWidth;
cbGroupByOptions.setBounds(x, y, groupByWidth, h);
x += groupByWidth + padding;
lblPileBy.setBounds(x, y, lblPileByWidth, h);
x += lblPileByWidth;
cbPileByOptions.setBounds(x, y, pileByWidth, h);
x += pileByWidth + padding;
return x;
}
private void updateLayout(boolean forRefresh) {
lockInput = true; //lock input until next repaint finishes
focalItem = null; //clear cached focalItem when layout changes

View File

@@ -252,6 +252,11 @@ public final class ItemListView<T extends InventoryItem> extends ItemView<T> {
list.setListData(model.getOrderedList());
}
@Override
protected float layoutOptionsPanel(float visibleWidth, float height) {
return visibleWidth;
}
public abstract static class ItemRenderer<T extends InventoryItem> {
public abstract float getItemHeight();
public abstract boolean tap(Entry<T, Integer> value, float x, float y, int count);

View File

@@ -61,11 +61,12 @@ public abstract class ItemView<T extends InventoryItem> {
}
}
protected abstract float layoutOptionsPanel(float visibleWidth, float height);
private class OptionsPanel extends FScrollPane {
@Override
protected ScrollBounds layoutAndGetScrollBounds(float visibleWidth, float visibleHeight) {
// TODO Auto-generated method stub
return new ScrollBounds(visibleWidth, visibleHeight);
return new ScrollBounds(layoutOptionsPanel(visibleWidth, visibleHeight), visibleHeight);
}
@Override

View File

@@ -127,6 +127,19 @@ public class FComboBox<E> extends FTextField {
return false; //don't allow editing text
}
@Override
public float getAutoSizeWidth() {
//use widest item width to determine auto-size width
float maxTextWidth = 0;
for (E item : items) {
float width = font.getFont().getBounds(item.toString()).width;
if (width > maxTextWidth) {
maxTextWidth = width;
}
}
return PADDING + maxTextWidth + getRightPadding();
}
@Override
public void draw(Graphics g) {
super.draw(g);

View File

@@ -34,7 +34,7 @@ public class FTextField extends FDisplayObject {
}
private String text, ghostText, textBeforeKeyInput;
private FSkinFont font;
protected FSkinFont font;
private HAlignment alignment;
private int selStart, selLength;
private boolean isEditing;
@@ -119,7 +119,7 @@ public class FTextField extends FDisplayObject {
}
public float getAutoSizeWidth() {
return font.getFont().getBounds(text).width + 2 * PADDING;
return PADDING + font.getFont().getBounds(text).width + getRightPadding();
}
private int getCharIndexAtPoint(float x, float y) {