mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-06-20 12:05:40 +00:00
112 lines
3.2 KiB
Java
112 lines
3.2 KiB
Java
/*
|
|
* Copyright (C) 2022-2023 JPEXS
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
package com.jpexs.decompiler.flash.gui;
|
|
|
|
import java.awt.BorderLayout;
|
|
import java.awt.Cursor;
|
|
import java.awt.event.ActionEvent;
|
|
import java.awt.event.ActionListener;
|
|
import java.awt.event.MouseAdapter;
|
|
import java.awt.event.MouseEvent;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import javax.swing.JLabel;
|
|
import javax.swing.JPanel;
|
|
import javax.swing.JTextField;
|
|
import javax.swing.event.DocumentEvent;
|
|
import javax.swing.event.DocumentListener;
|
|
|
|
/**
|
|
*
|
|
* @author JPEXS
|
|
*/
|
|
public class QuickTreeFindPanel extends JPanel {
|
|
|
|
private List<ActionListener> listeners = new ArrayList<>();
|
|
|
|
private JTextField filterField = new MyTextField("");
|
|
|
|
public QuickTreeFindPanel() {
|
|
|
|
filterField.getDocument().addDocumentListener(new DocumentListener() {
|
|
@Override
|
|
public void changedUpdate(DocumentEvent e) {
|
|
warn();
|
|
}
|
|
|
|
@Override
|
|
public void removeUpdate(DocumentEvent e) {
|
|
warn();
|
|
}
|
|
|
|
@Override
|
|
public void insertUpdate(DocumentEvent e) {
|
|
warn();
|
|
}
|
|
|
|
public void warn() {
|
|
fireAction();
|
|
}
|
|
});
|
|
|
|
setLayout(new BorderLayout());
|
|
add(filterField, BorderLayout.CENTER);
|
|
add(new JLabel(View.getIcon("search16")), BorderLayout.WEST);
|
|
JLabel closeSearchButton = new JLabel(View.getIcon("cancel16"));
|
|
closeSearchButton.addMouseListener(new MouseAdapter() {
|
|
@Override
|
|
public void mouseClicked(MouseEvent e) {
|
|
filterField.setText("");
|
|
setVisible(false);
|
|
fireAction();
|
|
}
|
|
});
|
|
closeSearchButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
|
add(closeSearchButton, BorderLayout.EAST);
|
|
setVisible(false);
|
|
}
|
|
|
|
private void fireAction() {
|
|
for (ActionListener listener : listeners) {
|
|
listener.actionPerformed(new ActionEvent(this, 0, ""));
|
|
}
|
|
}
|
|
|
|
public void addActionListener(ActionListener listener) {
|
|
listeners.add(listener);
|
|
}
|
|
|
|
public void removeActionListener(ActionListener listener) {
|
|
listeners.remove(listener);
|
|
}
|
|
|
|
public String getFilter() {
|
|
return filterField.getText().trim();
|
|
}
|
|
|
|
@Override
|
|
public void setVisible(boolean aFlag) {
|
|
super.setVisible(aFlag);
|
|
if (aFlag) {
|
|
filterField.requestFocusInWindow();
|
|
} else {
|
|
filterField.setText("");
|
|
}
|
|
}
|
|
|
|
}
|