⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 swinggui.java

📁 java中比较著名的js引擎当属mozilla开源的rhino
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                h = dimen.height;                desk.getDesktopManager().setBoundsForFrame(f, x, y, w, h);            }        } else {            Object obj = getFileWindow(cmd);            if (obj != null) {                FileWindow w = (FileWindow)obj;                try {                    if (w.isIcon()) {                        w.setIcon(false);                    }                    w.setVisible(true);                    w.moveToFront();                    w.setSelected(true);                } catch (Exception exc) {                }            }        }        if (returnValue != -1) {            updateEnabled(false);            dim.setReturnValue(returnValue);        }    }}/** * Helper class for showing a message dialog. */class MessageDialogWrapper {    /**     * Shows a message dialog, wrapping the <code>msg</code> at 60     * columns.     */    public static void showMessageDialog(Component parent, String msg,                                         String title, int flags) {        if (msg.length() > 60) {            StringBuffer buf = new StringBuffer();            int len = msg.length();            int j = 0;            int i;            for (i = 0; i < len; i++, j++) {                char c = msg.charAt(i);                buf.append(c);                if (Character.isWhitespace(c)) {                    int remainder = len - i;                    int k;                    for (k = i + 1; k < len; k++) {                        if (Character.isWhitespace(msg.charAt(k))) {                            break;                        }                    }                    if (k < len) {                        int nextWordLen = k - i;                        if (j + nextWordLen > 60) {                            buf.append('\n');                            j = 0;                        }                    }                }            }            msg = buf.toString();        }        JOptionPane.showMessageDialog(parent, msg, title, flags);    }}/** * Extension of JTextArea for script evaluation input. */class EvalTextArea    extends JTextArea    implements KeyListener, DocumentListener {    /**     * Serializable magic number.     */    private static final long serialVersionUID = -3918033649601064194L;    /**     * The debugger GUI.     */    private SwingGui debugGui;    /**     * History of expressions that have been evaluated     */    private Vector history;    /**     * Index of the selected history item.     */    private int historyIndex = -1;    /**     * Position in the display where output should go.     */    private int outputMark;    /**     * Creates a new EvalTextArea.     */    public EvalTextArea(SwingGui debugGui) {        this.debugGui = debugGui;        history = new java.util.Vector();        Document doc = getDocument();        doc.addDocumentListener(this);        addKeyListener(this);        setLineWrap(true);        setFont(new Font("Monospaced", 0, 12));        append("% ");        outputMark = doc.getLength();    }    /**     * Selects a subrange of the text.     */    public void select(int start, int end) {        //requestFocus();        super.select(start, end);    }    /**     * Called when Enter is pressed.     */    private synchronized void returnPressed() {        Document doc = getDocument();        int len = doc.getLength();        Segment segment = new Segment();        try {            doc.getText(outputMark, len - outputMark, segment);        } catch (javax.swing.text.BadLocationException ignored) {            ignored.printStackTrace();        }        String text = segment.toString();        if (debugGui.dim.stringIsCompilableUnit(text)) {            if (text.trim().length() > 0) {               history.addElement(text);               historyIndex = history.size();            }            append("\n");            String result = debugGui.dim.eval(text);            if (result.length() > 0) {                append(result);                append("\n");            }            append("% ");            outputMark = doc.getLength();        } else {            append("\n");        }    }    /**     * Writes output into the text area.     */    public synchronized void write(String str) {        insert(str, outputMark);        int len = str.length();        outputMark += len;        select(outputMark, outputMark);    }    // KeyListener    /**     * Called when a key is pressed.     */    public void keyPressed(KeyEvent e) {        int code = e.getKeyCode();        if (code == KeyEvent.VK_BACK_SPACE || code == KeyEvent.VK_LEFT) {            if (outputMark == getCaretPosition()) {                e.consume();            }        } else if (code == KeyEvent.VK_HOME) {           int caretPos = getCaretPosition();           if (caretPos == outputMark) {               e.consume();           } else if (caretPos > outputMark) {               if (!e.isControlDown()) {                   if (e.isShiftDown()) {                       moveCaretPosition(outputMark);                   } else {                       setCaretPosition(outputMark);                   }                   e.consume();               }           }        } else if (code == KeyEvent.VK_ENTER) {            returnPressed();            e.consume();        } else if (code == KeyEvent.VK_UP) {            historyIndex--;            if (historyIndex >= 0) {                if (historyIndex >= history.size()) {                    historyIndex = history.size() -1;                }                if (historyIndex >= 0) {                    String str = (String)history.elementAt(historyIndex);                    int len = getDocument().getLength();                    replaceRange(str, outputMark, len);                    int caretPos = outputMark + str.length();                    select(caretPos, caretPos);                } else {                    historyIndex++;                }            } else {                historyIndex++;            }            e.consume();        } else if (code == KeyEvent.VK_DOWN) {            int caretPos = outputMark;            if (history.size() > 0) {                historyIndex++;                if (historyIndex < 0) {historyIndex = 0;}                int len = getDocument().getLength();                if (historyIndex < history.size()) {                    String str = (String)history.elementAt(historyIndex);                    replaceRange(str, outputMark, len);                    caretPos = outputMark + str.length();                } else {                    historyIndex = history.size();                    replaceRange("", outputMark, len);                }            }            select(caretPos, caretPos);            e.consume();        }    }    /**     * Called when a key is typed.     */    public void keyTyped(KeyEvent e) {        int keyChar = e.getKeyChar();        if (keyChar == 0x8 /* KeyEvent.VK_BACK_SPACE */) {            if (outputMark == getCaretPosition()) {                e.consume();            }        } else if (getCaretPosition() < outputMark) {            setCaretPosition(outputMark);        }    }    /**     * Called when a key is released.     */    public synchronized void keyReleased(KeyEvent e) {    }    // DocumentListener    /**     * Called when text was inserted into the text area.     */    public synchronized void insertUpdate(DocumentEvent e) {        int len = e.getLength();        int off = e.getOffset();        if (outputMark > off) {            outputMark += len;        }    }    /**     * Called when text was removed from the text area.     */    public synchronized void removeUpdate(DocumentEvent e) {        int len = e.getLength();        int off = e.getOffset();        if (outputMark > off) {            if (outputMark >= off + len) {                outputMark -= len;            } else {                outputMark = off;            }        }    }    /**     * Attempts to clean up the damange done by {@link #updateComponentTreeUI}.     */    public synchronized void postUpdateUI() {        //requestFocus();        setCaret(getCaret());        select(outputMark, outputMark);    }    /**     * Called when text has changed in the text area.     */    public synchronized void changedUpdate(DocumentEvent e) {    }}/** * An internal frame for evaluating script. */class EvalWindow extends JInternalFrame implements ActionListener {    /**     * Serializable magic number.     */    private static final long serialVersionUID = -2860585845212160176L;    /**     * The text area into which expressions can be typed.     */    private EvalTextArea evalTextArea;    /**     * Creates a new EvalWindow.     */    public EvalWindow(String name, SwingGui debugGui) {        super(name, true, false, true, true);        evalTextArea = new EvalTextArea(debugGui);        evalTextArea.setRows(24);        evalTextArea.setColumns(80);        JScrollPane scroller = new JScrollPane(evalTextArea);        setContentPane(scroller);        //scroller.setPreferredSize(new Dimension(600, 400));        pack();        setVisible(true);    }    /**     * Sets whether the text area is enabled.     */    public void setEnabled(boolean b) {        super.setEnabled(b);        evalTextArea.setEnabled(b);    }    // ActionListener    /**     * Performs an action on the text area.     */    public void actionPerformed(ActionEvent e) {        String cmd = e.getActionCommand();        if (cmd.equals("Cut")) {            evalTextArea.cut();        } else if (cmd.equals("Copy")) {            evalTextArea.copy();        } else if (cmd.equals("Paste")) {            evalTextArea.paste();        }    }}/** * Internal frame for the console. */class JSInternalConsole extends JInternalFrame implements ActionListener {    /**     * Serializable magic number.     */    private static final long serialVersionUID = -5523468828771087292L;    /**     * Creates a new JSInternalConsole.     */    public JSInternalConsole(String name) {        super(name, true, false, true, true);        consoleTextArea = new ConsoleTextArea(null);        consoleTextArea.setRows(24);        consoleTextArea.setColumns(80);        JScrollPane scroller = new JScrollPane(consoleTextArea);        setContentPane(scroller);        pack();        addInternalFrameListener(new InternalFrameAdapter() {                public void internalFrameActivated(InternalFrameEvent e) {                    // hack                    if (consoleTextArea.hasFocus()) {                        consoleTextArea.getCaret().setVisible(false);                        consoleTextArea.getCaret().setVisible(true);                    }                }            });    }    /**     * The console text area.     */    ConsoleTextArea consoleTextArea;    /**     * Returns the input stream of the console text area.     */    public InputStream getIn() {        return consoleTextArea.getIn();    }    /**     * Returns the output stream of the console text area.     */    public PrintStream getOut() {        return consoleTextArea.getOut();    }    /**     * Returns the error stream of the console text area.     */    public PrintStream getErr() {        return consoleTextArea.getErr();    }    // ActionListener    /**     * Performs an action on the text area.     */    public void actionPerformed(ActionEvent e) {        String cmd = e.getActionCommand();        if (cmd.equals("Cut")) {            consoleTextArea.cut();        } else if (cmd.equals("Copy")) {            consoleTextArea.copy();        } else if (cmd.equals("Paste")) {            consoleTextArea.paste();        }    }}/** * Popup menu class for right-clicking on {@link FileTextArea}s. */class FilePopupMenu extends JPopupMenu {    /**     * Serializable magic number.     */    private static final long serialVersionUID = 3589525009546013565L;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -