fix: add a warning icon to the title field and in the game list if the title is too long and wil be wrapped in the carousel
This commit is contained in:
parent
2cf0652a13
commit
634739e578
|
@ -15,6 +15,7 @@ import java.util.Arrays;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.swing.ImageIcon;
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.JScrollPane;
|
import javax.swing.JScrollPane;
|
||||||
|
@ -33,7 +34,8 @@ public class DescriptionPanel extends JPanel
|
||||||
{
|
{
|
||||||
en, de, fr, es, it
|
en, de, fr, es, it
|
||||||
}
|
}
|
||||||
|
private ImageIcon warningIcon = new ImageIcon(getClass().getResource("/se/lantz/warning-icon.png"));
|
||||||
|
|
||||||
private JTextArea descriptionTextArea;
|
private JTextArea descriptionTextArea;
|
||||||
private JScrollPane descriptionScrollPane;
|
private JScrollPane descriptionScrollPane;
|
||||||
private JLabel charCountLabel;
|
private JLabel charCountLabel;
|
||||||
|
@ -221,7 +223,7 @@ public class DescriptionPanel extends JPanel
|
||||||
{
|
{
|
||||||
if (length > 512)
|
if (length > 512)
|
||||||
{
|
{
|
||||||
getCharCountLabel().setIcon(UIManager.getIcon("OptionPane.warningIcon"));
|
getCharCountLabel().setIcon(warningIcon);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -9,9 +9,11 @@ import javax.swing.BorderFactory;
|
||||||
import javax.swing.DefaultListCellRenderer;
|
import javax.swing.DefaultListCellRenderer;
|
||||||
import javax.swing.ImageIcon;
|
import javax.swing.ImageIcon;
|
||||||
import javax.swing.JList;
|
import javax.swing.JList;
|
||||||
|
import javax.swing.JTextField;
|
||||||
import javax.swing.SwingConstants;
|
import javax.swing.SwingConstants;
|
||||||
|
|
||||||
import se.lantz.manager.SavedStatesManager;
|
import se.lantz.manager.SavedStatesManager;
|
||||||
|
import se.lantz.model.InfoModel;
|
||||||
import se.lantz.model.data.GameListData;
|
import se.lantz.model.data.GameListData;
|
||||||
import se.lantz.model.data.GameView;
|
import se.lantz.model.data.GameView;
|
||||||
import se.lantz.util.FileManager;
|
import se.lantz.util.FileManager;
|
||||||
|
@ -37,6 +39,8 @@ public class GameListDataRenderer extends DefaultListCellRenderer
|
||||||
private ImageIcon saves2Icon = new ImageIcon(this.getClass().getResource("/se/lantz/16x16SaveIcon-2.png"));
|
private ImageIcon saves2Icon = new ImageIcon(this.getClass().getResource("/se/lantz/16x16SaveIcon-2.png"));
|
||||||
private ImageIcon saves3Icon = new ImageIcon(this.getClass().getResource("/se/lantz/16x16SaveIcon-3.png"));
|
private ImageIcon saves3Icon = new ImageIcon(this.getClass().getResource("/se/lantz/16x16SaveIcon-3.png"));
|
||||||
private ImageIcon saves4Icon = new ImageIcon(this.getClass().getResource("/se/lantz/16x16SaveIcon-4.png"));
|
private ImageIcon saves4Icon = new ImageIcon(this.getClass().getResource("/se/lantz/16x16SaveIcon-4.png"));
|
||||||
|
|
||||||
|
private ImageIcon warningIcon = new ImageIcon(getClass().getResource("/se/lantz/warning-icon.png"));
|
||||||
|
|
||||||
private final Font bold;
|
private final Font bold;
|
||||||
private final Font boldItalic;
|
private final Font boldItalic;
|
||||||
|
@ -62,7 +66,7 @@ public class GameListDataRenderer extends DefaultListCellRenderer
|
||||||
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
|
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
|
||||||
if (value instanceof GameListData)
|
if (value instanceof GameListData)
|
||||||
{
|
{
|
||||||
handleGameListData(value, isSelected);
|
handleGameListData(value, isSelected, list);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -71,7 +75,7 @@ public class GameListDataRenderer extends DefaultListCellRenderer
|
||||||
return listCellRendererComponent;
|
return listCellRendererComponent;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleGameListData(Object value, boolean isSelected)
|
private void handleGameListData(Object value, boolean isSelected, JList list)
|
||||||
{
|
{
|
||||||
GameListData listData = (GameListData) value;
|
GameListData listData = (GameListData) value;
|
||||||
if (listData.isFavorite())
|
if (listData.isFavorite())
|
||||||
|
@ -120,26 +124,34 @@ public class GameListDataRenderer extends DefaultListCellRenderer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Decide which icon to use
|
//Decide which icon to use
|
||||||
int numberOfSavedStates = savedStatesManager.getNumberOfSavedStatesForGame(listData.getGameFileName());
|
int titleLength = list.getGraphics().getFontMetrics().stringWidth(listData.getTitle());
|
||||||
if (numberOfSavedStates == 1)
|
if (titleLength > InfoModel.MAX_TITLE_LENGTH)
|
||||||
{
|
{
|
||||||
this.setIcon(saves1Icon);
|
this.setIcon(warningIcon);
|
||||||
}
|
|
||||||
else if (numberOfSavedStates == 2)
|
|
||||||
{
|
|
||||||
this.setIcon(saves2Icon);
|
|
||||||
}
|
|
||||||
else if (numberOfSavedStates == 3)
|
|
||||||
{
|
|
||||||
this.setIcon(saves3Icon);
|
|
||||||
}
|
|
||||||
else if (numberOfSavedStates == 4)
|
|
||||||
{
|
|
||||||
this.setIcon(saves4Icon);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this.setIcon(null);
|
int numberOfSavedStates = savedStatesManager.getNumberOfSavedStatesForGame(listData.getGameFileName());
|
||||||
|
if (numberOfSavedStates == 1)
|
||||||
|
{
|
||||||
|
this.setIcon(saves1Icon);
|
||||||
|
}
|
||||||
|
else if (numberOfSavedStates == 2)
|
||||||
|
{
|
||||||
|
this.setIcon(saves2Icon);
|
||||||
|
}
|
||||||
|
else if (numberOfSavedStates == 3)
|
||||||
|
{
|
||||||
|
this.setIcon(saves3Icon);
|
||||||
|
}
|
||||||
|
else if (numberOfSavedStates == 4)
|
||||||
|
{
|
||||||
|
this.setIcon(saves4Icon);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.setIcon(null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package se.lantz.gui;
|
package se.lantz.gui;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.Font;
|
|
||||||
import java.awt.GridBagConstraints;
|
import java.awt.GridBagConstraints;
|
||||||
import java.awt.GridBagLayout;
|
import java.awt.GridBagLayout;
|
||||||
import java.awt.Insets;
|
import java.awt.Insets;
|
||||||
|
@ -12,19 +12,19 @@ import java.awt.event.KeyEvent;
|
||||||
import java.beans.Beans;
|
import java.beans.Beans;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
|
||||||
import javax.swing.Action;
|
import javax.swing.ImageIcon;
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.JPopupMenu;
|
|
||||||
import javax.swing.JSpinner;
|
import javax.swing.JSpinner;
|
||||||
import javax.swing.JTabbedPane;
|
import javax.swing.JTabbedPane;
|
||||||
import javax.swing.JTextArea;
|
import javax.swing.JTextArea;
|
||||||
import javax.swing.JTextField;
|
import javax.swing.JTextField;
|
||||||
import javax.swing.KeyStroke;
|
|
||||||
import javax.swing.SpinnerModel;
|
import javax.swing.SpinnerModel;
|
||||||
import javax.swing.SpinnerNumberModel;
|
import javax.swing.SpinnerNumberModel;
|
||||||
|
import javax.swing.SwingConstants;
|
||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
import javax.swing.text.DefaultEditorKit;
|
import javax.swing.event.DocumentEvent;
|
||||||
|
import javax.swing.event.DocumentListener;
|
||||||
|
|
||||||
import se.lantz.model.InfoModel;
|
import se.lantz.model.InfoModel;
|
||||||
import se.lantz.util.CustomUndoPlainDocument;
|
import se.lantz.util.CustomUndoPlainDocument;
|
||||||
|
@ -32,6 +32,8 @@ import se.lantz.util.TextComponentSupport;
|
||||||
|
|
||||||
public class InfoPanel extends JPanel
|
public class InfoPanel extends JPanel
|
||||||
{
|
{
|
||||||
|
private ImageIcon warningIcon = new ImageIcon(getClass().getResource("/se/lantz/warning-icon14x14.png"));
|
||||||
|
JLabel titleLabel;
|
||||||
private JTextField titleField;
|
private JTextField titleField;
|
||||||
private JTextField authorField;
|
private JTextField authorField;
|
||||||
private JTextField composerField;
|
private JTextField composerField;
|
||||||
|
@ -59,7 +61,8 @@ public class InfoPanel extends JPanel
|
||||||
gridBagLayout.columnWidths = new int[] { 0, 0 };
|
gridBagLayout.columnWidths = new int[] { 0, 0 };
|
||||||
setLayout(gridBagLayout);
|
setLayout(gridBagLayout);
|
||||||
|
|
||||||
JLabel titleLabel = new JLabel("Game title");
|
titleLabel = new JLabel("Game title");
|
||||||
|
titleLabel.setHorizontalTextPosition(SwingConstants.LEFT);
|
||||||
GridBagConstraints gbc_titleLabel = new GridBagConstraints();
|
GridBagConstraints gbc_titleLabel = new GridBagConstraints();
|
||||||
gbc_titleLabel.anchor = GridBagConstraints.WEST;
|
gbc_titleLabel.anchor = GridBagConstraints.WEST;
|
||||||
gbc_titleLabel.gridwidth = 2;
|
gbc_titleLabel.gridwidth = 2;
|
||||||
|
@ -250,10 +253,39 @@ public class InfoPanel extends JPanel
|
||||||
model.setTitle(textField.getText());
|
model.setTitle(textField.getText());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
titleField.getDocument().addDocumentListener(new DocumentListener()
|
||||||
|
{
|
||||||
|
public void changedUpdate(DocumentEvent e)
|
||||||
|
{
|
||||||
|
updateWarningForTitleLength();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeUpdate(DocumentEvent e)
|
||||||
|
{
|
||||||
|
updateWarningForTitleLength();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void insertUpdate(DocumentEvent e)
|
||||||
|
{
|
||||||
|
updateWarningForTitleLength();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
return titleField;
|
return titleField;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateWarningForTitleLength()
|
||||||
|
{
|
||||||
|
int length = titleField.getGraphics().getFontMetrics().stringWidth(titleField.getText());
|
||||||
|
titleLabel.setIcon(length > InfoModel.MAX_TITLE_LENGTH ? warningIcon : null);
|
||||||
|
titleLabel.setToolTipText(length > InfoModel.MAX_TITLE_LENGTH
|
||||||
|
? "The title is too long, it will be wrapped in the carousel."
|
||||||
|
: null);
|
||||||
|
titleField.setForeground(length > InfoModel.MAX_TITLE_LENGTH ? Color.RED : Color.BLACK);
|
||||||
|
}
|
||||||
|
|
||||||
private JSpinner getYearField()
|
private JSpinner getYearField()
|
||||||
{
|
{
|
||||||
if (yearField == null)
|
if (yearField == null)
|
||||||
|
@ -303,13 +335,13 @@ public class InfoPanel extends JPanel
|
||||||
{
|
{
|
||||||
authorField = new JTextField();
|
authorField = new JTextField();
|
||||||
authorField.setDocument(new CustomUndoPlainDocument()
|
authorField.setDocument(new CustomUndoPlainDocument()
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public void updateModel()
|
|
||||||
{
|
{
|
||||||
model.setAuthor(authorField.getText());
|
@Override
|
||||||
}
|
public void updateModel()
|
||||||
});
|
{
|
||||||
|
model.setAuthor(authorField.getText());
|
||||||
|
}
|
||||||
|
});
|
||||||
authorField.addKeyListener(new KeyAdapter()
|
authorField.addKeyListener(new KeyAdapter()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
|
@ -329,13 +361,13 @@ public class InfoPanel extends JPanel
|
||||||
{
|
{
|
||||||
composerField = new JTextField();
|
composerField = new JTextField();
|
||||||
composerField.setDocument(new CustomUndoPlainDocument()
|
composerField.setDocument(new CustomUndoPlainDocument()
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public void updateModel()
|
|
||||||
{
|
{
|
||||||
model.setComposer(composerField.getText());
|
@Override
|
||||||
}
|
public void updateModel()
|
||||||
});
|
{
|
||||||
|
model.setComposer(composerField.getText());
|
||||||
|
}
|
||||||
|
});
|
||||||
composerField.addKeyListener(new KeyAdapter()
|
composerField.addKeyListener(new KeyAdapter()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -9,6 +9,8 @@ import se.lantz.util.FileManager;
|
||||||
|
|
||||||
public class InfoModel extends AbstractModel implements CommonInfoModel
|
public class InfoModel extends AbstractModel implements CommonInfoModel
|
||||||
{
|
{
|
||||||
|
//This is an approximate value of what fits on one row in the carousel on theC64/theVic20
|
||||||
|
public static int MAX_TITLE_LENGTH = 163;
|
||||||
private String title = "";
|
private String title = "";
|
||||||
//Use this when saving cover/screen/game files: If the title has been changed the files shall be renamed.
|
//Use this when saving cover/screen/game files: If the title has been changed the files shall be renamed.
|
||||||
private String titleInDb = "";
|
private String titleInDb = "";
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 613 B |
Loading…
Reference in New Issue