From 0cc29a3a667b4f2eef20860d32b5f8e498019a6f Mon Sep 17 00:00:00 2001 From: lantzelot-swe Date: Thu, 10 Dec 2020 22:53:38 +0100 Subject: [PATCH] adds game count for views log cleanup --- pcusb.db | Bin 352256 -> 352256 bytes .../java/se/lantz/gui/DocumentSizeFilter.java | 52 ------------------ .../lantz/gui/GameDetailsBackgroundPanel.java | 1 - .../se/lantz/gui/JoystickBottomPanel.java | 1 - src/main/java/se/lantz/gui/JoystickPanel.java | 50 ++++++++--------- .../java/se/lantz/gui/JoystickStickPanel.java | 1 - src/main/java/se/lantz/gui/MainPanel.java | 20 ++++++- .../lantz/gui/gameview/GameViewManager.java | 13 +++-- .../java/se/lantz/model/MainViewModel.java | 12 +++- .../java/se/lantz/model/data/GameView.java | 11 ++++ 10 files changed, 71 insertions(+), 90 deletions(-) delete mode 100644 src/main/java/se/lantz/gui/DocumentSizeFilter.java diff --git a/pcusb.db b/pcusb.db index 7c30f1192a38b13d1ba29db10612f76dce4037ad..d928ba1cc193ff165a6d89dc7e4f7989b1f435b0 100644 GIT binary patch delta 289 zcmZoTAlh(1bb>VF%84@0j4K-xwk9wx>gT)5z{0vkP-1ax#PD z9D&MQ7#J8hg*no6GkE#+7`XVZFz^fTed2$_e}sP--xdB2{w#hUeoK&TJNP(cgjgBH zb@`d6Pgu_=I{o81Mq34-c5a{$Ye;5^pcpHos5ldAWNKm&*hTCIWkjd@t!I>F6ai7v r%;_@1UD+yAd;VcY-!z1d2s delta 251 zcmZoTAlh(1bb>VFtcfztjI$aOwk9wx>gRjMz`}olf&VH0cmCV_7q$ydU|hmK*+4b6CC!{J!vbb-rpfRiY2{3o;YQ{r$#5ZY+yAd;1Y#y2X5RjPJqzOo E08l_eF8}}l diff --git a/src/main/java/se/lantz/gui/DocumentSizeFilter.java b/src/main/java/se/lantz/gui/DocumentSizeFilter.java deleted file mode 100644 index caf58a0..0000000 --- a/src/main/java/se/lantz/gui/DocumentSizeFilter.java +++ /dev/null @@ -1,52 +0,0 @@ -package se.lantz.gui; - -import java.awt.Toolkit; - -import javax.swing.text.AttributeSet; -import javax.swing.text.BadLocationException; -import javax.swing.text.DocumentFilter; - -public class DocumentSizeFilter extends DocumentFilter -{ - int maxCharacters; - boolean DEBUG = false; - - public DocumentSizeFilter(int maxChars) - { - maxCharacters = maxChars; - } - - public void insertString(FilterBypass fb, int offs, String str, AttributeSet a) throws BadLocationException - { - if (DEBUG) - { - System.out.println("in DocumentSizeFilter's insertString method"); - } - - //This rejects the entire insertion if it would make - //the contents too long. Another option would be - //to truncate the inserted string so the contents - //would be exactly maxCharacters in length. - if ((fb.getDocument().getLength() + str.length()) <= maxCharacters) - super.insertString(fb, offs, str, a); - else - Toolkit.getDefaultToolkit().beep(); - } - - public void replace(FilterBypass fb, int offs, int length, String str, AttributeSet a) throws BadLocationException - { - if (DEBUG) - { - System.out.println("in DocumentSizeFilter's replace method"); - } - //This rejects the entire replacement if it would make - //the contents too long. Another option would be - //to truncate the replacement string so the contents - //would be exactly maxCharacters in length. - if ((fb.getDocument().getLength() + str.length() - length) <= maxCharacters) - super.replace(fb, offs, length, str, a); - else - Toolkit.getDefaultToolkit().beep(); - } - -} \ No newline at end of file diff --git a/src/main/java/se/lantz/gui/GameDetailsBackgroundPanel.java b/src/main/java/se/lantz/gui/GameDetailsBackgroundPanel.java index ec932a9..94ac4ce 100644 --- a/src/main/java/se/lantz/gui/GameDetailsBackgroundPanel.java +++ b/src/main/java/se/lantz/gui/GameDetailsBackgroundPanel.java @@ -139,7 +139,6 @@ public class GameDetailsBackgroundPanel extends JPanel if (saveButton == null) { model.addSaveChangeListener(e -> { - logger.debug("SaveButton isDataChanged = {}", model.isDataChanged()); saveButton.setEnabled(model.isDataChanged()); }); saveButton = new JButton("Save"); diff --git a/src/main/java/se/lantz/gui/JoystickBottomPanel.java b/src/main/java/se/lantz/gui/JoystickBottomPanel.java index ec72177..e5ed5ee 100644 --- a/src/main/java/se/lantz/gui/JoystickBottomPanel.java +++ b/src/main/java/se/lantz/gui/JoystickBottomPanel.java @@ -67,7 +67,6 @@ public class JoystickBottomPanel extends JPanel getAComboBox().setSelectedCode(model.getA()); getBComboBox().setSelectedCode(model.getB()); getCComboBox().setSelectedCode(model.getC()); - System.out.println("modelChanged in JoystickBottomPanel"); } private KeySelectionComboBox getAComboBox() diff --git a/src/main/java/se/lantz/gui/JoystickPanel.java b/src/main/java/se/lantz/gui/JoystickPanel.java index 46e2a24..3a2c09f 100644 --- a/src/main/java/se/lantz/gui/JoystickPanel.java +++ b/src/main/java/se/lantz/gui/JoystickPanel.java @@ -14,13 +14,12 @@ import javax.swing.ImageIcon; import javax.swing.JCheckBox; import javax.swing.JLabel; import javax.swing.JPanel; +import javax.swing.JTextField; +import javax.swing.SwingConstants; import javax.swing.border.TitledBorder; import se.lantz.model.JoystickModel; -import javax.swing.SwingConstants; -import javax.swing.JTextField; - public class JoystickPanel extends JPanel { private JCheckBox primaryJoyCheckBox; @@ -124,9 +123,7 @@ public class JoystickPanel extends JPanel getRightFireComboBox().setSelectedCode(model.getRightFire()); getTlComboBox().setSelectedCode(model.getTl()); getTrComboBox().setSelectedCode(model.getTr()); - getConfigTextField().setText(model.getConfigString()); - System.out.println("modelChanged in JoystickStickPanel"); } private JCheckBox getPrimaryJoyCheckBox() @@ -273,31 +270,34 @@ public class JoystickPanel extends JPanel catch (Exception e) { configTextField.setText(model.getConfigString()); - } + } } }); } return configTextField; } - private JPanel getConfigPanel() { - if (configPanel == null) { - configPanel = new JPanel(); - GridBagLayout gbl_configPanel = new GridBagLayout(); - configPanel.setLayout(gbl_configPanel); - GridBagConstraints gbc_configLabel = new GridBagConstraints(); - gbc_configLabel.anchor = GridBagConstraints.WEST; - gbc_configLabel.insets = new Insets(0, 10, 0, 5); - gbc_configLabel.gridx = 0; - gbc_configLabel.gridy = 0; - configPanel.add(getConfigLabel(), gbc_configLabel); - GridBagConstraints gbc_configTextField = new GridBagConstraints(); - gbc_configTextField.insets = new Insets(0, 0, 0, 20); - gbc_configTextField.fill = GridBagConstraints.HORIZONTAL; - gbc_configTextField.weightx = 1.0; - gbc_configTextField.anchor = GridBagConstraints.NORTHWEST; - gbc_configTextField.gridx = 1; - gbc_configTextField.gridy = 0; - configPanel.add(getConfigTextField(), gbc_configTextField); + + private JPanel getConfigPanel() + { + if (configPanel == null) + { + configPanel = new JPanel(); + GridBagLayout gbl_configPanel = new GridBagLayout(); + configPanel.setLayout(gbl_configPanel); + GridBagConstraints gbc_configLabel = new GridBagConstraints(); + gbc_configLabel.anchor = GridBagConstraints.WEST; + gbc_configLabel.insets = new Insets(0, 10, 0, 5); + gbc_configLabel.gridx = 0; + gbc_configLabel.gridy = 0; + configPanel.add(getConfigLabel(), gbc_configLabel); + GridBagConstraints gbc_configTextField = new GridBagConstraints(); + gbc_configTextField.insets = new Insets(0, 0, 0, 20); + gbc_configTextField.fill = GridBagConstraints.HORIZONTAL; + gbc_configTextField.weightx = 1.0; + gbc_configTextField.anchor = GridBagConstraints.NORTHWEST; + gbc_configTextField.gridx = 1; + gbc_configTextField.gridy = 0; + configPanel.add(getConfigTextField(), gbc_configTextField); } return configPanel; } diff --git a/src/main/java/se/lantz/gui/JoystickStickPanel.java b/src/main/java/se/lantz/gui/JoystickStickPanel.java index ea1a84e..a74f4bd 100644 --- a/src/main/java/se/lantz/gui/JoystickStickPanel.java +++ b/src/main/java/se/lantz/gui/JoystickStickPanel.java @@ -62,7 +62,6 @@ public class JoystickStickPanel extends JPanel getDownComboBox().setSelectedCode(model.getDown()); getLeftComboBox().setSelectedCode(model.getLeft()); getRightComboBox().setSelectedCode(model.getRight()); - System.out.println("modelChanged in JoystickStickPanel"); } private KeySelectionComboBox getUpComboBox() diff --git a/src/main/java/se/lantz/gui/MainPanel.java b/src/main/java/se/lantz/gui/MainPanel.java index 56f0f9d..a4d16aa 100644 --- a/src/main/java/se/lantz/gui/MainPanel.java +++ b/src/main/java/se/lantz/gui/MainPanel.java @@ -49,7 +49,7 @@ public class MainPanel extends JPanel this.uiModel = uiModel; setLayout(new BorderLayout(0, 0)); add(getSplitPane(), BorderLayout.CENTER); - gameViewManager = new GameViewManager(getListViewComboBox(), uiModel); + gameViewManager = new GameViewManager(this, uiModel); uiModel.addSaveChangeListener(e -> { getListViewComboBox().setEnabled(!uiModel.isDataChanged()); @@ -278,7 +278,7 @@ public class MainPanel extends JPanel return listViewEditButton; } - private JComboBox getListViewComboBox() + public JComboBox getListViewComboBox() { if (listViewComboBox == null) { @@ -290,19 +290,33 @@ public class MainPanel extends JPanel uiModel.setSelectedGameView((GameView) listViewComboBox.getSelectedItem()); //TODO: keep track of selected index for the view and select it once data is updated getList().setSelectedIndex(0); + updateViewInfoLabel(); } }); listViewComboBox.setModel(uiModel.getGameViewModel()); } return listViewComboBox; } + + public void updateViewInfoLabel() + { + getViewInfoLabel().setText(uiModel.getGameListModel().getSize() + " of " + uiModel.getAllGamesCount()); + } private JPanel getViewInfoPanel() { if (viewInfoPanel == null) { viewInfoPanel = new JPanel(); - viewInfoPanel.add(getViewInfoLabel()); + GridBagLayout gbl_viewInfoPanel = new GridBagLayout(); + viewInfoPanel.setLayout(gbl_viewInfoPanel); + GridBagConstraints gbc_viewInfoLabel = new GridBagConstraints(); + gbc_viewInfoLabel.weightx = 1.0; + gbc_viewInfoLabel.insets = new Insets(0, 0, 5, 5); + gbc_viewInfoLabel.anchor = GridBagConstraints.EAST; + gbc_viewInfoLabel.gridx = 1; + gbc_viewInfoLabel.gridy = 0; + viewInfoPanel.add(getViewInfoLabel(), gbc_viewInfoLabel); } return viewInfoPanel; } diff --git a/src/main/java/se/lantz/gui/gameview/GameViewManager.java b/src/main/java/se/lantz/gui/gameview/GameViewManager.java index 89e526d..f251ab3 100644 --- a/src/main/java/se/lantz/gui/gameview/GameViewManager.java +++ b/src/main/java/se/lantz/gui/gameview/GameViewManager.java @@ -1,23 +1,24 @@ package se.lantz.gui.gameview; import javax.swing.JComboBox; -import javax.swing.JComponent; import javax.swing.SwingUtilities; +import se.lantz.gui.MainPanel; import se.lantz.gui.MainWindow; import se.lantz.model.MainViewModel; import se.lantz.model.data.GameView; public class GameViewManager { - - private JComboBox viewCombobox; + private JComboBox viewCombobox; private MainWindow mainWindow; private final MainViewModel uiModel; + private MainPanel mainPanel; - public GameViewManager(JComboBox viewCombobox, MainViewModel uiModel) + public GameViewManager(MainPanel mainPanel, MainViewModel uiModel) { - this.viewCombobox = viewCombobox; + this.mainPanel = mainPanel; + this.viewCombobox = mainPanel.getListViewComboBox(); this.uiModel = uiModel; } @@ -54,8 +55,8 @@ public class GameViewManager uiModel.setSelectedGameView(gameView); viewCombobox.invalidate(); viewCombobox.repaint(); + mainPanel.updateViewInfoLabel(); } } - } } diff --git a/src/main/java/se/lantz/model/MainViewModel.java b/src/main/java/se/lantz/model/MainViewModel.java index 5e2c3c4..8b371b3 100644 --- a/src/main/java/se/lantz/model/MainViewModel.java +++ b/src/main/java/se/lantz/model/MainViewModel.java @@ -26,6 +26,7 @@ public class MainViewModel extends AbstractModel GameListModel gameListModel = new GameListModel(); private GameView selectedGameView; + private int allGamesCount = 0; private InfoModel infoModel = new InfoModel(); private JoystickModel joy1Model = new JoystickModel(true); @@ -66,7 +67,6 @@ public class MainViewModel extends AbstractModel public ListModel getGameListModel() { - return gameListModel; } @@ -159,9 +159,19 @@ public class MainViewModel extends AbstractModel { gameListModel.addElement(gameListData); } + gameView.setGameCount(gamesList.size()); + if (gameView.getGameViewId() == GameView.ALL_GAMES_ID) + { + this.allGamesCount = gamesList.size(); + } logger.debug("...done."); } } + + public int getAllGamesCount() + { + return allGamesCount; + } public GameView getSelectedGameView() { diff --git a/src/main/java/se/lantz/model/data/GameView.java b/src/main/java/se/lantz/model/data/GameView.java index 8260553..4ea68bc 100644 --- a/src/main/java/se/lantz/model/data/GameView.java +++ b/src/main/java/se/lantz/model/data/GameView.java @@ -16,6 +16,8 @@ public class GameView private String sqlQuery = ""; private int gameViewId; + + private int gameCount = -1; public GameView(int gameViewId) { @@ -45,6 +47,10 @@ public class GameView @Override public String toString() { + if (gameCount > -1) + { + return name + " (" + gameCount + ")"; + } return name; } @@ -128,4 +134,9 @@ public class GameView { this.gameViewId = gameViewId; } + + public void setGameCount(int count) + { + this.gameCount = count; + } }