📄 fileselector.java
字号:
Image window = Image.createImage(windowImage.getWidth(),
windowImage.getHeight());
Graphics g = window.getGraphics();
g.drawImage(windowImage, 0, 0, ANCHOR);
//绘制停留框
g.setColor(AnyView.bordorcolor);
int y = VecPad + 5 +
(itemIndex - topIndex) * (AnyView.cf.FontHeight + LinePad);
g.drawImage(cube, 2, y, ANCHOR);
g.setStrokeStyle(Graphics.DOTTED);
g.drawRoundRect(2, y - 1, cubeWidth - 1, CustomFont.FontHeight + 3, 8,
8);
g.setStrokeStyle(Graphics.SOLID);
return window;
}
public void destroy() {
windowImage = null;
cube = null;
fileList.removeAllElements();
}
public boolean bof() {
return (topIndex == 0);
}
public void keyUp() {
itemIndex--;
if (itemIndex < 0) {
itemIndex = 0;
return;
}
if (itemIndex < topIndex) {
topIndex -= ShowItems;
topIndex = topIndex < 0 ? 0 : topIndex;
refreshList();
}
}
public void keyDown() {
itemIndex++;
if (itemIndex == fileList.size()) { //已到达最后一项
itemIndex = fileList.size() - 1;
return;
}
if (itemIndex - topIndex == ShowItems) {
topIndex++;
refreshList();
}
}
public void keyLeft() {
if (bof()) {
WINDOW_STATE = CLOSED;
return;
}
if (topIndex == 0) { //向上翻页无效
return;
}
topIndex -= ShowItems;
topIndex = topIndex < 0 ? 0 : topIndex;
itemIndex = topIndex;
refreshList();
}
public void keyRight() {
if (topIndex + ShowItems >= fileList.size()) { //翻页无效
return;
}
topIndex += ShowItems;
if (topIndex + ShowItems > fileList.size()) { //到顶了
topIndex = fileList.size() - ShowItems;
}
itemIndex = topIndex;
refreshList();
}
public void keyFire() {
Files f = (Files) fileList.elementAt(itemIndex);
if (!AnyView.Root.equals(root)) { //不是根目录
if (itemIndex == 0) { //返回上级目录
String filename = root.substring(0, root.length() - 1);
root = filename.substring(0, filename.lastIndexOf('/') + 1);
openDir();
return;
}
}
if (f.type == DIR) {
root += f.filename;
openDir();
} else if (f.type == TXT) {
sc.saveRec();
destroy();
AnyView.rootPath = root;
AnyView.av.switchTxt(root + f.filename);
//System.out.println("txt = " + root + f.filename);
} else if (f.type == IAV) {
destroy();
AnyView.av.switchIav(root + f.filename);
//System.out.println("iav = " + root + f.filename);
}
}
protected void pointerPressed(int x, int y) {
//System.out.println(x + ", " + y);
super.pointerPressed(x, y);
if (!contains(PRESSED_X, PRESSED_Y)) {
//WINDOW_STATE = CLOSED;
return;
}
//首先检查是不是翻页
pageup = false;
pagedown = false;
if (showScrollBar) { //有滚动条时才会有翻页的动作
int top = height - ButtonHeight;
if (PRESSED_Y > top && PRESSED_Y < height) { //在翻页按钮的Y轴范围内
if (PRESSED_X > width >> 1) { //向下翻
pagedown = true;
} else if (PRESSED_X > 0) { //向上翻
pageup = true;
}
}
}
//判断用户当前的选择项
int find = -1;
for (int i = 0; i < ShowItems && find == -1; i++) {
int top = VecPad + i * (CustomFont.FontHeight + LinePad) - 1;
if (PRESSED_Y > top && PRESSED_Y < top + CustomFont.FontHeight) {
find = topIndex + i;
itemIndex = topIndex + i;
//System.out.println("pressed: itemIndex = " + itemIndex);
}
}
}
protected void pointerDragged(int x, int y) {
}
protected void pointerReleased(int x, int y) {
//System.out.println(x + ", " + y);
super.pointerReleased(x, y);
if (!contains(RELEASE_X, RELEASE_Y)) {
WINDOW_STATE = CLOSED;
return;
}
//首先检查是不是翻页
if (showScrollBar) { //有滚动条时才会有翻页的动作
int top = height - ButtonHeight;
if (RELEASE_Y > top && RELEASE_Y < height) { //在翻页按钮的Y轴范围内
if (RELEASE_X > width >> 1) { //向下翻
if (!pagedown) { //按下时的动作并不是向下翻页
return;
}
if (topIndex + ShowItems >= fileList.size()) { //翻页无效
return;
}
topIndex += ShowItems;
if (topIndex + ShowItems > fileList.size()) { //到顶了
topIndex = fileList.size() - ShowItems;
}
itemIndex = topIndex;
refreshList();
} else if (RELEASE_X > 0) { //向上翻
if (!pageup) { //按下时的动作并不是向上翻页
return;
}
if (topIndex == 0) { //向上翻页无效
return;
}
topIndex -= ShowItems;
topIndex = topIndex < 0 ? 0 : topIndex;
itemIndex = topIndex;
refreshList();
}
}
}
//判断用户当前的选择项
int find = -1;
for (int i = 0; i < ShowItems && find == -1; i++) {
int top = VecPad + i * (CustomFont.FontHeight + LinePad) - 1;
if (RELEASE_Y > top && RELEASE_Y < top + CustomFont.FontHeight) {
find = i + topIndex;
//System.out.println("released: find = " + find);
}
}
if (find == -1) {
return;
}
if (find == itemIndex) { //用户确认选择功能
keyFire();
}
else {
itemIndex = find;
}
}
class Files {
String filename;
int type;
public Files(String f, int t) {
filename = f;
type = t;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -