Search in sources :

Example 1 with RSyntaxTextArea

use of org.fife.ui.rsyntaxtextarea.RSyntaxTextArea in project jadx by skylot.

the class LogViewer method initUI.

public final void initUI() {
    textPane = new RSyntaxTextArea();
    textPane.setBorder(BorderFactory.createEmptyBorder(15, 15, 15, 15));
    JPanel controlPane = new JPanel();
    controlPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    @SuppressWarnings("unchecked") final JComboBox cb = new JComboBox(LEVEL_ITEMS);
    cb.setSelectedItem(level);
    cb.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            int i = cb.getSelectedIndex();
            level = LEVEL_ITEMS[i];
            registerLogListener();
        }
    });
    JLabel levelLabel = new JLabel(NLS.str("log.level"));
    levelLabel.setLabelFor(cb);
    controlPane.add(levelLabel);
    controlPane.add(cb);
    JScrollPane scrollPane = new JScrollPane(textPane);
    JButton close = new JButton(NLS.str("tabs.close"));
    close.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent event) {
            close();
        }
    });
    close.setAlignmentX(0.5f);
    Container contentPane = getContentPane();
    contentPane.add(controlPane, BorderLayout.PAGE_START);
    contentPane.add(scrollPane, BorderLayout.CENTER);
    contentPane.add(close, BorderLayout.PAGE_END);
    setTitle("Log Viewer");
    pack();
    setSize(800, 600);
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    setModalityType(ModalityType.MODELESS);
    setLocationRelativeTo(null);
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) Container(java.awt.Container) RSyntaxTextArea(org.fife.ui.rsyntaxtextarea.RSyntaxTextArea) JComboBox(javax.swing.JComboBox) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel)

Example 2 with RSyntaxTextArea

use of org.fife.ui.rsyntaxtextarea.RSyntaxTextArea 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);
    }
}
Also used : KeyEvent(java.awt.event.KeyEvent) JHexEditor(com.jhe.hexed.JHexEditor) RSyntaxTextArea(org.fife.ui.rsyntaxtextarea.RSyntaxTextArea) ExceptionUI(the.bytecode.club.bytecodeviewer.api.ExceptionUI) KeyListener(java.awt.event.KeyListener) RTextScrollPane(org.fife.ui.rtextarea.RTextScrollPane)

Example 3 with RSyntaxTextArea

use of org.fife.ui.rsyntaxtextarea.RSyntaxTextArea 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);
    }
}
Also used : RSyntaxTextArea(org.fife.ui.rsyntaxtextarea.RSyntaxTextArea) JTextComponent(javax.swing.text.JTextComponent) RTextScrollPane(org.fife.ui.rtextarea.RTextScrollPane)

Aggregations

RSyntaxTextArea (org.fife.ui.rsyntaxtextarea.RSyntaxTextArea)3 RTextScrollPane (org.fife.ui.rtextarea.RTextScrollPane)2 JHexEditor (com.jhe.hexed.JHexEditor)1 Container (java.awt.Container)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 KeyEvent (java.awt.event.KeyEvent)1 KeyListener (java.awt.event.KeyListener)1 JButton (javax.swing.JButton)1 JComboBox (javax.swing.JComboBox)1 JLabel (javax.swing.JLabel)1 JPanel (javax.swing.JPanel)1 JScrollPane (javax.swing.JScrollPane)1 JTextComponent (javax.swing.text.JTextComponent)1 ExceptionUI (the.bytecode.club.bytecodeviewer.api.ExceptionUI)1