config: Fix issue with hide / unhide and reintroduce enabledBy and disabledBy
This commit is contained in:
@@ -443,6 +443,11 @@ class ConfigPanel extends PluginPanel
|
|||||||
|
|
||||||
for (ConfigItemDescriptor cid : cd.getItems())
|
for (ConfigItemDescriptor cid : cd.getItems())
|
||||||
{
|
{
|
||||||
|
if (!hideUnhide(cid))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
JPanel item = new JPanel();
|
JPanel item = new JPanel();
|
||||||
item.setLayout(new BorderLayout());
|
item.setLayout(new BorderLayout());
|
||||||
item.setMinimumSize(new Dimension(PANEL_WIDTH, 0));
|
item.setMinimumSize(new Dimension(PANEL_WIDTH, 0));
|
||||||
@@ -795,7 +800,7 @@ class ConfigPanel extends PluginPanel
|
|||||||
backButton.addActionListener(e -> pluginList.getMuxer().popState());
|
backButton.addActionListener(e -> pluginList.getMuxer().popState());
|
||||||
mainPanel.add(backButton);
|
mainPanel.add(backButton);
|
||||||
|
|
||||||
hideUnhide();
|
revalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Boolean parse(ConfigItem item, String value)
|
private Boolean parse(ConfigItem item, String value)
|
||||||
@@ -860,7 +865,7 @@ class ConfigPanel extends PluginPanel
|
|||||||
|
|
||||||
configManager.setConfiguration(cd.getGroup().value(), cid.getItem().keyName(), finalEnumSet);
|
configManager.setConfiguration(cd.getGroup().value(), cid.getItem().keyName(), finalEnumSet);
|
||||||
|
|
||||||
hideUnhide();
|
rebuild();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void changeConfiguration(Component component, ConfigDescriptor cd, ConfigItemDescriptor cid)
|
private void changeConfiguration(Component component, ConfigDescriptor cd, ConfigItemDescriptor cid)
|
||||||
@@ -911,7 +916,8 @@ class ConfigPanel extends PluginPanel
|
|||||||
configManager.setConfiguration(cd.getGroup().value(), cid.getItem().keyName(), hotkeyButton.getValue());
|
configManager.setConfiguration(cd.getGroup().value(), cid.getItem().keyName(), hotkeyButton.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
hideUnhide();
|
enableDisable(component, cid);
|
||||||
|
rebuild();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -961,78 +967,112 @@ class ConfigPanel extends PluginPanel
|
|||||||
return menuItem;
|
return menuItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void hideUnhide()
|
private boolean hideUnhide(ConfigItemDescriptor cid)
|
||||||
{
|
{
|
||||||
ConfigDescriptor cd = pluginConfig.getConfigDescriptor();
|
ConfigDescriptor cd = pluginConfig.getConfigDescriptor();
|
||||||
|
|
||||||
for (ConfigItemDescriptor cid : cd.getItems())
|
boolean unhide = cid.getItem().hidden();
|
||||||
|
boolean hide = !cid.getItem().hide().isEmpty();
|
||||||
|
|
||||||
|
if (unhide || hide)
|
||||||
{
|
{
|
||||||
boolean unhide = cid.getItem().hidden();
|
boolean show = false;
|
||||||
boolean hide = !cid.getItem().hide().isEmpty();
|
|
||||||
|
|
||||||
if (unhide || hide)
|
List<String> itemHide = Splitter
|
||||||
|
.onPattern("\\|\\|")
|
||||||
|
.trimResults()
|
||||||
|
.omitEmptyStrings()
|
||||||
|
.splitToList(String.format("%s || %s", cid.getItem().unhide(), cid.getItem().hide()));
|
||||||
|
|
||||||
|
for (ConfigItemDescriptor cid2 : cd.getItems())
|
||||||
{
|
{
|
||||||
boolean show = false;
|
if (itemHide.contains(cid2.getItem().keyName()))
|
||||||
|
|
||||||
List<String> itemHide = Splitter
|
|
||||||
.onPattern("\\|\\|")
|
|
||||||
.trimResults()
|
|
||||||
.omitEmptyStrings()
|
|
||||||
.splitToList(String.format("%s || %s", cid.getItem().unhide(), cid.getItem().hide()));
|
|
||||||
|
|
||||||
for (ConfigItemDescriptor cid2 : cd.getItems())
|
|
||||||
{
|
{
|
||||||
if (itemHide.contains(cid2.getItem().keyName()))
|
if (cid2.getType() == boolean.class)
|
||||||
{
|
{
|
||||||
if (cid2.getType() == boolean.class)
|
show = Boolean.parseBoolean(configManager.getConfiguration(cd.getGroup().value(), cid2.getItem().keyName()));
|
||||||
|
}
|
||||||
|
else if (cid2.getType().isEnum())
|
||||||
|
{
|
||||||
|
Class<? extends Enum> type = (Class<? extends Enum>) cid2.getType();
|
||||||
|
try
|
||||||
{
|
{
|
||||||
show = Boolean.parseBoolean(configManager.getConfiguration(cd.getGroup().value(), cid2.getItem().keyName()));
|
Enum selectedItem = Enum.valueOf(type, configManager.getConfiguration(cd.getGroup().value(), cid2.getItem().keyName()));
|
||||||
|
if (!cid.getItem().unhideValue().equals(""))
|
||||||
|
{
|
||||||
|
List<String> unhideValue = Splitter
|
||||||
|
.onPattern("\\|\\|")
|
||||||
|
.trimResults()
|
||||||
|
.omitEmptyStrings()
|
||||||
|
.splitToList(cid.getItem().unhideValue());
|
||||||
|
|
||||||
|
show = unhideValue.contains(selectedItem.toString());
|
||||||
|
}
|
||||||
|
else if (!cid.getItem().hideValue().equals(""))
|
||||||
|
{
|
||||||
|
List<String> hideValue = Splitter
|
||||||
|
.onPattern("\\|\\|")
|
||||||
|
.trimResults()
|
||||||
|
.omitEmptyStrings()
|
||||||
|
.splitToList(cid.getItem().hideValue());
|
||||||
|
|
||||||
|
show = !hideValue.contains(selectedItem.toString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (cid2.getType().isEnum())
|
catch (IllegalArgumentException ignored)
|
||||||
{
|
{
|
||||||
Class<? extends Enum> type = (Class<? extends Enum>) cid2.getType();
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Enum selectedItem = Enum.valueOf(type, configManager.getConfiguration(cd.getGroup().value(), cid2.getItem().keyName()));
|
|
||||||
if (!cid.getItem().unhideValue().equals(""))
|
|
||||||
{
|
|
||||||
List<String> unhideValue = Splitter
|
|
||||||
.onPattern("\\|\\|")
|
|
||||||
.trimResults()
|
|
||||||
.omitEmptyStrings()
|
|
||||||
.splitToList(cid.getItem().unhideValue());
|
|
||||||
|
|
||||||
show = unhideValue.contains(selectedItem.toString());
|
|
||||||
}
|
|
||||||
else if (!cid.getItem().hideValue().equals(""))
|
|
||||||
{
|
|
||||||
List<String> hideValue = Splitter
|
|
||||||
.onPattern("\\|\\|")
|
|
||||||
.trimResults()
|
|
||||||
.omitEmptyStrings()
|
|
||||||
.splitToList(cid.getItem().hideValue());
|
|
||||||
|
|
||||||
show = !hideValue.contains(selectedItem.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (IllegalArgumentException ignored)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Component comp = findComponentByName(mainPanel, cid.getItem().keyName());
|
return (!unhide || show) && (!hide || !show);
|
||||||
|
}
|
||||||
|
|
||||||
if (comp != null)
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void enableDisable(Component component, ConfigItemDescriptor cid)
|
||||||
|
{
|
||||||
|
ConfigDescriptor cd = pluginConfig.getConfigDescriptor();
|
||||||
|
|
||||||
|
if (component instanceof JCheckBox)
|
||||||
|
{
|
||||||
|
JCheckBox checkbox = (JCheckBox) component;
|
||||||
|
|
||||||
|
for (ConfigItemDescriptor cid2 : cd.getItems())
|
||||||
|
{
|
||||||
|
if (checkbox.isSelected())
|
||||||
{
|
{
|
||||||
comp.setVisible((!unhide || show) && (!hide || !show));
|
if (cid2.getItem().enabledBy().contains(cid.getItem().keyName()))
|
||||||
|
{
|
||||||
|
configManager.setConfiguration(cd.getGroup().value(), cid2.getItem().keyName(), "true");
|
||||||
|
}
|
||||||
|
else if (cid2.getItem().disabledBy().contains(cid.getItem().keyName()))
|
||||||
|
{
|
||||||
|
configManager.setConfiguration(cd.getGroup().value(), cid2.getItem().keyName(), "false");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (component instanceof JComboBox)
|
||||||
|
{
|
||||||
|
JComboBox jComboBox = (JComboBox) component;
|
||||||
|
|
||||||
revalidate();
|
for (ConfigItemDescriptor cid2 : cd.getItems())
|
||||||
repaint();
|
{
|
||||||
|
String changedVal = ((Enum) jComboBox.getSelectedItem()).name();
|
||||||
|
|
||||||
|
if (cid2.getItem().enabledBy().contains(cid.getItem().keyName()) && cid2.getItem().enabledByValue().equals(changedVal))
|
||||||
|
{
|
||||||
|
configManager.setConfiguration(cd.getGroup().value(), cid2.getItem().keyName(), "true");
|
||||||
|
}
|
||||||
|
else if (cid2.getItem().disabledBy().contains(cid.getItem().keyName()) && cid2.getItem().disabledByValue().equals(changedVal))
|
||||||
|
{
|
||||||
|
configManager.setConfiguration(cd.getGroup().value(), cid2.getItem().keyName(), "false");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String htmlLabel(String key, String value)
|
private static String htmlLabel(String key, String value)
|
||||||
|
|||||||
@@ -137,17 +137,12 @@ public class DynamicGridLayout extends GridLayout
|
|||||||
{
|
{
|
||||||
int i = r * ncols + c;
|
int i = r * ncols + c;
|
||||||
|
|
||||||
Component component = parent.getComponent(i);
|
if (i < ncomponents)
|
||||||
|
|
||||||
if (component.isVisible())
|
|
||||||
{
|
{
|
||||||
if (i < ncomponents)
|
parent.getComponent(i).setBounds(x, y, w[c], h[r]);
|
||||||
{
|
|
||||||
component.setBounds(x, y, w[c], h[r]);
|
|
||||||
}
|
|
||||||
|
|
||||||
y += h[r] + vgap;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
y += h[r] + vgap;
|
||||||
}
|
}
|
||||||
|
|
||||||
x += w[c] + hgap;
|
x += w[c] + hgap;
|
||||||
@@ -163,7 +158,7 @@ public class DynamicGridLayout extends GridLayout
|
|||||||
*/
|
*/
|
||||||
private Dimension calculateSize(final Container parent, final Function<Component, Dimension> sizer)
|
private Dimension calculateSize(final Container parent, final Function<Component, Dimension> sizer)
|
||||||
{
|
{
|
||||||
final int ncomponents = getVisibleComponents(parent);;
|
final int ncomponents = parent.getComponentCount();
|
||||||
int nrows = getRows();
|
int nrows = getRows();
|
||||||
int ncols = getColumns();
|
int ncols = getColumns();
|
||||||
|
|
||||||
@@ -220,19 +215,4 @@ public class DynamicGridLayout extends GridLayout
|
|||||||
insets.left + insets.right + nw + (ncols - 1) * getHgap(),
|
insets.left + insets.right + nw + (ncols - 1) * getHgap(),
|
||||||
insets.top + insets.bottom + nh + (nrows - 1) * getVgap());
|
insets.top + insets.bottom + nh + (nrows - 1) * getVgap());
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getVisibleComponents(Container parent)
|
|
||||||
{
|
|
||||||
int visible = 0;
|
|
||||||
|
|
||||||
for (Component c : parent.getComponents())
|
|
||||||
{
|
|
||||||
if (c.isVisible())
|
|
||||||
{
|
|
||||||
visible++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return visible;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user