2021-06-26 01:13:46 +00:00
|
|
|
package the.bytecode.club.bytecodeviewer.gui.components;
|
|
|
|
|
|
|
|
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
|
|
|
|
import org.fife.ui.rtextarea.RTextScrollPane;
|
|
|
|
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
|
2021-06-29 00:05:18 +00:00
|
|
|
import the.bytecode.club.bytecodeviewer.Configuration;
|
2021-07-06 23:08:08 +00:00
|
|
|
import the.bytecode.club.bytecodeviewer.GlobalHotKeys;
|
2021-06-26 01:13:46 +00:00
|
|
|
import the.bytecode.club.bytecodeviewer.Resources;
|
|
|
|
import the.bytecode.club.bytecodeviewer.gui.components.listeners.PressKeyListener;
|
|
|
|
import the.bytecode.club.bytecodeviewer.gui.components.listeners.ReleaseKeyListener;
|
2021-06-29 00:05:18 +00:00
|
|
|
import the.bytecode.club.bytecodeviewer.gui.theme.LAFTheme;
|
2021-06-30 22:27:23 +00:00
|
|
|
import the.bytecode.club.bytecodeviewer.translation.Translation;
|
|
|
|
import the.bytecode.club.bytecodeviewer.translation.components.TranslatedJCheckBox;
|
2021-06-26 01:13:46 +00:00
|
|
|
import the.bytecode.club.bytecodeviewer.util.JTextAreaUtils;
|
|
|
|
|
|
|
|
import javax.swing.*;
|
2021-06-28 00:02:56 +00:00
|
|
|
import javax.swing.text.BadLocationException;
|
2021-06-26 01:13:46 +00:00
|
|
|
import java.awt.*;
|
|
|
|
import java.awt.event.KeyEvent;
|
|
|
|
|
2021-06-26 03:33:06 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite *
|
|
|
|
* Copyright (C) 2014 Kalen 'Konloch' Kinloch - http://bytecodeviewer.com *
|
|
|
|
* *
|
|
|
|
* 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/>. *
|
|
|
|
***************************************************************************/
|
|
|
|
|
2021-06-26 01:13:46 +00:00
|
|
|
/**
|
|
|
|
* Searching on an RSyntaxTextArea using swing highlighting
|
|
|
|
*
|
|
|
|
* @author Konloch
|
|
|
|
* @since 6/25/2021
|
|
|
|
*/
|
|
|
|
public class SearchableRSyntaxTextArea extends RSyntaxTextArea
|
|
|
|
{
|
|
|
|
private final RTextScrollPane scrollPane = new RTextScrollPane(this);
|
|
|
|
private final JPanel searchPanel = new JPanel(new BorderLayout());
|
|
|
|
private final JTextField searchInput = new JTextField();
|
2021-06-30 22:27:23 +00:00
|
|
|
private final JCheckBox caseSensitiveSearch = new TranslatedJCheckBox("Exact", Translation.EXACT);
|
2021-06-26 02:42:54 +00:00
|
|
|
private final JLabel titleHeader = new JLabel("");
|
2021-06-29 00:05:18 +00:00
|
|
|
private final Color scrollBackground = new Color(0x3c3f41);
|
|
|
|
private final Color scrollForeground = new Color(0x575859);
|
2021-07-01 21:54:10 +00:00
|
|
|
private Runnable onCtrlS;
|
2021-06-26 01:13:46 +00:00
|
|
|
|
|
|
|
public SearchableRSyntaxTextArea()
|
|
|
|
{
|
2021-06-29 00:27:17 +00:00
|
|
|
if(Configuration.lafTheme == LAFTheme.DARK)
|
2021-06-29 00:05:18 +00:00
|
|
|
{
|
|
|
|
//this fixes the white border on the jScrollBar panes
|
|
|
|
scrollPane.getHorizontalScrollBar().setBackground(scrollBackground);
|
|
|
|
scrollPane.getHorizontalScrollBar().setForeground(scrollForeground);
|
|
|
|
scrollPane.getVerticalScrollBar().setBackground(scrollBackground);
|
|
|
|
scrollPane.getVerticalScrollBar().setForeground(scrollForeground);
|
|
|
|
}
|
|
|
|
|
2021-06-26 01:13:46 +00:00
|
|
|
setAntiAliasingEnabled(true);
|
|
|
|
|
|
|
|
scrollPane.setColumnHeaderView(searchPanel);
|
|
|
|
|
|
|
|
JButton searchNext = new JButton();
|
|
|
|
JButton searchPrev = new JButton();
|
|
|
|
JPanel buttonPane = new JPanel(new BorderLayout());
|
|
|
|
buttonPane.add(searchNext, BorderLayout.WEST);
|
|
|
|
buttonPane.add(searchPrev, BorderLayout.EAST);
|
|
|
|
searchNext.setIcon(Resources.nextIcon);
|
|
|
|
searchPrev.setIcon(Resources.prevIcon);
|
|
|
|
searchPanel.add(buttonPane, BorderLayout.WEST);
|
|
|
|
searchPanel.add(searchInput, BorderLayout.CENTER);
|
|
|
|
searchPanel.add(caseSensitiveSearch, BorderLayout.EAST);
|
|
|
|
|
|
|
|
searchNext.addActionListener(arg0 -> search(searchInput.getText(), true, caseSensitiveSearch.isSelected()));
|
|
|
|
searchPrev.addActionListener(arg0 -> search(searchInput.getText(), false, caseSensitiveSearch.isSelected()));
|
|
|
|
|
|
|
|
searchInput.addKeyListener(new ReleaseKeyListener(keyEvent ->
|
|
|
|
{
|
|
|
|
if (keyEvent.getKeyCode() == KeyEvent.VK_ENTER)
|
|
|
|
search(searchInput.getText(), true, caseSensitiveSearch.isSelected());
|
|
|
|
}));
|
|
|
|
|
|
|
|
addKeyListener(new PressKeyListener(keyEvent ->
|
|
|
|
{
|
|
|
|
if ((keyEvent.getKeyCode() == KeyEvent.VK_F) && ((keyEvent.getModifiers() & KeyEvent.CTRL_MASK) != 0))
|
|
|
|
searchInput.requestFocus();
|
|
|
|
|
2021-07-01 21:54:10 +00:00
|
|
|
if (onCtrlS != null && (keyEvent.getKeyCode() == KeyEvent.VK_S) && ((keyEvent.getModifiers() & KeyEvent.CTRL_MASK) != 0))
|
|
|
|
{
|
|
|
|
onCtrlS.run();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-07-06 23:08:08 +00:00
|
|
|
GlobalHotKeys.keyPressed(keyEvent);
|
2021-06-26 01:13:46 +00:00
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
public void search(String search, boolean forwardSearchDirection, boolean caseSensitiveSearch)
|
|
|
|
{
|
|
|
|
JTextAreaUtils.search(this, search, forwardSearchDirection, caseSensitiveSearch);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void highlight(String pattern, boolean caseSensitiveSearch)
|
|
|
|
{
|
|
|
|
JTextAreaUtils.highlight(this, pattern, caseSensitiveSearch);
|
|
|
|
}
|
|
|
|
|
2021-06-28 00:02:56 +00:00
|
|
|
public String getLineText(int line) {
|
|
|
|
try {
|
|
|
|
if (line < getLineCount()) {
|
|
|
|
int start = getLineStartOffset(line);
|
|
|
|
int end = getLineEndOffset(line);
|
|
|
|
return getText(start, end - start).trim();
|
|
|
|
}
|
|
|
|
} catch (BadLocationException ignored) { }
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2021-07-01 21:54:10 +00:00
|
|
|
public void setOnCtrlS(Runnable onCtrlS)
|
|
|
|
{
|
|
|
|
this.onCtrlS = onCtrlS;
|
|
|
|
}
|
|
|
|
|
2021-06-26 01:13:46 +00:00
|
|
|
public RTextScrollPane getScrollPane()
|
|
|
|
{
|
|
|
|
return scrollPane;
|
|
|
|
}
|
|
|
|
|
|
|
|
public JPanel getSearchPanel()
|
|
|
|
{
|
|
|
|
return searchPanel;
|
|
|
|
}
|
|
|
|
|
|
|
|
public JTextField getSearchInput()
|
|
|
|
{
|
|
|
|
return searchInput;
|
|
|
|
}
|
|
|
|
|
|
|
|
public JCheckBox getCaseSensitiveSearch()
|
|
|
|
{
|
|
|
|
return caseSensitiveSearch;
|
|
|
|
}
|
2021-06-26 02:42:54 +00:00
|
|
|
|
|
|
|
public JLabel getTitleHeader()
|
|
|
|
{
|
|
|
|
return titleHeader;
|
|
|
|
}
|
2021-07-01 21:54:10 +00:00
|
|
|
|
|
|
|
public Runnable getOnCtrlS()
|
|
|
|
{
|
|
|
|
return onCtrlS;
|
|
|
|
}
|
2021-06-26 01:13:46 +00:00
|
|
|
}
|