Merge pull request #1099 from deathbeam/nav-button-lookup-fix
Expand panels based on click event not isSelected
This commit is contained in:
@@ -131,7 +131,6 @@ public class GrandExchangePlugin extends Plugin
|
|||||||
|
|
||||||
if (!button.isSelected())
|
if (!button.isSelected())
|
||||||
{
|
{
|
||||||
button.setSelected(true);
|
|
||||||
button.getOnSelect().run();
|
button.getOnSelect().run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -129,7 +129,6 @@ public class HiscorePlugin extends Plugin
|
|||||||
{
|
{
|
||||||
if (!navButton.isSelected())
|
if (!navButton.isSelected())
|
||||||
{
|
{
|
||||||
navButton.setSelected(true);
|
|
||||||
navButton.getOnSelect().run();
|
navButton.getOnSelect().run();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -113,6 +113,7 @@ public class ClientUI
|
|||||||
private ClientPluginToolbar pluginToolbar;
|
private ClientPluginToolbar pluginToolbar;
|
||||||
private ClientTitleToolbar titleToolbar;
|
private ClientTitleToolbar titleToolbar;
|
||||||
private JButton currentButton;
|
private JButton currentButton;
|
||||||
|
private NavigationButton currentNavButton;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private ClientUI(
|
private ClientUI(
|
||||||
@@ -200,9 +201,9 @@ public class ClientUI
|
|||||||
{
|
{
|
||||||
SwingUtilities.invokeLater(() ->
|
SwingUtilities.invokeLater(() ->
|
||||||
{
|
{
|
||||||
final JButton button = SwingUtil.createSwingButton(event.getButton(), 0, (jButton) ->
|
final JButton button = SwingUtil.createSwingButton(event.getButton(), 0, (navButton, jButton) ->
|
||||||
{
|
{
|
||||||
final PluginPanel panel = event.getButton().getPanel();
|
final PluginPanel panel = navButton.getPanel();
|
||||||
|
|
||||||
if (panel == null)
|
if (panel == null)
|
||||||
{
|
{
|
||||||
@@ -214,15 +215,23 @@ public class ClientUI
|
|||||||
currentButton.setSelected(false);
|
currentButton.setSelected(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentButton == jButton)
|
if (currentNavButton != null)
|
||||||
|
{
|
||||||
|
currentNavButton.setSelected(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentButton == jButton && currentNavButton == navButton)
|
||||||
{
|
{
|
||||||
contract();
|
contract();
|
||||||
currentButton = null;
|
currentButton = null;
|
||||||
|
currentNavButton = null;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
currentButton = jButton;
|
currentButton = jButton;
|
||||||
|
currentNavButton = navButton;
|
||||||
currentButton.setSelected(true);
|
currentButton.setSelected(true);
|
||||||
|
currentNavButton.setSelected(true);
|
||||||
expand(panel);
|
expand(panel);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -59,16 +59,16 @@ public class NavigationButton
|
|||||||
*/
|
*/
|
||||||
private boolean selected;
|
private boolean selected;
|
||||||
|
|
||||||
/**
|
|
||||||
* On select action of the button.
|
|
||||||
*/
|
|
||||||
private Runnable onSelect;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* On click action of the button.
|
* On click action of the button.
|
||||||
*/
|
*/
|
||||||
private Runnable onClick;
|
private Runnable onClick;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* On select action of the button.
|
||||||
|
*/
|
||||||
|
private Runnable onSelect;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Plugin panel, used when expanding and contracting sidebar.
|
* Plugin panel, used when expanding and contracting sidebar.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ import java.awt.event.WindowEvent;
|
|||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.BiConsumer;
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import javax.swing.ImageIcon;
|
import javax.swing.ImageIcon;
|
||||||
@@ -261,7 +261,7 @@ public class SwingUtil
|
|||||||
public static JButton createSwingButton(
|
public static JButton createSwingButton(
|
||||||
@Nonnull final NavigationButton navigationButton,
|
@Nonnull final NavigationButton navigationButton,
|
||||||
int iconSize,
|
int iconSize,
|
||||||
@Nullable final Consumer<JButton> specialCallback)
|
@Nullable final BiConsumer<NavigationButton, JButton> specialCallback)
|
||||||
{
|
{
|
||||||
|
|
||||||
final BufferedImage scaledImage = iconSize > 0
|
final BufferedImage scaledImage = iconSize > 0
|
||||||
@@ -278,7 +278,7 @@ public class SwingUtil
|
|||||||
{
|
{
|
||||||
if (specialCallback != null)
|
if (specialCallback != null)
|
||||||
{
|
{
|
||||||
specialCallback.accept(button);
|
specialCallback.accept(navigationButton, button);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (navigationButton.getOnClick() != null)
|
if (navigationButton.getOnClick() != null)
|
||||||
@@ -301,16 +301,7 @@ public class SwingUtil
|
|||||||
button.setComponentPopupMenu(popupMenu);
|
button.setComponentPopupMenu(popupMenu);
|
||||||
}
|
}
|
||||||
|
|
||||||
navigationButton.setOnSelect(() ->
|
navigationButton.setOnSelect(button::doClick);
|
||||||
{
|
|
||||||
button.setSelected(navigationButton.isSelected());
|
|
||||||
|
|
||||||
if (navigationButton.isSelected())
|
|
||||||
{
|
|
||||||
button.doClick();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return button;
|
return button;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user