📄 qselector.java
字号:
/**
* 作者:cat 戚永城
* 时间:2008-3-1
* QQ:415898635
* E-Mail: 415898635@qq.com
* qyc_12345@163.com
*
* */
package org.qui.container;
//selector只对确定键抬起做事件反应(按下不作反应)
import org.qui.manager.QItem;
import org.qui.manager.UIManager;
public class QSelector {
public int br = 189;
public int bg = 156;
public int bb = 42;
public int selected = -1;
private UIManager ui = null;
public boolean inComboItem=false;
public boolean inInputItem=false;
public boolean inEmComboItem=false;
public boolean inEmInputItem=false;
public boolean enableoffset=false;
public QSelector(UIManager ui,boolean enableoffset) {
this.ui = ui;
this.enableoffset=enableoffset;
}
public void selectorBack(int pre,int cur) {//类似undo
ui.getItem(pre).focus=false;
ui.getItem(cur).focus=true;
if(enableoffset){
setoffset(ui.getItem(cur));
}
}
public boolean isLast = false;
public boolean setSelected(int index) {
selected=index;
if (selected < (ui.getItemSum() - 1)) {
isLast = false;
} else {
selected=ui.getItemSum()-1;
isLast = true;
}
setFocus(selected);
QItem item = ui.getItem(selected);
if(enableoffset){
setoffset(item);
}
return item.isVisible() ;
}
public boolean nextElement() {
if (selected < (ui.getItemSum() - 1)) {
selected++;
isLast = false;
} else {
selected=ui.getItemSum()-1;
isLast = true;
}
setFocus(selected);
QItem item = ui.getItem(selected);
if(enableoffset){
setoffset(item);
}
return item.isVisible() ;
}
public boolean preElement() {
if (selected > 0) {
selected--;
isLast = false;
} else {
selected = 0;
isLast = true;
}
setFocus(selected);
QItem item = ui.getItem(selected);
if(enableoffset){
setoffset(item);
}
return item.isVisible() ;
}
public void setFocus(int index){
int sum=ui.getItemSum();
for (int i = 0; i < sum; i++) {
ui.getItem(i).focus=false;
}
ui.getItem(index).focus=true;
}
private int lastOffx=0;
private int lastOffy=0;
private int curOffx=0;
private int curOffy=0;
private Thread movingThread=null;
private void setoffset(QItem item) {
//注销线程
if(movingThread!=null){
lastOffx=curOffx;
lastOffy=curOffy;
try {
Thread.sleep(41);
} catch (InterruptedException e1) {
// TODO 自动生成 catch 块
e1.printStackTrace();
}
movingThread=null;
}
int width=ui.frame.getWidth();
int height=ui.frame.getHeight();
int x=item.x+item.width;
int y=item.y+item.height;
//移动的时候右下各让出20像素(下方再让出20像素用于Menu)
lastOffx=ui.offx;
lastOffy=ui.offy;
curOffx=0;
curOffy=0;
if(x>width){
curOffx=width-x-20;
}else{
curOffx=0;
}
if(y>height){
curOffy=height-y-40;
}else{
curOffy=0;
}
movingThread=new Thread(new Runnable(){
public void run() {
// TODO 自动生成方法存根
while(lastOffx!=curOffx || lastOffy!=curOffy){
if(lastOffx>curOffx){
lastOffx=lastOffx-5;
if(lastOffx-curOffx<5){
lastOffx=curOffx;
}
}else if(lastOffx<curOffx){
lastOffx=lastOffx+5;
if(curOffx-lastOffx<5){
lastOffx=curOffx;
}
}
if(lastOffy>curOffy){
lastOffy=lastOffy-5;
if(lastOffy-curOffy<5){
lastOffy=curOffy;
}
}else if(lastOffy<curOffy){
lastOffy=lastOffy+5;
if(curOffy-lastOffy<5){
lastOffy=curOffy;
}
}
ui.offx=lastOffx;
ui.offy=lastOffy;
ui.frame.repaint();
try {
Thread.sleep(40);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
});
movingThread.start();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -