Skip to content

Commit

Permalink
Refreshes List on settings change
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolfsblvt committed Aug 16, 2016
1 parent 386b9be commit ff1f5cf
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
14 changes: 11 additions & 3 deletions src/me/corriekay/pokegoutil/windows/MenuBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions src/me/corriekay/pokegoutil/windows/PokemonGoMainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions src/me/corriekay/pokegoutil/windows/PokemonTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ private JPanel _buildPanelForOperation(String operation, ArrayList<Pokemon> poke
return panel;
}

private ArrayList<Pokemon> getSelectedPokemon() {
public ArrayList<Pokemon> getSelectedPokemon() {
ArrayList<Pokemon> pokes = new ArrayList<>();
PokemonTableModel model = (PokemonTableModel) pt.getModel();
for (int i : pt.getSelectedRows()) {
Expand All @@ -609,7 +609,7 @@ private ArrayList<Pokemon> getSelectedPokemon() {
return pokes;
}

private void refreshList() {
public void refreshList() {
List<Pokemon> pokes = new ArrayList<>();
String search = searchBar.getText().replaceAll(" ", "").replaceAll("_", "").replaceAll("snek", "ekans").toLowerCase();
String[] terms = search.split(";");
Expand Down

0 comments on commit ff1f5cf

Please sign in to comment.