raids/profiles panel: Make panel layouts better (#1380)

This commit is contained in:
Owain van Brakel
2019-08-17 23:34:47 +02:00
committed by James
parent 23710f3f4a
commit 882091e142
4 changed files with 129 additions and 169 deletions

View File

@@ -30,8 +30,12 @@ import java.awt.Dimension;
import java.awt.event.MouseAdapter; import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException; import java.security.spec.InvalidKeySpecException;
import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.inject.Singleton; import javax.inject.Singleton;
import javax.swing.BorderFactory; import javax.swing.BorderFactory;
import javax.swing.ImageIcon; import javax.swing.ImageIcon;
@@ -101,7 +105,7 @@ class ProfilePanel extends JPanel
{ {
parent.removeProfile(data); parent.removeProfile(data);
} }
catch (InvalidKeySpecException | NoSuchAlgorithmException ex) catch (InvalidKeySpecException | NoSuchAlgorithmException | IllegalBlockSizeException | InvalidKeyException | BadPaddingException | NoSuchPaddingException ex)
{ {
log.error(e.toString()); log.error(e.toString());
} }
@@ -159,6 +163,10 @@ class ProfilePanel extends JPanel
if (SwingUtilities.isLeftMouseButton(e) && client.getGameState() == GameState.LOGIN_SCREEN) if (SwingUtilities.isLeftMouseButton(e) && client.getGameState() == GameState.LOGIN_SCREEN)
{ {
client.setUsername(loginText); client.setUsername(loginText);
if (config.rememberPassword() && password != null)
{
client.setPassword(password);
}
} }
} }
}); });

View File

