hpfuncmisc.java

来自「一个简单的visio程序。」· Java 代码 · 共 2,139 行 · 第 1/4 页

JAVA
2,139
字号
/**
 * @(#)HpFuncMisc.java	98/06/18
 *
 * Copyright 1997-1998 by Halcyon Software Inc.,
 * All rights reserved.
 *
 * This program instructs miscellaneous functions, they are:
 *	PARTITION(number, start, stop, intrval),
 *	QBCOLOR(),      IIf(expr, truepart, falsepart),
 *	ENVIRON$(envStr |number ), VAL(string),
 *	RGB(red, green, blue),     VARTYPE(variant),
 *	ISEMPTY(variant),         ISERROR(variant),
 *	ISNULL(variant),           ISMISSING(variant),
 *	ISNUMERIC(variant),        ISOBJECT(variant),
 *	ISARRAY(variant),
 *	LBOUND(var[, dim]),         UBOUND(var[, dim]),
 *	TYPENAME(var),             VARTYPE(var),
 *	ERROR[(var)],
 *	Shell(pathname[, windowstyle])
 *	ARRAY(), SWITCH(), CHOOSE()
 *
 * @Version IB4J1.3
 */

package HPCore.stdfunc;

import  HPCore.Exception.*;
import  HECore.stddata.*;

import java.io.File;
import java.util.*;
import java.awt.Color;

public class HpFuncMisc
{
   /**
	* @FUNCTION:QBColor(color)
	* Returns the color code corresponding to a color number.
	*
	* The color argument is a whole number in the range 0 to 15.
	*/
	public static int QBCOLOR(short qbcolor) throws HpException
	{
		int colornumber = 0;

		if ((qbcolor > 32767) || (qbcolor < -32768))
			throw new HpException( 6, "Overflow");
		switch (qbcolor)
		{
			case 0:
				colornumber = 0;
				break;
			case 1:
				colornumber = 8388608;
				break;
			case 2:
				colornumber = 32768;
				break;
			case 3:
				colornumber = 8421376;
				break;
			case 4:
				colornumber = 128;
				break;
			case 5:
				colornumber = 8388736;
				break;
			case 6:
				colornumber = 32896;
				break;
			case 7:
				colornumber = 12632256;
				break;
			case 8:
				colornumber = 8421504;
				break;
			case 9:
				colornumber = 16711680;
				break;
			case 10:
				colornumber = 65280;
				break;
			case 11:
				colornumber = 16776960;
				break;
			case 12:
				colornumber = 0x000000FF;
				break;
			case 13:
				colornumber = 16711935;
				break;
			case 14:
				colornumber = 65535;
				break;
			case 15:
				colornumber = 16777215;
				break;
			default:
				throw new HpException(5, "Invalid procedure call");
		}
		return colornumber;
	}

   /**
	* @Function: Partition(number, start, stop, interval)
	*
	* number:   The Partition function is most useful in queries.
	* start:    Whole number that is the start of the overall range 
	*     of numbers.  It can't be less than 0.
	* stop:     Whole number that is the end of the overall range of
	*     numbers.  It can't be equal to or less than start.
	* interval: Whole number that is the interval spanned by each range
	*     in the series from start to stop.  It can't be less than 1.
	*
	* Returns a string indicating where a number occurs within a
	* calculated series of ranges.
	*
	* The Partition function is most useful in queries(Database SELECT).
	*/
	public static String PARTITION(int number, int start,
		int stop, int intrval) throws HpException
	{
		int             i, stoploopvalue;
		int             lowervalue, uppervalue;
		String          string1 = "", string2 = "", temps = ": ";
		StringBuffer    result = new StringBuffer();

		if ((number + 1 < -2147483647   || number > 2147483647)  ||
			(start + 1 < -2147483647    || start > 2147483647)   ||
			(stop + 1 < -2147483647     || stop > 2147483647)    ||
			(intrval + 1 < -2147483647  || intrval > 2147483647))
			throw new HpException(6, "Overflow") ;

		if (start < 0 || stop <= start || intrval < 1)
			throw new HpException(8, "Illegal function call");

		if ( number < start ) // in the following two cases, number outof start and stop
		{
			result.append(" :");
			start = start-1;
			result.append( start );
		}
		else if ( number > stop )
		{
			stop = stop+1;
			result.append(stop+": ");
		}
		else if ( intrval == 1 ) //in the following three cases, number between start and stop
		{
			result.append( number +":"+ number ) ;
		}
		else if ( intrval >= (stop - start + 1) )
		{
			result.append( start + ":" + stop) ;
		}
		else
		{
			lowervalue = start ;
			uppervalue = start + intrval - 1;
			if ( (stop-start+1)%intrval == 0 )
				stoploopvalue = (int)((stop-start+1)/intrval) ;
			else
				stoploopvalue = (int)((stop-start+1)/intrval)+1 ;

			for ( i = 0; i < stoploopvalue; i ++ )
			{
				if ( number >= lowervalue && number <= uppervalue  )
				{
					result.append( lowervalue + ":" + uppervalue) ;
					break ;
				}
				else
				{
					lowervalue = uppervalue + 1;
					uppervalue = lowervalue + intrval - 1;
					if ( uppervalue > stop )
					uppervalue = stop ;
				}
			}
		}
		return result.toString();
	}

   /**
	* @Function: IIf(expr, truepart, falsepart)
	* Returns one of two parts, depending on the evaluation of an expression.
	*/
	public static Variant IIF(Variant varexpr, Variant truepart,
		Variant falsepart) throws HpException
	{
		boolean expr = false;

		if (varexpr.getType() == Variant.V_STR && varexpr.strValue().equalsIgnoreCase("true"))
			expr = true;
		else if (varexpr.getType() == Variant.V_STR && varexpr.strValue().equalsIgnoreCase("false"))
			expr = false;
		else
			expr = varexpr.boolValue();

		if (expr)
			return truepart;
		else
			return falsepart;
	}

