Skip to content
This repository has been archived by the owner on Apr 8, 2023. It is now read-only.

Commit

Permalink
Merge pull request #2154 from Im2be/inventorysetups-sorted-combobox
Browse files Browse the repository at this point in the history
inventorysetups: Add sorting to the JComboBox
  • Loading branch information
stone-wall authored Dec 24, 2019
2 parents 0187672 + a079e16 commit 25d0cd9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@
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;
Expand Down Expand Up @@ -213,7 +215,7 @@ public void addInventorySetup()
SwingUtilities.invokeLater(() ->
{
inventorySetups.put(name, invSetup);
panel.addInventorySetup(name);
panel.addInventorySetupUnsorted(name);
panel.setCurrentInventorySetup(name);

updateConfig();
Expand Down Expand Up @@ -305,7 +307,7 @@ private void loadConfig()
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,19 @@ public void addInventorySetup(final String name)
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);
Expand Down Expand Up @@ -307,4 +320,4 @@ public final String getSelectedInventorySetup()
{
return (String) setupComboBox.getSelectedItem();
}
}
}

0 comments on commit 25d0cd9

Please sign in to comment.