📄 textcomponent.java
字号:
// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi
// Source File Name: TextComponent.java
package com.motorola.lwt;
import javax.microedition.lcdui.*;
// Referenced classes of package com.motorola.lwt:
// Component
public abstract class TextComponent extends Component
{
public static final int JUSTIFY_LEFT = 0;
public static final int JUSTIFY_CENTER = 1;
public static final int JUSTIFY_RIGHT = 2;
public static final int NO_LIMIT = 0;
static final int MARGIN = 2;
int justification;
int viewPortOriginX;
int viewPortOriginY;
int rows;
int columns;
int rowBoundaries[];
int rowCount;
char text[];
short textWidth[];
int textLength;
int caretPosition;
int lengthLimit;
boolean editable;
int screenPositionX;
int screenPositionY;
Font itsFont;
int lineHeight;
char echoChar;
boolean multiLine;
int constraint;
int lastWidth;
int lastHeight;
char oneChar[];
TextComponent(String s, boolean flag)
{
justification = 0;
viewPortOriginX = 0;
viewPortOriginY = 0;
rows = 1;
columns = 1;
rowBoundaries = new int[5];
rowCount = 1;
textLength = 0;
caretPosition = 0;
lengthLimit = 0;
editable = true;
screenPositionX = 0;
screenPositionY = 0;
itsFont = Font.getDefaultFont();
lineHeight = itsFont.getHeight();
echoChar = '\0';
multiLine = false;
constraint = 0;
lastWidth = 0;
lastHeight = 0;
oneChar = new char[1];
multiLine = flag;
if(s != null)
{
int i = s.length();
text = new char[i + 10];
textWidth = new short[i + 10];
setText(s);
} else
{
text = new char[10];
textWidth = new short[10];
}
acceptsKeyFocus = true;
}
public void setConstraint(int i)
throws IllegalArgumentException
{
if(i >= 0 && i <= 4)
{
constraint = i;
if(!validText(text, 0, textLength))
setText("");
return;
} else
{
throw new IllegalArgumentException();
}
}
public int getConstraint()
{
return constraint;
}
public int getPreferredWidth()
{
return itsFont.charWidth('W') * columns;
}
public int getPreferredHeight()
{
return lineHeight * rows + 10;
}
public Font getFont()
{
return itsFont;
}
public void setFont(Font font)
{
if(font == null)
font = Font.getDefaultFont();
itsFont = font;
lineHeight = font.getHeight();
for(int i = textLength - 1; i >= 0; i--)
textWidth[i] = (short)font.charWidth(text[i]);
preferredWidthChanged();
preferredHeightChanged();
reformatText(0, textLength - 1);
}
public void setJustification(int i)
throws IllegalArgumentException
{
if(justification != i)
if(i >= 0 && i <= 2)
{
justification = i;
repaint();
} else
{
throw new IllegalArgumentException();
}
}
public char getEchoChar()
{
return echoChar;
}
public void setEchoChar(char c)
{
if(c != echoChar)
{
echoChar = c;
char ac[] = getText().toCharArray();
replaceTextRange(ac, 0, textLength, false);
}
}
public int getLengthLimit()
{
return lengthLimit;
}
public void setLengthLimit(int i)
{
if(i != lengthLimit)
{
if(i <= 0)
i = 0;
lengthLimit = i;
if(lengthLimit != 0 && textLength > lengthLimit)
{
textLength = lengthLimit;
textChanged(0, textLength, false);
}
}
}
public synchronized String getText()
{
return new String(text, 0, textLength);
}
public synchronized void setText(String s)
throws IllegalArgumentException
{
replaceTextRange(s != null ? s.toCharArray() : null, 0, textLength, false);
}
public synchronized void appendText(String s)
throws IllegalArgumentException
{
replaceTextRange(s.toCharArray(), textLength, textLength, false);
}
public synchronized void appendChar(char c)
throws IllegalArgumentException
{
replaceTextRange(c, textLength, textLength, false);
}
public synchronized void insertText(String s, int i)
throws IllegalArgumentException
{
replaceTextRange(s.toCharArray(), i, i, false);
}
public synchronized void insertChar(char c, int i)
throws IllegalArgumentException
{
replaceTextRange(c, i, i, false);
}
public void pointerPressed(int i, int j)
{
requestFocus();
setCaretPosition(charIndex(i, j + lineHeight));
}
public boolean keyRepeated(int i)
{
return keyPressed(i);
}
public boolean keyPressed(int i)
{
if(i == parent.getKeyCode(2))
{
setCaretPosition(caretPosition - 1);
return true;
}
if(i == parent.getKeyCode(1))
if(getRowNumber(caretPosition) > 0)
{
screenPosition(caretPosition);
int j = screenPositionY - lineHeight;
if(!editable)
j = getHeight() * 2;
setCaretPosition(charIndex(screenPositionY, j));
return true;
} else
{
return false;
}
if(i == parent.getKeyCode(5))
{
setCaretPosition(caretPosition + 1);
return true;
}
if(i == parent.getKeyCode(6))
if(getRowNumber(caretPosition) < rowCount - 1)
{
screenPosition(caretPosition);
int k = screenPositionY + lineHeight;
if(!editable)
k = getHeight() * 2;
setCaretPosition(charIndex(screenPositionY, k));
return true;
} else
{
return false;
}
if(i <= 0)
return false;
if(editable)
{
switch(i)
{
case 8: // '\b'
if(caretPosition > 0)
{
setCaretPosition(caretPosition - 1);
replaceTextRange(((char []) (null)), caretPosition, caretPosition + 1, true);
}
return true;
case 127: // '\177'
if(caretPosition < textLength)
{
replaceTextRange(((char []) (null)), caretPosition, caretPosition + 1, true);
setCaretPosition(caretPosition);
}
return true;
case 10: // '\n'
if(multiLine)
{
replaceTextRange('\n', caretPosition, caretPosition, true);
setCaretPosition(caretPosition + 1);
return true;
} else
{
return false;
}
case 201:
case 202:
case 203:
case 204:
return false;
}
try
{
char c = (char)i;
if(itsFont.charWidth(c) > 0 && (lengthLimit == 0 || textLength < lengthLimit))
{
replaceTextRange(c, caretPosition, caretPosition, true);
setCaretPosition(caretPosition + 1);
}
}
catch(Throwable _ex) { }
}
return true;
}
protected void textChanged(int i, int j, boolean flag)
{
}
int getRowNumber(int i)
{
int j;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -