📄 display.java
字号:
} else {
eventDispatcher.put(new KeyEvent(KeyEvent.KEY_RELEASED, keyCode));
}
}
public void pointerPressed(int x, int y) {
if (current != null) {
eventDispatcher.put(eventDispatcher.new PointerEvent(current,
EventDispatcher.PointerEvent.POINTER_PRESSED, x, y));
}
}
public void pointerReleased(int x, int y) {
if (current != null) {
eventDispatcher.put(eventDispatcher.new PointerEvent(current,
EventDispatcher.PointerEvent.POINTER_RELEASED, x, y));
}
}
public void pointerDragged(int x, int y) {
if (current != null) {
eventDispatcher.put(eventDispatcher.new PointerEvent(current,
EventDispatcher.PointerEvent.POINTER_DRAGGED, x, y));
}
}
public void paint(Graphics g) {
// TODO consider removal of DisplayAccess::paint(..)
if (current != null) {
try {
current.paint(g);
} catch (Throwable th) {
th.printStackTrace();
}
g.translate(-g.getTranslateX(), -g.getTranslateY());
}
}
public Displayable getCurrent() {
return getDisplay().getCurrent();
}
public DisplayableUI getCurrentUI() {
Displayable current = getCurrent();
if (current == null) {
return null;
} else {
return current.ui;
}
}
public boolean isFullScreenMode() {
Displayable current = getCurrent();
if (current instanceof Canvas) {
return ((Canvas) current).fullScreenMode;
} else {
return false;
}
}
public void serviceRepaints() {
getDisplay().serviceRepaints();
}
public void setCurrent(Displayable d) {
getDisplay().setCurrent(d);
}
public void sizeChanged(int width, int height) {
if (current != null) {
if (current instanceof GameCanvas) {
GameCanvasKeyAccess access = MIDletBridge.getMIDletAccess().getGameCanvasKeyAccess();
access.initBuffer();
}
current.sizeChanged(width, height);
updateCommands();
}
}
public void updateCommands() {
getDisplay().updateCommands();
}
public void clean() {
if (current != null) {
current.hideNotify();
}
eventDispatcher.cancel();
timer.cancel();
}
}
private class AlertTimeout implements Runnable {
int time;
AlertTimeout(int time) {
this.time = time;
}
public void run() {
try {
Thread.sleep(time);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
Displayable d = current;
if (d != null && d instanceof Alert) {
Alert alert = (Alert) d;
if (alert.time != Alert.FOREVER) {
alert.getCommandListener().commandAction((Command) alert.getCommands().get(0), alert);
}
}
}
}
private final Timer timer = new Timer();
/**
* Wrap any runnable as a timertask so that when the timer gets fired, the
* runnable gets run
*
* @author radoshi
*
*/
private final class RunnableWrapper extends TimerTask {
private final Runnable runnable;
RunnableWrapper(Runnable runnable) {
this.runnable = runnable;
}
public void run() {
eventDispatcher.put(runnable);
}
}
Display() {
accessor = new DisplayAccessor(this);
startEventDispatcher();
timer.scheduleAtFixedRate(new RunnableWrapper(new TickerPaintTask()), 0, Ticker.PAINT_TIMEOUT);
timer.scheduleAtFixedRate(new RunnableWrapper(new GaugePaintTask()), 0, Ticker.PAINT_TIMEOUT);
}
private final void startEventDispatcher() {
Thread thread = new Thread(eventDispatcher, EVENT_DISPATCHER_NAME);
thread.setDaemon(true);
thread.start();
}
public void callSerially(Runnable runnable) {
eventDispatcher.put(runnable);
}
public int numAlphaLevels() {
return DeviceFactory.getDevice().getDeviceDisplay().numAlphaLevels();
}
public int numColors() {
return DeviceFactory.getDevice().getDeviceDisplay().numColors();
}
public boolean flashBacklight(int duration) {
// TODO
return false;
}
public static Display getDisplay(MIDlet m) {
Display result;
if (MIDletBridge.getMIDletAccess(m).getDisplayAccess() == null) {
result = new Display();
MIDletBridge.getMIDletAccess(m).setDisplayAccess(result.accessor);
} else {
result = MIDletBridge.getMIDletAccess(m).getDisplayAccess().getDisplay();
}
return result;
}
public int getColor(int colorSpecifier) {
// TODO implement better
switch (colorSpecifier) {
case COLOR_BACKGROUND:
case COLOR_HIGHLIGHTED_FOREGROUND:
case COLOR_HIGHLIGHTED_BORDER:
return 0xFFFFFF;
default:
return 0x000000;
}
}
public int getBorderStyle(boolean highlighted) {
// TODO implement better
return highlighted ? Graphics.DOTTED : Graphics.SOLID;
}
public int getBestImageWidth(int imageType) {
// TODO implement
return 0;
}
public int getBestImageHeight(int imageType) {
// TODO implement
return 0;
}
public Displayable getCurrent() {
return current;
}
public boolean isColor() {
return DeviceFactory.getDevice().getDeviceDisplay().isColor();
}
public void setCurrent(Displayable nextDisplayable) {
if (nextDisplayable != null) {
eventDispatcher.put(new ShowHideNotifyEvent(ShowHideNotifyEvent.SHOW_NOTIFY, current, nextDisplayable));
}
}
public void setCurrent(Alert alert, Displayable nextDisplayable) {
// TODO check if nextDisplayble is Alert
// TODO change to putInQueue implementation
Alert.nextDisplayable = nextDisplayable;
current = alert;
current.showNotify(this);
updateCommands();
current.repaint();
if (alert.getTimeout() != Alert.FOREVER) {
AlertTimeout at = new AlertTimeout(alert.getTimeout());
Thread t = new Thread(at);
t.start();
}
}
public void setCurrentItem(Item item) {
// TODO implement
}
public boolean vibrate(int duration) {
return DeviceFactory.getDevice().vibrate(duration);
}
// Who call this?? (Andres Navarro)
void clearAlert() {
setCurrent(Alert.nextDisplayable);
}
static int getGameAction(int keyCode) {
return DeviceFactory.getDevice().getInputMethod().getGameAction(keyCode);
}
static int getKeyCode(int gameAction) {
return DeviceFactory.getDevice().getInputMethod().getKeyCode(gameAction);
}
static String getKeyName(int keyCode) throws IllegalArgumentException {
return DeviceFactory.getDevice().getInputMethod().getKeyName(keyCode);
}
boolean isShown(Displayable d) {
if (current == null || current != d) {
return false;
} else {
return true;
}
}
void repaint(Displayable d, int x, int y, int width, int height) {
if (current == d) {
eventDispatcher.put(eventDispatcher.new PaintEvent(x, y, width, height));
}
}
void serviceRepaints() {
//
// If service repaints is being called from the event thread, then we
// just execute an immediate repaint and call it a day. If it is being
// called from another thread, then we setup a repaint barrier and wait
// for that barrier to execute
//
if (EVENT_DISPATCHER_NAME.equals(Thread.currentThread().getName())) {
DeviceFactory.getDevice().getDeviceDisplay().repaint(0, 0, current.getWidth(), current.getHeight());
return;
}
eventDispatcher.serviceRepaints();
}
void setScrollDown(boolean state) {
DeviceFactory.getDevice().getDeviceDisplay().setScrollDown(state);
}
void setScrollUp(boolean state) {
DeviceFactory.getDevice().getDeviceDisplay().setScrollUp(state);
}
void updateCommands() {
if (current == null) {
CommandManager.getInstance().updateCommands(null);
} else {
CommandManager.getInstance().updateCommands(current.getCommands());
}
repaint(current, 0, 0, current.getWidth(), current.getHeight());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -