diff --git a/src/main/java/se/lantz/gui/DescriptionPanel.java b/src/main/java/se/lantz/gui/DescriptionPanel.java index d4416bb..81398ca 100644 --- a/src/main/java/se/lantz/gui/DescriptionPanel.java +++ b/src/main/java/se/lantz/gui/DescriptionPanel.java @@ -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,7 +34,8 @@ 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; private JLabel charCountLabel; @@ -221,7 +223,7 @@ public class DescriptionPanel extends JPanel { if (length > 512) { - getCharCountLabel().setIcon(UIManager.getIcon("OptionPane.warningIcon")); + getCharCountLabel().setIcon(warningIcon); } else { diff --git a/src/main/java/se/lantz/gui/GameListDataRenderer.java b/src/main/java/se/lantz/gui/GameListDataRenderer.java index 22e5e35..9bac1d0 100644 --- a/src/main/java/se/lantz/gui/GameListDataRenderer.java +++ b/src/main/java/se/lantz/gui/GameListDataRenderer.java @@ -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; @@ -37,6 +39,8 @@ public class GameListDataRenderer extends DefaultListCellRenderer 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 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; @@ -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,26 +124,34 @@ public class GameListDataRenderer extends DefaultListCellRenderer } } //Decide which icon to use - int numberOfSavedStates = savedStatesManager.getNumberOfSavedStatesForGame(listData.getGameFileName()); - if (numberOfSavedStates == 1) + int titleLength = list.getGraphics().getFontMetrics().stringWidth(listData.getTitle()); + if (titleLength > InfoModel.MAX_TITLE_LENGTH) { - this.setIcon(saves1Icon); - } - else if (numberOfSavedStates == 2) - { - this.setIcon(saves2Icon); - } - else if (numberOfSavedStates == 3) - { - this.setIcon(saves3Icon); - } - else if (numberOfSavedStates == 4) - { - this.setIcon(saves4Icon); + this.setIcon(warningIcon); } 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); + } } } diff --git a/src/main/java/se/lantz/gui/InfoPanel.java b/src/main/java/se/lantz/gui/InfoPanel.java index a90ec69..7dcb872 100644 --- a/src/main/java/se/lantz/gui/InfoPanel.java +++ b/src/main/java/se/lantz/gui/InfoPanel.java @@ -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) @@ -303,13 +335,13 @@ public class InfoPanel extends JPanel { authorField = new JTextField(); authorField.setDocument(new CustomUndoPlainDocument() - { - @Override - public void updateModel() { - model.setAuthor(authorField.getText()); - } - }); + @Override + public void updateModel() + { + model.setAuthor(authorField.getText()); + } + }); authorField.addKeyListener(new KeyAdapter() { @Override @@ -329,13 +361,13 @@ public class InfoPanel extends JPanel { composerField = new JTextField(); composerField.setDocument(new CustomUndoPlainDocument() - { - @Override - public void updateModel() { - model.setComposer(composerField.getText()); - } - }); + @Override + public void updateModel() + { + model.setComposer(composerField.getText()); + } + }); composerField.addKeyListener(new KeyAdapter() { @Override diff --git a/src/main/java/se/lantz/model/InfoModel.java b/src/main/java/se/lantz/model/InfoModel.java index 71901f7..a9873fa 100644 --- a/src/main/java/se/lantz/model/InfoModel.java +++ b/src/main/java/se/lantz/model/InfoModel.java @@ -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 = ""; diff --git a/src/main/resources/se/lantz/warning-icon14x14.png b/src/main/resources/se/lantz/warning-icon14x14.png new file mode 100644 index 0000000..96934d9 Binary files /dev/null and b/src/main/resources/se/lantz/warning-icon14x14.png differ