?? dynamicbeaninfomock.java
字號(hào):
/* * This source code is part of TWaver 1.3.1 * * SERVA Software PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. * Copyright 2000-2005 SERVA Software, Inc. All rights reserved. */package demo.sheet.dynamicbean;
import java.awt.Color;
import java.beans.BeanInfo;
import java.beans.PropertyDescriptor;
import java.beans.SimpleBeanInfo;
import java.util.Random;
import twaver.BeanInfoLoader;
import twaver.Element;
import twaver.ElementAttribute;
import twaver.TDataBox;
import twaver.TaggedPropertyDescriptor;
import twaver.TaskAdapter;
import twaver.TaskScheduler;
import twaver.table.Category;
public class DynamicBeanInfoMock extends TaskAdapter{
private BeanInfo defaultBF = null;
private Random random = new Random();
private Element element = null;
private TDataBox box = null;
int counter = 0;
public DynamicBeanInfoMock(Element element, TDataBox box){
this.element = element;
this.box = box;
TaskScheduler.getInstance().register(this);
// register category
Category.registerCategory("dynamic1", "Dynamic1", true);
Category.registerCategory("dynamic2", "Dynamic2", true);
Category.registerCategory("dynamic3", "Dynamic3", true);
defaultBF = BeanInfoLoader.getBeanInfo(element.getClass());
}
public void run(long clock) {
counter = (++counter) % 4;
if(counter == 1){
registerNewBeanInfo("dynamic1", Color.BLUE);
}
else if(counter == 2){
registerNewBeanInfo("dynamic2", Color.YELLOW);
}
else if(counter == 3){
registerNewBeanInfo("dynamic3", Color.RED);
}
else{
BeanInfoLoader.registerBeanInfo(element.getClass(), defaultBF);
}
this.box.getSelectionModel().clearSelection();
this.box.getSelectionModel().setSelection(element);
}
private void registerNewBeanInfo(String categoryName, Color color){
int newCount = random.nextInt(6) + 1;
BeanInfo lastBF = BeanInfoLoader.getBeanInfo(element.getClass());
PropertyDescriptor[] lastPds;
if(lastBF == null){
lastPds = new PropertyDescriptor[]{};
}else{
lastPds = lastBF.getPropertyDescriptors();
}
final PropertyDescriptor[] pds = new PropertyDescriptor[lastPds.length + newCount];
for(int i=0; i<lastPds.length; i++){
pds[i] = lastPds[i];
}
for(int i=0; i<newCount; i++){
String key = categoryName + "_porp_" + i;
ElementAttribute attribute = new ElementAttribute();
attribute.setCategoryName(categoryName);
attribute.setClientProperty(true);
attribute.setClientPropertyKey(key);
attribute.setDisplayName(key);
attribute.setName(key);
attribute.setWrite(false);
attribute.setRenderer(new BarRenderer(color));
try {
pds[lastPds.length + i] = new TaggedPropertyDescriptor(attribute, element.getClass());
} catch (Exception e) {
e.printStackTrace();
}
element.putClientProperty(key, new Double(random.nextInt(100) / 100.0));
}
BeanInfoLoader.registerBeanInfo(element.getClass(), new SimpleBeanInfo() {
public PropertyDescriptor[] getPropertyDescriptors() {
return pds;
}
});
}
public int getInterval() {
return 500;
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -