feat: adds new gb column: "Viewtag" for defining custom views with specific tags

This commit is contained in:
lantzelot-swe 2021-03-14 22:45:44 +01:00
parent 410b754ace
commit ffcb509d9e
8 changed files with 122 additions and 8 deletions

View File

@ -94,6 +94,7 @@ public class DbConnector
columnList.add(DbConstants.SYSTEM);
columnList.add(DbConstants.VERTICALSHIFT);
columnList.add(DbConstants.FAVORITE);
columnList.add(DbConstants.VIEW_TAG);
//Check if database file exists, if not create an empty db.
File dbFile = new File("./" + DB_NAME);
if (!dbFile.exists())
@ -134,14 +135,16 @@ public class DbConnector
String addEsSql = "ALTER TABLE gameinfo ADD COLUMN Description_es STRING;";
String addItSql = "ALTER TABLE gameinfo ADD COLUMN Description_it STRING;";
String addDuplicateSql = "ALTER TABLE gameinfo ADD COLUMN Duplicate INTEGER DEFAULT 0;";
String addViewTagSql = "ALTER TABLE gameinfo ADD COLUMN Viewtag STRING;";
try (Connection conn = this.connect(); PreparedStatement stmnt = conn.prepareStatement(tableInfoSql);
ResultSet rs = stmnt.executeQuery(); Statement addDestmnt = conn.createStatement();
Statement addFrstmnt = conn.createStatement(); Statement addEsstmnt = conn.createStatement();
Statement addItstmnt = conn.createStatement(); Statement addDuplicatestmnt = conn.createStatement();)
Statement addItstmnt = conn.createStatement(); Statement addDuplicatestmnt = conn.createStatement(); Statement addViewtagstmnt = conn.createStatement())
{
boolean columnsAvailable = false;
boolean duplicateAvailable = false;
boolean viewTagAvailable = false;
while (rs.next())
{
//Check if one of the language columns are available
@ -153,6 +156,10 @@ public class DbConnector
{
duplicateAvailable = true;
}
if (rs.getString("Name").equals("Viewtag"))
{
viewTagAvailable = true;
}
}
if (!columnsAvailable)
@ -170,10 +177,16 @@ public class DbConnector
addDuplicatestmnt.executeUpdate(addDuplicateSql);
logger.debug("Duplicate column added.");
}
if (!viewTagAvailable)
{
logger.debug("Viewtag column is missing in the database, adding column.");
addViewtagstmnt.executeUpdate(addViewTagSql);
logger.debug("Viewtag column added.");
}
}
catch (SQLException e)
{
ExceptionHandler.handleException(e, "Could not update db for language and duplicate columns");
ExceptionHandler.handleException(e, "Could not update db for language, duplicate columns and view tag");
}
}
@ -558,6 +571,8 @@ public class DbConnector
st.append(",0");
}
st.append(",");
//Append empty string for viewtag
st.append("\"\",");
st.append(duplicateIndex);
st.append("),(");
}
@ -601,17 +616,17 @@ public class DbConnector
StringBuilder sqlBuilder = new StringBuilder();
sqlBuilder.append("UPDATE gameinfo SET ");
//Loop from 1 (year) to verticalshift, exclude favorite from loop
for (int i = 1; i < columnList.size() - 1; i++)
for (int i = 1; i < columnList.size() - 2; i++)
{
sqlBuilder.append(columnList.get(i));
sqlBuilder.append(" = ");
if (i > 1 && i < columnList.size() - 2)
if (i > 1 && i < columnList.size() - 3)
{
sqlBuilder.append("\"");
}
sqlBuilder.append(splittedRowValueList.get(i));
if (i < columnList.size() - 2)
if (i < columnList.size() - 3)
{
if (i == 1)
{
@ -631,6 +646,7 @@ public class DbConnector
{
sqlBuilder.append(",Favorite = 0");
}
sqlBuilder.append(" WHERE title = ");
sqlBuilder.append(title);
sqlBuilder.append("\" AND Duplicate = ");
@ -690,6 +706,7 @@ public class DbConnector
returnValue.setSystem(rs.getString(DbConstants.SYSTEM));
returnValue.setVerticalShift(rs.getInt(DbConstants.VERTICALSHIFT));
returnValue.setDuplicateIndex(rs.getInt(DbConstants.DUPLICATE_INDEX));
returnValue.setViewTag(rs.getString(DbConstants.VIEW_TAG));
logger.debug("SELECT Executed successfully");
}
catch (SQLException e)
@ -773,7 +790,9 @@ public class DbConnector
st.append(details.getSystem());
st.append("\",");
st.append(details.getVerticalShift());
st.append(",0,");
st.append(",0,\"");
st.append(details.getViewTag());
st.append("\",");
st.append(details.getDuplicateIndex());
st.append(");");
@ -874,6 +893,10 @@ public class DbConnector
sqlBuilder.append("=\"");
sqlBuilder.append(details.getSystem());
sqlBuilder.append("\",");
sqlBuilder.append(DbConstants.VIEW_TAG);
sqlBuilder.append("=\"");
sqlBuilder.append(details.getViewTag());
sqlBuilder.append("\",");
sqlBuilder.append(DbConstants.VERTICALSHIFT);
sqlBuilder.append("=");
sqlBuilder.append(details.getVerticalShift());

View File

@ -7,6 +7,8 @@ import java.awt.Image;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
import java.beans.Beans;
import java.io.File;
@ -30,6 +32,7 @@ import org.slf4j.LoggerFactory;
import se.lantz.gui.screenshot.EditScreenshotDialog;
import se.lantz.model.InfoModel;
import se.lantz.model.MainViewModel;
import se.lantz.util.CustomUndoPlainDocument;
import se.lantz.util.ExceptionHandler;
import se.lantz.util.FileDrop;
import se.lantz.util.FileManager;
@ -77,6 +80,8 @@ public class ScreenshotsPanel extends JPanel
private JLabel resolution1Label;
private JLabel resolution2Label;
private MainViewModel model;
private JLabel viewTagLabel;
private JTextField viewTagTextField;
public ScreenshotsPanel(MainViewModel model)
{
@ -135,6 +140,7 @@ public class ScreenshotsPanel extends JPanel
}
// Read from model
getGameTextField().setText(getGameFileName());
getViewTagTextField().setText(infomodel.getViewTag());
reloadScreens();
}
@ -529,6 +535,12 @@ public class ScreenshotsPanel extends JPanel
gbc_gameLabel.gridx = 0;
gbc_gameLabel.gridy = 0;
gamePanel.add(getGameLabel(), gbc_gameLabel);
GridBagConstraints gbc_viewTagLabel = new GridBagConstraints();
gbc_viewTagLabel.anchor = GridBagConstraints.WEST;
gbc_viewTagLabel.insets = new Insets(12, 0, 0, 3);
gbc_viewTagLabel.gridx = 2;
gbc_viewTagLabel.gridy = 0;
gamePanel.add(getViewTagLabel(), gbc_viewTagLabel);
GridBagConstraints gbc_gameTextField = new GridBagConstraints();
gbc_gameTextField.anchor = GridBagConstraints.NORTHWEST;
gbc_gameTextField.weighty = 1.0;
@ -538,13 +550,20 @@ public class ScreenshotsPanel extends JPanel
gbc_gameTextField.gridy = 1;
gamePanel.add(getGameTextField(), gbc_gameTextField);
GridBagConstraints gbc_gameButton = new GridBagConstraints();
gbc_gameButton.weightx = 1.0;
gbc_gameButton.weighty = 1.0;
gbc_gameButton.anchor = GridBagConstraints.NORTHWEST;
gbc_gameButton.weightx = 1.0;
gbc_gameButton.insets = new Insets(0, 0, 10, 5);
gbc_gameButton.gridx = 1;
gbc_gameButton.gridy = 1;
gamePanel.add(getGameButton(), gbc_gameButton);
GridBagConstraints gbc_viewTagTextField = new GridBagConstraints();
gbc_viewTagTextField.insets = new Insets(0, 0, 0, 3);
gbc_viewTagTextField.anchor = GridBagConstraints.NORTHWEST;
gbc_viewTagTextField.fill = GridBagConstraints.HORIZONTAL;
gbc_viewTagTextField.gridx = 2;
gbc_viewTagTextField.gridy = 1;
gamePanel.add(getViewTagTextField(), gbc_viewTagTextField);
}
return gamePanel;
}
@ -564,7 +583,7 @@ public class ScreenshotsPanel extends JPanel
{
gameTextField = new JTextField();
gameTextField.setEditable(false);
gameTextField.setPreferredSize(new Dimension(130, 20));
gameTextField.setPreferredSize(new Dimension(155, 20));
new FileDrop(gameTextField, new FileDrop.Listener()
{
public void filesDropped(java.io.File[] files)
@ -830,4 +849,40 @@ public class ScreenshotsPanel extends JPanel
}
return resolution2Label;
}
private JLabel getViewTagLabel()
{
if (viewTagLabel == null)
{
viewTagLabel = new JLabel("View tag");
}
return viewTagLabel;
}
private JTextField getViewTagTextField()
{
if (viewTagTextField == null)
{
viewTagTextField = new JTextField();
viewTagTextField.setColumns(10);
viewTagTextField.setDocument(new CustomUndoPlainDocument()
{
@Override
public void updateModel()
{
infomodel.setViewTag(viewTagTextField.getText());
}
});
viewTagTextField.addKeyListener(new KeyAdapter()
{
@Override
public void keyReleased(KeyEvent e)
{
JTextField textField = (JTextField) e.getSource();
infomodel.setViewTag(textField.getText());
}
});
}
return viewTagTextField;
}
}

