mirror of
https://github.com/2006-Scape/Parabot.git
synced 2026-07-06 16:50:39 +00:00
Spring Cleaning
Clisprail is so bad.
This commit is contained in:
@@ -5,7 +5,6 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
|
|
||||||
|
|
||||||
import org.parabot.core.asm.ASMClassLoader;
|
import org.parabot.core.asm.ASMClassLoader;
|
||||||
import org.parabot.core.bot.loader.BotLoader;
|
import org.parabot.core.bot.loader.BotLoader;
|
||||||
import org.parabot.core.classpath.ClassPath;
|
import org.parabot.core.classpath.ClassPath;
|
||||||
@@ -17,6 +16,7 @@ import org.parabot.environment.servers.ServerProvider;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Game context
|
* Game context
|
||||||
|
*
|
||||||
* @author Clisprail
|
* @author Clisprail
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@@ -38,8 +38,6 @@ public class Context {
|
|||||||
|
|
||||||
public boolean added = false;
|
public boolean added = false;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public Context(final ServerProvider serverProvider) {
|
public Context(final ServerProvider serverProvider) {
|
||||||
threadGroups.put(Thread.currentThread().getThreadGroup(), this);
|
threadGroups.put(Thread.currentThread().getThreadGroup(), this);
|
||||||
tab = id;
|
tab = id;
|
||||||
@@ -50,6 +48,7 @@ public class Context {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the ServerProvider class loader
|
* Sets the ServerProvider class loader
|
||||||
|
*
|
||||||
* @param serverEnvironment
|
* @param serverEnvironment
|
||||||
*/
|
*/
|
||||||
public void setEnvironment(ASMClassLoader serverEnvironment) {
|
public void setEnvironment(ASMClassLoader serverEnvironment) {
|
||||||
@@ -65,6 +64,7 @@ public class Context {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* ClassPath
|
* ClassPath
|
||||||
|
*
|
||||||
* @return classpath
|
* @return classpath
|
||||||
*/
|
*/
|
||||||
public ClassPath getClassPath() {
|
public ClassPath getClassPath() {
|
||||||
@@ -73,6 +73,7 @@ public class Context {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines if applet has been set
|
* Determines if applet has been set
|
||||||
|
*
|
||||||
* @return <b>true</b> if set
|
* @return <b>true</b> if set
|
||||||
*/
|
*/
|
||||||
public boolean appletSet() {
|
public boolean appletSet() {
|
||||||
@@ -81,6 +82,7 @@ public class Context {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets game applet
|
* Gets game applet
|
||||||
|
*
|
||||||
* @return applet
|
* @return applet
|
||||||
*/
|
*/
|
||||||
public Applet getApplet() {
|
public Applet getApplet() {
|
||||||
@@ -89,6 +91,7 @@ public class Context {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolves the context from threadgroup
|
* Resolves the context from threadgroup
|
||||||
|
*
|
||||||
* @return context
|
* @return context
|
||||||
*/
|
*/
|
||||||
public static Context resolve() {
|
public static Context resolve() {
|
||||||
@@ -102,10 +105,10 @@ public class Context {
|
|||||||
serverProvider.parseJar();
|
serverProvider.parseJar();
|
||||||
serverProvider.injectHooks();
|
serverProvider.injectHooks();
|
||||||
gameApplet = serverProvider.fetchApplet();
|
gameApplet = serverProvider.fetchApplet();
|
||||||
if(getClient() == null) {
|
if (getClient() == null) {
|
||||||
setClientInstance(gameApplet);
|
setClientInstance(gameApplet);
|
||||||
}
|
}
|
||||||
serverProvider.addMenuItems(BotUI.getInstance().getBar());
|
serverProvider.addMenuItems(BotUI.getInstance().getJMenuBar());
|
||||||
BotUI.getInstance().validate();
|
BotUI.getInstance().validate();
|
||||||
final GamePanel panel = GamePanel.getInstance();
|
final GamePanel panel = GamePanel.getInstance();
|
||||||
panel.removeLoader();
|
panel.removeLoader();
|
||||||
@@ -122,6 +125,7 @@ public class Context {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the server prodiver belonging to this context
|
* Gets the server prodiver belonging to this context
|
||||||
|
*
|
||||||
* @return server provider
|
* @return server provider
|
||||||
*/
|
*/
|
||||||
public ServerProvider getServerProvider() {
|
public ServerProvider getServerProvider() {
|
||||||
@@ -130,6 +134,7 @@ public class Context {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets class loader from this context
|
* Gets class loader from this context
|
||||||
|
*
|
||||||
* @return class loader
|
* @return class loader
|
||||||
*/
|
*/
|
||||||
public ASMClassLoader getASMClassLoader() {
|
public ASMClassLoader getASMClassLoader() {
|
||||||
@@ -138,6 +143,7 @@ public class Context {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the id of this context
|
* Gets the id of this context
|
||||||
|
*
|
||||||
* @return id context
|
* @return id context
|
||||||
*/
|
*/
|
||||||
public static int getID() {
|
public static int getID() {
|
||||||
@@ -146,6 +152,7 @@ public class Context {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Tab id of this context
|
* Tab id of this context
|
||||||
|
*
|
||||||
* @return tab id of this context
|
* @return tab id of this context
|
||||||
*/
|
*/
|
||||||
public int getTab() {
|
public int getTab() {
|
||||||
@@ -154,6 +161,7 @@ public class Context {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a paintable instance to the paintables
|
* Adds a paintable instance to the paintables
|
||||||
|
*
|
||||||
* @param paintable
|
* @param paintable
|
||||||
*/
|
*/
|
||||||
public void addPaintable(Paintable paintable) {
|
public void addPaintable(Paintable paintable) {
|
||||||
@@ -162,6 +170,7 @@ public class Context {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes a paintable instance from the paintables
|
* Removes a paintable instance from the paintables
|
||||||
|
*
|
||||||
* @param paintable
|
* @param paintable
|
||||||
*/
|
*/
|
||||||
public void removePaintable(Paintable paintable) {
|
public void removePaintable(Paintable paintable) {
|
||||||
@@ -170,6 +179,7 @@ public class Context {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the paintable instances
|
* Gets the paintable instances
|
||||||
|
*
|
||||||
* @return array of paintable instances
|
* @return array of paintable instances
|
||||||
*/
|
*/
|
||||||
public Paintable[] getPaintables() {
|
public Paintable[] getPaintables() {
|
||||||
@@ -178,6 +188,7 @@ public class Context {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The client debug painter
|
* The client debug painter
|
||||||
|
*
|
||||||
* @return debug painter
|
* @return debug painter
|
||||||
*/
|
*/
|
||||||
public PaintDebugger getPaintDebugger() {
|
public PaintDebugger getPaintDebugger() {
|
||||||
@@ -186,6 +197,7 @@ public class Context {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the main/client instance
|
* Gets the main/client instance
|
||||||
|
*
|
||||||
* @return instance of the the client
|
* @return instance of the the client
|
||||||
*/
|
*/
|
||||||
public Object getClient() {
|
public Object getClient() {
|
||||||
|
|||||||
@@ -1,80 +1,105 @@
|
|||||||
package org.parabot.core.ui;
|
package org.parabot.core.ui;
|
||||||
|
|
||||||
|
import java.awt.BorderLayout;
|
||||||
|
import java.awt.Dimension;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
import javax.swing.GroupLayout;
|
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
import javax.swing.JMenu;
|
import javax.swing.JMenu;
|
||||||
import javax.swing.JMenuBar;
|
import javax.swing.JMenuBar;
|
||||||
import javax.swing.JMenuItem;
|
import javax.swing.JMenuItem;
|
||||||
import javax.swing.JPopupMenu;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.JScrollPane;
|
import javax.swing.JScrollPane;
|
||||||
import javax.swing.JToolBar;
|
import javax.swing.JToolBar;
|
||||||
import javax.swing.WindowConstants;
|
|
||||||
|
|
||||||
import org.parabot.core.ui.components.BotToolbar;
|
import org.parabot.core.ui.components.BotToolbar;
|
||||||
import org.parabot.core.ui.components.GamePanel;
|
import org.parabot.core.ui.components.GamePanel;
|
||||||
import org.parabot.core.ui.components.LogArea;
|
import org.parabot.core.ui.components.LogArea;
|
||||||
import org.parabot.core.ui.images.Images;
|
import org.parabot.core.ui.images.Images;
|
||||||
import org.parabot.core.ui.utils.AwtUtil;
|
|
||||||
import org.parabot.core.ui.utils.SwingUtil;
|
import org.parabot.core.ui.utils.SwingUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bot frame
|
|
||||||
*
|
*
|
||||||
* @author Clisprail
|
* @author Dane
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class BotUI extends JFrame {
|
public class BotUI extends JFrame implements ActionListener {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = -2126184292879805519L;
|
||||||
private static BotUI instance = null;
|
private static BotUI instance = null;
|
||||||
private JMenuBar bar = null;
|
|
||||||
|
|
||||||
public static BotUI getInstance() {
|
public static BotUI getInstance() {
|
||||||
return instance == null ? instance = new BotUI() : instance;
|
return instance == null ? instance = new BotUI() : instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BotUI() {
|
public BotUI() {
|
||||||
JPopupMenu.setDefaultLightWeightPopupEnabled(false);
|
|
||||||
setDefaultLookAndFeelDecorated(false);
|
|
||||||
bar = new JMenuBar();
|
|
||||||
JMenu file = new JMenu("File");
|
|
||||||
JMenuItem screenshot = new JMenuItem("Screenshot");
|
|
||||||
screenshot.addActionListener(new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent arg0) {
|
|
||||||
new Thread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
|
|
||||||
}
|
this.setTitle("Parabot");
|
||||||
}).start();
|
this.setResizable(false);
|
||||||
}
|
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
});
|
this.setIconImage(Images.getResource("/org/parabot/core/ui/images/icon.png"));
|
||||||
file.add(screenshot);
|
this.setLayout(new BorderLayout());
|
||||||
bar.add(file);
|
|
||||||
|
|
||||||
JScrollPane textPane = LogArea.getInstance();
|
int iToolbarHeight = 24;
|
||||||
GroupLayout layout = new GroupLayout(getContentPane());
|
int iGameHeight = 503;
|
||||||
JToolBar tool = BotToolbar.getInstance();
|
int iLogHeight = 128;
|
||||||
GamePanel pane = GamePanel.getInstance();
|
|
||||||
pane.addLoader();
|
JPanel panel = new JPanel();
|
||||||
getContentPane().setLayout(layout);
|
panel.setLocation(0, 0);
|
||||||
setJMenuBar(bar);
|
panel.setPreferredSize(new Dimension(765, iToolbarHeight + iGameHeight + iLogHeight));
|
||||||
setTitle("Parabot");
|
|
||||||
setIconImage(Images.getResource("/org/parabot/core/ui/images/icon.png"));
|
JMenuBar menubar = new JMenuBar();
|
||||||
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
|
||||||
setResizable(false);
|
JMenu mnuFile = new JMenu("File");
|
||||||
SwingUtil.center(this);
|
JMenuItem itmScreenshot = new JMenuItem("Screenshot");
|
||||||
layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addContainerGap().addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING))).addComponent(tool, 768, 768, 768).addComponent(pane, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addComponent(textPane, 768, 768, 768));
|
itmScreenshot.addActionListener(this);
|
||||||
layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addComponent(tool, 30, 30, 30).addComponent(pane, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addComponent(textPane, 100, 100, 100).addContainerGap(58, Short.MAX_VALUE)));
|
|
||||||
LogArea.log("Welcome to Parabot v2");
|
mnuFile.add(itmScreenshot);
|
||||||
|
menubar.add(mnuFile);
|
||||||
|
|
||||||
|
this.setJMenuBar(menubar);
|
||||||
|
|
||||||
|
int x = 0;
|
||||||
|
int y = 0;
|
||||||
|
|
||||||
|
JToolBar toolbar = BotToolbar.getInstance();
|
||||||
|
toolbar.setPreferredSize(new Dimension(765, iToolbarHeight));
|
||||||
|
toolbar.setLocation(x, y);
|
||||||
|
|
||||||
|
y += iToolbarHeight;
|
||||||
|
|
||||||
|
GamePanel gamePanel = GamePanel.getInstance();
|
||||||
|
gamePanel.setPreferredSize(new Dimension(765, iGameHeight));
|
||||||
|
toolbar.setLocation(x, y);
|
||||||
|
|
||||||
|
y += iGameHeight;
|
||||||
|
|
||||||
|
JScrollPane scrlConsole = LogArea.getInstance();
|
||||||
|
scrlConsole.setPreferredSize(new Dimension(765, iLogHeight));
|
||||||
|
toolbar.setLocation(x, y);
|
||||||
|
|
||||||
|
panel.add(toolbar);
|
||||||
|
panel.add(gamePanel);
|
||||||
|
panel.add(scrlConsole);
|
||||||
|
|
||||||
|
this.add(panel, BorderLayout.CENTER);
|
||||||
|
|
||||||
|
SwingUtil.finalize(this);
|
||||||
|
|
||||||
|
LogArea.log("Welcome to Parabot!");
|
||||||
}
|
}
|
||||||
|
|
||||||
public JMenuBar getBar() {
|
@Override
|
||||||
return bar;
|
public void actionPerformed(ActionEvent e) {
|
||||||
}
|
String command = e.getActionCommand();
|
||||||
|
|
||||||
|
switch (command) {
|
||||||
|
case "Screenshot":
|
||||||
|
LogArea.log("Boop");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
System.out.println("Invalid command: ");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package org.parabot.core.ui.components;
|
package org.parabot.core.ui.components;
|
||||||
|
|
||||||
|
|
||||||
import java.awt.Dimension;
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
@@ -23,12 +21,7 @@ public class LogArea extends JScrollPane {
|
|||||||
private static LogTextArea logArea = new LogTextArea();
|
private static LogTextArea logArea = new LogTextArea();
|
||||||
|
|
||||||
private LogArea() {
|
private LogArea() {
|
||||||
super(TextAreaLogHandler.TEXT_AREA,
|
super(TextAreaLogHandler.TEXT_AREA, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
|
||||||
ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
|
|
||||||
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
|
|
||||||
logArea.setPreferredSize(new Dimension(775, 80));
|
|
||||||
setPreferredSize(new Dimension(776, 100));
|
|
||||||
setSize(775, 100);
|
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
registerLogging();
|
registerLogging();
|
||||||
}
|
}
|
||||||
@@ -63,19 +56,15 @@ public class LogArea extends JScrollPane {
|
|||||||
final Properties logging = new Properties();
|
final Properties logging = new Properties();
|
||||||
final String logFormatter = LogFormatter.class.getCanonicalName();
|
final String logFormatter = LogFormatter.class.getCanonicalName();
|
||||||
final String fileHandler = FileHandler.class.getCanonicalName();
|
final String fileHandler = FileHandler.class.getCanonicalName();
|
||||||
logging.setProperty("handlers",
|
logging.setProperty("handlers", TextAreaLogHandler.class.getCanonicalName() + "," + fileHandler);
|
||||||
TextAreaLogHandler.class.getCanonicalName() + "," + fileHandler);
|
|
||||||
logging.setProperty(".level", "INFO");
|
logging.setProperty(".level", "INFO");
|
||||||
logging.setProperty(SystemConsoleHandler.class.getCanonicalName()
|
logging.setProperty(SystemConsoleHandler.class.getCanonicalName() + ".formatter", logFormatter);
|
||||||
+ ".formatter", logFormatter);
|
|
||||||
logging.setProperty(fileHandler + ".formatter", logFormatter);
|
logging.setProperty(fileHandler + ".formatter", logFormatter);
|
||||||
logging.setProperty(TextAreaLogHandler.class.getCanonicalName()
|
logging.setProperty(TextAreaLogHandler.class.getCanonicalName() + ".formatter", logFormatter);
|
||||||
+ ".formatter", logFormatter);
|
|
||||||
final ByteArrayOutputStream logout = new ByteArrayOutputStream();
|
final ByteArrayOutputStream logout = new ByteArrayOutputStream();
|
||||||
try {
|
try {
|
||||||
logging.store(logout, "");
|
logging.store(logout, "");
|
||||||
LogManager.getLogManager().readConfiguration(
|
LogManager.getLogManager().readConfiguration(new ByteArrayInputStream(logout.toByteArray()));
|
||||||
new ByteArrayInputStream(logout.toByteArray()));
|
|
||||||
} catch (final Exception ignored) {
|
} catch (final Exception ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user