From ed0c34bb6a7ed1bbbbec3e1d9207bd3c70b57ace Mon Sep 17 00:00:00 2001 From: Adam Date: Mon, 13 Feb 2017 19:43:18 -0500 Subject: [PATCH] client: move hiscore nav initialization to plugin --- .../client/plugins/hiscore/Hiscore.java | 24 ++++++++- .../runelite/client/ui/NavigationButton.java | 41 ++++++++++++++++ .../runelite/client/ui/NavigationPanel.java | 49 ++++++++++++------- .../net/runelite/client/ui/PluginPanel.java | 24 +++++++++ 4 files changed, 119 insertions(+), 19 deletions(-) create mode 100644 runelite-client/src/main/java/net/runelite/client/ui/NavigationButton.java diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/hiscore/Hiscore.java b/runelite-client/src/main/java/net/runelite/client/plugins/hiscore/Hiscore.java index a789131e78..b3a6ff3067 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/hiscore/Hiscore.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/hiscore/Hiscore.java @@ -26,19 +26,41 @@ package net.runelite.client.plugins.hiscore; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.io.IOException; +import javax.imageio.ImageIO; +import javax.swing.ImageIcon; import net.runelite.client.RuneLite; import net.runelite.client.plugins.Plugin; import net.runelite.client.ui.ClientUI; +import net.runelite.client.ui.NavigationButton; import net.runelite.client.ui.overlay.Overlay; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class Hiscore extends Plugin implements ActionListener { + private static final Logger logger = LoggerFactory.getLogger(Hiscore.class); + + private final NavigationButton navButton = new NavigationButton("Hiscore"); private final HiscorePanel hiscorePanel = new HiscorePanel(); + private final ClientUI ui = RuneLite.getRunelite().getGui(); public Hiscore() { - ui.getNavigationPanel().getHiscores().addActionListener(this); + navButton.getButton().addActionListener(this); + + try + { + ImageIcon icon = new ImageIcon(ImageIO.read(getClass().getResourceAsStream("hiscore.gif"))); + navButton.getButton().setIcon(icon); + } + catch (IOException ex) + { + logger.warn(null, ex); + } + + ui.getNavigationPanel().addNavigation(navButton); } @Override diff --git a/runelite-client/src/main/java/net/runelite/client/ui/NavigationButton.java b/runelite-client/src/main/java/net/runelite/client/ui/NavigationButton.java new file mode 100644 index 0000000000..1c28583177 --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/ui/NavigationButton.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2017, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.client.ui; + +import javax.swing.JButton; + +public class NavigationButton +{ + private final JButton button = new JButton(); + + public NavigationButton(String name) + { + } + + public JButton getButton() + { + return button; + } +} diff --git a/runelite-client/src/main/java/net/runelite/client/ui/NavigationPanel.java b/runelite-client/src/main/java/net/runelite/client/ui/NavigationPanel.java index 5d5c4b1537..81422f745f 100644 --- a/runelite-client/src/main/java/net/runelite/client/ui/NavigationPanel.java +++ b/runelite-client/src/main/java/net/runelite/client/ui/NavigationPanel.java @@ -1,10 +1,32 @@ +/* + * Copyright (c) 2017, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ package net.runelite.client.ui; import java.awt.Dimension; -import java.io.IOException; -import javax.imageio.ImageIO; -import javax.swing.ImageIcon; -import javax.swing.JButton; +import java.util.ArrayList; +import java.util.List; import javax.swing.JPanel; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -15,28 +37,19 @@ public class NavigationPanel extends JPanel private static final int PANEL_WIDTH = 20, PANEL_HEIGHT = 503; - private final JButton hiscores = new JButton(); + private final List buttons = new ArrayList<>(); public NavigationPanel() { setSize(new Dimension(PANEL_WIDTH, PANEL_HEIGHT)); setMinimumSize(new Dimension(PANEL_WIDTH, PANEL_HEIGHT)); setPreferredSize(new Dimension(PANEL_WIDTH, PANEL_HEIGHT)); - - try - { - hiscores.setIcon(new ImageIcon(ImageIO.read(getClass().getResourceAsStream("/net/runelite/client/plugins/hiscore/hiscore.gif")))); - } - catch (IOException ex) - { - logger.warn(null, ex); - } - - add(hiscores); } - public JButton getHiscores() + public void addNavigation(NavigationButton button) { - return hiscores; + buttons.add(button); + add(button.getButton()); + revalidate(); } } diff --git a/runelite-client/src/main/java/net/runelite/client/ui/PluginPanel.java b/runelite-client/src/main/java/net/runelite/client/ui/PluginPanel.java index 1ba57ea8e3..a85fcc64ae 100644 --- a/runelite-client/src/main/java/net/runelite/client/ui/PluginPanel.java +++ b/runelite-client/src/main/java/net/runelite/client/ui/PluginPanel.java @@ -1,3 +1,27 @@ +/* + * Copyright (c) 2017, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ package net.runelite.client.ui; import javax.swing.JPanel;