runelite-client: Remove IconButton
Most of this class is defaults, which can just be a normal method and a listener for hover support, which is part of the base class anyway.
This commit is contained in:
@@ -29,8 +29,6 @@ import com.google.inject.Inject;
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
@@ -52,7 +50,7 @@ import net.runelite.client.util.ImageUtil;
|
||||
class KourendLibraryPanel extends PluginPanel
|
||||
{
|
||||
private static final ImageIcon RESET_ICON;
|
||||
private static final ImageIcon RESET_CLICK_ICON;
|
||||
private static final ImageIcon RESET_HOVER_ICON;
|
||||
|
||||
private final KourendLibraryConfig config;
|
||||
private final Library library;
|
||||
@@ -63,7 +61,7 @@ class KourendLibraryPanel extends PluginPanel
|
||||
{
|
||||
final BufferedImage resetIcon = ImageUtil.getResourceStreamFromClass(KourendLibraryPanel.class, "/util/reset.png");
|
||||
RESET_ICON = new ImageIcon(resetIcon);
|
||||
RESET_CLICK_ICON = new ImageIcon(ImageUtil.alphaOffset(resetIcon, -100));
|
||||
RESET_HOVER_ICON = new ImageIcon(ImageUtil.alphaOffset(resetIcon, -100));
|
||||
}
|
||||
|
||||
@Inject
|
||||
@@ -100,21 +98,11 @@ class KourendLibraryPanel extends PluginPanel
|
||||
});
|
||||
|
||||
JButton reset = new JButton("Reset", RESET_ICON);
|
||||
reset.addMouseListener(new MouseAdapter()
|
||||
reset.setRolloverIcon(RESET_HOVER_ICON);
|
||||
reset.addActionListener(ev ->
|
||||
{
|
||||
@Override
|
||||
public void mousePressed(MouseEvent mouseEvent)
|
||||
{
|
||||
reset.setIcon(RESET_CLICK_ICON);
|
||||
library.reset();
|
||||
update();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent mouseEvent)
|
||||
{
|
||||
reset.setIcon(RESET_ICON);
|
||||
}
|
||||
library.reset();
|
||||
update();
|
||||
});
|
||||
|
||||
add(reset, BorderLayout.NORTH);
|
||||
|
||||
@@ -30,12 +30,12 @@ import java.awt.Dimension;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.event.FocusEvent;
|
||||
import java.awt.event.FocusListener;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.time.Duration;
|
||||
import java.time.format.DateTimeParseException;
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JToggleButton;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.border.Border;
|
||||
import javax.swing.border.CompoundBorder;
|
||||
@@ -43,7 +43,7 @@ import javax.swing.border.EmptyBorder;
|
||||
import lombok.Getter;
|
||||
import net.runelite.client.ui.ColorScheme;
|
||||
import net.runelite.client.ui.components.FlatTextField;
|
||||
import net.runelite.client.ui.components.IconButton;
|
||||
import net.runelite.client.util.SwingUtil;
|
||||
|
||||
abstract class ClockPanel extends JPanel
|
||||
{
|
||||
@@ -63,7 +63,7 @@ abstract class ClockPanel extends JPanel
|
||||
final JPanel rightActions;
|
||||
|
||||
private final FlatTextField nameInput;
|
||||
private final IconButton startPauseButton;
|
||||
private final JToggleButton startPauseButton;
|
||||
private final FlatTextField displayInput;
|
||||
|
||||
@Getter
|
||||
@@ -167,28 +167,17 @@ abstract class ClockPanel extends JPanel
|
||||
leftActions = new JPanel(new FlowLayout(FlowLayout.LEFT, 6, 0));
|
||||
leftActions.setBackground(ColorScheme.DARKER_GRAY_COLOR);
|
||||
|
||||
startPauseButton = new IconButton(ClockTabPanel.START_ICON);
|
||||
startPauseButton = new JToggleButton(ClockTabPanel.START_ICON);
|
||||
startPauseButton.setRolloverIcon(ClockTabPanel.START_ICON_HOVER);
|
||||
startPauseButton.setSelectedIcon(ClockTabPanel.PAUSE_ICON);
|
||||
startPauseButton.setRolloverSelectedIcon(ClockTabPanel.PAUSE_ICON_HOVER);
|
||||
SwingUtil.removeButtonDecorations(startPauseButton);
|
||||
startPauseButton.setPreferredSize(new Dimension(16, 14));
|
||||
updateActivityStatus();
|
||||
|
||||
startPauseButton.addMouseListener(new MouseAdapter()
|
||||
{
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent e)
|
||||
{
|
||||
startPauseButton.setIcon(clock.isActive() ? ClockTabPanel.PAUSE_ICON_HOVER : ClockTabPanel.START_ICON_HOVER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseExited(MouseEvent e)
|
||||
{
|
||||
startPauseButton.setIcon(clock.isActive() ? ClockTabPanel.PAUSE_ICON : ClockTabPanel.START_ICON);
|
||||
}
|
||||
});
|
||||
|
||||
startPauseButton.addActionListener(e ->
|
||||
{
|
||||
if (clock.isActive())
|
||||
if (!startPauseButton.isSelected())
|
||||
{
|
||||
clock.pause();
|
||||
}
|
||||
@@ -201,7 +190,9 @@ abstract class ClockPanel extends JPanel
|
||||
clockManager.saveToConfig();
|
||||
});
|
||||
|
||||
IconButton resetButton = new IconButton(ClockTabPanel.RESET_ICON, ClockTabPanel.RESET_ICON_HOVER);
|
||||
JButton resetButton = new JButton(ClockTabPanel.RESET_ICON);
|
||||
resetButton.setRolloverIcon(ClockTabPanel.RESET_ICON_HOVER);
|
||||
SwingUtil.removeButtonDecorations(resetButton);
|
||||
resetButton.setPreferredSize(new Dimension(16, 14));
|
||||
resetButton.setToolTipText("Reset " + clockType);
|
||||
|
||||
@@ -249,7 +240,7 @@ abstract class ClockPanel extends JPanel
|
||||
displayInput.setEditable(editable && !isActive);
|
||||
displayInput.getTextField().setForeground(isActive ? ACTIVE_CLOCK_COLOR : INACTIVE_CLOCK_COLOR);
|
||||
startPauseButton.setToolTipText(isActive ? "Pause " + clockType : "Start " + clockType);
|
||||
startPauseButton.setIcon(isActive ? ClockTabPanel.PAUSE_ICON : ClockTabPanel.START_ICON);
|
||||
startPauseButton.setSelected(isActive);
|
||||
|
||||
if (editable && clock.getDisplayTime() == 0 && !isActive)
|
||||
{
|
||||
|
||||
@@ -32,6 +32,7 @@ import java.awt.image.BufferedImage;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
@@ -40,9 +41,9 @@ import net.runelite.client.plugins.timetracking.TimeTrackingPlugin;
|
||||
import net.runelite.client.ui.ColorScheme;
|
||||
import net.runelite.client.ui.DynamicGridLayout;
|
||||
import net.runelite.client.ui.FontManager;
|
||||
import net.runelite.client.ui.components.IconButton;
|
||||
import net.runelite.client.ui.components.shadowlabel.JShadowedLabel;
|
||||
import net.runelite.client.util.ImageUtil;
|
||||
import net.runelite.client.util.SwingUtil;
|
||||
|
||||
public class ClockTabPanel extends TabContentPanel
|
||||
{
|
||||
@@ -150,7 +151,9 @@ public class ClockTabPanel extends TabContentPanel
|
||||
headerLabel.setFont(FontManager.getRunescapeSmallFont());
|
||||
panel.add(headerLabel, BorderLayout.CENTER);
|
||||
|
||||
IconButton addButton = new IconButton(ADD_ICON, ADD_ICON_HOVER);
|
||||
JButton addButton = new JButton(ADD_ICON);
|
||||
addButton.setRolloverIcon(ADD_ICON_HOVER);
|
||||
SwingUtil.removeButtonDecorations(addButton);
|
||||
addButton.setPreferredSize(new Dimension(14, 14));
|
||||
addButton.setToolTipText("Add a " + type);
|
||||
addButton.addActionListener(actionListener);
|
||||
|
||||
@@ -30,13 +30,14 @@ import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.Insets;
|
||||
import java.util.List;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import net.runelite.client.ui.ColorScheme;
|
||||
import net.runelite.client.ui.FontManager;
|
||||
import net.runelite.client.ui.components.IconButton;
|
||||
import net.runelite.client.util.SwingUtil;
|
||||
|
||||
class StopwatchPanel extends ClockPanel
|
||||
{
|
||||
@@ -57,7 +58,9 @@ class StopwatchPanel extends ClockPanel
|
||||
|
||||
contentContainer.add(lapsContainer);
|
||||
|
||||
IconButton lapButton = new IconButton(ClockTabPanel.LAP_ICON, ClockTabPanel.LAP_ICON_HOVER);
|
||||
JButton lapButton = new JButton(ClockTabPanel.LAP_ICON);
|
||||
lapButton.setRolloverIcon(ClockTabPanel.LAP_ICON_HOVER);
|
||||
SwingUtil.removeButtonDecorations(lapButton);
|
||||
lapButton.setPreferredSize(new Dimension(16, 14));
|
||||
lapButton.setToolTipText("Add lap time");
|
||||
|
||||
@@ -70,7 +73,9 @@ class StopwatchPanel extends ClockPanel
|
||||
|
||||
leftActions.add(lapButton);
|
||||
|
||||
IconButton deleteButton = new IconButton(ClockTabPanel.DELETE_ICON, ClockTabPanel.DELETE_ICON_HOVER);
|
||||
JButton deleteButton = new JButton(ClockTabPanel.DELETE_ICON);
|
||||
deleteButton.setRolloverIcon(ClockTabPanel.DELETE_ICON_HOVER);
|
||||
SwingUtil.removeButtonDecorations(deleteButton);
|
||||
deleteButton.setPreferredSize(new Dimension(16, 14));
|
||||
deleteButton.setToolTipText("Delete stopwatch");
|
||||
deleteButton.addActionListener(e -> clockManager.removeStopwatch(stopwatch));
|
||||
|
||||
@@ -25,7 +25,8 @@
|
||||
package net.runelite.client.plugins.timetracking.clocks;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import net.runelite.client.ui.components.IconButton;
|
||||
import javax.swing.JButton;
|
||||
import net.runelite.client.util.SwingUtil;
|
||||
|
||||
class TimerPanel extends ClockPanel
|
||||
{
|
||||
@@ -33,7 +34,9 @@ class TimerPanel extends ClockPanel
|
||||
{
|
||||
super(clockManager, timer, "timer", true);
|
||||
|
||||
IconButton deleteButton = new IconButton(ClockTabPanel.DELETE_ICON, ClockTabPanel.DELETE_ICON_HOVER);
|
||||
JButton deleteButton = new JButton(ClockTabPanel.DELETE_ICON);
|
||||
SwingUtil.removeButtonDecorations(deleteButton);
|
||||
deleteButton.setRolloverIcon(ClockTabPanel.DELETE_ICON_HOVER);
|
||||
deleteButton.setPreferredSize(new Dimension(16, 14));
|
||||
deleteButton.setToolTipText("Delete timer");
|
||||
deleteButton.addActionListener(e -> clockManager.removeTimer(timer));
|
||||
|
||||
@@ -1,71 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018, Daniel Teo <https://github.com/takuyakanbr>
|
||||
* 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.components;
|
||||
|
||||
import java.awt.Insets;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JButton;
|
||||
|
||||
/**
|
||||
* A button that consists of an icon, without any background, borders, or margins.
|
||||
*/
|
||||
public class IconButton extends JButton
|
||||
{
|
||||
public IconButton(ImageIcon icon)
|
||||
{
|
||||
this(icon, null);
|
||||
}
|
||||
|
||||
public IconButton(ImageIcon icon, ImageIcon hoverIcon)
|
||||
{
|
||||
setIcon(icon);
|
||||
setBorderPainted(false);
|
||||
setContentAreaFilled(false);
|
||||
setFocusPainted(false);
|
||||
setMargin(new Insets(0, 0, 0, 0));
|
||||
setOpaque(false);
|
||||
setRolloverEnabled(false);
|
||||
|
||||
if (hoverIcon != null)
|
||||
{
|
||||
addMouseListener(new MouseAdapter()
|
||||
{
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent e)
|
||||
{
|
||||
setIcon(hoverIcon);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseExited(MouseEvent e)
|
||||
{
|
||||
setIcon(icon);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user