runelite-client: fix some incorrect swing usage
All swing operations should be on the event dispatch thread
This commit is contained in:
@@ -41,6 +41,7 @@ import java.io.InputStreamReader;
|
|||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
|
import javax.swing.SwingUtilities;
|
||||||
import joptsimple.OptionParser;
|
import joptsimple.OptionParser;
|
||||||
import joptsimple.OptionSet;
|
import joptsimple.OptionSet;
|
||||||
import net.runelite.api.Client;
|
import net.runelite.api.Client;
|
||||||
@@ -118,9 +119,12 @@ public class RuneLite
|
|||||||
|
|
||||||
public void start() throws Exception
|
public void start() throws Exception
|
||||||
{
|
{
|
||||||
gui = new ClientUI();
|
SwingUtilities.invokeAndWait(() ->
|
||||||
|
{
|
||||||
|
gui = new ClientUI();
|
||||||
|
|
||||||
setupTrayIcon();
|
setupTrayIcon();
|
||||||
|
});
|
||||||
|
|
||||||
configManager.load();
|
configManager.load();
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ package net.runelite.client.callback;
|
|||||||
|
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import javax.swing.SwingUtilities;
|
||||||
import net.runelite.api.ChatMessageType;
|
import net.runelite.api.ChatMessageType;
|
||||||
import net.runelite.api.MenuAction;
|
import net.runelite.api.MenuAction;
|
||||||
import net.runelite.api.Skill;
|
import net.runelite.api.Skill;
|
||||||
@@ -88,11 +90,24 @@ public class Hooks
|
|||||||
|
|
||||||
OverlayRenderer renderer = runelite.getRenderer();
|
OverlayRenderer renderer = runelite.getRenderer();
|
||||||
|
|
||||||
|
assert !SwingUtilities.isEventDispatchThread();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
renderer.render(image);
|
SwingUtilities.invokeAndWait(() ->
|
||||||
|
{
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
renderer.render(image);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
logger.warn("Error during overlay rendering", ex);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (InterruptedException | InvocationTargetException ex)
|
||||||
{
|
{
|
||||||
logger.warn("Error during overlay rendering", ex);
|
logger.warn("Error during overlay rendering", ex);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import com.google.common.util.concurrent.AbstractIdleService;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
import javax.swing.SwingUtilities;
|
||||||
import net.runelite.client.ui.overlay.Overlay;
|
import net.runelite.client.ui.overlay.Overlay;
|
||||||
|
|
||||||
public abstract class Plugin extends AbstractIdleService
|
public abstract class Plugin extends AbstractIdleService
|
||||||
@@ -54,6 +55,6 @@ public abstract class Plugin extends AbstractIdleService
|
|||||||
@Override
|
@Override
|
||||||
protected Executor executor()
|
protected Executor executor()
|
||||||
{
|
{
|
||||||
return r -> r.run();
|
return r -> SwingUtilities.invokeLater(r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,14 +55,18 @@ public class AccountPlugin extends Plugin
|
|||||||
|
|
||||||
private final RuneLite runelite = RuneLite.getRunelite();
|
private final RuneLite runelite = RuneLite.getRunelite();
|
||||||
private final ClientUI ui = runelite.getGui();
|
private final ClientUI ui = runelite.getGui();
|
||||||
private final NavigationButton loginButton = new NavigationButton("Login");
|
|
||||||
private final NavigationButton logoutButton = new NavigationButton("Logout");
|
private NavigationButton loginButton;
|
||||||
|
private NavigationButton logoutButton;
|
||||||
|
|
||||||
private final AccountClient loginClient = new AccountClient();
|
private final AccountClient loginClient = new AccountClient();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void startUp() throws Exception
|
protected void startUp() throws Exception
|
||||||
{
|
{
|
||||||
|
loginButton = new NavigationButton("Login");
|
||||||
|
logoutButton = new NavigationButton("Logout");
|
||||||
|
|
||||||
ImageIcon icon = new ImageIcon(ImageIO.read(getClass().getResourceAsStream("login_icon.png")));
|
ImageIcon icon = new ImageIcon(ImageIO.read(getClass().getResourceAsStream("login_icon.png")));
|
||||||
loginButton.getButton().setIcon(icon);
|
loginButton.getButton().setIcon(icon);
|
||||||
|
|
||||||
|
|||||||
@@ -38,13 +38,16 @@ public class ConfigPlugin extends Plugin
|
|||||||
{
|
{
|
||||||
private static final Logger logger = LoggerFactory.getLogger(ConfigPlugin.class);
|
private static final Logger logger = LoggerFactory.getLogger(ConfigPlugin.class);
|
||||||
|
|
||||||
private final NavigationButton navButton = new NavigationButton("Configuration");
|
|
||||||
private final RuneLite runelite = RuneLite.getRunelite();
|
private final RuneLite runelite = RuneLite.getRunelite();
|
||||||
private final ClientUI ui = runelite.getGui();
|
private final ClientUI ui = runelite.getGui();
|
||||||
|
|
||||||
|
private NavigationButton navButton;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void startUp() throws Exception
|
protected void startUp() throws Exception
|
||||||
{
|
{
|
||||||
|
navButton = new NavigationButton("Configuration");
|
||||||
|
|
||||||
navButton.getButton().addActionListener(this::setPluginPanel);
|
navButton.getButton().addActionListener(this::setPluginPanel);
|
||||||
|
|
||||||
ImageIcon icon = new ImageIcon(ImageIO.read(getClass().getResourceAsStream("config_icon.png")));
|
ImageIcon icon = new ImageIcon(ImageIO.read(getClass().getResourceAsStream("config_icon.png")));
|
||||||
|
|||||||
@@ -39,8 +39,8 @@ import net.runelite.client.ui.overlay.Overlay;
|
|||||||
public class DevTools extends Plugin
|
public class DevTools extends Plugin
|
||||||
{
|
{
|
||||||
private final DevToolsOverlay overlay = new DevToolsOverlay(this);
|
private final DevToolsOverlay overlay = new DevToolsOverlay(this);
|
||||||
private final DevToolsPanel panel = new DevToolsPanel(this);
|
private DevToolsPanel panel;
|
||||||
private final NavigationButton navButton = new NavigationButton("DevTools");
|
private NavigationButton navButton;
|
||||||
private final ClientUI ui = RuneLite.getRunelite().getGui();
|
private final ClientUI ui = RuneLite.getRunelite().getGui();
|
||||||
|
|
||||||
private boolean togglePlayers;
|
private boolean togglePlayers;
|
||||||
@@ -61,6 +61,9 @@ public class DevTools extends Plugin
|
|||||||
@Override
|
@Override
|
||||||
protected void startUp() throws Exception
|
protected void startUp() throws Exception
|
||||||
{
|
{
|
||||||
|
panel = new DevToolsPanel(this);
|
||||||
|
navButton = new NavigationButton("DevTools");
|
||||||
|
|
||||||
navButton.getButton().addActionListener(this::setPluginPanel);
|
navButton.getButton().addActionListener(this::setPluginPanel);
|
||||||
|
|
||||||
ImageIcon icon = new ImageIcon(ImageIO.read(getClass().getResourceAsStream("devtools_icon.png")));
|
ImageIcon icon = new ImageIcon(ImageIO.read(getClass().getResourceAsStream("devtools_icon.png")));
|
||||||
|
|||||||
@@ -46,12 +46,15 @@ public class Hiscore extends Plugin
|
|||||||
private final RuneLite runeLite = RuneLite.getRunelite();
|
private final RuneLite runeLite = RuneLite.getRunelite();
|
||||||
private final ClientUI ui = runeLite.getGui();
|
private final ClientUI ui = runeLite.getGui();
|
||||||
|
|
||||||
private final NavigationButton navButton = new NavigationButton("Hiscore");
|
private NavigationButton navButton;
|
||||||
private final HiscorePanel hiscorePanel = new HiscorePanel(runeLite);
|
private HiscorePanel hiscorePanel;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void startUp() throws Exception
|
protected void startUp() throws Exception
|
||||||
{
|
{
|
||||||
|
navButton = new NavigationButton("Hiscore");
|
||||||
|
hiscorePanel = new HiscorePanel(runeLite);
|
||||||
|
|
||||||
navButton.getButton().addActionListener(this::setPluginPanel);
|
navButton.getButton().addActionListener(this::setPluginPanel);
|
||||||
|
|
||||||
ImageIcon icon = new ImageIcon(ImageIO.read(getClass().getResourceAsStream("hiscore.gif")));
|
ImageIcon icon = new ImageIcon(ImageIO.read(getClass().getResourceAsStream("hiscore.gif")));
|
||||||
|
|||||||
@@ -48,10 +48,37 @@ public class XPTracker extends Plugin
|
|||||||
private final ClientUI ui = runeLite.getGui();
|
private final ClientUI ui = runeLite.getGui();
|
||||||
private final Client client = RuneLite.getClient();
|
private final Client client = RuneLite.getClient();
|
||||||
|
|
||||||
private final NavigationButton navButton = new NavigationButton("XP Tracker");
|
private NavigationButton navButton;
|
||||||
private final XPPanel xpPanel = new XPPanel(runeLite, this);
|
private XPPanel xpPanel;
|
||||||
private final SkillXPInfo[] xpInfos = new SkillXPInfo[NUMBER_OF_SKILLS];
|
private final SkillXPInfo[] xpInfos = new SkillXPInfo[NUMBER_OF_SKILLS];
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void startUp() throws Exception
|
||||||
|
{
|
||||||
|
navButton = new NavigationButton("XP Tracker");
|
||||||
|
xpPanel = new XPPanel(runeLite, this);
|
||||||
|
|
||||||
|
navButton.getButton().addActionListener(this::setPluginPanel);
|
||||||
|
|
||||||
|
navButton.getButton().setText("XP");
|
||||||
|
ui.getNavigationPanel().addNavigation(navButton);
|
||||||
|
|
||||||
|
Font font = Font.createFont(Font.TRUETYPE_FONT, getClass().getResourceAsStream("/runescape.ttf"));
|
||||||
|
font = font.deriveFont(Font.BOLD, 16);
|
||||||
|
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||||
|
ge.registerFont(font);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void shutDown() throws Exception
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setPluginPanel(ActionEvent e)
|
||||||
|
{
|
||||||
|
ui.expand(xpPanel);
|
||||||
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onGameStateChanged(GameStateChanged event)
|
public void onGameStateChanged(GameStateChanged event)
|
||||||
{
|
{
|
||||||
@@ -80,30 +107,6 @@ public class XPTracker extends Plugin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setPluginPanel(ActionEvent e)
|
|
||||||
{
|
|
||||||
ui.expand(xpPanel);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void startUp() throws Exception
|
|
||||||
{
|
|
||||||
navButton.getButton().addActionListener(this::setPluginPanel);
|
|
||||||
|
|
||||||
navButton.getButton().setText("XP");
|
|
||||||
ui.getNavigationPanel().addNavigation(navButton);
|
|
||||||
|
|
||||||
Font font = Font.createFont(Font.TRUETYPE_FONT, getClass().getResourceAsStream("/runescape.ttf"));
|
|
||||||
font = font.deriveFont(Font.BOLD, 16);
|
|
||||||
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
|
||||||
ge.registerFont(font);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void shutDown() throws Exception
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
@Schedule(
|
@Schedule(
|
||||||
period = 600,
|
period = 600,
|
||||||
unit = ChronoUnit.MILLIS
|
unit = ChronoUnit.MILLIS
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import java.applet.Applet;
|
|||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.BorderLayout;
|
import java.awt.BorderLayout;
|
||||||
|
import java.io.IOException;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import net.runelite.api.Client;
|
import net.runelite.api.Client;
|
||||||
import net.runelite.client.ClientLoader;
|
import net.runelite.client.ClientLoader;
|
||||||
@@ -44,19 +45,17 @@ final class ClientPanel extends JPanel
|
|||||||
|
|
||||||
private Applet rs;
|
private Applet rs;
|
||||||
|
|
||||||
public ClientPanel(boolean loadRs) throws Exception
|
public ClientPanel()
|
||||||
{
|
{
|
||||||
setSize(new Dimension(PANEL_WIDTH, PANEL_HEIGHT));
|
setSize(new Dimension(PANEL_WIDTH, PANEL_HEIGHT));
|
||||||
setMinimumSize(new Dimension(PANEL_WIDTH, PANEL_HEIGHT));
|
setMinimumSize(new Dimension(PANEL_WIDTH, PANEL_HEIGHT));
|
||||||
setPreferredSize(new Dimension(PANEL_WIDTH, PANEL_HEIGHT));
|
setPreferredSize(new Dimension(PANEL_WIDTH, PANEL_HEIGHT));
|
||||||
setLayout(new BorderLayout());
|
setLayout(new BorderLayout());
|
||||||
setBackground(Color.black);
|
setBackground(Color.black);
|
||||||
|
}
|
||||||
|
|
||||||
if (!loadRs)
|
public void loadRs() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException
|
||||||
{
|
{
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ClientLoader loader = new ClientLoader();
|
ClientLoader loader = new ClientLoader();
|
||||||
|
|
||||||
UpdateCheckClient updateCheck = new UpdateCheckClient();
|
UpdateCheckClient updateCheck = new UpdateCheckClient();
|
||||||
|
|||||||
@@ -28,19 +28,22 @@ import java.awt.BorderLayout;
|
|||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.event.WindowAdapter;
|
import java.awt.event.WindowAdapter;
|
||||||
import java.awt.event.WindowEvent;
|
import java.awt.event.WindowEvent;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.JPopupMenu;
|
import javax.swing.SwingUtilities;
|
||||||
import javax.swing.UIManager;
|
|
||||||
import javax.swing.UnsupportedLookAndFeelException;
|
|
||||||
import net.runelite.api.Client;
|
import net.runelite.api.Client;
|
||||||
import net.runelite.api.GameState;
|
import net.runelite.api.GameState;
|
||||||
import net.runelite.client.RuneLite;
|
import net.runelite.client.RuneLite;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
public final class ClientUI extends JFrame
|
public final class ClientUI extends JFrame
|
||||||
{
|
{
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(ClientUI.class);
|
||||||
|
|
||||||
private static final int PANEL_WIDTH = 805;
|
private static final int PANEL_WIDTH = 805;
|
||||||
private static final int PANEL_HEIGHT = 541;
|
private static final int PANEL_HEIGHT = 541;
|
||||||
private static final int EXPANDED_WIDTH = PANEL_WIDTH + PluginPanel.PANEL_WIDTH;
|
private static final int EXPANDED_WIDTH = PANEL_WIDTH + PluginPanel.PANEL_WIDTH;
|
||||||
@@ -51,7 +54,7 @@ public final class ClientUI extends JFrame
|
|||||||
private NavigationPanel navigationPanel;
|
private NavigationPanel navigationPanel;
|
||||||
private PluginPanel pluginPanel;
|
private PluginPanel pluginPanel;
|
||||||
|
|
||||||
public ClientUI() throws Exception
|
public ClientUI()
|
||||||
{
|
{
|
||||||
init();
|
init();
|
||||||
pack();
|
pack();
|
||||||
@@ -62,8 +65,10 @@ public final class ClientUI extends JFrame
|
|||||||
setVisible(true);
|
setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void init() throws Exception
|
private void init()
|
||||||
{
|
{
|
||||||
|
assert SwingUtilities.isEventDispatchThread();
|
||||||
|
|
||||||
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
|
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
|
||||||
setMinimumSize(new Dimension(PANEL_WIDTH, PANEL_HEIGHT));
|
setMinimumSize(new Dimension(PANEL_WIDTH, PANEL_HEIGHT));
|
||||||
|
|
||||||
@@ -76,19 +81,21 @@ public final class ClientUI extends JFrame
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
JPopupMenu.setDefaultLightWeightPopupEnabled(false);
|
|
||||||
try
|
|
||||||
{
|
|
||||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
|
||||||
}
|
|
||||||
catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ignored)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
container = new JPanel();
|
container = new JPanel();
|
||||||
container.setLayout(new BorderLayout(0, 0));
|
container.setLayout(new BorderLayout(0, 0));
|
||||||
|
|
||||||
panel = new ClientPanel(!RuneLite.getOptions().has("no-rs"));
|
panel = new ClientPanel();
|
||||||
|
if (!RuneLite.getOptions().has("no-rs"))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
panel.loadRs();
|
||||||
|
}
|
||||||
|
catch (IOException | ClassNotFoundException | InstantiationException | IllegalAccessException ex)
|
||||||
|
{
|
||||||
|
logger.warn("Error loading RS!", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
container.add(panel, BorderLayout.CENTER);
|
container.add(panel, BorderLayout.CENTER);
|
||||||
|
|
||||||
navContainer = new JPanel();
|
navContainer = new JPanel();
|
||||||
|
|||||||
Reference in New Issue
Block a user