📄 framedform.java
字号:
//#condition polish.usePolishGui
/*
* Created on 12-Apr-2005 at 13:31:53.
*
* Copyright (c) 2005 Robert Virkus / Enough Software
*
* This file is part of J2ME Polish.
*
* J2ME Polish 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.
*
* J2ME Polish 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 J2ME Polish; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Commercial licenses are also available, please
* refer to the accompanying LICENSE.txt or visit
* http://www.j2mepolish.org for details.
*/
package de.enough.polish.ui;
import javax.microedition.lcdui.Graphics;
/**
* <p>Allows to split up a form into several frames.</p>
* <p>The main frame is used for the normal content. Additional frames
* can be used for keeping GUI elements always in the same position,
* regardless whether the form is scrolled.
* </p>
*
* <p>Copyright (c) 2005, 2006 Enough Software</p>
* <pre>
* history
* 14-Apr-2005 - rob creation
* </pre>
* @author Robert Virkus, j2mepolish@enough.de
*/
public class FramedForm extends Form {
private Container leftFrame;
private Container rightFrame;
private Container topFrame;
private Container bottomFrame;
private int originalContentHeight;
private int originalContentWidth;
private boolean expandRightFrame;
private boolean expandLeftFrame;
private Container currentlyActiveContainer;
private int originalContentY;
private int originalContentX;
/**
* Creates a new FramedForm
*
* @param title the title of this form
*/
public FramedForm(String title ) {
this( title, null );
}
/**
* Creates a new FramedForm
*
* @param title the title of this form
* @param style the style of this form, usually set with a #style directive
*/
public FramedForm(String title, Style style) {
super( title, style );
this.currentlyActiveContainer = this.container;
//#if polish.Container.allowCycling != false
this.container.allowCycling = false;
//#endif
}
private Container getFrame( int frameOrientation ) {
switch (frameOrientation) {
case Graphics.TOP:
return this.topFrame;
case Graphics.BOTTOM:
return this.bottomFrame;
case Graphics.LEFT:
return this.leftFrame;
case Graphics.RIGHT:
return this.rightFrame;
}
return this.container;
}
/**
* Deletes all the items from all frames of this <code>FramedForm</code>, leaving it with zero items.
* This method does nothing if the <code>FramedForm</code> is already empty.
*
* @since MIDP 2.0
*/
public void deleteAll()
{
super.deleteAll();
if (this.leftFrame != null)
{
this.leftFrame.clear();
}
if (this.rightFrame != null)
{
this.rightFrame.clear();
}
if (this.topFrame != null)
{
this.topFrame.clear();
}
if (this.bottomFrame != null)
{
this.bottomFrame.clear();
}
}
/**
* Removes all items from the specifid frame.
*
* @param frameOrientation either Graphics.TOP, Graphics.BOTTOM, Graphics.LEFT or Graphics.RIGHT
*/
public void deleteAll( int frameOrientation ) {
Container frame = getFrame( frameOrientation );
if (frame != null) {
frame.clear();
}
}
//#if polish.LibraryBuild
//# public int append( javax.microedition.lcdui.Item item ) {
//# // just a convenience method, in reality the append( Item item ) method is called
//# return -1;
//# }
//#endif
//#if polish.LibraryBuild
//# public void set( int frameIndex, int itemNumber, javax.microedition.lcdui.Item item ) {
//# // just a convenience method, in reality the append( Item item ) method is called
//# }
//#endif
//#if polish.LibraryBuild
//# public void set( int itemNumber, javax.microedition.lcdui.Item item ) {
//# // just a convenience method, in reality the append( Item item ) method is called
//# }
//#endif
//#if polish.LibraryBuild
//# public void append( int frameOrientation, javax.microedition.lcdui.Item item ) {
//# // just a convenience method, in reality the addItem( Item item, int frameOrientation ) method is called
//# }
//#endif
//#if polish.LibraryBuild
//# public void setItemStateListener( javax.microedition.lcdui.ItemStateListener listener ) {
//# throw new RuntimeException("Unable to use standard ItemStateListener in a framed form.");
//# }
//#endif
/**
* Adds the given item to the specifid frame.
*
* @param frameOrientation either Graphics.TOP, Graphics.BOTTOM, Graphics.LEFT or Graphics.RIGHT
* @param item the item
*/
public void append( int frameOrientation, Item item ) {
append( frameOrientation, item, null );
}
/**
* Updates an existing item in the specified frame
* @param frameOrientation either Graphics.TOP, Graphics.BOTTOM, Graphics.LEFT or Graphics.RIGHT
* @param itemNum the index of the previous item
* @param item the new item
*/
public void set( int frameOrientation, int itemNum, Item item ) {
Container frame = getFrame( frameOrientation );
if (frame != null) {
frame.set(itemNum, item);
}
}
/**
* Removes the given item from the specifid frame.
* The <code>itemNum</code> parameter must be
* within the range <code>[0..size()-1]</code>, inclusive.
*
* @param frameOrientation either Graphics.TOP, Graphics.BOTTOM, Graphics.LEFT or Graphics.RIGHT
* @param itemNum the index of the item
*/
public void delete( int frameOrientation, int itemNum ) {
Container frame = getFrame( frameOrientation );
if (frame != null) {
frame.remove(itemNum);
}
}
/**
* Adds the given item to the specifid frame.
*
* @param frameOrientation either Graphics.TOP, Graphics.BOTTOM, Graphics.LEFT or Graphics.RIGHT
* @param item the item
* @param itemStyle the style for that item, is ignored when null
*/
public void append( int frameOrientation, Item item, Style itemStyle ) {
if (itemStyle != null) {
item.setStyle( itemStyle );
}
Container frame;
switch (frameOrientation) {
case Graphics.TOP:
if (this.topFrame == null) {
//#style topframe, frame, default
this.topFrame = new Container( false , de.enough.polish.ui.StyleSheet.defaultStyle );
}
frame = this.topFrame;
break;
case Graphics.BOTTOM:
if (this.bottomFrame == null) {
//#style bottomframe, frame, default
this.bottomFrame = new Container( false , de.enough.polish.ui.StyleSheet.defaultStyle );
}
frame = this.bottomFrame;
break;
case Graphics.LEFT:
if (this.leftFrame == null) {
//#style leftframe, frame, default
this.leftFrame = new Container( false , de.enough.polish.ui.StyleSheet.defaultStyle );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -