mirror of
https://github.com/2006-Scape/Parabot.git
synced 2026-07-06 16:50:39 +00:00
Indention fix v2
This commit is contained in:
@@ -27,280 +27,280 @@ import java.util.ArrayList;
|
|||||||
*/
|
*/
|
||||||
public class BotUI extends JFrame implements ActionListener, ComponentListener, WindowListener {
|
public class BotUI extends JFrame implements ActionListener, ComponentListener, WindowListener {
|
||||||
|
|
||||||
private static final long serialVersionUID = -2126184292879805519L;
|
private static final long serialVersionUID = -2126184292879805519L;
|
||||||
private static BotUI instance;
|
private static BotUI instance;
|
||||||
private static JDialog dialog;
|
private static JDialog dialog;
|
||||||
|
|
||||||
private JMenuItem run, pause, stop, cacheClear;
|
private JMenuItem run, pause, stop, cacheClear;
|
||||||
private boolean runScript, pauseScript;
|
private boolean runScript, pauseScript;
|
||||||
|
|
||||||
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");
|
||||||
}
|
}
|
||||||
instance = this;
|
instance = this;
|
||||||
//WebLookAndFeel.install();
|
//WebLookAndFeel.install();
|
||||||
JPopupMenu.setDefaultLightWeightPopupEnabled(false);
|
JPopupMenu.setDefaultLightWeightPopupEnabled(false);
|
||||||
|
|
||||||
setTitle("Parabot");
|
setTitle("Parabot");
|
||||||
setResizable(false);
|
setResizable(false);
|
||||||
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
||||||
createMenu();
|
createMenu();
|
||||||
|
|
||||||
setLayout(new BorderLayout());
|
setLayout(new BorderLayout());
|
||||||
addComponentListener(this);
|
addComponentListener(this);
|
||||||
addWindowListener(this);
|
addWindowListener(this);
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
SwingUtil.setParabotIcons(this);
|
SwingUtil.setParabotIcons(this);
|
||||||
|
|
||||||
pack();
|
pack();
|
||||||
setLocationRelativeTo(null);
|
setLocationRelativeTo(null);
|
||||||
BotDialog.getInstance(this);
|
BotDialog.getInstance(this);
|
||||||
|
|
||||||
if (!OperatingSystem.getOS().equals(OperatingSystem.WINDOWS)) {
|
if (!OperatingSystem.getOS().equals(OperatingSystem.WINDOWS)) {
|
||||||
BotDialog.getInstance().setVisible(false);
|
BotDialog.getInstance().setVisible(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BotUI getInstance() {
|
public static BotUI getInstance() {
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void createMenu() {
|
private void createMenu() {
|
||||||
JMenuBar menuBar = new JMenuBar();
|
JMenuBar menuBar = new JMenuBar();
|
||||||
|
|
||||||
JMenu file = new JMenu("File");
|
JMenu file = new JMenu("File");
|
||||||
JMenu scripts = new JMenu("Script");
|
JMenu scripts = new JMenu("Script");
|
||||||
JMenu features = new JMenu("Features");
|
JMenu features = new JMenu("Features");
|
||||||
|
|
||||||
JMenuItem screenshot = new JMenuItem("Create screenshot");
|
JMenuItem screenshot = new JMenuItem("Create screenshot");
|
||||||
JMenuItem proxy = new JMenuItem("Network");
|
JMenuItem proxy = new JMenuItem("Network");
|
||||||
JMenuItem randoms = new JMenuItem("Randoms");
|
JMenuItem randoms = new JMenuItem("Randoms");
|
||||||
JMenuItem dialog = new JCheckBoxMenuItem("Disable dialog");
|
JMenuItem dialog = new JCheckBoxMenuItem("Disable dialog");
|
||||||
JMenuItem logger = new JCheckBoxMenuItem("Logger");
|
JMenuItem logger = new JCheckBoxMenuItem("Logger");
|
||||||
|
|
||||||
if (!OperatingSystem.getOS().equals(OperatingSystem.WINDOWS)) {
|
if (!OperatingSystem.getOS().equals(OperatingSystem.WINDOWS)) {
|
||||||
dialog.setSelected(true);
|
dialog.setSelected(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
JMenuItem explorer = new JMenuItem("Reflection explorer");
|
JMenuItem explorer = new JMenuItem("Reflection explorer");
|
||||||
JMenuItem exit = new JMenuItem("Exit");
|
JMenuItem exit = new JMenuItem("Exit");
|
||||||
|
|
||||||
run = new JMenuItem("Run");
|
run = new JMenuItem("Run");
|
||||||
run.setIcon(new ImageIcon(Images.getResource("/storage/images/run.png")));
|
run.setIcon(new ImageIcon(Images.getResource("/storage/images/run.png")));
|
||||||
|
|
||||||
pause = new JMenuItem("Pause");
|
pause = new JMenuItem("Pause");
|
||||||
pause.setEnabled(false);
|
pause.setEnabled(false);
|
||||||
pause.setIcon(new ImageIcon(Images.getResource("/storage/images/pause.png")));
|
pause.setIcon(new ImageIcon(Images.getResource("/storage/images/pause.png")));
|
||||||
|
|
||||||
stop = new JMenuItem("Stop");
|
stop = new JMenuItem("Stop");
|
||||||
stop.setEnabled(false);
|
stop.setEnabled(false);
|
||||||
stop.setIcon(new ImageIcon(Images.getResource("/storage/images/stop.png")));
|
stop.setIcon(new ImageIcon(Images.getResource("/storage/images/stop.png")));
|
||||||
|
|
||||||
cacheClear = new JMenuItem("Clear cache");
|
cacheClear = new JMenuItem("Clear cache");
|
||||||
cacheClear.setIcon(new ImageIcon(Images.getResource("/storage/images/trash.png")));
|
cacheClear.setIcon(new ImageIcon(Images.getResource("/storage/images/trash.png")));
|
||||||
|
|
||||||
screenshot.addActionListener(this);
|
screenshot.addActionListener(this);
|
||||||
proxy.addActionListener(this);
|
proxy.addActionListener(this);
|
||||||
randoms.addActionListener(this);
|
randoms.addActionListener(this);
|
||||||
dialog.addActionListener(this);
|
dialog.addActionListener(this);
|
||||||
logger.addActionListener(this);
|
logger.addActionListener(this);
|
||||||
explorer.addActionListener(this);
|
explorer.addActionListener(this);
|
||||||
exit.addActionListener(this);
|
exit.addActionListener(this);
|
||||||
cacheClear.addActionListener(this);
|
cacheClear.addActionListener(this);
|
||||||
|
|
||||||
run.addActionListener(this);
|
run.addActionListener(this);
|
||||||
pause.addActionListener(this);
|
pause.addActionListener(this);
|
||||||
stop.addActionListener(this);
|
stop.addActionListener(this);
|
||||||
|
|
||||||
file.add(screenshot);
|
file.add(screenshot);
|
||||||
file.add(proxy);
|
file.add(proxy);
|
||||||
file.add(randoms);
|
file.add(randoms);
|
||||||
file.add(dialog);
|
file.add(dialog);
|
||||||
file.add(logger);
|
file.add(logger);
|
||||||
file.add(explorer);
|
file.add(explorer);
|
||||||
file.add(exit);
|
file.add(exit);
|
||||||
|
|
||||||
scripts.add(run);
|
scripts.add(run);
|
||||||
scripts.add(pause);
|
scripts.add(pause);
|
||||||
scripts.add(stop);
|
scripts.add(stop);
|
||||||
|
|
||||||
features.add(cacheClear);
|
features.add(cacheClear);
|
||||||
|
|
||||||
menuBar.add(file);
|
menuBar.add(file);
|
||||||
menuBar.add(scripts);
|
menuBar.add(scripts);
|
||||||
menuBar.add(features);
|
menuBar.add(features);
|
||||||
|
|
||||||
|
|
||||||
setJMenuBar(menuBar);
|
setJMenuBar(menuBar);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
String command = e.getActionCommand();
|
String command = e.getActionCommand();
|
||||||
|
|
||||||
switch (command) {
|
switch (command) {
|
||||||
case "Create screenshot":
|
case "Create screenshot":
|
||||||
try {
|
try {
|
||||||
Robot robot = new Robot();
|
Robot robot = new Robot();
|
||||||
Rectangle parabotScreen = new Rectangle((int) getLocation().getX(), (int) getLocation().getY(), getWidth(), getHeight());
|
Rectangle parabotScreen = new Rectangle((int) getLocation().getX(), (int) getLocation().getY(), getWidth(), getHeight());
|
||||||
BufferedImage image = robot.createScreenCapture(parabotScreen);
|
BufferedImage image = robot.createScreenCapture(parabotScreen);
|
||||||
ImageIO.write(image, "png", new File(Directories.getScreenshotDir().getPath() + "/" + StringUtils.randomString(10) + ".png"));
|
ImageIO.write(image, "png", new File(Directories.getScreenshotDir().getPath() + "/" + StringUtils.randomString(10) + ".png"));
|
||||||
} catch (IOException k) {
|
} catch (IOException k) {
|
||||||
k.printStackTrace();
|
k.printStackTrace();
|
||||||
} catch (AWTException e1) {
|
} catch (AWTException e1) {
|
||||||
e1.printStackTrace();
|
e1.printStackTrace();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "Exit":
|
case "Exit":
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
break;
|
break;
|
||||||
case "Network":
|
case "Network":
|
||||||
NetworkUI.getInstance().setVisible(true);
|
NetworkUI.getInstance().setVisible(true);
|
||||||
break;
|
break;
|
||||||
case "Randoms":
|
case "Randoms":
|
||||||
ArrayList<String> randoms = new ArrayList<>();
|
ArrayList<String> randoms = new ArrayList<>();
|
||||||
for (Random r : Context.getInstance().getRandomHandler().getRandoms()) {
|
for (Random r : Context.getInstance().getRandomHandler().getRandoms()) {
|
||||||
randoms.add(r.getName());
|
randoms.add(r.getName());
|
||||||
}
|
}
|
||||||
RandomUI.getInstance().openFrame(randoms);
|
RandomUI.getInstance().openFrame(randoms);
|
||||||
break;
|
break;
|
||||||
case "Reflection explorer":
|
case "Reflection explorer":
|
||||||
new ReflectUI().setVisible(true);
|
new ReflectUI().setVisible(true);
|
||||||
break;
|
break;
|
||||||
case "Run":
|
case "Run":
|
||||||
if (pauseScript) {
|
if (pauseScript) {
|
||||||
pauseScript = false;
|
pauseScript = false;
|
||||||
pause.setEnabled(true);
|
pause.setEnabled(true);
|
||||||
run.setEnabled(false);
|
run.setEnabled(false);
|
||||||
setScriptState(Script.STATE_RUNNING);
|
setScriptState(Script.STATE_RUNNING);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
new ScriptSelector().setVisible(true);
|
new ScriptSelector().setVisible(true);
|
||||||
break;
|
break;
|
||||||
case "Pause":
|
case "Pause":
|
||||||
setScriptState(Script.STATE_PAUSE);
|
setScriptState(Script.STATE_PAUSE);
|
||||||
pause.setEnabled(false);
|
pause.setEnabled(false);
|
||||||
run.setEnabled(true);
|
run.setEnabled(true);
|
||||||
pauseScript = true;
|
pauseScript = true;
|
||||||
break;
|
break;
|
||||||
case "Stop":
|
case "Stop":
|
||||||
setScriptState(Script.STATE_STOPPED);
|
setScriptState(Script.STATE_STOPPED);
|
||||||
break;
|
break;
|
||||||
case "Logger":
|
case "Logger":
|
||||||
Logger.getInstance().setVisible(!Logger.getInstance().isVisible());
|
Logger.getInstance().setVisible(!Logger.getInstance().isVisible());
|
||||||
BotUI.getInstance().pack();
|
BotUI.getInstance().pack();
|
||||||
BotUI.getInstance().revalidate();
|
BotUI.getInstance().revalidate();
|
||||||
if (!Logger.getInstance().isClearable()) {
|
if (!Logger.getInstance().isClearable()) {
|
||||||
Logger.getInstance().setClearable();
|
Logger.getInstance().setClearable();
|
||||||
} else if (Logger.getInstance().isClearable() && !Logger.getInstance().isVisible()) {
|
} else if (Logger.getInstance().isClearable() && !Logger.getInstance().isVisible()) {
|
||||||
Logger.clearLogger();
|
Logger.clearLogger();
|
||||||
Logger.addMessage("Logger started", false);
|
Logger.addMessage("Logger started", false);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "Disable dialog":
|
case "Disable dialog":
|
||||||
BotDialog.getInstance().setVisible(!dialog.isVisible());
|
BotDialog.getInstance().setVisible(!dialog.isVisible());
|
||||||
break;
|
break;
|
||||||
case "Clear cache":
|
case "Clear cache":
|
||||||
Directories.clearCache();
|
Directories.clearCache();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
System.out.println("Invalid command: " + command);
|
System.out.println("Invalid command: " + command);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setDialog(JDialog dialog) {
|
protected void setDialog(JDialog dialog) {
|
||||||
BotUI.dialog = dialog;
|
BotUI.dialog = dialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void componentMoved(ComponentEvent e) {
|
public void componentMoved(ComponentEvent e) {
|
||||||
if (dialog == null || !isVisible()) {
|
if (dialog == null || !isVisible()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Point gameLocation = GamePanel.getInstance().getLocationOnScreen();
|
Point gameLocation = GamePanel.getInstance().getLocationOnScreen();
|
||||||
dialog.setLocation(gameLocation.x, gameLocation.y);
|
dialog.setLocation(gameLocation.x, gameLocation.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void toggleRun() {
|
public void toggleRun() {
|
||||||
runScript = !runScript;
|
runScript = !runScript;
|
||||||
if (runScript) {
|
if (runScript) {
|
||||||
scriptRunning();
|
scriptRunning();
|
||||||
} else {
|
} else {
|
||||||
scriptStopped();
|
scriptStopped();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void scriptRunning() {
|
private void scriptRunning() {
|
||||||
run.setEnabled(false);
|
run.setEnabled(false);
|
||||||
pause.setEnabled(true);
|
pause.setEnabled(true);
|
||||||
stop.setEnabled(true);
|
stop.setEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void scriptStopped() {
|
private void scriptStopped() {
|
||||||
run.setEnabled(true);
|
run.setEnabled(true);
|
||||||
pause.setEnabled(false);
|
pause.setEnabled(false);
|
||||||
stop.setEnabled(false);
|
stop.setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setScriptState(int state) {
|
private void setScriptState(int state) {
|
||||||
if (Context.getInstance().getRunningScript() != null) {
|
if (Context.getInstance().getRunningScript() != null) {
|
||||||
Context.getInstance().getRunningScript().setState(state);
|
Context.getInstance().getRunningScript().setState(state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void componentResized(ComponentEvent e) {
|
public void componentResized(ComponentEvent e) {
|
||||||
if (isVisible()) {
|
if (isVisible()) {
|
||||||
BotDialog.getInstance().setSize(getSize());
|
BotDialog.getInstance().setSize(getSize());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void componentShown(ComponentEvent e) {
|
public void componentShown(ComponentEvent e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void componentHidden(ComponentEvent e) {
|
public void componentHidden(ComponentEvent e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void windowActivated(WindowEvent arg0) {
|
public void windowActivated(WindowEvent arg0) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void windowClosed(WindowEvent arg0) {
|
public void windowClosed(WindowEvent arg0) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void windowClosing(WindowEvent e) {
|
public void windowClosing(WindowEvent e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void windowDeactivated(WindowEvent arg0) {
|
public void windowDeactivated(WindowEvent arg0) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void windowDeiconified(WindowEvent arg0) {
|
public void windowDeiconified(WindowEvent arg0) {
|
||||||
if (isVisible()) {
|
if (isVisible()) {
|
||||||
BotDialog.getInstance().setVisible(false);
|
BotDialog.getInstance().setVisible(false);
|
||||||
BotDialog.getInstance().setVisible(true);
|
BotDialog.getInstance().setVisible(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void windowIconified(WindowEvent arg0) {
|
public void windowIconified(WindowEvent arg0) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void windowOpened(WindowEvent arg0) {
|
public void windowOpened(WindowEvent arg0) {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user