   /**
	* @Function: Environ$(string)
	*
	* Returns the string associated with an operating system environment
	* variable.
	*/
	public static String ENVIRON$(double varenvStr) throws HpException {
		String str = null;
		Properties   props = System.getProperties();

		int envint = (int)varenvStr;
		if (envint > 32767 || envint < -32768)
			throw new HpException(6,"Overflow");
		if (envint < 1 || envint > 255)
			throw new HpException(5, "Invalid procedure call");
		else if (envint > props.size())
			str = "";
		else
		{
			switch (envint)
			{
				case 1:
					if( props.getProperty("classpath", "java.class.path") == null)
						str = "";
					else
						str = "CLASSPATH=" + (props.getProperty("java.class.path" ,"classpath"));
					break;
				case 2:
					if( props.getProperty("computername")==null)
						str = "";
					else
						str = "COMPUTERNAME=" +props.getProperty("computername");
					break;
				case 3:
					if( props.getProperty("comspec")==null)
						str = "";
					else
						str = "ComSpec="+props.getProperty("comspec");
					break;
				case 4:
					if(props.getProperty("user.home","homedrive" )==null )
						str = "";
					else
						str = "HOMEDRIVE="+props.getProperty("user.home","homedrive");
					break;
				case 5:
					if( props.getProperty("file.separator","homepath")==null)
						str = "";
					else
						str = "HOMEPATH="+props.getProperty("file.separator","homepath");
					break;
				case 6:
					if( props.getProperty("ib4jhome")==null)
						str = "";
					else
						str = "IB4JHOME="+props.getProperty("ib4jhome");
					break;
				case 7:
					if( props.getProperty("include")==null )
						str = "";
					else
						str = "include="+props.getProperty("include");
					break;
				case 8:
					if( props.getProperty("lib")==null )
						str = "";
					else
						str = "lib="+props.getProperty("lib");
					break;
				case 9:
					if( props.getProperty("lib")==null )
						str = "";
					else
						str = "MsDevDir=" +props.getProperty("lib");
					break;
				case 10:
					if( props.getProperty("number_of_processors")==null )
						str = "";
					else
						str = "NUMBER_OF_PROCESSORS=" +props.getProperty("number_of_processors");
					break;
				case 11:
					if( props.getProperty("os", "os.name")==null )
						str = "";
					else
						str = "OS=" + props.getProperty("os","os.name");
					break;
				case 12:
					if( props.getProperty("os2libpath")==null )
						str = "";
					else
						str = "Os2LibPath=" +props.getProperty("os2libpath");
					break;
				case 13:
					if( props.getProperty("path","java.home")==null )
						str = "";
					else
						str = "Path=" +props.getProperty("path","java.home");
					break;
				case 14:
					if( props.getProperty("processor")==null )
						str = "";
					else
						str = "PROCESSOR=" +props.getProperty("processor");
					break;
				case 15:
					if( props.getProperty("processor_identifier")==null )
						str = "";
					else
						str = "PROCESSOR_IDENTIFIER=" +props.getProperty("processor_identifier");
					break;
				case 16:
					if(props.getProperty("processor_level")==null )
						str = "";
					else
						str = "PROCESSOR_LEVEL=" +props.getProperty("processor_level");
					break;
				case 17:
					if( props.getProperty("processor_revision")==null )
						str = "";
					else
						str = "PROCESSOR_REVISION=" +props.getProperty("processor_revision");
					break;
				case 18:
					if( props.getProperty("systemdrive","usr.home")==null )
						str = "";
					else
						str = "SystemDrive=" +props.getProperty("systemdrive","usr.home");
					break;
				case 19:
					if( props.getProperty("systemroot")==null )
						str = "";
					else
						str = "SystemRoot=" +props.getProperty("systemroot");
					break;
				case 20:
					if( props.getProperty("userdomain")==null )
						str = "";
					else
						str = "USERDOMANIN=" +props.getProperty("userdomain");
					break;
				case 21:
					if( props.getProperty("user.name")==null )
						str = "";
					else
						str = "USERNAME=" +props.getProperty("user.name");
					break;
				case 22:
					if( props.getProperty("userprofile")==null )
						str = "";
					else
						str = "USERPROFILE=" +props.getProperty("userprofile");
					break;
				case 23:
					if( props.getProperty("user.dir")==null )
						str = "";
					else
						str = "usrdir=" +props.getProperty("user.dir");
					break;
				default:
					int i = 0;
					for (Enumeration e = props.keys(); e.hasMoreElements(); )
					{
						String tempkey = (String)e.nextElement();           //get property key
						i++;
						if (i == envint) {
							str = tempkey + "=" + (String)props.get(tempkey);
							break;
						}
					}
			}
		}
		return str;
	}

	public static String ENVIRON$(short varenvStr) throws HpException {
		return ENVIRON$((double)varenvStr);
	}

	public static String ENVIRON$(int varenvStr) throws HpException {
		return ENVIRON$((double)varenvStr);
	}

	public static String ENVIRON$(float varenvStr) throws HpException {
		return ENVIRON$((double)varenvStr);
	}

	public static String ENVIRON$(HByte varenvStr) throws HpException {
		return ENVIRON$(varenvStr.dblValue());
	}

	public static String ENVIRON$(boolean varenvStr) throws HpException {
		throw new HpException(5, "Invalid procedure call");
	}

	public static String ENVIRON$(HDate varenvStr) throws HpException {
		return ENVIRON$(varenvStr.dblValue());
	}

	public static String ENVIRON$(HCurr varenvStr) throws HpException {
		return ENVIRON$(varenvStr.dblValue());
	}

	public static String ENVIRON$(String envStr) throws HpException {
		if( envStr.equalsIgnoreCase("classpath") )
			envStr = "java.class.path";
		else if( envStr.equalsIgnoreCase("home") )
			envStr = "user.home";
		else if( envStr.equalsIgnoreCase("homedrive") )
			envStr = "user.home";
		else if( envStr.equalsIgnoreCase("os") )
			envStr = "os.name";
		else if( envStr.equalsIgnoreCase("homepath") )
			envStr = "file.separator";
		else if( envStr.equalsIgnoreCase("path") )
			envStr = "java.home";
		else if( envStr.equalsIgnoreCase("username") )
			envStr = "user.name";
		else if( envStr.equalsIgnoreCase("systemdrive") )
			envStr = "user.home";

		String str = System.getProperty(envStr);
		if(str == null)
			str = new String("");
		else if( str != "" )
			str = str.toUpperCase();
		return str;
	}

	public static String ENVIRON$(fixedString varenvStr) throws HpException {
		return ENVIRON$(varenvStr.strValue());
	}

	public static String ENVIRON$(VNull varenvStr) throws HpException {
		throw new HpException(94, "Invalid use of null");
	}

	public static String ENVIRON$(VObject varenvStr) throws HpException {
		throw new HpException( 5, "Invalid procedure call");
	}

	public static String ENVIRON$(Variant varenvStr) throws HpException
	{
		String   str = null;

		int type = varenvStr.getType();
		switch( type )
		{
			case Variant.V_NULL:
				throw new HpException(94, "Invalid use of null");
			case Variant.V_BYTE:
			case Variant.V_BOL:
			case Variant.V_INT:
			case Variant.V_LONG:
			case Variant.V_SINGLE:
			case Variant.V_DATE:
			case Variant.V_CURR:
			case Variant.V_DBL:
				str = ENVIRON$(varenvStr.dblValue());
				break;
			case Variant.V_OBJ:
			case Variant.V_EMPTY:
				throw new HpException( 5, "Invalid procedure call");
			case Variant.V_FIX_STR:
				str = ENVIRON$(((VString)varenvStr).getfixedLenStrValue().strValue());
				break;
			case Variant.V_STR:
				str = ENVIRON$(varenvStr.strValue());
				break;
			default:
				throw new HpException(13,"Type mismatch");
		}
		return str;
	}

   /**
	* @Function: Environ(string)
	*/
	public static Variant ENVIRON(double varenvStr) throws HpException {
		return new VString(ENVIRON$(varenvStr));
	}

	public static Variant ENVIRON(short varenvStr) throws HpException {
		return new VString(ENVIRON$(varenvStr));
	}

	public static Variant ENVIRON(int varenvStr) throws HpException {
		return new VString(ENVIRON$(varenvStr));
	}

	public static Variant ENVIRON(float varenvStr) throws HpException {
		return new VString(ENVIRON$(varenvStr));
	}

	public static Variant ENVIRON(HByte varenvStr) throws HpException {
		return new VString(ENVIRON$(varenvStr));
	}

	public static Variant ENVIRON(boolean varenvStr) throws HpException {
		throw new HpException(5, "Invalid procedure call");
	}

	public static Variant ENVIRON(HDate varenvStr) throws HpException {
		return new VString(ENVIRON$(varenvStr));
	}

	public static Variant ENVIRON(HCurr varenvStr) throws HpException {
		return new VString(ENVIRON$(varenvStr));
	}

	public static Variant ENVIRON(String envStr) throws HpException {
		return new VString(ENVIRON$(envStr));
	}

	public static Variant ENVIRON(fixedString varenvStr) throws HpException {
		return new VString(ENVIRON$(varenvStr));
	}

	public static Variant ENVIRON(VNull varenvStr) throws HpException {
		throw new HpException(94, "Invalid use of null");
	}

	public static Variant ENVIRON(VObject varenvStr) throws HpException {
		throw new HpException( 5, "Invalid procedure call");
	}

	public static Variant ENVIRON(Variant varenvStr) throws HpException {
		return new VString(ENVIRON$(varenvStr));
	}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?