============ the file name: Attribute.java
package fs.cb;
import java.util.List;
import java.util.Vector;
public class Attribute {
private BaseObject source;
private String name;
private Object value;
private List<AttributeListener> listeners = new Vector<AttributeListener>();
public Attribute(BaseObject source, String name) {
this(source, name, null);
}
public Attribute(BaseObject source, String name, Object value) {
check(source, name);
this.source = source;
this.name = name;
this.value = value;
}
protected void check(BaseObject source, String name) {
if (source == null || name == null) {
throw new IllegalArgumentException("Either source or name is null");
}
}
public synchronized void addListener(AttributeListener listener) {
listeners.add(listener);
}
public synchronized void removeListener(AttributeListener listener) {
listeners.remove(listener);
}
public Object getValue() {
return value;
}
public void setValue(Object value) {
this.value = value;
}
public List<AttributeListener> getListeners() {
return listeners;
}
}
============ the file name: AttributeEvent.java
package fs.cb;
import java.util.EventObject;
public class AttributeEvent extends EventObject {
private String name;
private Object oldValue;
private Object newValue;
public AttributeEvent(Object source, String attribute, Object oldValue,
Object newValue) {
super(source);
this.name = attribute;
this.oldValue = oldValue;
this.newValue = newValue;
}
public String toString() {
return "{[" + getSource() + "], (attribute:" + name
+ "), (oldValue:" + oldValue + "), (newValue:" + newValue
+ ")}";
}
public String getName() {
return name;
}
public void setAttribute(String attribute) {
this.name = attribute;
}
public Object getNewValue() {
return newValue;
}
public void setNewValue(Object newValue) {
this.newValue = newValue;
}
public Object getOldValue() {
return oldValue;
}
public void setOldValue(Object oldValue) {
this.oldValue = oldValue;
}
}
============ the file name: AttributeListener.java
package fs.cb;
import java.util.List;
public interface AttributeListener {
void onChange(AttributeEvent ae);
}
============ the file name: AttributeSupportTest.java
package fs.cb;
import java.util.Arrays;
import junit.framework.TestCase;
public class AttributeSupportTest extends TestCase {
public void testA() {
BaseObject ps = new BaseObject();
ps.set("username", "shaucle");
assertEquals(ps.get("username"), "shaucle");
System.out.println(ps.get("username") + "aaa");
}
public void testB() {
final BaseObject a = new BaseObject();
final BaseObject b = new BaseObject();
Binder.bind(b, "username", a, "am");
a.set("am", "augmtuem");
// Arrays.fill(a, val);
System.out.println(b.get("username") + "========");
}
public void testC() throws Exception {
final BaseObject a = new BaseObject() {
public void onName(AttributeEvent ae) {
System.out.println("DANAME");
}
public void onname(AttributeEvent ae) {
System.out.println("xiaoname");
}
public void onTitle(AttributeEvent ae) {
System.out.println("title" + ae.getNewValue());
}
};
a.set("name", "carlos");
a.set("title", "this is a title");
}
}
============ the file name: BaseObject.java
package fs.cb;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.*;
public class BaseObject {
private Map<String, Attribute> attributes = new HashMap<String, Attribute>();
public Object get(String name) {
Attribute attribute = attributes.get(name);
if (attribute == null)
return null;
return attribute.getValue();
}
public synchronized void set(String name, Object value) {
Object oldValue = get(name);
getOrCreateAttribute(name).setValue(value);
fireAttributeChange(name, oldValue, value);
}
public void addListener(String name, AttributeListener listener) {
getOrCreateAttribute(name).addListener(listener);
}
Attribute getAttribute(String name) {
return attributes.get(name);
}
Attribute getOrCreateAttribute(String name) {
Attribute attribute = attributes.get(name);
if (attribute == null) {
attribute = new Attribute(this, name);
attributes.put(name, attribute);
}
return attribute;
}
private void fireAttributeChange(String name, Object oldValue,
Object newValue) {
AttributeEvent ae = new AttributeEvent(this, name, oldValue, newValue);
List<AttributeListener> listeners = attributes.get(name).getListeners();
for (int i = 0; i < listeners.size(); i++) {
AttributeListener listener = listeners.get(i);
listener.onChange(ae);
}
EventUtils.sendEvent(ae);
}
public String toString(){
return this.getClass().getName();
}
}
============ the file name: Binder.java
package fs.cb;
public class Binder {
public static void bind(final BaseObject target, final String targetName,
final BaseObject source, final String sourceName) {
source.addListener(sourceName, new AttributeListener() {
public void onChange(AttributeEvent ae) {
target.set(targetName, source.get(sourceName));
}
});
}
public static void bind(final BaseObject target, final String targetName,
final BaseObject source) {
source.addListener(targetName, new AttributeListener() {
public void onChange(AttributeEvent ae) {
target.set(targetName, source.get(targetName));
}
});
}
}
============ the file name: EventUtils.java
package fs.cb;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.concurrent.*;
public class EventUtils {
private final static ExecutorService pool = Executors
.newFixedThreadPool(10);
public static boolean on = true;
public static void setOn(boolean on) {
EventUtils.on = on;
}
public static void sendEventAsyn(final AttributeEvent ae) {
if (!on)
return;
pool.execute(new Runnable() {
public void run() {
sendEvent(ae);
}
});
}
public static void sendEvent(AttributeEvent ae) {
if (!on)
return;
BaseObject source = (BaseObject) ae.getSource();
Method method = getEventMethod(source, ae.getName());
if (method == null)
return;
try {
if (method.getParameterTypes().length == 0) {
method.invoke(source);
} else {
method.invoke(source, ae);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
private static Method getEventMethod(BaseObject source, String name) {
Method method = null;
String methodName = "on" + Character.toUpperCase(name.charAt(0))
+ name.substring(1);
method = getMethod(source, methodName);
if (method == null) {
method = getMethod(source, "on" + name);
}
return method;
}
private static Method getMethod(BaseObject source, String methodName) {
Method method = null;
try {
method = source.getClass().getMethod(methodName,
AttributeEvent.class);
} catch (Exception e) {
try {
method = source.getClass().getMethod(methodName);
} catch (Exception e2) {
// ignore
}
}
return method;
}
}
the threda's name: Thread-0java.lang.ThreadGroup[name=main,maxpri=10] toString: Thread[Thread-0,5,main]
94
分享到:
相关推荐
SUIPack是一款为Delphi和C++Builder开发的所见即所得的界面增强VCL组件,它可以帮助您创建具有专业的界面外观设计的应用程序,大大节省您的时间和开发成本。 SUIPack 提供超过60个组件。只要将它们放置在一个form...
用于给特别容易白屏的索爱W550c刷机,方便快捷省钱。
【标题】"Midware D3-D7,D2005-D2007,CB3-CB6,Fs,FreeWare" 涉及的是一个软件开发相关的项目或工具集,其中包含了对不同版本的Delphi(D3到D7)和CodeBuilder(CB3到CB6)的支持,以及Fs(可能指的是文件系统或框架...
- **量程**:能够检测±60deg/s的角速度变化,非线性度控制在±0.5%FS以内,确保了在标准温度下的高精度测量。 - **频率响应**:具有10Hz的典型频率响应,相位延迟角度为90°。 - **轴间交叉敏感度**:最大±5%,...
EhLib v3.6 FS For D4-9/CB4-6 是一款专为DELPHI开发者设计的数据库连接和界面控制库,它提供了一组强大的VCL(Visual Component Library)控件,用于增强数据库应用程序的用户界面和数据管理功能。这个版本的EhLib...
在STM32F103CB上,我们需要配置USB相关的寄存器,如USB_otg_fs_global_registers、USB_otg_device_registers等,设置设备地址、速度、端点等参数。 在实现过程中,通常需要以下几个步骤: 1. 初始化USB控制器:设置...
这个压缩包"QuickReport Maintenance Release 2012-01-19 Delphi CB 2009, 2010, XE, XE2 FS.7z"显然包含了针对2012年1月19日的QuickReport维护版本,适用于Delphi的CodeGear 2009、2010、XE以及XE2这几个不同的开发...
在Node.js中,`fs.exists`方法是用来检测指定路径下的文件或目录是否存在的。这个方法在处理文件系统操作时非常实用,例如在决定是否需要创建一个新的文件或者读取已存在的文件之前,先确认文件是否存在。 **方法...
5. 精度和分辨率:产品的测量精度可达±0.3%(FS)+1数字,对于R、S、B型传感器,测量范围是0~399℃时精度为±2℃;对于T、U型传感器,测量范围是-199.9~100.0℃时精度为±3℃。 6. 控制功能:控制器提供PID控制...
A package of standard and unique components for professional GUI design development using AlphaSkins. AlphaControls is an easy-to-use universal and powerful tool for developing original skinned and ...
标题中的“synergy-v1.8.8-stable-25a8cb2-Windows-x64.msi”是一款名为Synergy的软件的稳定版本,适用于64位的Windows操作系统。Synergy是一款强大的多平台屏幕共享和键盘鼠标控制工具,通过它,用户可以使用一套...
参量fp {String} :要读取的文件路径options {String} :传递给fs.readFile其他选项cb {Function} :具有err和contents参数的回调函数。 读取文件时将被调用。 例子readFile ( 'path/to/my/file' , function ( ...
首先,我们看到文件名中包含 "BCB" 和 "CB",这可能代表 Borland C++ Builder 和 CodeGear RAD Studio(以前也称为 Borland Delphi)。BCB 是一个集成开发环境(IDE),与 Delphi 类似,使用相同的 VCL(Visual ...
作为fs.readdir,但它返回绝对路径 安装 使用安装readdir-absolute : npm install --save readdir-absolute 用法 模块使用 var readdir = require ( 'readdir-absolute' ) ; readdir ( '/folder' , function ( ...
该模块向本机“ fs”模块添加了一些防止有毒空字节的保护措施。...{if(e){console.error('error cb');throw e;}console.log(d.length)})> 2226> require('protect-fs'){}> require('fs').readFileSy
- **步骤(2)**: 变电站出线断路器(CB)执行保护跳闸操作,导致所有相关的开关因失压而跳闸。 - **步骤(3)**: CB在2秒后尝试第一次重合闸。 - **步骤(4)**: FS1一侧因为存在电压并且记录了故障电流,因此延时7秒后自动...
这个名为“LiWD-DevArt UniDAC v.3.50.0.14 FS.rar”的压缩包包含了适用于不同Delphi版本的安装程序,包括D11到D15以及CodeGear RAD Studio 6(CB6)的版本,确保了对广泛Delphi开发环境的支持。 UniDAC的核心优势...
g fs-enhance###API ####fsEnhance.copyFile 复制文件######范围: src : String源文件路径target : String目标文件路径cb : Function发生错误的回调######例子: var fsEnhance = require ( 'fs-...