diff --git a/CHANGELOG.md b/CHANGELOG.md index ee9f55d50..81ae2f667 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file. - Hilight clipboard panel on copy/cut action for a few seconds - Drag and drop to move/copy tags in the tag list view - Setting for enabling placing Define tags into DefineSprite +- Icons for tags in replace character dialog ## [16.2.0] - 2022-11-08 ### Added diff --git a/src/com/jpexs/decompiler/flash/gui/ReplaceCharacterDialog.java b/src/com/jpexs/decompiler/flash/gui/ReplaceCharacterDialog.java index 0b3b25db3..7be48f4dd 100644 --- a/src/com/jpexs/decompiler/flash/gui/ReplaceCharacterDialog.java +++ b/src/com/jpexs/decompiler/flash/gui/ReplaceCharacterDialog.java @@ -17,17 +17,21 @@ package com.jpexs.decompiler.flash.gui; import com.jpexs.decompiler.flash.SWF; +import com.jpexs.decompiler.flash.gui.tagtree.AbstractTagTree; import com.jpexs.decompiler.flash.tags.base.CharacterTag; import java.awt.BorderLayout; +import java.awt.Component; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.Window; import java.awt.event.ActionEvent; import java.util.Map; +import javax.swing.DefaultListCellRenderer; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JDialog; import javax.swing.JLabel; +import javax.swing.JList; import javax.swing.JPanel; /** @@ -40,7 +44,7 @@ public class ReplaceCharacterDialog extends AppDialog { private final JButton cancelButton = new JButton(translate("button.cancel")); - private final JComboBox> charactersComboBox = new JComboBox<>(); + private final JComboBox> charactersComboBox = new JComboBox<>(); private int result = ERROR_OPTION; @@ -53,6 +57,9 @@ public class ReplaceCharacterDialog extends AppDialog { charactersComboBox.setPreferredSize(new Dimension(400, charactersComboBox.getPreferredSize().height)); add(charactersComboBox, BorderLayout.CENTER); + + charactersComboBox.setRenderer(new CharacterTagListCellRenderer()); + JPanel panButtons = new JPanel(new FlowLayout()); okButton.addActionListener(this::okButtonActionPerformed); @@ -86,8 +93,8 @@ public class ReplaceCharacterDialog extends AppDialog { } @SuppressWarnings("unchecked") - ComboBoxItem item = (ComboBoxItem) charactersComboBox.getSelectedItem(); - return item.getValue(); + ComboBoxItem item = (ComboBoxItem) charactersComboBox.getSelectedItem(); + return item.getValue().getCharacterId(); } public int showDialog(SWF swf, int selectedCharacterId) { @@ -96,7 +103,7 @@ public class ReplaceCharacterDialog extends AppDialog { CharacterTag character = characters.get(key); int characterId = character.getCharacterId(); if (characterId != selectedCharacterId) { - charactersComboBox.addItem(new ComboBoxItem<>(character.getName(), characterId)); + charactersComboBox.addItem(new ComboBoxItem<>(character.getName(), character)); } } @@ -104,3 +111,17 @@ public class ReplaceCharacterDialog extends AppDialog { return result; } } + +class CharacterTagListCellRenderer extends DefaultListCellRenderer { + + @Override + public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { + Component component = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); + if (component instanceof JLabel) { + JLabel label = (JLabel) component; + ComboBoxItem comboboxItem = (ComboBoxItem) value; + label.setIcon(AbstractTagTree.getIconForType(AbstractTagTree.getTreeNodeType(comboboxItem.getValue()))); + } + return component; + } +} \ No newline at end of file