From ff1f5cf329927a543807d86e238f3365a2e47d51 Mon Sep 17 00:00:00 2001 From: Wolfsblvt Date: Tue, 16 Aug 2016 02:44:38 +0200 Subject: [PATCH] Refreshes List on settings change --- src/me/corriekay/pokegoutil/windows/MenuBar.java | 14 +++++++++++--- .../pokegoutil/windows/PokemonGoMainWindow.java | 5 +++-- .../corriekay/pokegoutil/windows/PokemonTab.java | 4 ++-- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/me/corriekay/pokegoutil/windows/MenuBar.java b/src/me/corriekay/pokegoutil/windows/MenuBar.java index 124f8cc4..30a6f185 100644 --- a/src/me/corriekay/pokegoutil/windows/MenuBar.java +++ b/src/me/corriekay/pokegoutil/windows/MenuBar.java @@ -18,7 +18,7 @@ public class MenuBar extends JMenuBar { private final PokemonGo go; private ConfigNew config = ConfigNew.getConfig(); - public MenuBar(PokemonGo go) { + public MenuBar(PokemonGo go, PokemonTab pokemonTab) { this.go = go; JMenu file, settings, help; @@ -63,12 +63,20 @@ public MenuBar(PokemonGo go) { JCheckBoxMenuItem includeFamily = new JCheckBoxMenuItem("Include Family On Searchbar"); includeFamily.setSelected(config.getBool(ConfigKey.INCLUDE_FAMILY)); - includeFamily.addItemListener(e -> config.setBool(ConfigKey.INCLUDE_FAMILY, includeFamily.isSelected())); + includeFamily.addItemListener(e -> { + config.setBool(ConfigKey.INCLUDE_FAMILY, includeFamily.isSelected()); + if (!pokemonTab.getSelectedPokemon().isEmpty()) { + SwingUtilities.invokeLater(pokemonTab::refreshList); + } + }); settings.add(includeFamily); JCheckBoxMenuItem alternativeIVCalculation = new JCheckBoxMenuItem("Use Alternative IV Calculation (weighted stats)"); alternativeIVCalculation.setSelected(config.getBool(ConfigKey.ALTERNATIVE_IV_CALCULATION)); - alternativeIVCalculation.addItemListener(e -> config.setBool(ConfigKey.ALTERNATIVE_IV_CALCULATION, alternativeIVCalculation.isSelected())); + alternativeIVCalculation.addItemListener(e -> { + config.setBool(ConfigKey.ALTERNATIVE_IV_CALCULATION, alternativeIVCalculation.isSelected()); + SwingUtilities.invokeLater(pokemonTab::refreshList); + }); settings.add(alternativeIVCalculation); add(settings); diff --git a/src/me/corriekay/pokegoutil/windows/PokemonGoMainWindow.java b/src/me/corriekay/pokegoutil/windows/PokemonGoMainWindow.java index 83f0616f..14d08e70 100644 --- a/src/me/corriekay/pokegoutil/windows/PokemonGoMainWindow.java +++ b/src/me/corriekay/pokegoutil/windows/PokemonGoMainWindow.java @@ -70,8 +70,9 @@ public void componentMoved(ComponentEvent e) { int posy = config.getInt(ConfigKey.WINDOW_POS_Y, pt.y); setLocation(posx, posy); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - setJMenuBar(new MenuBar(go)); - tab.add("Pokémon", new PokemonTab(go)); + PokemonTab pokemonTab = new PokemonTab(go); + setJMenuBar(new MenuBar(go, pokemonTab)); + tab.add("Pokémon", pokemonTab); add(tab, BorderLayout.CENTER); diff --git a/src/me/corriekay/pokegoutil/windows/PokemonTab.java b/src/me/corriekay/pokegoutil/windows/PokemonTab.java index 75c7ee9c..0df4e780 100644 --- a/src/me/corriekay/pokegoutil/windows/PokemonTab.java +++ b/src/me/corriekay/pokegoutil/windows/PokemonTab.java @@ -597,7 +597,7 @@ private JPanel _buildPanelForOperation(String operation, ArrayList poke return panel; } - private ArrayList getSelectedPokemon() { + public ArrayList getSelectedPokemon() { ArrayList pokes = new ArrayList<>(); PokemonTableModel model = (PokemonTableModel) pt.getModel(); for (int i : pt.getSelectedRows()) { @@ -609,7 +609,7 @@ private ArrayList getSelectedPokemon() { return pokes; } - private void refreshList() { + public void refreshList() { List pokes = new ArrayList<>(); String search = searchBar.getText().replaceAll(" ", "").replaceAll("_", "").replaceAll("snek", "ekans").toLowerCase(); String[] terms = search.split(";");