@@ -25,10 +25,7 @@
package net.runelite.client.plugins.profiles; package net.runelite.client.plugins.profiles;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.Dimension; import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.FocusEvent; import java.awt.event.FocusEvent;
import java.awt.event.FocusListener; import java.awt.event.FocusListener;
import java.awt.event.KeyAdapter; import java.awt.event.KeyAdapter;
@@ -42,6 +39,7 @@ import java.security.spec.InvalidKeySpecException;
import java.security.spec.KeySpec; import java.security.spec.KeySpec;
import java.util.Arrays; import java.util.Arrays;
import java.util.Base64; import java.util.Base64;
import javax.annotation.Nullable;
import javax.crypto.BadPaddingException; import javax.crypto.BadPaddingException;
import javax.crypto.Cipher; import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException; import javax.crypto.IllegalBlockSizeException;
@@ -63,6 +61,7 @@ import javax.swing.border.EmptyBorder;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import net.runelite.api.Client; import net.runelite.api.Client;
import net.runelite.client.ui.ColorScheme; import net.runelite.client.ui.ColorScheme;
import net.runelite.client.ui.DynamicGridLayout;
import net.runelite.client.ui.FontManager; import net.runelite.client.ui.FontManager;
import net.runelite.client.ui.PluginPanel; import net.runelite.client.ui.PluginPanel;
@@ -72,71 +71,60 @@ class ProfilesPanel extends PluginPanel
{ {
private static final int iterations = 100000; private static final int iterations = 100000;
private static final String UNLOCK_PASSWORD = "Encryption Password"; private static final String UNLOCK_PASSWORD = "Encryption Password";
private static final String LOAD_ACCOUNTS = "Load Accounts";
private static final String ACCOUNT_USERNAME = "Account Username"; private static final String ACCOUNT_USERNAME = "Account Username";
private static final String ACCOUNT_LABEL = "Account Label"; private static final String ACCOUNT_LABEL = "Account Label";
private static final String PASSWORD_LABEL = "Account Password"; private static final String PASSWORD_LABEL = "Account Password";
private static final String HELP = "To add and load accounts, first enter a password into the Encryption Password " + private static final String HELP = "To add and load accounts, first enter a password into the Encryption Password " +
"field then press Load Accounts. You can now add as many accounts as you would like. The next time you restart " + "field then press %s. <br /><br /> You can now add as many accounts as you would like. <br /><br /> The next time you restart " +
"RunelitePlus, enter your encryption password and click load accounts to see the accounts you entered"; "RunelitePlus, enter your encryption password and click load accounts to see the accounts you entered.";
private static final Dimension PREFERRED_SIZE = new Dimension(PluginPanel.PANEL_WIDTH - 20, 30);
private static final Dimension HELP_PREFERRED_SIZE = new Dimension(PluginPanel.PANEL_WIDTH - 20, 130);
private static final Dimension MINIMUM_SIZE = new Dimension(0, 30); @Inject
@Nullable
private Client client;
private final Client client; @Inject
private static ProfilesConfig profilesConfig; private ProfilesConfig profilesConfig;
private final JPasswordField txtDecryptPassword = new JPasswordField(UNLOCK_PASSWORD); private final JPasswordField txtDecryptPassword = new JPasswordField(UNLOCK_PASSWORD);
private final JTextField txtAccountLabel = new JTextField(ACCOUNT_LABEL); private final JTextField txtAccountLabel = new JTextField(ACCOUNT_LABEL);
private final JPasswordField txtAccountLogin = new JPasswordField(ACCOUNT_USERNAME); private final JPasswordField txtAccountLogin = new JPasswordField(ACCOUNT_USERNAME);
private final JPasswordField txtPasswordLogin = new JPasswordField(PASSWORD_LABEL); private final JPasswordField txtPasswordLogin = new JPasswordField(PASSWORD_LABEL);
private final JPanel profilesPanel = new JPanel(); private final JPanel profilesPanel = new JPanel();
private final GridBagConstraints c; private final JPanel accountPanel = new JPanel();
private final JPanel loginPanel = new JPanel();
@Inject void init()
public ProfilesPanel(final Client client, final ProfilesConfig config)
{ {
super(); final String LOAD_ACCOUNTS = profilesConfig.salt().length() == 0 ? "Save" : "Unlock";
this.client = client;
profilesConfig = config;
setBorder(new EmptyBorder(18, 10, 0, 10)); setLayout(new BorderLayout(0, 10));
setBackground(ColorScheme.DARK_GRAY_COLOR); setBackground(ColorScheme.DARK_GRAY_COLOR);
setLayout(new GridBagLayout()); setBorder(new EmptyBorder(10, 10, 10, 10));
c = new GridBagConstraints(); final Font smallFont = FontManager.getRunescapeSmallFont();
c.fill = GridBagConstraints.HORIZONTAL;
c.gridx = 0;
c.gridy = 0;
c.weightx = 1;
c.weighty = 0;
c.insets = new Insets(0, 0, 4, 0);
JPanel helpPanel = new JPanel(new BorderLayout()); JPanel helpPanel = new JPanel();
helpPanel.setBackground(ColorScheme.DARKER_GRAY_COLOR); helpPanel.setBackground(ColorScheme.DARKER_GRAY_COLOR);
JLabel helpLabel = new JLabel("<html> <p>" + HELP + "</p></html>"); helpPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
helpLabel.setFont(FontManager.getRunescapeSmallFont()); helpPanel.setLayout(new DynamicGridLayout(1, 1));
helpPanel.setPreferredSize(HELP_PREFERRED_SIZE);
// helpPanel.setSize(MINIMUM_SIZE);
helpPanel.add(helpLabel, BorderLayout.NORTH);
add(helpPanel); JLabel helpLabel = new JLabel(htmlLabel(String.format(HELP, profilesConfig.salt().length() == 0 ? "save" : "unlock")));
c.gridy = c.gridy + 3; helpLabel.setFont(smallFont);
c.gridy++;
helpPanel.add(helpLabel);
loginPanel.setBackground(ColorScheme.DARKER_GRAY_COLOR);
loginPanel.setBorder(new EmptyBorder(10, 10, 10, 3));
loginPanel.setLayout(new DynamicGridLayout(0, 1, 0, 5));
txtDecryptPassword.setEchoChar((char) 0); txtDecryptPassword.setEchoChar((char) 0);
txtDecryptPassword.setPreferredSize(PREFERRED_SIZE); txtDecryptPassword.setForeground(ColorScheme.LIGHT_GRAY_COLOR);
txtDecryptPassword.setForeground(ColorScheme.MEDIUM_GRAY_COLOR);
txtDecryptPassword.setBackground(ColorScheme.DARKER_GRAY_COLOR);
txtDecryptPassword.setMinimumSize(MINIMUM_SIZE);
txtDecryptPassword.setToolTipText(UNLOCK_PASSWORD); txtDecryptPassword.setToolTipText(UNLOCK_PASSWORD);
txtDecryptPassword.addFocusListener(new FocusListener() txtDecryptPassword.addFocusListener(new FocusListener()
{ {
@Override @Override
public void focusGained(FocusEvent e) public void focusGained(FocusEvent e)
{ {
txtDecryptPassword.setForeground(ColorScheme.LIGHT_GRAY_COLOR);
if (String.valueOf(txtDecryptPassword.getPassword()).equals(UNLOCK_PASSWORD)) if (String.valueOf(txtDecryptPassword.getPassword()).equals(UNLOCK_PASSWORD))
{ {
txtDecryptPassword.setText(""); txtDecryptPassword.setText("");
@@ -147,7 +135,6 @@ class ProfilesPanel extends PluginPanel
@Override @Override
public void focusLost(FocusEvent e) public void focusLost(FocusEvent e)
{ {
txtDecryptPassword.setForeground(ColorScheme.MEDIUM_GRAY_COLOR);
if (txtDecryptPassword.getPassword().length == 0) if (txtDecryptPassword.getPassword().length == 0)
{ {
txtDecryptPassword.setText(UNLOCK_PASSWORD); txtDecryptPassword.setText(UNLOCK_PASSWORD);
@@ -156,13 +143,7 @@ class ProfilesPanel extends PluginPanel
} }
}); });
add(txtDecryptPassword, c);
c.gridy++;
JButton btnLoadAccounts = new JButton(LOAD_ACCOUNTS); JButton btnLoadAccounts = new JButton(LOAD_ACCOUNTS);
btnLoadAccounts.setPreferredSize(PREFERRED_SIZE);
btnLoadAccounts.setBackground(ColorScheme.DARKER_GRAY_COLOR);
btnLoadAccounts.setMinimumSize(MINIMUM_SIZE);
btnLoadAccounts.setToolTipText(LOAD_ACCOUNTS); btnLoadAccounts.setToolTipText(LOAD_ACCOUNTS);
btnLoadAccounts.addMouseListener(new MouseListener() btnLoadAccounts.addMouseListener(new MouseListener()
{ {
@@ -175,20 +156,26 @@ class ProfilesPanel extends PluginPanel
@Override @Override
public void mousePressed(MouseEvent e) public void mousePressed(MouseEvent e)
{ {
try
{
remove(loginPanel);
add(accountPanel, BorderLayout.CENTER);
profilesPanel.setLayout(new DynamicGridLayout(0, 1, 0, 3));
add(profilesPanel, BorderLayout.SOUTH);
redrawProfiles();
}
catch (InvalidKeySpecException | NoSuchAlgorithmException | IllegalBlockSizeException | InvalidKeyException | BadPaddingException | NoSuchPaddingException ex)
{
showErrorMessage("Unable to load data", "Incorrect password!");
}
} }
@Override @Override
public void mouseReleased(MouseEvent e) public void mouseReleased(MouseEvent e)
{ {
try
{
redrawProfiles();
}
catch (InvalidKeySpecException | NoSuchAlgorithmException ex)
{
showErrorMessage("Unable to load data", "Incorrect password!");
}
} }
@Override @Override
@@ -204,13 +191,14 @@ class ProfilesPanel extends PluginPanel
} }
}); });
add(btnLoadAccounts, c); loginPanel.add(txtDecryptPassword);
c.gridy++; loginPanel.add(btnLoadAccounts);
txtAccountLabel.setPreferredSize(PREFERRED_SIZE); accountPanel.setBackground(ColorScheme.DARKER_GRAY_COLOR);
txtAccountLabel.setForeground(ColorScheme.MEDIUM_GRAY_COLOR); accountPanel.setBorder(new EmptyBorder(10, 10, 10, 3));
txtAccountLabel.setBackground(ColorScheme.DARKER_GRAY_COLOR); accountPanel.setLayout(new DynamicGridLayout(0, 1, 0, 5));
txtAccountLabel.setMinimumSize(MINIMUM_SIZE);
txtAccountLabel.setForeground(ColorScheme.LIGHT_GRAY_COLOR);
txtAccountLabel.addFocusListener(new FocusListener() txtAccountLabel.addFocusListener(new FocusListener()
{ {
@Override @Override
@@ -219,7 +207,6 @@ class ProfilesPanel extends PluginPanel
if (txtAccountLabel.getText().equals(ACCOUNT_LABEL)) if (txtAccountLabel.getText().equals(ACCOUNT_LABEL))
{ {
txtAccountLabel.setText(""); txtAccountLabel.setText("");
txtAccountLabel.setForeground(ColorScheme.LIGHT_GRAY_COLOR);
} }
} }
@@ -228,21 +215,14 @@ class ProfilesPanel extends PluginPanel
{ {
if (txtAccountLabel.getText().isEmpty()) if (txtAccountLabel.getText().isEmpty())
{ {
txtAccountLabel.setForeground(ColorScheme.MEDIUM_GRAY_COLOR);
txtAccountLabel.setText(ACCOUNT_LABEL); txtAccountLabel.setText(ACCOUNT_LABEL);
} }
} }
}); });
add(txtAccountLabel, c);
c.gridy++;
// Do not hide username characters until they focus or if in streamer mode // Do not hide username characters until they focus or if in streamer mode
txtAccountLogin.setEchoChar((char) 0); txtAccountLogin.setEchoChar((char) 0);
txtAccountLogin.setPreferredSize(PREFERRED_SIZE); txtAccountLogin.setForeground(ColorScheme.LIGHT_GRAY_COLOR);
txtAccountLogin.setForeground(ColorScheme.MEDIUM_GRAY_COLOR);
txtAccountLogin.setBackground(ColorScheme.DARKER_GRAY_COLOR);
txtAccountLogin.setMinimumSize(MINIMUM_SIZE);
txtAccountLogin.addFocusListener(new FocusListener() txtAccountLogin.addFocusListener(new FocusListener()
{ {
@Override @Override
@@ -251,11 +231,10 @@ class ProfilesPanel extends PluginPanel
if (ACCOUNT_USERNAME.equals(String.valueOf(txtAccountLogin.getPassword()))) if (ACCOUNT_USERNAME.equals(String.valueOf(txtAccountLogin.getPassword())))
{ {
txtAccountLogin.setText(""); txtAccountLogin.setText("");
if (config.isStreamerMode()) if (profilesConfig.isStreamerMode())
{ {
txtAccountLogin.setEchoChar('*'); txtAccountLogin.setEchoChar('*');
} }
txtAccountLogin.setForeground(ColorScheme.LIGHT_GRAY_COLOR);
} }
} }
@@ -264,22 +243,15 @@ class ProfilesPanel extends PluginPanel
{ {
if (txtAccountLogin.getPassword().length == 0) if (txtAccountLogin.getPassword().length == 0)
{ {
txtAccountLogin.setForeground(ColorScheme.MEDIUM_GRAY_COLOR);
txtAccountLogin.setText(ACCOUNT_USERNAME); txtAccountLogin.setText(ACCOUNT_USERNAME);
txtAccountLogin.setEchoChar((char) 0); txtAccountLogin.setEchoChar((char) 0);
} }
} }
}); });
add(txtAccountLogin, c);
c.gridy++;
txtPasswordLogin.setEchoChar((char) 0); txtPasswordLogin.setEchoChar((char) 0);
txtPasswordLogin.setPreferredSize(PREFERRED_SIZE); txtPasswordLogin.setForeground(ColorScheme.LIGHT_GRAY_COLOR);
txtPasswordLogin.setForeground(ColorScheme.MEDIUM_GRAY_COLOR);
txtPasswordLogin.setBackground(ColorScheme.DARKER_GRAY_COLOR);
txtPasswordLogin.setToolTipText(PASSWORD_LABEL); txtPasswordLogin.setToolTipText(PASSWORD_LABEL);
txtPasswordLogin.setMinimumSize(MINIMUM_SIZE);
txtPasswordLogin.addFocusListener(new FocusListener() txtPasswordLogin.addFocusListener(new FocusListener()
{ {
@Override @Override
@@ -289,7 +261,6 @@ class ProfilesPanel extends PluginPanel
{ {
txtPasswordLogin.setText(""); txtPasswordLogin.setText("");
txtPasswordLogin.setEchoChar('*'); txtPasswordLogin.setEchoChar('*');
txtPasswordLogin.setForeground(ColorScheme.LIGHT_GRAY_COLOR);
} }
} }
@@ -298,25 +269,14 @@ class ProfilesPanel extends PluginPanel
{ {
if (txtPasswordLogin.getPassword().length == 0) if (txtPasswordLogin.getPassword().length == 0)
{ {
txtPasswordLogin.setForeground(ColorScheme.MEDIUM_GRAY_COLOR);
txtPasswordLogin.setText(PASSWORD_LABEL); txtPasswordLogin.setText(PASSWORD_LABEL);
txtPasswordLogin.setEchoChar((char) 0); txtPasswordLogin.setEchoChar((char) 0);
} }
} }
}); });
if (config.rememberPassword())
{
add(txtPasswordLogin, c);
c.gridy++;
}
c.insets = new Insets(0, 0, 15, 0);
JButton btnAddAccount = new JButton("Add Account"); JButton btnAddAccount = new JButton("Add Account");
btnAddAccount.setPreferredSize(PREFERRED_SIZE);
btnAddAccount.setBackground(ColorScheme.DARKER_GRAY_COLOR); btnAddAccount.setBackground(ColorScheme.DARKER_GRAY_COLOR);
btnAddAccount.setMinimumSize(MINIMUM_SIZE);
btnAddAccount.addActionListener(e -> btnAddAccount.addActionListener(e ->
{ {
String labelText = String.valueOf(txtAccountLabel.getText()); String labelText = String.valueOf(txtAccountLabel.getText());
@@ -328,7 +288,7 @@ class ProfilesPanel extends PluginPanel
return; return;
} }
String data; String data;
if (config.rememberPassword() && txtPasswordLogin.getPassword() != null) if (profilesConfig.rememberPassword() && txtPasswordLogin.getPassword() != null)
{ {
data = labelText + ":" + loginText + ":" + passwordText; data = labelText + ":" + loginText + ":" + passwordText;
} }
@@ -344,7 +304,7 @@ class ProfilesPanel extends PluginPanel
return; return;
} }
} }
catch (InvalidKeySpecException | NoSuchAlgorithmException ex) catch (InvalidKeySpecException | NoSuchAlgorithmException | IllegalBlockSizeException | InvalidKeyException | BadPaddingException | NoSuchPaddingException ex)
{ {
log.error(e.toString()); log.error(e.toString());
} }
@@ -352,15 +312,12 @@ class ProfilesPanel extends PluginPanel
this.addAccount(data); this.addAccount(data);
txtAccountLabel.setText(ACCOUNT_LABEL); txtAccountLabel.setText(ACCOUNT_LABEL);
txtAccountLabel.setForeground(ColorScheme.MEDIUM_GRAY_COLOR);
txtAccountLogin.setText(ACCOUNT_USERNAME); txtAccountLogin.setText(ACCOUNT_USERNAME);
txtAccountLogin.setEchoChar((char) 0); txtAccountLogin.setEchoChar((char) 0);
txtAccountLogin.setForeground(ColorScheme.MEDIUM_GRAY_COLOR);
txtPasswordLogin.setText(PASSWORD_LABEL); txtPasswordLogin.setText(PASSWORD_LABEL);
txtPasswordLogin.setEchoChar((char) 0); txtPasswordLogin.setEchoChar((char) 0);
txtPasswordLogin.setForeground(ColorScheme.MEDIUM_GRAY_COLOR);
}); });
txtAccountLogin.addKeyListener(new KeyAdapter() txtAccountLogin.addKeyListener(new KeyAdapter()
@@ -408,21 +365,23 @@ class ProfilesPanel extends PluginPanel
} }
}); });
add(btnAddAccount, c); accountPanel.add(txtAccountLabel);
c.gridy++; accountPanel.add(txtAccountLogin);
if (profilesConfig.rememberPassword())
{
accountPanel.add(txtPasswordLogin);
}
accountPanel.add(btnAddAccount);
profilesPanel.setLayout(new GridBagLayout()); add(helpPanel, BorderLayout.NORTH);
add(profilesPanel, c); add(loginPanel, BorderLayout.CENTER);
c.gridy = 0;
c.insets = new Insets(0, 0, 5, 0);
// addAccounts(config.profilesData()); // addAccounts(config.profilesData());
} }
private void redrawProfiles() throws InvalidKeySpecException, NoSuchAlgorithmException private void redrawProfiles() throws InvalidKeySpecException, NoSuchAlgorithmException, IllegalBlockSizeException, InvalidKeyException, BadPaddingException, NoSuchPaddingException
{ {
profilesPanel.removeAll(); profilesPanel.removeAll();
c.gridy = 0;
addAccounts(getProfileData()); addAccounts(getProfileData());
revalidate(); revalidate();
@@ -432,8 +391,7 @@ class ProfilesPanel extends PluginPanel
private void addAccount(String data) private void addAccount(String data)
{ {
ProfilePanel profile = new ProfilePanel(client, data, profilesConfig, this); ProfilePanel profile = new ProfilePanel(client, data, profilesConfig, this);
c.gridy++; profilesPanel.add(profile);
profilesPanel.add(profile, c);
revalidate(); revalidate();
repaint(); repaint();
@@ -450,13 +408,13 @@ class ProfilesPanel extends PluginPanel
Arrays.stream(data.split("\\n")).forEach(this::addAccount); Arrays.stream(data.split("\\n")).forEach(this::addAccount);
} }
private boolean addProfile(String data) throws InvalidKeySpecException, NoSuchAlgorithmException private boolean addProfile(String data) throws InvalidKeySpecException, NoSuchAlgorithmException, IllegalBlockSizeException, InvalidKeyException, BadPaddingException, NoSuchPaddingException
{ {
return setProfileData( return setProfileData(
getProfileData() + data + "\n"); getProfileData() + data + "\n");
} }
void removeProfile(String data) throws InvalidKeySpecException, NoSuchAlgorithmException void removeProfile(String data) throws InvalidKeySpecException, NoSuchAlgorithmException, IllegalBlockSizeException, InvalidKeyException, BadPaddingException, NoSuchPaddingException
{ {
setProfileData( setProfileData(
getProfileData().replaceAll(data + "\\n", "")); getProfileData().replaceAll(data + "\\n", ""));
@@ -492,7 +450,7 @@ class ProfilesPanel extends PluginPanel
return factory.generateSecret(spec); return factory.generateSecret(spec);
} }
private String getProfileData() throws InvalidKeySpecException, NoSuchAlgorithmException private String getProfileData() throws InvalidKeySpecException, NoSuchAlgorithmException, IllegalBlockSizeException, InvalidKeyException, BadPaddingException, NoSuchPaddingException
{ {
String tmp = profilesConfig.profilesData(); String tmp = profilesConfig.profilesData();
if (tmp.startsWith("¬")) if (tmp.startsWith("¬"))
@@ -508,7 +466,7 @@ class ProfilesPanel extends PluginPanel
return tmp; return tmp;
} }
private boolean setProfileData(String data) throws InvalidKeySpecException, NoSuchAlgorithmException private boolean setProfileData(String data) throws InvalidKeySpecException, NoSuchAlgorithmException, IllegalBlockSizeException, InvalidKeyException, BadPaddingException, NoSuchPaddingException
{ {
if (txtDecryptPassword.getPassword().length == 0 || String.valueOf(txtDecryptPassword.getPassword()).equals(UNLOCK_PASSWORD)) if (txtDecryptPassword.getPassword().length == 0 || String.valueOf(txtDecryptPassword.getPassword()).equals(UNLOCK_PASSWORD))
{ {
@@ -541,36 +499,20 @@ class ProfilesPanel extends PluginPanel
* @param text text to encrypt * @param text text to encrypt
* @return encrypted string * @return encrypted string
*/ */
private static byte[] encryptText(String text, SecretKey aesKey) private static byte[] encryptText(String text, SecretKey aesKey) throws NoSuchAlgorithmException, IllegalBlockSizeException, InvalidKeyException, BadPaddingException, NoSuchPaddingException
{ {
try Cipher cipher = Cipher.getInstance("AES");
{ SecretKeySpec newKey = new SecretKeySpec(aesKey.getEncoded(), "AES");
Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.ENCRYPT_MODE, newKey);
SecretKeySpec newKey = new SecretKeySpec(aesKey.getEncoded(), "AES"); return cipher.doFinal(text.getBytes());
cipher.init(Cipher.ENCRYPT_MODE, newKey);
return cipher.doFinal(text.getBytes());
}
catch (NoSuchAlgorithmException | IllegalBlockSizeException | InvalidKeyException | BadPaddingException | NoSuchPaddingException e)
{
log.error(e.toString());
}
return new byte[0];
} }
private static String decryptText(byte[] enc, SecretKey aesKey) private static String decryptText(byte[] enc, SecretKey aesKey) throws NoSuchAlgorithmException, IllegalBlockSizeException, InvalidKeyException, BadPaddingException, NoSuchPaddingException
{ {
try Cipher cipher = Cipher.getInstance("AES");
{ SecretKeySpec newKey = new SecretKeySpec(aesKey.getEncoded(), "AES");
Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.DECRYPT_MODE, newKey);
SecretKeySpec newKey = new SecretKeySpec(aesKey.getEncoded(), "AES"); return new String(cipher.doFinal(enc));
cipher.init(Cipher.DECRYPT_MODE, newKey);
return new String(cipher.doFinal(enc));
}
catch (NoSuchAlgorithmException | IllegalBlockSizeException | InvalidKeyException | BadPaddingException | NoSuchPaddingException e)
{
log.error(e.toString());
}
return "";
} }
private static void showErrorMessage(String title, String text) private static void showErrorMessage(String title, String text)
@@ -581,4 +523,8 @@ class ProfilesPanel extends PluginPanel
JOptionPane.ERROR_MESSAGE)); JOptionPane.ERROR_MESSAGE));
} }
private static String htmlLabel(String text)
{
return "<html><body><span style = 'color:white'>" + text + "</span></body></html>";
}
} }