View File

@ -193,6 +193,7 @@ public class FilterPanel extends JPanel
fieldTableComboBox.addItem(DbConstants.SYSTEM);
fieldTableComboBox.addItem(DbConstants.FAVORITE);
fieldTableComboBox.addItem(DbConstants.GAME);
fieldTableComboBox.addItem(DbConstants.VIEW_TAG);
fieldTableComboBox.addActionListener(e -> {

View File

@ -43,6 +43,8 @@ public class InfoModel extends AbstractModel
private String oldScreens2File = "";
private int duplicateIndex = 0;
private String viewTag = "";
public String getTitle()
{
@ -482,4 +484,19 @@ public class InfoModel extends AbstractModel
{
return oldScreens2File;
}
public String getViewTag()
{
return viewTag;
}
public void setViewTag(String viewTag)
{
String old = getViewTag();
this.viewTag = viewTag;
if (!Objects.equals(old, viewTag))
{
notifyChange();
}
}
}

View File

@ -165,6 +165,7 @@ public class MainViewModel extends AbstractModel
infoModel.setScreens1File(currentGameDetails.getScreen1());
infoModel.setScreens2File(currentGameDetails.getScreen2());
infoModel.setDuplicateIndex(currentGameDetails.getDuplicateIndex());
infoModel.setViewTag(currentGameDetails.getViewTag());
//Reset and images that where added previously
infoModel.resetImagesAndOldFileNames();
joy1Model.setConfigStringFromDb(currentGameDetails.getJoy1());
@ -377,6 +378,7 @@ public class MainViewModel extends AbstractModel
updatedGame.setJoy2(joy2Model.getConfigString());
updatedGame.setSystem(systemModel.getConfigString());
updatedGame.setVerticalShift(systemModel.getVerticalShift());
updatedGame.setViewTag(infoModel.getViewTag());
if (currentGameId.isEmpty())
{

View File

@ -29,6 +29,7 @@ public class GameDetails
private String system = "";
private int verticalshift = 0;
private int duplicateIndex = 0;
private String viewTag = "";
public GameDetails()
{
@ -225,4 +226,14 @@ public class GameDetails
{
this.duplicateIndex = index;
}
public String getViewTag()
{
return viewTag;
}
public void setViewTag(String viewTag)
{
this.viewTag = viewTag == null ? "" : viewTag;
}
}

View File

@ -121,6 +121,8 @@ public class GameView implements Comparable
break;
case ViewFilter.EMPTY:
builder.append(" is null or ");
builder.append(viewFilter.getField());
builder.append(" = ''");
break;
@ -199,6 +201,8 @@ public class GameView implements Comparable
break;
case ViewFilter.EMPTY:
builder.append(" is null or ");
builder.append(viewFilter.getField());
builder.append(" = ''");
break;

View File

@ -22,6 +22,7 @@ public class DbConstants
public static final String VERTICALSHIFT = "VerticalShift";
public static final String FAVORITE = "Favorite";
public static final String DUPLICATE_INDEX = "Duplicate";
public static final String VIEW_TAG = "Viewtag";
private DbConstants()
{