📄 inputsprite.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)
// Source File Name: InputSprite.java
package se.southend.drops.gui;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import se.southend.drops.scene.Sprite;
import se.southend.drops.screen.Device;
import se.southend.drops.screen.KeyHandler;
// Referenced classes of package se.southend.drops.gui:
// InputField
public class InputSprite extends Sprite
{
public InputSprite(Font textFont, int textColor, int maxWidth)
{
inputField = new InputField();
setTextFont(textFont);
setTextColor(textColor);
setCaretColor(textColor);
setMaxWidth(maxWidth);
inputField.setInputMode(2);
setCaretBlinkingDuration(750);
setCaretVisible(true);
caretAdvanceDelay = 1000;
caretWidth = 2;
passwordChar = '\0';
empty();
}
public void empty()
{
inputField.empty();
textHeight = textFont.getHeight();
textWidth = 0;
textStart = 0;
textEnd = 0;
xCaret = 0;
output = null;
updatedSincePress = true;
caretBlink(true);
}
public InputField getInputField()
{
return inputField;
}
public void setCaretVisible(boolean visible)
{
caretVisible = visible;
}
public void setCaretBlinkingDuration(int duration)
{
caretBlinkingDuration = duration;
}
public void setTextColor(int textColor)
{
this.textColor = textColor;
}
public void setCaretColor(int textColor)
{
caretColor = caretColor;
}
public void setTextFont(Font textFont)
{
this.textFont = textFont;
}
public int getMaxWidth()
{
return textMaxWidth;
}
public void setMaxWidth(int textMaxWidth)
{
this.textMaxWidth = textMaxWidth;
}
public void setPasswordChar(char c)
{
passwordChar = c;
inputField.setPasswordChar(c);
}
public String getText()
{
return inputField.getText();
}
public void setText(String text)
{
if(text == null)
text = "";
inputField.setText(text);
inputField.setCaretPosition(text.length());
textStart = 0;
textEnd = text.length();
update();
}
public void input(KeyHandler keyHandler)
{
boolean update = true;
if(keyHandler.wasPressed(0x1000000))
{
inputField.backspace();
textStart--;
} else
if(keyHandler.wasPressed(1))
inputField.caretLeft();
else
if(keyHandler.wasPressed(2))
{
inputField.caretRight();
} else
{
long currentTime = Device.getTime();
int keyLastPressed = keyHandler.getLastPressed();
if(keyHeld != keyLastPressed)
{
keyHeld = keyLastPressed;
if(keyLastPressed != 0)
{
if(keyLastPressed != keySwitched)
{
keySwitched = keyLastPressed;
inputField.placeCharacter();
textEnd++;
}
keyTimer = Device.getTime();
keyPressed(keyLastPressed);
updatedSincePress = false;
}
} else
if(keyHeld != 0)
{
if(currentTime >= keyTimer + 750L)
{
keyTimer = Device.getTime();
keyHeldLong(keyHeld);
updatedSincePress = false;
}
} else
{
update = false;
if(currentTime >= keyTimer + 1000L)
{
inputField.placeCharacter();
if(passwordChar != 0 && !updatedSincePress)
{
update = true;
updatedSincePress = true;
}
}
}
}
if(update)
update();
}
private void update()
{
String text = inputField.getDisplayText();
int caretPos = inputField.getCaretPosition();
if(textEnd > text.length())
textEnd = text.length();
if(textStart < 0)
textStart = 0;
else
if(caretPos < textStart)
textStart = caretPos;
output = text.substring(textStart, textEnd);
for(textWidth = textFont.stringWidth(output); textEnd < text.length() && (textEnd < caretPos || textWidth < textMaxWidth); textWidth = textFont.stringWidth(output))
{
if(textWidth <= textMaxWidth)
textEnd++;
output = text.substring(textStart, textEnd);
}
do
{
output = text.substring(textStart, textEnd);
textWidth = textFont.stringWidth(output);
xCaret = textFont.stringWidth(text.substring(textStart, caretPos));
if(textWidth > textMaxWidth)
if(caretPos == text.length() || xCaret > textMaxWidth)
textStart++;
else
textEnd--;
} while(textWidth > textMaxWidth);
caretBlink(true);
}
private void caretBlink(boolean show)
{
caretShowing = show;
caretBlinkTime = Device.getTime() + (long)caretBlinkingDuration;
}
private void keyPressed(int key)
{
switch(key)
{
default:
break;
case 512:
inputField.press(0);
break;
case 1024:
inputField.press(1);
break;
case 2048:
inputField.press(2);
break;
case 4096:
inputField.press(3);
break;
case 8192:
inputField.press(4);
break;
case 16384:
inputField.press(5);
break;
case 32768:
inputField.press(6);
break;
case 65536:
inputField.press(7);
break;
case 131072:
inputField.press(8);
break;
case 262144:
inputField.press(9);
break;
case 524288:
inputField.press(10);
break;
case 1048576:
if(inputField.getInputMode() == 2)
inputField.setInputMode(1);
else
inputField.setInputMode(2);
break;
}
}
private void keyHeldLong(int key)
{
switch(key)
{
default:
break;
case 512:
inputField.hold(0);
break;
case 1024:
inputField.hold(1);
break;
case 2048:
inputField.hold(2);
break;
case 4096:
inputField.hold(3);
break;
case 8192:
inputField.hold(4);
break;
case 16384:
inputField.hold(5);
break;
case 32768:
inputField.hold(6);
break;
case 65536:
inputField.hold(7);
break;
case 131072:
inputField.hold(8);
break;
case 262144:
inputField.hold(9);
break;
case 524288:
if(inputField.getInputType() == 1)
inputField.setInputType(0);
else
inputField.setInputType(1);
break;
}
}
public int getWidth()
{
return textWidth;
}
public int getHeight()
{
return textHeight;
}
public void paint(Graphics graphics)
{
if(!isOnScreen())
return;
int xScr = getScreenX();
int yScr = getScreenY();
if(textFont == null)
textFont = graphics.getFont();
if(!caretVisible)
caretShowing = false;
else
if(caretBlinkingDuration > 0)
{
if(Device.getTime() > caretBlinkTime)
caretBlink(!caretShowing);
} else
{
caretShowing = true;
}
if(caretShowing)
{
graphics.setColor(caretColor);
InputField _tmp = inputField;
if(inputField.getInputMode() == 2)
{
graphics.fillRect(xScr + xCaret, yScr, caretWidth, textFont.getBaselinePosition());
} else
{
int offset = textFont.getBaselinePosition() / 4;
graphics.fillRect(xScr + xCaret, yScr + offset, caretWidth, textFont.getBaselinePosition() - offset);
}
}
if(output != null)
{
graphics.setColor(textColor);
graphics.setFont(textFont);
graphics.drawString(output, xScr, yScr, 20);
}
}
private static final int CARET_ADVANCE_DELAY = 1000;
private static final int CARET_BLINKING_DURATION = 750;
private static final int CARET_WIDTH = 2;
private static final int KEY_HELD_DURATION = 750;
private InputField inputField;
private int textMaxWidth;
private int textWidth;
private int textHeight;
private Font textFont;
private int textColor;
private int caretColor;
private int textStart;
private int textEnd;
private int caretWidth;
private int caretBlinkingDuration;
private int caretAdvanceDelay;
private boolean caretShowing;
private boolean caretVisible;
private long caretBlinkTime;
private int xCaret;
private String output;
private long keyTimer;
private boolean updatedSincePress;
private int keyHeld;
private int keySwitched;
private char passwordChar;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -