mirror of
https://github.com/2006-Scape/Parabot.git
synced 2026-07-04 16:49:10 +00:00
MainScreenComponent
This commit is contained in:
@@ -1,17 +1,18 @@
|
||||
package org.parabot;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.UIManager;
|
||||
|
||||
import org.parabot.core.Core;
|
||||
import org.parabot.core.Directories;
|
||||
import org.parabot.core.forum.AccountManager;
|
||||
import org.parabot.core.ui.LoginUI;
|
||||
import org.parabot.core.ui.BotUI;
|
||||
import org.parabot.core.ui.ServerSelector;
|
||||
import org.parabot.core.ui.utils.UILog;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Parabot v2
|
||||
*
|
||||
@@ -51,14 +52,14 @@ public final class Landing {
|
||||
AccountManager.validate();
|
||||
|
||||
if (username != null && password != null) {
|
||||
new LoginUI(username, password);
|
||||
new BotUI(username, password);
|
||||
username = null;
|
||||
password = null;
|
||||
return;
|
||||
}
|
||||
|
||||
Core.verbose("Starting login gui...");
|
||||
new LoginUI().setVisible(true);
|
||||
new BotUI(null, null);
|
||||
}
|
||||
|
||||
private static void parseArgs(String... args) {
|
||||
|
||||
@@ -177,7 +177,7 @@ public class Context {
|
||||
BotUI.getInstance().pack();
|
||||
BotUI.getInstance().validate();
|
||||
|
||||
panel.removeLoader();
|
||||
panel.removeComponents();
|
||||
gameApplet.setSize(appletSize);
|
||||
panel.add(gameApplet);
|
||||
panel.validate();
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.parabot.core.Directories;
|
||||
import org.parabot.core.asm.ClassRemapper;
|
||||
import org.parabot.core.build.BuildPath;
|
||||
import org.parabot.core.io.SizeInputStream;
|
||||
import org.parabot.core.ui.components.VerboseLoader;
|
||||
import org.parabot.core.ui.components.MainScreenComponent;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -85,7 +85,7 @@ public class ClassPath {
|
||||
try {
|
||||
final int size = connection.getContentLength();
|
||||
final SizeInputStream sizeInputStream = new SizeInputStream(
|
||||
connection.getInputStream(), size, VerboseLoader.get());
|
||||
connection.getInputStream(), size, MainScreenComponent.get());
|
||||
final ZipInputStream zin = new ZipInputStream(sizeInputStream);
|
||||
ZipEntry e;
|
||||
while ((e = zin.getNextEntry()) != null) {
|
||||
@@ -96,13 +96,13 @@ public class ClassPath {
|
||||
} else {
|
||||
loadResource(e.getName(), zin);
|
||||
}
|
||||
VerboseLoader.setState("Downloading: " + e.getName());
|
||||
MainScreenComponent.setState("Downloading: " + e.getName());
|
||||
}
|
||||
zin.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
VerboseLoader.get().onProgressUpdate(100);
|
||||
MainScreenComponent.get().onProgressUpdate(100);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
package org.parabot.core.forum;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.parabot.core.Configuration;
|
||||
import org.parabot.core.Core;
|
||||
import org.parabot.core.parsers.scripts.SDNScripts;
|
||||
import org.parabot.core.parsers.servers.PublicServers;
|
||||
import org.parabot.core.ui.LoginUI;
|
||||
import org.parabot.core.ui.components.MainScreenComponent;
|
||||
import org.parabot.environment.api.utils.WebUtil;
|
||||
import org.parabot.environment.scripts.executers.SDNScriptExecuter;
|
||||
import org.parabot.environment.servers.executers.PublicServerExecuter;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Handles logging in to parabot forum, only certain classes may use this class.
|
||||
*
|
||||
@@ -39,7 +39,7 @@ public final class AccountManager {
|
||||
Core.verbose("Initializing account manager accessors...");
|
||||
final ArrayList<AccountManagerAccess> accessors = new ArrayList<AccountManagerAccess>();
|
||||
accessors.add(SDNScripts.MANAGER_FETCHER);
|
||||
accessors.add(LoginUI.MANAGER_FETCHER);
|
||||
accessors.add(MainScreenComponent.MANAGER_FETCHER);
|
||||
accessors.add(SDNScriptExecuter.MANAGER_FETCHER);
|
||||
accessors.add(PublicServers.MANAGER_FETCHER);
|
||||
accessors.add(PublicServerExecuter.MANAGER_FETCHER);
|
||||
|
||||
@@ -20,6 +20,7 @@ import javax.swing.JPopupMenu;
|
||||
|
||||
import org.parabot.core.Context;
|
||||
import org.parabot.core.ui.components.GamePanel;
|
||||
import org.parabot.core.ui.components.MainScreenComponent;
|
||||
import org.parabot.core.ui.images.Images;
|
||||
import org.parabot.core.ui.utils.SwingUtil;
|
||||
import org.parabot.environment.scripts.Script;
|
||||
@@ -41,10 +42,14 @@ public class BotUI extends JFrame implements ActionListener, ComponentListener,
|
||||
private boolean runScript, pauseScript;
|
||||
|
||||
public static BotUI getInstance() {
|
||||
return instance == null ? instance = new BotUI() : instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
private BotUI() {
|
||||
public BotUI(String username, String password) {
|
||||
if(instance != null) {
|
||||
throw new IllegalStateException("BotUI already created");
|
||||
}
|
||||
instance = this;
|
||||
JPopupMenu.setDefaultLightWeightPopupEnabled(false);
|
||||
|
||||
setTitle("Parabot");
|
||||
@@ -57,7 +62,7 @@ public class BotUI extends JFrame implements ActionListener, ComponentListener,
|
||||
addWindowListener(this);
|
||||
|
||||
add(GamePanel.getInstance());
|
||||
GamePanel.getInstance().addLoader();
|
||||
GamePanel.getInstance().add(MainScreenComponent.get(username, password), BorderLayout.CENTER);
|
||||
|
||||
SwingUtil.setParabotIcons(this);
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@ import javax.swing.JTextField;
|
||||
|
||||
import org.parabot.core.Core;
|
||||
import org.parabot.core.forum.AccountManager;
|
||||
import org.parabot.core.forum.AccountManagerAccess;
|
||||
import org.parabot.core.ui.images.Images;
|
||||
import org.parabot.core.ui.utils.SwingUtil;
|
||||
|
||||
@@ -42,14 +41,6 @@ public class LoginUI extends JFrame {
|
||||
private JButton cmdLogin;
|
||||
private JButton cmdRegister;
|
||||
|
||||
public static final AccountManagerAccess MANAGER_FETCHER = new AccountManagerAccess() {
|
||||
|
||||
@Override
|
||||
public final void setManager(AccountManager manager) {
|
||||
LoginUI.manager = manager;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
public void attemptLogin() {
|
||||
String username = txtUsername.getText();
|
||||
|
||||
@@ -5,14 +5,12 @@ import java.awt.Dimension;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Queue;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
|
||||
import org.parabot.core.desc.ServerDescription;
|
||||
import org.parabot.core.parsers.servers.ServerParser;
|
||||
import org.parabot.core.ui.components.ServerComponent;
|
||||
import org.parabot.core.ui.utils.SwingUtil;
|
||||
import org.parabot.environment.Environment;
|
||||
|
||||
/**
|
||||
@@ -23,12 +21,10 @@ import org.parabot.environment.Environment;
|
||||
*
|
||||
*/
|
||||
|
||||
public class ServerSelector extends JFrame {
|
||||
public class ServerSelector extends JPanel {
|
||||
public static String initServer;
|
||||
private static final long serialVersionUID = 5238720307271493899L;
|
||||
private static ServerSelector instance;
|
||||
|
||||
private JPanel panel;
|
||||
|
||||
public static ServerSelector getInstance() {
|
||||
if (instance == null) {
|
||||
@@ -46,15 +42,10 @@ public class ServerSelector extends JFrame {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
this.setTitle("Servers");
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
this.setResizable(false);
|
||||
|
||||
SwingUtil.setParabotIcons(this);
|
||||
|
||||
this.panel = new JPanel(new BorderLayout());
|
||||
this.panel.setPreferredSize(new Dimension(600, 400));
|
||||
setLayout(new BorderLayout());
|
||||
setPreferredSize(new Dimension(600, 400));
|
||||
|
||||
JPanel interior = new JPanel(null);
|
||||
|
||||
@@ -79,10 +70,7 @@ public class ServerSelector extends JFrame {
|
||||
scrlInterior
|
||||
.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
|
||||
|
||||
this.panel.add(scrlInterior, BorderLayout.CENTER);
|
||||
this.add(panel);
|
||||
|
||||
SwingUtil.finalize(this);
|
||||
add(scrlInterior, BorderLayout.CENTER);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@ import org.parabot.core.Context;
|
||||
public class GamePanel extends JPanel {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static GamePanel instance;
|
||||
private static VerboseLoader loader = VerboseLoader.get();
|
||||
|
||||
private GamePanel() {
|
||||
setFocusable(true);
|
||||
@@ -54,16 +53,9 @@ public class GamePanel extends JPanel {
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the loader applet
|
||||
* Removes all components
|
||||
*/
|
||||
public void addLoader() {
|
||||
add(loader, BorderLayout.CENTER);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the loader applet
|
||||
*/
|
||||
public void removeLoader() {
|
||||
remove(loader);
|
||||
public void removeComponents() {
|
||||
removeAll();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,241 @@
|
||||
package org.parabot.core.ui.components;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Font;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
import javax.swing.Box;
|
||||
import javax.swing.BoxLayout;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JPasswordField;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
import org.parabot.core.forum.AccountManager;
|
||||
import org.parabot.core.forum.AccountManagerAccess;
|
||||
import org.parabot.core.io.ProgressListener;
|
||||
import org.parabot.core.ui.ServerSelector;
|
||||
import org.parabot.core.ui.images.Images;
|
||||
|
||||
/**
|
||||
* An informative JPanel which tells the user what bot is doing
|
||||
*
|
||||
* @author Everel
|
||||
*
|
||||
*/
|
||||
public class MainScreenComponent extends JPanel implements ProgressListener {
|
||||
private static final long serialVersionUID = 7412412644921803896L;
|
||||
private static MainScreenComponent current;
|
||||
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
|
||||
public final void setManager(AccountManager manager) {
|
||||
MainScreenComponent.manager = manager;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
private MainScreenComponent(String username, String password) {
|
||||
if(current != null) {
|
||||
throw new IllegalStateException("MainScreenComponent already made.");
|
||||
}
|
||||
current = this;
|
||||
this.background = Images.getResource("/org/parabot/core/ui/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(manager.login(username, password)) {
|
||||
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);
|
||||
userInput.setFont(labelFont);
|
||||
userInput.setAlignmentX(Box.CENTER_ALIGNMENT);
|
||||
userInput.setMaximumSize(userInput.getPreferredSize());
|
||||
|
||||
final JTextField passInput = new JPasswordField(25);
|
||||
passInput.setAlignmentX(Box.CENTER_ALIGNMENT);
|
||||
passInput.setMaximumSize(userInput.getPreferredSize());
|
||||
|
||||
JLabel passwordLabel = new JLabel("Password");
|
||||
passwordLabel.setFont(labelFont);
|
||||
passwordLabel.setAlignmentX(Box.CENTER_ALIGNMENT);
|
||||
passwordLabel.setForeground(Color.white);
|
||||
|
||||
JButton login = new JButton("Login");
|
||||
login.setAlignmentX(Box.CENTER_ALIGNMENT);
|
||||
login.setOpaque(false);
|
||||
|
||||
login.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if(manager.login(userInput.getText(), passInput.getText())) {
|
||||
switchState(STATE_SERVER_SELECT);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets instance of this panel
|
||||
* @return instance of this panel
|
||||
*/
|
||||
public static MainScreenComponent get(String username, String password) {
|
||||
return current == null ? new MainScreenComponent(username, password) : current;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets instance of this panel
|
||||
* @return instance of this panel
|
||||
*/
|
||||
public static MainScreenComponent get() {
|
||||
return current == null ? new MainScreenComponent(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));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,16 +1,20 @@
|
||||
package org.parabot.core.ui.components;
|
||||
|
||||
import org.parabot.core.desc.ServerDescription;
|
||||
import org.parabot.core.ui.BotUI;
|
||||
import org.parabot.core.ui.ServerSelector;
|
||||
import org.parabot.environment.Environment;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.Color;
|
||||
import java.awt.Cursor;
|
||||
import java.awt.Font;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
import java.awt.event.MouseMotionListener;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import org.parabot.core.desc.ServerDescription;
|
||||
import org.parabot.environment.Environment;
|
||||
|
||||
/**
|
||||
* A neat looking server component
|
||||
*
|
||||
@@ -74,8 +78,7 @@ public class ServerComponent extends JPanel implements MouseListener,
|
||||
}
|
||||
|
||||
public void load(final ServerDescription desc) {
|
||||
ServerSelector.getInstance().dispose();
|
||||
BotUI.getInstance();
|
||||
MainScreenComponent.get().switchState(MainScreenComponent.STATE_LOADING);
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
package org.parabot.core.ui.components;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
|
||||
import javax.swing.GroupLayout;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
/**
|
||||
*
|
||||
* Game Applet holder
|
||||
*
|
||||
* @author Everel
|
||||
*
|
||||
*/
|
||||
public class ServerPanel extends JPanel {
|
||||
private static final long serialVersionUID = 6034139911394898295L;
|
||||
|
||||
public ServerPanel() {
|
||||
setBorder(null);
|
||||
setOpaque(false);
|
||||
setPreferredSize(new Dimension(765, 503));
|
||||
GroupLayout layout = new GroupLayout(this);
|
||||
setLayout(layout);
|
||||
layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGap(0, 706, Short.MAX_VALUE));
|
||||
layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGap(0, 418, Short.MAX_VALUE));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
g.setColor(Color.LIGHT_GRAY);
|
||||
g.fillRect(0, 0, getWidth(), getHeight());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
package org.parabot.core.ui.components;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Font;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import org.parabot.core.io.ProgressListener;
|
||||
import org.parabot.core.ui.images.Images;
|
||||
|
||||
/**
|
||||
* An informative JPanel which tells the user what bot is doing
|
||||
*
|
||||
* @author Everel
|
||||
*
|
||||
*/
|
||||
public class VerboseLoader extends JPanel implements ProgressListener {
|
||||
private static final long serialVersionUID = 7412412644921803896L;
|
||||
private static VerboseLoader current;
|
||||
private static String state = "Initializing loader...";
|
||||
|
||||
private FontMetrics fontMetrics;
|
||||
private BufferedImage background;
|
||||
private ProgressBar p;
|
||||
|
||||
public VerboseLoader() {
|
||||
this.background = Images.getResource("/org/parabot/core/ui/images/background.png");
|
||||
this.p = new ProgressBar(400, 20);
|
||||
setSize(775, 510);
|
||||
setPreferredSize(new Dimension(775, 510));
|
||||
setBackground(Color.black);
|
||||
setDoubleBuffered(true);
|
||||
setOpaque(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Paints on this panel
|
||||
*/
|
||||
@Override
|
||||
public void paint(Graphics graphics) {
|
||||
Graphics2D g = (Graphics2D) graphics;
|
||||
g.setRenderingHint(
|
||||
RenderingHints.KEY_TEXT_ANTIALIASING,
|
||||
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
||||
|
||||
g.drawImage(background, 0, 0, null);
|
||||
|
||||
p.draw(g, (getWidth() / 2) - 200, 220);
|
||||
g.setFont(new Font("Times New Roman", Font.PLAIN, 14));
|
||||
if (fontMetrics == null) {
|
||||
fontMetrics = g.getFontMetrics();
|
||||
}
|
||||
g.setColor(Color.white);
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets instance of this panel
|
||||
* @return instance of this panel
|
||||
*/
|
||||
public static VerboseLoader get() {
|
||||
return current == null ? current = new VerboseLoader() : 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) {
|
||||
p.setValue(value);
|
||||
this.repaint();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDownloadSpeed(double mbPerSecond) {
|
||||
p.setText(String.format("(%.2fMB/s)", mbPerSecond));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,7 +7,7 @@ import org.parabot.core.desc.ServerDescription;
|
||||
import org.parabot.core.lib.Library;
|
||||
import org.parabot.core.lib.javafx.JavaFX;
|
||||
import org.parabot.core.parsers.servers.ServerParser;
|
||||
import org.parabot.core.ui.components.VerboseLoader;
|
||||
import org.parabot.core.ui.components.MainScreenComponent;
|
||||
import org.parabot.environment.api.utils.WebUtil;
|
||||
|
||||
|
||||
@@ -33,8 +33,8 @@ public class Environment {
|
||||
for(Library lib : libs) {
|
||||
if(!lib.hasJar()) {
|
||||
Core.verbose("Downloading " + lib.getLibraryName() + "...");
|
||||
VerboseLoader.setState("Downloading " + lib.getLibraryName() + "...");
|
||||
WebUtil.downloadFile(lib.getDownloadLink(), lib.getJarFile(), VerboseLoader.get());
|
||||
MainScreenComponent.setState("Downloading " + lib.getLibraryName() + "...");
|
||||
WebUtil.downloadFile(lib.getDownloadLink(), lib.getJarFile(), MainScreenComponent.get());
|
||||
Core.verbose("Downloaded " + lib.getLibraryName() + ".");
|
||||
}
|
||||
Core.verbose("Initializing " + lib.getLibraryName());
|
||||
|
||||
@@ -9,7 +9,7 @@ import org.parabot.core.classpath.ClassPath;
|
||||
import org.parabot.core.desc.ServerProviderInfo;
|
||||
import org.parabot.core.forum.AccountManager;
|
||||
import org.parabot.core.forum.AccountManagerAccess;
|
||||
import org.parabot.core.ui.components.VerboseLoader;
|
||||
import org.parabot.core.ui.components.MainScreenComponent;
|
||||
import org.parabot.core.ui.utils.UILog;
|
||||
import org.parabot.environment.api.utils.WebUtil;
|
||||
import org.parabot.environment.servers.ServerProvider;
|
||||
@@ -76,7 +76,7 @@ public class PublicServerExecuter extends ServerExecuter {
|
||||
Core.verbose("Found cached server provider [CRC32: " + serverProviderInfo.getCRC32() + "]");
|
||||
} else {
|
||||
WebUtil.downloadFile(new URL(jarUrl), destination,
|
||||
VerboseLoader.get(), manager.getAccount().getUsername(), manager.getAccount().getPassword());
|
||||
MainScreenComponent.get(), manager.getAccount().getUsername(), manager.getAccount().getPassword());
|
||||
Core.verbose("Server provider downloaded...");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user