runelite-client: convert nav panel to a toolbar
This commit is contained in:
@@ -41,7 +41,7 @@ import net.runelite.client.events.SessionOpen;
|
||||
import net.runelite.client.plugins.Plugin;
|
||||
import net.runelite.client.ui.ClientUI;
|
||||
import net.runelite.client.ui.NavigationButton;
|
||||
import net.runelite.client.ui.NavigationPanel;
|
||||
import net.runelite.client.ui.PluginToolbar;
|
||||
import net.runelite.client.util.RunnableExceptionLogger;
|
||||
import net.runelite.http.api.account.AccountClient;
|
||||
import net.runelite.http.api.account.OAuthResponse;
|
||||
@@ -76,7 +76,7 @@ public class AccountPlugin extends Plugin
|
||||
loginButton.getButton().addActionListener(this::loginClick);
|
||||
logoutButton.getButton().addActionListener(this::logoutClick);
|
||||
|
||||
ui.getNavigationPanel().addNavigation(loginButton);
|
||||
ui.getPluginToolbar().addNavigation(loginButton);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -111,7 +111,7 @@ public class AccountPlugin extends Plugin
|
||||
runelite.deleteSession(); // delete saved session file
|
||||
|
||||
// Replace logout nav button with login
|
||||
NavigationPanel navigationPanel = ui.getNavigationPanel();
|
||||
PluginToolbar navigationPanel = ui.getPluginToolbar();
|
||||
navigationPanel.removeNavigation(logoutButton);
|
||||
navigationPanel.addNavigation(loginButton);
|
||||
}
|
||||
@@ -199,7 +199,7 @@ public class AccountPlugin extends Plugin
|
||||
private void replaceLoginWithLogout()
|
||||
{
|
||||
// Replace login nav button with logout
|
||||
NavigationPanel navigationPanel = ui.getNavigationPanel();
|
||||
PluginToolbar navigationPanel = ui.getPluginToolbar();
|
||||
navigationPanel.removeNavigation(loginButton);
|
||||
navigationPanel.addNavigation(logoutButton);
|
||||
}
|
||||
|
||||
@@ -34,16 +34,25 @@ import java.awt.event.FocusListener;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import javax.swing.*;
|
||||
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JFormattedTextField;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JSpinner;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.SpinnerModel;
|
||||
import javax.swing.SpinnerNumberModel;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import net.runelite.client.RuneLite;
|
||||
import net.runelite.client.config.ConfigDescriptor;
|
||||
import net.runelite.client.config.ConfigItemDescriptor;
|
||||
import net.runelite.client.config.ConfigManager;
|
||||
import net.runelite.client.ui.PluginPanel;
|
||||
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -68,12 +77,6 @@ public class ConfigPanel extends PluginPanel
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other)
|
||||
{
|
||||
return other.getClass() == this.getClass();
|
||||
}
|
||||
|
||||
public void init()
|
||||
{
|
||||
add(createConfigPanel(), BorderLayout.NORTH);
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
*/
|
||||
package net.runelite.client.plugins.config;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.ImageIcon;
|
||||
import net.runelite.client.RuneLite;
|
||||
@@ -46,14 +45,12 @@ public class ConfigPlugin extends Plugin
|
||||
@Override
|
||||
protected void startUp() throws Exception
|
||||
{
|
||||
navButton = new NavigationButton("Configuration");
|
||||
|
||||
navButton.getButton().addActionListener(this::setPluginPanel);
|
||||
navButton = new NavigationButton("Configuration", this::buildPanel);
|
||||
|
||||
ImageIcon icon = new ImageIcon(ImageIO.read(getClass().getResourceAsStream("config_icon.png")));
|
||||
navButton.getButton().setIcon(icon);
|
||||
|
||||
ui.getNavigationPanel().addNavigation(navButton);
|
||||
ui.getPluginToolbar().addNavigation(navButton);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -61,12 +58,11 @@ public class ConfigPlugin extends Plugin
|
||||
{
|
||||
}
|
||||
|
||||
private void setPluginPanel(ActionEvent ae)
|
||||
private ConfigPanel buildPanel()
|
||||
{
|
||||
ConfigPanel panel = new ConfigPanel();
|
||||
panel.init();
|
||||
|
||||
ui.expand(panel);
|
||||
return panel;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,7 +26,6 @@ package net.runelite.client.plugins.devtools;
|
||||
|
||||
import java.awt.Font;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.awt.event.ActionEvent;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.ImageIcon;
|
||||
|
||||
@@ -62,14 +61,12 @@ public class DevTools extends Plugin
|
||||
protected void startUp() throws Exception
|
||||
{
|
||||
panel = new DevToolsPanel(this);
|
||||
navButton = new NavigationButton("DevTools");
|
||||
|
||||
navButton.getButton().addActionListener(this::setPluginPanel);
|
||||
navButton = new NavigationButton("DevTools", () -> panel);
|
||||
|
||||
ImageIcon icon = new ImageIcon(ImageIO.read(getClass().getResourceAsStream("devtools_icon.png")));
|
||||
navButton.getButton().setIcon(icon);
|
||||
|
||||
ui.getNavigationPanel().addNavigation(navButton);
|
||||
ui.getPluginToolbar().addNavigation(navButton);
|
||||
|
||||
font = Font.createFont(Font.TRUETYPE_FONT, getClass().getResourceAsStream("/runescape.ttf"));
|
||||
|
||||
@@ -89,11 +86,6 @@ public class DevTools extends Plugin
|
||||
return overlay;
|
||||
}
|
||||
|
||||
private void setPluginPanel(ActionEvent e)
|
||||
{
|
||||
ui.expand(panel);
|
||||
}
|
||||
|
||||
Font getFont()
|
||||
{
|
||||
return font;
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
package net.runelite.client.plugins.hiscore;
|
||||
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.ImageIcon;
|
||||
@@ -52,15 +51,13 @@ public class Hiscore extends Plugin
|
||||
@Override
|
||||
protected void startUp() throws Exception
|
||||
{
|
||||
navButton = new NavigationButton("Hiscore");
|
||||
navButton = new NavigationButton("Hiscore", () -> hiscorePanel);
|
||||
hiscorePanel = new HiscorePanel(runeLite);
|
||||
|
||||
navButton.getButton().addActionListener(this::setPluginPanel);
|
||||
|
||||
ImageIcon icon = new ImageIcon(ImageIO.read(getClass().getResourceAsStream("hiscore.gif")));
|
||||
navButton.getButton().setIcon(icon);
|
||||
|
||||
ui.getNavigationPanel().addNavigation(navButton);
|
||||
ui.getPluginToolbar().addNavigation(navButton);
|
||||
|
||||
runeLite.getMenuManager().addPlayerMenuItem(LOOKUP);
|
||||
}
|
||||
@@ -70,11 +67,6 @@ public class Hiscore extends Plugin
|
||||
{
|
||||
}
|
||||
|
||||
private void setPluginPanel(ActionEvent e)
|
||||
{
|
||||
ui.expand(hiscorePanel);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onLookupMenuClicked(PlayerMenuOptionClicked event)
|
||||
{
|
||||
|
||||
@@ -36,7 +36,6 @@ import net.runelite.client.ui.ClientUI;
|
||||
import net.runelite.client.ui.NavigationButton;
|
||||
import java.awt.Font;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import net.runelite.client.task.Schedule;
|
||||
|
||||
@@ -55,13 +54,11 @@ public class XPTracker extends Plugin
|
||||
@Override
|
||||
protected void startUp() throws Exception
|
||||
{
|
||||
navButton = new NavigationButton("XP Tracker");
|
||||
navButton = new NavigationButton("XP Tracker", () -> xpPanel);
|
||||
xpPanel = new XPPanel(runeLite, this);
|
||||
|
||||
navButton.getButton().addActionListener(this::setPluginPanel);
|
||||
|
||||
navButton.getButton().setText("XP");
|
||||
ui.getNavigationPanel().addNavigation(navButton);
|
||||
ui.getPluginToolbar().addNavigation(navButton);
|
||||
|
||||
Font font = Font.createFont(Font.TRUETYPE_FONT, getClass().getResourceAsStream("/runescape.ttf"));
|
||||
font = font.deriveFont(Font.BOLD, 16);
|
||||
@@ -74,11 +71,6 @@ public class XPTracker extends Plugin
|
||||
{
|
||||
}
|
||||
|
||||
private void setPluginPanel(ActionEvent e)
|
||||
{
|
||||
ui.expand(xpPanel);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onGameStateChanged(GameStateChanged event)
|
||||
{
|
||||
|
||||
@@ -29,7 +29,6 @@ import java.awt.Dimension;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
@@ -51,7 +50,7 @@ public final class ClientUI extends JFrame
|
||||
private JPanel container;
|
||||
private JPanel navContainer;
|
||||
private ClientPanel panel;
|
||||
private NavigationPanel navigationPanel;
|
||||
private PluginToolbar pluginToolbar;
|
||||
private PluginPanel pluginPanel;
|
||||
|
||||
public ClientUI()
|
||||
@@ -102,38 +101,36 @@ public final class ClientUI extends JFrame
|
||||
navContainer.setLayout(new BorderLayout(0, 0));
|
||||
container.add(navContainer, BorderLayout.EAST);
|
||||
|
||||
navigationPanel = new NavigationPanel();
|
||||
navContainer.add(navigationPanel, BorderLayout.EAST);
|
||||
pluginToolbar = new PluginToolbar(this);
|
||||
navContainer.add(pluginToolbar, BorderLayout.EAST);
|
||||
|
||||
add(container);
|
||||
}
|
||||
|
||||
public void expand(PluginPanel panel)
|
||||
void expand(PluginPanel panel)
|
||||
{
|
||||
if (Objects.equals(pluginPanel, panel))
|
||||
if (pluginPanel != null)
|
||||
{
|
||||
navContainer.remove(1);
|
||||
container.validate();
|
||||
this.setMinimumSize(new Dimension(PANEL_WIDTH, PANEL_HEIGHT));
|
||||
if (this.getWidth() == EXPANDED_WIDTH)
|
||||
{
|
||||
this.setSize(PANEL_WIDTH, PANEL_HEIGHT);
|
||||
}
|
||||
pluginPanel = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (pluginPanel != null)
|
||||
{
|
||||
navContainer.remove(1);
|
||||
container.validate();
|
||||
}
|
||||
|
||||
pluginPanel = panel;
|
||||
navContainer.add(pluginPanel, BorderLayout.WEST);
|
||||
container.validate();
|
||||
this.setMinimumSize(new Dimension(EXPANDED_WIDTH, PANEL_HEIGHT));
|
||||
pluginPanel = panel;
|
||||
navContainer.add(pluginPanel, BorderLayout.WEST);
|
||||
container.validate();
|
||||
this.setMinimumSize(new Dimension(EXPANDED_WIDTH, PANEL_HEIGHT));
|
||||
}
|
||||
|
||||
void contract()
|
||||
{
|
||||
navContainer.remove(1);
|
||||
container.validate();
|
||||
this.setMinimumSize(new Dimension(PANEL_WIDTH, PANEL_HEIGHT));
|
||||
if (this.getWidth() == EXPANDED_WIDTH)
|
||||
{
|
||||
this.setSize(PANEL_WIDTH, PANEL_HEIGHT);
|
||||
}
|
||||
pluginPanel = null;
|
||||
}
|
||||
|
||||
private void checkExit()
|
||||
@@ -153,9 +150,9 @@ public final class ClientUI extends JFrame
|
||||
}
|
||||
}
|
||||
|
||||
public NavigationPanel getNavigationPanel()
|
||||
public PluginToolbar getPluginToolbar()
|
||||
{
|
||||
return navigationPanel;
|
||||
return pluginToolbar;
|
||||
}
|
||||
|
||||
public PluginPanel getPluginPanel()
|
||||
|
||||
@@ -24,18 +24,31 @@
|
||||
*/
|
||||
package net.runelite.client.ui;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
import javax.swing.JButton;
|
||||
|
||||
public class NavigationButton
|
||||
{
|
||||
private final JButton button = new JButton();
|
||||
private final Supplier<PluginPanel> panelSupplier;
|
||||
|
||||
public NavigationButton(String name)
|
||||
{
|
||||
this.panelSupplier = null;
|
||||
}
|
||||
|
||||
public NavigationButton(String name, Supplier<PluginPanel> panelSupplier)
|
||||
{
|
||||
this.panelSupplier = panelSupplier;
|
||||
}
|
||||
|
||||
public JButton getButton()
|
||||
{
|
||||
return button;
|
||||
}
|
||||
|
||||
public Supplier<PluginPanel> getPanelSupplier()
|
||||
{
|
||||
return panelSupplier;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,27 +27,36 @@ package net.runelite.client.ui;
|
||||
import java.awt.Dimension;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.swing.JPanel;
|
||||
import java.util.function.Supplier;
|
||||
import javax.swing.JToolBar;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class NavigationPanel extends JPanel
|
||||
public class PluginToolbar extends JToolBar
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(NavigationPanel.class);
|
||||
private static final Logger logger = LoggerFactory.getLogger(PluginToolbar.class);
|
||||
|
||||
public static final int PANEL_WIDTH = 24, PANEL_HEIGHT = 503;
|
||||
public static final int TOOLBAR_WIDTH = 36, TOOLBAR_BEIGHT = 503;
|
||||
|
||||
private final ClientUI ui;
|
||||
private final List<NavigationButton> buttons = new ArrayList<>();
|
||||
|
||||
public NavigationPanel()
|
||||
private NavigationButton current;
|
||||
|
||||
public PluginToolbar(ClientUI ui)
|
||||
{
|
||||
setSize(new Dimension(PANEL_WIDTH, PANEL_HEIGHT));
|
||||
setMinimumSize(new Dimension(PANEL_WIDTH, PANEL_HEIGHT));
|
||||
setPreferredSize(new Dimension(PANEL_WIDTH, PANEL_HEIGHT));
|
||||
super(JToolBar.VERTICAL);
|
||||
this.ui = ui;
|
||||
|
||||
setSize(new Dimension(TOOLBAR_WIDTH, TOOLBAR_BEIGHT));
|
||||
setMinimumSize(new Dimension(TOOLBAR_WIDTH, TOOLBAR_BEIGHT));
|
||||
setPreferredSize(new Dimension(TOOLBAR_WIDTH, TOOLBAR_BEIGHT));
|
||||
}
|
||||
|
||||
public void addNavigation(NavigationButton button)
|
||||
{
|
||||
button.getButton().addActionListener((ae) -> onClick(button));
|
||||
|
||||
buttons.add(button);
|
||||
add(button.getButton());
|
||||
revalidate();
|
||||
@@ -59,4 +68,33 @@ public class NavigationPanel extends JPanel
|
||||
remove(button.getButton());
|
||||
revalidate();
|
||||
}
|
||||
|
||||
private void onClick(NavigationButton button)
|
||||
{
|
||||
Supplier<PluginPanel> panelSupplier = button.getPanelSupplier();
|
||||
if (panelSupplier == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (current != null)
|
||||
{
|
||||
current.getButton().setSelected(false);
|
||||
}
|
||||
|
||||
if (current == button)
|
||||
{
|
||||
ui.contract();
|
||||
current = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
PluginPanel pluginPanel = panelSupplier.get();
|
||||
ui.expand(pluginPanel);
|
||||
|
||||
current = button;
|
||||
current.getButton().setSelected(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user