Display user-defined materials with (ud) prefix
This commit is contained in:
parent
faeec8e854
commit
829109ee2d
@ -172,7 +172,17 @@ public class MaterialPanel extends JPanel implements Invalidatable, Invalidating
|
|||||||
public static SearchableAndCategorizableComboBox<MaterialGroup, Material> createComboBox(
|
public static SearchableAndCategorizableComboBox<MaterialGroup, Material> createComboBox(
|
||||||
MaterialGroup[] allGroups, Material[] materials, Component... extraCategoryWidgets) {
|
MaterialGroup[] allGroups, Material[] materials, Component... extraCategoryWidgets) {
|
||||||
final Map<MaterialGroup, Material[]> materialGroupMap = createMaterialGroupMap(allGroups, materials);
|
final Map<MaterialGroup, Material[]> materialGroupMap = createMaterialGroupMap(allGroups, materials);
|
||||||
return new SearchableAndCategorizableComboBox<>(materialGroupMap, trans.get("MaterialPanel.MaterialComboBox.placeholder"), extraCategoryWidgets);
|
return new SearchableAndCategorizableComboBox<>(materialGroupMap,
|
||||||
|
trans.get("MaterialPanel.MaterialComboBox.placeholder"), extraCategoryWidgets) {
|
||||||
|
@Override
|
||||||
|
public String getDisplayString(Material item) {
|
||||||
|
String baseText = item.toString();
|
||||||
|
if (item.isUserDefined()) {
|
||||||
|
baseText = "(ud) " + baseText;
|
||||||
|
}
|
||||||
|
return baseText;
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void updateComboBoxItems(SearchableAndCategorizableComboBox<MaterialGroup, Material> comboBox,
|
public static void updateComboBoxItems(SearchableAndCategorizableComboBox<MaterialGroup, Material> comboBox,
|
||||||
|
@ -85,6 +85,7 @@ public class SearchableAndCategorizableComboBox<E, T> extends JComboBox<T> {
|
|||||||
this.extraCategoryWidgets = extraCategoryWidgets;
|
this.extraCategoryWidgets = extraCategoryWidgets;
|
||||||
this.placeHolderText = placeHolderText;
|
this.placeHolderText = placeHolderText;
|
||||||
updateItems(itemGroupMap);
|
updateItems(itemGroupMap);
|
||||||
|
setupMainRenderer();
|
||||||
|
|
||||||
// Add key listener for the search fields
|
// Add key listener for the search fields
|
||||||
searchFieldCategory.addKeyListener(new KeyAdapter() {
|
searchFieldCategory.addKeyListener(new KeyAdapter() {
|
||||||
@ -155,6 +156,19 @@ public class SearchableAndCategorizableComboBox<E, T> extends JComboBox<T> {
|
|||||||
textSelectionBackground = GUIUtil.getUITheme().getTextSelectionBackgroundColor();
|
textSelectionBackground = GUIUtil.getUITheme().getTextSelectionBackgroundColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setupMainRenderer() {
|
||||||
|
setRenderer(new DefaultListCellRenderer() {
|
||||||
|
@Override
|
||||||
|
public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
|
||||||
|
JLabel label = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
|
||||||
|
if (value != null) {
|
||||||
|
label.setText(getDisplayString((T) value));
|
||||||
|
}
|
||||||
|
return label;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public void updateItems(Map<E, T[]> itemGroupMap) {
|
public void updateItems(Map<E, T[]> itemGroupMap) {
|
||||||
this.itemGroupMap = itemGroupMap;
|
this.itemGroupMap = itemGroupMap;
|
||||||
this.allItems = extractItemsFromMap(itemGroupMap);
|
this.allItems = extractItemsFromMap(itemGroupMap);
|
||||||
@ -197,7 +211,7 @@ public class SearchableAndCategorizableComboBox<E, T> extends JComboBox<T> {
|
|||||||
|
|
||||||
if (itemsForGroup != null) {
|
if (itemsForGroup != null) {
|
||||||
for (T item : itemsForGroup) {
|
for (T item : itemsForGroup) {
|
||||||
JMenuItem itemMenu = new JMenuItem(item.toString()) {
|
JMenuItem itemMenu = new JMenuItem(getDisplayString(item)) {
|
||||||
@Override
|
@Override
|
||||||
public void paintComponent(Graphics g) {
|
public void paintComponent(Graphics g) {
|
||||||
super.paintComponent(g);
|
super.paintComponent(g);
|
||||||
@ -240,6 +254,10 @@ public class SearchableAndCategorizableComboBox<E, T> extends JComboBox<T> {
|
|||||||
return menu;
|
return menu;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getDisplayString(T item) {
|
||||||
|
return item.toString();
|
||||||
|
}
|
||||||
|
|
||||||
private JList<T> createFilteredList() {
|
private JList<T> createFilteredList() {
|
||||||
JList<T> list = new JList<>(); // Don't fill the list with the items yet, this will be done during filtering
|
JList<T> list = new JList<>(); // Don't fill the list with the items yet, this will be done during filtering
|
||||||
|
|
||||||
@ -248,7 +266,7 @@ public class SearchableAndCategorizableComboBox<E, T> extends JComboBox<T> {
|
|||||||
public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
|
public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
|
||||||
JLabel label = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
|
JLabel label = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
|
||||||
T item = (T) value;
|
T item = (T) value;
|
||||||
String itemName = item.toString();
|
String itemName = getDisplayString(item);
|
||||||
|
|
||||||
// If the item is currently selected, draw a checkmark before it
|
// If the item is currently selected, draw a checkmark before it
|
||||||
if (item.equals(getSelectedItem())) {
|
if (item.equals(getSelectedItem())) {
|
||||||
@ -337,7 +355,7 @@ public class SearchableAndCategorizableComboBox<E, T> extends JComboBox<T> {
|
|||||||
SortedListModel<T> filteredModel = new SortedListModel<>();
|
SortedListModel<T> filteredModel = new SortedListModel<>();
|
||||||
|
|
||||||
for (T item : this.allItems) {
|
for (T item : this.allItems) {
|
||||||
if (item.toString().toLowerCase().contains(searchText)) {
|
if (getDisplayString(item).toLowerCase().contains(searchText)) {
|
||||||
filteredModel.add(item);
|
filteredModel.add(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user