hpfuncmisc.java
来自「一个简单的visio程序。」· Java 代码 · 共 2,139 行 · 第 1/4 页
JAVA
2,139 行
/**
* @Funtion: Val(string)
* Returns the numbers contained in a string.
*/
public static double VAL(short varstrexp) throws HpException {
return (double)varstrexp;
}
public static double VAL(int varstrexp) throws HpException {
return (double)varstrexp;
}
public static double VAL(HByte varstrexp) throws HpException {
return varstrexp.dblValue();
}
public static double VAL(double varstrexp) throws HpException {
return varstrexp;
}
public static double VAL(float varstrexp) throws HpException {
return (double)varstrexp;
}
public static double VAL(boolean varstrexp) throws HpException {
return (double)0;
}
public static double VAL(String s) throws HpException {
if ( s == null )
throw new HpException(94,"Invalid use of null");
return str2dbl(s);
}
public static double VAL(fixedString varstrexp) throws HpException {
return VAL(varstrexp.strValue());
}
public static double VAL(HDate varstrexp) throws HpException {
return VAL(varstrexp.strValue());
}
public static double VAL(HCurr varstrexp) throws HpException {
return varstrexp.dblValue();
}
public static double VAL(VNull varstrexp) throws HpException {
throw new HpException(94,"Invalid use of Null");
}
public static double VAL(VObject varstrexp) throws HpException {
Object obj = varstrexp.objValue(); //Wrapper obj = varstrexp.getObject();
if ( obj == null )
throw new HpException( 91, "Object variable or With block variable not set");
if ( varstrexp.getClassType().equalsIgnoreCase("1 2 3 nothing") )
throw new HpException(2000, "Invalid use of object");
double db = 0;
try {
db = (varstrexp.getDefaultProperty()).dblValue();
} catch (Exception err) {
db = 0;
}
return db;
}
public static double VAL(Variant varstrexp) throws HpException
{
double db = 0;
switch (varstrexp.getType()) {
case Variant.V_NULL:
throw new HpException(94,"Invalid use of Null");
case Variant.V_EMPTY:
case Variant.V_BYTE:
case Variant.V_INT:
case Variant.V_LONG:
case Variant.V_CURR:
case Variant.V_DBL:
case Variant.V_SINGLE:
db = varstrexp.dblValue();
break;
case Variant.V_OBJ:
db = VAL((VObject)varstrexp);
break;
case Variant.V_FIX_STR:
db = VAL(((VString)varstrexp).getfixedLenStrValue().strValue());
break;
case Variant.V_DATE:
case Variant.V_BOL:
case Variant.V_STR:
db = VAL(varstrexp.strValue());
break;
default:
throw new HpException(13,"Type mismatch");
}
return db;
}
static double str2dbl(String s) throws HpException
{
double db = 0;
StringBuffer sbuf = new StringBuffer("");
try {
db = Double.valueOf(s).doubleValue();
} catch( Exception err1) {
int len,j=0;
len=s.length();
if( len==0 )
{
db=0;
}
else if( s.charAt(0)<='9' && s.charAt(0)>='0' )
{
for(j=0; j<len; j++)
{
if( (s.charAt(j)<'0' && s.charAt(j)!=' ') || s.charAt(j)>'9' )
break;
if(s.charAt(j)!=' ' )
sbuf.append(s.charAt(j) );
}
if(j!=0 && j!=len && s.charAt(j)>'9' &&
(s.charAt(j)=='d' || s.charAt(j)=='D' || s.charAt(j)=='e' || s.charAt(j)=='E') )
{
boolean label=false, numeric=false;
int tt=j+1;
if( s.substring(j).indexOf('&')!=-1 )
throw new HpException(13,"Type mismatch");
if( tt<len )
{
sbuf.append('e');
}
for(; tt<len; tt++ )
{
if( (s.charAt(tt)<'0' && s.charAt(tt)!=' ') || s.charAt(tt)>'9' )
{
if( label==false && numeric==false && (s.charAt(tt)=='-' || s.charAt(tt)=='+'))
label = true;
else
break;
}
if(s.charAt(tt)!=' ' )
{
if( s.charAt(tt)!='-' || s.charAt(tt)!='+' )
{
numeric = true;
}
sbuf.append(s.charAt(tt) );
}
}
}
try
{
String sbuf_str = sbuf.toString();
if ( sbuf_str.charAt(sbuf_str.length()-1 )=='e' )
sbuf_str = sbuf_str + '0';
db = Double.valueOf( sbuf_str).doubleValue();
}catch( Exception err ){;}
if ( s.charAt(j)=='&' && db>(double)2147483647 )
{
throw new HpException(13, "Type mismatch");
}
}//end of '0'~'9'
else if( s.charAt(0)=='&' )
{
if( len==1 )
{
db = 0;
}
else
{
s = s.substring(1).trim();
s = s.toUpperCase();
len = s.length();
if( len==0 )
{
db=0;
}
else if( s.charAt(0)=='H' ) //16
{
s = s.substring(1).trim();
len = s.length();
if( len==0 )
db = 0;
else
{
int tmpj=0;
for(j=0; j<len; j++ )
{
if( (s.charAt(j)<'0' && s.charAt(j)!=' ' )
|| (s.charAt(j)>'9' && s.charAt(j)<'A' )
|| s.charAt(j)>'F' )
break;
if( s.charAt(j)!=' ' )
{
sbuf.append(s.charAt(j));
tmpj++;
if( tmpj>8 && sbuf.charAt(tmpj-9)!='0' )
throw new HpException(6, "Overflow");
}
}
try
{
String tmp = sbuf.toString();
int jj=0;
for( ; jj<tmp.length() && tmp.charAt(jj)=='0'; jj++)
;
tmp = tmp.substring( jj );
tmpj = tmp.length();
if( tmp.equalsIgnoreCase( "ffff") && j==len )
db = (double)(-1);
else if( tmpj>8 )
db = (double)Long.parseLong(tmp,16 ) - (double)Long.parseLong("FFFFFFFF",16 ) -1;
else
db = (double)Long.parseLong(tmp,16 );
}catch( Exception err){;}
}
}
else if( s.charAt(0)=='O' ) //8
{
s = s.substring(1).trim();
len = s.length();
if( len==0 )
db = 0;
else
{
int templen=0;
for(j=0; j<len; j++ )
{
if ((s.charAt(j)<'0' && s.charAt(j)!=' ' )
|| s.charAt(j)>'7' )
break;
if( s.charAt(j)!=' ' )
{
sbuf.append(s.charAt(j));
templen++;
if( (templen==11 && sbuf.charAt(0)>'3') || (templen>11 && sbuf.charAt(templen-12)!= '0') )
throw new HpException(6,"Overflow");
}
}
try
{
String temp_sbuf = sbuf.toString();
if( templen>11 )
temp_sbuf = temp_sbuf.substring( templen-11);
if( templen>=11 && (temp_sbuf.charAt(0)== '3' || temp_sbuf.charAt(0)=='2'))
{
db = (double)Long.parseLong(temp_sbuf,8 ) - (double)Long.parseLong("37777777777", 8 ) - 1;
}
else
{
db = (double)Long.parseLong(temp_sbuf,8 );
}
}catch( Exception err){;}
}
}
else if( s.charAt(0)>='0' && s.charAt(0)<='7' ) //8
{
int templen2=0;
for(j=0; j<len; j++ )
{
if( (s.charAt(j)<'0' && s.charAt(j)!=' ' )
|| s.charAt(j)>'7' )
break;
if( s.charAt(j)!=' ' )
{
sbuf.append(s.charAt(j));
templen2++;
if( (templen2==11 && sbuf.charAt(0)>'3') || (templen2>11 && sbuf.charAt(templen2-12)!= '0') )
throw new HpException(6,"Overflow");
}
}
try
{
String temp_sbuf2 = sbuf.toString();
if( templen2>11 )
temp_sbuf2 = temp_sbuf2.substring( templen2-11);
if( templen2>=11 && (temp_sbuf2.charAt(0)== '3' || temp_sbuf2.charAt(0)=='2') )
{
db = (double)Long.parseLong(sbuf.toString(),8 ) - (double)Long.parseLong("37777777777", 8 ) - 1;
}
else
{
db = (double)Long.parseLong(sbuf.toString(),8 );
}
}catch( Exception err){;}
}
else
db=0;
}//end of len!=1
}//end of '&'
else if( s.charAt(0)=='-' || s.charAt(0)=='+' )
{
s = s.substring(1);
len = s.length();
if( len==0 )
db=0;
else
{
boolean isNag=false;
if( s.charAt(0)=='+' )
isNag = true;
for(j=0; j<len; j++ )
{
if( (s.charAt(j)<'0' && s.charAt(j)!=' ' )
|| s.charAt(j)>'9' )
break;
if( s.charAt(j)!=' ' )
sbuf.append(s.charAt(j));
}
try {
db = Double.valueOf(sbuf.toString()).doubleValue();
}catch( Exception err){;}
if( isNag==false )
db = -db;
}
}//end of '-','+'
}//end of catch
return db;
}
/**
* @Function: RGB (red, green, blue)
* Returns a whole number representing an RGB color value.
*/
public static int RGB(int red, int green, int blue) throws HpException
{
int colornumber;
String tmp ,tmpbuf;
if (red>32767 || green > 32767 || blue > 32767)
throw new HpException(6, "Overflow");
if (red < 0 || green < 0 || blue < 0)
throw new HpException(5, "Invalid procedure call");
if (red > 255) red = 255;
if (green > 255) green = 255;
if (blue > 255) blue = 255;
Color col = new Color(red, green, blue);
colornumber = col.getRGB();
tmp = Integer.toHexString(colornumber);
tmp = tmp.substring(2);
tmpbuf = tmp.substring(4) + tmp.substring(2,4) + tmp.substring(0,2);
colornumber = Integer.parseInt(tmpbuf,16);
return colornumber;
}
/**
* @Function: VarType(varname)
* Returns a value indicating the subtype of a variable.
*/
public static short VARTYPE(short variant) throws HpException {
return 2;
}
public static short VARTYPE(int variant) throws HpException {
return 3;
}
public static short VARTYPE(HByte variant) throws HpException {
return 17;
}
public static short VARTYPE(double variant) throws HpException {
return 5;
}
public static short VARTYPE(float variant) throws HpException {
return 4;
}
public static short VARTYPE(boolean variant) throws HpException {
return 11;
}
public static short VARTYPE(String variant) throws HpException {
return 8;
}
public static short VARTYPE(VObject variant) throws HpException {
short result = 0;
Object obj = variant.objValue(); //Wrapper obj = variant.getObject();
if (obj == null)
return 9;
String s = variant.getClassType();
if (s.equalsIgnoreCase("app") || s.equalsIgnoreCase("1 2 3 nothing") )
result = 9;
else
{
Variant Var = variant.getDefaultProperty();
result = VARTYPE(Var);
}
return result;
}
public static short VARTYPE(VNull variant) throws HpException {
return 1;
}
public static short VARTYPE(HDate variant) throws HpException {
return 7;
}
public static short VARTYPE(HCurr variant) throws HpException {
return 6;
}
public static short VARTYPE(fixedString variant) throws HpException {
return 8;
}
public static short VARTYPE(VArray variant) throws HpException {
short tmptype = 0;
switch (variant.getType()) {
case Variant.V_EMPTY:
tmptype = 0;
break;
case Variant.V_NULL:
tmptype = 1;
break;
case Variant.V_INT:
tmptype = 2;
break;
case Variant.V_LONG:
tmptype = 3;
break;
case Variant.V_SINGLE:
tmptype = 4;
break;
case Variant.V_DBL:
tmptype = 5;
break;
case Variant.V_CURR:
tmptype = 6;
break;
case Variant.V_DATE:
tmptype = 7;
break;
case Variant.V_STR:
case Variant.V_FIX_STR:
tmptype = 8;
break;
//case Variant.V_FORM:
case Variant.V_OBJ:
tmptype = 9;
break;
case Variant.V_ERR:
return 10;
case Variant.V_BOL:
tmptype = 11;
break;
case Variant.V_BYTE:
tmptype = 17;
break;
case Variant.V_VAR:
tmptype = 12;
break;
}
return (short)(8192+ tmptype);
}
public static short VARTYPE(Variant variant) throws HpException
{
short result = 0;
switch(variant.getType())
{
case Variant.V_EMPTY:
result = 0;
break;
case Variant.V_NULL:
result = 1;
break;
case Variant.V_INT:
result = 2;
break;
case Variant.V_LONG:
result = 3;
break;
case Variant.V_SINGLE:
result = 4;
break;
case Variant.V_DBL:
result = 5;
break;
case Variant.V_CURR:
result = 6;
break;
case Variant.V_DATE:
result = 7;
break;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?