📄 vobject.java
字号:
private void getJavaDimension()
{
Dimension d;
if (this.obj instanceof java.awt.Component)
d=((java.awt.Component)obj).getSize();
else
d=new Dimension(0,0);
this.JavaWidth=d.width;
this.JavaHeight=d.height;
}
private void getJavaLocation()
{
if (this.obj instanceof java.awt.Component)
{
Point p=((Component)obj).getLocation();
this.JavaLeft=p.x;
this.JavaTop=p.y;
}
}
private void setLeft(int l){
if (!(this.obj instanceof java.awt.Component))
return;
getJavaLocation();
int newleft=(int)l/15;
((Component)obj).setLocation(newleft,this.JavaTop);
}
private void setTop(int l){
if (!(this.obj instanceof java.awt.Component))
return;
getJavaLocation();
int newtop=(int)l/15;
((Component)obj).setLocation(this.JavaLeft,newtop);
}
private void setWidth(int l){
if(!(this.obj instanceof java.awt.Component))
return;
getJavaDimension();
int newwidth=(int)l/15;
((Component)obj).setSize(newwidth,this.JavaHeight);
}
private void setHeight(int l)
{
if (!(this.obj instanceof java.awt.Component))
return;
getJavaDimension();
int newheight=(int)l/15;
((Component)obj).setSize(this.JavaWidth,newheight);
}
public void setParent(Container c) {
con = c;
}
/**
*get the obj's parent.
*/
public Container getParent() {
return con;
}
private void dealParam(Class[] param) throws HpException
{
for(int i=0;i<beanparam.size();i++)
{
if(param[i]==short.class)
{
if(!(beanparam.elementAt(i) instanceof java.lang.Short) )
beanparam.setElementAt(new Short((short)convert.tointValue(beanparam.elementAt(i))),i);
}
else
if(param[i]==int.class)
{
if(!(beanparam.elementAt(i) instanceof java.lang.Integer) )
beanparam.setElementAt(new Integer(convert.tointValue(beanparam.elementAt(i))),i);
}
else
if(param[i]==float.class)
{
if(!(beanparam.elementAt(i) instanceof java.lang.Integer) )
beanparam.setElementAt(new Float((float)convert.todoubleValue(beanparam.elementAt(i))),i);
}
else
if(param[i]==String.class)
{
beanparam.setElementAt(beanparam.elementAt(i).toString(),i);
}
else
if(param[i]==boolean.class)
{
if(!(beanparam.elementAt(i) instanceof java.lang.Boolean))
beanparam.setElementAt(new Boolean(convert.toboolValue(beanparam.elementAt(i))),i);
}
else
if(param[i]==double.class)
{
if(!(beanparam.elementAt(i) instanceof java.lang.Double) )
beanparam.setElementAt(new Double(convert.todoubleValue(beanparam.elementAt(i))),i);
}
else
if(param[i]==Object.class)
{
if(!(beanparam.elementAt(i) instanceof java.lang.Object) )
throw new HpException(424 ,"Object required");//beanparam.setElementAt(new Double(convert.todoubleValue(beanparam.elementAt(i))),i);
}
}
}
private Variant dealReturnType(Class returnType,Method md,Object[] objarg)
{
try{
if(returnType==short.class)
return new VInt(((Short)md.invoke(obj,objarg)).shortValue());
else
if(returnType==int.class)
return new VLong(((Integer)md.invoke(obj,objarg)).intValue());
else
if(returnType==boolean.class)
return new VBoolean(((Boolean)md.invoke(obj,objarg)).booleanValue());
else
if(returnType==float.class)
return new VSingle(((Float)md.invoke(obj,objarg)).floatValue());
else
if(returnType==double.class)
return new VDouble(((Double)md.invoke(obj,objarg)).doubleValue());
else
if(returnType==String.class)
{
return new VString((String)md.invoke(obj,objarg));
}
else
return new VObject((Object)md.invoke(obj,objarg));
}catch(Throwable e){e.printStackTrace();return null;}
}
public void setValue(String field ,short i) throws HpException
{
Field fd = dealUdtField(field);
try{
if(fd!=null)
{
Class fieldtype =fd.getType();
if(fieldtype !=short.class && fieldtype!=Variant.class)
throw new HpException(9,"Type mismatch");
if(fieldtype==Variant.class)
fd.set(obj,new VInt(i));
else
fd.setShort(obj,i);
}
}catch(Throwable e){System.out.println(e);}
}
public void setValue(String field ,int i) throws HpException
{
Field fd = dealUdtField(field);
try{
if(fd!=null)
{
Class fieldtype =fd.getType();
if(fieldtype !=int.class && fieldtype!=Variant.class)
throw new HpException(9,"Type mismatch");
if(fieldtype==Variant.class)
fd.set(obj,new VLong(i));
else
fd.setInt(obj,i);
}
}catch(Throwable e){System.out.println(e);}
}
public void setValue(String field ,float f) throws HpException
{
Field fd = dealUdtField(field);
try{
if(fd!=null)
{
Class fieldtype =fd.getType();
if(fieldtype !=float.class && fieldtype!=Variant.class)
throw new HpException(9,"Type mismatch");
if(fieldtype==Variant.class)
fd.set(obj,new VLong(f));
else
fd.setFloat(obj,f);
}
}catch(Throwable e){System.out.println(e);}
}
public void setValue(String field ,boolean bool) throws HpException
{
Field fd = dealUdtField(field);
try{
if(fd!=null)
{
Class fieldtype =fd.getType();
if(fieldtype !=boolean.class && fieldtype!=Variant.class)
throw new HpException(9,"Type mismatch");
if(fieldtype==Variant.class)
fd.set(obj,new VBoolean(bool));
else
fd.setBoolean(obj,bool);
}
}catch(Throwable e){System.out.println(e);}
}
public void setValue(String field ,double db) throws HpException
{
Field fd = dealUdtField(field);
try{
if(fd!=null)
{
Class fieldtype =fd.getType();
if(fieldtype !=double.class && fieldtype!=Variant.class)
throw new HpException(9,"Type mismatch");
if(fieldtype==Variant.class)
fd.set(obj,new VDouble(db));
else
fd.setDouble(obj,db);
}
}catch(Throwable e){System.out.println(e);}
}
public void setValue(String field ,String str) throws HpException
{
Field fd = dealUdtField(field);
try{
if(fd!=null)
{
Class fieldtype =fd.getType();
if(fieldtype !=String.class && fieldtype!=Variant.class)
throw new HpException(9,"Type mismatch");
if(fieldtype==Variant.class)
fd.set(obj,new VString(str));
else
fd.set(obj,str);
}
}catch(Throwable e){System.out.println(e);}
}
/**
*
*
*
*/
public void setValue(String field ,Variant var)
{
Field fd = dealUdtField(field);
try{
if(fd!=null)
{
Var2All(fd,var);
}
}catch(Throwable e){System.out.println(e);}
}
private Field dealUdtField(String field)
{
Class cls =obj.getClass();
try{
return cls.getDeclaredField(field);
}catch(Throwable e){System.out.println(e);return null;}
}
private void Var2All(Field field ,Variant var) throws HpException
{
try{
Class FieldType=field.getType();
if(FieldType ==short.class)
field.setShort(obj,(short)var.dblValue());
else
if(FieldType ==int.class)
field.setInt(obj,(int)var.dblValue());
else
if(FieldType ==boolean.class)
field.setBoolean(obj,(boolean)boolValue());
else
if(FieldType ==float.class)
field.setFloat(obj,(float)var.dblValue());
else
if(FieldType ==double.class)
field.setInt(obj,(int)var.dblValue());
else
if(FieldType ==String.class)
field.set(obj,(String)var.toString());
else
if(FieldType ==Variant.class)
field.set(obj,var);
else
;
}catch(Throwable e){}
}
/**
*
* convert All type to Variant.
* Type is this Field class type .field is this UDT Field.
* return Variant.
*/
private Variant All2Var(Class Type,Field field)
{
try{
if(Type==short.class)
return new VInt(field.getShort(obj));
else
if(Type==int.class)
return new VLong(field.getInt(obj));
else
if(Type==boolean.class)
return new VBoolean(field.getBoolean(obj));
else
if(Type==float.class)
return new VSingle(field.getFloat(obj));
else
if(Type==double.class)
return new VDouble(field.getDouble(obj));
else
if(Type==String.class)
{
return new VString((String)field.get(obj));
}
else
return new VObject(field.get(obj));
}catch(Throwable e){System.out.println(e);return null;}
}
/**
*
* get UDT Field.
* if this Field type is Variant return this Field .
*/
public Variant getValue(String field) throws HpException
{
Field fd = dealUdtField(field);
try{
if(fd!=null)
{
Class fieldtype =fd.getType();
if(!(fieldtype==Variant.class))
throw new HpException(9,"Type mismatch");
else
return All2Var(fieldtype,fd);
}
else
return null;
}catch(Throwable e){System.out.println(e);return null;}
}
/**
*
* get UDT array Field.
* return type is VArray;
*/
public VArray get(String getmethod)
{
try{
Class cls =obj.getClass();
Class[] param={};
Object[] objarg={};
Method md =cls.getDeclaredMethod(getmethod,param);
return (VArray)md.invoke(obj,objarg);
}catch(Throwable e){System.out.println(e);return null;}
}
public synchronized void addEventTarget(Object listener) {
try {
for (int i = 0; i < events.length; i++) {
Method adder = events[i].getAddListenerMethod();
Object args[] = { listener };
adder.invoke(obj, args);
}
} catch (Throwable ex) {
}
}
public static void setNoplugin(boolean flag)
{
isnoplugin=flag;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -