Move creation of UI to ClientUI class
- Move setting of UI-related variables to ClientUI class (create new "create" static method to set them before creating the UI window) - Clean up ClientUI class Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
This commit is contained in:
@@ -33,12 +33,7 @@ import java.io.File;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import javax.inject.Singleton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPopupMenu;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.ToolTipManager;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.UnsupportedLookAndFeelException;
|
||||
import joptsimple.OptionParser;
|
||||
import joptsimple.OptionSet;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -50,7 +45,6 @@ import net.runelite.client.menus.MenuManager;
|
||||
import net.runelite.client.plugins.PluginManager;
|
||||
import net.runelite.client.ui.ClientUI;
|
||||
import net.runelite.client.ui.overlay.OverlayRenderer;
|
||||
import org.pushingpixels.substance.api.skin.SubstanceGraphiteLookAndFeel;
|
||||
|
||||
@Singleton
|
||||
@Slf4j
|
||||
@@ -96,15 +90,6 @@ public class RuneLite
|
||||
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
// Force heavy-weight popups/tooltips.
|
||||
// Prevents them from being obscured by the game applet.
|
||||
ToolTipManager.sharedInstance().setLightWeightPopupEnabled(false);
|
||||
// Do not render shadows under popups/tooltips.
|
||||
// Fixes black boxes under popups that are above the game applet.
|
||||
System.setProperty("jgoodies.popupDropShadowEnabled", "false");
|
||||
// Do not fill in background on repaint. Reduces flickering when
|
||||
// the applet is resized.
|
||||
System.setProperty("sun.awt.noerasebackground", "true");
|
||||
|
||||
OptionParser parser = new OptionParser();
|
||||
parser.accepts("developer-mode");
|
||||
@@ -139,25 +124,13 @@ public class RuneLite
|
||||
this.client = (Client) client;
|
||||
}
|
||||
|
||||
SwingUtilities.invokeAndWait(() ->
|
||||
{
|
||||
JFrame.setDefaultLookAndFeelDecorated(true);
|
||||
JPopupMenu.setDefaultLightWeightPopupEnabled(false);
|
||||
|
||||
try
|
||||
{
|
||||
UIManager.setLookAndFeel(new SubstanceGraphiteLookAndFeel());
|
||||
}
|
||||
catch (UnsupportedLookAndFeelException ex)
|
||||
{
|
||||
log.warn("unable to set look and feel", ex);
|
||||
}
|
||||
|
||||
setGui(new ClientUI(properties, client));
|
||||
});
|
||||
// Load swing UI
|
||||
SwingUtilities.invokeAndWait(() -> setGui(ClientUI.create(properties, client)));
|
||||
|
||||
// Load default configuration
|
||||
configManager.load();
|
||||
|
||||
// Register event listeners
|
||||
eventBus.register(overlayRenderer);
|
||||
eventBus.register(menuManager);
|
||||
eventBus.register(chatMessageManager);
|
||||
|
||||
@@ -24,8 +24,8 @@
|
||||
*/
|
||||
package net.runelite.client.ui;
|
||||
|
||||
import java.applet.Applet;
|
||||
import com.google.common.base.Strings;
|
||||
import java.applet.Applet;
|
||||
import java.awt.AWTException;
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Dimension;
|
||||
@@ -43,17 +43,20 @@ import javax.imageio.ImageIO;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JPopupMenu;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.ScrollPaneConstants;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.ToolTipManager;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.UnsupportedLookAndFeelException;
|
||||
import javax.swing.plaf.FontUIResource;
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.GameState;
|
||||
import net.runelite.client.RuneLite;
|
||||
import net.runelite.client.RuneliteProperties;
|
||||
import org.pushingpixels.substance.api.skin.SubstanceGraphiteLookAndFeel;
|
||||
import org.pushingpixels.substance.internal.ui.SubstanceRootPaneUI;
|
||||
|
||||
@Slf4j
|
||||
@@ -62,6 +65,7 @@ public class ClientUI extends JFrame
|
||||
private static final int CLIENT_WIDTH = 809;
|
||||
private static final int SCROLLBAR_WIDTH = 17;
|
||||
private static final int EXPANDED_WIDTH = CLIENT_WIDTH + PluginPanel.PANEL_WIDTH + SCROLLBAR_WIDTH;
|
||||
private static final BufferedImage ICON;
|
||||
|
||||
@Getter
|
||||
private TrayIcon trayIcon;
|
||||
@@ -70,23 +74,70 @@ public class ClientUI extends JFrame
|
||||
private final RuneliteProperties properties;
|
||||
private JPanel container;
|
||||
private JPanel navContainer;
|
||||
private ClientPanel panel;
|
||||
private PluginToolbar pluginToolbar;
|
||||
private PluginPanel pluginPanel;
|
||||
private BufferedImage icon;
|
||||
|
||||
public ClientUI(RuneliteProperties properties, Applet client)
|
||||
static
|
||||
{
|
||||
BufferedImage icon = null;
|
||||
|
||||
try
|
||||
{
|
||||
icon = ImageIO.read(ClientUI.class.getResourceAsStream("/runelite.png"));
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
log.warn("Client icon failed to load", e);
|
||||
}
|
||||
|
||||
ICON = icon;
|
||||
}
|
||||
|
||||
public static ClientUI create(RuneliteProperties properties, Applet client)
|
||||
{
|
||||
// Force heavy-weight popups/tooltips.
|
||||
// Prevents them from being obscured by the game applet.
|
||||
ToolTipManager.sharedInstance().setLightWeightPopupEnabled(false);
|
||||
JPopupMenu.setDefaultLightWeightPopupEnabled(false);
|
||||
|
||||
// Do not render shadows under popups/tooltips.
|
||||
// Fixes black boxes under popups that are above the game applet.
|
||||
System.setProperty("jgoodies.popupDropShadowEnabled", "false");
|
||||
|
||||
// Do not fill in background on repaint. Reduces flickering when
|
||||
// the applet is resized.
|
||||
System.setProperty("sun.awt.noerasebackground", "true");
|
||||
|
||||
// Use custom window decorations
|
||||
JFrame.setDefaultLookAndFeelDecorated(true);
|
||||
|
||||
// Use substance look and feel
|
||||
try
|
||||
{
|
||||
UIManager.setLookAndFeel(new SubstanceGraphiteLookAndFeel());
|
||||
}
|
||||
catch (UnsupportedLookAndFeelException ex)
|
||||
{
|
||||
log.warn("unable to set look and feel", ex);
|
||||
}
|
||||
|
||||
// Use custom UI font
|
||||
setUIFont(new FontUIResource(FontManager.getRunescapeFont()));
|
||||
|
||||
return new ClientUI(properties, client);
|
||||
}
|
||||
|
||||
private ClientUI(RuneliteProperties properties, Applet client)
|
||||
{
|
||||
this.properties = properties;
|
||||
this.client = client;
|
||||
setUIFont(new FontUIResource(FontManager.getRunescapeFont()));
|
||||
setupTrayIcon();
|
||||
this.trayIcon = setupTrayIcon();
|
||||
|
||||
init();
|
||||
pack();
|
||||
TitleBarPane titleBarPane = new TitleBarPane(this.getRootPane(), (SubstanceRootPaneUI)this.getRootPane().getUI());
|
||||
titleBarPane.editTitleBar(this);
|
||||
new TitleBarPane(this.getRootPane(), (SubstanceRootPaneUI)this.getRootPane().getUI()).editTitleBar(this);
|
||||
setTitle(null);
|
||||
setIconImage(icon);
|
||||
setIconImage(ICON);
|
||||
setLocationRelativeTo(getOwner());
|
||||
setResizable(true);
|
||||
setVisible(true);
|
||||
@@ -108,25 +159,15 @@ public class ClientUI extends JFrame
|
||||
}
|
||||
}
|
||||
|
||||
private void setupTrayIcon()
|
||||
private TrayIcon setupTrayIcon()
|
||||
{
|
||||
if (!SystemTray.isSupported())
|
||||
{
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
SystemTray systemTray = SystemTray.getSystemTray();
|
||||
|
||||
try
|
||||
{
|
||||
icon = ImageIO.read(ClientUI.class.getResourceAsStream("/runelite.png"));
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
log.warn("Client icon failed to load", e);
|
||||
}
|
||||
|
||||
trayIcon = new TrayIcon(icon, properties.getTitle());
|
||||
TrayIcon trayIcon = new TrayIcon(ICON, properties.getTitle());
|
||||
trayIcon.setImageAutoSize(true);
|
||||
|
||||
try
|
||||
@@ -136,7 +177,7 @@ public class ClientUI extends JFrame
|
||||
catch (AWTException ex)
|
||||
{
|
||||
log.debug("Unable to add system tray icon", ex);
|
||||
return;
|
||||
return trayIcon;
|
||||
}
|
||||
|
||||
// bring to front when tray icon is clicked
|
||||
@@ -149,6 +190,8 @@ public class ClientUI extends JFrame
|
||||
setState(Frame.NORMAL); // unminimize
|
||||
}
|
||||
});
|
||||
|
||||
return trayIcon;
|
||||
}
|
||||
|
||||
|
||||
@@ -182,9 +225,7 @@ public class ClientUI extends JFrame
|
||||
|
||||
container = new JPanel();
|
||||
container.setLayout(new BorderLayout(0, 0));
|
||||
|
||||
panel = new ClientPanel(client);
|
||||
container.add(panel, BorderLayout.CENTER);
|
||||
container.add(new ClientPanel(client), BorderLayout.CENTER);
|
||||
|
||||
navContainer = new JPanel();
|
||||
navContainer.setLayout(new BorderLayout(0, 0));
|
||||
@@ -265,9 +306,4 @@ public class ClientUI extends JFrame
|
||||
{
|
||||
return pluginToolbar;
|
||||
}
|
||||
|
||||
public PluginPanel getPluginPanel()
|
||||
{
|
||||
return pluginPanel;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user