alertlfimpl.java
来自「This is a resource based on j2me embedde」· Java 代码 · 共 596 行 · 第 1/2 页
JAVA
596 行
/* * * * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version * 2 only, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License version 2 for more details (a copy is * included at /legal/license.txt). * * You should have received a copy of the GNU General Public License * version 2 along with this work; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa * Clara, CA 95054 or visit www.sun.com if you need additional * information or have any questions. */package javax.microedition.lcdui;import com.sun.midp.i18n.Resource;import com.sun.midp.i18n.ResourceConstants;import com.sun.midp.util.ResourceHandler;import java.util.Timer;import java.util.TimerTask;import com.sun.midp.security.SecurityToken;import com.sun.midp.security.SecurityInitializer;import com.sun.midp.security.ImplicitlyTrustedClass;/** * Look & Feel implementation of <code>Alert</code> based on * platform widget. */class AlertLFImpl extends DisplayableLFImpl implements AlertLF { /** * Creates an <code>AlertLF</code> for the passed in <code>Alert</code> * instance. * @param a The <code>Alert</code> associated with this look & feel */ AlertLFImpl(Alert a) { super(a); alert = a; } // ************************************************************ // public methods - AlertLF interface implementation // ************************************************************ /** * Determines if <code>Alert</code> associated with this view is modal. * * @return true if this <code>AlertLF</code> should be displayed as modal */ public boolean lIsModal() { if (alert.numCommands > 1) { return true; } if (isContentScroll < 0) { layout(); } return (isContentScroll == 1); } /** * Gets default timeout for the <code>Alert</code> associated with * this view. * * @return the default timeout */ public int lGetDefaultTimeout() { return DEFAULT_TIMEOUT; } /** * Return the command that should be mapped to * <code>Alert.DISMISS_COMMAND</code>. * * @return command that maps to <code>Alert.DISMISS_COMMAND</code> */ public Command lGetDismissCommand() { return DISMISS_COMMAND; } /** * Notifies timeout change. * Changing timeout on an already visible <code>Alert</code> will * restart the timer, but has no effect on current layout. * * @param timeout the new timeout set in the corresponding * <code>Alert</code>. */ public void lSetTimeout(int timeout) { if (timerTask != null) { try { timerTask.cancel(); if (timeout == Alert.FOREVER) { timerTask = null; } else { timerTask = new TimeoutTask(); timeoutTimer.schedule(timerTask, timeout); } } catch (Throwable t) { } } } /** * Notifies <code>Alert</code> type change. * Changing type on an already visible <code>Alert</code> will only * update the default icon. No sound will be played. * * @param type the new <code>AlertType</code> set in the * corresponding <code>Alert</code>. */ public void lSetType(AlertType type) { lRequestInvalidate(); } /** * Notifies string change. * * @param oldString the old string set in the corresponding * <code>Alert</code>. * @param newString the new string set in the corresponding * <code>Alert</code>. */ public void lSetString(String oldString, String newString) { lRequestInvalidate(); } /** * Notifies image change. * * @param oldImg the old image set in the corresponding * <code>Alert</code>. * @param newImg the new image set in the corresponding * <code>Alert</code>. */ public void lSetImage(Image oldImg, Image newImg) { lRequestInvalidate(); } /** * Notifies indicator change. * * @param oldIndicator the old indicator set in the corresponding * <code>Alert</code>. * @param newIndicator the new indicator set in the corresponding * <code>Alert</code>. */ public void lSetIndicator(Gauge oldIndicator, Gauge newIndicator) { lRequestInvalidate(); } /** * Notify this <code>Alert</code> that it is being displayed. * Override the version in <code>DisplayableLFImpl</code>. */ void lCallShow() { // Create native resource with title and ticker super.lCallShow(); // Play sound if (alert.type != null) { currentDisplay.playAlertSound(alert.type); } // Setup contained items and show them showContents(); // Show the Alert dialog window showNativeResource0(nativeId); // Start Java timer // If native dialog will cause VM to freeze, this timer // needs to be moved to native. if (alert.time != Alert.FOREVER && alert.numCommands == 1 && isContentScroll == 0) { if (timeoutTimer == null) { timeoutTimer = new Timer(); } timerTask = new TimeoutTask(); timeoutTimer.schedule(timerTask, alert.time); } } /** * Notify this <code>Alert</code> that it will no longer be displayed. * Override the version in <code>DisplayableLFImpl</code>. */ void lCallHide() { // Stop the timer if (timerTask != null) { try { timerTask.cancel(); timerTask = null; } catch (Throwable t) { } } // Hide and delete gauge resource if (alert.indicator != null) { GaugeLFImpl gaugeLF = (GaugeLFImpl)alert.indicator.gaugeLF; gaugeLF.lHideNativeResource(); gaugeLF.deleteNativeResource(); if (gaugeLF.visibleInViewport) { gaugeLF.lCallHideNotify(); } } // Hide and delete alert dialog window including title and ticker super.lCallHide(); } /** * Called by the event handler to perform a re-layout * on this <code>AlertLF</code>. */ public void uCallInvalidate() { synchronized (Display.LCDUILock) { showContents(); } } /** * Notify return screen about screen size change */ public void uCallSizeChanged(int w, int h) { super.uCallSizeChanged(w,h); Displayable returnScreen = alert.getReturnScreen(); if (returnScreen != null) { (returnScreen.displayableLF).uCallSizeChanged(w,h); } } // ***************************************************** // Package private methods // ***************************************************** /** * Called upon content change to schedule a request for relayout and * repaint. */ void lRequestInvalidate() { super.lRequestInvalidate(); isContentScroll = -1; // Unknown scrolling state } // ***************************************************** // Private methods // ***************************************************** /** * Layout the content of this <code>Alert</code>. * Query native resource for two informations: * - Whether the content needs scrolling, in 'isContentScroll' * - Location of the gauge indicator * * SYNC NOTE: Caller of this function should hold LCDUILock around * this call. */ private void layout() { boolean wasNoNative = (nativeId == INVALID_NATIVE_ID); // If no native resource yet, create it temporarily if (wasNoNative) { createNativeResource(); } Image img = alert.image; // If no image is specified, default icon for that type should be used if (img == null && alert.type != null) { img = getAlertImage(alert.type); } // Bounds array of gauge // The reason gauge bounds is passed back from native is to be // consistent with Form's Java layout code.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?