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

📄 textcomponent.java

📁 moto手机专用的LWT类库源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        for(j = 0; j < rowCount - 1 && i >= rowBoundaries[j + 1]; j++);
        return j;
    }

    void drawChars(Graphics g, char ac[], int i, int j, int k, int l)
    {
        if(j > 0)
        {
            if(multiLine)
            {
                int i1;
                for(i1 = (i + j) - 1; i1 >= 0 && (ac[i1] == '\n' || ac[i1] == '\r'); i1--);
                j = (i1 + 1) - i;
            }
            if(j > 0)
            {
                if(echoChar != 0)
                {
                    ac = new char[j];
                    for(int j1 = 0; j1 < j; j1++)
                        ac[j1] = echoChar;

                }
                g.drawChars(ac, i, j, k, l, 36);
            }
        }
    }

    void paintInsertionPoint(Graphics g)
    {
        if(editable && hasFocus() && enabled)
        {
            screenPosition(caretPosition);
            g.fillRect(screenPositionX - 1, screenPositionY - lineHeight, 2, lineHeight);
        }
    }

    void paintBorder(Graphics g)
    {
        if(hasFocus())
            g.drawRect(0, 0, getWidth() - 1, getHeight() - 1);
    }

    void screenPosition(int i)
    {
        int j = getRowNumber(i);
        int k = rowBoundaries[j];
        int l = rowBoundaries[j + 1];
        int i1 = 0;
        if((justification & 0x2) > 0)
        {
            i1 = getWidth() - 2;
            for(int j1 = l - 1; j1 >= i; j1--)
                i1 -= textWidth[j1];

        } else
        if((justification & 0x1) > 0)
        {
            i1 = getWidth() - getWidth(k, l) >> 1;
            for(int k1 = k; k1 < i; k1++)
                i1 += textWidth[k1];

        } else
        {
            i1 = 2;
            for(int l1 = k; l1 < i; l1++)
                i1 += textWidth[l1];

        }
        screenPositionX = i1 - viewPortOriginX;
        screenPositionY = getYLocationForRow(j);
    }

    int getWidth(int i, int j)
    {
        int k = 0;
        for(int l = i; l < j; l++)
            k += textWidth[l];

        return k;
    }

    int getYLocationForRow(int i)
    {
        return (2 + lineHeight + lineHeight * i) - viewPortOriginY;
    }

    boolean validChar(char c)
    {
        if(constraint == 2)
            return c >= '0' && c <= '9';
        if(constraint == 3)
            return c >= '0' && c <= '9' || c == '+';
        else
            return true;
    }

    boolean validText(char ac[], int i, int j)
    {
        if(constraint == 2 || constraint == 3)
        {
            for(int k = i; k < i + j; k++)
                if(!validChar(ac[k]))
                    return false;

        }
        return true;
    }

    abstract void reformatText(int i, int j);

    int getRowForYLocation(int i)
    {
        int j = ((i + viewPortOriginY) - 2 - lineHeight) / lineHeight;
        if(j > rowCount - 1)
            j = rowCount - 1;
        if(j < 0)
            j = 0;
        return j;
    }

    int charIndex(int i, int j)
    {
        int k = getRowForYLocation(j);
        int l = rowBoundaries[k];
        int i1 = rowBoundaries[k + 1];
        screenPosition(l);
        int j1 = screenPositionX;
        int k1;
        for(k1 = l; k1 < i1; k1++)
        {
            if(text[k1] == '\n')
                break;
            short word0 = textWidth[k1];
            if(i < j1 + (word0 >> 1))
                break;
            j1 += word0;
        }

        return k1;
    }

    int getCaretPosition()
    {
        return caretPosition;
    }

    void setCaretPosition(int i)
    {
        caretPosition = clipIndex(i);
        scrollTo(caretPosition, true);
        repaint();
    }

    public boolean isEditable()
    {
        return editable;
    }

    public synchronized void setEditable(boolean flag)
    {
        if(editable != flag)
        {
            editable = flag;
            repaint();
        }
    }

    private void scrollToCursor()
    {
        scrollTo(caretPosition, true);
        repaint();
    }

    private synchronized void scrollTo(int i, boolean flag)
    {
        screenPosition(i);
        if(multiLine)
        {
            if(screenPositionY < lineHeight)
            {
                viewPortOriginY += screenPositionY - lineHeight;
                if(viewPortOriginY < 0)
                    viewPortOriginY = 0;
            } else
            if(screenPositionY > height)
                viewPortOriginY += screenPositionY - height;
        } else
        {
            int j = 2;
            if(flag)
                j = getWidth() >> 1;
            if(screenPositionX < 2)
            {
                viewPortOriginX += screenPositionX - j;
                if((justification & 0x3) == 0 && viewPortOriginX < 0)
                    viewPortOriginX = 0;
            } else
            if(screenPositionX > getWidth() - 2)
            {
                viewPortOriginX += (screenPositionX + j) - getWidth();
                if((justification & 0x3) == 2 && viewPortOriginX > 0)
                    viewPortOriginX = 0;
            }
        }
    }

    int clipIndex(int i)
    {
        if(i < 0)
            return 0;
        if(i > textLength)
            return textLength;
        else
            return i;
    }

    public synchronized void paint(Graphics g)
    {
        if(lastWidth != width || lastHeight != height)
        {
            reformatText(0, textLength);
            lastWidth = width;
            lastHeight = height;
        }
        if(enabled && editable)
        {
            g.setColor(0x808080);
            g.fillRect(0, 0, getWidth(), getHeight());
        }
        g.setColor(enabled ? 0 : 0x808080);
        g.setFont(itsFont);
        if(multiLine)
        {
            int i = getRowForYLocation(g.getClipY());
            int j = getRowForYLocation(g.getClipY() + g.getClipHeight());
            for(int k = i; k <= j; k++)
            {
                screenPosition(rowBoundaries[k]);
                drawChars(g, text, rowBoundaries[k], rowBoundaries[k + 1] - rowBoundaries[k], screenPositionX, screenPositionY);
            }

        } else
        {
            screenPosition(0);
            drawChars(g, text, 0, textLength, screenPositionX, screenPositionY);
        }
        paintInsertionPoint(g);
        paintBorder(g);
    }

    private void replaceTextRange(char ac[], int i, int j, boolean flag)
        throws IllegalArgumentException
    {
        i = clipIndex(i);
        j = clipIndex(j);
        if(ac != null && ac.length > 0)
        {
            if(!validText(ac, 0, ac.length))
                throw new IllegalArgumentException();
            int k = ((textLength + ac.length) - j) + i;
            if(k + 1 > text.length)
            {
                char ac1[] = new char[k + 50];
                short aword0[] = new short[k + 50];
                if(i > 0)
                {
                    System.arraycopy(text, 0, ac1, 0, i);
                    System.arraycopy(textWidth, 0, aword0, 0, i);
                }
                if(j < textLength)
                {
                    System.arraycopy(text, j, ac1, i + ac.length, textLength - j);
                    System.arraycopy(textWidth, j, aword0, i + ac.length, textLength - j);
                }
                text = ac1;
                textWidth = aword0;
            } else
            if(j < textLength)
            {
                System.arraycopy(text, j, text, i + ac.length, textLength - j);
                System.arraycopy(textWidth, j, textWidth, i + ac.length, textLength - j);
            }
            System.arraycopy(ac, 0, text, i, ac.length);
            if(multiLine)
            {
                short word0 = echoChar != 0 ? (short)itsFont.charWidth(echoChar) : 0;
                for(int l = 0; l < ac.length; l++)
                    textWidth[i + l] = word0 != 0 ? word0 : (short)itsFont.charWidth(ac[l]);

            } else
            {
                short word1 = echoChar != 0 ? (short)itsFont.charWidth(echoChar) : 0;
                for(int i1 = 0; i1 < ac.length; i1++)
                {
                    if(ac[i1] == '\n' || ac[i1] == '\r')
                        text[i + i1] = ' ';
                    textWidth[i + i1] = word1 != 0 ? word1 : (short)itsFont.charWidth(ac[i1]);
                }

            }
            textLength = k;
        } else
        if(j > i)
        {
            System.arraycopy(text, j, text, i, textLength - j);
            System.arraycopy(textWidth, j, textWidth, i, textLength - j);
            textLength -= j - i;
        }
        if(lengthLimit > 0 && textLength > lengthLimit)
            textLength = lengthLimit;
        caretPosition = clipIndex(caretPosition);
        reformatText(i, textLength - 1);
        textChanged(i, j, flag);
    }

    private void replaceTextRange(char c, int i, int j, boolean flag)
    {
        oneChar[0] = c;
        replaceTextRange(oneChar, i, j, flag);
    }
}

⌨️ 快捷键说明

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