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

📄 swinggui.java

📁 javascript语言的解释器源码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- * * The contents of this file are subject to the Netscape Public * License Version 1.1 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.mozilla.org/NPL/ * * Software distributed under the License is distributed on an "AS * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or * implied. See the License for the specific language governing * rights and limitations under the License. * * The Original Code is Rhino JavaScript Debugger code, released * November 21, 2000. * * The Initial Developer of the Original Code is SeeBeyond Corporation. * Portions created by SeeBeyond are * Copyright (C) 2000 SeeBeyond Technology Corporation. All * Rights Reserved. * * Contributor(s): * Igor Bukanov * Matt Gould * Christopher Oliver * * Alternatively, the contents of this file may be used under the * terms of the GNU Public License (the "GPL"), in which case the * provisions of the GPL are applicable instead of those above. * If you wish to allow use of your version of this file only * under the terms of the GPL and not to allow others to use your * version of this file under the NPL, indicate your decision by * deleting the provisions above and replace them with the notice * and other provisions required by the GPL.  If you do not delete * the provisions above, a recipient may use your version of this * file under either the NPL or the GPL. */package org.mozilla.javascript.tools.debugger;import javax.swing.*;import javax.swing.text.*;import javax.swing.event.*;import javax.swing.table.*;import java.awt.*;import java.awt.event.*;import java.util.*;import java.io.*;import javax.swing.tree.DefaultTreeCellRenderer;import javax.swing.tree.TreePath;import java.lang.reflect.Method;import org.mozilla.javascript.Kit;import org.mozilla.javascript.tools.shell.ConsoleTextArea;import org.mozilla.javascript.tools.debugger.downloaded.JTreeTable;import org.mozilla.javascript.tools.debugger.downloaded.TreeTableModel;import org.mozilla.javascript.tools.debugger.downloaded.TreeTableModelAdapter;class MessageDialogWrapper {    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);    }};class EvalTextArea    extends JTextArea implements KeyListener, DocumentListener{    static final long serialVersionUID = -3918033649601064194L;    SwingGui debugGui;    private java.util.Vector history;    private int historyIndex = -1;    private int outputMark = 0;    public void select(int start, int end) {        //requestFocus();        super.select(start, end);    }    public EvalTextArea(SwingGui debugGui) {        super();        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();    }    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");        }    }    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();        }    }    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);        }    }    public synchronized void keyReleased(KeyEvent e) {    }    public synchronized void write(String str) {        insert(str, outputMark);        int len = str.length();        outputMark += len;        select(outputMark, outputMark);    }    public synchronized void insertUpdate(DocumentEvent e) {        int len = e.getLength();        int off = e.getOffset();        if (outputMark > off) {            outputMark += len;        }    }    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;            }        }    }    public synchronized void postUpdateUI() {        // this attempts to cleanup the damage done by updateComponentTreeUI        //requestFocus();        setCaret(getCaret());        select(outputMark, outputMark);    }    public synchronized void changedUpdate(DocumentEvent e) {    }};class EvalWindow    extends JInternalFrame implements ActionListener{    static final long serialVersionUID = -2860585845212160176L;    EvalTextArea evalTextArea;    public void setEnabled(boolean b) {        super.setEnabled(b);        evalTextArea.setEnabled(b);    }    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);    }    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();        }    }};class JSInternalConsole    extends JInternalFrame implements ActionListener{    static final long serialVersionUID = -5523468828771087292L;    ConsoleTextArea consoleTextArea;    public InputStream getIn() {        return consoleTextArea.getIn();    }    public PrintStream getOut() {        return consoleTextArea.getOut();    }    public PrintStream getErr() {        return consoleTextArea.getErr();    }    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);                    }                }            });    }    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();        }    }};class FilePopupMenu extends JPopupMenu{    static final long serialVersionUID = 3589525009546013565L;    FileTextArea w;    int x, y;    FilePopupMenu(FileTextArea w) {        super();        this.w = w;        JMenuItem item;        add(item = new JMenuItem("Set Breakpoint"));        item.addActionListener(w);        add(item = new JMenuItem("Clear Breakpoint"));        item.addActionListener(w);        add(item = new JMenuItem("Run"));        item.addActionListener(w);    }    void show(JComponent comp, int x, int y) {        this.x = x;        this.y = y;        super.show(comp, x, y);    }};class FileTextArea extends JTextArea    implements ActionListener, PopupMenuListener, KeyListener, MouseListener{    static final long serialVersionUID = -25032065448563720L;    FileWindow w;    FilePopupMenu popup;    FileTextArea(FileWindow w) {        this.w = w;

⌨️ 快捷键说明

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