configpanel: Add on off toggle in the title area

This commit is contained in:
Owain van Brakel
2019-10-21 20:03:55 +02:00
parent e9fd279a20
commit ef1d57a2ce
2 changed files with 11 additions and 12 deletions

View File

@@ -479,6 +479,13 @@ public class ConfigPanel extends PluginPanel
title.setToolTipText("<html>" + name + ":<br>" + listItem.getDescription() + "</html>");
topPanel.add(title);
IconButton toggleButton = new IconButton(PluginListItem.OFF_SWITCHER);
toggleButton.setPreferredSize(new Dimension(25, 0));
listItem.updateToggleButton(toggleButton);
listItem.attachToggleButtonListener(toggleButton);
topPanel.add(toggleButton, BorderLayout.EAST);
final Map<String, JPanel> sectionWidgets = new HashMap<>();
final Map<String, JPanel> titleSectionWidgets = new HashMap<>();

View File

@@ -60,7 +60,7 @@ public class PluginListItem extends JPanel
private static final ImageIcon CONFIG_ICON;
private static final ImageIcon CONFIG_ICON_HOVER;
private static final ImageIcon ON_SWITCHER;
private static final ImageIcon OFF_SWITCHER;
public static final ImageIcon OFF_SWITCHER;
private static final ImageIcon ON_STAR;
private static final ImageIcon OFF_STAR;
@@ -93,6 +93,7 @@ public class PluginListItem extends JPanel
private final IconButton configButton = new IconButton(CONFIG_ICON, CONFIG_ICON_HOVER);
private final IconButton toggleButton = new IconButton(OFF_SWITCHER);
@Getter
private boolean isPluginEnabled = false;
@Getter
@@ -214,7 +215,7 @@ public class PluginListItem extends JPanel
buttonPanel.add(toggleButton);
}
private void attachToggleButtonListener(IconButton button)
void attachToggleButtonListener(IconButton button)
{
// no need for a listener if there is no plugin to enable / disable
if (plugin == null)
@@ -239,15 +240,6 @@ public class PluginListItem extends JPanel
});
}
IconButton createToggleButton()
{
IconButton button = new IconButton(OFF_SWITCHER);
button.setPreferredSize(new Dimension(25, 0));
updateToggleButton(button);
attachToggleButtonListener(button);
return button;
}
void setPluginEnabled(boolean enabled)
{
isPluginEnabled = enabled;
@@ -282,7 +274,7 @@ public class PluginListItem extends JPanel
isHidden = hidden;
}
private void updateToggleButton(IconButton button)
void updateToggleButton(IconButton button)
{
button.setIcon(isPluginEnabled ? ON_SWITCHER : OFF_SWITCHER);
button.setToolTipText(isPluginEnabled ? "Disable plugin" : "Enable plugin");