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())
|
||||
{
|
||||
if (!hideUnhide(cid))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
JPanel item = new JPanel();
|
||||
item.setLayout(new BorderLayout());
|
||||
item.setMinimumSize(new Dimension(PANEL_WIDTH, 0));
|
||||
@@ -795,7 +800,7 @@ class ConfigPanel extends PluginPanel
|
||||
backButton.addActionListener(e -> pluginList.getMuxer().popState());
|
||||
mainPanel.add(backButton);
|
||||
|
||||
hideUnhide();
|
||||
revalidate();
|
||||
}
|
||||
|
||||
private Boolean parse(ConfigItem item, String value)
|
||||
@@ -860,7 +865,7 @@ class ConfigPanel extends PluginPanel
|
||||
|
||||
configManager.setConfiguration(cd.getGroup().value(), cid.getItem().keyName(), finalEnumSet);
|
||||
|
||||
hideUnhide();
|
||||
rebuild();
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
hideUnhide();
|
||||
enableDisable(component, cid);
|
||||
rebuild();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -961,78 +967,112 @@ class ConfigPanel extends PluginPanel
|
||||
return menuItem;
|
||||
}
|
||||
|
||||
private void hideUnhide()
|
||||
private boolean hideUnhide(ConfigItemDescriptor cid)
|
||||
{
|
||||
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 hide = !cid.getItem().hide().isEmpty();
|
||||
boolean show = false;
|
||||
|
||||
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;
|
||||
|
||||
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 (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();
|
||||
repaint();
|
||||
for (ConfigItemDescriptor cid2 : cd.getItems())
|
||||
{
|
||||
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)
|
||||
|
||||
@@ -137,17 +137,12 @@ public class DynamicGridLayout extends GridLayout
|
||||
{
|
||||
int i = r * ncols + c;
|
||||
|
||||
Component component = parent.getComponent(i);
|
||||
|
||||
if (component.isVisible())
|
||||
if (i < ncomponents)
|
||||
{
|
||||
if (i < ncomponents)
|
||||
{
|
||||
component.setBounds(x, y, w[c], h[r]);
|
||||
}
|
||||
|
||||
y += h[r] + vgap;
|
||||
parent.getComponent(i).setBounds(x, y, w[c], h[r]);
|
||||
}
|
||||
|
||||
y += h[r] + vgap;
|
||||
}
|
||||
|
||||
x += w[c] + hgap;
|
||||
@@ -163,7 +158,7 @@ public class DynamicGridLayout extends GridLayout
|
||||
*/
|
||||
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 ncols = getColumns();
|
||||
|
||||
@@ -220,19 +215,4 @@ public class DynamicGridLayout extends GridLayout
|
||||
insets.left + insets.right + nw + (ncols - 1) * getHgap(),
|
||||
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