📄 stack.java
字号:
/*
* Copyright (C) 2006-2007 Funambol
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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 for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package com.funambol.mailclient.ui.controller;
import javax.microedition.lcdui.*;
/**
* This class can be used to implement a stack of displayable screens.
* It provides a function to go forward and back with the screens
* of the UI
*/
public class Stack {
/** Array of screens in the Stack
* Configure the right dimension of the stack considering the depth of the
* UI workflow: i.e. how many back commands do we need to go back from the
* leaf to the root of the UI?
*/
private Displayable [] screens;
private final int STACK_DEPTH=20;
public Stack() {
screens = new Displayable [STACK_DEPTH];
}
/**
* Insert a screen in the Stack
* @param d Displayable screen to put in the Stack in order to retrieve later
*/
public void push(Displayable d) {
if ((d!=null) && (d!=screens[0]) && !(d instanceof Alert)) {
for (int i=STACK_DEPTH-1; i>0;i--) {
screens[i] = screens[i-1];
}
screens[0] = d;
}
}
/**
* Get the latest Screen to go back
* @return Returns the Displayable Screen to display to go back
*/
public Displayable pop() {
Displayable result = screens[0];
for (int i=0; i<STACK_DEPTH-2;i++) {
screens[i] = screens[i+1];
}
screens[STACK_DEPTH-1] = null;
return result;
}
public Displayable peek() {
try {
return screens[0];
} catch (NullPointerException ex) {
return null;
}
}
public void clear() {
for (int i=0; i<STACK_DEPTH-2;i++) {
screens[i] = null;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -