[FEATURE] Added base for Key listeners

This commit is contained in:
JKetelaar
2016-06-12 02:35:52 +02:00
parent 5b79000bf5
commit 02b655d23c
4 changed files with 61 additions and 1 deletions
+9 -1
View File
@@ -6,6 +6,7 @@ import org.parabot.core.Directories;
import org.parabot.core.ui.components.GamePanel;
import org.parabot.core.ui.components.VerboseLoader;
import org.parabot.core.ui.images.Images;
import org.parabot.core.ui.listeners.PBKeyListener;
import org.parabot.core.ui.utils.SwingUtil;
import org.parabot.environment.OperatingSystem;
import org.parabot.environment.api.utils.StringUtils;
@@ -35,6 +36,8 @@ public class BotUI extends JFrame implements ActionListener, ComponentListener,
private JMenuItem run, pause, stop;
private boolean runScript, pauseScript;
private PBKeyListener keyListener;
public BotUI(String username, String password) {
if (instance != null) {
throw new IllegalStateException("BotUI already created");
@@ -51,6 +54,9 @@ public class BotUI extends JFrame implements ActionListener, ComponentListener,
addComponentListener(this);
addWindowListener(this);
this.keyListener = new PBKeyListener();
addKeyListener(keyListener);
add(GamePanel.getInstance());
GamePanel.getInstance().add(VerboseLoader.get(username, password), BorderLayout.CENTER);
add(Logger.getInstance(), BorderLayout.SOUTH);
@@ -142,8 +148,10 @@ public class BotUI extends JFrame implements ActionListener, ComponentListener,
@Override
public void actionPerformed(ActionEvent e) {
String command = e.getActionCommand();
this.performCommand(e.getActionCommand());
}
public void performCommand(String command){
switch (command) {
case "Create screenshot":
try {
@@ -0,0 +1,7 @@
package org.parabot.core.ui.listeners;
/**
* @author JKetelaar
*/
public class PBKeyListener {
}
@@ -0,0 +1,22 @@
package org.parabot.core.ui.listeners.key;
import org.parabot.core.ui.BotUI;
/**
* @author JKetelaar
*/
public class ActionEventBinding extends Binding {
private String actionString;
public ActionEventBinding(int key, String actionString) {
super(key);
this.actionString = actionString;
}
@Override
public void perform() {
BotUI.getInstance().performCommand(actionString);
}
}
@@ -0,0 +1,23 @@
package org.parabot.core.ui.listeners.key;
/**
* @author JKetelaar
*/
public abstract class Binding {
private int key;
public Binding(int key) {
this.key = key;
}
public int getKey() {
return key;
}
public void setKey(int key) {
this.key = key;
}
public abstract void perform();
}