Search in sources :

Example 1 with JHexEditor

use of com.jhe.hexed.JHexEditor in project bytecode-viewer by Konloch.

the class FileViewer method setContents.

public void setContents() {
    String name = this.name.toLowerCase();
    panelArea.setCodeFoldingEnabled(true);
    panelArea.setAntiAliasingEnabled(true);
    RTextScrollPane scrollPane = new RTextScrollPane(panelArea);
    panelArea.addKeyListener(new KeyListener() {

        public void keyPressed(KeyEvent e) {
            if ((e.getKeyCode() == KeyEvent.VK_F) && ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0)) {
                field.requestFocus();
            }
            BytecodeViewer.checkHotKey(e);
        }

        @Override
        public void keyReleased(KeyEvent arg0) {
        }

        @Override
        public void keyTyped(KeyEvent arg0) {
        }
    });
    String contentsS = new String(contents);
    if (!isPureAscii(contentsS)) {
        if (name.endsWith(".png") || name.endsWith(".jpg") || name.endsWith(".jpeg") || name.endsWith(".gif") || name.endsWith(".tif") || name.endsWith(".bmp")) {
            canRefresh = true;
            try {
                //gifs fail cause of this
                image = ImageIO.read(new ByteArrayInputStream(contents));
                JLabel label = new JLabel("", new ImageIcon(image), JLabel.CENTER);
                panel2.add(label, BorderLayout.CENTER);
                panel2.addMouseWheelListener(new MouseWheelListener() {

                    @Override
                    public void mouseWheelMoved(MouseWheelEvent e) {
                        int notches = e.getWheelRotation();
                        if (notches < 0) {
                            image = Scalr.resize(image, Scalr.Method.SPEED, image.getWidth() + 10, image.getHeight() + 10);
                        } else {
                            image = Scalr.resize(image, Scalr.Method.SPEED, image.getWidth() - 10, image.getHeight() - 10);
                        }
                        panel2.removeAll();
                        JLabel label = new JLabel("", new ImageIcon(image), JLabel.CENTER);
                        panel2.add(label, BorderLayout.CENTER);
                        panel2.updateUI();
                    }
                });
                return;
            } catch (Exception e) {
                new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e);
            }
        } else {
            JHexEditor hex = new JHexEditor(contents);
            panel2.add(hex);
            return;
        }
    }
    if (name.endsWith(".xml") || contentsS.startsWith("<?xml") || contentsS.startsWith(("<xml"))) {
        panelArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_XML);
        panelArea.setText(contentsS);
    } else if (name.endsWith(".py") || name.endsWith(".python")) {
        panelArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_PYTHON);
        panelArea.setText(contentsS);
    } else if (name.endsWith(".rb") || name.endsWith(".ruby")) {
        panelArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_RUBY);
        panelArea.setText(contentsS);
    } else if (name.endsWith(".java")) {
        panelArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVA);
        panelArea.setText(contentsS);
    } else if (name.endsWith(".html")) {
        panelArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_HTML);
        panelArea.setText(contentsS);
    } else if (name.endsWith(".css")) {
        panelArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_CSS);
        panelArea.setText(contentsS);
    } else if (name.endsWith(".properties") || name.endsWith(".mf") || name.endsWith(".sf")) {
        panelArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_PROPERTIES_FILE);
        panelArea.setText(contentsS);
    } else if (name.endsWith(".php") || contentsS.startsWith("<?php")) {
        panelArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_PHP);
        panelArea.setText(contentsS);
    } else if (name.endsWith(".js")) {
        panelArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVASCRIPT);
        panelArea.setText(contentsS);
    } else if (name.endsWith(".bat")) {
        panelArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_WINDOWS_BATCH);
        panelArea.setText(contentsS);
    } else if (name.endsWith(".sh")) {
        panelArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_UNIX_SHELL);
        panelArea.setText(contentsS);
    } else if (name.endsWith(".c")) {
        panelArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_C);
        panelArea.setText(contentsS);
    } else if (name.endsWith(".cpp")) {
        panelArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_CPLUSPLUS);
        panelArea.setText(contentsS);
    } else if (name.endsWith(".scala")) {
        panelArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_SCALA);
        panelArea.setText(contentsS);
    } else if (name.endsWith(".clojure")) {
        panelArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_CLOJURE);
        panelArea.setText(contentsS);
    } else if (name.endsWith(".groovy")) {
        panelArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_GROOVY);
        panelArea.setText(contentsS);
    } else if (name.endsWith(".lua")) {
        panelArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_LUA);
        panelArea.setText(contentsS);
    } else if (name.endsWith(".sql")) {
        panelArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_SQL);
        panelArea.setText(contentsS);
    } else if (name.endsWith(".json")) {
        panelArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JSON);
        panelArea.setText(contentsS);
    } else if (name.endsWith(".jsp")) {
        panelArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JSP);
        panelArea.setText(contentsS);
    } else {
        panelArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_NONE);
        panelArea.setText(contentsS);
    }
    panelArea.setCaretPosition(0);
    scrollPane.setColumnHeaderView(panel);
    panel2.add(scrollPane);
}
Also used : IOException(java.io.IOException) JHexEditor(com.jhe.hexed.JHexEditor) ByteArrayInputStream(java.io.ByteArrayInputStream) RTextScrollPane(org.fife.ui.rtextarea.RTextScrollPane)

Example 2 with JHexEditor

use of com.jhe.hexed.JHexEditor 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)

Aggregations

JHexEditor (com.jhe.hexed.JHexEditor)2 RTextScrollPane (org.fife.ui.rtextarea.RTextScrollPane)2 KeyEvent (java.awt.event.KeyEvent)1 KeyListener (java.awt.event.KeyListener)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 RSyntaxTextArea (org.fife.ui.rsyntaxtextarea.RSyntaxTextArea)1 ExceptionUI (the.bytecode.club.bytecodeviewer.api.ExceptionUI)1