📄 treeitem.java
字号:
//#condition polish.usePolishGui
/*
* Created on 30-Dez-2005 at 16:32:21.
*
* 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 java.io.IOException;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
/**
* <p>Provides a tree of items that can contain several branches.</p>
* <p>Each tree branch behaves like a normal J2ME Polish container, so
* you can specify view-types, columns, colspans, etc.
* </p>
*
* <p>Copyright (c) 2005, 2006, 2007 Enough Software</p>
* <pre>
* history
* 16-Feb-2005 - rob creation
* </pre>
* @author Robert Virkus, j2mepolish@enough.de
*/
public class TreeItem
//#if polish.LibraryBuild
//# extends FakeContainerCustomItem
//#else
extends Container
//#endif
{
/**
* Creates a new tree item.
*
* @param label the label of this item
*/
public TreeItem(String label ) {
this( label, null );
}
/**
* Creates a new tree item.
*
* @param label the label of this item
* @param style the style
*/
public TreeItem(String label, Style style) {
super( false, style );
setLabel( label );
}
//#if polish.LibraryBuild
//# /**
//# * Adds the specified item to this tree.
//# *
//# * @param item the item that should be added
//# */
//# public void appendToRoot( javax.microedition.lcdui.Item item ) {
//# // ignore, only for the users
//# }
//#endif
//#if polish.LibraryBuild
//# /**
//# * Adds the specified item to this tree.
//# *
//# * @param node the parent node that has been previously added to this tree
//# * @param item the item that should be added
//# */
//# public void appendToNode( javax.microedition.lcdui.Item node, javax.microedition.lcdui.Item item ) {
//# // ignore, only for the users
//# }
//#endif
//#if polish.LibraryBuild
//# /**
//# * Adds the specified text/image to this tree.
//# *
//# * @param node the parent node that has been previously added to this tree
//# * @param text the text
//# * @param image the image
//# * @return the created item
//# */
//# public javax.microedition.lcdui.Item appendToNode( javax.microedition.lcdui.Item node, String text, Image image ) {
//# // ignore, only for the users
//# return null;
//# }
//#endif
//#if polish.LibraryBuild
//# /**
//# * Removes the specified item from this list.
//# *
//# * @param item the item that should be removed
//# * @return true when the item was contained in this list.
//# */
//# public boolean remove( javax.microedition.lcdui.Item item ) {
//# // ignore, only for the users
//# return false;
//# }
//#endif
/**
* Appends the specified text and image to this list.
*
* @param text the text
* @param image the image
* @return the created item
*/
//#if polish.LibraryBuild
//# public javax.microedition.lcdui.Item appendToRoot( String text, Image image ) {
//# return null;
//#else
public Item appendToRoot( String text, Image image ) {
return appendToRoot( text, image, null );
//#endif
}
/**
* Appends the specified text and image to this list and provides it with the given style.
*
* @param text the text
* @param image the image
* @param style the style
* @return return the created item
*/
//#if polish.LibraryBuild
//# public javax.microedition.lcdui.Item appendToRoot( String text, Image image, Style style ) {
//#else
public Item appendToRoot( String text, Image image, Style style ) {
//#endif
IconItem item = new IconItem( text, image, style );
appendToRoot( item );
//#if polish.LibraryBuild
//# return null;
//#else
return item;
//#endif
}
/**
* Adds the specified item to this list.
*
* @param item the item that should be added
*/
public void appendToRoot( Item item ) {
add(item);
// this.lastAddedItem = item;
}
/**
* Adds the specified item to this list.
*
* @param item the item that should be added
* @param nodeStyle the style
*/
public void appendToRoot( Item item, Style nodeStyle ) {
if (nodeStyle != null) {
item.setStyle( nodeStyle );
}
add(item);
// this.lastAddedItem = item;
}
/**
* Adds the specified text/image to this tree.
*
* @param node the parent node that has been previously added to this tree
* @param text the text
* @param image the image
* @return the created item
*/
public Item appendToNode( Item node, String text, Image image ) {
return appendToNode(node, text, image, null);
}
/**
* Adds the specified text/image to this tree.
*
* @param node the parent node that has been previously added to this tree
* @param text the text
* @param image the image
* @param style the style
* @return the created item
*/
public Item appendToNode( Item node, String text, Image image, Style style ) {
IconItem item = new IconItem( text, image);
appendToNode( node, item, style );
return item;
}
/**
* Adds the specified item to this tree.
*
* @param node the parent node that has been previously added to this tree
* @param item the item that should be added
*/
public void appendToNode( Item node, Item item ) {
appendToNode(node, item, null);
}
/**
* Adds the specified item to this tree.
*
* @param node the parent node that has been previously added to this tree
* @param item the item that should be added
* @param nodeStyle the style
*/
public void appendToNode( Item node, Item item, Style nodeStyle ) {
if (nodeStyle != null) {
item.setStyle( nodeStyle );
}
// find correct Node:
Node parentNode;
if ( !(node.parent instanceof Node) ) {
// the item has to be converted into a node:
Container parentContainer;
//#if polish.LibraryBuild
//# if ( (Object)node.parent == this) {
//# // this is a root item:
//# parentContainer = (Container) ((Object)this);
//#else
if (node.parent == this) {
// this is a root item:
parentContainer = this;
//#endif
} else {
parentContainer = (Container) node.parent;
}
parentNode = new Node( node );
Item[] items = parentContainer.getItems();
for (int i = 0; i < items.length; i++) {
Item rootItem = items[i];
if ( node == rootItem ) {
parentContainer.set(i, parentNode);
node.parent = parentNode;
break;
}
}
} else {
parentNode = ((Node)node.parent);
}
item.parent = parentNode;
parentNode.addChild(item);
// this.lastAddedItem = item;
}
/**
* Clears this list.
*/
public void removeAll() {
clear();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -