⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 util.java

📁 打印管理程序,测试完全通过.windows开发环境.
💻 JAVA
字号:
/*
    $Author: $
    $Date: $
    $Revision: $
    $NoKeywords: $
*/
package jp.co.ntl;

import java.awt.*;
import java.text.MessageFormat;
import java.util.Locale;

import jp.co.ntl.codec.Base64;
import jp.co.ntl.codec.MsgDigest;
import jp.co.ntl.ext.GlobalContext;
import jp.co.ntl.spooler.SpoolerInfo;
import jp.co.ntl.preference.PreferenceInfo;

public class Util {
	
    /**
     * 暥帤楍傪嬮宍偺恀傫拞偵彂偔偲偒偺奐巒埵抲偺庢摼
     */
    public static Point basePoint(FontMetrics fm, String s, int width, int height) {
        Point pt = new Point();
        pt.x = (int)((width - fm.stringWidth(s)) / 2 + 0.5);
        pt.y = (int)((height + fm.getAscent() - fm.getDescent()) / 2 + 2.5);//2.5偼挷惍抣

        return pt;
    }

    /**
     * 暥帤楍傪嬮宍偺恀傫拞偵彂偔偲偒偺奐巒埵抲偺X嵗昗偺庢摼
     */
    public static int basePointX(FontMetrics fm, String s, int width) {
        return (int)((width - fm.stringWidth(s)) / 2 + 0.5);
    }

    /**
     * 暥帤楍傪嬮宍偺恀傫拞偵彂偔偲偒偺奐巒埵抲偺Y嵗昗偺庢摼
     */
    public static int basePointY(FontMetrics fm, String s, int height) {
        return (int)((height + fm.getAscent() - fm.getDescent() + 2.5) / 2);
    }

    /**
     * 暥帤楍傪嬮宍偺恀傫拞偵彂偔偲偒偺奐巒埵抲偺Y嵗昗偺庢摼
     */
    public static int basePointY(FontMetrics fm, int height) {
        return (int)((height + fm.getAscent() - fm.getDescent() + 2.5) / 2);
    }

    /**
     * 彫悢傪桳岠寘悢偱昞偟偨暥帤楍偵曄姺
     * @param f         僼僅乕儅僢僩偡傞彫悢
     * @param effective 桳岠寘悢
     * @return          桳岠寘悢偱昞偝傟偨暥帤楍
     */
    public static String getEffectiveNumber(float f, int effective) {
        String number = "" + f;
        int point = number.indexOf('.');
        int len = number.length();
        String ret = null;
        if (effective == 0) {
            if (point == -1) {
                ret = number;
            } else {
                ret = number.substring(0, point);
            }
        } else {
            if (point == -1) {
                ret = number + ".";
                for (int i = 0; i < effective; i++) {
                    ret += "0";
                }
            } else {
                if (len - point - 1 < effective) {
                    ret = number;
                    for (int i = 0; i < effective - len + point + 1; i++) {
                        ret += "0";
                    }
                } else {
                    ret = number.substring(0, point + effective + 1);
                }
            }
        }
        return ret;
    }

    /**
     *
     */
    public static int[] getIntArray(String src, int length, char delim) {
        int top, bottom;
        int[] array = new int[length];
        try {
            top = 0;
            for (int i = 0; i < array.length - 1; i++) {               
                if ((bottom = src.indexOf(delim, top)) == -1) {
                    return null;
                }
                array[i] = Integer.parseInt(src.substring(top, bottom));
                top = bottom + 1;
            }
            array[array.length - 1] = Integer.parseInt(src.substring(top));
        } catch (NumberFormatException e) {
            return null;
        }
        
        return array;
    }
    
    public static String getFiguredString(String num, int figure) {
        String ret = "";
        int length = num.length();
        if (length < figure) {
            for (int i = 0; i < figure - length; i++) {
                ret += "0";
            }
            ret += num;
        } else {
            ret = num;
        }
        return ret;
    }
    
	public static String floatFormat(double value, int floatCol)
	{
		int index;
		String str;
		String temp = new Double(value).toString();

		if ((index = temp.indexOf('.')) != -1) {
			index += floatCol + 1;
			if (index > temp.length()) {
				index = temp.length();
			}
			str = temp.substring(0, index);
		} else {
			str = temp;
		}

		return str;
	}
	
	public static String getEncoding(Locale l) {
		String	encoding = "iso-8859-1";
		
		encoding = System.getProperty("file.encoding", "iso-8859-1");
//		Util.debugPrint("File encoding = " + encoding);
		if (GlobalContext.getInstance().getPreferenceInfo().isDebug()) {
			System.out.println("File encoding = " + encoding);
		}
		return encoding;
	}
	
	public static String getStatusString(String language, int status, int error) {
		Resource.load(new Locale(language, ""));

		switch (status) {
		case SpoolerInfo.SC_SPOOL:
			return Resource.getString(Resource.SC_SPOOLING);
		case SpoolerInfo.SC_SPOOL_END:
			return Resource.getString(Resource.SC_SPOOL_END);
		case SpoolerInfo.SC_DEVICE:
		case SpoolerInfo.SC_PRINT:
			return Resource.getString(Resource.SC_PRINTING);
		case SpoolerInfo.SC_DEVICE_END:
		case SpoolerInfo.SC_PRINT_END:
		case SpoolerInfo.SC_OK:
			return Resource.getString(Resource.SC_PRINT_END);
		case SpoolerInfo.SC_PRINT_RETRY:
			return Resource.getString(Resource.SC_PRINT_RETRY);
		case SpoolerInfo.SC_PRINT_OFF:
			return Resource.getString(Resource.SC_PRINT_OFF);
		case SpoolerInfo.SC_RETRY_ERROR:
			return Resource.getString(Resource.SC_RETRY_ERROR);
		case SpoolerInfo.SC_DELETING:
			return Resource.getString(Resource.SC_DELETING);
		default:
			switch (error) {
			case SpoolerInfo.EC_SPOOL:
				return Resource.getString(Resource.EC_SPOOL);
			case SpoolerInfo.EC_DEVICE:
				return Resource.getString(Resource.EC_DEVICE);
			case SpoolerInfo.EC_PRINT:
				return Resource.getString(Resource.EC_PRINT);
			case SpoolerInfo.EC_SUSPEND:
				return Resource.getString(Resource.EC_SUSPEND);
			case SpoolerInfo.EC_FULL:
			case SpoolerInfo.EC_DISK_FULL:
				return Resource.getString(Resource.EC_DISK_FULL);
			case SpoolerInfo.EC_CANCEL:
				return Resource.getString(Resource.EC_CANCEL);
			case SpoolerInfo.EC_LIMIT_USER_DAY:
			case SpoolerInfo.EC_LIMIT_USER_MONTH:
			case SpoolerInfo.EC_LIMIT_USER_YEAR:
			case SpoolerInfo.EC_LIMIT_GROUP_DAY:
			case SpoolerInfo.EC_LIMIT_GROUP_MONTH:
			case SpoolerInfo.EC_LIMIT_GROUP_YEAR:
			case SpoolerInfo.EC_TIME_LIMIT:
			case SpoolerInfo.EC_LIMIT:
				return Resource.getString(Resource.EC_LIMIT);
			case SpoolerInfo.EC_MEMORY:
				return Resource.getString(Resource.EC_MEMORY);
			case SpoolerInfo.EC_SIZE_NOT_SUPPORT:
				return Resource.getString(Resource.EC_SIZE_NOT_SUPPORT);
			case SpoolerInfo.EC_TRAY_NOT_SUPPORT:
				return Resource.getString(Resource.EC_TRAY_NOT_SUPPORT);
			case SpoolerInfo.EC_MEDIA_NOT_SUPPORT:
				return Resource.getString(Resource.EC_MEDIA_NOT_SUPPORT);
			case SpoolerInfo.EC_WAIT_RETRY:
				return Resource.getString(Resource.EC_WAIT_RETRY);
			case SpoolerInfo.EC_PRINT_OFF:
				return Resource.getString(Resource.EC_PRINT_OFF);
			case SpoolerInfo.EC_SERIAL:
				return Resource.getString(Resource.EC_SERIAL);
			case SpoolerInfo.EC_LIMIT_USER_PRINT:
				return Resource.getString(Resource.EC_LIMIT_USER_PRINT);
			case SpoolerInfo.EC_STOP_USER_PRINT:
				return Resource.getString(Resource.EC_STOP_USER_PRINT);
			case SpoolerInfo.EC_LIMIT_GROUP_PRINT:
				return Resource.getString(Resource.EC_LIMIT_GROUP_PRINT);
			case SpoolerInfo.EC_STOP_GROUP_PRINT:
				return Resource.getString(Resource.EC_STOP_GROUP_PRINT);
			case SpoolerInfo.EC_DATABASE:
				return Resource.getString(Resource.EC_DATABASE);
			case SpoolerInfo.EC_NOT_ALLOWED_GROUP:
				return Resource.getString(Resource.EC_NOT_ALLOWED_GROUP);
			default:
				return Resource.getString(Resource.SC_ERROR) + " : " + error;
			}
		}
	}
	
	public static String getSizeString(String language, long size) {
		Resource.load(new Locale(language, ""));
		
		String	unitForm;

		double	dSize = size;
		if (dSize >= 1024 * 1024) {
			dSize /= 1024 * 1024;
			unitForm = Resource.getString(Resource.UNIT_SIZE_MB);
		} else {
			dSize /= 1024;
			unitForm = Resource.getString(Resource.UNIT_SIZE_KB);
		}
		String[]	param = new String[] { Util.floatFormat(dSize, 2) };
		
		return MessageFormat.format(unitForm, (Object[])param);
	}
	
	public static Locale getCurrentLocale() {
		String language = Util.getPreferenceInfo().getLanguage();
		Locale	loc = null;
		if (language.compareTo("") == 0) {
			loc = Locale.getDefault();
			language = loc.getLanguage();
		}
		
		loc = new Locale(language, "");
		return loc;
	}
	
	public static String makePassword(String srcPassword) {
		String	destPassword = "";

		if (srcPassword == null || srcPassword != null && srcPassword.length() == 0) {
			return destPassword;
		} else {
			destPassword = Base64.encode(MsgDigest.getDigest(srcPassword));
		}
		
		return destPassword;
	}
	
	public static void debugPrint(String msg) {
		if (Util.getPreferenceInfo().isDebug()) {
			System.out.println(msg);
		}
	}
	
	public static PreferenceInfo getPreferenceInfo() {
		return GlobalContext.getInstance().getPreferenceInfo();
	}
}

⌨️ 快捷键说明

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