Java Code Examples for sun.jvm.hotspot.CommandProcessor

Following code examples demonstrate how to use sun.jvm.hotspot.CommandProcessorfrom java. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use sun.jvm.hotspot.CommandProcessorand various code implementation of this class.

    public CommandProcessorPanel(CommandProcessor cp) {

        commands = cp;

        setLayout(new BorderLayout());

        editor = new JTextArea();
        editor.setDocument(new EditableAtEndDocument());
        editor.setFont(GraphicsUtilities.lookupFont("Courier"));
        JScrollPane scroller = new JScrollPane();
        scroller.getViewport().add(editor);
        add(scroller, BorderLayout.CENTER);

        PrintStream o = new PrintStream(baos, true);
        cp.setOutput(o);
        cp.setErr(o);

        editor.getDocument().addDocumentListener(new DocumentListener() {
                public void changedUpdate(DocumentEvent e) {
                }

                public void insertUpdate(DocumentEvent e) {
                    if (updating) return;
                    beginUpdate();
                    editor.setCaretPosition(editor.getDocument().getLength());
                    if (insertContains(e, '\n')) {
                        String cmd = getMarkedText();
                        if ((cmd.length() == 0) || (cmd.charAt(cmd.length() - 1) != '\\')) {
                            final String ln = trimContinuations(cmd);
                            SwingUtilities.invokeLater(new Runnable() {
                                    public void run() {
                                        beginUpdate();
                                        try {
                                            commands.executeCommand(ln);
                                            commands.printPrompt();
                                            Document d = editor.getDocument();
                                            try {
                                                d.insertString(d.getLength(), baos.toString(), null);
                                            }
                                            catch (BadLocationException ble) {
                                                ble.printStackTrace();
                                            }
                                            baos.reset();
                                            editor.setCaretPosition(editor.getDocument().getLength());
                                            setMark();
                                        } finally {
                                            endUpdate();
                                        }
                                    }
                                });
                        }
                    } else {
                        endUpdate();
                    }
                }

                public void removeUpdate(DocumentEvent e) {
                }
            });

        editor.addCaretListener(new CaretListener() {
                public void caretUpdate(CaretEvent e) {
                    int len = editor.getDocument().getLength();
                    if (e.getDot() > len) {
                        editor.setCaretPosition(len);
                    }
                }
            });

        Box hbox = Box.createHorizontalBox();
        hbox.add(Box.createGlue());
        JButton button = new JButton("Clear Saved Text");
        button.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    clear();
                }
            });
        hbox.add(button);
        hbox.add(Box.createGlue());
        add(hbox, BorderLayout.SOUTH);

        clear();
    } 


Advertisement
Advertisement