📄 exclusivesinglelineview.java
字号:
//#condition polish.usePolishGui
/*
* Created on 08-Apr-2005 at 11:17:51.
*
* 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.containerviews;
import java.io.IOException;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import de.enough.polish.ui.Background;
import de.enough.polish.ui.ChoiceGroup;
import de.enough.polish.ui.ChoiceItem;
import de.enough.polish.ui.Container;
import de.enough.polish.ui.ContainerView;
import de.enough.polish.ui.Item;
import de.enough.polish.ui.Style;
import de.enough.polish.ui.StyleSheet;
/**
* <p>Shows only the currently selected item of an exclusive ChoiceGroup or an exclusive List.</p>
* <p>Apply this view by specifying "view-type: exclusive-single-line;" in your polish.css file.</p>
*
* <p>Copyright (c) 2005, 2006 Enough Software</p>
* <pre>
* history
* 08-Apr-2005 - rob creation
* </pre>
* @author Robert Virkus, j2mepolish@enough.de
*/
public class ExclusiveSingleLineView extends ContainerView {
private final static int POSITION_BOTH_SIDES = 0;
private final static int POSITION_RIGHT = 1;
private final static int POSITION_LEFT = 2;
private int arrowColor;
//#ifdef polish.css.exclusiveview-left-arrow
//# private Image leftArrow;
//# private int leftYOffset;
//#endif
//#ifdef polish.css.exclusiveview-right-arrow
//# private Image rightArrow;
//# private int rightYOffset;
//#endif
//#ifdef polish.css.exclusiveview-arrow-position
//# private int arrowPosition;
//#ifdef polish.css.exclusiveview-arrow-padding
//# private int arrowPadding;
//#endif
//#endif
private boolean allowRoundTrip;
//#ifdef polish.css.exclusiveview-expand-background
//# private Background background;
//# private boolean expandBackground;
//#endif
private int arrowWidth = 10;
private int currentItemIndex;
private ChoiceItem currentItem;
private int leftArrowStartX;
private int leftArrowEndX;
private int rightArrowStartX;
private int rightArrowEndX;
private int xStart;
private Background parentBackground;
//private boolean isInitialized;
/**
* Creates a new view
*/
public ExclusiveSingleLineView() {
super();
this.allowsAutoTraversal = false;
}
/* (non-Javadoc)
* @see de.enough.polish.ui.ContainerView#initContent(de.enough.polish.ui.Container, int, int)
*/
protected void initContent(Item parentItm, int firstLineWidth, int lineWidth)
{
//#debug
//# System.out.println("Initalizing ExclusiveSingleLineView");
Container parent = (Container) parentItm;
if (this.isFocused && this.parentBackground == null) {
Background bg = parent.background;
if (bg != null) {
this.parentBackground = bg;
parent.background = null;
}
//System.out.println("EXCLUSIVE: INIT CONTENT WITH NO PARENT BG, now parentBackround != null: " + (this.parentBackground != null));
}
int selectedItemIndex = ((ChoiceGroup) parent).getSelectedIndex();
if (selectedItemIndex == -1) {
selectedItemIndex = 0;
}
parent.focusedIndex = selectedItemIndex;
int height = 0;
//#if polish.css.exclusiveview-left-arrow || polish.css.exclusiveview-right-arrow
//# int width = 0;
//#ifdef polish.css.exclusiveview-left-arrow
//# if (this.leftArrow != null) {
//# width = this.leftArrow.getWidth();
//# height = this.leftArrow.getHeight();
//# }
//#endif
//#ifdef polish.css.exclusiveview-right-arrow
//# if (this.rightArrow != null) {
//# if ( this.rightArrow.getWidth() > width) {
//# width = this.rightArrow.getWidth();
//# if (this.leftArrow.getHeight() > height) {
//# height = this.leftArrow.getHeight();
//# }
//# }
//# }
//#endif
//#if polish.css.exclusiveview-left-arrow && polish.css.exclusiveview-right-arrow
//# if (this.rightArrow != null && this.leftArrow != null) {
//# this.arrowWidth = width;
//# } else {
//#endif
//# if (width > this.arrowWidth) {
//# this.arrowWidth = width;
//# }
//#if polish.css.exclusiveview-left-arrow && polish.css.exclusiveview-right-arrow
//# }
//#endif
//#endif
//#if polish.css.exclusiveview-arrow-padding
//# int completeArrowWidth = ( this.arrowWidth * 2 ) + this.paddingHorizontal + this.arrowPadding;
//#else
int completeArrowWidth = ( this.arrowWidth + this.paddingHorizontal ) << 1;
//#endif
//#ifdef polish.css.exclusiveview-arrow-position
//# if (this.arrowPosition == POSITION_BOTH_SIDES) {
//#endif
this.leftArrowStartX = 0;
this.leftArrowEndX = this.arrowWidth;
this.rightArrowStartX = lineWidth - this.arrowWidth;
this.rightArrowEndX = lineWidth;
//#ifdef polish.css.exclusiveview-arrow-position
//# } else if (this.arrowPosition == POSITION_RIGHT ){
//# this.leftArrowStartX = lineWidth - completeArrowWidth + this.paddingHorizontal;
//# this.leftArrowEndX = this.leftArrowStartX + this.arrowWidth;
//# this.rightArrowStartX = lineWidth - this.arrowWidth;
//# this.rightArrowEndX = lineWidth;
//# } else {
//# this.leftArrowStartX = 0;
//# this.leftArrowEndX = this.arrowWidth;
//# this.rightArrowStartX = this.arrowWidth + this.paddingHorizontal;
//# this.rightArrowEndX = this.rightArrowStartX + this.arrowWidth;
//# }
//#endif
lineWidth -= completeArrowWidth;
int selectedItemHeight = 0;
if (selectedItemIndex < parent.size() ) {
ChoiceItem selectedItem = (ChoiceItem) parent.get( selectedItemIndex );
selectedItem.drawBox = false;
selectedItemHeight = selectedItem.getItemHeight(lineWidth, lineWidth);
this.contentWidth = selectedItem.getItemWidth( lineWidth, lineWidth ) + completeArrowWidth;
this.appearanceMode = Item.INTERACTIVE;
this.currentItem = selectedItem;
this.currentItemIndex = selectedItemIndex;
} else {
this.appearanceMode = Item.PLAIN;
if (this.isLayoutExpand()) {
this.contentWidth = lineWidth + completeArrowWidth;
} else {
this.contentWidth = this.paddingHorizontal + completeArrowWidth;
}
}
if (selectedItemHeight > height) {
//#debug
//# System.out.println("contentHeight = selectedItemHeight; selectedItemHeight > height: " + selectedItemHeight + ">" + height);
this.contentHeight = selectedItemHeight;
} else {
//#debug
//# System.out.println("contentHeight = height; selectedItemHeight <= height: " + selectedItemHeight + "<=" + height);
this.contentHeight = height;
}
//if ( selectedItem.isFocused ) {
//System.out.println("Exclusive Single Line View: contentHeight=" + this.contentHeight);
//}
//this.isInitialized = true;
//#if polish.css.exclusiveview-left-arrow
//# if (this.leftArrow != null) {
//# this.leftYOffset = (this.contentHeight - this.leftArrow.getHeight()) / 2; // always center vertically
//# }
//#endif
//#if polish.css.exclusiveview-right-arrow
//# if (this.rightArrow != null) {
//# this.rightYOffset = (this.contentHeight - this.rightArrow.getHeight()) / 2; // always center vertically
//# }
//#endif
// System.out.println("leftX=" + this.leftArrowStartX);
// System.out.println("rightX=" + this.rightArrowStartX);
// System.out.println("arrowColor=" + Integer.toHexString(this.arrowColor));
}
protected void setStyle(Style style) {
//#ifdef polish.css.exclusiveview-expand-background
//# Boolean expandBackgroundBool = style.getBooleanProperty(105);
//# if (expandBackgroundBool != null) {
//# this.expandBackground = expandBackgroundBool.booleanValue();
//# }
//# if (this.expandBackground) {
//# this.background = style.background;
//# }
//#endif
super.setStyle(style);
//#ifdef polish.css.exclusiveview-left-arrow
//# String leftArrowUrl = style.getProperty(57);
//# if (leftArrowUrl != null) {
//# try {
//# this.leftArrow = StyleSheet.getImage( leftArrowUrl, this, true );
//# } catch (IOException e) {
//#debug error
//# System.out.println("Unable to load left arrow image [" + leftArrowUrl + "]" + e );
//# }
//# }
//#endif
//#ifdef polish.css.exclusiveview-right-arrow
//# String rightArrowUrl = style.getProperty(56);
//# if (rightArrowUrl != null) {
//# try {
//# this.rightArrow = StyleSheet.getImage( rightArrowUrl, this, true );
//# } catch (IOException e) {
//#debug error
//# System.out.println("Unable to load right arrow image [" + rightArrowUrl + "]" + e );
//# }
//# }
//#endif
//#ifdef polish.css.exclusiveview-arrow-color
//# Integer colorInt = style.getIntProperty(55);
//# if ( colorInt != null ) {
//# this.arrowColor = colorInt.intValue();
//# }
//#endif
//#ifdef polish.css.exclusiveview-arrow-position
//# Integer positionInt = style.getIntProperty(104);
//# if ( positionInt != null ) {
//# this.arrowPosition = positionInt.intValue();
//# }
//#ifdef polish.css.exclusiveview-arrow-padding
//# Integer arrowPaddingInt = style.getIntProperty(128);
//# if (arrowPaddingInt != null) {
//# this.arrowPadding = arrowPaddingInt.intValue();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -