📄 flowpanel.java
字号:
package com.ismyway.fairyui;
import javax.microedition.lcdui.Graphics;
import com.ismyway.anyview.others.Settings;
public class FlowPanel extends Panel {
private int maxHeight = 100;
public FlowPanel() {
setBorder(true);
}
public FlowPanel(Callback callback) {
super(callback);
setBorder(true);
}
public void paint(Graphics g, int adjustx, int adjusty) {
g.setClip(getLeft(), getTop(), mainCanvas.getWidth(), getHeight());
g.setColor(bgColor);
int filly = getTop() - adjusty;
filly = filly < 0 ? 0 : filly;
int fillh = getTop() + getHeight() - filly - adjusty;
fillh = fillh > mainCanvas.getHeight() ? mainCanvas.getHeight() : fillh;
g.fillRect(getLeft() - adjustx, filly, getWidth(), fillh);
// System.out.println(filly + ", " + fillh);
//绘制滚动条
if (showscrollbar) {
drawScrollbar(g, adjustx, adjusty);
}
for (int i = 0; i < components.size(); ++i) {
Row row = (Row) components.get(i);
//System.out.println(row.getClass().getName());
if (row.getTop() + row.getHeight() < getTop() + adjusty) {
continue;
}
if (row.getTop() > getTop() + viewportHeight + adjusty) {
break;
}
row.setFilledColor(bgColor);
row.paint(g, adjustx, adjusty);
}
paintTitleBottom(g, adjustx, adjusty);
restoreClip(g);
}
synchronized public void validate() {
//onActive();
int width = mainCanvas.getWidth();
viewportHeight = maxHeight;
//System.out.println("viewportHeight = " + viewportHeight + "/" + control.getHeight());
showscrollbar = false;
internalHeight = getTopHeight();
verticalOffset = 0;
//首先,假设不需要滚动条
int top = getTop() + getTopHeight();
for (int i = 0; i < components.size(); ++i) {
Component c = (Component) components.get(i);
c.setTop(top);
c.setWidth(width);
c.validate();
internalHeight += c.getHeight();
top += c.getHeight();
if (internalHeight > viewportHeight) { //需要滚动条
this.showscrollbar = true;
break;
}
}
internalHeight += getBottomHeight();
if (internalHeight > viewportHeight) { //需要滚动条
this.showscrollbar = true;
}
if (!showscrollbar) {
setWidth(width);
setHeight(internalHeight);
resetPointer();
return;
}
//需要滚动条,重新计算
showscrollbar = true;
internalHeight = 0;
width -= Settings.SCROLLBAR_WIDTH;
top = getTop() + getTopHeight();
for (int i = 0; i < components.size(); ++i) {
Component c = (Component) components.get(i);
c.setTop(top);
c.setWidth(width);
c.validate();
internalHeight += c.getHeight();
top += c.getHeight();
}
internalHeight += getBottomHeight();
setWidth(width);
scrollbarHeight = viewportHeight * viewportHeight / internalHeight;
scrollbarHeight = scrollbarHeight < 16 ? 16 : scrollbarHeight;
setHeight(viewportHeight);
resetPointer();
}
public int getMaxHeight() {
return maxHeight;
}
public void setMaxHeight(int maxHeight) {
this.maxHeight = maxHeight;
}
public void setSelectPointer(int index) {
if (hotpots.size() < 1 || currentPointer == index || index < 0
|| index > hotpots.size() - 1) {
return;
}
((Component) hotpots.get(index)).setSelected(true);
((Component) hotpots.get(currentPointer)).setSelected(false);
currentPointer = index;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -