Skip to content

Commit

Permalink
Fix sorting lost bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolfsblvt committed Aug 14, 2016
1 parent ceb51a9 commit 7906d60
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 12 deletions.
7 changes: 7 additions & 0 deletions src/me/corriekay/pokegoutil/utils/ConfigKey.java
@@ -1,5 +1,7 @@
package me.corriekay.pokegoutil.utils; package me.corriekay.pokegoutil.utils;


import javax.swing.*;

public enum ConfigKey { public enum ConfigKey {


DEVELOPFLAG("develop", false, Boolean.class), DEVELOPFLAG("develop", false, Boolean.class),
Expand All @@ -14,6 +16,11 @@ public enum ConfigKey {
WINDOW_POS_X("options.window.posx", 0, Integer.class), WINDOW_POS_X("options.window.posx", 0, Integer.class),
WINDOW_POS_Y("options.window.posy", 0, Integer.class), WINDOW_POS_Y("options.window.posy", 0, Integer.class),


SORT_COLINDEX_1("options.sort.1.colIndex", 0, Integer.class),
SORT_ORDER_1("options.sort.1.order", SortOrder.ASCENDING.toString(), String.class),
SORT_COLINDEX_2("options.sort.2.colIndex", 12, Integer.class),
SORT_ORDER_2("options.sort.2.order", SortOrder.DESCENDING.toString(), String.class),

TRANSFER_AFTER_EVOLVE("transfer.afterEvolve", false, Boolean.class), TRANSFER_AFTER_EVOLVE("transfer.afterEvolve", false, Boolean.class),
SHOW_BULK_POPUP("popup.afterBulk", true, Boolean.class), SHOW_BULK_POPUP("popup.afterBulk", true, Boolean.class),


Expand Down
65 changes: 53 additions & 12 deletions src/me/corriekay/pokegoutil/windows/PokemonTab.java
Expand Up @@ -9,13 +9,17 @@
import com.pokegoapi.api.PokemonGo; import com.pokegoapi.api.PokemonGo;
import com.pokegoapi.api.map.pokemon.EvolutionResult; import com.pokegoapi.api.map.pokemon.EvolutionResult;
import com.pokegoapi.api.player.PlayerProfile.Currency; import com.pokegoapi.api.player.PlayerProfile.Currency;
import com.pokegoapi.api.pokemon.*; import com.pokegoapi.api.pokemon.Pokemon;
import me.corriekay.pokegoutil.utils.*; import com.pokegoapi.api.pokemon.PokemonMeta;
import com.pokegoapi.api.pokemon.PokemonMetaRegistry;
import me.corriekay.pokegoutil.utils.ConfigKey;
import me.corriekay.pokegoutil.utils.ConfigNew;
import me.corriekay.pokegoutil.utils.Utilities;
import me.corriekay.pokegoutil.utils.helpers.DateHelper;
import me.corriekay.pokegoutil.utils.helpers.JTableColumnPacker; import me.corriekay.pokegoutil.utils.helpers.JTableColumnPacker;
import me.corriekay.pokegoutil.utils.helpers.LDocumentListener; import me.corriekay.pokegoutil.utils.helpers.LDocumentListener;
import me.corriekay.pokegoutil.utils.pokemon.PokeHandler; import me.corriekay.pokegoutil.utils.pokemon.PokeHandler;
import me.corriekay.pokegoutil.utils.pokemon.PokemonCpUtils; import me.corriekay.pokegoutil.utils.pokemon.PokemonCpUtils;
import me.corriekay.pokegoutil.utils.helpers.DateHelper;
import me.corriekay.pokegoutil.utils.pokemon.PokemonUtils; import me.corriekay.pokegoutil.utils.pokemon.PokemonUtils;
import me.corriekay.pokegoutil.utils.ui.GhostText; import me.corriekay.pokegoutil.utils.ui.GhostText;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
Expand All @@ -27,18 +31,14 @@
import javax.swing.RowSorter.SortKey; import javax.swing.RowSorter.SortKey;
import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener; import javax.swing.event.ListSelectionListener;
import javax.swing.table.AbstractTableModel; import javax.swing.table.*;
import javax.swing.table.TableModel;
import javax.swing.table.TableRowSorter;
import java.awt.*; import java.awt.*;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import java.awt.event.KeyListener; import java.awt.event.KeyListener;
import java.text.NumberFormat; import java.text.NumberFormat;
import java.util.*; import java.util.*;
import java.util.List; import java.util.List;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumn;


@SuppressWarnings("serial") @SuppressWarnings("serial")
public class PokemonTab extends JPanel { public class PokemonTab extends JPanel {
Expand Down Expand Up @@ -713,12 +713,26 @@ private static class PokemonTable extends JTable {
* 27 Double - Move 1 Rating * 27 Double - Move 1 Rating
* 28 Double - Move 2 Rating * 28 Double - Move 2 Rating
*/ */
int sortColIndex = 0; ConfigNew config = ConfigNew.getConfig();
SortOrder so = SortOrder.ASCENDING;
int sortColIndex1, sortColIndex2;
SortOrder sortOrder1, sortOrder2;


private PokemonTable() { private PokemonTable() {
setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
setAutoResizeMode(AUTO_RESIZE_OFF); setAutoResizeMode(AUTO_RESIZE_OFF);

// Load sort configs
sortColIndex1 = config.getInt(ConfigKey.SORT_COLINDEX_1);
sortColIndex2 = config.getInt(ConfigKey.SORT_COLINDEX_2);
try {
sortOrder1 = SortOrder.valueOf(config.getString(ConfigKey.SORT_ORDER_1));
sortOrder2 = SortOrder.valueOf(config.getString(ConfigKey.SORT_ORDER_2));
} catch (IllegalArgumentException e) {
e.printStackTrace();
sortOrder1 = SortOrder.ASCENDING;
sortOrder2 = SortOrder.ASCENDING;
}
} }


private void constructNewTableModel(PokemonGo go, List<Pokemon> pokes) { private void constructNewTableModel(PokemonGo go, List<Pokemon> pokes) {
Expand Down Expand Up @@ -758,10 +772,37 @@ private void constructNewTableModel(PokemonGo go, List<Pokemon> pokes) {
trs.setComparator(27, cDouble); trs.setComparator(27, cDouble);
trs.setComparator(28, cDouble); trs.setComparator(28, cDouble);
setRowSorter(trs); setRowSorter(trs);
trs.toggleSortOrder(sortColIndex);
List<SortKey> sortKeys = new ArrayList<>(); List<SortKey> sortKeys = new ArrayList<>();
sortKeys.add(new SortKey(sortColIndex, so)); sortKeys.add(new SortKey(sortColIndex1, sortOrder1));
sortKeys.add(new SortKey(sortColIndex2, sortOrder2));
trs.setSortKeys(sortKeys); trs.setSortKeys(sortKeys);

// Add listener to save those sorting values
trs.addRowSorterListener(
e -> {
RowSorter sorter = e.getSource();
if (sorter != null) {
List<SortKey> keys = sorter.getSortKeys();
if (keys.size() > 0) {
System.out.println("DEBUG-> Size: " + keys.size());
for (SortKey key : keys) {
System.out.println("SortKey: { column: " + key.getColumn() + ", order: " + key.getSortOrder().toString() + "}");
}
SortKey prim = keys.get(0);
sortOrder1 = prim.getSortOrder();
config.setString(ConfigKey.SORT_ORDER_1, sortOrder1.toString());
sortColIndex1 = prim.getColumn();
config.setInt(ConfigKey.SORT_COLINDEX_1, sortColIndex1);
}
if (keys.size() > 1) {
SortKey sec = keys.get(1);
sortOrder2 = sec.getSortOrder();
config.setString(ConfigKey.SORT_ORDER_2, sortOrder2.toString());
sortColIndex2 = sec.getColumn();
config.setInt(ConfigKey.SORT_COLINDEX_2, sortColIndex2);
}
}
});
} }
} }


Expand Down

0 comments on commit 7906d60

Please sign in to comment.