From 1ebd4a14e7a80e2f6ed96b7ce9e7c0eaeb2f0243 Mon Sep 17 00:00:00 2001 From: lantzelot-swe Date: Sat, 6 Feb 2021 15:58:56 +0100 Subject: [PATCH] fix: only empty fields are pre-selected in the scraper dialog when opened --- .../lantz/gui/GameDetailsBackgroundPanel.java | 2 +- .../lantz/gui/scraper/C64comOptionsPanel.java | 17 ++++++++++++++++- .../lantz/gui/scraper/Gb64comOptionsPanel.java | 16 +++++++++++++++- .../gui/scraper/MobyGamesOptionsPanel.java | 17 ++++++++++++++++- .../se/lantz/gui/scraper/ScraperDialog.java | 14 ++++++++++---- .../java/se/lantz/model/data/GameDetails.java | 1 - 6 files changed, 58 insertions(+), 9 deletions(-) diff --git a/src/main/java/se/lantz/gui/GameDetailsBackgroundPanel.java b/src/main/java/se/lantz/gui/GameDetailsBackgroundPanel.java index 64b990d..aab5691 100644 --- a/src/main/java/se/lantz/gui/GameDetailsBackgroundPanel.java +++ b/src/main/java/se/lantz/gui/GameDetailsBackgroundPanel.java @@ -276,7 +276,7 @@ public class GameDetailsBackgroundPanel extends JPanel { if (scraperDialog == null) { - scraperDialog = new ScraperDialog(MainWindow.getInstance(), scraperManager); + scraperDialog = new ScraperDialog(MainWindow.getInstance(), scraperManager, model.getInfoModel()); scraperDialog.pack(); scraperDialog.setLocationRelativeTo(MainWindow.getInstance()); } diff --git a/src/main/java/se/lantz/gui/scraper/C64comOptionsPanel.java b/src/main/java/se/lantz/gui/scraper/C64comOptionsPanel.java index 221b4f1..bf32479 100644 --- a/src/main/java/se/lantz/gui/scraper/C64comOptionsPanel.java +++ b/src/main/java/se/lantz/gui/scraper/C64comOptionsPanel.java @@ -26,6 +26,7 @@ import javax.swing.UIManager; import javax.swing.event.HyperlinkEvent; import se.lantz.manager.ScraperManager; +import se.lantz.model.InfoModel; import se.lantz.model.data.ScraperFields; import se.lantz.util.ExceptionHandler; @@ -50,11 +51,13 @@ public class C64comOptionsPanel extends JPanel private JButton okButton; private JCheckBox genreCheckBox; private JCheckBox composerCheckBox; + private InfoModel model; - public C64comOptionsPanel(ScraperManager scraper, JButton okButton) + public C64comOptionsPanel(ScraperManager scraper, JButton okButton, InfoModel model) { this.scraper = scraper; this.okButton = okButton; + this.model = model; GridBagLayout gridBagLayout = new GridBagLayout(); setLayout(gridBagLayout); GridBagConstraints gbc_infoLabel = new GridBagConstraints(); @@ -386,4 +389,16 @@ public class C64comOptionsPanel extends JPanel } return composerCheckBox; } + + public void preSelectFields() + { + getTitleCheckBox().setSelected(model.getTitle().isEmpty()); + getAuthorCheckBox().setSelected(model.getAuthor().isEmpty()); + getYearCheckBox().setSelected(model.getYear() == 1986 && model.isNewGame()); + getGenreCheckBox().setSelected(model.getGenre().isEmpty()); + getComposerCheckBox().setSelected(model.getComposer().isEmpty()); + getCoverCheckBox().setSelected(model.getCoverFile().isEmpty() && model.getCoverImage() == null); + getScreensCheckBox().setSelected((model.getScreens1File().isEmpty() && model.getScreen1Image() == null) || (model.getScreens1File().isEmpty() && model.getScreen1Image() == null)); + getGameCheckBox().setSelected(model.getGamesFile().isEmpty() && model.getGamesPath() == null); + } } diff --git a/src/main/java/se/lantz/gui/scraper/Gb64comOptionsPanel.java b/src/main/java/se/lantz/gui/scraper/Gb64comOptionsPanel.java index bcf617c..bb398ff 100644 --- a/src/main/java/se/lantz/gui/scraper/Gb64comOptionsPanel.java +++ b/src/main/java/se/lantz/gui/scraper/Gb64comOptionsPanel.java @@ -26,6 +26,7 @@ import javax.swing.UIManager; import javax.swing.event.HyperlinkEvent; import se.lantz.manager.ScraperManager; +import se.lantz.model.InfoModel; import se.lantz.model.data.ScraperFields; import se.lantz.util.ExceptionHandler; @@ -49,11 +50,13 @@ public class Gb64comOptionsPanel extends JPanel private JButton okButton; private JCheckBox genreCheckBox; private JCheckBox composerCheckBox; + private InfoModel model; - public Gb64comOptionsPanel(ScraperManager scraper, JButton okButton) + public Gb64comOptionsPanel(ScraperManager scraper, JButton okButton, InfoModel model) { this.scraper = scraper; this.okButton = okButton; + this.model = model; GridBagLayout gridBagLayout = new GridBagLayout(); setLayout(gridBagLayout); GridBagConstraints gbc_infoLabel = new GridBagConstraints(); @@ -368,4 +371,15 @@ public class Gb64comOptionsPanel extends JPanel } return composerCheckBox; } + + public void preSelectFields() + { + getTitleCheckBox().setSelected(model.getTitle().isEmpty()); + getAuthorCheckBox().setSelected(model.getAuthor().isEmpty()); + getYearCheckBox().setSelected(model.getYear() == 1986 && model.isNewGame()); + getGenreCheckBox().setSelected(model.getGenre().isEmpty()); + getComposerCheckBox().setSelected(model.getComposer().isEmpty()); + getScreensCheckBox().setSelected((model.getScreens1File().isEmpty() && model.getScreen1Image() == null) || (model.getScreens1File().isEmpty() && model.getScreen1Image() == null)); + getGameCheckBox().setSelected(model.getGamesFile().isEmpty() && model.getGamesPath() == null); + } } diff --git a/src/main/java/se/lantz/gui/scraper/MobyGamesOptionsPanel.java b/src/main/java/se/lantz/gui/scraper/MobyGamesOptionsPanel.java index f1b12fb..02c5f19 100644 --- a/src/main/java/se/lantz/gui/scraper/MobyGamesOptionsPanel.java +++ b/src/main/java/se/lantz/gui/scraper/MobyGamesOptionsPanel.java @@ -26,6 +26,7 @@ import javax.swing.UIManager; import javax.swing.event.HyperlinkEvent; import se.lantz.manager.ScraperManager; +import se.lantz.model.InfoModel; import se.lantz.model.data.ScraperFields; import se.lantz.util.ExceptionHandler; @@ -50,11 +51,13 @@ public class MobyGamesOptionsPanel extends JPanel private JButton okButton; private JCheckBox genreCheckBox; private JCheckBox composerCheckBox; + private InfoModel model; - public MobyGamesOptionsPanel(ScraperManager scraper, JButton okButton) + public MobyGamesOptionsPanel(ScraperManager scraper, JButton okButton, InfoModel model) { this.scraper = scraper; this.okButton = okButton; + this.model = model; GridBagLayout gridBagLayout = new GridBagLayout(); setLayout(gridBagLayout); GridBagConstraints gbc_infoLabel = new GridBagConstraints(); @@ -384,4 +387,16 @@ public class MobyGamesOptionsPanel extends JPanel } return composerCheckBox; } + + public void preSelectFields() + { + getTitleCheckBox().setSelected(model.getTitle().isEmpty()); + getAuthorCheckBox().setSelected(model.getAuthor().isEmpty()); + getYearCheckBox().setSelected(model.getYear() == 1986 && model.isNewGame()); + getGenreCheckBox().setSelected(model.getGenre().isEmpty()); + getDescriptionCheckBox().setSelected(model.getDescription().isEmpty()); + getComposerCheckBox().setSelected(model.getComposer().isEmpty()); + getCoverCheckBox().setSelected(model.getCoverFile().isEmpty() && model.getCoverImage() == null); + getScreensCheckBox().setSelected((model.getScreens1File().isEmpty() && model.getScreen1Image() == null) || (model.getScreens1File().isEmpty() && model.getScreen1Image() == null)); + } } diff --git a/src/main/java/se/lantz/gui/scraper/ScraperDialog.java b/src/main/java/se/lantz/gui/scraper/ScraperDialog.java index 894d048..469369e 100644 --- a/src/main/java/se/lantz/gui/scraper/ScraperDialog.java +++ b/src/main/java/se/lantz/gui/scraper/ScraperDialog.java @@ -16,6 +16,7 @@ import javax.swing.JPanel; import se.lantz.gui.BaseDialog; import se.lantz.manager.ScraperManager; import se.lantz.manager.ScraperManager.SCRAPER; +import se.lantz.model.InfoModel; import se.lantz.model.data.ScraperFields; public class ScraperDialog extends BaseDialog @@ -35,10 +36,12 @@ public class ScraperDialog extends BaseDialog private JLabel scraperInfoLabel; private JComboBox scraperComboBox; private JPanel cardPanel; + private InfoModel model; - public ScraperDialog(Frame owner, ScraperManager scraper) + public ScraperDialog(Frame owner, ScraperManager scraper, InfoModel model) { super(owner); + this.model = model; setTitle("Scrape game information"); this.scraper = scraper; JPanel content = new JPanel(); @@ -58,7 +61,7 @@ public class ScraperDialog extends BaseDialog { if (mobyGamesPanel == null) { - mobyGamesPanel = new MobyGamesOptionsPanel(scraper, getOkButton()); + mobyGamesPanel = new MobyGamesOptionsPanel(scraper, getOkButton(), model); } return mobyGamesPanel; } @@ -67,7 +70,7 @@ public class ScraperDialog extends BaseDialog { if (c64comPanel == null) { - c64comPanel = new C64comOptionsPanel(scraper, getOkButton()); + c64comPanel = new C64comOptionsPanel(scraper, getOkButton(), model); } return c64comPanel; } @@ -76,7 +79,7 @@ public class ScraperDialog extends BaseDialog { if (gb64comPanel == null) { - gb64comPanel = new Gb64comOptionsPanel(scraper, getOkButton()); + gb64comPanel = new Gb64comOptionsPanel(scraper, getOkButton(), model); } return gb64comPanel; } @@ -100,6 +103,9 @@ public class ScraperDialog extends BaseDialog @Override public boolean showDialog() { + getMobyGamesPanel().preSelectFields(); + getC64comPanel().preSelectFields(); + getGb64comPanel().preSelectFields(); getMobyGamesPanel().getUrlTextField().requestFocusInWindow(); this.getRootPane().setDefaultButton(getMobyGamesPanel().getConnectButton()); diff --git a/src/main/java/se/lantz/model/data/GameDetails.java b/src/main/java/se/lantz/model/data/GameDetails.java index 6431e7c..1ac8480 100644 --- a/src/main/java/se/lantz/model/data/GameDetails.java +++ b/src/main/java/se/lantz/model/data/GameDetails.java @@ -31,7 +31,6 @@ public class GameDetails public GameDetails() { - setTitle("New Game"); setJoy1("J:1:" + JoystickModel.DEFAULT_CONFIG); setJoy2("J:2*:" + JoystickModel.DEFAULT_CONFIG); }