Merge pull request #2154 from Im2be/inventorysetups-sorted-combobox
inventorysetups: Add sorting to the JComboBox
This commit is contained in:
@@ -32,10 +32,12 @@ import java.awt.Color;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import javax.swing.JOptionPane;
|
||||
@@ -213,7 +215,7 @@ public class InventorySetupPlugin extends Plugin
|
||||
SwingUtilities.invokeLater(() ->
|
||||
{
|
||||
inventorySetups.put(name, invSetup);
|
||||
panel.addInventorySetup(name);
|
||||
panel.addInventorySetupUnsorted(name);
|
||||
panel.setCurrentInventorySetup(name);
|
||||
|
||||
updateConfig();
|
||||
@@ -305,7 +307,7 @@ public class InventorySetupPlugin extends Plugin
|
||||
inventorySetups.putAll(gson.fromJson(json, type));
|
||||
}
|
||||
|
||||
for (final String key : inventorySetups.keySet())
|
||||
for (final String key : inventorySetups.keySet().stream().sorted(Comparator.comparing(String::toLowerCase)).collect(Collectors.toList()))
|
||||
{
|
||||
panel.addInventorySetup(key);
|
||||
}
|
||||
|
||||
@@ -275,6 +275,19 @@ public class InventorySetupPluginPanel extends PluginPanel
|
||||
setupComboBox.addItem(name);
|
||||
}
|
||||
|
||||
public void addInventorySetupUnsorted(final String name)
|
||||
{
|
||||
for (int i = 1; i < setupComboBox.getItemCount(); ++i)
|
||||
{
|
||||
if (setupComboBox.getItemAt(i).toLowerCase().compareTo(name.toLowerCase()) > 0)
|
||||
{
|
||||
setupComboBox.insertItemAt(name, i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
setupComboBox.addItem(name);
|
||||
}
|
||||
|
||||
public void removeInventorySetup(final String name)
|
||||
{
|
||||
setupComboBox.removeItem(name);
|
||||
@@ -307,4 +320,4 @@ public class InventorySetupPluginPanel extends PluginPanel
|
||||
{
|
||||
return (String) setupComboBox.getSelectedItem();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user