Skip to content

Commit

Permalink
Changing to use ConfigNew - Phase 1
Browse files Browse the repository at this point in the history
  • Loading branch information
Cryptically committed Aug 14, 2016
1 parent e39237c commit 796db74
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
7 changes: 6 additions & 1 deletion src/me/corriekay/pokegoutil/utils/ConfigKey.java
@@ -1,7 +1,12 @@
package me.corriekay.pokegoutil.utils;

public enum ConfigKey {
WindowHeight("options.window.width", 800, Integer.class);
WINDOW_WIDTH("options.window.width", 800, Integer.class),
WINDOW_HEIGHT("options.window.height", 650, Integer.class),
WINDOW_POS_X("options.window.posx", 0, Integer.class),
WINDOW_POS_Y("options.window.posy", 0, Integer.class),

;

public final String keyName;
private Object defaultValue;
Expand Down
18 changes: 10 additions & 8 deletions src/me/corriekay/pokegoutil/windows/PokemonGoMainWindow.java
Expand Up @@ -6,6 +6,8 @@
import com.pokegoapi.exceptions.LoginFailedException;
import com.pokegoapi.exceptions.RemoteServerException;
import me.corriekay.pokegoutil.utils.Config;
import me.corriekay.pokegoutil.utils.ConfigKey;
import me.corriekay.pokegoutil.utils.ConfigNew;
import me.corriekay.pokegoutil.utils.ui.Console;
import me.corriekay.pokegoutil.utils.helpers.FileHelper;
import me.corriekay.pokegoutil.utils.helpers.UIHelper;
Expand All @@ -23,7 +25,7 @@ public class PokemonGoMainWindow extends JFrame {
private final PokemonGo go;
private final PlayerProfile pp;
public static PokemonGoMainWindow window = null;
private Config config = Config.getConfig();
private ConfigNew config = ConfigNew.getConfig();

public PokemonGo getPoGo() {
return go;
Expand Down Expand Up @@ -51,27 +53,27 @@ public PokemonGoMainWindow(PokemonGo pkmngo, Console console) {
setLayout(new BorderLayout());
refreshTitle();
setIconImage(FileHelper.loadImage("icon/PokeBall-icon.png"));
setBounds(0, 0, config.getInt("options.window.width", 800), config.getInt("options.window.height", 650));
setBounds(0, 0, config.getInt(ConfigKey.WINDOW_WIDTH), config.getInt(ConfigKey.WINDOW_HEIGHT));
// add EventHandler to save new window size and position to
// config for the app to remember over restarts
this.addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
JFrame w = (JFrame) e.getComponent();
config.setInt("options.window.width", w.getWidth());
config.setInt("options.window.height", w.getHeight());
config.setInt(ConfigKey.WINDOW_WIDTH, w.getWidth());
config.setInt(ConfigKey.WINDOW_HEIGHT, w.getHeight());
}

@Override
public void componentMoved(ComponentEvent e) {
JFrame w = (JFrame) e.getComponent();
config.setInt("options.window.posx", w.getX());
config.setInt("options.window.posy", w.getY());
config.setInt(ConfigKey.WINDOW_POS_X, w.getX());
config.setInt(ConfigKey.WINDOW_POS_Y, w.getY());
}
});
Point pt = UIHelper.getLocationMidScreen(this);
int posx = config.getInt("options.window.posx", pt.x);
int posy = config.getInt("options.window.posy", pt.y);
int posx = config.getInt(ConfigKey.WINDOW_POS_X, pt.x);
int posy = config.getInt(ConfigKey.WINDOW_POS_Y, pt.y);
setLocation(posx, posy);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setJMenuBar(new MenuBar(go));
Expand Down

0 comments on commit 796db74

Please sign in to comment.