📄 sdalistview.java
字号:
} //画项目 private void paintItems(Graphics g) { getMaxInfo(); setColRow(); SetClip(g, 2, 2, getHBarWidth() - 2, getVBarHeight() - 4); //单个大小 int itemWidth = maxLenght / colCount; int itemHeight = rowHeight; int itemLeft = 0; int itemTop = 0; Image image = null; int imageLeft = 0; int imageTop = 0; Font ft = getFont(); int fontHeight = showItemText ? getFont().getHeight() : 0; SDAListViewItem item = null; for (int i = 0; i < itemList.size(); i++) { item = (SDAListViewItem) itemList.elementAt(i); if (item.getImage() != null) { if (item.equals(curItem)) { image = item.getSelectedImage() != null ? item.getSelectedImage() : item.getImage(); itemLeft = item.getCol() * itemWidth; itemTop = item.getRow() * itemHeight; imageLeft = (itemWidth - image.getWidth()) / 2 + itemLeft - startLeft; imageTop = (itemHeight - image.getHeight() - fontHeight) / 2 + itemTop - startTop; drawImage(g, image, imageLeft, imageTop, 0); if (showItemText) { g.setColor(itemFocusedFontColor); drawString(g, item.getItemString(), (itemWidth - ft.stringWidth(item.getItemString())) / 2 + itemLeft - startLeft, imageTop + image.getHeight() + 2); } if (showItemRect) { g.setColor(itemFocusedRectColor); drawRect(g, item.getCol() * itemWidth - startLeft, item.getRow() * rowHeight - startTop, itemWidth, itemHeight); } } else { image = item.getImage(); itemLeft = item.getCol() * itemWidth; itemTop = item.getRow() * itemHeight; imageLeft = (itemWidth - image.getWidth()) / 2 + itemLeft - startLeft; imageTop = (itemHeight - image.getHeight() - fontHeight) / 2 + itemTop - startTop; drawImage(g, image, imageLeft, imageTop, 0); if (showItemText) { g.setColor(foreColor); drawString(g, item.getItemString(), (itemWidth - ft.stringWidth(item.getItemString())) / 2 + itemLeft - startLeft, imageTop + image.getHeight() + 2); } } } else { if (item.equals(curItem)) { itemLeft = item.getCol() * itemWidth; itemTop = item.getRow() * itemHeight; if (showItemText) { g.setColor(itemFocusedFontColor); drawString(g, item.getItemString(), (itemWidth - ft.stringWidth(item.getItemString())) / 2 + itemLeft - startLeft, itemTop + (itemHeight - ft.getHeight()) / 2); } if (showItemRect) { g.setColor(itemFocusedRectColor); drawRect(g, item.getCol() * itemWidth - startLeft, item.getRow() * rowHeight - startTop, itemWidth, itemHeight); } } else { itemLeft = item.getCol() * itemWidth; itemTop = item.getRow() * itemHeight; if (showItemText) { g.setColor(foreColor); drawString(g, item.getItemString(), (itemWidth - ft.stringWidth(item.getItemString())) / 2 + itemLeft - startLeft, itemTop + (itemHeight - ft.getHeight()) / 2); } } } } } //获取最大长度和高度 private void getMaxInfo() { //根据滚动条类型来自动安排 int rowCount = 1; if (itemList.size() > 0) { rowCount = itemList.size() % colCount > 0 ? (itemList.size() / colCount + 1) : (itemList.size() / colCount); } if (!autoRowHeight) { if (rowCount * rowHeight > getVBarHeight()) { scrollBars = SDAConsts.srVertical; } else { scrollBars = SDAConsts.srNone; } } else { scrollBars = SDAConsts.srNone; rowHeight = getVBarHeight() / rowCount; } if (scrollBars == SDAConsts.srVertical) { maxLenght = getHBarWidth(); maxHeight = rowCount * rowHeight; } if (scrollBars == SDAConsts.srNone) { maxLenght = getHBarWidth(); maxHeight = getVBarHeight(); } } //设置行列属性 private void setColRow() { SDAListViewItem item = null; int id = 0; maxCol = 0; maxRow = 0; for (int i = 0; i < itemList.size(); i++) { item = (SDAListViewItem) itemList.elementAt(i); id = (i + 1) % colCount == 0 ? colCount - 1 : (i + 1) % colCount - 1; if (maxCol < id) { maxCol = id; } item.setCol(id); id = i / colCount; if (maxRow < id) { maxRow = id; } item.setRow(id); } } //处理项目 public SDAListViewItem addItem() { SDAListViewItem item = new SDAListViewItem(); itemList.addElement(item); repaintControl(); return item; } public SDAListViewItem addItem(String itemString) { SDAListViewItem item = new SDAListViewItem(); item.setItemString(itemString); itemList.addElement(item); repaintControl(); return item; } public int getItemCount() { return itemList.size(); } public SDAListViewItem addItem(String itemString, Image image, Image selectedImage) { SDAListViewItem item = new SDAListViewItem(); item.setItemString(itemString); item.setImage(image); item.setSelectedImage(selectedImage); itemList.addElement(item); repaintControl(); return item; } public void addItem(SDAListViewItem item) { if (!itemList.contains(item)) { itemList.addElement(item); repaintControl(); } } public void removeItem(SDAListViewItem item) { if (itemList.contains(item)) { itemList.removeElement(item); repaintControl(); } } public void removeItem(int itemIndex) { if (itemIndex > -1 && itemIndex < itemList.size()) { itemList.removeElementAt(itemIndex); repaintControl(); } } public int getBorderStyle() { return borderStyle; } public void setBorderStyle(int borderStyle) { this.borderStyle = borderStyle; internalPaint(); } public int getScrollBarWidth() { return barwidth; } public void setScrollBarWidth(int barwidth) { this.barwidth = barwidth; internalPaint(); } public int getBorderColor() { return borderColor; } public void setBorderColor(int borderColor) { this.borderColor = borderColor; internalPaint(); } public int getScrollBarColor() { return scrollBarColor; } public int getColCount() { return colCount; } public void setColCount(int colCount) { this.colCount = colCount; } public int getRowHeight() { return rowHeight; } public void setRowHeight(int rowHeight) { this.rowHeight = rowHeight; } public int getItemSelectedColor() { return itemFocusedRectColor; } public void setItemSelectedColor(int itemSelectedColor) { this.itemFocusedRectColor = itemSelectedColor; } public SDAListViewItem getCurItem() { return curItem; } public int getItemIndex() { if (curItem == null) { return -1; } else { return itemList.indexOf(curItem); } } public void setItemIndex(int itemIndex) { if (itemIndex > -1 && itemIndex < itemList.size()) { curItem = (SDAListViewItem) itemList.elementAt(itemIndex); } else { curItem = null; } } public boolean isAutoRowHeight() { return autoRowHeight; } public void setAutoRowHeight(boolean autoRowHeight) { this.autoRowHeight = autoRowHeight; } public boolean isShowItemText() { return showItemText; } public void setShowItemText(boolean showItemText) { this.showItemText = showItemText; } public int getItemFocusedColor() { return itemFocusedRectColor; } public void setItemFocusedColor(int itemFocusedColor) { this.itemFocusedRectColor = itemFocusedColor; } public int getItemFocusedFontColor() { return itemFocusedFontColor; } public void setItemFocusedFontColor(int itemFocusedFontColor) { this.itemFocusedFontColor = itemFocusedFontColor; } public boolean isShowItemRect() { return showItemRect; } public void setShowItemRect(boolean showItemRect) { this.showItemRect = showItemRect; } private int getHBarWidth() {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -