Consistent behaviour between ClientUI and InfoPane
- Move method for creation of all buttons from NavigationButton to swing util - Correctly update InfoPanel when plugin is started or needs title bar refresh - Correctly update ClientUI title bar when custom one is visible Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
This commit is contained in:
@@ -28,16 +28,13 @@ import com.google.common.eventbus.EventBus;
|
|||||||
import com.google.common.eventbus.Subscribe;
|
import com.google.common.eventbus.Subscribe;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
import javax.inject.Singleton;
|
||||||
import javax.swing.BorderFactory;
|
import javax.swing.BorderFactory;
|
||||||
import javax.swing.GroupLayout;
|
import javax.swing.GroupLayout;
|
||||||
import javax.swing.ImageIcon;
|
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
import javax.swing.JMenuItem;
|
|
||||||
import javax.swing.JPopupMenu;
|
|
||||||
import javax.swing.LayoutStyle;
|
import javax.swing.LayoutStyle;
|
||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
import javax.swing.event.HyperlinkEvent;
|
import javax.swing.event.HyperlinkEvent;
|
||||||
@@ -54,12 +51,11 @@ import net.runelite.client.events.TitleToolbarButtonRemoved;
|
|||||||
import net.runelite.client.ui.ClientTitleToolbar;
|
import net.runelite.client.ui.ClientTitleToolbar;
|
||||||
import net.runelite.client.ui.FontManager;
|
import net.runelite.client.ui.FontManager;
|
||||||
import net.runelite.client.ui.PluginPanel;
|
import net.runelite.client.ui.PluginPanel;
|
||||||
import net.runelite.client.ui.TitleToolbar;
|
|
||||||
import net.runelite.client.util.RunnableExceptionLogger;
|
import net.runelite.client.util.RunnableExceptionLogger;
|
||||||
import net.runelite.client.util.SwingUtil;
|
import net.runelite.client.util.SwingUtil;
|
||||||
import org.pushingpixels.substance.internal.SubstanceSynapse;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
@Singleton
|
||||||
public class InfoPanel extends PluginPanel
|
public class InfoPanel extends PluginPanel
|
||||||
{
|
{
|
||||||
private static final int TITLEBAR_SIZE = 23;
|
private static final int TITLEBAR_SIZE = 23;
|
||||||
@@ -69,9 +65,6 @@ public class InfoPanel extends PluginPanel
|
|||||||
@Nullable
|
@Nullable
|
||||||
private Client client;
|
private Client client;
|
||||||
|
|
||||||
@Inject
|
|
||||||
private TitleToolbar titleToolbar;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private RuneLiteConfig runeliteConfig;
|
private RuneLiteConfig runeliteConfig;
|
||||||
|
|
||||||
@@ -97,7 +90,7 @@ public class InfoPanel extends PluginPanel
|
|||||||
setLayout(layout);
|
setLayout(layout);
|
||||||
|
|
||||||
final Font smallFont = FontManager.getRunescapeSmallFont();
|
final Font smallFont = FontManager.getRunescapeSmallFont();
|
||||||
titleBar.setVisible(false);
|
updateTitleBar();
|
||||||
|
|
||||||
final JLabel runeliteVersionHeader = new JLabel("RuneLite version");
|
final JLabel runeliteVersionHeader = new JLabel("RuneLite version");
|
||||||
runeliteVersionHeader.setFont(smallFont);
|
runeliteVersionHeader.setFont(smallFont);
|
||||||
@@ -125,7 +118,8 @@ public class InfoPanel extends PluginPanel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
setNotLoggedIn();
|
|
||||||
|
updateLoggedIn();
|
||||||
|
|
||||||
final JRichTextPane issueLink = new JRichTextPane("text/html",
|
final JRichTextPane issueLink = new JRichTextPane("text/html",
|
||||||
"RuneLite is open source!<br>"
|
"RuneLite is open source!<br>"
|
||||||
@@ -175,39 +169,48 @@ public class InfoPanel extends PluginPanel
|
|||||||
eventBus.register(this);
|
eventBus.register(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setNotLoggedIn()
|
private void updateLoggedIn()
|
||||||
{
|
{
|
||||||
username.setContentType("text/html");
|
final String name = sessionManager.getAccountSession() != null
|
||||||
username.setText("<a href=\"" + RUNELITE_LOGIN + "\">Login</a> to sync settings to the cloud.");
|
? sessionManager.getAccountSession().getUsername()
|
||||||
usernameHeader.setText("Not logged in");
|
: null;
|
||||||
}
|
|
||||||
|
|
||||||
@Subscribe
|
|
||||||
public void onClientUILoaded(ClientUILoaded e)
|
|
||||||
{
|
|
||||||
// Add the title toolbar to the infopanel if the custom chrome is disabled
|
|
||||||
if (!runeliteConfig.enableCustomChrome())
|
|
||||||
{
|
|
||||||
titleBar.setVisible(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Subscribe
|
|
||||||
public void onSessionOpen(SessionOpen sessionOpen)
|
|
||||||
{
|
|
||||||
String name = sessionManager.getAccountSession().getUsername();
|
|
||||||
if (name != null)
|
if (name != null)
|
||||||
{
|
{
|
||||||
username.setContentType("text/plain");
|
username.setContentType("text/plain");
|
||||||
username.setText(name);
|
username.setText(name);
|
||||||
usernameHeader.setText("Logged in as");
|
usernameHeader.setText("Logged in as");
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
username.setContentType("text/html");
|
||||||
|
username.setText("<a href=\"" + RUNELITE_LOGIN + "\">Login</a> to sync settings to the cloud.");
|
||||||
|
usernameHeader.setText("Not logged in");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateTitleBar()
|
||||||
|
{
|
||||||
|
titleBar.setVisible(!runeliteConfig.enableCustomChrome());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onClientUILoaded(ClientUILoaded e)
|
||||||
|
{
|
||||||
|
// Add the title toolbar to the infopanel if the custom chrome is disabled
|
||||||
|
updateTitleBar();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onSessionOpen(SessionOpen sessionOpen)
|
||||||
|
{
|
||||||
|
updateLoggedIn();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onSessionClose(SessionClose e)
|
public void onSessionClose(SessionClose e)
|
||||||
{
|
{
|
||||||
setNotLoggedIn();
|
updateLoggedIn();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
@@ -220,38 +223,8 @@ public class InfoPanel extends PluginPanel
|
|||||||
|
|
||||||
SwingUtilities.invokeLater(() ->
|
SwingUtilities.invokeLater(() ->
|
||||||
{
|
{
|
||||||
|
|
||||||
final int iconSize = TITLEBAR_SIZE - 6;
|
final int iconSize = TITLEBAR_SIZE - 6;
|
||||||
final BufferedImage scaledImage = SwingUtil.resizeImage(event.getButton().getIcon(), iconSize, iconSize);
|
final JButton button = SwingUtil.createSwingButton(event.getButton(), iconSize, null);
|
||||||
|
|
||||||
final JButton button = new JButton();
|
|
||||||
button.putClientProperty(SubstanceSynapse.FLAT_LOOK, Boolean.TRUE);
|
|
||||||
button.setName(event.getButton().getName());
|
|
||||||
button.setToolTipText(event.getButton().getTooltip());
|
|
||||||
button.setIcon(new ImageIcon(scaledImage));
|
|
||||||
button.setRolloverIcon(new ImageIcon(SwingUtil.createInvertedImage(scaledImage)));
|
|
||||||
|
|
||||||
if (event.getButton().getOnClick() != null)
|
|
||||||
{
|
|
||||||
button.addActionListener(e -> event.getButton().getOnClick().run());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.getButton().getPopup() != null)
|
|
||||||
{
|
|
||||||
final JPopupMenu popupMenu = new JPopupMenu();
|
|
||||||
|
|
||||||
event.getButton().getPopup().forEach((name, callback) ->
|
|
||||||
{
|
|
||||||
final JMenuItem menuItem = new JMenuItem(name);
|
|
||||||
menuItem.addActionListener((e) -> callback.run());
|
|
||||||
popupMenu.add(menuItem);
|
|
||||||
});
|
|
||||||
|
|
||||||
button.setComponentPopupMenu(popupMenu);
|
|
||||||
}
|
|
||||||
|
|
||||||
event.getButton().setOnSelect(() -> button.setSelected(event.getButton().isSelected()));
|
|
||||||
|
|
||||||
titleBar.addComponent(event.getButton(), button);
|
titleBar.addComponent(event.getButton(), button);
|
||||||
titleBar.revalidate();
|
titleBar.revalidate();
|
||||||
titleBar.repaint();
|
titleBar.repaint();
|
||||||
|
|||||||
@@ -27,10 +27,12 @@ package net.runelite.client.plugins.info;
|
|||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
import net.runelite.client.config.RuneLiteConfig;
|
||||||
import net.runelite.client.plugins.Plugin;
|
import net.runelite.client.plugins.Plugin;
|
||||||
import net.runelite.client.plugins.PluginDescriptor;
|
import net.runelite.client.plugins.PluginDescriptor;
|
||||||
import net.runelite.client.ui.NavigationButton;
|
import net.runelite.client.ui.NavigationButton;
|
||||||
import net.runelite.client.ui.PluginToolbar;
|
import net.runelite.client.ui.PluginToolbar;
|
||||||
|
import net.runelite.client.ui.TitleToolbar;
|
||||||
|
|
||||||
@PluginDescriptor(
|
@PluginDescriptor(
|
||||||
name = "Info Panel",
|
name = "Info Panel",
|
||||||
@@ -41,6 +43,12 @@ public class InfoPlugin extends Plugin
|
|||||||
@Inject
|
@Inject
|
||||||
private PluginToolbar pluginToolbar;
|
private PluginToolbar pluginToolbar;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private TitleToolbar titleToolbar;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private RuneLiteConfig runeLiteConfig;
|
||||||
|
|
||||||
private NavigationButton navButton;
|
private NavigationButton navButton;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -62,6 +70,11 @@ public class InfoPlugin extends Plugin
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
pluginToolbar.addNavigation(navButton);
|
pluginToolbar.addNavigation(navButton);
|
||||||
|
|
||||||
|
if (!runeLiteConfig.enableCustomChrome())
|
||||||
|
{
|
||||||
|
titleToolbar.refresh();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -44,13 +44,10 @@ import javax.imageio.ImageIO;
|
|||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
import javax.swing.BoxLayout;
|
import javax.swing.BoxLayout;
|
||||||
import javax.swing.ImageIcon;
|
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
import javax.swing.JMenuItem;
|
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.JPopupMenu;
|
|
||||||
import javax.swing.JRootPane;
|
import javax.swing.JRootPane;
|
||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
@@ -70,7 +67,6 @@ import net.runelite.client.util.OSType;
|
|||||||
import net.runelite.client.util.OSXUtil;
|
import net.runelite.client.util.OSXUtil;
|
||||||
import net.runelite.client.util.SwingUtil;
|
import net.runelite.client.util.SwingUtil;
|
||||||
import org.pushingpixels.substance.api.skin.SubstanceGraphiteLookAndFeel;
|
import org.pushingpixels.substance.api.skin.SubstanceGraphiteLookAndFeel;
|
||||||
import org.pushingpixels.substance.internal.SubstanceSynapse;
|
|
||||||
import org.pushingpixels.substance.internal.utils.SubstanceCoreUtilities;
|
import org.pushingpixels.substance.internal.utils.SubstanceCoreUtilities;
|
||||||
import org.pushingpixels.substance.internal.utils.SubstanceTitlePaneUtilities;
|
import org.pushingpixels.substance.internal.utils.SubstanceTitlePaneUtilities;
|
||||||
|
|
||||||
@@ -202,45 +198,37 @@ public class ClientUI
|
|||||||
@Subscribe
|
@Subscribe
|
||||||
public void onPluginToolbarButtonAdded(final PluginToolbarButtonAdded event)
|
public void onPluginToolbarButtonAdded(final PluginToolbarButtonAdded event)
|
||||||
{
|
{
|
||||||
final JButton button = new JButton();
|
SwingUtilities.invokeLater(() ->
|
||||||
button.setName(event.getButton().getName());
|
|
||||||
button.setToolTipText(event.getButton().getTooltip());
|
|
||||||
button.setToolTipText(event.getButton().getTooltip());
|
|
||||||
button.setIcon(new ImageIcon(event.getButton().getIcon()));
|
|
||||||
button.addActionListener(e ->
|
|
||||||
{
|
{
|
||||||
final PluginPanel panel = event.getButton().getPanel();
|
final JButton button = SwingUtil.createSwingButton(event.getButton(), 0, (jButton) ->
|
||||||
|
{
|
||||||
|
final PluginPanel panel = event.getButton().getPanel();
|
||||||
|
|
||||||
if (panel == null)
|
if (panel == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentButton != null)
|
if (currentButton != null)
|
||||||
{
|
{
|
||||||
currentButton.setSelected(false);
|
currentButton.setSelected(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentButton == button)
|
if (currentButton == jButton)
|
||||||
{
|
{
|
||||||
contract();
|
contract();
|
||||||
currentButton = null;
|
currentButton = null;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
currentButton = button;
|
currentButton = jButton;
|
||||||
currentButton.setSelected(true);
|
currentButton.setSelected(true);
|
||||||
expand(panel);
|
expand(panel);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
if (event.getButton().getOnClick() != null)
|
pluginToolbar.addComponent(event.getIndex(), event.getButton(), button);
|
||||||
{
|
|
||||||
event.getButton().getOnClick().run();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
event.getButton().setOnSelect(() -> button.setSelected(event.getButton().isSelected()));
|
|
||||||
SwingUtilities.invokeLater(() -> pluginToolbar.addComponent(event.getIndex(), event.getButton(), button));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
@@ -252,44 +240,15 @@ public class ClientUI
|
|||||||
@Subscribe
|
@Subscribe
|
||||||
public void onTitleToolbarButtonAdded(final TitleToolbarButtonAdded event)
|
public void onTitleToolbarButtonAdded(final TitleToolbarButtonAdded event)
|
||||||
{
|
{
|
||||||
if (!config.enableCustomChrome())
|
if (!config.enableCustomChrome() && !SwingUtil.isCustomTitlePanePresent(frame))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SwingUtilities.invokeLater(() ->
|
SwingUtilities.invokeLater(() ->
|
||||||
{
|
{
|
||||||
|
|
||||||
final int iconSize = ClientTitleToolbar.TITLEBAR_SIZE - 6;
|
final int iconSize = ClientTitleToolbar.TITLEBAR_SIZE - 6;
|
||||||
final BufferedImage scaledImage = SwingUtil.resizeImage(event.getButton().getIcon(), iconSize, iconSize);
|
final JButton button = SwingUtil.createSwingButton(event.getButton(), iconSize, null);
|
||||||
final JButton button = new JButton();
|
|
||||||
button.setName(event.getButton().getName());
|
|
||||||
button.setToolTipText(event.getButton().getTooltip());
|
|
||||||
button.setIcon(new ImageIcon(scaledImage));
|
|
||||||
button.setRolloverIcon(new ImageIcon(SwingUtil.createInvertedImage(scaledImage)));
|
|
||||||
button.putClientProperty(SubstanceSynapse.FLAT_LOOK, Boolean.TRUE);
|
|
||||||
button.setFocusable(false);
|
|
||||||
|
|
||||||
if (event.getButton().getOnClick() != null)
|
|
||||||
{
|
|
||||||
button.addActionListener(e -> event.getButton().getOnClick().run());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.getButton().getPopup() != null)
|
|
||||||
{
|
|
||||||
final JPopupMenu popupMenu = new JPopupMenu();
|
|
||||||
|
|
||||||
event.getButton().getPopup().forEach((name, callback) ->
|
|
||||||
{
|
|
||||||
final JMenuItem menuItem = new JMenuItem(name);
|
|
||||||
menuItem.addActionListener((e) -> callback.run());
|
|
||||||
popupMenu.add(menuItem);
|
|
||||||
});
|
|
||||||
|
|
||||||
button.setComponentPopupMenu(popupMenu);
|
|
||||||
}
|
|
||||||
|
|
||||||
event.getButton().setOnSelect(() -> button.setSelected(event.getButton().isSelected()));
|
|
||||||
titleToolbar.addComponent(event.getButton(), button);
|
titleToolbar.addComponent(event.getButton(), button);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -297,7 +256,7 @@ public class ClientUI
|
|||||||
@Subscribe
|
@Subscribe
|
||||||
public void onTitleToolbarButtonRemoved(final TitleToolbarButtonRemoved event)
|
public void onTitleToolbarButtonRemoved(final TitleToolbarButtonRemoved event)
|
||||||
{
|
{
|
||||||
if (!config.enableCustomChrome())
|
if (!config.enableCustomChrome() && !SwingUtil.isCustomTitlePanePresent(frame))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,22 +31,24 @@ import java.awt.Frame;
|
|||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.Image;
|
import java.awt.Image;
|
||||||
import java.awt.Rectangle;
|
import java.awt.Rectangle;
|
||||||
import java.awt.RenderingHints;
|
|
||||||
import java.awt.SystemTray;
|
import java.awt.SystemTray;
|
||||||
import java.awt.Toolkit;
|
import java.awt.Toolkit;
|
||||||
import java.awt.TrayIcon;
|
import java.awt.TrayIcon;
|
||||||
|
import java.awt.Window;
|
||||||
import java.awt.event.MouseAdapter;
|
import java.awt.event.MouseAdapter;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
import java.awt.event.WindowAdapter;
|
import java.awt.event.WindowAdapter;
|
||||||
import java.awt.event.WindowEvent;
|
import java.awt.event.WindowEvent;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.awt.image.LookupOp;
|
|
||||||
import java.awt.image.LookupTable;
|
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
|
import java.util.function.Consumer;
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
import javax.swing.ImageIcon;
|
||||||
|
import javax.swing.JButton;
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
|
import javax.swing.JMenuItem;
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
import javax.swing.JPopupMenu;
|
import javax.swing.JPopupMenu;
|
||||||
import javax.swing.LookAndFeel;
|
import javax.swing.LookAndFeel;
|
||||||
@@ -56,6 +58,9 @@ import javax.swing.UnsupportedLookAndFeelException;
|
|||||||
import static javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE;
|
import static javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE;
|
||||||
import javax.swing.plaf.FontUIResource;
|
import javax.swing.plaf.FontUIResource;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import net.runelite.client.ui.NavigationButton;
|
||||||
|
import org.pushingpixels.substance.internal.SubstanceSynapse;
|
||||||
|
import org.pushingpixels.substance.internal.utils.SubstanceCoreUtilities;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Various Swing utilities.
|
* Various Swing utilities.
|
||||||
@@ -234,44 +239,7 @@ public class SwingUtil
|
|||||||
frame.setMinimumSize(frame.getLayout().minimumLayoutSize(frame));
|
frame.setMinimumSize(frame.getLayout().minimumLayoutSize(frame));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private static BufferedImage resizeImage(BufferedImage image, int newWidth, int newHeight)
|
||||||
* Create inverted buffered image
|
|
||||||
*
|
|
||||||
* @param image buffered image
|
|
||||||
* @return inverted buffered image
|
|
||||||
*/
|
|
||||||
public static BufferedImage createInvertedImage(BufferedImage image)
|
|
||||||
{
|
|
||||||
if (image.getType() != BufferedImage.TYPE_INT_ARGB)
|
|
||||||
{
|
|
||||||
image = convertToARGB(image);
|
|
||||||
}
|
|
||||||
|
|
||||||
final LookupTable lookup = new LookupTable(0, 4)
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public int[] lookupPixel(int[] src, int[] dest)
|
|
||||||
{
|
|
||||||
dest[0] = 255 - src[0];
|
|
||||||
dest[1] = 255 - src[1];
|
|
||||||
dest[2] = 255 - src[2];
|
|
||||||
return dest;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
final LookupOp op = new LookupOp(lookup, new RenderingHints(null));
|
|
||||||
return op.filter(image, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Resize buffered image.
|
|
||||||
*
|
|
||||||
* @param image the image
|
|
||||||
* @param newWidth the new width
|
|
||||||
* @param newHeight the new height
|
|
||||||
* @return the buffered image
|
|
||||||
*/
|
|
||||||
public static BufferedImage resizeImage(BufferedImage image, int newWidth, int newHeight)
|
|
||||||
{
|
{
|
||||||
final Image tmp = image.getScaledInstance(newWidth, newHeight, Image.SCALE_SMOOTH);
|
final Image tmp = image.getScaledInstance(newWidth, newHeight, Image.SCALE_SMOOTH);
|
||||||
final BufferedImage dimg = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_ARGB);
|
final BufferedImage dimg = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_ARGB);
|
||||||
@@ -282,15 +250,69 @@ public class SwingUtil
|
|||||||
return dimg;
|
return dimg;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static BufferedImage convertToARGB(final BufferedImage image)
|
/**
|
||||||
|
* Create swing button from navigation button.
|
||||||
|
*
|
||||||
|
* @param navigationButton the navigation button
|
||||||
|
* @param iconSize the icon size (in case it is 0 default icon size will be used)
|
||||||
|
* @param specialCallback the special callback
|
||||||
|
* @return the swing button
|
||||||
|
*/
|
||||||
|
public static JButton createSwingButton(
|
||||||
|
@Nonnull final NavigationButton navigationButton,
|
||||||
|
int iconSize,
|
||||||
|
@Nullable final Consumer<JButton> specialCallback)
|
||||||
{
|
{
|
||||||
final BufferedImage newImage = new BufferedImage(
|
|
||||||
image.getWidth(), image.getHeight(),
|
|
||||||
BufferedImage.TYPE_INT_ARGB);
|
|
||||||
|
|
||||||
final Graphics2D g = newImage.createGraphics();
|
final BufferedImage scaledImage = iconSize > 0
|
||||||
g.drawImage(image, 0, 0, null);
|
? resizeImage(navigationButton.getIcon(), iconSize, iconSize)
|
||||||
g.dispose();
|
: navigationButton.getIcon();
|
||||||
return newImage;
|
|
||||||
|
final JButton button = new JButton();
|
||||||
|
button.setName(navigationButton.getName());
|
||||||
|
button.setToolTipText(navigationButton.getTooltip());
|
||||||
|
button.setIcon(new ImageIcon(scaledImage));
|
||||||
|
button.putClientProperty(SubstanceSynapse.FLAT_LOOK, Boolean.TRUE);
|
||||||
|
button.setFocusable(false);
|
||||||
|
button.addActionListener(e ->
|
||||||
|
{
|
||||||
|
if (specialCallback != null)
|
||||||
|
{
|
||||||
|
specialCallback.accept(button);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (navigationButton.getOnClick() != null)
|
||||||
|
{
|
||||||
|
navigationButton.getOnClick().run();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (navigationButton.getPopup() != null)
|
||||||
|
{
|
||||||
|
final JPopupMenu popupMenu = new JPopupMenu();
|
||||||
|
|
||||||
|
navigationButton.getPopup().forEach((name, callback) ->
|
||||||
|
{
|
||||||
|
final JMenuItem menuItem = new JMenuItem(name);
|
||||||
|
menuItem.addActionListener((e) -> callback.run());
|
||||||
|
popupMenu.add(menuItem);
|
||||||
|
});
|
||||||
|
|
||||||
|
button.setComponentPopupMenu(popupMenu);
|
||||||
|
}
|
||||||
|
|
||||||
|
navigationButton.setOnSelect(() -> button.setSelected(navigationButton.isSelected()));
|
||||||
|
return button;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if custom substance title pane is present.
|
||||||
|
*
|
||||||
|
* @param frame the parent frame
|
||||||
|
* @return true if title pane is present
|
||||||
|
*/
|
||||||
|
public static boolean isCustomTitlePanePresent(final Window frame)
|
||||||
|
{
|
||||||
|
return SubstanceCoreUtilities.getTitlePaneComponent(frame) != null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user