View File

@@ -77,7 +77,6 @@ public class ProfilesPlugin extends Plugin
@Override @Override
protected void startUp() throws Exception protected void startUp() throws Exception
{ {
updateConfig(); updateConfig();
eventBus.subscribe(ConfigChanged.class, this, this::onConfigChanged); eventBus.subscribe(ConfigChanged.class, this, this::onConfigChanged);
@@ -87,6 +86,7 @@ public class ProfilesPlugin extends Plugin
} }
panel = injector.getInstance(ProfilesPanel.class); panel = injector.getInstance(ProfilesPanel.class);
panel.init();
final BufferedImage icon = ImageUtil.getResourceStreamFromClass(getClass(), "profiles_icon.png"); final BufferedImage icon = ImageUtil.getResourceStreamFromClass(getClass(), "profiles_icon.png");

View File

@@ -24,18 +24,19 @@
*/ */
package net.runelite.client.plugins.raids; package net.runelite.client.plugins.raids;
import java.awt.BorderLayout; import java.awt.GridLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import javax.swing.BorderFactory;
import javax.swing.JButton; import javax.swing.JButton;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.border.EmptyBorder;
import net.runelite.api.Client; import net.runelite.api.Client;
import net.runelite.api.GameState; import net.runelite.api.GameState;
import net.runelite.client.ui.ColorScheme; import net.runelite.client.ui.ColorScheme;
import net.runelite.client.ui.FontManager;
import net.runelite.client.ui.PluginPanel; import net.runelite.client.ui.PluginPanel;
@Singleton @Singleton
@@ -48,32 +49,32 @@ class RaidsPanel extends PluginPanel
private final JButton reloadButton = new JButton("Reload Instance"); private final JButton reloadButton = new JButton("Reload Instance");
private final JButton reloadScouter = new JButton("Reload Raid Overlay"); private final JButton reloadScouter = new JButton("Reload Raid Overlay");
private final JLabel reloadMessage = new JLabel("<html><center><h3>Instance Reload Helper </h3>Reloading an instance will cause your client to disconnect temporarily.<br></center></html>");
void init() void init()
{ {
setLayout(new GridLayout(2, 1));
// this may or may not qualify as a hack
// but this lets the editor pane expand to fill the whole parent panel
getParent().setLayout(new FlowLayout());
getParent().add(this, BorderLayout.CENTER);
setLayout(new BorderLayout());
setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
setBackground(ColorScheme.DARK_GRAY_COLOR); setBackground(ColorScheme.DARK_GRAY_COLOR);
setBorder(new EmptyBorder(10, 10, 10, 10));
JPanel reloadContainer = new JPanel(); JPanel raidsPanel = new JPanel();
JPanel scouterContainer = new JPanel(); raidsPanel.setBackground(ColorScheme.DARKER_GRAY_COLOR);
JPanel buttons = new JPanel(); raidsPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
reloadContainer.setLayout(new BorderLayout()); raidsPanel.setLayout(new GridLayout(2, 1));
buttons.setLayout(new BorderLayout());
buttons.setBackground(ColorScheme.DARKER_GRAY_COLOR); JLabel title = new JLabel(htmlLabel("<center>Instance Reload Helper</center>"), SwingConstants.CENTER);
reloadContainer.setBackground(ColorScheme.DARKER_GRAY_COLOR); title.setFont(FontManager.getRunescapeFont());
scouterContainer.setLayout(new BorderLayout());
scouterContainer.setBackground(ColorScheme.DARKER_GRAY_COLOR); JLabel subTitle = new JLabel(htmlLabel("Reloading an instance will cause your client to disconnect temporarily."));
subTitle.setFont(FontManager.getRunescapeSmallFont());
raidsPanel.add(title);
raidsPanel.add(subTitle);
JPanel buttonPanel = new JPanel();
buttonPanel.setBackground(ColorScheme.DARKER_GRAY_COLOR);
buttonPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
buttonPanel.setLayout(new GridLayout(2, 1, 0, 5));
JPanel reloadFrame = new JPanel();
JPanel scoutFrame = new JPanel();
reloadButton.addActionListener((ActionEvent e) -> reloadButton.addActionListener((ActionEvent e) ->
{ {
if ((client.getGameState() == GameState.LOGGED_IN)) if ((client.getGameState() == GameState.LOGGED_IN))
@@ -81,6 +82,7 @@ class RaidsPanel extends PluginPanel
client.setGameState(40); client.setGameState(40);
} }
}); });
reloadScouter.addActionListener((ActionEvent e) -> reloadScouter.addActionListener((ActionEvent e) ->
{ {
if ((client.getGameState() == GameState.LOGGED_IN)) if ((client.getGameState() == GameState.LOGGED_IN))
@@ -89,11 +91,15 @@ class RaidsPanel extends PluginPanel
} }
}); });
reloadFrame.add(reloadButton); buttonPanel.add(reloadButton);
scoutFrame.add(reloadScouter); buttonPanel.add(reloadScouter);
reloadContainer.add(reloadFrame, BorderLayout.NORTH);
reloadContainer.add(scoutFrame, BorderLayout.SOUTH); add(raidsPanel);
add(reloadMessage, BorderLayout.PAGE_START); add(buttonPanel);
add(reloadContainer, BorderLayout.CENTER); }
private static String htmlLabel(String text)
{
return "<html><body><span style = 'color:white'>" + text + "</span></body></html>";
} }
} }