feat: adds language support for the description field
4 new tabs in the ui, 4 new columns in the db for de,fr,es,it. Db is updated automatically at startup. Bug fix: Year is exported properly
This commit is contained in:
parent
692a236252
commit
615147e83b
|
@ -72,6 +72,10 @@ public class DbConnector
|
|||
columnList.add(DbConstants.COMPOSER);
|
||||
columnList.add(DbConstants.GENRE);
|
||||
columnList.add(DbConstants.DESC);
|
||||
columnList.add(DbConstants.DESC_DE);
|
||||
columnList.add(DbConstants.DESC_FR);
|
||||
columnList.add(DbConstants.DESC_ES);
|
||||
columnList.add(DbConstants.DESC_IT);
|
||||
columnList.add(DbConstants.GAME);
|
||||
columnList.add(DbConstants.COVER);
|
||||
columnList.add(DbConstants.SCREEN1);
|
||||
|
@ -88,6 +92,8 @@ public class DbConnector
|
|||
createNewDb();
|
||||
logger.debug("Database missing, new db created.");
|
||||
}
|
||||
//To be backwards compatible with 1.0 db, update if missing
|
||||
addLanguageColumnsIfMissing();
|
||||
}
|
||||
|
||||
private void createNewDb()
|
||||
|
@ -106,6 +112,49 @@ public class DbConnector
|
|||
}
|
||||
}
|
||||
|
||||
private void addLanguageColumnsIfMissing()
|
||||
{
|
||||
String tableInfoSql = "PRAGMA table_info(gameinfo)";
|
||||
String addDeSql = "ALTER TABLE gameinfo ADD COLUMN Description_de STRING;";
|
||||
String addFrSql = "ALTER TABLE gameinfo ADD COLUMN Description_fr STRING;";
|
||||
String addEsSql = "ALTER TABLE gameinfo ADD COLUMN Description_es STRING;";
|
||||
String addItSql = "ALTER TABLE gameinfo ADD COLUMN Description_it 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();
|
||||
)
|
||||
{
|
||||
boolean columnsAvailable = false;
|
||||
while (rs.next())
|
||||
{
|
||||
//Check if one of the language columns are available
|
||||
if (rs.getString("Name").equals("Description_de"))
|
||||
{
|
||||
columnsAvailable = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!columnsAvailable)
|
||||
{
|
||||
logger.debug("Language columns are missing in the database, adding columns.");
|
||||
addDestmnt.executeUpdate(addDeSql);
|
||||
addFrstmnt.executeUpdate(addFrSql);
|
||||
addEsstmnt.executeUpdate(addEsSql);
|
||||
addItstmnt.executeUpdate(addItSql);
|
||||
logger.debug("Language columns added.");
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
ExceptionHandler.handleException(e, "Could not update db for language columns");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Connect to the database.
|
||||
*/
|
||||
|
@ -568,6 +617,10 @@ public class DbConnector
|
|||
returnValue.setComposer(rs.getString(DbConstants.COMPOSER));
|
||||
returnValue.setGenre(rs.getString(DbConstants.GENRE));
|
||||
returnValue.setDescription(rs.getString(DbConstants.DESC));
|
||||
returnValue.setDescriptionDe(rs.getString(DbConstants.DESC_DE));
|
||||
returnValue.setDescriptionFr(rs.getString(DbConstants.DESC_FR));
|
||||
returnValue.setDescriptionEs(rs.getString(DbConstants.DESC_ES));
|
||||
returnValue.setDescriptionIt(rs.getString(DbConstants.DESC_IT));
|
||||
returnValue.setGame(rs.getString(DbConstants.GAME));
|
||||
returnValue.setCover(rs.getString(DbConstants.COVER));
|
||||
returnValue.setScreen1(rs.getString(DbConstants.SCREEN1));
|
||||
|
@ -632,6 +685,14 @@ public class DbConnector
|
|||
st.append(COMMA);
|
||||
st.append(details.getDescription());
|
||||
st.append(COMMA);
|
||||
st.append(details.getDescriptionDe());
|
||||
st.append(COMMA);
|
||||
st.append(details.getDescriptionFr());
|
||||
st.append(COMMA);
|
||||
st.append(details.getDescriptionEs());
|
||||
st.append(COMMA);
|
||||
st.append(details.getDescriptionIt());
|
||||
st.append(COMMA);
|
||||
st.append(details.getGame());
|
||||
st.append(COMMA);
|
||||
st.append(details.getCover());
|
||||
|
@ -703,6 +764,22 @@ public class DbConnector
|
|||
sqlBuilder.append("=\"");
|
||||
sqlBuilder.append(details.getDescription());
|
||||
sqlBuilder.append("\",");
|
||||
sqlBuilder.append(DbConstants.DESC_DE);
|
||||
sqlBuilder.append("=\"");
|
||||
sqlBuilder.append(details.getDescriptionDe());
|
||||
sqlBuilder.append("\",");
|
||||
sqlBuilder.append(DbConstants.DESC_FR);
|
||||
sqlBuilder.append("=\"");
|
||||
sqlBuilder.append(details.getDescriptionFr());
|
||||
sqlBuilder.append("\",");
|
||||
sqlBuilder.append(DbConstants.DESC_ES);
|
||||
sqlBuilder.append("=\"");
|
||||
sqlBuilder.append(details.getDescriptionEs());
|
||||
sqlBuilder.append("\",");
|
||||
sqlBuilder.append(DbConstants.DESC_IT);
|
||||
sqlBuilder.append("=\"");
|
||||
sqlBuilder.append(details.getDescriptionIt());
|
||||
sqlBuilder.append("\",");
|
||||
sqlBuilder.append(DbConstants.GAME);
|
||||
sqlBuilder.append("=\"");
|
||||
sqlBuilder.append(details.getGame());
|
||||
|
|
|
@ -0,0 +1,194 @@
|
|||
package se.lantz.gui;
|
||||
|
||||
import java.awt.LayoutManager;
|
||||
import java.awt.event.FocusAdapter;
|
||||
import java.awt.event.FocusEvent;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
import java.awt.GridBagLayout;
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.KeyStroke;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.event.DocumentEvent;
|
||||
import javax.swing.event.DocumentListener;
|
||||
import javax.swing.text.DefaultStyledDocument;
|
||||
|
||||
import se.lantz.model.InfoModel;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.GridBagConstraints;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JLabel;
|
||||
import java.awt.Insets;
|
||||
import java.awt.KeyboardFocusManager;
|
||||
|
||||
public class DescriptionPanel extends JPanel
|
||||
{
|
||||
public enum Language
|
||||
{
|
||||
en, de, fr, es, it
|
||||
}
|
||||
private JTextArea descriptionTextArea;
|
||||
private JScrollPane descriptionScrollPane;
|
||||
private JLabel charCountLabel;
|
||||
private InfoModel model;
|
||||
private Language language;
|
||||
|
||||
public DescriptionPanel(InfoModel model, Language language)
|
||||
{
|
||||
this.model = model;
|
||||
this.language = language;
|
||||
GridBagLayout gridBagLayout = new GridBagLayout();
|
||||
setLayout(gridBagLayout);
|
||||
GridBagConstraints gbc_descriptionScrollPane = new GridBagConstraints();
|
||||
gbc_descriptionScrollPane.weighty = 1.0;
|
||||
gbc_descriptionScrollPane.weightx = 1.0;
|
||||
gbc_descriptionScrollPane.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_descriptionScrollPane.fill = GridBagConstraints.BOTH;
|
||||
gbc_descriptionScrollPane.gridx = 0;
|
||||
gbc_descriptionScrollPane.gridy = 0;
|
||||
add(getDescriptionScrollPane(), gbc_descriptionScrollPane);
|
||||
GridBagConstraints gbc_charCountLabel = new GridBagConstraints();
|
||||
gbc_charCountLabel.insets = new Insets(0, 5, 0, 5);
|
||||
gbc_charCountLabel.anchor = GridBagConstraints.NORTHWEST;
|
||||
gbc_charCountLabel.gridx = 0;
|
||||
gbc_charCountLabel.gridy = 1;
|
||||
add(getCharCountLabel(), gbc_charCountLabel);
|
||||
|
||||
}
|
||||
|
||||
protected JTextArea getDescriptionTextArea() {
|
||||
if (descriptionTextArea == null) {
|
||||
descriptionTextArea = new JTextArea();
|
||||
descriptionTextArea.setFont(new JLabel().getFont());
|
||||
descriptionTextArea.setWrapStyleWord(true);
|
||||
descriptionTextArea.setLineWrap(true);
|
||||
|
||||
DefaultStyledDocument doc = new DefaultStyledDocument();
|
||||
doc.addDocumentListener(new DocumentListener()
|
||||
{
|
||||
@Override
|
||||
public void changedUpdate(DocumentEvent e)
|
||||
{
|
||||
updateDescriptionCharCount(e.getDocument().getLength());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void insertUpdate(DocumentEvent e)
|
||||
{
|
||||
updateDescriptionCharCount(e.getDocument().getLength());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeUpdate(DocumentEvent e)
|
||||
{
|
||||
updateDescriptionCharCount(e.getDocument().getLength());
|
||||
}
|
||||
});
|
||||
descriptionTextArea.setDocument(doc);
|
||||
|
||||
//Setup tab and shift tab to transfer focus
|
||||
Set<KeyStroke> strokes = new HashSet<>(Arrays.asList(KeyStroke.getKeyStroke("pressed TAB")));
|
||||
descriptionTextArea.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, strokes);
|
||||
strokes = new HashSet<>(Arrays.asList(KeyStroke.getKeyStroke("shift pressed TAB")));
|
||||
descriptionTextArea.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, strokes);
|
||||
|
||||
getCharCountLabel()
|
||||
.setToolTipText("<html>The Carousel description screen can only show a limited number of characters.<br>Consider limiting the text to 512 characters at the most.</html>");
|
||||
|
||||
updateDescriptionCharCount(doc.getLength());
|
||||
|
||||
descriptionTextArea.addKeyListener(new KeyAdapter()
|
||||
{
|
||||
@Override
|
||||
public void keyReleased(KeyEvent e)
|
||||
{
|
||||
JTextArea textField = (JTextArea) e.getSource();
|
||||
switch (language)
|
||||
{
|
||||
case de:
|
||||
model.setDescriptionDe(textField.getText());
|
||||
break;
|
||||
case en:
|
||||
model.setDescription(textField.getText());
|
||||
break;
|
||||
case es:
|
||||
model.setDescriptionEs(textField.getText());
|
||||
break;
|
||||
case fr:
|
||||
model.setDescriptionFr(textField.getText());
|
||||
break;
|
||||
case it:
|
||||
model.setDescriptionIt(textField.getText());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
descriptionTextArea.addFocusListener(new FocusAdapter()
|
||||
{
|
||||
@Override
|
||||
public void focusLost(FocusEvent e)
|
||||
{
|
||||
//Read the text from the model again to "format" it
|
||||
JTextArea textField = (JTextArea) e.getSource();
|
||||
switch (language)
|
||||
{
|
||||
case de:
|
||||
textField.setText(model.getDescriptionDe());
|
||||
break;
|
||||
case en:
|
||||
textField.setText(model.getDescription());
|
||||
break;
|
||||
case es:
|
||||
textField.setText(model.getDescriptionEs());
|
||||
break;
|
||||
case fr:
|
||||
textField.setText(model.getDescriptionFr());
|
||||
break;
|
||||
case it:
|
||||
textField.setText(model.getDescriptionIt());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
return descriptionTextArea;
|
||||
}
|
||||
private JScrollPane getDescriptionScrollPane() {
|
||||
if (descriptionScrollPane == null) {
|
||||
descriptionScrollPane = new JScrollPane();
|
||||
descriptionScrollPane.setPreferredSize(new Dimension(290, 150));
|
||||
descriptionScrollPane.setViewportView(getDescriptionTextArea());
|
||||
}
|
||||
return descriptionScrollPane;
|
||||
}
|
||||
private JLabel getCharCountLabel() {
|
||||
if (charCountLabel == null) {
|
||||
charCountLabel = new JLabel("0");
|
||||
}
|
||||
return charCountLabel;
|
||||
}
|
||||
|
||||
|
||||
private void updateDescriptionCharCount(int length)
|
||||
{
|
||||
if (length > 512)
|
||||
{
|
||||
getCharCountLabel().setIcon(UIManager.getIcon("OptionPane.warningIcon"));
|
||||
}
|
||||
else
|
||||
{
|
||||
getCharCountLabel().setIcon(null);
|
||||
}
|
||||
getCharCountLabel().setText(length + " characters (recommended max: 512)");
|
||||
}
|
||||
}
|
|
@ -1,43 +1,30 @@
|
|||
package se.lantz.gui;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.Insets;
|
||||
import java.awt.KeyboardFocusManager;
|
||||
import java.awt.event.FocusAdapter;
|
||||
import java.awt.event.FocusEvent;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.beans.Beans;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JSpinner;
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.JTabbedPane;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.KeyStroke;
|
||||
import javax.swing.SpinnerModel;
|
||||
import javax.swing.SpinnerNumberModel;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.event.DocumentEvent;
|
||||
import javax.swing.event.DocumentListener;
|
||||
import javax.swing.text.DefaultStyledDocument;
|
||||
|
||||
import se.lantz.model.InfoModel;
|
||||
|
||||
public class InfoPanel extends JPanel
|
||||
{
|
||||
private InfoModel model;
|
||||
private JPanel textPanel;
|
||||
private JPanel settingsPanel;
|
||||
private JLabel titleLabel;
|
||||
private JTextField titleField;
|
||||
private JLabel authorLabel;
|
||||
|
@ -48,11 +35,13 @@ public class InfoPanel extends JPanel
|
|||
private JSpinner yearField;
|
||||
private JLabel genreLabel;
|
||||
private GenreComboBox genreComboBox;
|
||||
private JLabel descriptionLabel;
|
||||
private JScrollPane descriptionScrollPane;
|
||||
private JTextArea descriptionTextArea;
|
||||
private ScreenshotsPanel screensPanel;
|
||||
private JLabel charCountLabel;
|
||||
private JTabbedPane descriptionTabbedPane;
|
||||
private DescriptionPanel descriptionPanel;
|
||||
private DescriptionPanel descriptionDePanel;
|
||||
private DescriptionPanel descriptionFrPanel;
|
||||
private DescriptionPanel descriptionEsPanel;
|
||||
private DescriptionPanel descriptionItPanel;
|
||||
|
||||
public InfoPanel(InfoModel model)
|
||||
{
|
||||
|
@ -61,14 +50,12 @@ public class InfoPanel extends JPanel
|
|||
GridBagLayout gbl_this = new GridBagLayout();
|
||||
this.setLayout(gbl_this);
|
||||
GridBagConstraints gbc_titleLabel = new GridBagConstraints();
|
||||
gbc_titleLabel.gridwidth = 2;
|
||||
gbc_titleLabel.anchor = GridBagConstraints.WEST;
|
||||
gbc_titleLabel.insets = new Insets(10, 10, 0, 5);
|
||||
gbc_titleLabel.gridx = 0;
|
||||
gbc_titleLabel.gridy = 0;
|
||||
this.add(getTitleLabel(), gbc_titleLabel);
|
||||
GridBagConstraints gbc_titleField = new GridBagConstraints();
|
||||
gbc_titleField.gridwidth = 2;
|
||||
gbc_titleField.insets = new Insets(0, 10, 5, 5);
|
||||
gbc_titleField.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_titleField.gridx = 0;
|
||||
|
@ -77,11 +64,10 @@ public class InfoPanel extends JPanel
|
|||
GridBagConstraints gbc_yearField = new GridBagConstraints();
|
||||
gbc_yearField.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_yearField.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_yearField.gridx = 2;
|
||||
gbc_yearField.gridx = 1;
|
||||
gbc_yearField.gridy = 1;
|
||||
this.add(getYearField(), gbc_yearField);
|
||||
GridBagConstraints gbc_authorLabel = new GridBagConstraints();
|
||||
gbc_authorLabel.gridwidth = 2;
|
||||
gbc_authorLabel.insets = new Insets(0, 10, 0, 5);
|
||||
gbc_authorLabel.anchor = GridBagConstraints.WEST;
|
||||
gbc_authorLabel.gridx = 0;
|
||||
|
@ -90,19 +76,17 @@ public class InfoPanel extends JPanel
|
|||
GridBagConstraints gbc_genreLabel = new GridBagConstraints();
|
||||
gbc_genreLabel.anchor = GridBagConstraints.WEST;
|
||||
gbc_genreLabel.insets = new Insets(0, 0, 0, 5);
|
||||
gbc_genreLabel.gridx = 2;
|
||||
gbc_genreLabel.gridx = 1;
|
||||
gbc_genreLabel.gridy = 2;
|
||||
this.add(getGenreLabel(), gbc_genreLabel);
|
||||
GridBagConstraints gbc_authorField = new GridBagConstraints();
|
||||
gbc_authorField.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_authorField.anchor = GridBagConstraints.WEST;
|
||||
gbc_authorField.gridwidth = 2;
|
||||
gbc_authorField.insets = new Insets(0, 10, 5, 100);
|
||||
gbc_authorField.gridx = 0;
|
||||
gbc_authorField.gridy = 3;
|
||||
this.add(getAuthorField(), gbc_authorField);
|
||||
GridBagConstraints gbc_composerLabel = new GridBagConstraints();
|
||||
gbc_composerLabel.gridwidth = 2;
|
||||
gbc_composerLabel.anchor = GridBagConstraints.WEST;
|
||||
gbc_composerLabel.insets = new Insets(0, 10, 0, 5);
|
||||
gbc_composerLabel.gridx = 0;
|
||||
|
@ -111,7 +95,6 @@ public class InfoPanel extends JPanel
|
|||
GridBagConstraints gbc_composerField = new GridBagConstraints();
|
||||
gbc_composerField.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_composerField.anchor = GridBagConstraints.WEST;
|
||||
gbc_composerField.gridwidth = 2;
|
||||
gbc_composerField.insets = new Insets(0, 10, 5, 100);
|
||||
gbc_composerField.gridx = 0;
|
||||
gbc_composerField.gridy = 5;
|
||||
|
@ -119,30 +102,22 @@ public class InfoPanel extends JPanel
|
|||
GridBagConstraints gbc_yearLabel = new GridBagConstraints();
|
||||
gbc_yearLabel.anchor = GridBagConstraints.WEST;
|
||||
gbc_yearLabel.insets = new Insets(10, 0, 0, 5);
|
||||
gbc_yearLabel.gridx = 2;
|
||||
gbc_yearLabel.gridx = 1;
|
||||
gbc_yearLabel.gridy = 0;
|
||||
this.add(getYearLabel(), gbc_yearLabel);
|
||||
GridBagConstraints gbc_genreComboBox = new GridBagConstraints();
|
||||
gbc_genreComboBox.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_genreComboBox.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_genreComboBox.gridx = 2;
|
||||
gbc_genreComboBox.gridx = 1;
|
||||
gbc_genreComboBox.gridy = 3;
|
||||
this.add(getGenreComboBox(), gbc_genreComboBox);
|
||||
GridBagConstraints gbc_descriptionLabel = new GridBagConstraints();
|
||||
gbc_descriptionLabel.gridwidth = 2;
|
||||
gbc_descriptionLabel.insets = new Insets(0, 10, 0, 5);
|
||||
gbc_descriptionLabel.anchor = GridBagConstraints.WEST;
|
||||
gbc_descriptionLabel.gridx = 0;
|
||||
gbc_descriptionLabel.gridy = 6;
|
||||
this.add(getDescriptionLabel(), gbc_descriptionLabel);
|
||||
GridBagConstraints gbc_descriptionScrollPane = new GridBagConstraints();
|
||||
gbc_descriptionScrollPane.anchor = GridBagConstraints.NORTH;
|
||||
gbc_descriptionScrollPane.gridwidth = 2;
|
||||
gbc_descriptionScrollPane.insets = new Insets(0, 10, 0, 5);
|
||||
gbc_descriptionScrollPane.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_descriptionScrollPane.gridx = 0;
|
||||
gbc_descriptionScrollPane.gridy = 7;
|
||||
this.add(getDescriptionScrollPane(), gbc_descriptionScrollPane);
|
||||
GridBagConstraints gbc_descriptionTabbedPane = new GridBagConstraints();
|
||||
gbc_descriptionTabbedPane.fill = GridBagConstraints.BOTH;
|
||||
gbc_descriptionTabbedPane.insets = new Insets(0, 10, 5, 5);
|
||||
gbc_descriptionTabbedPane.gridx = 0;
|
||||
gbc_descriptionTabbedPane.gridy = 6;
|
||||
gbc_descriptionTabbedPane.gridheight = 3;
|
||||
add(getDescriptionTabbedPane(), gbc_descriptionTabbedPane);
|
||||
GridBagConstraints gbc_screensPanel = new GridBagConstraints();
|
||||
gbc_screensPanel.fill = GridBagConstraints.BOTH;
|
||||
gbc_screensPanel.weighty = 1.0;
|
||||
|
@ -150,37 +125,16 @@ public class InfoPanel extends JPanel
|
|||
gbc_screensPanel.weightx = 1.0;
|
||||
gbc_screensPanel.insets = new Insets(0, 10, 0, 0);
|
||||
gbc_screensPanel.gridheight = 9;
|
||||
gbc_screensPanel.gridx = 3;
|
||||
gbc_screensPanel.gridx = 2;
|
||||
gbc_screensPanel.gridy = 0;
|
||||
this.add(getScreensPanel(), gbc_screensPanel);
|
||||
GridBagConstraints gbc_charCountLabel = new GridBagConstraints();
|
||||
gbc_charCountLabel.gridwidth = 2;
|
||||
gbc_charCountLabel.anchor = GridBagConstraints.NORTHWEST;
|
||||
gbc_charCountLabel.insets = new Insets(5, 10, 0, 5);
|
||||
gbc_charCountLabel.gridx = 0;
|
||||
gbc_charCountLabel.gridy = 8;
|
||||
add(getCharCountLabel(), gbc_charCountLabel);
|
||||
|
||||
if (!Beans.isDesignTime())
|
||||
{
|
||||
model.addPropertyChangeListener((e) -> modelChanged());
|
||||
}
|
||||
}
|
||||
|
||||
// private void initFont()
|
||||
// {
|
||||
// try {
|
||||
// c64Font = Font.createFont(Font.TRUETYPE_FONT, getClass().getResource("/se/lantz/C64_Pro-STYLE.ttf").openStream());
|
||||
// GraphicsEnvironment genv = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||
// genv.registerFont(c64Font);
|
||||
// // makesure to derive the size
|
||||
// c64Font = c64Font.deriveFont(12f);
|
||||
// } catch (FontFormatException | IOException e) {
|
||||
// // TODO Auto-generated catch block
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
//
|
||||
// }
|
||||
|
||||
private void modelChanged()
|
||||
{
|
||||
// Read from model
|
||||
|
@ -188,9 +142,25 @@ public class InfoPanel extends JPanel
|
|||
{
|
||||
getTitleField().setText(model.getTitle());
|
||||
}
|
||||
if (!getDescriptionTextArea().hasFocus())
|
||||
if (!getDescriptionPanel().getDescriptionTextArea().hasFocus())
|
||||
{
|
||||
getDescriptionTextArea().setText(model.getDescription());
|
||||
getDescriptionPanel().getDescriptionTextArea().setText(model.getDescription());
|
||||
}
|
||||
if (!getDescriptionDePanel().getDescriptionTextArea().hasFocus())
|
||||
{
|
||||
getDescriptionDePanel().getDescriptionTextArea().setText(model.getDescriptionDe());
|
||||
}
|
||||
if (!getDescriptionFrPanel().getDescriptionTextArea().hasFocus())
|
||||
{
|
||||
getDescriptionFrPanel().getDescriptionTextArea().setText(model.getDescriptionFr());
|
||||
}
|
||||
if (!getDescriptionEsPanel().getDescriptionTextArea().hasFocus())
|
||||
{
|
||||
getDescriptionEsPanel().getDescriptionTextArea().setText(model.getDescriptionEs());
|
||||
}
|
||||
if (!getDescriptionItPanel().getDescriptionTextArea().hasFocus())
|
||||
{
|
||||
getDescriptionItPanel().getDescriptionTextArea().setText(model.getDescriptionIt());
|
||||
}
|
||||
if (!getYearField().hasFocus())
|
||||
{
|
||||
|
@ -210,16 +180,6 @@ public class InfoPanel extends JPanel
|
|||
}
|
||||
}
|
||||
|
||||
private JPanel getSettingsPanel()
|
||||
{
|
||||
if (settingsPanel == null)
|
||||
{
|
||||
settingsPanel = new JPanel();
|
||||
settingsPanel.setLayout(new BorderLayout(0, 0));
|
||||
}
|
||||
return settingsPanel;
|
||||
}
|
||||
|
||||
private JLabel getTitleLabel()
|
||||
{
|
||||
if (titleLabel == null)
|
||||
|
@ -368,92 +328,6 @@ public class InfoPanel extends JPanel
|
|||
return genreComboBox;
|
||||
}
|
||||
|
||||
private JLabel getDescriptionLabel()
|
||||
{
|
||||
if (descriptionLabel == null)
|
||||
{
|
||||
descriptionLabel = new JLabel("Description");
|
||||
}
|
||||
return descriptionLabel;
|
||||
}
|
||||
|
||||
private JScrollPane getDescriptionScrollPane()
|
||||
{
|
||||
if (descriptionScrollPane == null)
|
||||
{
|
||||
descriptionScrollPane = new JScrollPane();
|
||||
descriptionScrollPane.setPreferredSize(new Dimension(290, 150));
|
||||
descriptionScrollPane.setViewportView(getDescriptionTextArea());
|
||||
}
|
||||
return descriptionScrollPane;
|
||||
}
|
||||
|
||||
private JTextArea getDescriptionTextArea()
|
||||
{
|
||||
if (descriptionTextArea == null)
|
||||
{
|
||||
descriptionTextArea = new JTextArea();
|
||||
descriptionTextArea.setFont(getTitleField().getFont());
|
||||
descriptionTextArea.setWrapStyleWord(true);
|
||||
descriptionTextArea.setLineWrap(true);
|
||||
|
||||
DefaultStyledDocument doc = new DefaultStyledDocument();
|
||||
doc.addDocumentListener(new DocumentListener()
|
||||
{
|
||||
@Override
|
||||
public void changedUpdate(DocumentEvent e)
|
||||
{
|
||||
updateDescriptionCharCount(e.getDocument().getLength());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void insertUpdate(DocumentEvent e)
|
||||
{
|
||||
updateDescriptionCharCount(e.getDocument().getLength());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeUpdate(DocumentEvent e)
|
||||
{
|
||||
updateDescriptionCharCount(e.getDocument().getLength());
|
||||
}
|
||||
});
|
||||
descriptionTextArea.setDocument(doc);
|
||||
|
||||
//Setup tab and shift tab to transfer focus
|
||||
Set<KeyStroke> strokes = new HashSet<>(Arrays.asList(KeyStroke.getKeyStroke("pressed TAB")));
|
||||
descriptionTextArea.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, strokes);
|
||||
strokes = new HashSet<>(Arrays.asList(KeyStroke.getKeyStroke("shift pressed TAB")));
|
||||
descriptionTextArea.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, strokes);
|
||||
|
||||
getCharCountLabel()
|
||||
.setToolTipText("<html>The Carousel description screen can only show a limited number of characters.<br>Consider limiting the text to 512 characters at the most.</html>");
|
||||
|
||||
updateDescriptionCharCount(doc.getLength());
|
||||
|
||||
descriptionTextArea.addKeyListener(new KeyAdapter()
|
||||
{
|
||||
@Override
|
||||
public void keyReleased(KeyEvent e)
|
||||
{
|
||||
JTextArea textField = (JTextArea) e.getSource();
|
||||
model.setDescription(textField.getText());
|
||||
}
|
||||
});
|
||||
descriptionTextArea.addFocusListener(new FocusAdapter()
|
||||
{
|
||||
@Override
|
||||
public void focusLost(FocusEvent e)
|
||||
{
|
||||
//Read the text from the model again to "format" it
|
||||
JTextArea textField = (JTextArea) e.getSource();
|
||||
textField.setText(model.getDescription());
|
||||
}
|
||||
});
|
||||
}
|
||||
return descriptionTextArea;
|
||||
}
|
||||
|
||||
public ScreenshotsPanel getScreensPanel()
|
||||
{
|
||||
if (screensPanel == null)
|
||||
|
@ -463,30 +337,68 @@ public class InfoPanel extends JPanel
|
|||
return screensPanel;
|
||||
}
|
||||
|
||||
private JLabel getCharCountLabel()
|
||||
{
|
||||
if (charCountLabel == null)
|
||||
{
|
||||
charCountLabel = new JLabel("0");
|
||||
}
|
||||
return charCountLabel;
|
||||
}
|
||||
|
||||
private void updateDescriptionCharCount(int length)
|
||||
{
|
||||
if (length > 512)
|
||||
{
|
||||
getCharCountLabel().setIcon(UIManager.getIcon("OptionPane.warningIcon"));
|
||||
}
|
||||
else
|
||||
{
|
||||
getCharCountLabel().setIcon(null);
|
||||
}
|
||||
getCharCountLabel().setText(length + " characters (recommended max: 512)");
|
||||
}
|
||||
|
||||
void focusTitleField()
|
||||
{
|
||||
getTitleField().requestFocus();
|
||||
}
|
||||
|
||||
private JTabbedPane getDescriptionTabbedPane()
|
||||
{
|
||||
if (descriptionTabbedPane == null)
|
||||
{
|
||||
descriptionTabbedPane = new JTabbedPane(JTabbedPane.TOP);
|
||||
descriptionTabbedPane.setPreferredSize(new Dimension(290, 150));
|
||||
descriptionTabbedPane.addTab("Description: en", null, getDescriptionPanel(), null);
|
||||
descriptionTabbedPane.addTab("de", null, getDescriptionDePanel(), null);
|
||||
descriptionTabbedPane.addTab("fr", null, getDescriptionFrPanel(), null);
|
||||
descriptionTabbedPane.addTab("es", null, getDescriptionEsPanel(), null);
|
||||
descriptionTabbedPane.addTab("it", null, getDescriptionItPanel(), null);
|
||||
}
|
||||
return descriptionTabbedPane;
|
||||
}
|
||||
|
||||
private DescriptionPanel getDescriptionPanel()
|
||||
{
|
||||
if (descriptionPanel == null)
|
||||
{
|
||||
descriptionPanel = new DescriptionPanel(model, DescriptionPanel.Language.en);
|
||||
}
|
||||
return descriptionPanel;
|
||||
}
|
||||
|
||||
private DescriptionPanel getDescriptionDePanel()
|
||||
{
|
||||
if (descriptionDePanel == null)
|
||||
{
|
||||
descriptionDePanel = new DescriptionPanel(model, DescriptionPanel.Language.de);
|
||||
}
|
||||
return descriptionDePanel;
|
||||
}
|
||||
|
||||
private DescriptionPanel getDescriptionFrPanel()
|
||||
{
|
||||
if (descriptionFrPanel == null)
|
||||
{
|
||||
descriptionFrPanel = new DescriptionPanel(model, DescriptionPanel.Language.fr);
|
||||
}
|
||||
return descriptionFrPanel;
|
||||
}
|
||||
|
||||
private DescriptionPanel getDescriptionEsPanel()
|
||||
{
|
||||
if (descriptionEsPanel == null)
|
||||
{
|
||||
descriptionEsPanel = new DescriptionPanel(model, DescriptionPanel.Language.es);
|
||||
}
|
||||
return descriptionEsPanel;
|
||||
}
|
||||
|
||||
private DescriptionPanel getDescriptionItPanel()
|
||||
{
|
||||
if (descriptionItPanel == null)
|
||||
{
|
||||
descriptionItPanel = new DescriptionPanel(model, DescriptionPanel.Language.it);
|
||||
}
|
||||
return descriptionItPanel;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -148,6 +148,10 @@ public class ImportManager
|
|||
String composer = "";
|
||||
String genre = "";
|
||||
String description = "";
|
||||
String description_de = "";
|
||||
String description_fr = "";
|
||||
String description_es = "";
|
||||
String description_it = "";
|
||||
String gamefile = "";
|
||||
String coverfile = "";
|
||||
String screen1file = "";
|
||||
|
@ -183,6 +187,22 @@ public class ImportManager
|
|||
{
|
||||
description = line.replace("\"", "\"\"").substring(5);
|
||||
}
|
||||
else if (line.startsWith("D:de"))
|
||||
{
|
||||
description_de = line.replace("\"", "\"\"").substring(5);
|
||||
}
|
||||
else if (line.startsWith("D:fr"))
|
||||
{
|
||||
description_fr = line.replace("\"", "\"\"").substring(5);
|
||||
}
|
||||
else if (line.startsWith("D:es"))
|
||||
{
|
||||
description_es = line.replace("\"", "\"\"").substring(5);
|
||||
}
|
||||
else if (line.startsWith("D:it"))
|
||||
{
|
||||
description_it = line.replace("\"", "\"\"").substring(5);
|
||||
}
|
||||
else if (line.startsWith("F:"))
|
||||
{
|
||||
gamefile = line.substring(2);
|
||||
|
@ -241,6 +261,25 @@ public class ImportManager
|
|||
verticalShift = line.substring(2);
|
||||
}
|
||||
}
|
||||
|
||||
//Check if other languages are the same as english. If that's the case don't import it, leave it empty.
|
||||
if (description_de.equals(description))
|
||||
{
|
||||
description_de = "";
|
||||
}
|
||||
if (description_fr.equals(description))
|
||||
{
|
||||
description_fr = "";
|
||||
}
|
||||
if (description_es.equals(description))
|
||||
{
|
||||
description_es = "";
|
||||
}
|
||||
if (description_it.equals(description))
|
||||
{
|
||||
description_it = "";
|
||||
}
|
||||
|
||||
// Construct a data row
|
||||
List<String> list = Arrays.asList(title,
|
||||
year,
|
||||
|
@ -248,6 +287,10 @@ public class ImportManager
|
|||
composer,
|
||||
genre,
|
||||
description,
|
||||
description_de,
|
||||
description_fr,
|
||||
description_es,
|
||||
description_it,
|
||||
gamefile,
|
||||
coverfile,
|
||||
screen1file,
|
||||
|
@ -293,10 +336,10 @@ public class ImportManager
|
|||
|
||||
String[] splittedForPaths = dbRowData.split("\",\"");
|
||||
|
||||
gameName = splittedForPaths[6];
|
||||
coverName = splittedForPaths[7];
|
||||
screen1Name = splittedForPaths[8];
|
||||
screen2Name = splittedForPaths[9];
|
||||
gameName = splittedForPaths[10];
|
||||
coverName = splittedForPaths[11];
|
||||
screen1Name = splittedForPaths[12];
|
||||
screen2Name = splittedForPaths[13];
|
||||
//Copy!
|
||||
|
||||
Path coverPath = srcCoversFolder.resolve(coverName);
|
||||
|
|
|
@ -99,6 +99,11 @@ public class ScraperManager
|
|||
{
|
||||
infoModel.setGenre(genre);
|
||||
}
|
||||
else
|
||||
{
|
||||
//Use first one as default
|
||||
infoModel.setGenre("adventure");
|
||||
}
|
||||
}
|
||||
if (fields.isComposer())
|
||||
{
|
||||
|
|
|
@ -13,6 +13,10 @@ public class InfoModel extends AbstractModel
|
|||
//Use this when saving cover/screen/game files: If the title has been changed the files shall be renamed.
|
||||
private String titleInDb = "";
|
||||
private String description = "";
|
||||
private String description_de = "";
|
||||
private String description_fr = "";
|
||||
private String description_es = "";
|
||||
private String description_it = "";
|
||||
private int year = 0;
|
||||
private String genre = "";
|
||||
private String composer = "";
|
||||
|
@ -77,6 +81,74 @@ public class InfoModel extends AbstractModel
|
|||
}
|
||||
}
|
||||
|
||||
public String getDescriptionDe()
|
||||
{
|
||||
return description_de;
|
||||
}
|
||||
|
||||
public void setDescriptionDe(String description)
|
||||
{
|
||||
String old = getDescriptionDe();
|
||||
//Replace all double spaces, tabs and newlines
|
||||
this.description_de = description.replaceAll("\\s\\s+", " ");
|
||||
this.description_de = this.description_de.replace("\t", " ");
|
||||
if (!Objects.equals(old, description))
|
||||
{
|
||||
notifyChange();
|
||||
}
|
||||
}
|
||||
|
||||
public String getDescriptionFr()
|
||||
{
|
||||
return description_fr;
|
||||
}
|
||||
|
||||
public void setDescriptionFr(String description)
|
||||
{
|
||||
String old = getDescriptionFr();
|
||||
//Replace all double spaces, tabs and newlines
|
||||
this.description_fr = description.replaceAll("\\s\\s+", " ");
|
||||
this.description_fr = this.description_fr.replace("\t", " ");
|
||||
if (!Objects.equals(old, description))
|
||||
{
|
||||
notifyChange();
|
||||
}
|
||||
}
|
||||
|
||||
public String getDescriptionEs()
|
||||
{
|
||||
return description_es;
|
||||
}
|
||||
|
||||
public void setDescriptionEs(String description)
|
||||
{
|
||||
String old = getDescriptionEs();
|
||||
//Replace all double spaces, tabs and newlines
|
||||
this.description_es = description.replaceAll("\\s\\s+", " ");
|
||||
this.description_es = this.description_es.replace("\t", " ");
|
||||
if (!Objects.equals(old, description))
|
||||
{
|
||||
notifyChange();
|
||||
}
|
||||
}
|
||||
|
||||
public String getDescriptionIt()
|
||||
{
|
||||
return description_it;
|
||||
}
|
||||
|
||||
public void setDescriptionIt(String description)
|
||||
{
|
||||
String old = getDescriptionIt();
|
||||
//Replace all double spaces, tabs and newlines
|
||||
this.description_it = description.replaceAll("\\s\\s+", " ");
|
||||
this.description_it = this.description_it.replace("\t", " ");
|
||||
if (!Objects.equals(old, description))
|
||||
{
|
||||
notifyChange();
|
||||
}
|
||||
}
|
||||
|
||||
public int getYear()
|
||||
{
|
||||
return year;
|
||||
|
|
|
@ -149,6 +149,10 @@ public class MainViewModel extends AbstractModel
|
|||
|
||||
infoModel.setTitle(details.getTitle());
|
||||
infoModel.setDescription(details.getDescription());
|
||||
infoModel.setDescriptionDe(details.getDescriptionDe());
|
||||
infoModel.setDescriptionFr(details.getDescriptionFr());
|
||||
infoModel.setDescriptionEs(details.getDescriptionEs());
|
||||
infoModel.setDescriptionIt(details.getDescriptionIt());
|
||||
infoModel.setYear(details.getYear());
|
||||
infoModel.setAuthor(details.getAuthor());
|
||||
infoModel.setGenre(details.getGenre());
|
||||
|
@ -355,6 +359,10 @@ public class MainViewModel extends AbstractModel
|
|||
updatedGame.setComposer(infoModel.getComposer().replace("\"", "\"\""));
|
||||
updatedGame.setGenre(infoModel.getGenre());
|
||||
updatedGame.setDescription(infoModel.getDescription().replace("\"", "\"\""));
|
||||
updatedGame.setDescriptionDe(infoModel.getDescriptionDe().replace("\"", "\"\""));
|
||||
updatedGame.setDescriptionFr(infoModel.getDescriptionFr().replace("\"", "\"\""));
|
||||
updatedGame.setDescriptionEs(infoModel.getDescriptionEs().replace("\"", "\"\""));
|
||||
updatedGame.setDescriptionIt(infoModel.getDescriptionIt().replace("\"", "\"\""));
|
||||
updatedGame.setGame(infoModel.getGamesFile());
|
||||
updatedGame.setCover(infoModel.getCoverFile());
|
||||
updatedGame.setScreen1(infoModel.getScreens1File());
|
||||
|
|
|
@ -5,18 +5,21 @@ import se.lantz.model.JoystickModel;
|
|||
/**
|
||||
* The data structure representing a specific game.
|
||||
*
|
||||
* @author Mikael
|
||||
* @author lantzelot
|
||||
*
|
||||
*/
|
||||
public class GameDetails
|
||||
{
|
||||
|
||||
private String title = "";
|
||||
private int year = 1986;
|
||||
private String author = "";
|
||||
private String composer = "";
|
||||
private String genre = "";
|
||||
private String description = "";
|
||||
private String description_de = "";
|
||||
private String description_fr = "";
|
||||
private String description_es = "";
|
||||
private String description_it = "";
|
||||
private String game = "";
|
||||
private String cover = "";
|
||||
private String screen1 = "";
|
||||
|
@ -53,6 +56,46 @@ public class GameDetails
|
|||
this.description = description == null ? "" : description;
|
||||
}
|
||||
|
||||
public String getDescriptionDe()
|
||||
{
|
||||
return description_de;
|
||||
}
|
||||
|
||||
public void setDescriptionDe(String description)
|
||||
{
|
||||
this.description_de = description == null ? "" : description;
|
||||
}
|
||||
|
||||
public String getDescriptionFr()
|
||||
{
|
||||
return description_fr;
|
||||
}
|
||||
|
||||
public void setDescriptionFr(String description)
|
||||
{
|
||||
this.description_fr = description == null ? "" : description;
|
||||
}
|
||||
|
||||
public String getDescriptionEs()
|
||||
{
|
||||
return description_es;
|
||||
}
|
||||
|
||||
public void setDescriptionEs(String description)
|
||||
{
|
||||
this.description_es = description == null ? "" : description;
|
||||
}
|
||||
|
||||
public String getDescriptionIt()
|
||||
{
|
||||
return description_it;
|
||||
}
|
||||
|
||||
public void setDescriptionIt(String description)
|
||||
{
|
||||
this.description_it = description == null ? "" : description;
|
||||
}
|
||||
|
||||
public int getYear()
|
||||
{
|
||||
return year;
|
||||
|
|
|
@ -8,6 +8,10 @@ public class DbConstants
|
|||
public static final String COMPOSER = "Composer";
|
||||
public static final String GENRE = "Genre";
|
||||
public static final String DESC = "Description";
|
||||
public static final String DESC_DE = "Description_de";
|
||||
public static final String DESC_FR = "Description_fr";
|
||||
public static final String DESC_ES = "Description_es";
|
||||
public static final String DESC_IT = "Description_it";
|
||||
public static final String GAME = "Gamefile";
|
||||
public static final String COVER = "Coverfile";
|
||||
public static final String SCREEN1 = "Screen1file";
|
||||
|
|
|
@ -320,6 +320,10 @@ public class FileManager
|
|||
fw.write("T:" + gameDetails.getTitle() + "\n");
|
||||
fw.write("X:" + gameDetails.getSystem() + "\n");
|
||||
fw.write("D:en:" + gameDetails.getDescription() + "\n");
|
||||
fw.write("D:de:" + (gameDetails.getDescriptionDe().isEmpty() ? gameDetails.getDescription() : gameDetails.getDescriptionDe()) + "\n");
|
||||
fw.write("D:fr:" + (gameDetails.getDescriptionFr().isEmpty() ? gameDetails.getDescription() : gameDetails.getDescriptionFr()) + "\n");
|
||||
fw.write("D:es:" + (gameDetails.getDescriptionEs().isEmpty() ? gameDetails.getDescription() : gameDetails.getDescriptionEs()) + "\n");
|
||||
fw.write("D:it:" + (gameDetails.getDescriptionIt().isEmpty() ? gameDetails.getDescription() : gameDetails.getDescriptionIt()) + "\n");
|
||||
if (!gameDetails.getAuthor().isEmpty())
|
||||
{
|
||||
fw.write("A:" + gameDetails.getAuthor() + "\n");
|
||||
|
@ -329,6 +333,7 @@ public class FileManager
|
|||
fw.write("M:" + gameDetails.getComposer() + "\n");
|
||||
}
|
||||
fw.write("E:" + gameDetails.getGenre() + "\n");
|
||||
fw.write("Y:" + gameDetails.getYear() + "\n");
|
||||
if (favFormat)
|
||||
{
|
||||
String folderName = generateFileNameFromTitle(gameDetails.getTitle());
|
||||
|
|
Loading…
Reference in New Issue