feat: add Favorite to selectable fields in the game view edit dialog
With this you can e.g. exclude favorites from a view. Also adds better value handling (year only accepts four digits as input, favorite only "true" or "false")
This commit is contained in:
parent
c1cceb5d84
commit
b38f0011e0
TODO.txt
src/main/java/se/lantz
5
TODO.txt
5
TODO.txt
|
@ -1,9 +1,8 @@
|
|||
-Add Lemon as a scraper site.
|
||||
-Allow for saving without a cover or one missing screenshot. Use "missing" for it instead. Makes it easier to add games where you don't have a cover for example.
|
||||
-Add translation feature to automatically translate the description field. As a separate function for each game and when you scrape. An option to translate all games in one batch perhaps (not sure
|
||||
how the google scripts would cope with that, there is a cap at 5000 executions per day)
|
||||
-Add translation feature to automatically translate the description field. As a separate function for each game and when you scrape. An option to translate all games in one batch perhaps (not sure how the google scripts would cope with that, there is a cap at 5000 executions per day)
|
||||
-Keep gameinfo screens from PCU when deleting all games.
|
||||
-Add option to only delete all games in the current game view.
|
||||
-Only pre-select the empty fields for a game when opening the scraper dialog.
|
||||
|
||||
-Bug: prg files for vic-20?
|
||||
-Bug: prg files for vic-20?
|
|
@ -7,7 +7,6 @@ import java.awt.Insets;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.ButtonGroup;
|
||||
import javax.swing.DefaultCellEditor;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComboBox;
|
||||
|
@ -188,15 +187,21 @@ public class FilterPanel extends JPanel
|
|||
fieldTableComboBox.addItem(DbConstants.JOY1);
|
||||
fieldTableComboBox.addItem(DbConstants.JOY2);
|
||||
fieldTableComboBox.addItem(DbConstants.SYSTEM);
|
||||
fieldTableComboBox.addItem(DbConstants.FAVORITE);
|
||||
|
||||
fieldTableComboBox.addActionListener(e -> {
|
||||
if (!fieldTableComboBox.getSelectedItem().equals(DbConstants.YEAR))
|
||||
|
||||
if (fieldTableComboBox.getSelectedItem().equals(DbConstants.FAVORITE))
|
||||
{
|
||||
addStringOperators();
|
||||
addBooleanOperators();
|
||||
}
|
||||
else if (fieldTableComboBox.getSelectedItem().equals(DbConstants.YEAR))
|
||||
{
|
||||
addIntOperators();
|
||||
}
|
||||
else
|
||||
{
|
||||
addIntOperators();
|
||||
addStringOperators();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -220,6 +225,12 @@ public class FilterPanel extends JPanel
|
|||
getOperatorTableComboBox().addItem(ViewFilter.AFTER);
|
||||
}
|
||||
|
||||
private void addBooleanOperators()
|
||||
{
|
||||
getOperatorTableComboBox().removeAllItems();
|
||||
getOperatorTableComboBox().addItem(ViewFilter.IS);
|
||||
}
|
||||
|
||||
private JComboBox<String> getOperatorTableComboBox()
|
||||
{
|
||||
if (operatorTableComboBox == null)
|
||||
|
@ -250,13 +261,29 @@ public class FilterPanel extends JPanel
|
|||
{
|
||||
if (column == 0)
|
||||
{
|
||||
if (!value.equals(DbConstants.YEAR) && getValueAt(row, 0).equals(DbConstants.YEAR))
|
||||
{
|
||||
setValueAt(ViewFilter.BEGINS_WITH_TEXT, row, 1);
|
||||
}
|
||||
if (value.equals(DbConstants.YEAR) && !getValueAt(row, 0).equals(DbConstants.YEAR))
|
||||
if (value.equals(DbConstants.FAVORITE))
|
||||
{
|
||||
setValueAt(ViewFilter.IS, row, 1);
|
||||
if (!getValueAt(row, 2).equals("false"))
|
||||
{
|
||||
setValueAt("true", row, 2);
|
||||
}
|
||||
}
|
||||
else if (value.equals(DbConstants.YEAR))
|
||||
{
|
||||
setValueAt(ViewFilter.IS, row, 1);
|
||||
try
|
||||
{
|
||||
Integer.parseInt((String) getValueAt(row, 2));
|
||||
}
|
||||
catch (NumberFormatException e)
|
||||
{
|
||||
setValueAt("1986", row, 2);
|
||||
}
|
||||
}
|
||||
else if (getValueAt(row, 0).equals(DbConstants.YEAR) || getValueAt(row, 0).equals(DbConstants.FAVORITE))
|
||||
{
|
||||
setValueAt(ViewFilter.BEGINS_WITH_TEXT, row, 1);
|
||||
}
|
||||
}
|
||||
super.setValueAt(value, row, column);
|
||||
|
@ -287,7 +314,11 @@ public class FilterPanel extends JPanel
|
|||
if (column == 1)
|
||||
{
|
||||
String field = (String) table.getModel().getValueAt(row, 0);
|
||||
if (field.equals(DbConstants.YEAR))
|
||||
if (field.equals(DbConstants.FAVORITE))
|
||||
{
|
||||
addBooleanOperators();
|
||||
}
|
||||
else if (field.equals(DbConstants.YEAR))
|
||||
{
|
||||
addIntOperators();
|
||||
}
|
||||
|
@ -300,6 +331,9 @@ public class FilterPanel extends JPanel
|
|||
}
|
||||
});
|
||||
|
||||
TableColumn valueColumn = table.getColumnModel().getColumn(2);
|
||||
valueColumn.setCellEditor(new ValueCellEditor());
|
||||
|
||||
table.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||
table.setColumnSelectionAllowed(false);
|
||||
table.getSelectionModel().addListSelectionListener(e -> {
|
||||
|
|
|
@ -0,0 +1,175 @@
|
|||
package se.lantz.gui.gameview;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.Toolkit;
|
||||
import java.util.EventObject;
|
||||
|
||||
import javax.swing.DefaultCellEditor;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.event.CellEditorListener;
|
||||
import javax.swing.table.TableCellEditor;
|
||||
import javax.swing.text.AbstractDocument;
|
||||
import javax.swing.text.AttributeSet;
|
||||
import javax.swing.text.BadLocationException;
|
||||
import javax.swing.text.DocumentFilter;
|
||||
|
||||
import se.lantz.util.DbConstants;
|
||||
|
||||
public class ValueCellEditor implements TableCellEditor
|
||||
{
|
||||
private final static int BOOLEAN = 0;
|
||||
|
||||
private final static int STRING = 1;
|
||||
|
||||
private final static int NUM_EDITOR = 2;
|
||||
|
||||
DefaultCellEditor[] cellEditors;
|
||||
|
||||
JComboBox<String> comboBox;
|
||||
|
||||
int flg;
|
||||
|
||||
public ValueCellEditor()
|
||||
{
|
||||
cellEditors = new DefaultCellEditor[3];
|
||||
comboBox = new JComboBox<>();
|
||||
comboBox.addItem("true");
|
||||
comboBox.addItem("false");
|
||||
cellEditors[BOOLEAN] = new DefaultCellEditor(comboBox);
|
||||
JTextField textField = new JTextField();
|
||||
cellEditors[STRING] = new DefaultCellEditor(textField);
|
||||
JTextField numberField = new JTextField();
|
||||
((AbstractDocument) numberField.getDocument()).setDocumentFilter(new NumberDocumentFilter());
|
||||
cellEditors[NUM_EDITOR] = new DefaultCellEditor(numberField);
|
||||
flg = STRING;
|
||||
}
|
||||
|
||||
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column)
|
||||
{
|
||||
|
||||
String field = (String) table.getModel().getValueAt(row, 0);
|
||||
if (field.equals(DbConstants.FAVORITE))
|
||||
{
|
||||
flg = BOOLEAN;
|
||||
return cellEditors[BOOLEAN].getTableCellEditorComponent(table, value, isSelected, row, column);
|
||||
}
|
||||
else if (field.equals(DbConstants.YEAR))
|
||||
{
|
||||
flg = NUM_EDITOR;
|
||||
return cellEditors[NUM_EDITOR].getTableCellEditorComponent(table, value, isSelected, row, column);
|
||||
}
|
||||
else
|
||||
{
|
||||
flg = STRING;
|
||||
return cellEditors[STRING].getTableCellEditorComponent(table, value, isSelected, row, column);
|
||||
}
|
||||
}
|
||||
|
||||
public Object getCellEditorValue()
|
||||
{
|
||||
return cellEditors[flg].getCellEditorValue();
|
||||
}
|
||||
|
||||
public Component getComponent()
|
||||
{
|
||||
return cellEditors[flg].getComponent();
|
||||
}
|
||||
|
||||
public boolean stopCellEditing()
|
||||
{
|
||||
return cellEditors[flg].stopCellEditing();
|
||||
}
|
||||
|
||||
public void cancelCellEditing()
|
||||
{
|
||||
cellEditors[flg].cancelCellEditing();
|
||||
}
|
||||
|
||||
public boolean isCellEditable(EventObject anEvent)
|
||||
{
|
||||
return cellEditors[flg].isCellEditable(anEvent);
|
||||
}
|
||||
|
||||
public boolean shouldSelectCell(EventObject anEvent)
|
||||
{
|
||||
return cellEditors[flg].shouldSelectCell(anEvent);
|
||||
}
|
||||
|
||||
public void addCellEditorListener(CellEditorListener l)
|
||||
{
|
||||
cellEditors[flg].addCellEditorListener(l);
|
||||
}
|
||||
|
||||
public void removeCellEditorListener(CellEditorListener l)
|
||||
{
|
||||
cellEditors[flg].removeCellEditorListener(l);
|
||||
}
|
||||
|
||||
public void setClickCountToStart(int n)
|
||||
{
|
||||
cellEditors[flg].setClickCountToStart(n);
|
||||
}
|
||||
|
||||
public int getClickCountToStart()
|
||||
{
|
||||
return cellEditors[flg].getClickCountToStart();
|
||||
}
|
||||
}
|
||||
|
||||
class NumberDocumentFilter extends DocumentFilter
|
||||
{
|
||||
@Override
|
||||
public void insertString(DocumentFilter.FilterBypass fp, int offset, String string, AttributeSet aset)
|
||||
throws BadLocationException
|
||||
{
|
||||
if (offset > 3 || offset + string.length() > 4)
|
||||
{
|
||||
Toolkit.getDefaultToolkit().beep();
|
||||
return;
|
||||
}
|
||||
int len = string.length();
|
||||
boolean isValidInteger = true;
|
||||
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
if (!Character.isDigit(string.charAt(i)))
|
||||
{
|
||||
isValidInteger = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (isValidInteger)
|
||||
super.insertString(fp, offset, string, aset);
|
||||
else
|
||||
Toolkit.getDefaultToolkit().beep();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void replace(DocumentFilter.FilterBypass fp, int offset, int length, String string, AttributeSet aset)
|
||||
throws BadLocationException
|
||||
{
|
||||
if (offset > 3 || offset + string.length() > 4)
|
||||
{
|
||||
Toolkit.getDefaultToolkit().beep();
|
||||
return;
|
||||
}
|
||||
|
||||
int len = string.length();
|
||||
boolean isValidInteger = true;
|
||||
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
if (!Character.isDigit(string.charAt(i)))
|
||||
{
|
||||
isValidInteger = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (isValidInteger)
|
||||
super.replace(fp, offset, length, string, aset);
|
||||
else
|
||||
Toolkit.getDefaultToolkit().beep();
|
||||
}
|
||||
}
|
|
@ -112,7 +112,19 @@ public class GameView implements Comparable
|
|||
|
||||
case ViewFilter.IS:
|
||||
builder.append(" = ");
|
||||
builder.append(viewFilter.getFilterData());
|
||||
//Handle Favorites where value is either true or false, mapped towards 1 and 0 in the db
|
||||
if (viewFilter.getFilterData().equals("true"))
|
||||
{
|
||||
builder.append("1");
|
||||
}
|
||||
else if (viewFilter.getFilterData().equals("false"))
|
||||
{
|
||||
builder.append("0");
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.append(viewFilter.getFilterData());
|
||||
}
|
||||
break;
|
||||
|
||||
case ViewFilter.BEFORE:
|
||||
|
|
Loading…
Reference in New Issue