?? sdalistview.java
字號(hào):
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package cn.sda.ui;import cn.sda.event.KeybordEvent;import cn.sda.event.ListViewSelectChangeEvent;import cn.sda.event.ListViewSelectItemEvent;import cn.sda.event.PointerEvent;import java.util.Vector;import javax.microedition.lcdui.Graphics;import javax.microedition.lcdui.Image;import javax.microedition.lcdui.Font;/** * @author not attributable * @version 1.0 */public class SDAListView extends SDABaseControl { //邊框 private int borderStyle = SDAConsts.bsFixedSingle; //滾動(dòng)邊框(多行) private int scrollBars = SDAConsts.srNone; private int barwidth = 10; //邊框線顏色 private int borderColor = SDAConsts.clBlack; //滾動(dòng)條顏色 private int scrollBarColor = SDAConsts.clBtnFace; //選中的項(xiàng)目的顏色 private int itemFocusedRectColor = SDAConsts.clBtnShadow; private int itemFocusedFontColor = SDAConsts.clActiveCaption; //列 private int colCount = 3; //行 private int rowHeight = 40; private boolean autoRowHeight = false; //內(nèi)部變量 //行數(shù),行最大長(zhǎng)度 private int maxLenght = 0; private int maxHeight = 0; //垂直開始顯示位置 private int startTop = 0; //水平開始顯示位置 private int startLeft = 0; //變動(dòng)前位置 private int oldStartLine = 0; private int oldStartLeft = 0; //水平滾條位置 private int HSLeft = 0; private int HSTop = 0; private int HSWidth = 0; private int HSHeight = 0; //垂直滾動(dòng)條位置 private int VSLeft = 0; private int VSTop = 0; private int VSWidth = 0; private int VSHeight = 0; //點(diǎn)擊的滾動(dòng)條的位置 private int oldScrollPointx = 0; private int oldScrollPointy = 0; //按下滾動(dòng)條 private boolean isscrollbarpointdown = false; //記錄按下的滾動(dòng)條0:水平,1:垂直的 private byte scrollbardownHV = 0; //項(xiàng)目管理 private Vector itemList = null; //但前選中項(xiàng) private SDAListViewItem curItem = null; //最大列,最大行 private int maxCol = 0; private int maxRow = 0; //是否顯示文字 private boolean showItemText = false; private boolean showItemRect = true; //事件 private ListViewSelectChangeEvent onSelectChange = null; private ListViewSelectItemEvent onSelectItem = null; public SDAListView() { super(); internalSDAListView(); } private void internalSDAListView() { itemList = new Vector(); this.setVisible(true); setLeft(0); setTop(0); setBorderStyle(SDAConsts.bsFixedSingle); super.setWidth(160); setHeight(100); super.setBackColor(SDAConsts.clWhite); this.onPointerPressed = new PointerEvent() { public void Event(SDABaseControl ctrl, int x, int y) { doPointerPressed(x, y); } }; this.onPointerReleased = new PointerEvent() { public void Event(SDABaseControl ctrl, int x, int y) { doPointerReleased(x, y); } }; this.onKeyUp = new KeybordEvent() { public void Event(SDABaseControl ctrl, int keyCode) { doKeyUp(keyCode); } }; } //畫 public void paint() { internalPaint(); } private void internalPaint() { if (!IsCanPaint()) { return; } Graphics g = form.getGraphics(); g.setFont(getFont()); InternalPaint(g); } protected void InternalPaint(Graphics g) { //可視下才畫 if (isVisible()) { //初始化引用變量 int thisWidth = getWidth(); int thisHeight = getHeight(); int HBarWidth = getHBarWidth(); int VBarHeight = getVBarHeight(); //對(duì)齊方式處理后,畫組件 //設(shè)置字體 g.setFont(super.getFont()); //外框 SetClip(g); //透明 if (!isTransparent()) { g.setColor(backColor); fillRect(g, 0, 0, thisWidth, thisHeight); } if (borderStyle == SDAConsts.bsFixed3D) { g.setColor(SDAConsts.clGray); drawLine(g, 0, 0, thisWidth, 0); drawLine(g, 0, 0, 0, thisHeight); g.setColor(SDAConsts.clBlack); drawLine(g, 1, 1, thisWidth - 1, 1); drawLine(g, 1, 1, 1, thisHeight - 1); g.setColor(SDAConsts.clBtnFace); drawLine(g, 2, thisHeight - 1, thisWidth - 2, thisHeight - 1); drawLine(g, thisWidth - 1, 2, thisWidth - 1, thisHeight - 1); g.setColor(SDAConsts.clWhite); drawLine(g, 1, thisHeight, thisWidth, thisHeight); drawLine(g, thisWidth, 1, thisWidth, thisHeight); if (isFoucsed()) { g.setColor(SDAConsts.clFocusShadow); drawRect(g, 1, 1, thisWidth - 2, thisHeight - 2); } } if (borderStyle == SDAConsts.bsFixedSingle) { //邊框 g.setColor(this.getBorderColor()); drawRect(g, 0, 0, thisWidth, thisHeight); if (isFoucsed()) { g.setColor(SDAConsts.clFocusShadow); drawRect(g, 1, 1, thisWidth - 2, thisHeight - 2); } } //畫項(xiàng)目 paintItems(g); //滾動(dòng)條 if (borderStyle == SDAConsts.bsFixed3D) { SetClip(g, 2, 2, thisWidth - 2, thisHeight - 2); } else { SetClip(g, 1, 1, thisWidth - 1, thisHeight - 1); } if ((scrollBars == SDAConsts.srHorizontal) || (scrollBars == SDAConsts.srBoth)) { //水平 g.setColor(scrollBarColor); fillRect(g, 0, thisHeight - barwidth, barwidth, barwidth); fillRect(g, HBarWidth - barwidth, thisHeight - barwidth, barwidth, barwidth); g.setColor(getBorderColor()); drawRect(g, 0, thisHeight - barwidth, barwidth, barwidth); drawRect(g, HBarWidth - barwidth, thisHeight - barwidth, barwidth, barwidth); //滾動(dòng)塊 g.setColor(backColor); fillRect(g, barwidth, thisHeight - barwidth, HBarWidth - 2 * barwidth, barwidth); g.setColor(this.getBorderColor()); drawRect(g, barwidth, thisHeight - barwidth, HBarWidth - 2 * barwidth, barwidth); //塊大小 int pwidth = HBarWidth - 2 * barwidth; if (maxLenght > HBarWidth) { pwidth = ((HBarWidth) * (HBarWidth - 2 * barwidth)) / maxLenght; } //計(jì)算塊位置 int ppos = (startLeft * (HBarWidth - 2 * barwidth)) / maxLenght; //修正位置 if (ppos + pwidth > HBarWidth - 2 * barwidth) { ppos = HBarWidth - 2 * barwidth - pwidth; } //畫塊 g.setColor(scrollBarColor); fillRect(g, barwidth + ppos, thisHeight - barwidth, pwidth, barwidth); g.setColor(getBorderColor()); drawRect(g, barwidth + ppos, thisHeight - barwidth, pwidth, barwidth); //記錄大小 HSLeft = barwidth + ppos; HSTop = thisHeight - barwidth; HSWidth = pwidth; HSHeight = barwidth; //畫塊上的線 int tpos = HSWidth / 2 + HSLeft; drawRect(g, tpos, HSTop + 2, 0, HSHeight - 4); if (tpos - 2 > HSLeft) { drawRect(g, tpos - 2, HSTop + 2, 0, HSHeight - 4); } if (tpos + 2 < HSLeft + HSWidth) { drawRect(g, tpos + 2, HSTop + 2, 0, HSHeight - 4); } //三角 g.setColor(getBorderColor()); fillTriangle(g, barwidth / 2 - 2, thisHeight - barwidth / 2, barwidth / 2 + 2, thisHeight - barwidth / 2 - 4, barwidth / 2 + 2, thisHeight - barwidth / 2 + 4); fillTriangle(g, HBarWidth - barwidth + barwidth / 2 + 2, thisHeight - barwidth / 2, HBarWidth - barwidth + barwidth / 2 - 2, thisHeight - barwidth / 2 - 4, HBarWidth - barwidth + barwidth / 2 - 2, thisHeight - barwidth / 2 + 4); } if ((scrollBars == SDAConsts.srVertical) || (scrollBars == SDAConsts.srBoth)) { //垂直 g.setColor(scrollBarColor); fillRect(g, thisWidth - barwidth, 0, barwidth, barwidth); fillRect(g, thisWidth - barwidth, VBarHeight - barwidth, barwidth, barwidth); g.setColor(getBorderColor()); drawRect(g, thisWidth - barwidth, 0, barwidth, barwidth); drawRect(g, thisWidth - barwidth, VBarHeight - barwidth, barwidth, barwidth); //滾動(dòng)塊 g.setColor(backColor); fillRect(g, thisWidth - barwidth, barwidth, barwidth, VBarHeight - 2 * barwidth); g.setColor(getBorderColor()); drawRect(g, thisWidth - barwidth, barwidth, barwidth, VBarHeight - 2 * barwidth); //塊大小 int pheight = VBarHeight - 2 * barwidth; if (maxHeight > VBarHeight) { pheight = ((VBarHeight) * (VBarHeight - 2 * barwidth) / maxHeight); } //計(jì)算塊位置 int ppos = barwidth; if (maxHeight > 0) { ppos = (startTop * (VBarHeight - 2 * barwidth)) / maxHeight; } //修正位置 if (ppos + pheight > VBarHeight - 2 * barwidth) { ppos = VBarHeight - 2 * barwidth - pheight; } //畫塊 g.setColor(scrollBarColor); fillRect(g, thisWidth - barwidth, barwidth + ppos, barwidth, pheight); g.setColor(getBorderColor()); drawRect(g, thisWidth - barwidth, barwidth + ppos, barwidth, pheight); //記錄大小 VSLeft = thisWidth - barwidth; VSTop = barwidth + ppos; VSWidth = barwidth; VSHeight = pheight; //畫塊上的線 int tpos = VSHeight / 2 + VSTop; drawRect(g, VSLeft + 2, tpos, barwidth - 4, 0); if (tpos - 2 > VSTop) { drawRect(g, VSLeft + 2, tpos - 2, VSWidth - 4, 0); } if (tpos + 2 < VSTop + VSHeight) { drawRect(g, VSLeft + 2, tpos + 2, VSWidth - 4, 0); } //三角 g.setColor(getBorderColor()); fillTriangle(g, thisWidth - barwidth + barwidth / 2, barwidth / 2 - 2, thisWidth - barwidth + barwidth / 2 - 4, barwidth / 2 + 2, thisWidth - barwidth + barwidth / 2 + 4, barwidth / 2 + 2); fillTriangle(g, thisWidth - barwidth + barwidth / 2 - 4, VBarHeight - barwidth + barwidth / 2 - 2, thisWidth - barwidth + barwidth / 2 + 4, VBarHeight - barwidth + barwidth / 2 - 2, thisWidth - barwidth + barwidth / 2, VBarHeight - barwidth / 2 + 2); } PaintChilds(); }
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -