abstracttoolkit.java

来自「纯java操作系统jnode,安装简单和操作简单的个人使用的Java操作系统」· Java 代码 · 共 949 行 · 第 1/3 页

JAVA
949
字号

        if (key_ < 0x20) {
            buf.append("^");
            buf.append((char) (key_ + 0x40));
        } else if (key_ == 0x20) {
            buf.append("SPACE");
        } else if (key_ < 0x7f) {
            buf.append((char) key_);
        } else {
            switch (key_) {
                case KeyEvent.VK_DOWN:
                    buf.append("VK_DOWN");
                    break;
                case KeyEvent.VK_UP:
                    buf.append("VK_UP");
                    break;
                case KeyEvent.VK_LEFT:
                    buf.append("VK_LEFT");
                    break;
                case KeyEvent.VK_RIGHT:
                    buf.append("VK_RIGHT");
                    break;
                case KeyEvent.VK_HOME:
                    buf.append("VK_HOME");
                    break;
                case KeyEvent.VK_BACK_SPACE:
                    buf.append("VK_BACK_SPACE");
                    break;
                case KeyEvent.VK_F1:
                case KeyEvent.VK_F2:
                case KeyEvent.VK_F3:
                case KeyEvent.VK_F4:
                case KeyEvent.VK_F5:
                case KeyEvent.VK_F6:
                case KeyEvent.VK_F7:
                case KeyEvent.VK_F8:
                case KeyEvent.VK_F9:
                case KeyEvent.VK_F10:
                case KeyEvent.VK_F11:
                case KeyEvent.VK_F12:
                case KeyEvent.VK_F13:
                case KeyEvent.VK_F14:
                case KeyEvent.VK_F15:
                case KeyEvent.VK_F16:
                case KeyEvent.VK_F17:
                case KeyEvent.VK_F18:
                case KeyEvent.VK_F19:
                case KeyEvent.VK_F20:
                    buf.append("VK_F");
                    int c = 1 + key_ - KeyEvent.VK_F1;
                    buf.append(c);
                    break;
                case KeyEvent.VK_DELETE:
                    buf.append("VK_DELETE");
                    break;
                case KeyEvent.VK_INSERT:
                    buf.append("VK_INSERT");
                    break;
                case KeyEvent.VK_PAGE_DOWN:
                    buf.append("VK_PAGE_DOWN");
                    break;
                case KeyEvent.VK_PAGE_UP:
                    buf.append("VK_PAGE_UP");
                    break;
                case KeyEvent.VK_ENTER:
                    buf.append("VK_ENTER");
                    break;
                case KeyEvent.VK_BACK_TAB:
                    buf.append("VK_BACK_TAB");
                    break;
                case KeyEvent.VK_END:
                    buf.append("VK_END");
                    break;
                default:
                    buf.append("UNKNOWN");
            }
        }

        return buf.toString();

    }

    /** Close the terminal window and restore terminal settings
     * (calls the curses endwin() function).
     */
    public abstract void close();

    /** Clears the screen (calls the curses clear() function).
     */
    public abstract void clear();

    /**
     * Set absolute cursor position
     */
    public void setCursor(Point p) {
        setCursor(p.x, p.y);
    }

    /**
     * Set absolute cursor position
     */
    public abstract void setCursor(int x_, int y_);

    /**
     * Get absolute cursor position
     */
    public Point getCursor() {
        int x = getx();
        int y = gety();
        return new Point(x, y);
    }

    /**
     * Get absolute cursor position.  Use this overloaded version to
     * avoid allocating a new Point on the heap.
     */
    public Point getCursor(Point p_) {
        p_.x = getx();
        p_.y = gety();
        return p_;
    }

    /**
     * Add a character to the virtual terminal at the current cursor position.
     */
    public abstract void addChar(int chr, int attrib, int colorpair_);

    //NOT USED
    /**
     * Draw a horizontal line of the specified length starting at the current
     * cursor position.
     */
//    public abstract void addHorizontalLine(int length_, int attrib_,
//	int colorpair);

    /**
     * Draw a vertical line of the specified length starting at the current
     * cursor position.
     */
    public abstract void addVerticalLine(int length_, int attrib_,
                                         int colorpair_);

    /**
     * Add a string to the virtual terminal at the current cursor position.
     */
    public abstract void addString(String str_, int attrib_, int colorpair_);

    /**
     * Draw a box.
     */
    public void drawBox(Point origin_, Dimension size_) {
        drawBoxNative(origin_.x, origin_.y,
                origin_.x + size_.width - 1,
                origin_.y + size_.height - 1,
                0);
    }

    /**
     * Draw a box using the specified color pair.
     */
    public void drawBox(Point origin_, Dimension size_, int colorpair_) {
        drawBoxNative(origin_.x, origin_.y,
                origin_.x + size_.width - 1,
                origin_.y + size_.height - 1,
                colorpair_);
    }

    public abstract void drawBoxNative(int left_, int top_,
                                       int right_, int bottom_, int colorpair_);

    /**
     */
    public void blankBox(Point origin_, Dimension size_) {
        blankBoxNative(origin_.x, origin_.y,
                origin_.x + size_.width - 1,
                origin_.y + size_.height - 1,
                0);
    }

    /** Blank out a box using the specified color pair.
     * @param origin_ The top left corner of the rectangle.
     * @param size_ The dimensions of the rectangle to blank out.
     * @param colorpair_ The number of the color-pair (foreground+background)
     * to use for blanking the rectangle.
     */
    public void blankBox(Point origin_, Dimension size_, int colorpair_) {
        blankBoxNative(origin_.x, origin_.y,
                origin_.x + size_.width - 1,
                origin_.y + size_.height - 1,
                colorpair_);
    }

    /**
     * Blank out the specified rectangle.
     */
    public abstract void blankBoxNative(int left_, int top_,
                                        int right_, int bottom_, int colorpair_);

    /**
     * Set a clipping rectangle.
     */
    public void setClipRect(Rectangle clip_) {
        setClipRectNative(clip_.getLeft(), clip_.getTop(),
                clip_.getRight(), clip_.getBottom());
    }

    /**
     * Set a clipping rectangle.
     */
    public abstract void setClipRectNative(int left_, int top_,
                                           int right_, int bottom_);

    /**
     * Reset the clipping rectangle to the screen size.
     */
    public abstract void resetClipRect();

    /**
     * Ring the terminal's bell.
     */
    public abstract void beep();

    public abstract int getScreenRows();

    public abstract int getScreenColumns();

    public Dimension getScreenSize() {
        return new Dimension(getScreenColumns(), getScreenRows());
    }

    /** Returns true if the terminal is capable of displaying colours.
     */
    public abstract boolean hasColors();

    /**
     * Returns the maximum number of color-pairs (provides an interface
     * to the ncurses COLOR_PAIRS global variable).
     */
    public abstract int getMaxColorPairs();

    /** An interface to the terminfo "start_colors()" function.
     */
    public abstract void startColors();

    /**
     * Returns the color-pair index corresponding to the specified
     * color-pair.  If the color pair does not exist yet, it is created
     * using the ncurses "init_pair" function.  If all the available
     * color-pairs are already in use, a TerminfoCapabilityException
     * is thrown.
     */
    public int getColorPairIndex(ColorPair pair_)
            throws TerminfoCapabilityException {
        int index = _colorPairs.indexOf(pair_);
        if (index != -1)
            return index;

        if (_colorPairs.size() == getMaxColorPairs()) {
            throw new TerminfoCapabilityException(
                    "max number of color pairs (" + getMaxColorPairs() +
                    ") exceeded");
        }

        index = _colorPairs.size();
        _colorPairs.add(pair_);
        initColorPair(index,
                pair_.getForeground(),
                pair_.getBackground());
        return index;
    }

    /**
     * Synchronize the state of the physical terminal with the state of
     * the virtual terminal maintained by curses (ie provides an interface
     * to the curses refresh() function).
     */
    public abstract void sync();

    //NOT USED
    /**
     * Indicate to ncurses that all the lines on the screen have changed
     * and need to be redrawn the next time Toolkit.sync() is called. This
     * just calls the ncurses function "redrawwin(stdscr)".
     */
//    public abstract void redrawWin();

    /**
     * Provides an interface to the ncurses "tigetstr()" function.
     */
//    public abstract String getStringCapability(String capname_)
//	throws TerminfoCapabilityException;

    /**
     * Provides an interface to the ncurses "tigetnum()" function.
     */
//    public abstract int getNumericCapability(String capname_)
//	throws TerminfoCapabilityException;

    /**
     * Provides an interface to the ncurses "tigetflag()" function.
     */
//    public abstract boolean getBooleanCapability(String capname_)
//	throws TerminfoCapabilityException;

//NOT USED
    /**
     * Provides an interface to the ncurses "putp()" function, to write a
     * string to the terminal; the string must be a return value from
     * getStringCapability().
     */
//    public abstract void putp(String str_);

    //NOT USED
    /**
     * Provides an interface to the ncurses "mcprint()" function to ship
     * the specified string to a printer attached to the terminal. Makes
     * use of the "mc4" and "mc5" capabilities of the terminal (see

⌨️ 快捷键说明

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