Merge pull request #77 from Parabot/master
[MERGE] Syncing master into development
@@ -121,4 +121,5 @@ parabotv2
|
|||||||
releases
|
releases
|
||||||
._*
|
._*
|
||||||
|
|
||||||
Test.java
|
Test.java
|
||||||
|
*.DS_Store
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
language: java
|
||||||
|
|
||||||
|
jdk:
|
||||||
|
- oraclejdk7
|
||||||
|
|
||||||
|
before_install:
|
||||||
|
- chmod +x ./.travis/artifact-upload.sh
|
||||||
|
- chmod +x ./.travis/maven-build.sh
|
||||||
|
|
||||||
|
script: ./.travis/maven-build.sh
|
||||||
|
|
||||||
|
notifications:
|
||||||
|
slack:
|
||||||
|
secure: ciAOsdv9lf/IbAwyzeR/z2nlBSevmBHBqca6tf0Yh2DIyAx/uUo1ojon0W7Kv6tCECGhSTdfQAnZ+nFjjqaRs+Jq4svd9WKYrFuZyOWmT31iSJ/nvPymRvevSsgwpSKr0nJS9dxePKto/T3ozW29kx88eaJQH17zOaX2rfuIje4=
|
||||||
|
webhooks:
|
||||||
|
urls:
|
||||||
|
- https://dockbit.com/webhooks/7PrMKazLtLw5hhpXvakVKWoq
|
||||||
|
on_success: always
|
||||||
|
on_failure: always
|
||||||
|
on_start: never
|
||||||
|
|
||||||
|
env:
|
||||||
|
global:
|
||||||
|
- secure: UG+b1tEgc8xv9x4r//2OAIK1RrYv6n209KTTFMMwcnAa7DI8HaP8nljRa5/VhDhuKHdlVrYH/tI90v7UVBs0GDVNwK5V17Io0fMm3FUGZekSthTCqqno5wAGa9r6a6mMLtSaSmIFeIKi0+0d2ZwplRuhj/dtEYjjBBj+kK8g4nE=
|
||||||
|
- secure: St/fecUDInFBCRriYqgp2F8PU9/SooorgxD9Mrs+b0EsC7AbtSsQXvdIv2Lp6xzdQ0VSXPcLIhULPOYrmBKnGQ/NjXTIZXxnroyQxxnI6xyEWIZwiHRY/bKRJDRbQTxD9NL32szKiDSwnw7pu6llF4D64UqQvziq4Gm6VohU75M=
|
||||||
|
- secure: bD15GVZWowiknbfLavh8CxSh0GsnF5kT4kZ6ggCuUDGyj0mzqf7dNRnchQIKkCG0WRYyTrFN4pEiygeywWsipEeAVv9Xhx3cuUZmzeQaR5KCWabSwJ8gK6jZd1YhcWmM9vrdPHobZr65MP0y/8mu/Fovgky9dY7KDf4G3SebNrM=
|
||||||
|
|
||||||
|
addons:
|
||||||
|
artifacts:
|
||||||
|
paths: ./target/final/
|
||||||
|
s3_region: "us-west-1"
|
||||||
|
|
||||||
|
cache:
|
||||||
|
directories:
|
||||||
|
- .autoconf
|
||||||
|
- $HOME/.m2
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
#! /bin/bash
|
||||||
|
|
||||||
|
local_file="$(ls $TRAVIS_BUILD_DIR/target/final/Parabot-V*.jar | head -n 1 | xargs -n 1 basename)"
|
||||||
|
local_path="$(ls $TRAVIS_BUILD_DIR/target/final/Parabot-V*.jar | head -n 1)"
|
||||||
|
target_url="ftp://$FTP_HOST/$local_file"
|
||||||
|
|
||||||
|
echo "Uploading $local_file to $target_url"
|
||||||
|
curl -us $FTP_USERNAME:$FTP_PASSWORD -T "$local_path" "$target_url"
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
#! /bin/bash
|
||||||
|
|
||||||
|
if [ "$TRAVIS_BRANCH" == "master" ]; then
|
||||||
|
mvn -U package
|
||||||
|
else
|
||||||
|
mvn -Dversion="-RC-$TRAVIS_BUILD_ID" -U package
|
||||||
|
fi
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
|
[](https://travis-ci.org/Parabot/Parabot)
|
||||||
|
|
||||||
# Parabot
|
# Parabot
|
||||||
|
|
||||||
Parabot V2.4.
|
Parabot V2.5.
|
||||||
|
|
||||||
#### Website
|
#### Website
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
mvn install:install-file -DgroupId=${project.groupId} -DartifactId=${project.artifactId} -Dversion=${project.version} -Dpackaging=jar -Dfile=../target/${project.build.finalName}-jar-with-dependencies.jar -DlocalRepositoryPath=../../Maven-Repository
|
mvn install:install-file -DgroupId=${project.groupId} -DartifactId=${project.artifactId} -Dversion=${project.version} -Dpackaging=jar -Dfile=../target/final/${project.build.finalName}-jar-with-dependencies.jar -DlocalRepositoryPath=../../Maven-Repository
|
||||||
|
|
||||||
:: mvn install:install-file -DgroupId=org.parabot -DartifactId=client -Dversion=2.4.1.1 -Dpackaging=jar -Dfile=../target/Parabot-V2.4.1.1-jar-with-dependencies.jar -DlocalRepositoryPath=../../Maven-Repository
|
:: mvn install:install-file -DgroupId=org.parabot -DartifactId=client -Dversion=2.4.1.1 -Dpackaging=jar -Dfile=../target/Parabot-V2.4.1.1-jar-with-dependencies.jar -DlocalRepositoryPath=../../Maven-Repository
|
||||||
:: mvn install:install-file -DgroupId=org.parabot -DartifactId=client -Dversion=2.4.3 -Dpackaging=jar -Dfile=../target/Parabot-V2.4.3-jar-with-dependencies.jar -DlocalRepositoryPath=../../Maven-Repository
|
:: mvn install:install-file -DgroupId=org.parabot -DartifactId=client -Dversion=2.4.3 -Dpackaging=jar -Dfile=../target/Parabot-V2.4.3-jar-with-dependencies.jar -DlocalRepositoryPath=../../Maven-Repository
|
||||||
|
:: mvn install:install-file -DgroupId=org.parabot -DartifactId=client -Dversion=2.5 -Dpackaging=jar -Dfile=../target/final/Parabot-V2.5-jar-with-dependencies.jar -DlocalRepositoryPath=../../Maven-Repository
|
||||||
|
|||||||
@@ -6,12 +6,13 @@
|
|||||||
|
|
||||||
<groupId>org.parabot</groupId>
|
<groupId>org.parabot</groupId>
|
||||||
<artifactId>client</artifactId>
|
<artifactId>client</artifactId>
|
||||||
<version>2.4.5</version>
|
<version>2.5.1</version>
|
||||||
|
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<jdk.version>1.7</jdk.version>
|
<jdk.version>1.7</jdk.version>
|
||||||
|
<build.version></build.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<name>Parabot client</name>
|
<name>Parabot client</name>
|
||||||
@@ -80,7 +81,7 @@
|
|||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<finalName>Parabot-V${version}</finalName>
|
<finalName>Parabot-V${version}${build.version}</finalName>
|
||||||
<resources>
|
<resources>
|
||||||
<resource>
|
<resource>
|
||||||
<directory>src/main/resources</directory>
|
<directory>src/main/resources</directory>
|
||||||
@@ -89,18 +90,29 @@
|
|||||||
<resource>
|
<resource>
|
||||||
<directory>deploy</directory>
|
<directory>deploy</directory>
|
||||||
<filtering>true</filtering>
|
<filtering>true</filtering>
|
||||||
<!--<excludes>-->
|
<excludes>
|
||||||
<!--<exclude>deploy.bat</exclude>-->
|
<exclude>deploy.bat</exclude>
|
||||||
<!--<exclude>package.bat</exclude>-->
|
<exclude>package.bat</exclude>
|
||||||
<!--<exclude>clean.bat</exclude>-->
|
<exclude>clean.bat</exclude>
|
||||||
<!--</excludes>-->
|
</excludes>
|
||||||
<includes>
|
<!--<includes>-->
|
||||||
<include>deploy.bat</include>
|
<!--<include>deploy.bat</include>-->
|
||||||
</includes>
|
<!--</includes>-->
|
||||||
</resource>
|
</resource>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
||||||
<plugins>
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-resources-plugin</artifactId>
|
||||||
|
<version>2.5</version>
|
||||||
|
<configuration>
|
||||||
|
<encoding>UTF-8</encoding>
|
||||||
|
<nonFilteredFileExtensions>
|
||||||
|
<nonFilteredFileExtension>ttf</nonFilteredFileExtension>
|
||||||
|
</nonFilteredFileExtensions>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
@@ -114,7 +126,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-assembly-plugin</artifactId>
|
<artifactId>maven-assembly-plugin</artifactId>
|
||||||
<version>2.4.1</version>
|
<version>${version}</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<descriptorRefs>
|
<descriptorRefs>
|
||||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||||
@@ -124,6 +136,8 @@
|
|||||||
<mainClass>org.parabot.Landing</mainClass>
|
<mainClass>org.parabot.Landing</mainClass>
|
||||||
</manifest>
|
</manifest>
|
||||||
</archive>
|
</archive>
|
||||||
|
<outputDirectory>${project.build.directory}/final/</outputDirectory>
|
||||||
|
<appendAssemblyId>false</appendAssemblyId>
|
||||||
</configuration>
|
</configuration>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
@@ -135,7 +149,6 @@
|
|||||||
</goals>
|
</goals>
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
|
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|||||||
@@ -26,4 +26,7 @@ public class Configuration {
|
|||||||
public static final String BUGSNAG_API = "d79752cf94dd4beb24c3d312a8609f53";
|
public static final String BUGSNAG_API = "d79752cf94dd4beb24c3d312a8609f53";
|
||||||
|
|
||||||
public static final Version BOT_VERSION = ProjectProperties.getProjectVersion();
|
public static final Version BOT_VERSION = ProjectProperties.getProjectVersion();
|
||||||
|
|
||||||
|
public static final String BOT_TITLE = "Parabot";
|
||||||
|
public static final String BOT_SLOGAN = "The best RuneScape private server bot";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -163,6 +163,7 @@ public class Context {
|
|||||||
* Loads the game
|
* Loads the game
|
||||||
*/
|
*/
|
||||||
public void load() {
|
public void load() {
|
||||||
|
BotUI.getInstance().getJMenuBar().remove(2);
|
||||||
Core.verbose("Parsing server jar...");
|
Core.verbose("Parsing server jar...");
|
||||||
serverProvider.init();
|
serverProvider.init();
|
||||||
serverProvider.parseJar();
|
serverProvider.parseJar();
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ public class Directories {
|
|||||||
cached.put("Settings", new File(cached.get("Root"), "/Parabot/settings/"));
|
cached.put("Settings", new File(cached.get("Root"), "/Parabot/settings/"));
|
||||||
cached.put("Servers", new File(cached.get("Root"), "/Parabot/servers/"));
|
cached.put("Servers", new File(cached.get("Root"), "/Parabot/servers/"));
|
||||||
cached.put("Cache", new File(cached.get("Root"), "/Parabot/cache/"));
|
cached.put("Cache", new File(cached.get("Root"), "/Parabot/cache/"));
|
||||||
|
cached.put("Screenshots", new File(cached.get("Root"), "/Parabot/screenshots/"));
|
||||||
Core.verbose("Directories cached.");
|
Core.verbose("Directories cached.");
|
||||||
|
|
||||||
clearCache(259200);
|
clearCache(259200);
|
||||||
@@ -192,6 +193,16 @@ public class Directories {
|
|||||||
return cached.get("Home");
|
return cached.get("Home");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the screenshot folder.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static File getScreenshotDir() {
|
||||||
|
return cached.get("Screenshots");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validates all directories and makes them if necessary
|
* Validates all directories and makes them if necessary
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -196,7 +196,7 @@ public class ClassPath {
|
|||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
protected void loadClass(InputStream in) throws IOException {
|
protected void loadClass(InputStream in) throws IOException {
|
||||||
ClassReader cr = new ClassReader(in);
|
ClassReader cr = new ClassReader(in);
|
||||||
ClassNode cn = new ClassNode();
|
ClassNode cn = new ClassNode();
|
||||||
RemappingClassAdapter rca = new RemappingClassAdapter(cn,classRemapper);
|
RemappingClassAdapter rca = new RemappingClassAdapter(cn,classRemapper);
|
||||||
RedirectClassAdapter redir = new RedirectClassAdapter(rca);
|
RedirectClassAdapter redir = new RedirectClassAdapter(rca);
|
||||||
|
|||||||
@@ -1,17 +1,23 @@
|
|||||||
package org.parabot.core.ui;
|
package org.parabot.core.ui;
|
||||||
|
|
||||||
import org.parabot.core.Context;
|
import org.parabot.core.Context;
|
||||||
|
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.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.scripts.Script;
|
import org.parabot.environment.scripts.Script;
|
||||||
import org.parabot.environment.scripts.randoms.Random;
|
import org.parabot.environment.scripts.randoms.Random;
|
||||||
|
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.*;
|
import java.awt.event.*;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -25,7 +31,7 @@ public class BotUI extends JFrame implements ActionListener, ComponentListener,
|
|||||||
private static BotUI instance;
|
private static BotUI instance;
|
||||||
private static JDialog dialog;
|
private static JDialog dialog;
|
||||||
|
|
||||||
private JMenuItem run, pause, stop;
|
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) {
|
||||||
@@ -38,7 +44,7 @@ public class BotUI extends JFrame implements ActionListener, ComponentListener,
|
|||||||
|
|
||||||
setTitle("Parabot");
|
setTitle("Parabot");
|
||||||
setResizable(false);
|
setResizable(false);
|
||||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
||||||
createMenu();
|
createMenu();
|
||||||
|
|
||||||
setLayout(new BorderLayout());
|
setLayout(new BorderLayout());
|
||||||
@@ -64,11 +70,13 @@ public class BotUI extends JFrame implements ActionListener, ComponentListener,
|
|||||||
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");
|
||||||
|
|
||||||
JMenuItem screenshot = new JMenuItem("Create screenshot");
|
JMenuItem screenshot = new JMenuItem("Create screenshot");
|
||||||
JMenuItem proxy = new JMenuItem("Network");
|
JMenuItem proxy = new JMenuItem("Network");
|
||||||
@@ -94,6 +102,9 @@ public class BotUI extends JFrame implements ActionListener, ComponentListener,
|
|||||||
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.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);
|
||||||
@@ -101,6 +112,7 @@ public class BotUI extends JFrame implements ActionListener, ComponentListener,
|
|||||||
logger.addActionListener(this);
|
logger.addActionListener(this);
|
||||||
explorer.addActionListener(this);
|
explorer.addActionListener(this);
|
||||||
exit.addActionListener(this);
|
exit.addActionListener(this);
|
||||||
|
cacheClear.addActionListener(this);
|
||||||
|
|
||||||
run.addActionListener(this);
|
run.addActionListener(this);
|
||||||
pause.addActionListener(this);
|
pause.addActionListener(this);
|
||||||
@@ -118,8 +130,12 @@ public class BotUI extends JFrame implements ActionListener, ComponentListener,
|
|||||||
scripts.add(pause);
|
scripts.add(pause);
|
||||||
scripts.add(stop);
|
scripts.add(stop);
|
||||||
|
|
||||||
|
features.add(cacheClear);
|
||||||
|
|
||||||
menuBar.add(file);
|
menuBar.add(file);
|
||||||
menuBar.add(scripts);
|
menuBar.add(scripts);
|
||||||
|
menuBar.add(features);
|
||||||
|
|
||||||
|
|
||||||
setJMenuBar(menuBar);
|
setJMenuBar(menuBar);
|
||||||
}
|
}
|
||||||
@@ -130,7 +146,33 @@ public class BotUI extends JFrame implements ActionListener, ComponentListener,
|
|||||||
|
|
||||||
switch (command) {
|
switch (command) {
|
||||||
case "Create screenshot":
|
case "Create screenshot":
|
||||||
JOptionPane.showMessageDialog(this, "We are still working on this...");
|
try {
|
||||||
|
Robot robot = new Robot();
|
||||||
|
Rectangle parabotScreen = new Rectangle((int) getLocation().getX(), (int) getLocation().getY(), getWidth(), getHeight());
|
||||||
|
BufferedImage image = robot.createScreenCapture(parabotScreen);
|
||||||
|
String randString = StringUtils.randomString(10);
|
||||||
|
boolean search = true;
|
||||||
|
boolean duplicate = false;
|
||||||
|
while (search == true) {
|
||||||
|
for (File f : Directories.getScreenshotDir().listFiles()) {
|
||||||
|
if (f.getAbsoluteFile().getName().contains(randString)) {
|
||||||
|
duplicate = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!duplicate) {
|
||||||
|
search = false;
|
||||||
|
} else {
|
||||||
|
randString = StringUtils.randomString(10);
|
||||||
|
duplicate = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
File file = new File(Directories.getScreenshotDir().getPath() + "/" + randString + ".png");
|
||||||
|
ImageIO.write(image, "png", file);
|
||||||
|
|
||||||
|
} catch (IOException | AWTException k) {
|
||||||
|
k.printStackTrace();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case "Exit":
|
case "Exit":
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
@@ -173,7 +215,7 @@ public class BotUI extends JFrame implements ActionListener, ComponentListener,
|
|||||||
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);
|
||||||
}
|
}
|
||||||
@@ -181,6 +223,9 @@ public class BotUI extends JFrame implements ActionListener, ComponentListener,
|
|||||||
case "Disable dialog":
|
case "Disable dialog":
|
||||||
BotDialog.getInstance().setVisible(!dialog.isVisible());
|
BotDialog.getInstance().setVisible(!dialog.isVisible());
|
||||||
break;
|
break;
|
||||||
|
case "Clear cache":
|
||||||
|
Directories.clearCache();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
System.out.println("Invalid command: " + command);
|
System.out.println("Invalid command: " + command);
|
||||||
}
|
}
|
||||||
@@ -274,4 +319,5 @@ public class BotUI extends JFrame implements ActionListener, ComponentListener,
|
|||||||
@Override
|
@Override
|
||||||
public void windowOpened(WindowEvent arg0) {
|
public void windowOpened(WindowEvent arg0) {
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
}
|
||||||
@@ -1,198 +1,263 @@
|
|||||||
package org.parabot.core.ui;
|
package org.parabot.core.ui;
|
||||||
|
|
||||||
import java.awt.Dimension;
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
import javax.swing.Box;
|
|
||||||
import javax.swing.BoxLayout;
|
|
||||||
import javax.swing.JEditorPane;
|
|
||||||
import javax.swing.JFrame;
|
|
||||||
import javax.swing.JPanel;
|
|
||||||
import javax.swing.JScrollPane;
|
|
||||||
import javax.swing.JTree;
|
|
||||||
import javax.swing.event.TreeSelectionEvent;
|
|
||||||
import javax.swing.event.TreeSelectionListener;
|
|
||||||
import javax.swing.tree.DefaultMutableTreeNode;
|
|
||||||
import javax.swing.tree.DefaultTreeModel;
|
|
||||||
import javax.swing.tree.TreePath;
|
|
||||||
|
|
||||||
import org.parabot.core.Context;
|
import org.parabot.core.Context;
|
||||||
import org.parabot.core.asm.ASMClassLoader;
|
import org.parabot.core.asm.ASMClassLoader;
|
||||||
import org.parabot.core.classpath.ClassPath;
|
import org.parabot.core.classpath.ClassPath;
|
||||||
import org.parabot.core.reflect.RefClass;
|
import org.parabot.core.reflect.RefClass;
|
||||||
import org.parabot.core.reflect.RefField;
|
import org.parabot.core.reflect.RefField;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import javax.swing.event.TreeSelectionEvent;
|
||||||
|
import javax.swing.event.TreeSelectionListener;
|
||||||
|
import javax.swing.tree.DefaultMutableTreeNode;
|
||||||
|
import javax.swing.tree.DefaultTreeModel;
|
||||||
|
import javax.swing.tree.TreeNode;
|
||||||
|
import javax.swing.tree.TreePath;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.util.Enumeration;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* A Reflection explorer
|
* A Reflection explorer
|
||||||
*
|
*
|
||||||
* @author Everel
|
* @author Everel
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class ReflectUI extends JFrame {
|
public class ReflectUI extends JFrame {
|
||||||
private static final long serialVersionUID = 98565034137367257L;
|
private static final long serialVersionUID = 98565034137367257L;
|
||||||
private DefaultMutableTreeNode root;
|
private JTree tree;
|
||||||
private DefaultTreeModel model;
|
private DefaultMutableTreeNode root;
|
||||||
private JEditorPane basicInfoPane;
|
private DefaultTreeModel model;
|
||||||
private JEditorPane selectionInfoPane;
|
private JEditorPane basicInfoPane;
|
||||||
|
private JEditorPane selectionInfoPane;
|
||||||
private Object instance;
|
|
||||||
|
|
||||||
private HashMap<DefaultMutableTreeNode, RefClass> classes;
|
private Object instance;
|
||||||
private HashMap<DefaultMutableTreeNode, RefField> fields;
|
|
||||||
|
|
||||||
public ReflectUI() {
|
private HashMap<DefaultMutableTreeNode, RefClass> classes;
|
||||||
this.root = new DefaultMutableTreeNode("Classes");
|
private HashMap<DefaultMutableTreeNode, RefField> fields;
|
||||||
this.model = new DefaultTreeModel(root);
|
|
||||||
this.basicInfoPane = new JEditorPane();
|
|
||||||
this.selectionInfoPane = new JEditorPane();
|
|
||||||
this.classes = new HashMap<>();
|
|
||||||
this.fields = new HashMap<>();
|
|
||||||
this.instance = Context.getInstance().getClient();
|
|
||||||
|
|
||||||
fillModel();
|
public ReflectUI() {
|
||||||
|
this.root = new DefaultMutableTreeNode("Classes");
|
||||||
|
this.model = new DefaultTreeModel(root);
|
||||||
|
this.basicInfoPane = new JEditorPane();
|
||||||
|
this.selectionInfoPane = new JEditorPane();
|
||||||
|
this.classes = new HashMap<>();
|
||||||
|
this.fields = new HashMap<>();
|
||||||
|
this.instance = Context.getInstance().getClient();
|
||||||
|
|
||||||
setTitle("Reflection explorer");
|
fillModel();
|
||||||
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
|
||||||
|
|
||||||
JPanel content = new JPanel();
|
setTitle("Reflection explorer");
|
||||||
content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS));
|
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
||||||
|
|
||||||
JPanel exploreContent = new JPanel();
|
JPanel content = new JPanel();
|
||||||
exploreContent.setLayout(new BoxLayout(exploreContent, BoxLayout.X_AXIS));
|
content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS));
|
||||||
|
|
||||||
JPanel infoContent = new JPanel();
|
|
||||||
infoContent.setLayout(new BoxLayout(infoContent, BoxLayout.Y_AXIS));
|
|
||||||
|
|
||||||
JTree tree = new JTree();
|
JPanel exploreContent = new JPanel();
|
||||||
tree.setRootVisible(true);
|
exploreContent.setLayout(new BoxLayout(exploreContent, BoxLayout.X_AXIS));
|
||||||
tree.setShowsRootHandles(true);
|
|
||||||
tree.setModel(model);
|
|
||||||
tree.addTreeSelectionListener(new TreeSelectionListener() {
|
|
||||||
|
|
||||||
@Override
|
JPanel infoContent = new JPanel();
|
||||||
public void valueChanged(TreeSelectionEvent event) {
|
infoContent.setLayout(new BoxLayout(infoContent, BoxLayout.Y_AXIS));
|
||||||
TreePath path = event.getPath();
|
|
||||||
Object[] pathElements = path.getPath();
|
|
||||||
Object element = pathElements[pathElements.length-1];
|
|
||||||
if(pathElements.length == 2) {
|
|
||||||
// class
|
|
||||||
setClassInfo(classes.get(element));
|
|
||||||
}
|
|
||||||
if(pathElements.length == 3) {
|
|
||||||
// field
|
|
||||||
setFieldInfo(fields.get(element));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
JScrollPane scrollTreePane = new JScrollPane(tree);
|
JPanel searchContent = new JPanel();
|
||||||
scrollTreePane.setPreferredSize(new Dimension(400, 300));
|
searchContent.setLayout(new BoxLayout(searchContent, BoxLayout.X_AXIS));
|
||||||
|
|
||||||
basicInfoPane.setContentType("text/html");
|
|
||||||
basicInfoPane.setEditable(false);
|
|
||||||
|
|
||||||
selectionInfoPane.setContentType("text/html");
|
final JTextField searchFunction = new JTextField(10);
|
||||||
selectionInfoPane.setEditable(false);
|
searchFunction.setHorizontalAlignment(JTextField.CENTER);
|
||||||
|
searchFunction.setSize(30, 30);
|
||||||
JScrollPane scrollBasicInfoPane = new JScrollPane(basicInfoPane);
|
searchFunction.setColumns(1);
|
||||||
scrollBasicInfoPane.setPreferredSize(new Dimension(400, 90));
|
searchFunction.setPreferredSize(new Dimension(30, 30));
|
||||||
|
|
||||||
JScrollPane scrollSelectInfoPane = new JScrollPane(selectionInfoPane);
|
final JButton searchButton = new JButton("Search");
|
||||||
scrollSelectInfoPane.setPreferredSize(new Dimension(400, 200));
|
searchFunction.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
infoContent.add(scrollBasicInfoPane);
|
public void actionPerformed(ActionEvent e) {
|
||||||
infoContent.add(Box.createRigidArea(new Dimension(0, 10)));
|
searchButton.getActionListeners()[0].actionPerformed(e);
|
||||||
infoContent.add(scrollSelectInfoPane);
|
}
|
||||||
|
});
|
||||||
|
|
||||||
exploreContent.add(scrollTreePane);
|
searchButton.addActionListener(new ActionListener() {
|
||||||
exploreContent.add(Box.createRigidArea(new Dimension(10, 0)));
|
@Override
|
||||||
exploreContent.add(infoContent);
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
RefField result = null;
|
||||||
|
String search = searchFunction.getText();
|
||||||
|
for (RefField f : fields.values()) {
|
||||||
|
if (f != null && (f.asObject()) != null) {
|
||||||
|
String value;
|
||||||
|
if ((value = f.asObject().toString()).equalsIgnoreCase(search)) {
|
||||||
|
result = f;
|
||||||
|
} else if (value.toLowerCase().startsWith(search.toLowerCase())) {
|
||||||
|
result = f;
|
||||||
|
} else if (value.toLowerCase().endsWith(search.toLowerCase())) {
|
||||||
|
result = f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (result != null) {
|
||||||
|
setFieldInfo(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
content.add(exploreContent);
|
|
||||||
|
|
||||||
JScrollPane contentPane = new JScrollPane(content);
|
final JButton adjustClasses = new JButton("Expand");
|
||||||
Dimension prefSize = content.getPreferredSize();
|
adjustClasses.addActionListener(new ActionListener() {
|
||||||
contentPane.setPreferredSize(new Dimension(prefSize.width + contentPane.getVerticalScrollBar().getPreferredSize().width, prefSize.height + contentPane.getHorizontalScrollBar().getPreferredSize().height));
|
@Override
|
||||||
setContentPane(contentPane);
|
public void actionPerformed(ActionEvent e) {
|
||||||
pack();
|
Enumeration<?> topLevelNodes
|
||||||
setLocationRelativeTo(null);
|
= ((TreeNode) tree.getModel().getRoot()).children();
|
||||||
setVisible(true);
|
while (topLevelNodes.hasMoreElements()) {
|
||||||
}
|
DefaultMutableTreeNode node
|
||||||
|
= (DefaultMutableTreeNode) topLevelNodes.nextElement();
|
||||||
|
TreePath treePath = new TreePath(node.getPath());
|
||||||
|
if (adjustClasses.getText().equalsIgnoreCase("expand")) {
|
||||||
|
tree.expandPath(treePath);
|
||||||
|
} else {
|
||||||
|
tree.collapsePath(treePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void fillModel() {
|
adjustClasses.setText(adjustClasses.getText().equalsIgnoreCase("expand") ? "Collapse" : "Expand");
|
||||||
Context context = Context.getInstance();
|
}
|
||||||
ClassPath classPath = context.getClassPath();
|
});
|
||||||
ASMClassLoader classLoader = context.getASMClassLoader();
|
|
||||||
for (String className : classPath.classNames) {
|
|
||||||
try {
|
|
||||||
DefaultMutableTreeNode classNode = new DefaultMutableTreeNode(
|
|
||||||
"Class: " + className);
|
|
||||||
DefaultMutableTreeNode fieldNode;
|
|
||||||
|
|
||||||
Class<?> clazz = classLoader.loadClass(className);
|
searchContent.add(adjustClasses);
|
||||||
|
searchContent.add(searchFunction);
|
||||||
|
searchContent.setMaximumSize(new Dimension(500, (int) searchContent.getPreferredSize().getHeight()));
|
||||||
|
searchContent.add(searchButton);
|
||||||
|
|
||||||
RefClass refClass = new RefClass(clazz);
|
|
||||||
if(refClass.instanceOf(this.instance)) {
|
|
||||||
refClass.setInstance(this.instance);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (RefField field : refClass.getFields()) {
|
|
||||||
fieldNode = new DefaultMutableTreeNode("Field: " + field.getName() + " [type: " + field.getASMType() + "] [value: " + field.asObject() + "]");
|
|
||||||
classNode.add(fieldNode);
|
|
||||||
fields.put(fieldNode, field);
|
|
||||||
}
|
|
||||||
classes.put(classNode, refClass);
|
|
||||||
|
|
||||||
root.add(classNode);
|
tree = new JTree();
|
||||||
} catch (Throwable t) {
|
tree.setRootVisible(true);
|
||||||
t.printStackTrace();
|
tree.setShowsRootHandles(true);
|
||||||
}
|
tree.setModel(model);
|
||||||
}
|
tree.addTreeSelectionListener(new TreeSelectionListener() {
|
||||||
}
|
|
||||||
|
|
||||||
private void fillBasicInfoPane() {
|
|
||||||
Context context = Context.getInstance();
|
|
||||||
ClassPath classPath = context.getClassPath();
|
|
||||||
|
|
||||||
StringBuilder builder = new StringBuilder();
|
|
||||||
|
|
||||||
builder.append("<b>Classes: </b>").append(classPath.classNames.size()).append("<br/>");
|
|
||||||
builder.append("<b>Using instance: </b>").append(instance.toString()).append("<br/>");
|
|
||||||
|
|
||||||
basicInfoPane.setText(builder.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setFieldInfo(RefField refField) {
|
|
||||||
StringBuilder builder = new StringBuilder();
|
|
||||||
RefClass refClass = refField.getOwner();
|
|
||||||
builder.append("<h1>").append(refClass.getClassName()).append(".").append(refField.getName()).append("</h1><br/>");
|
|
||||||
builder.append("<b>Class: </b>").append(refClass.getClassName()).append("<br/>");
|
|
||||||
builder.append("<b>Value: </b>").append(refField.asObject()).append("<br/>");
|
|
||||||
builder.append("<b>Type: </b>").append(refField.getASMType().getClassName()).append("<br/>");
|
|
||||||
builder.append("<b>Static: </b>").append(refField.isStatic() ? "yes" : "no").append("<br/>");
|
|
||||||
builder.append("<b>Array: </b>").append(refField.isArray() ? refField.getArrayDimensions() + " dimension(s)" : "no").append("<br/>");
|
|
||||||
selectionInfoPane.setText(builder.toString());
|
|
||||||
|
|
||||||
fillBasicInfoPane();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setClassInfo(RefClass refClass) {
|
|
||||||
StringBuilder builder = new StringBuilder();
|
|
||||||
builder.append("<h1>").append(refClass.getClassName()).append("</h1><br/>");
|
|
||||||
if(refClass.getClassName().contains(".")) {
|
|
||||||
builder.append("<b>Package: </b>").append(refClass.getClassName().substring(0, refClass.getClassName().lastIndexOf("."))).append("<br/>");
|
|
||||||
}
|
|
||||||
builder.append("<b>Abstract: </b>").append(refClass.isAbstract() ? "yes" : "no").append("<br/>");
|
|
||||||
builder.append("<b>Interface: </b>").append(refClass.isInterface() ? "yes" : "no").append("<br/>");
|
|
||||||
builder.append("<b>Superclass: </b>").append(refClass.hasSuperclass() ? refClass.getSuperclass().getClassName() : "no").append("<br/>");
|
|
||||||
builder.append("<b>Fields: </b>").append(refClass.getFields().length).append("<br/>");
|
|
||||||
builder.append("<b>Methods: </b>").append(refClass.getMethods().length).append("<br/>");
|
|
||||||
builder.append("<b>Constructors: </b>").append(refClass.getConstructors().length).append("<br/>");
|
|
||||||
selectionInfoPane.setText(builder.toString());
|
|
||||||
|
|
||||||
fillBasicInfoPane();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
@Override
|
||||||
|
public void valueChanged(TreeSelectionEvent event) {
|
||||||
|
TreePath path = event.getPath();
|
||||||
|
Object[] pathElements = path.getPath();
|
||||||
|
Object element = pathElements[pathElements.length - 1];
|
||||||
|
if (pathElements.length == 2) {
|
||||||
|
setClassInfo(classes.get(element));
|
||||||
|
} else if (pathElements.length == 3) {
|
||||||
|
RefField field = fields.get(element);
|
||||||
|
setFieldInfo(field);
|
||||||
|
DefaultMutableTreeNode el = (DefaultMutableTreeNode) element;
|
||||||
|
el.setUserObject("Field: " + field.getName() + " [type: " + field.getASMType() + "] [value: " + field.asObject() + "]");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
JScrollPane scrollTreePane = new JScrollPane(tree);
|
||||||
|
scrollTreePane.setPreferredSize(new Dimension(400, 300));
|
||||||
|
|
||||||
|
basicInfoPane.setContentType("text/html");
|
||||||
|
basicInfoPane.setEditable(false);
|
||||||
|
|
||||||
|
selectionInfoPane.setContentType("text/html");
|
||||||
|
selectionInfoPane.setEditable(false);
|
||||||
|
|
||||||
|
JScrollPane scrollBasicInfoPane = new JScrollPane(basicInfoPane);
|
||||||
|
scrollBasicInfoPane.setPreferredSize(new Dimension(400, 90));
|
||||||
|
|
||||||
|
JScrollPane scrollSelectInfoPane = new JScrollPane(selectionInfoPane);
|
||||||
|
scrollSelectInfoPane.setPreferredSize(new Dimension(400, 200));
|
||||||
|
|
||||||
|
infoContent.add(scrollBasicInfoPane);
|
||||||
|
infoContent.add(Box.createRigidArea(new Dimension(0, 10)));
|
||||||
|
infoContent.add(scrollSelectInfoPane);
|
||||||
|
|
||||||
|
exploreContent.add(scrollTreePane);
|
||||||
|
exploreContent.add(Box.createRigidArea(new Dimension(10, 0)));
|
||||||
|
exploreContent.add(infoContent);
|
||||||
|
|
||||||
|
content.add(exploreContent);
|
||||||
|
content.add(searchContent);
|
||||||
|
|
||||||
|
JScrollPane contentPane = new JScrollPane(content);
|
||||||
|
Dimension prefSize = content.getPreferredSize();
|
||||||
|
contentPane.setPreferredSize(new Dimension(prefSize.width + contentPane.getVerticalScrollBar().getPreferredSize().width, prefSize.height + contentPane.getHorizontalScrollBar().getPreferredSize().height));
|
||||||
|
setContentPane(contentPane);
|
||||||
|
pack();
|
||||||
|
setLocationRelativeTo(null);
|
||||||
|
setVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void fillModel() {
|
||||||
|
Context context = Context.getInstance();
|
||||||
|
ClassPath classPath = context.getClassPath();
|
||||||
|
ASMClassLoader classLoader = context.getASMClassLoader();
|
||||||
|
for (String className : classPath.classNames) {
|
||||||
|
try {
|
||||||
|
DefaultMutableTreeNode classNode = new DefaultMutableTreeNode(
|
||||||
|
"Class: " + className);
|
||||||
|
DefaultMutableTreeNode fieldNode;
|
||||||
|
|
||||||
|
Class<?> clazz = classLoader.loadClass(className);
|
||||||
|
|
||||||
|
RefClass refClass = new RefClass(clazz);
|
||||||
|
if (refClass.instanceOf(this.instance)) {
|
||||||
|
refClass.setInstance(this.instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (RefField field : refClass.getFields()) {
|
||||||
|
fieldNode = new DefaultMutableTreeNode("Field: " + field.getName() + " [type: " + field.getASMType() + "] [value: " + field.asObject() + "]");
|
||||||
|
classNode.add(fieldNode);
|
||||||
|
fields.put(fieldNode, field);
|
||||||
|
}
|
||||||
|
classes.put(classNode, refClass);
|
||||||
|
|
||||||
|
root.add(classNode);
|
||||||
|
} catch (Throwable t) {
|
||||||
|
t.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void fillBasicInfoPane() {
|
||||||
|
Context context = Context.getInstance();
|
||||||
|
ClassPath classPath = context.getClassPath();
|
||||||
|
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
|
||||||
|
builder.append("<b>Classes: </b>").append(classPath.classNames.size()).append("<br/>");
|
||||||
|
builder.append("<b>Using instance: </b>").append(instance.toString()).append("<br/>");
|
||||||
|
|
||||||
|
basicInfoPane.setText(builder.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setFieldInfo(RefField refField) {
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
RefClass refClass = refField.getOwner();
|
||||||
|
builder.append("<h1>").append(refClass.getClassName()).append(".").append(refField.getName()).append("</h1><br/>");
|
||||||
|
builder.append("<b>Class: </b>").append(refClass.getClassName()).append("<br/>");
|
||||||
|
builder.append("<b>Value: </b>").append(refField.asObject()).append("<br/>");
|
||||||
|
builder.append("<b>Type: </b>").append(refField.getASMType().getClassName()).append("<br/>");
|
||||||
|
builder.append("<b>Static: </b>").append(refField.isStatic() ? "yes" : "no").append("<br/>");
|
||||||
|
builder.append("<b>Array: </b>").append(refField.isArray() ? refField.getArrayDimensions() + " dimension(s)" : "no").append("<br/>");
|
||||||
|
selectionInfoPane.setText(builder.toString());
|
||||||
|
|
||||||
|
fillBasicInfoPane();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setClassInfo(RefClass refClass) {
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
builder.append("<h1>").append(refClass.getClassName()).append("</h1><br/>");
|
||||||
|
if (refClass.getClassName().contains(".")) {
|
||||||
|
builder.append("<b>Package: </b>").append(refClass.getClassName().substring(0, refClass.getClassName().lastIndexOf("."))).append("<br/>");
|
||||||
|
}
|
||||||
|
builder.append("<b>Abstract: </b>").append(refClass.isAbstract() ? "yes" : "no").append("<br/>");
|
||||||
|
builder.append("<b>Interface: </b>").append(refClass.isInterface() ? "yes" : "no").append("<br/>");
|
||||||
|
builder.append("<b>Superclass: </b>").append(refClass.hasSuperclass() ? refClass.getSuperclass().getClassName() : "no").append("<br/>");
|
||||||
|
builder.append("<b>Fields: </b>").append(refClass.getFields().length).append("<br/>");
|
||||||
|
builder.append("<b>Methods: </b>").append(refClass.getMethods().length).append("<br/>");
|
||||||
|
builder.append("<b>Constructors: </b>").append(refClass.getConstructors().length).append("<br/>");
|
||||||
|
selectionInfoPane.setText(builder.toString());
|
||||||
|
|
||||||
|
fillBasicInfoPane();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -31,7 +31,6 @@ public class ServerSelector extends JPanel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ServerSelector() {
|
public ServerSelector() {
|
||||||
|
|
||||||
Queue<ServerComponent> widgets = getServers();
|
Queue<ServerComponent> widgets = getServers();
|
||||||
if (initServer != null) {
|
if (initServer != null) {
|
||||||
if (runServer(widgets)) {
|
if (runServer(widgets)) {
|
||||||
@@ -42,7 +41,7 @@ public class ServerSelector extends JPanel {
|
|||||||
|
|
||||||
|
|
||||||
setLayout(new BorderLayout());
|
setLayout(new BorderLayout());
|
||||||
setPreferredSize(new Dimension(600, 400));
|
setPreferredSize(new Dimension(600, 350));
|
||||||
|
|
||||||
JPanel interior = new JPanel(null);
|
JPanel interior = new JPanel(null);
|
||||||
|
|
||||||
@@ -66,8 +65,7 @@ public class ServerSelector extends JPanel {
|
|||||||
.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
|
.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
|
||||||
scrlInterior
|
scrlInterior
|
||||||
.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
|
.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
|
||||||
|
add(scrlInterior);
|
||||||
add(scrlInterior, BorderLayout.CENTER);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import java.awt.event.MouseMotionListener;
|
|||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
|
|
||||||
import org.parabot.core.desc.ServerDescription;
|
import org.parabot.core.desc.ServerDescription;
|
||||||
|
import org.parabot.core.ui.fonts.Fonts;
|
||||||
import org.parabot.environment.Environment;
|
import org.parabot.environment.Environment;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -61,13 +62,13 @@ public class ServerComponent extends JPanel implements MouseListener,
|
|||||||
g2d.setColor(bgColor);
|
g2d.setColor(bgColor);
|
||||||
g2d.fillRect(0, 0, w, h);
|
g2d.fillRect(0, 0, w, h);
|
||||||
g.setColor(Color.black);
|
g.setColor(Color.black);
|
||||||
Font title = new Font("Arial", Font.BOLD, 16);
|
Font title = Fonts.getResource("leelawadee.ttf", 16);
|
||||||
g.setFont(title);
|
g.setFont(title);
|
||||||
String serverName = desc.getServerName();
|
String serverName = desc.getServerName();
|
||||||
int sw = g.getFontMetrics().stringWidth(serverName);
|
int sw = g.getFontMetrics().stringWidth(serverName);
|
||||||
g.drawString(serverName, (w / 2) - (sw / 2), 30);
|
g.drawString(serverName, (w / 2) - (sw / 2), 30);
|
||||||
|
|
||||||
Font normal = new Font("Arial", Font.PLAIN, 12);
|
Font normal = Fonts.getResource("leelawadee.ttf");
|
||||||
g.setFont(normal);
|
g.setFont(normal);
|
||||||
FontMetrics fm = g.getFontMetrics();
|
FontMetrics fm = g.getFontMetrics();
|
||||||
String author = "Author: " + desc.getAuthor();
|
String author = "Author: " + desc.getAuthor();
|
||||||
|
|||||||
@@ -1,250 +1,286 @@
|
|||||||
package org.parabot.core.ui.components;
|
package org.parabot.core.ui.components;
|
||||||
|
|
||||||
|
import org.parabot.core.Configuration;
|
||||||
import org.parabot.core.Core;
|
import org.parabot.core.Core;
|
||||||
import org.parabot.core.forum.AccountManager;
|
import org.parabot.core.forum.AccountManager;
|
||||||
import org.parabot.core.forum.AccountManagerAccess;
|
import org.parabot.core.forum.AccountManagerAccess;
|
||||||
import org.parabot.core.io.ProgressListener;
|
import org.parabot.core.io.ProgressListener;
|
||||||
import org.parabot.core.ui.ServerSelector;
|
import org.parabot.core.ui.ServerSelector;
|
||||||
import org.parabot.core.ui.images.Images;
|
import org.parabot.core.ui.images.Images;
|
||||||
|
import org.parabot.core.ui.fonts.Fonts;
|
||||||
import org.parabot.core.ui.utils.UILog;
|
import org.parabot.core.ui.utils.UILog;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
|
import java.awt.geom.Line2D;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.awt.image.RescaleOp;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An informative JPanel which tells the user what bot is doing
|
* An informative JPanel which tells the user what bot is doing
|
||||||
*
|
|
||||||
* @author Everel
|
|
||||||
*
|
*
|
||||||
|
* @author Everel, EmmaStone
|
||||||
*/
|
*/
|
||||||
public class VerboseLoader extends JPanel implements ProgressListener {
|
public class VerboseLoader extends JPanel implements ProgressListener {
|
||||||
private static final long serialVersionUID = 7412412644921803896L;
|
private static final long serialVersionUID = 7412412644921803896L;
|
||||||
private static VerboseLoader current;
|
private static VerboseLoader current;
|
||||||
private static String state = "Initializing loader...";
|
private static String state = "Initializing loader...";
|
||||||
|
|
||||||
public static final int STATE_AUTHENTICATION = 0;
|
|
||||||
public static final int STATE_LOADING = 1;
|
|
||||||
public static final int STATE_SERVER_SELECT = 2;
|
|
||||||
private int currentState;
|
|
||||||
|
|
||||||
private static AccountManager manager;
|
|
||||||
|
|
||||||
private FontMetrics fontMetrics;
|
|
||||||
private BufferedImage background;
|
|
||||||
private ProgressBar progressBar;
|
|
||||||
private JPanel loginPanel;
|
|
||||||
|
|
||||||
public static final AccountManagerAccess MANAGER_FETCHER = new AccountManagerAccess() {
|
|
||||||
|
|
||||||
@Override
|
private static final int STATE_AUTHENTICATION = 0;
|
||||||
public final void setManager(AccountManager manager) {
|
public static final int STATE_LOADING = 1;
|
||||||
VerboseLoader.manager = manager;
|
private static final int STATE_SERVER_SELECT = 2;
|
||||||
}
|
private int currentState;
|
||||||
|
|
||||||
};
|
private static AccountManager manager;
|
||||||
|
|
||||||
private VerboseLoader(String username, String password) {
|
private FontMetrics fontMetrics;
|
||||||
if(current != null) {
|
private BufferedImage background, banner, loginBox;
|
||||||
throw new IllegalStateException("MainScreenComponent already made.");
|
private ProgressBar progressBar;
|
||||||
}
|
private JPanel loginPanel;
|
||||||
current = this;
|
|
||||||
this.background = Images.getResource("/storage/images/background.png");
|
|
||||||
this.progressBar = new ProgressBar(400, 20);
|
|
||||||
setLayout(new GridBagLayout());
|
|
||||||
setSize(775, 510);
|
|
||||||
setPreferredSize(new Dimension(775, 510));
|
|
||||||
setDoubleBuffered(true);
|
|
||||||
setOpaque(false);
|
|
||||||
|
|
||||||
if(username != null && password != null) {
|
|
||||||
if(Core.inDebugMode() || manager.login(username, password, false)) {
|
|
||||||
currentState = STATE_SERVER_SELECT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(currentState == STATE_AUTHENTICATION) {
|
|
||||||
addLoginPanel();
|
|
||||||
} else if(currentState == STATE_SERVER_SELECT) {
|
|
||||||
addServerPanel();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addServerPanel() {
|
|
||||||
JPanel servers = ServerSelector.getInstance();
|
|
||||||
add(servers, new GridBagConstraints());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addLoginPanel() {
|
|
||||||
loginPanel = new JPanel();
|
|
||||||
loginPanel.setOpaque(false);
|
|
||||||
|
|
||||||
loginPanel.setLayout(new BoxLayout(loginPanel, BoxLayout.Y_AXIS));
|
|
||||||
|
|
||||||
Font labelFont = new Font("Times New Roman", Font.PLAIN, 11);
|
|
||||||
|
|
||||||
JLabel usernameLabel = new JLabel("Username");
|
|
||||||
usernameLabel.setFont(labelFont);
|
|
||||||
usernameLabel.setAlignmentX(Box.CENTER_ALIGNMENT);
|
|
||||||
usernameLabel.setForeground(Color.white);
|
|
||||||
|
|
||||||
final JTextField userInput = new JTextField(25);
|
|
||||||
final JTextField passInput = new JPasswordField(25);
|
|
||||||
userInput.addActionListener(new ActionListener() {
|
|
||||||
|
|
||||||
@Override
|
public static final AccountManagerAccess MANAGER_FETCHER = new AccountManagerAccess() {
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
passInput.requestFocus();
|
@Override
|
||||||
}
|
public final void setManager(AccountManager manager) {
|
||||||
|
VerboseLoader.manager = manager;
|
||||||
});
|
}
|
||||||
userInput.setFont(labelFont);
|
|
||||||
userInput.setAlignmentX(Box.CENTER_ALIGNMENT);
|
};
|
||||||
userInput.setMaximumSize(userInput.getPreferredSize());
|
|
||||||
|
private VerboseLoader(String username, String password) {
|
||||||
final JButton login = new JButton("Login");
|
if (current != null) {
|
||||||
|
throw new IllegalStateException("MainScreenComponent already made.");
|
||||||
passInput.setAlignmentX(Box.CENTER_ALIGNMENT);
|
}
|
||||||
passInput.setMaximumSize(userInput.getPreferredSize());
|
current = this;
|
||||||
|
this.background = Images.getResource("/storage/images/background.png");
|
||||||
|
this.banner = Images.getResource("/storage/images/logo.png");
|
||||||
|
this.loginBox = Images.getResource("/storage/images/login.png");
|
||||||
|
this.progressBar = new ProgressBar(400, 20);
|
||||||
|
setLayout(new GridBagLayout());
|
||||||
|
setSize(775, 510);
|
||||||
|
setPreferredSize(new Dimension(775, 510));
|
||||||
|
setDoubleBuffered(true);
|
||||||
|
setOpaque(false);
|
||||||
|
|
||||||
|
if (username != null && password != null) {
|
||||||
|
if (Core.inDebugMode() || manager.login(username, password, false)) {
|
||||||
|
currentState = STATE_SERVER_SELECT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentState == STATE_AUTHENTICATION) {
|
||||||
|
addLoginPanel();
|
||||||
|
} else if (currentState == STATE_SERVER_SELECT) {
|
||||||
|
addServerPanel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addServerPanel() {
|
||||||
|
JPanel servers = ServerSelector.getInstance();
|
||||||
|
GridBagLayout bagLayout = (GridBagLayout) getLayout();
|
||||||
|
GridBagConstraints c = new GridBagConstraints();
|
||||||
|
|
||||||
|
c.weightx = 1;
|
||||||
|
c.weighty = 1;
|
||||||
|
c.gridx = 0;
|
||||||
|
c.gridy = 0;
|
||||||
|
c.anchor = GridBagConstraints.SOUTH;
|
||||||
|
c.insets = new Insets(0, 0, 25, 0);
|
||||||
|
|
||||||
|
bagLayout.setConstraints(servers, c);
|
||||||
|
add(servers);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addLoginPanel() {
|
||||||
|
loginPanel = new JPanel();
|
||||||
|
loginPanel.setOpaque(false);
|
||||||
|
|
||||||
|
loginPanel.setLayout(new BoxLayout(loginPanel, BoxLayout.Y_AXIS));
|
||||||
|
|
||||||
|
Font labelFont = Fonts.getResource("leelawadee.ttf");
|
||||||
|
|
||||||
|
JLabel usernameLabel = new JLabel("Username");
|
||||||
|
usernameLabel.setFont(labelFont);
|
||||||
|
usernameLabel.setAlignmentX(Box.CENTER_ALIGNMENT);
|
||||||
|
usernameLabel.setForeground(Color.white);
|
||||||
|
|
||||||
|
final JTextField userInput = new JTextField(20);
|
||||||
|
final JTextField passInput = new JPasswordField(20);
|
||||||
|
userInput.addActionListener(new ActionListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
passInput.requestFocus();
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
userInput.setFont(labelFont);
|
||||||
|
userInput.setAlignmentX(Box.CENTER_ALIGNMENT);
|
||||||
|
userInput.setMaximumSize(userInput.getPreferredSize());
|
||||||
|
|
||||||
|
final JButton login = new JButton("Login");
|
||||||
|
|
||||||
|
passInput.setAlignmentX(Box.CENTER_ALIGNMENT);
|
||||||
|
passInput.setMaximumSize(userInput.getPreferredSize());
|
||||||
passInput.setPreferredSize(new Dimension(userInput.getWidth(), 20));
|
passInput.setPreferredSize(new Dimension(userInput.getWidth(), 20));
|
||||||
passInput.addActionListener(new ActionListener() {
|
passInput.addActionListener(new ActionListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
login.doClick();
|
login.doClick();
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
JLabel passwordLabel = new JLabel("Password");
|
|
||||||
passwordLabel.setFont(labelFont);
|
|
||||||
passwordLabel.setAlignmentX(Box.CENTER_ALIGNMENT);
|
|
||||||
passwordLabel.setForeground(Color.white);
|
|
||||||
|
|
||||||
|
|
||||||
login.setAlignmentX(Box.CENTER_ALIGNMENT);
|
|
||||||
login.setOpaque(false);
|
|
||||||
|
|
||||||
login.addActionListener(new ActionListener() {
|
|
||||||
|
|
||||||
@Override
|
JLabel passwordLabel = new JLabel("Password");
|
||||||
public void actionPerformed(ActionEvent e) {
|
passwordLabel.setFont(labelFont);
|
||||||
if(manager.login(userInput.getText(), passInput.getText(), false)) {
|
passwordLabel.setAlignmentX(Box.CENTER_ALIGNMENT);
|
||||||
switchState(STATE_SERVER_SELECT);
|
passwordLabel.setForeground(Color.white);
|
||||||
} else {
|
|
||||||
Core.verbose("Failed to log in.");
|
|
||||||
UILog.log("Error", "Incorrect username or password. Have you tried logging into http://bdn.parabot.org/account/", JOptionPane.ERROR_MESSAGE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
loginPanel.add(Box.createRigidArea(new Dimension(0, 5)));
|
|
||||||
loginPanel.add(usernameLabel);
|
|
||||||
loginPanel.add(Box.createRigidArea(new Dimension(0, 5)));
|
|
||||||
loginPanel.add(userInput);
|
|
||||||
loginPanel.add(Box.createRigidArea(new Dimension(0, 5)));
|
|
||||||
loginPanel.add(passwordLabel);
|
|
||||||
loginPanel.add(Box.createRigidArea(new Dimension(0, 5)));
|
|
||||||
loginPanel.add(passInput);
|
|
||||||
loginPanel.add(Box.createRigidArea(new Dimension(0, 5)));
|
|
||||||
loginPanel.add(login);
|
|
||||||
loginPanel.add(Box.createRigidArea(new Dimension(0, 5)));
|
|
||||||
|
|
||||||
add(loginPanel, new GridBagConstraints());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void switchState(int state) {
|
|
||||||
removeAll();
|
|
||||||
if(state == STATE_AUTHENTICATION) {
|
|
||||||
addLoginPanel();
|
|
||||||
} else if(state == STATE_SERVER_SELECT) {
|
|
||||||
addServerPanel();
|
|
||||||
}
|
|
||||||
this.currentState = state;
|
|
||||||
revalidate();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
login.setAlignmentX(Box.CENTER_ALIGNMENT);
|
||||||
* Paints on this panel
|
login.setOpaque(false);
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void paintComponent(Graphics graphics) {
|
|
||||||
super.paintComponent(graphics);
|
|
||||||
|
|
||||||
|
|
||||||
Graphics2D g = (Graphics2D) graphics;
|
|
||||||
g.setRenderingHint(
|
|
||||||
RenderingHints.KEY_TEXT_ANTIALIASING,
|
|
||||||
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
|
||||||
|
|
||||||
g.drawImage(background, 0, 0, null);
|
|
||||||
|
|
||||||
if (fontMetrics == null) {
|
|
||||||
fontMetrics = g.getFontMetrics();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(currentState == STATE_AUTHENTICATION) {
|
|
||||||
g.setColor(new Color(74, 74, 72, 100));
|
|
||||||
g.fillRect(loginPanel.getX() - 10, loginPanel.getY(), loginPanel.getWidth() + 20, loginPanel.getHeight());
|
|
||||||
g.setColor(Color.black);
|
|
||||||
g.drawRect(loginPanel.getX() - 10, loginPanel.getY(), loginPanel.getWidth() + 20, loginPanel.getHeight());
|
|
||||||
}
|
|
||||||
|
|
||||||
g.setColor(Color.white);
|
|
||||||
|
|
||||||
if(currentState == STATE_LOADING) {
|
|
||||||
progressBar.draw(g, (getWidth() / 2) - 200, 220);
|
|
||||||
g.setFont(new Font("Times New Roman", Font.PLAIN, 14));
|
|
||||||
int x = (getWidth() / 2) - (fontMetrics.stringWidth(state) / 2);
|
|
||||||
g.drawString(state, x, 200);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
g.setFont(new Font("Times New Roman", Font.PLAIN, 12));
|
|
||||||
final String version = "v2.1";
|
|
||||||
g.drawString(version,
|
|
||||||
getWidth() - g.getFontMetrics().stringWidth(version) - 10,
|
|
||||||
getHeight() - 12);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
login.addActionListener(new ActionListener() {
|
||||||
* Gets instance of this panel
|
@Override
|
||||||
* @return instance of this panel
|
public void actionPerformed(ActionEvent e) {
|
||||||
*/
|
if (manager.login(userInput.getText(), passInput.getText(), false)) {
|
||||||
public static VerboseLoader get(String username, String password) {
|
switchState(STATE_SERVER_SELECT);
|
||||||
return current == null ? new VerboseLoader(username, password) : current;
|
} else {
|
||||||
}
|
Core.verbose("Failed to log in.");
|
||||||
|
UILog.log("Error", "Incorrect username or password. Have you tried logging into http://bdn.parabot.org/account/", JOptionPane.ERROR_MESSAGE);
|
||||||
/**
|
}
|
||||||
* Gets instance of this panel
|
}
|
||||||
* @return instance of this panel
|
|
||||||
*/
|
|
||||||
public static VerboseLoader get() {
|
|
||||||
return current == null ? new VerboseLoader(null, null) : current;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
});
|
||||||
* Updates the status message and repaints the panel
|
|
||||||
* @param message
|
|
||||||
*/
|
|
||||||
public static void setState(final String message) {
|
|
||||||
state = message;
|
|
||||||
current.repaint();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
loginPanel.add(Box.createRigidArea(new Dimension(0, 8)));
|
||||||
public void onProgressUpdate(double value) {
|
loginPanel.add(usernameLabel);
|
||||||
progressBar.setValue(value);
|
loginPanel.add(Box.createRigidArea(new Dimension(0, 4)));
|
||||||
this.repaint();
|
loginPanel.add(userInput);
|
||||||
}
|
loginPanel.add(Box.createRigidArea(new Dimension(0, 4)));
|
||||||
|
loginPanel.add(passwordLabel);
|
||||||
|
loginPanel.add(Box.createRigidArea(new Dimension(0, 4)));
|
||||||
|
loginPanel.add(passInput);
|
||||||
|
loginPanel.add(Box.createRigidArea(new Dimension(0, 2)));
|
||||||
|
loginPanel.add(login);
|
||||||
|
loginPanel.add(Box.createRigidArea(new Dimension(0, 4)));
|
||||||
|
|
||||||
@Override
|
add(loginPanel, new GridBagConstraints());
|
||||||
public void updateDownloadSpeed(double mbPerSecond) {
|
}
|
||||||
progressBar.setText(String.format("(%.2fMB/s)", mbPerSecond));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
public void switchState(int state) {
|
||||||
|
removeAll();
|
||||||
|
if (state == STATE_AUTHENTICATION) {
|
||||||
|
addLoginPanel();
|
||||||
|
} else if (state == STATE_SERVER_SELECT) {
|
||||||
|
addServerPanel();
|
||||||
|
}
|
||||||
|
this.currentState = state;
|
||||||
|
revalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Paints on this panel
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void paintComponent(Graphics graphics) {
|
||||||
|
super.paintComponent(graphics);
|
||||||
|
|
||||||
|
|
||||||
|
Graphics2D g = (Graphics2D) graphics;
|
||||||
|
g.setRenderingHint(
|
||||||
|
RenderingHints.KEY_TEXT_ANTIALIASING,
|
||||||
|
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
||||||
|
|
||||||
|
g.drawImage(background, 0, 0, null);
|
||||||
|
float[] scales = {1f, 1f, 1f, 0.9f};
|
||||||
|
float[] offsets = new float[4];
|
||||||
|
RescaleOp rop = new RescaleOp(scales, offsets, null);
|
||||||
|
g.drawImage(banner, rop, 0, 0);
|
||||||
|
|
||||||
|
g.setStroke(new BasicStroke(5));
|
||||||
|
g.setPaint(Color.WHITE);
|
||||||
|
|
||||||
|
g.draw(new Line2D.Float(0, 1, this.getWidth(), 1)); //TOP
|
||||||
|
g.draw(new Line2D.Float(0, 0, 0, 120)); //LEFT
|
||||||
|
g.draw(new Line2D.Float(0, 120, this.getWidth(), 120)); //BOTTOM
|
||||||
|
g.draw(new Line2D.Float(this.getWidth() - 6, 0, this.getWidth() - 6, 120)); //RIGHT
|
||||||
|
|
||||||
|
g.setColor(Color.white);
|
||||||
|
|
||||||
|
g.setFont(Fonts.getResource("leelawadee.ttf", 30));
|
||||||
|
g.getFont().deriveFont(Font.BOLD);
|
||||||
|
g.drawString(Configuration.BOT_TITLE, 20, 50);
|
||||||
|
|
||||||
|
g.setFont(Fonts.getResource("leelawadee.ttf", 15));
|
||||||
|
g.getFont().deriveFont(Font.ITALIC);
|
||||||
|
g.drawString(Configuration.BOT_SLOGAN, 20, 85);
|
||||||
|
|
||||||
|
if (fontMetrics == null) {
|
||||||
|
fontMetrics = g.getFontMetrics();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentState == STATE_AUTHENTICATION) {
|
||||||
|
g.drawImage(loginBox, loginPanel.getX() - 30, loginPanel.getY() - 22, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
g.setColor(Color.white);
|
||||||
|
|
||||||
|
if (currentState == STATE_LOADING) {
|
||||||
|
progressBar.draw(g, (getWidth() / 2) - 200, 220);
|
||||||
|
g.setFont(Fonts.getResource("leelawadee.ttf"));
|
||||||
|
int x = (getWidth() / 2) - (fontMetrics.stringWidth(state) / 2);
|
||||||
|
g.drawString(state, x, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
g.setFont(Fonts.getResource("leelawadee.ttf"));
|
||||||
|
final String version = Configuration.BOT_VERSION.get();
|
||||||
|
g.drawString(version,
|
||||||
|
getWidth() - g.getFontMetrics().stringWidth(version) - 10,
|
||||||
|
getHeight() - 12);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets instance of this panel
|
||||||
|
*
|
||||||
|
* @return instance of this panel
|
||||||
|
*/
|
||||||
|
public static VerboseLoader get(String username, String password) {
|
||||||
|
return current == null ? new VerboseLoader(username, password) : current;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets instance of this panel
|
||||||
|
*
|
||||||
|
* @return instance of this panel
|
||||||
|
*/
|
||||||
|
public static VerboseLoader get() {
|
||||||
|
return current == null ? new VerboseLoader(null, null) : current;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the status message and repaints the panel
|
||||||
|
*
|
||||||
|
* @param message
|
||||||
|
*/
|
||||||
|
public static void setState(final String message) {
|
||||||
|
state = message;
|
||||||
|
current.repaint();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onProgressUpdate(double value) {
|
||||||
|
progressBar.setValue(value);
|
||||||
|
this.repaint();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateDownloadSpeed(double mbPerSecond) {
|
||||||
|
progressBar.setText(String.format("(%.2fMB/s)", mbPerSecond));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package org.parabot.core.ui.fonts;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Capslock
|
||||||
|
*/
|
||||||
|
public class Fonts {
|
||||||
|
private static final java.util.List<ParabotFont> FONT_CACHE = new ArrayList<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calls the getResource with the default size of 12
|
||||||
|
*
|
||||||
|
* @param resource
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static Font getResource(final String resource) {
|
||||||
|
return getResource(resource, 12f);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Font getResource(final String fileName, float size) {
|
||||||
|
ParabotFont parabotFont = null;
|
||||||
|
|
||||||
|
for (ParabotFont font : FONT_CACHE) {
|
||||||
|
if (font.getLocation().equalsIgnoreCase(fileName) && font.getSize() == size) {
|
||||||
|
parabotFont = font;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parabotFont == null) {
|
||||||
|
parabotFont = new ParabotFont(fileName, size);
|
||||||
|
FONT_CACHE.add(parabotFont);
|
||||||
|
}
|
||||||
|
|
||||||
|
return parabotFont.getFont();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
package org.parabot.core.ui.fonts;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Capslock
|
||||||
|
*/
|
||||||
|
public class ParabotFont {
|
||||||
|
|
||||||
|
private String location;
|
||||||
|
private Font font;
|
||||||
|
|
||||||
|
public ParabotFont(String location, float size) {
|
||||||
|
if (!location.toLowerCase().startsWith("/storage/fonts/")) {
|
||||||
|
location = "/storage/fonts/" + location;
|
||||||
|
}
|
||||||
|
this.location = location;
|
||||||
|
|
||||||
|
try {
|
||||||
|
this.font = createFont(size);
|
||||||
|
} catch (FontFormatException | IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Font createFont(float size) throws IOException, FontFormatException {
|
||||||
|
return Font.createFont(Font.TRUETYPE_FONT, Fonts.class.getResourceAsStream(this.location)).deriveFont(size);
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getSize() {
|
||||||
|
return font.getSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLocation() {
|
||||||
|
return location;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Font getFont() {
|
||||||
|
return font;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (obj != null) {
|
||||||
|
if (obj instanceof ParabotFont) {
|
||||||
|
ParabotFont otherFont = (ParabotFont) obj;
|
||||||
|
if (otherFont.getSize() == this.getSize()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
After Width: | Height: | Size: 3.5 KiB |
|
Before Width: | Height: | Size: 152 B After Width: | Height: | Size: 152 B |
|
Before Width: | Height: | Size: 1.5 MiB After Width: | Height: | Size: 1.1 MiB |
|
Before Width: | Height: | Size: 299 B After Width: | Height: | Size: 299 B |
|
Before Width: | Height: | Size: 332 B After Width: | Height: | Size: 332 B |
|
Before Width: | Height: | Size: 331 B After Width: | Height: | Size: 331 B |
|
Before Width: | Height: | Size: 325 B After Width: | Height: | Size: 325 B |
|
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 2.0 KiB |
|
Before Width: | Height: | Size: 489 B After Width: | Height: | Size: 489 B |
|
Before Width: | Height: | Size: 357 B After Width: | Height: | Size: 357 B |
|
Before Width: | Height: | Size: 371 B After Width: | Height: | Size: 371 B |
|
Before Width: | Height: | Size: 307 B After Width: | Height: | Size: 307 B |
|
Before Width: | Height: | Size: 311 B After Width: | Height: | Size: 311 B |
|
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
|
Before Width: | Height: | Size: 611 B After Width: | Height: | Size: 611 B |
|
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
|
Before Width: | Height: | Size: 343 B After Width: | Height: | Size: 343 B |
|
Before Width: | Height: | Size: 893 B After Width: | Height: | Size: 893 B |
|
Before Width: | Height: | Size: 328 B After Width: | Height: | Size: 328 B |
|
Before Width: | Height: | Size: 431 B After Width: | Height: | Size: 431 B |
|
Before Width: | Height: | Size: 371 B After Width: | Height: | Size: 371 B |
|
Before Width: | Height: | Size: 452 B After Width: | Height: | Size: 452 B |
|
Before Width: | Height: | Size: 668 B After Width: | Height: | Size: 668 B |
|
Before Width: | Height: | Size: 354 B After Width: | Height: | Size: 354 B |
|
Before Width: | Height: | Size: 276 B After Width: | Height: | Size: 276 B |
|
Before Width: | Height: | Size: 310 B After Width: | Height: | Size: 310 B |
|
Before Width: | Height: | Size: 377 B After Width: | Height: | Size: 377 B |
|
Before Width: | Height: | Size: 3.1 KiB After Width: | Height: | Size: 3.1 KiB |
|
Before Width: | Height: | Size: 3.1 KiB After Width: | Height: | Size: 3.1 KiB |
|
Before Width: | Height: | Size: 76 KiB After Width: | Height: | Size: 76 KiB |
|
After Width: | Height: | Size: 130 KiB |
|
After Width: | Height: | Size: 89 KiB |
|
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 17 KiB |
|
Before Width: | Height: | Size: 125 B After Width: | Height: | Size: 125 B |
|
Before Width: | Height: | Size: 155 B After Width: | Height: | Size: 155 B |
|
Before Width: | Height: | Size: 110 B After Width: | Height: | Size: 110 B |
|
After Width: | Height: | Size: 3.5 KiB |