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

📄 swinggui.java

📁 java中比较著名的js引擎当属mozilla开源的rhino
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    /**     * The {@link FileTextArea} this popup menu is attached to.     */    private FileTextArea w;    /**     * The popup x position.     */    int x;        /**     * The popup y position.     */    int y;    /**     * Creates a new FilePopupMenu.     */    public FilePopupMenu(FileTextArea w) {        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);    }    /**     * Displays the menu at the given coordinates.     */    public void show(JComponent comp, int x, int y) {        this.x = x;        this.y = y;        super.show(comp, x, y);    }}/** * Text area to display script source. */class FileTextArea    extends JTextArea    implements ActionListener, PopupMenuListener, KeyListener, MouseListener {    /**     * Serializable magic number.     */    private static final long serialVersionUID = -25032065448563720L;    /**     * The owning {@link FileWindow}.     */    private FileWindow w;    /**     * The popup menu.     */    private FilePopupMenu popup;    /**     * Creates a new FileTextArea.     */    public FileTextArea(FileWindow w) {        this.w = w;        popup = new FilePopupMenu(this);        popup.addPopupMenuListener(this);        addMouseListener(this);        addKeyListener(this);        setFont(new Font("Monospaced", 0, 12));    }    /**     * Moves the selection to the given offset.     */    public void select(int pos) {        if (pos >= 0) {            try {                int line = getLineOfOffset(pos);                Rectangle rect = modelToView(pos);                if (rect == null) {                    select(pos, pos);                } else {                    try {                        Rectangle nrect =                            modelToView(getLineStartOffset(line + 1));                        if (nrect != null) {                            rect = nrect;                        }                    } catch (Exception exc) {                    }                    JViewport vp = (JViewport)getParent();                    Rectangle viewRect = vp.getViewRect();                    if (viewRect.y + viewRect.height > rect.y) {                        // need to scroll up                        select(pos, pos);                    } else {                        // need to scroll down                        rect.y += (viewRect.height - rect.height)/2;                        scrollRectToVisible(rect);                        select(pos, pos);                    }                }            } catch (BadLocationException exc) {                select(pos, pos);                //exc.printStackTrace();            }        }    }    /**     * Checks if the popup menu should be shown.     */    private void checkPopup(MouseEvent e) {        if (e.isPopupTrigger()) {            popup.show(this, e.getX(), e.getY());        }    }    // MouseListener    /**     * Called when a mouse button is pressed.     */    public void mousePressed(MouseEvent e) {        checkPopup(e);    }    /**     * Called when the mouse is clicked.     */    public void mouseClicked(MouseEvent e) {        checkPopup(e);        requestFocus();        getCaret().setVisible(true);    }    /**     * Called when the mouse enters the component.     */    public void mouseEntered(MouseEvent e) {    }    /**     * Called when the mouse exits the component.     */    public void mouseExited(MouseEvent e) {    }    /**     * Called when a mouse button is released.     */    public void mouseReleased(MouseEvent e) {        checkPopup(e);    }    // PopupMenuListener    /**     * Called before the popup menu will become visible.     */    public void popupMenuWillBecomeVisible(PopupMenuEvent e) {    }    /**     * Called before the popup menu will become invisible.     */    public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {    }    /**     * Called when the popup menu is cancelled.     */    public void popupMenuCanceled(PopupMenuEvent e) {    }    // ActionListener    /**     * Performs an action.     */    public void actionPerformed(ActionEvent e) {        int pos = viewToModel(new Point(popup.x, popup.y));        popup.setVisible(false);        String cmd = e.getActionCommand();        int line = -1;        try {            line = getLineOfOffset(pos);        } catch (Exception exc) {        }        if (cmd.equals("Set Breakpoint")) {            w.setBreakPoint(line + 1);        } else if (cmd.equals("Clear Breakpoint")) {            w.clearBreakPoint(line + 1);        } else if (cmd.equals("Run")) {            w.load();        }    }    // KeyListener    /**     * Called when a key is pressed.     */    public void keyPressed(KeyEvent e) {        switch (e.getKeyCode()) {        case KeyEvent.VK_BACK_SPACE:        case KeyEvent.VK_ENTER:        case KeyEvent.VK_DELETE:            e.consume();            break;        }    }    /**     * Called when a key is typed.     */    public void keyTyped(KeyEvent e) {        e.consume();    }    /**     * Called when a key is released.     */    public void keyReleased(KeyEvent e) {        e.consume();    }}/** * Dialog to list the available windows. */class MoreWindows extends JDialog implements ActionListener {    /**     * Serializable magic number.     */    private static final long serialVersionUID = 5177066296457377546L;    /**     * Last selected value.     */    private String value;    /**     * The list component.     */    private JList list;    /**     * Table of file windows.     */    private Hashtable fileWindows;    /**     * The "Select" button.     */    private JButton setButton;    /**     * The "Refresh" button.     */    private JButton refreshButton;    /**     * The "Cancel" button.     */    private JButton cancelButton;    /**     * Creates a new MoreWindows.     */    MoreWindows(JFrame frame, Hashtable fileWindows, String title,                String labelText) {        super(frame, title, true);        this.fileWindows = fileWindows;        //buttons        cancelButton = new JButton("Cancel");        setButton = new JButton("Select");        cancelButton.addActionListener(this);        setButton.addActionListener(this);        getRootPane().setDefaultButton(setButton);        //dim part of the dialog        list = new JList(new DefaultListModel());        DefaultListModel model = (DefaultListModel)list.getModel();        model.clear();        //model.fireIntervalRemoved(model, 0, size);        Enumeration e = fileWindows.keys();        while (e.hasMoreElements()) {            String data = e.nextElement().toString();            model.addElement(data);        }        list.setSelectedIndex(0);        //model.fireIntervalAdded(model, 0, data.length);        setButton.setEnabled(true);        list.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);        list.addMouseListener(new MouseHandler());        JScrollPane listScroller = new JScrollPane(list);        listScroller.setPreferredSize(new Dimension(320, 240));        //XXX: Must do the following, too, or else the scroller thinks        //XXX: it's taller than it is:        listScroller.setMinimumSize(new Dimension(250, 80));        listScroller.setAlignmentX(LEFT_ALIGNMENT);        //Create a container so that we can add a title around        //the scroll pane.  Can't add a title directly to the        //scroll pane because its background would be white.        //Lay out the label and scroll pane from top to button.        JPanel listPane = new JPanel();        listPane.setLayout(new BoxLayout(listPane, BoxLayout.Y_AXIS));        JLabel label = new JLabel(labelText);        label.setLabelFor (list);        listPane.add(label);        listPane.add(Box.createRigidArea(new Dimension(0,5)));        listPane.add(listScroller);        listPane.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));        //Lay out the buttons from left to right.        JPanel buttonPane = new JPanel();        buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.X_AXIS));        buttonPane.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10));        buttonPane.add(Box.createHorizontalGlue());        buttonPane.add(cancelButton);        buttonPane.add(Box.createRigidArea(new Dimension(10, 0)));        buttonPane.add(setButton);        //Put everything together, using the content pane's BorderLayout.        Container contentPane = getContentPane();        contentPane.add(listPane, BorderLayout.CENTER);        contentPane.add(buttonPane, BorderLayout.SOUTH);        pack();        addKeyListener(new KeyAdapter() {                public void keyPressed(KeyEvent ke) {                    int code = ke.getKeyCode();                    if (code == KeyEvent.VK_ESCAPE) {                        ke.consume();                        value = null;                        setVisible(false);                    }                }            });    }    /**     * Shows the dialog.     */    public String showDialog(Component comp) {        value = null;        setLocationRelativeTo(comp);        setVisible(true);        return value;    }    /**     * Sets the selected value.     */    private void setValue(String newValue) {        value = newValue;        list.setSelectedValue(value, true);    }    // ActionListener    /**     * Performs an action.     */    public void actionPerformed(ActionEvent e) {        String cmd = e.getActionCommand();        if (cmd.equals("Cancel")) {            setVisible(false);            value = null;        } else if (cmd.equals("Select")) {            value = (String)list.getSelectedValue();            setVisible(false);            JInternalFrame w = (JInternalFrame)fileWindows.get(value);            if (w != null) {                try {                    w.show();                    w.setSelected(true);                } catch (Exception exc) {                }            }        }    }    /**     * MouseListener implementation for {@link #list}.     */    private class MouseHandler extends MouseAdapter {        public void mouseClicked(MouseEvent e) {            if (e.getClickCount() == 2) {                setButton.doClick();            }        }    };};/** * Find function dialog. */class FindFunction extends JDialog implements ActionListener {    /**     * Serializable magic number.     */    private static final long serialVersionUID = 559491015232880916L;    /**     * Last selected function.     */    private String value;    /**     * List of functions.     */    private JList list;    /**     * The debug GUI frame.     */    private SwingGui debugGui;    /**     * The "Select" button.     */    private JButton setButton;    /**     * The "Refresh" button.     */

⌨️ 快捷键说明

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