Remove the need to extend JFrame in ClientUI
- Make ClientUI wrap JFrame inside - Do not make RuneLite class depend on Swing API at all - Create ClientUI through Guice - Simplify initialization and showing of UI Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
This commit is contained in:
@@ -35,7 +35,6 @@ import java.applet.Applet;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
import javax.swing.SwingUtilities;
|
|
||||||
import joptsimple.OptionParser;
|
import joptsimple.OptionParser;
|
||||||
import joptsimple.OptionSet;
|
import joptsimple.OptionSet;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@@ -43,9 +42,7 @@ import net.runelite.api.Client;
|
|||||||
import net.runelite.client.account.SessionManager;
|
import net.runelite.client.account.SessionManager;
|
||||||
import net.runelite.client.chat.ChatMessageManager;
|
import net.runelite.client.chat.ChatMessageManager;
|
||||||
import net.runelite.client.config.ConfigManager;
|
import net.runelite.client.config.ConfigManager;
|
||||||
import net.runelite.client.config.RuneLiteConfig;
|
|
||||||
import net.runelite.client.discord.DiscordService;
|
import net.runelite.client.discord.DiscordService;
|
||||||
import net.runelite.client.events.ClientUILoaded;
|
|
||||||
import net.runelite.client.menus.MenuManager;
|
import net.runelite.client.menus.MenuManager;
|
||||||
import net.runelite.client.plugins.PluginManager;
|
import net.runelite.client.plugins.PluginManager;
|
||||||
import net.runelite.client.ui.ClientUI;
|
import net.runelite.client.ui.ClientUI;
|
||||||
@@ -66,9 +63,6 @@ public class RuneLite
|
|||||||
private static Injector injector;
|
private static Injector injector;
|
||||||
private static OptionSet options;
|
private static OptionSet options;
|
||||||
|
|
||||||
@Inject
|
|
||||||
private RuneLiteProperties properties;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private PluginManager pluginManager;
|
private PluginManager pluginManager;
|
||||||
|
|
||||||
@@ -90,17 +84,16 @@ public class RuneLite
|
|||||||
@Inject
|
@Inject
|
||||||
private SessionManager sessionManager;
|
private SessionManager sessionManager;
|
||||||
|
|
||||||
@Inject
|
|
||||||
private RuneLiteConfig runeliteConfig;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private DiscordService discordService;
|
private DiscordService discordService;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private ClientSessionManager clientSessionManager;
|
private ClientSessionManager clientSessionManager;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private ClientUI clientUI;
|
||||||
|
|
||||||
Client client;
|
Client client;
|
||||||
ClientUI gui;
|
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception
|
public static void main(String[] args) throws Exception
|
||||||
{
|
{
|
||||||
@@ -147,8 +140,8 @@ public class RuneLite
|
|||||||
this.client = (Client) client;
|
this.client = (Client) client;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load swing UI
|
// Initialize UI
|
||||||
SwingUtilities.invokeAndWait(() -> setGui(ClientUI.create(this, properties, client)));
|
clientUI.init(client);
|
||||||
|
|
||||||
// Initialize Discord service
|
// Initialize Discord service
|
||||||
discordService.init();
|
discordService.init();
|
||||||
@@ -157,10 +150,10 @@ public class RuneLite
|
|||||||
configManager.load();
|
configManager.load();
|
||||||
|
|
||||||
// Register event listeners
|
// Register event listeners
|
||||||
|
eventBus.register(clientUI);
|
||||||
eventBus.register(overlayRenderer);
|
eventBus.register(overlayRenderer);
|
||||||
eventBus.register(menuManager);
|
eventBus.register(menuManager);
|
||||||
eventBus.register(chatMessageManager);
|
eventBus.register(chatMessageManager);
|
||||||
eventBus.register(gui);
|
|
||||||
eventBus.register(pluginManager);
|
eventBus.register(pluginManager);
|
||||||
|
|
||||||
// Tell the plugin manager if client is outdated or not
|
// Tell the plugin manager if client is outdated or not
|
||||||
@@ -183,28 +176,8 @@ public class RuneLite
|
|||||||
// Load the session, including saved configuration
|
// Load the session, including saved configuration
|
||||||
sessionManager.loadSession();
|
sessionManager.loadSession();
|
||||||
|
|
||||||
SwingUtilities.invokeAndWait(() ->
|
// Show UI after all plugins are loaded
|
||||||
{
|
clientUI.show();
|
||||||
if (client != null)
|
|
||||||
{
|
|
||||||
client.setSize(runeliteConfig.gameSize());
|
|
||||||
client.setPreferredSize(runeliteConfig.gameSize());
|
|
||||||
|
|
||||||
client.getParent().setPreferredSize(runeliteConfig.gameSize());
|
|
||||||
client.getParent().setSize(runeliteConfig.gameSize());
|
|
||||||
}
|
|
||||||
|
|
||||||
gui.showWithChrome(runeliteConfig.enableCustomChrome());
|
|
||||||
|
|
||||||
if (gui.isAlwaysOnTopSupported())
|
|
||||||
{
|
|
||||||
gui.setAlwaysOnTop(runeliteConfig.gameAlwaysOnTop());
|
|
||||||
}
|
|
||||||
|
|
||||||
gui.setResizable(!runeliteConfig.lockWindowSize());
|
|
||||||
});
|
|
||||||
|
|
||||||
eventBus.post(new ClientUILoaded());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void shutdown()
|
public void shutdown()
|
||||||
@@ -213,11 +186,6 @@ public class RuneLite
|
|||||||
discordService.close();
|
discordService.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setGui(ClientUI gui)
|
|
||||||
{
|
|
||||||
this.gui = gui;
|
|
||||||
}
|
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public void setClient(Client client)
|
public void setClient(Client client)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -41,7 +41,6 @@ import net.runelite.client.game.ItemManager;
|
|||||||
import net.runelite.client.menus.MenuManager;
|
import net.runelite.client.menus.MenuManager;
|
||||||
import net.runelite.client.plugins.PluginManager;
|
import net.runelite.client.plugins.PluginManager;
|
||||||
import net.runelite.client.task.Scheduler;
|
import net.runelite.client.task.Scheduler;
|
||||||
import net.runelite.client.ui.ClientUI;
|
|
||||||
import net.runelite.client.util.QueryRunner;
|
import net.runelite.client.util.QueryRunner;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@@ -67,12 +66,6 @@ public class RuneLiteModule extends AbstractModule
|
|||||||
return runeLite.client;
|
return runeLite.client;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
|
||||||
ClientUI provideClientUi(RuneLite runelite)
|
|
||||||
{
|
|
||||||
return runelite.gui;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
RuneLiteConfig provideConfig(ConfigManager configManager)
|
RuneLiteConfig provideConfig(ConfigManager configManager)
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
*/
|
*/
|
||||||
package net.runelite.client.ui;
|
package net.runelite.client.ui;
|
||||||
|
|
||||||
|
import com.google.common.eventbus.EventBus;
|
||||||
import com.google.common.eventbus.Subscribe;
|
import com.google.common.eventbus.Subscribe;
|
||||||
import java.applet.Applet;
|
import java.applet.Applet;
|
||||||
import java.awt.BorderLayout;
|
import java.awt.BorderLayout;
|
||||||
@@ -32,12 +33,16 @@ import java.awt.Component;
|
|||||||
import java.awt.Container;
|
import java.awt.Container;
|
||||||
import java.awt.Cursor;
|
import java.awt.Cursor;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
|
import java.awt.Graphics;
|
||||||
import java.awt.LayoutManager;
|
import java.awt.LayoutManager;
|
||||||
import java.awt.Toolkit;
|
import java.awt.Toolkit;
|
||||||
import java.awt.TrayIcon;
|
import java.awt.TrayIcon;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Singleton;
|
||||||
import javax.swing.BoxLayout;
|
import javax.swing.BoxLayout;
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
@@ -51,6 +56,8 @@ import net.runelite.api.GameState;
|
|||||||
import net.runelite.api.events.ConfigChanged;
|
import net.runelite.api.events.ConfigChanged;
|
||||||
import net.runelite.client.RuneLite;
|
import net.runelite.client.RuneLite;
|
||||||
import net.runelite.client.RuneLiteProperties;
|
import net.runelite.client.RuneLiteProperties;
|
||||||
|
import net.runelite.client.config.RuneLiteConfig;
|
||||||
|
import net.runelite.client.events.ClientUILoaded;
|
||||||
import net.runelite.client.util.OSType;
|
import net.runelite.client.util.OSType;
|
||||||
import net.runelite.client.util.OSXUtil;
|
import net.runelite.client.util.OSXUtil;
|
||||||
import net.runelite.client.util.SwingUtil;
|
import net.runelite.client.util.SwingUtil;
|
||||||
@@ -58,25 +65,16 @@ import org.pushingpixels.substance.api.skin.SubstanceGraphiteLookAndFeel;
|
|||||||
import org.pushingpixels.substance.internal.utils.SubstanceCoreUtilities;
|
import org.pushingpixels.substance.internal.utils.SubstanceCoreUtilities;
|
||||||
import org.pushingpixels.substance.internal.utils.SubstanceTitlePaneUtilities;
|
import org.pushingpixels.substance.internal.utils.SubstanceTitlePaneUtilities;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Client UI.
|
||||||
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class ClientUI extends JFrame
|
@Singleton
|
||||||
|
public class ClientUI
|
||||||
{
|
{
|
||||||
private static final int PANEL_EXPANDED_WIDTH = PluginPanel.PANEL_WIDTH + PluginPanel.SCROLLBAR_WIDTH;
|
private static final int PANEL_EXPANDED_WIDTH = PluginPanel.PANEL_WIDTH + PluginPanel.SCROLLBAR_WIDTH;
|
||||||
public static final BufferedImage ICON;
|
public static final BufferedImage ICON;
|
||||||
|
|
||||||
@Getter
|
|
||||||
private TrayIcon trayIcon;
|
|
||||||
|
|
||||||
private final RuneLite runelite;
|
|
||||||
private final Applet client;
|
|
||||||
private final RuneLiteProperties properties;
|
|
||||||
private JPanel navContainer;
|
|
||||||
private PluginToolbar pluginToolbar;
|
|
||||||
private PluginPanel pluginPanel;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
private TitleToolbar titleToolbar;
|
|
||||||
|
|
||||||
static
|
static
|
||||||
{
|
{
|
||||||
BufferedImage icon = null;
|
BufferedImage icon = null;
|
||||||
@@ -96,115 +94,42 @@ public class ClientUI extends JFrame
|
|||||||
ICON = icon;
|
ICON = icon;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ClientUI create(RuneLite runelite, RuneLiteProperties properties, Applet client)
|
@Getter
|
||||||
{
|
private TrayIcon trayIcon;
|
||||||
// Set some sensible swing defaults
|
|
||||||
SwingUtil.setupDefaults();
|
|
||||||
|
|
||||||
// Use substance look and feel
|
@Getter
|
||||||
SwingUtil.setTheme(new SubstanceGraphiteLookAndFeel());
|
private PluginToolbar pluginToolbar;
|
||||||
|
|
||||||
// Use custom UI font
|
@Getter
|
||||||
SwingUtil.setFont(FontManager.getRunescapeFont());
|
private TitleToolbar titleToolbar;
|
||||||
|
|
||||||
final ClientUI gui = new ClientUI(runelite, properties, client);
|
private final RuneLite runelite;
|
||||||
|
private final RuneLiteProperties properties;
|
||||||
|
private final RuneLiteConfig config;
|
||||||
|
private final EventBus eventBus;
|
||||||
|
private Applet client;
|
||||||
|
private JFrame frame;
|
||||||
|
private JPanel navContainer;
|
||||||
|
private PluginPanel pluginPanel;
|
||||||
|
|
||||||
// Try to enable fullscreen on OSX
|
@Inject
|
||||||
OSXUtil.tryEnableFullscreen(gui);
|
private ClientUI(
|
||||||
|
RuneLite runelite,
|
||||||
return gui;
|
RuneLiteProperties properties,
|
||||||
}
|
RuneLiteConfig config,
|
||||||
|
EventBus eventBus)
|
||||||
private ClientUI(RuneLite runelite, RuneLiteProperties properties, Applet client)
|
|
||||||
{
|
{
|
||||||
this.runelite = runelite;
|
this.runelite = runelite;
|
||||||
this.properties = properties;
|
this.properties = properties;
|
||||||
this.client = client;
|
this.config = config;
|
||||||
this.trayIcon = SwingUtil.createTrayIcon(ICON, properties.getTitle(), this);
|
this.eventBus = eventBus;
|
||||||
|
|
||||||
init();
|
|
||||||
setTitle(properties.getTitle());
|
|
||||||
setIconImage(ICON);
|
|
||||||
// Prevent substance from using a resize cursor for pointing
|
|
||||||
getLayeredPane().setCursor(Cursor.getDefaultCursor());
|
|
||||||
setLocationRelativeTo(getOwner());
|
|
||||||
setResizable(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void showWithChrome(boolean customChrome)
|
|
||||||
{
|
|
||||||
setUndecorated(customChrome);
|
|
||||||
|
|
||||||
if (customChrome)
|
|
||||||
{
|
|
||||||
getRootPane().setWindowDecorationStyle(JRootPane.FRAME);
|
|
||||||
|
|
||||||
JComponent titleBar = SubstanceCoreUtilities.getTitlePaneComponent(this);
|
|
||||||
titleToolbar.putClientProperty(SubstanceTitlePaneUtilities.EXTRA_COMPONENT_KIND, SubstanceTitlePaneUtilities.ExtraComponentKind.TRAILING);
|
|
||||||
titleBar.add(titleToolbar);
|
|
||||||
|
|
||||||
// Substance's default layout manager for the title bar only lays out substance's components
|
|
||||||
// This wraps the default manager and lays out the TitleToolbar as well.
|
|
||||||
LayoutManager delegate = titleBar.getLayout();
|
|
||||||
titleBar.setLayout(new LayoutManager()
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public void addLayoutComponent(String name, Component comp)
|
|
||||||
{
|
|
||||||
delegate.addLayoutComponent(name, comp);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void removeLayoutComponent(Component comp)
|
|
||||||
{
|
|
||||||
delegate.removeLayoutComponent(comp);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Dimension preferredLayoutSize(Container parent)
|
|
||||||
{
|
|
||||||
return delegate.preferredLayoutSize(parent);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Dimension minimumLayoutSize(Container parent)
|
|
||||||
{
|
|
||||||
return delegate.minimumLayoutSize(parent);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void layoutContainer(Container parent)
|
|
||||||
{
|
|
||||||
delegate.layoutContainer(parent);
|
|
||||||
final int width = titleToolbar.getPreferredSize().width;
|
|
||||||
titleToolbar.setBounds(titleBar.getWidth() - 75 - width, 0, width, titleBar.getHeight());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
pack();
|
|
||||||
revalidateMinimumSize();
|
|
||||||
setLocationRelativeTo(getOwner());
|
|
||||||
|
|
||||||
setVisible(true);
|
|
||||||
toFront();
|
|
||||||
requestFocus();
|
|
||||||
giveClientFocus();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void giveClientFocus()
|
|
||||||
{
|
|
||||||
if (client instanceof Client)
|
|
||||||
{
|
|
||||||
final Canvas c = ((Client) client).getCanvas();
|
|
||||||
c.requestFocusInWindow();
|
|
||||||
}
|
|
||||||
else if (client != null)
|
|
||||||
{
|
|
||||||
client.requestFocusInWindow();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* On config changed.
|
||||||
|
*
|
||||||
|
* @param event the event
|
||||||
|
*/
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onConfigChanged(ConfigChanged event)
|
public void onConfigChanged(ConfigChanged event)
|
||||||
{
|
{
|
||||||
@@ -213,91 +138,235 @@ public class ClientUI extends JFrame
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.getKey().equals("gameAlwaysOnTop"))
|
|
||||||
{
|
|
||||||
if (this.isAlwaysOnTopSupported())
|
|
||||||
{
|
|
||||||
this.setAlwaysOnTop(Boolean.valueOf(event.getNewValue()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.getKey().equals("lockWindowSize"))
|
|
||||||
{
|
|
||||||
SwingUtilities.invokeLater(() -> setResizable(!Boolean.valueOf(event.getNewValue())));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!event.getKey().equals("gameSize"))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (client == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
String[] splitStr = event.getNewValue().split("x");
|
|
||||||
int width = Integer.parseInt(splitStr[0]);
|
|
||||||
int height = Integer.parseInt(splitStr[1]);
|
|
||||||
|
|
||||||
// The upper bounds are defined by the applet's max size
|
|
||||||
// The lower bounds are taken care of by ClientPanel's setMinimumSize
|
|
||||||
|
|
||||||
if (width > 7680)
|
|
||||||
{
|
|
||||||
width = 7680;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (height > 2160)
|
|
||||||
{
|
|
||||||
height = 2160;
|
|
||||||
}
|
|
||||||
|
|
||||||
Dimension size = new Dimension(width, height);
|
|
||||||
|
|
||||||
SwingUtilities.invokeLater(() ->
|
SwingUtilities.invokeLater(() ->
|
||||||
{
|
{
|
||||||
|
if (event.getKey().equals("gameAlwaysOnTop"))
|
||||||
|
{
|
||||||
|
if (frame.isAlwaysOnTopSupported())
|
||||||
|
{
|
||||||
|
frame.setAlwaysOnTop(config.gameAlwaysOnTop());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.getKey().equals("lockWindowSize"))
|
||||||
|
{
|
||||||
|
SwingUtilities.invokeLater(() -> frame.setResizable(!config.lockWindowSize()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!event.getKey().equals("gameSize"))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (client == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int width = config.gameSize().width;
|
||||||
|
int height = config.gameSize().height;
|
||||||
|
|
||||||
|
// The upper bounds are defined by the applet's max size
|
||||||
|
// The lower bounds are taken care of by ClientPanel's setMinimumSize
|
||||||
|
|
||||||
|
if (width > 7680)
|
||||||
|
{
|
||||||
|
width = 7680;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (height > 2160)
|
||||||
|
{
|
||||||
|
height = 2160;
|
||||||
|
}
|
||||||
|
|
||||||
|
final Dimension size = new Dimension(width, height);
|
||||||
|
|
||||||
client.setSize(size);
|
client.setSize(size);
|
||||||
client.setPreferredSize(size);
|
client.setPreferredSize(size);
|
||||||
|
|
||||||
client.getParent().setPreferredSize(size);
|
client.getParent().setPreferredSize(size);
|
||||||
client.getParent().setSize(size);
|
client.getParent().setSize(size);
|
||||||
|
|
||||||
if (isVisible())
|
if (frame.isVisible())
|
||||||
{
|
{
|
||||||
pack();
|
frame.pack();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void init()
|
/**
|
||||||
|
* Initialize UI.
|
||||||
|
*
|
||||||
|
* @param client the client
|
||||||
|
* @throws Exception exception that can occur during creation of the UI
|
||||||
|
*/
|
||||||
|
public void init(@Nullable final Applet client) throws Exception
|
||||||
{
|
{
|
||||||
assert SwingUtilities.isEventDispatchThread();
|
this.client = client;
|
||||||
|
|
||||||
SwingUtil.addGracefulExitCallback(this, runelite::shutdown,
|
SwingUtilities.invokeAndWait(() ->
|
||||||
() -> client != null
|
{
|
||||||
&& client instanceof Client
|
// Set some sensible swing defaults
|
||||||
&& ((Client) client).getGameState() != GameState.LOGIN_SCREEN);
|
SwingUtil.setupDefaults();
|
||||||
|
|
||||||
final JPanel container = new JPanel();
|
// Use substance look and feel
|
||||||
container.setLayout(new BoxLayout(container, BoxLayout.X_AXIS));
|
SwingUtil.setTheme(new SubstanceGraphiteLookAndFeel());
|
||||||
container.add(new ClientPanel(client));
|
|
||||||
|
|
||||||
navContainer = new JPanel();
|
// Use custom UI font
|
||||||
navContainer.setLayout(new BorderLayout(0, 0));
|
SwingUtil.setFont(FontManager.getRunescapeFont());
|
||||||
navContainer.setMinimumSize(new Dimension(0, 0));
|
|
||||||
navContainer.setMaximumSize(new Dimension(0, Integer.MAX_VALUE));
|
|
||||||
container.add(navContainer);
|
|
||||||
|
|
||||||
pluginToolbar = new PluginToolbar(this);
|
// Create main window
|
||||||
container.add(pluginToolbar);
|
frame = new JFrame();
|
||||||
|
|
||||||
titleToolbar = new TitleToolbar(properties);
|
// Try to enable fullscreen on OSX
|
||||||
|
OSXUtil.tryEnableFullscreen(frame);
|
||||||
|
|
||||||
add(container);
|
trayIcon = SwingUtil.createTrayIcon(ICON, properties.getTitle(), frame);
|
||||||
|
|
||||||
|
frame.setTitle(properties.getTitle());
|
||||||
|
frame.setIconImage(ICON);
|
||||||
|
frame.getLayeredPane().setCursor(Cursor.getDefaultCursor()); // Prevent substance from using a resize cursor for pointing
|
||||||
|
frame.setLocationRelativeTo(frame.getOwner());
|
||||||
|
frame.setResizable(true);
|
||||||
|
|
||||||
|
SwingUtil.addGracefulExitCallback(frame, runelite::shutdown,
|
||||||
|
() -> client != null
|
||||||
|
&& client instanceof Client
|
||||||
|
&& ((Client) client).getGameState() != GameState.LOGIN_SCREEN);
|
||||||
|
|
||||||
|
final JPanel container = new JPanel();
|
||||||
|
container.setLayout(new BoxLayout(container, BoxLayout.X_AXIS));
|
||||||
|
container.add(new ClientPanel(client));
|
||||||
|
|
||||||
|
navContainer = new JPanel();
|
||||||
|
navContainer.setLayout(new BorderLayout(0, 0));
|
||||||
|
navContainer.setMinimumSize(new Dimension(0, 0));
|
||||||
|
navContainer.setMaximumSize(new Dimension(0, Integer.MAX_VALUE));
|
||||||
|
container.add(navContainer);
|
||||||
|
|
||||||
|
pluginToolbar = new PluginToolbar(this);
|
||||||
|
container.add(pluginToolbar);
|
||||||
|
|
||||||
|
titleToolbar = new TitleToolbar(properties);
|
||||||
|
|
||||||
|
frame.add(container);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/**
|
||||||
|
* Show client UI after everything else is done.
|
||||||
|
*
|
||||||
|
* @throws Exception exception that can occur during modification of the UI
|
||||||
|
*/
|
||||||
|
public void show() throws Exception
|
||||||
|
{
|
||||||
|
final boolean withTitleBar = config.enableCustomChrome();
|
||||||
|
|
||||||
|
SwingUtilities.invokeAndWait(() ->
|
||||||
|
{
|
||||||
|
frame.setUndecorated(withTitleBar);
|
||||||
|
|
||||||
|
if (withTitleBar)
|
||||||
|
{
|
||||||
|
frame.getRootPane().setWindowDecorationStyle(JRootPane.FRAME);
|
||||||
|
|
||||||
|
JComponent titleBar = SubstanceCoreUtilities.getTitlePaneComponent(frame);
|
||||||
|
titleToolbar.putClientProperty(SubstanceTitlePaneUtilities.EXTRA_COMPONENT_KIND, SubstanceTitlePaneUtilities.ExtraComponentKind.TRAILING);
|
||||||
|
titleBar.add(titleToolbar);
|
||||||
|
|
||||||
|
// Substance's default layout manager for the title bar only lays out substance's components
|
||||||
|
// This wraps the default manager and lays out the TitleToolbar as well.
|
||||||
|
LayoutManager delegate = titleBar.getLayout();
|
||||||
|
titleBar.setLayout(new LayoutManager()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void addLayoutComponent(String name, Component comp)
|
||||||
|
{
|
||||||
|
delegate.addLayoutComponent(name, comp);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeLayoutComponent(Component comp)
|
||||||
|
{
|
||||||
|
delegate.removeLayoutComponent(comp);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Dimension preferredLayoutSize(Container parent)
|
||||||
|
{
|
||||||
|
return delegate.preferredLayoutSize(parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Dimension minimumLayoutSize(Container parent)
|
||||||
|
{
|
||||||
|
return delegate.minimumLayoutSize(parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void layoutContainer(Container parent)
|
||||||
|
{
|
||||||
|
delegate.layoutContainer(parent);
|
||||||
|
final int width = titleToolbar.getPreferredSize().width;
|
||||||
|
titleToolbar.setBounds(titleBar.getWidth() - 75 - width, 0, width, titleBar.getHeight());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
frame.pack();
|
||||||
|
SwingUtil.revalidateMinimumSize(frame);
|
||||||
|
frame.setLocationRelativeTo(frame.getOwner());
|
||||||
|
frame.setVisible(true);
|
||||||
|
frame.toFront();
|
||||||
|
requestFocus();
|
||||||
|
giveClientFocus();
|
||||||
|
});
|
||||||
|
|
||||||
|
eventBus.post(new ClientUILoaded());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Paint this component to target graphics
|
||||||
|
*
|
||||||
|
* @param graphics the graphics
|
||||||
|
*/
|
||||||
|
public void paint(final Graphics graphics)
|
||||||
|
{
|
||||||
|
frame.paint(graphics);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets component width.
|
||||||
|
*
|
||||||
|
* @return the width
|
||||||
|
*/
|
||||||
|
public int getWidth()
|
||||||
|
{
|
||||||
|
return frame.getWidth();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets component height.
|
||||||
|
*
|
||||||
|
* @return the height
|
||||||
|
*/
|
||||||
|
public int getHeight()
|
||||||
|
{
|
||||||
|
return frame.getHeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if this component has focus.
|
||||||
|
*
|
||||||
|
* @return true if component has focus
|
||||||
|
*/
|
||||||
|
public boolean isFocused()
|
||||||
|
{
|
||||||
|
return frame.isFocused();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request focus on this component and then on client component
|
||||||
|
*/
|
||||||
public void requestFocus()
|
public void requestFocus()
|
||||||
{
|
{
|
||||||
if (OSType.getOSType() == OSType.MacOS)
|
if (OSType.getOSType() == OSType.MacOS)
|
||||||
@@ -305,17 +374,16 @@ public class ClientUI extends JFrame
|
|||||||
OSXUtil.requestFocus();
|
OSXUtil.requestFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
super.requestFocus();
|
frame.requestFocus();
|
||||||
giveClientFocus();
|
giveClientFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void revalidateMinimumSize()
|
/**
|
||||||
{
|
* Expand panel.
|
||||||
// The JFrame only respects minimumSize if it was set by setMinimumSize, for some reason. (atleast on windows/native)
|
*
|
||||||
this.setMinimumSize(this.getLayout().minimumLayoutSize(this));
|
* @param panel the panel
|
||||||
}
|
*/
|
||||||
|
public void expand(PluginPanel panel)
|
||||||
void expand(PluginPanel panel)
|
|
||||||
{
|
{
|
||||||
if (pluginPanel != null)
|
if (pluginPanel != null)
|
||||||
{
|
{
|
||||||
@@ -324,10 +392,10 @@ public class ClientUI extends JFrame
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (SwingUtil.isInScreenBounds(
|
if (SwingUtil.isInScreenBounds(
|
||||||
getLocationOnScreen().y + getWidth() + PANEL_EXPANDED_WIDTH,
|
frame.getLocationOnScreen().y + frame.getWidth() + PANEL_EXPANDED_WIDTH,
|
||||||
getLocationOnScreen().y))
|
frame.getLocationOnScreen().y))
|
||||||
{
|
{
|
||||||
this.setSize(getWidth() + PANEL_EXPANDED_WIDTH, getHeight());
|
frame.setSize(frame.getWidth() + PANEL_EXPANDED_WIDTH, frame.getHeight());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -344,34 +412,45 @@ public class ClientUI extends JFrame
|
|||||||
panel.onActivate();
|
panel.onActivate();
|
||||||
|
|
||||||
wrappedPanel.repaint();
|
wrappedPanel.repaint();
|
||||||
revalidateMinimumSize();
|
SwingUtil.revalidateMinimumSize(frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
void contract()
|
/**
|
||||||
|
* Contract. panel.
|
||||||
|
*/
|
||||||
|
public void contract()
|
||||||
{
|
{
|
||||||
boolean wasMinimumWidth = this.getWidth() == (int) this.getMinimumSize().getWidth();
|
boolean wasMinimumWidth = frame.getWidth() == frame.getMinimumSize().width;
|
||||||
pluginPanel.onDeactivate();
|
pluginPanel.onDeactivate();
|
||||||
navContainer.remove(0);
|
navContainer.remove(0);
|
||||||
navContainer.setMinimumSize(new Dimension(0, 0));
|
navContainer.setMinimumSize(new Dimension(0, 0));
|
||||||
navContainer.setMaximumSize(new Dimension(0, Integer.MAX_VALUE));
|
navContainer.setMaximumSize(new Dimension(0, 0));
|
||||||
navContainer.revalidate();
|
navContainer.revalidate();
|
||||||
giveClientFocus();
|
giveClientFocus();
|
||||||
revalidateMinimumSize();
|
SwingUtil.revalidateMinimumSize(frame);
|
||||||
|
|
||||||
if (wasMinimumWidth)
|
if (wasMinimumWidth)
|
||||||
{
|
{
|
||||||
this.setSize((int) this.getMinimumSize().getWidth(), getHeight());
|
frame.setSize(frame.getMinimumSize().width, frame.getHeight());
|
||||||
}
|
}
|
||||||
else if (getWidth() < Toolkit.getDefaultToolkit().getScreenSize().getWidth())
|
else if (frame.getWidth() < Toolkit.getDefaultToolkit().getScreenSize().getWidth())
|
||||||
{
|
{
|
||||||
this.setSize(getWidth() - PANEL_EXPANDED_WIDTH, getHeight());
|
frame.setSize(frame.getWidth() - PANEL_EXPANDED_WIDTH, frame.getHeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
pluginPanel = null;
|
pluginPanel = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PluginToolbar getPluginToolbar()
|
private void giveClientFocus()
|
||||||
{
|
{
|
||||||
return pluginToolbar;
|
if (client instanceof Client)
|
||||||
|
{
|
||||||
|
final Canvas c = ((Client) client).getCanvas();
|
||||||
|
c.requestFocusInWindow();
|
||||||
|
}
|
||||||
|
else if (client != null)
|
||||||
|
{
|
||||||
|
client.requestFocusInWindow();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,7 +45,6 @@ import joptsimple.OptionSet;
|
|||||||
import net.runelite.api.Client;
|
import net.runelite.api.Client;
|
||||||
import net.runelite.client.RuneLite;
|
import net.runelite.client.RuneLite;
|
||||||
import net.runelite.client.RuneLiteModule;
|
import net.runelite.client.RuneLiteModule;
|
||||||
import net.runelite.client.ui.ClientUI;
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
@@ -67,9 +66,6 @@ public class PluginManagerTest
|
|||||||
private RuneLite runelite;
|
private RuneLite runelite;
|
||||||
private Set<Class> pluginClasses;
|
private Set<Class> pluginClasses;
|
||||||
|
|
||||||
@Mock
|
|
||||||
ClientUI clientUi;
|
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
Client client;
|
Client client;
|
||||||
|
|
||||||
@@ -83,7 +79,6 @@ public class PluginManagerTest
|
|||||||
RuneLite.setInjector(injector);
|
RuneLite.setInjector(injector);
|
||||||
|
|
||||||
runelite = injector.getInstance(RuneLite.class);
|
runelite = injector.getInstance(RuneLite.class);
|
||||||
runelite.setGui(clientUi);
|
|
||||||
|
|
||||||
// Find plugins we expect to have
|
// Find plugins we expect to have
|
||||||
pluginClasses = new HashSet<>();
|
pluginClasses = new HashSet<>();
|
||||||
|
|||||||
Reference in New Issue
Block a user