adds game count for views

log cleanup
This commit is contained in:
lantzelot-swe 2020-12-10 22:53:38 +01:00
parent c302267e6d
commit 0cc29a3a66
10 changed files with 71 additions and 90 deletions

BIN
pcusb.db

Binary file not shown.

View File

@ -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();
}
}

View File

@ -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");

View File

@ -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()

View File

@ -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;
}

View File

@ -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()

View File

@ -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<GameView> getListViewComboBox()
public JComboBox<GameView> 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;
}

View File

@ -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<GameView> 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();
}
}
}
}

View File

@ -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<GameListData> 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()
{

View File

@ -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;
}
}