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:
Tomas Slusny
2017-12-24 03:55:29 +01:00
parent 6bf63a447f
commit 6c2e827d4a
2 changed files with 72 additions and 63 deletions

View File

@@ -33,12 +33,7 @@ import java.io.File;
import java.util.Optional; import java.util.Optional;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
import javax.inject.Singleton; import javax.inject.Singleton;
import javax.swing.JFrame;
import javax.swing.JPopupMenu;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import javax.swing.ToolTipManager;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import joptsimple.OptionParser; import joptsimple.OptionParser;
import joptsimple.OptionSet; import joptsimple.OptionSet;
import lombok.extern.slf4j.Slf4j; 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.plugins.PluginManager;
import net.runelite.client.ui.ClientUI; import net.runelite.client.ui.ClientUI;
import net.runelite.client.ui.overlay.OverlayRenderer; import net.runelite.client.ui.overlay.OverlayRenderer;
import org.pushingpixels.substance.api.skin.SubstanceGraphiteLookAndFeel;
@Singleton @Singleton
@Slf4j @Slf4j
@@ -96,15 +90,6 @@ public class RuneLite
public static void main(String[] args) throws Exception 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(); OptionParser parser = new OptionParser();
parser.accepts("developer-mode"); parser.accepts("developer-mode");
@@ -139,25 +124,13 @@ public class RuneLite
this.client = (Client) client; this.client = (Client) client;
} }
SwingUtilities.invokeAndWait(() -> // Load swing UI
{ SwingUtilities.invokeAndWait(() -> setGui(ClientUI.create(properties, client)));
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 default configuration
configManager.load(); configManager.load();
// Register event listeners
eventBus.register(overlayRenderer); eventBus.register(overlayRenderer);
eventBus.register(menuManager); eventBus.register(menuManager);
eventBus.register(chatMessageManager); eventBus.register(chatMessageManager);

View File

@@ -24,8 +24,8 @@
*/ */
package net.runelite.client.ui; package net.runelite.client.ui;
import java.applet.Applet;
import com.google.common.base.Strings; import com.google.common.base.Strings;
import java.applet.Applet;
import java.awt.AWTException; import java.awt.AWTException;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.Dimension; import java.awt.Dimension;
@@ -43,17 +43,20 @@ import javax.imageio.ImageIO;
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.JScrollPane; import javax.swing.JScrollPane;
import javax.swing.ScrollPaneConstants; import javax.swing.ScrollPaneConstants;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import javax.swing.ToolTipManager;
import javax.swing.UIManager; import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.plaf.FontUIResource; import javax.swing.plaf.FontUIResource;
import lombok.Getter; import lombok.Getter;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
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.RuneliteProperties; import net.runelite.client.RuneliteProperties;
import org.pushingpixels.substance.api.skin.SubstanceGraphiteLookAndFeel;
import org.pushingpixels.substance.internal.ui.SubstanceRootPaneUI; import org.pushingpixels.substance.internal.ui.SubstanceRootPaneUI;
@Slf4j @Slf4j
@@ -62,6 +65,7 @@ public class ClientUI extends JFrame
private static final int CLIENT_WIDTH = 809; private static final int CLIENT_WIDTH = 809;
private static final int SCROLLBAR_WIDTH = 17; private static final int SCROLLBAR_WIDTH = 17;
private static final int EXPANDED_WIDTH = CLIENT_WIDTH + PluginPanel.PANEL_WIDTH + SCROLLBAR_WIDTH; private static final int EXPANDED_WIDTH = CLIENT_WIDTH + PluginPanel.PANEL_WIDTH + SCROLLBAR_WIDTH;
private static final BufferedImage ICON;
@Getter @Getter
private TrayIcon trayIcon; private TrayIcon trayIcon;
@@ -70,23 +74,70 @@ public class ClientUI extends JFrame
private final RuneliteProperties properties; private final RuneliteProperties properties;
private JPanel container; private JPanel container;
private JPanel navContainer; private JPanel navContainer;
private ClientPanel panel;
private PluginToolbar pluginToolbar; private PluginToolbar pluginToolbar;
private PluginPanel pluginPanel; 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.properties = properties;
this.client = client; this.client = client;
setUIFont(new FontUIResource(FontManager.getRunescapeFont())); this.trayIcon = setupTrayIcon();
setupTrayIcon();
init(); init();
pack(); pack();
TitleBarPane titleBarPane = new TitleBarPane(this.getRootPane(), (SubstanceRootPaneUI)this.getRootPane().getUI()); new TitleBarPane(this.getRootPane(), (SubstanceRootPaneUI)this.getRootPane().getUI()).editTitleBar(this);
titleBarPane.editTitleBar(this);
setTitle(null); setTitle(null);
setIconImage(icon); setIconImage(ICON);
setLocationRelativeTo(getOwner()); setLocationRelativeTo(getOwner());
setResizable(true); setResizable(true);
setVisible(true); setVisible(true);
@@ -108,25 +159,15 @@ public class ClientUI extends JFrame
} }
} }
private void setupTrayIcon() private TrayIcon setupTrayIcon()
{ {
if (!SystemTray.isSupported()) if (!SystemTray.isSupported())
{ {
return; return null;
} }
SystemTray systemTray = SystemTray.getSystemTray(); SystemTray systemTray = SystemTray.getSystemTray();
TrayIcon trayIcon = new TrayIcon(ICON, properties.getTitle());
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.setImageAutoSize(true); trayIcon.setImageAutoSize(true);
try try
@@ -136,7 +177,7 @@ public class ClientUI extends JFrame
catch (AWTException ex) catch (AWTException ex)
{ {
log.debug("Unable to add system tray icon", ex); log.debug("Unable to add system tray icon", ex);
return; return trayIcon;
} }
// bring to front when tray icon is clicked // bring to front when tray icon is clicked
@@ -149,6 +190,8 @@ public class ClientUI extends JFrame
setState(Frame.NORMAL); // unminimize setState(Frame.NORMAL); // unminimize
} }
}); });
return trayIcon;
} }
@@ -182,9 +225,7 @@ public class ClientUI extends JFrame
container = new JPanel(); container = new JPanel();
container.setLayout(new BorderLayout(0, 0)); container.setLayout(new BorderLayout(0, 0));
container.add(new ClientPanel(client), BorderLayout.CENTER);
panel = new ClientPanel(client);
container.add(panel, BorderLayout.CENTER);
navContainer = new JPanel(); navContainer = new JPanel();
navContainer.setLayout(new BorderLayout(0, 0)); navContainer.setLayout(new BorderLayout(0, 0));
@@ -265,9 +306,4 @@ public class ClientUI extends JFrame
{ {
return pluginToolbar; return pluginToolbar;
} }
public PluginPanel getPluginPanel()
{
return pluginPanel;
}
} }