use of org.fife.ui.rtextarea.RTextScrollPane in project bytecode-viewer by Konloch.
the class PaneUpdaterThread method run.
public void run() {
try {
final byte[] b = BytecodeViewer.getClassBytes(viewer.container, viewer.cn.name + ".class");
if (decompiler != Decompiler.HEXCODE) {
RSyntaxTextArea panelArea = new RSyntaxTextArea();
panelArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVA);
panelArea.setCodeFoldingEnabled(true);
panelArea.setAntiAliasingEnabled(true);
final RTextScrollPane scrollPane = new RTextScrollPane(panelArea);
panelArea.setText(decompiler.decompileClassNode(viewer.cn, b));
panelArea.setCaretPosition(0);
panelArea.setEditable(viewer.isPaneEditable(paneId));
panelArea.addKeyListener(new KeyListener() {
@Override
public void keyPressed(KeyEvent e) {
if ((e.getKeyCode() == KeyEvent.VK_F) && ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0)) {
viewer.requestFocus(paneId);
}
BytecodeViewer.checkHotKey(e);
}
@Override
public void keyReleased(KeyEvent arg0) {
}
@Override
public void keyTyped(KeyEvent arg0) {
}
});
scrollPane.setColumnHeaderView(new JLabel(decompiler.getName() + " Decompiler - Editable: " + panelArea.isEditable()));
panelArea.setFont(new Font(Font.MONOSPACED, Font.PLAIN, (int) BytecodeViewer.viewer.fontSpinner.getValue()));
SwingUtilities.invokeLater(new Runnable() {
public void run() {
target.add(scrollPane);
}
});
viewer.updatePane(paneId, panelArea, decompiler);
} else {
final JHexEditor hex = new JHexEditor(b);
hex.setFont(new Font(Font.MONOSPACED, Font.PLAIN, (int) BytecodeViewer.viewer.fontSpinner.getValue()));
SwingUtilities.invokeLater(new Runnable() {
public void run() {
target.add(hex);
}
});
}
} catch (Exception e) {
new ExceptionUI(e);
} finally {
viewer.resetDivider();
BytecodeViewer.viewer.setIcon(false);
if (button != null)
button.setEnabled(true);
}
}
use of org.fife.ui.rtextarea.RTextScrollPane in project bytecode-viewer by Konloch.
the class ClassViewer method search.
/**
* This was really interesting to write.
*
* @author Konloch
*/
public void search(int pane, String search, boolean next) {
try {
Component[] com = panels.get(pane).getComponents();
for (Component c : com) {
if (c instanceof RTextScrollPane) {
RSyntaxTextArea area = (RSyntaxTextArea) ((RTextScrollPane) c).getViewport().getComponent(0);
if (search.isEmpty()) {
highlight(pane, area, "");
return;
}
int startLine = area.getDocument().getDefaultRootElement().getElementIndex(area.getCaretPosition()) + 1;
int currentLine = 1;
boolean canSearch = false;
String[] test = null;
if (area.getText().split("\n").length >= 2)
test = area.getText().split("\n");
else
test = area.getText().split("\r");
int lastGoodLine = -1;
int firstPos = -1;
boolean found = false;
if (next) {
for (String s : test) {
if (pane == 0 && !exacts.get(0).isSelected() || pane == 1 && !exacts.get(1).isSelected()) {
s = s.toLowerCase();
search = search.toLowerCase();
}
if (currentLine == startLine) {
canSearch = true;
} else if (s.contains(search)) {
if (canSearch) {
area.setCaretPosition(area.getDocument().getDefaultRootElement().getElement(currentLine - 1).getStartOffset());
canSearch = false;
found = true;
}
if (firstPos == -1)
firstPos = currentLine;
}
currentLine++;
}
if (!found && firstPos != -1) {
area.setCaretPosition(area.getDocument().getDefaultRootElement().getElement(firstPos - 1).getStartOffset());
}
} else {
canSearch = true;
for (String s : test) {
if (pane == 0 && !exacts.get(0).isSelected() || pane == 1 && !exacts.get(1).isSelected() || pane == 2 && !exacts.get(2).isSelected()) {
s = s.toLowerCase();
search = search.toLowerCase();
}
if (s.contains(search)) {
if (lastGoodLine != -1 && canSearch)
area.setCaretPosition(area.getDocument().getDefaultRootElement().getElement(lastGoodLine - 1).getStartOffset());
lastGoodLine = currentLine;
if (currentLine >= startLine)
canSearch = false;
}
currentLine++;
}
if (lastGoodLine != -1 && area.getDocument().getDefaultRootElement().getElementIndex(area.getCaretPosition()) + 1 == startLine) {
area.setCaretPosition(area.getDocument().getDefaultRootElement().getElement(lastGoodLine - 1).getStartOffset());
}
}
highlight(pane, area, search);
}
}
} catch (Exception e) {
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e);
}
}
Aggregations