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:
lantzelot-swe 2022-03-19 14:25:07 +01:00
parent 2cf0652a13
commit 634739e578
5 changed files with 87 additions and 39 deletions

View File

@ -15,6 +15,7 @@ import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
@ -33,6 +34,7 @@ public class DescriptionPanel extends JPanel
{
en, de, fr, es, it
}
private ImageIcon warningIcon = new ImageIcon(getClass().getResource("/se/lantz/warning-icon.png"));
private JTextArea descriptionTextArea;
private JScrollPane descriptionScrollPane;
@ -221,7 +223,7 @@ public class DescriptionPanel extends JPanel
{
if (length > 512)
{
getCharCountLabel().setIcon(UIManager.getIcon("OptionPane.warningIcon"));
getCharCountLabel().setIcon(warningIcon);
}
else
{

View File

@ -9,9 +9,11 @@ import javax.swing.BorderFactory;
import javax.swing.DefaultListCellRenderer;
import javax.swing.ImageIcon;
import javax.swing.JList;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import se.lantz.manager.SavedStatesManager;
import se.lantz.model.InfoModel;
import se.lantz.model.data.GameListData;
import se.lantz.model.data.GameView;
import se.lantz.util.FileManager;
@ -38,6 +40,8 @@ public class GameListDataRenderer extends DefaultListCellRenderer
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 warningIcon = new ImageIcon(getClass().getResource("/se/lantz/warning-icon.png"));
private final Font bold;
private final Font boldItalic;
private SavedStatesManager savedStatesManager;
@ -62,7 +66,7 @@ public class GameListDataRenderer extends DefaultListCellRenderer
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (value instanceof GameListData)
{
handleGameListData(value, isSelected);
handleGameListData(value, isSelected, list);
}
else
{
@ -71,7 +75,7 @@ public class GameListDataRenderer extends DefaultListCellRenderer
return listCellRendererComponent;
}
private void handleGameListData(Object value, boolean isSelected)
private void handleGameListData(Object value, boolean isSelected, JList list)
{
GameListData listData = (GameListData) value;
if (listData.isFavorite())
@ -120,6 +124,13 @@ public class GameListDataRenderer extends DefaultListCellRenderer
}
}
//Decide which icon to use
int titleLength = list.getGraphics().getFontMetrics().stringWidth(listData.getTitle());
if (titleLength > InfoModel.MAX_TITLE_LENGTH)
{
this.setIcon(warningIcon);
}
else
{
int numberOfSavedStates = savedStatesManager.getNumberOfSavedStatesForGame(listData.getGameFileName());
if (numberOfSavedStates == 1)
{
@ -142,6 +153,7 @@ public class GameListDataRenderer extends DefaultListCellRenderer
this.setIcon(null);
}
}
}
private void handleGameListView(Object value, boolean isSelected, int index)
{

View File

@ -1,7 +1,7 @@
package se.lantz.gui;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
@ -12,19 +12,19 @@ import java.awt.event.KeyEvent;
import java.beans.Beans;
import java.util.Calendar;
import javax.swing.Action;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JSpinner;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.KeyStroke;
import javax.swing.SpinnerModel;
import javax.swing.SpinnerNumberModel;
import javax.swing.SwingConstants;
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.util.CustomUndoPlainDocument;
@ -32,6 +32,8 @@ import se.lantz.util.TextComponentSupport;
public class InfoPanel extends JPanel
{
private ImageIcon warningIcon = new ImageIcon(getClass().getResource("/se/lantz/warning-icon14x14.png"));
JLabel titleLabel;
private JTextField titleField;
private JTextField authorField;
private JTextField composerField;
@ -59,7 +61,8 @@ public class InfoPanel extends JPanel
gridBagLayout.columnWidths = new int[] { 0, 0 };
setLayout(gridBagLayout);
JLabel titleLabel = new JLabel("Game title");
titleLabel = new JLabel("Game title");
titleLabel.setHorizontalTextPosition(SwingConstants.LEFT);
GridBagConstraints gbc_titleLabel = new GridBagConstraints();
gbc_titleLabel.anchor = GridBagConstraints.WEST;
gbc_titleLabel.gridwidth = 2;
@ -250,10 +253,39 @@ public class InfoPanel extends JPanel
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;
}
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()
{
if (yearField == null)

View File

@ -9,6 +9,8 @@ import se.lantz.util.FileManager;
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 = "";
//Use this when saving cover/screen/game files: If the title has been changed the files shall be renamed.
private String titleInDb = "";

Binary file not shown.

After

Width:  |  Height:  |  Size: 613 B