mirror of
https://github.com/2006-Scape/Parabot.git
synced 2026-07-06 16:50:39 +00:00
[FEATURE] Added base for Key listeners
This commit is contained in:
@@ -6,6 +6,7 @@ import org.parabot.core.Directories;
|
|||||||
import org.parabot.core.ui.components.GamePanel;
|
import org.parabot.core.ui.components.GamePanel;
|
||||||
import org.parabot.core.ui.components.VerboseLoader;
|
import org.parabot.core.ui.components.VerboseLoader;
|
||||||
import org.parabot.core.ui.images.Images;
|
import org.parabot.core.ui.images.Images;
|
||||||
|
import org.parabot.core.ui.listeners.PBKeyListener;
|
||||||
import org.parabot.core.ui.utils.SwingUtil;
|
import org.parabot.core.ui.utils.SwingUtil;
|
||||||
import org.parabot.environment.OperatingSystem;
|
import org.parabot.environment.OperatingSystem;
|
||||||
import org.parabot.environment.api.utils.StringUtils;
|
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 JMenuItem run, pause, stop;
|
||||||
private boolean runScript, pauseScript;
|
private boolean runScript, pauseScript;
|
||||||
|
|
||||||
|
private PBKeyListener keyListener;
|
||||||
|
|
||||||
public BotUI(String username, String password) {
|
public BotUI(String username, String password) {
|
||||||
if (instance != null) {
|
if (instance != null) {
|
||||||
throw new IllegalStateException("BotUI already created");
|
throw new IllegalStateException("BotUI already created");
|
||||||
@@ -51,6 +54,9 @@ public class BotUI extends JFrame implements ActionListener, ComponentListener,
|
|||||||
addComponentListener(this);
|
addComponentListener(this);
|
||||||
addWindowListener(this);
|
addWindowListener(this);
|
||||||
|
|
||||||
|
this.keyListener = new PBKeyListener();
|
||||||
|
addKeyListener(keyListener);
|
||||||
|
|
||||||
add(GamePanel.getInstance());
|
add(GamePanel.getInstance());
|
||||||
GamePanel.getInstance().add(VerboseLoader.get(username, password), BorderLayout.CENTER);
|
GamePanel.getInstance().add(VerboseLoader.get(username, password), BorderLayout.CENTER);
|
||||||
add(Logger.getInstance(), BorderLayout.SOUTH);
|
add(Logger.getInstance(), BorderLayout.SOUTH);
|
||||||
@@ -142,8 +148,10 @@ public class BotUI extends JFrame implements ActionListener, ComponentListener,
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
String command = e.getActionCommand();
|
this.performCommand(e.getActionCommand());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void performCommand(String command){
|
||||||
switch (command) {
|
switch (command) {
|
||||||
case "Create screenshot":
|
case "Create screenshot":
|
||||||
try {
|
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();
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user