Add search bar to ConfigPanel
Add search bar to ConfigPanel that will search plugin configuration names and filter them based on input. Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
This commit is contained in:
@@ -34,11 +34,15 @@ import java.awt.event.ActionEvent;
|
|||||||
import java.awt.event.FocusEvent;
|
import java.awt.event.FocusEvent;
|
||||||
import java.awt.event.FocusListener;
|
import java.awt.event.FocusListener;
|
||||||
import java.awt.event.ItemEvent;
|
import java.awt.event.ItemEvent;
|
||||||
|
import java.awt.event.KeyAdapter;
|
||||||
|
import java.awt.event.KeyEvent;
|
||||||
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.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.TreeMap;
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
import javax.swing.JCheckBox;
|
import javax.swing.JCheckBox;
|
||||||
import javax.swing.JColorChooser;
|
import javax.swing.JColorChooser;
|
||||||
@@ -68,6 +72,7 @@ public class ConfigPanel extends PluginPanel
|
|||||||
private static final int SPINNER_FIELD_WIDTH = 6;
|
private static final int SPINNER_FIELD_WIDTH = 6;
|
||||||
|
|
||||||
private final ConfigManager configManager;
|
private final ConfigManager configManager;
|
||||||
|
private JTextField searchBar;
|
||||||
|
|
||||||
public ConfigPanel(ConfigManager configManager)
|
public ConfigPanel(ConfigManager configManager)
|
||||||
{
|
{
|
||||||
@@ -76,10 +81,24 @@ public class ConfigPanel extends PluginPanel
|
|||||||
populateConfig();
|
populateConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void invalidate()
|
||||||
|
{
|
||||||
|
super.invalidate();
|
||||||
|
|
||||||
|
if (searchBar != null)
|
||||||
|
{
|
||||||
|
searchBar.requestFocusInWindow();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void populateConfig()
|
private void populateConfig()
|
||||||
{
|
{
|
||||||
removeAll();
|
removeAll();
|
||||||
add(new JLabel("Plugin Configuration", SwingConstants.CENTER));
|
add(new JLabel("Plugin Configuration", SwingConstants.CENTER));
|
||||||
|
searchBar = new JTextField();
|
||||||
|
add(searchBar);
|
||||||
|
final Map<String, JPanel> children = new TreeMap<>();
|
||||||
|
|
||||||
configManager.getConfigProxies().stream()
|
configManager.getConfigProxies().stream()
|
||||||
.map(configManager::getConfigDescriptor)
|
.map(configManager::getConfigDescriptor)
|
||||||
@@ -91,9 +110,34 @@ public class ConfigPanel extends PluginPanel
|
|||||||
JButton viewGroupItemsButton = new JButton(cd.getGroup().name());
|
JButton viewGroupItemsButton = new JButton(cd.getGroup().name());
|
||||||
viewGroupItemsButton.addActionListener(ae -> openGroupConfigPanel(cd, configManager));
|
viewGroupItemsButton.addActionListener(ae -> openGroupConfigPanel(cd, configManager));
|
||||||
groupPanel.add(viewGroupItemsButton);
|
groupPanel.add(viewGroupItemsButton);
|
||||||
|
children.put(cd.getGroup().name(), groupPanel);
|
||||||
add(groupPanel);
|
add(groupPanel);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
searchBar.addKeyListener(new KeyAdapter()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void keyTyped(KeyEvent e)
|
||||||
|
{
|
||||||
|
children.forEach((key, value) ->
|
||||||
|
{
|
||||||
|
final String text = searchBar.getText().toLowerCase();
|
||||||
|
final String labelToSearch = key.toLowerCase();
|
||||||
|
|
||||||
|
if (text.isEmpty() || labelToSearch.contains(text))
|
||||||
|
{
|
||||||
|
add(value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
remove(value);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
revalidate();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
revalidate();
|
revalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -284,4 +328,4 @@ public class ConfigPanel extends PluginPanel
|
|||||||
populateConfig();
|
populateConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user