001: /*
002: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
004: *
005: * This program is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU General Public License version
007: * 2 only, as published by the Free Software Foundation.
008: *
009: * This program is distributed in the hope that it will be useful, but
010: * WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * General Public License version 2 for more details (a copy is
013: * included at /legal/license.txt).
014: *
015: * You should have received a copy of the GNU General Public License
016: * version 2 along with this work; if not, write to the Free Software
017: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
018: * 02110-1301 USA
019: *
020: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
021: * Clara, CA 95054 or visit www.sun.com if you need additional
022: * information or have any questions.
023: */
024: package com.sun.mmedia;
025:
026: import javax.microedition.lcdui.*;
027: import javax.microedition.media.MediaException;
028: import javax.microedition.media.control.VideoControl;
029:
030: /**
031: * CustomItem, which supports full screen
032: * (as an off-screen canvas, replacing current Displayable)...
033: */
034: public abstract class MMCustomItem extends CustomItem {
035:
036: // Full screen canvas
037: private Canvas fullScreen = null;
038:
039: // Display to set current displayable
040: private Display display = null;
041:
042: // Saved displayable replaced by canvas in fullscreen mode
043: private Displayable oldDisplayable = null;
044:
045: // Callback to VideoControl implementation to restore sizes of the item
046: // when user manually exits fullscreen mode from the canvas.
047: private VideoControl callerVideoControl = null;
048:
049: // Canvas painter
050: private MIDPVideoPainter videoPainter = null;
051:
052: // Constructor
053: protected MMCustomItem(String label) {
054: super (label);
055: }
056:
057: // Enter fullscreen mode,
058: // setting VideoControl callback to restore normal mode
059: // when user manually exits fullscreen mode from the canvas.
060: public Canvas toFullScreen(VideoControl caller,
061: MIDPVideoPainter painter) {
062: if (fullScreen == null) {
063: fullScreen = new FullScreenCanvas();
064: }
065:
066: if (display == null) {
067: MMHelper mmh = MMHelper.getMMHelper();
068: if (mmh == null)
069: return null;
070:
071: display = mmh.getItemDisplay(this );
072: if (display == null)
073: return null;
074: }
075:
076: callerVideoControl = caller;
077: videoPainter = painter;
078:
079: if (oldDisplayable == null)
080: oldDisplayable = display.getCurrent();
081:
082: // Setting fullscreen canvas
083: display.setCurrent(fullScreen);
084:
085: fullScreen.setFullScreenMode(true);
086:
087: return fullScreen;
088: }
089:
090: // Return to normal, non-fullscreen mode, restoring old displayable
091: public void toNormal() {
092: if (oldDisplayable != null) {
093: display.setCurrent(oldDisplayable);
094: oldDisplayable = null;
095: }
096:
097: callerVideoControl = null;
098: videoPainter = null;
099: }
100:
101: // Fullscreen canvas implementation
102: // Any key or pointer press returns to non-fullscreen mode.
103: class FullScreenCanvas extends Canvas {
104: FullScreenCanvas() {
105: }
106:
107: protected void paint(Graphics g) {
108: g.fillRect(0, 0, getWidth(), getHeight());
109: videoPainter.paintVideo(g);
110: }
111:
112: // Any key returns to normal mode
113: protected void keyPressed(int keyCode) {
114: if (callerVideoControl != null)
115: try {
116: callerVideoControl.setDisplayFullScreen(false);
117: } catch (MediaException me) {
118: }
119: super .keyPressed(keyCode);
120: }
121:
122: // Any click returns to normal mode
123: protected void pointerPressed(int x, int y) {
124: if (callerVideoControl != null)
125: try {
126: callerVideoControl.setDisplayFullScreen(false);
127: } catch (MediaException me) {
128: }
129: super .pointerPressed(x, y);
130: }
131:
132: // Leave fullscreen mode when Canvas becomes invisible
133: protected void hideNotify() {
134: if (callerVideoControl != null)
135: try {
136: callerVideoControl.setDisplayFullScreen(false);
137: } catch (MediaException me) {
138: }
139: super.hideNotify();
140: }
141: }
142: }
|