mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-09-25 07:41:07 +00:00
Added #2189 Search bar in replace character (+ replace references) window
This commit is contained in:
@@ -20,19 +20,28 @@ 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.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Container;
|
||||
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.DefaultListModel;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JList;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.ListSelectionModel;
|
||||
import javax.swing.event.DocumentEvent;
|
||||
import javax.swing.event.DocumentListener;
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
import javax.swing.event.ListSelectionListener;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -44,7 +53,13 @@ public class ReplaceCharacterDialog extends AppDialog {
|
||||
|
||||
private final JButton cancelButton = new JButton(translate("button.cancel"));
|
||||
|
||||
private final JComboBox<ComboBoxItem<CharacterTag>> charactersComboBox = new JComboBox<>();
|
||||
//private final JComboBox<ComboBoxItem<CharacterTag>> charactersComboBox = new JComboBox<>();
|
||||
|
||||
private final JList<ComboBoxItem<CharacterTag>> charactersListBox = new JList<>();
|
||||
|
||||
private final JTextField searchTextField = new JTextField(10);
|
||||
|
||||
private DefaultListModel<ComboBoxItem<CharacterTag>> fullModel = new DefaultListModel<>();
|
||||
|
||||
private int result = ERROR_OPTION;
|
||||
|
||||
@@ -52,13 +67,45 @@ public class ReplaceCharacterDialog extends AppDialog {
|
||||
super(owner);
|
||||
setSize(400, 150);
|
||||
setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
|
||||
setLayout(new BorderLayout());
|
||||
add(new JLabel(translate("replace.with")), BorderLayout.NORTH);
|
||||
Container cnt = getContentPane();
|
||||
cnt.setLayout(new BorderLayout());
|
||||
|
||||
JPanel topPanel = new JPanel(new BorderLayout());
|
||||
topPanel.add(new JLabel(translate("replace.with")), BorderLayout.WEST);
|
||||
|
||||
JPanel searchPanel = new JPanel(new FlowLayout());
|
||||
JLabel iconSearchLabel = new JLabel(View.getIcon("search16"));
|
||||
searchPanel.add(iconSearchLabel);
|
||||
searchPanel.add(searchTextField);
|
||||
topPanel.add(searchPanel, BorderLayout.EAST);
|
||||
|
||||
cnt.add(topPanel, BorderLayout.NORTH);
|
||||
|
||||
charactersComboBox.setPreferredSize(new Dimension(400, charactersComboBox.getPreferredSize().height));
|
||||
add(charactersComboBox, BorderLayout.CENTER);
|
||||
charactersListBox.setModel(new DefaultListModel<>());
|
||||
if (View.isOceanic()) {
|
||||
charactersListBox.setBackground(Color.white);
|
||||
}
|
||||
charactersListBox.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||
charactersListBox.addListSelectionListener(new ListSelectionListener() {
|
||||
@Override
|
||||
public void valueChanged(ListSelectionEvent e) {
|
||||
okButton.setEnabled(charactersListBox.getSelectedIndex() > -1);
|
||||
if (okButton.isEnabled()) {
|
||||
getRootPane().setDefaultButton(okButton);
|
||||
} else {
|
||||
getRootPane().setDefaultButton(null);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
okButton.setEnabled(false);
|
||||
|
||||
charactersComboBox.setRenderer(new CharacterTagListCellRenderer());
|
||||
JScrollPane sc = new JScrollPane(charactersListBox);
|
||||
sc.setPreferredSize(new Dimension(400,300));
|
||||
|
||||
cnt.add(sc, BorderLayout.CENTER);
|
||||
|
||||
charactersListBox.setCellRenderer(new CharacterTagListCellRenderer());
|
||||
|
||||
JPanel panButtons = new JPanel(new FlowLayout());
|
||||
okButton.addActionListener(this::okButtonActionPerformed);
|
||||
@@ -66,12 +113,50 @@ public class ReplaceCharacterDialog extends AppDialog {
|
||||
panButtons.add(okButton);
|
||||
panButtons.add(cancelButton);
|
||||
|
||||
add(panButtons, BorderLayout.SOUTH);
|
||||
cnt.add(panButtons, BorderLayout.SOUTH);
|
||||
|
||||
|
||||
searchTextField.getDocument().addDocumentListener(new DocumentListener() {
|
||||
@Override
|
||||
public void insertUpdate(DocumentEvent e) {
|
||||
update();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeUpdate(DocumentEvent e) {
|
||||
update();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changedUpdate(DocumentEvent e) {
|
||||
update();
|
||||
}
|
||||
|
||||
private void update() {
|
||||
String searchedText = searchTextField.getText();
|
||||
ComboBoxItem<CharacterTag> selectedValue = charactersListBox.getSelectedValue();
|
||||
DefaultListModel<ComboBoxItem<CharacterTag>> filteredModel = new DefaultListModel<>();
|
||||
int newSelectedIndex = -1;
|
||||
boolean isEmpty = searchedText.trim().isEmpty();
|
||||
for (int i = 0; i < fullModel.getSize(); i++) {
|
||||
ComboBoxItem<CharacterTag> element = fullModel.getElementAt(i);
|
||||
if (isEmpty || element.toString().toLowerCase().contains(searchedText.toLowerCase())) {
|
||||
filteredModel.addElement(element);
|
||||
if (selectedValue == element) {
|
||||
newSelectedIndex = filteredModel.size() - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
charactersListBox.setModel(filteredModel);
|
||||
if (newSelectedIndex != -1) {
|
||||
charactersListBox.setSelectedIndex(newSelectedIndex);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
setModalityType(ModalityType.APPLICATION_MODAL);
|
||||
View.setWindowIcon(this);
|
||||
setTitle(translate("dialog.title"));
|
||||
getRootPane().setDefaultButton(okButton);
|
||||
setTitle(translate("dialog.title"));
|
||||
pack();
|
||||
View.centerScreen(this);
|
||||
}
|
||||
@@ -91,20 +176,25 @@ public class ReplaceCharacterDialog extends AppDialog {
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
ComboBoxItem<CharacterTag> item = (ComboBoxItem<CharacterTag>) charactersComboBox.getSelectedItem();
|
||||
ComboBoxItem<CharacterTag> item = charactersListBox.getSelectedValue();
|
||||
if (item == null) {
|
||||
return null;
|
||||
}
|
||||
return item.getValue().getCharacterId();
|
||||
}
|
||||
|
||||
public int showDialog(SWF swf, int selectedCharacterId) {
|
||||
Map<Integer, CharacterTag> characters = swf.getCharacters();
|
||||
Map<Integer, CharacterTag> characters = swf.getCharacters();
|
||||
fullModel = new DefaultListModel<>();
|
||||
fullModel.clear();
|
||||
for (Integer key : characters.keySet()) {
|
||||
CharacterTag character = characters.get(key);
|
||||
int characterId = character.getCharacterId();
|
||||
if (characterId != selectedCharacterId) {
|
||||
charactersComboBox.addItem(new ComboBoxItem<>(character.getName(), character));
|
||||
if (characterId != selectedCharacterId) {
|
||||
fullModel.addElement(new ComboBoxItem<>(character.getName(), character));
|
||||
}
|
||||
}
|
||||
charactersListBox.setModel(fullModel);
|
||||
|
||||
setVisible(true);
|
||||
return result;
|
||||
|
||||
Reference in New Issue
Block a user