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

📄 jtpresource.java

📁 这个是一个java绘图方面的源码
💻 JAVA
字号:
package com.sunking.tp.util;

import java.io.*;
import java.util.*;

/**
 * <p>Title: JTPResource</p>
 * <p>Description: 资源调入,运行此类可以将手写的properties文件生成unicode码的资源文件</p>
 * <p>Copyright: Copyright (c) 2003</p>
 * <p>Company: </p>
 * @author <a href="mailto:sunkingxie@hotmail.com">SunKing</a>
 * @version 1.0
 */

public class JTPResource {
    ResourceBundle rb;
    private JTPResource() {}

    private static JTPResource defaultInstance;
    public static JTPResource getDefault() {
        if (defaultInstance == null) {
            defaultInstance = new JTPResource();
        }
        return defaultInstance;
    }

    public String getString(String key) {
        if (rb == null) {
            try {
                rb = ResourceBundle.getBundle("JTPResources", Locale.getDefault(),
                    ClassLoader.getSystemClassLoader());
            } catch (Exception ex) {
                throw new NullPointerException("ERROR:CAN NOT FOUND RESOURCE FILE!  " +
                    new File("src/JTPResources_" +
                    Locale.getDefault().toString() + ".properties").getAbsolutePath());
            }
        }
        return rb.getString(key);
    }

    /**
     * 资源文件生成
     */
    public static void main(String argv[]) {
        try {
            //英文
            Properties p = new Properties();
            p.load(new FileInputStream("resources/JTPResources.properties"));
            p.store(new FileOutputStream("src/JTPResources.properties"), null);
            //简体中文
            p = new MyProperties("GB2312");
            p.load(new FileInputStream("resources/JTPResources_zh_CN.properties"));
            p.store(new FileOutputStream("src/JTPResources_zh_CN.properties"), null);
            //繁体中文
            p = new MyProperties("BIG5");
            p.load(new FileInputStream("resources/JTPResources_zh_TW.properties"));
            p.store(new FileOutputStream("src/JTPResources_zh_TW.properties"), null);
            p.store(new FileOutputStream("src/JTPResources_zh_HK.properties"), null);
            p.store(new FileOutputStream("src/JTPResources_zh_MO.properties"), null);
            //日语
            p = new MyProperties("SJIS");
            p.load(new FileInputStream("resources/JTPResources_ja_JP.properties"));
            p.store(new FileOutputStream("src/JTPResources_ja_JP.properties"), null);

        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}

/**
 * <p>Title: MyProperties</p>
 * <p>Description: 可调入自定义内码的Properties</p>
 * <p>Copyright: Copyright (c) 2003</p>
 * <p>Company: </p>
 * @author <a href="mailto:sunkingxie@hotmail.com">SunKing</a>
 * @version 1.0
 */
class MyProperties extends Properties {
    String encoding;
    public MyProperties(String encoding) {
        this.encoding = encoding;
    }

    private static final String keyValueSeparators = "=: \t\r\n\f";
    private static final String strictKeyValueSeparators = "=:";
    private static final String specialSaveChars = "=: \t\r\n\f#!";
    private static final String whiteSpaceChars = " \t\r\n\f";
    public synchronized void load(InputStream inStream) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(inStream, encoding));
        while (true) {
            // Get next line
            String line = in.readLine();
            if (line == null)
                return;

            if (line.length() > 0) {

                // Find start of key
                int len = line.length();
                int keyStart;
                for (keyStart = 0; keyStart < len; keyStart++)
                    if (whiteSpaceChars.indexOf(line.charAt(keyStart)) == -1)
                        break;

                // Blank lines are ignored
                if (keyStart == len)
                    continue;

                // Continue lines that end in slashes if they are not comments
                char firstChar = line.charAt(keyStart);
                if ( (firstChar != '#') && (firstChar != '!')) {
                    while (continueLine(line)) {
                        String nextLine = in.readLine();
                        if (nextLine == null)
                            nextLine = "";
                        String loppedLine = line.substring(0, len - 1);
                        // Advance beyond whitespace on new line
                        int startIndex;
                        for (startIndex = 0; startIndex < nextLine.length(); startIndex++)
                            if (whiteSpaceChars.indexOf(nextLine.charAt(startIndex)) == -1)
                                break;
                        nextLine = nextLine.substring(startIndex, nextLine.length());
                        line = new String(loppedLine + nextLine);
                        len = line.length();
                    }

                    // Find separation between key and value
                    int separatorIndex;
                    for (separatorIndex = keyStart; separatorIndex < len; separatorIndex++) {
                        char currentChar = line.charAt(separatorIndex);
                        if (currentChar == '\\')
                            separatorIndex++;
                        else if (keyValueSeparators.indexOf(currentChar) != -1)
                            break;
                    }

                    // Skip over whitespace after key if any
                    int valueIndex;
                    for (valueIndex = separatorIndex; valueIndex < len; valueIndex++)
                        if (whiteSpaceChars.indexOf(line.charAt(valueIndex)) == -1)
                            break;

                    // Skip over one non whitespace key value separators if any
                    if (valueIndex < len)
                        if (strictKeyValueSeparators.indexOf(line.charAt(valueIndex)) != -1)
                            valueIndex++;

                            // Skip over white space after other separators if any
                    while (valueIndex < len) {
                        if (whiteSpaceChars.indexOf(line.charAt(valueIndex)) == -1)
                            break;
                        valueIndex++;
                    }
                    String key = line.substring(keyStart, separatorIndex);
                    String value = (separatorIndex < len) ? line.substring(valueIndex, len) : "";

                    // Convert then store key and value
                    key = loadConvert(key);
                    value = loadConvert(value);
                    put(key, value);
                }
            }
        }
    }

    private boolean continueLine(String line) {
        int slashCount = 0;
        int index = line.length() - 1;
        while ( (index >= 0) && (line.charAt(index--) == '\\'))
            slashCount++;
        return (slashCount % 2 == 1);
    }

    private String loadConvert(String theString) {
        char aChar;
        int len = theString.length();
        StringBuffer outBuffer = new StringBuffer(len);

        for (int x = 0; x < len; ) {
            aChar = theString.charAt(x++);
            if (aChar == '\\') {
                aChar = theString.charAt(x++);
                if (aChar == 'u') {
                    // Read the xxxx
                    int value = 0;
                    for (int i = 0; i < 4; i++) {
                        aChar = theString.charAt(x++);
                        switch (aChar) {
                            case '0':
                            case '1':
                            case '2':
                            case '3':
                            case '4':
                            case '5':
                            case '6':
                            case '7':
                            case '8':
                            case '9':
                                value = (value << 4) + aChar - '0';
                                break;
                            case 'a':
                            case 'b':
                            case 'c':
                            case 'd':
                            case 'e':
                            case 'f':
                                value = (value << 4) + 10 + aChar - 'a';
                                break;
                            case 'A':
                            case 'B':
                            case 'C':
                            case 'D':
                            case 'E':
                            case 'F':
                                value = (value << 4) + 10 + aChar - 'A';
                                break;
                            default:
                                throw new IllegalArgumentException(
                                    "Malformed \\uxxxx encoding.");
                        }
                    }
                    outBuffer.append( (char) value);
                } else {
                    if (aChar == 't')
                        aChar = '\t';
                    else if (aChar == 'r')
                        aChar = '\r';
                    else if (aChar == 'n')
                        aChar = '\n';
                    else if (aChar == 'f')
                        aChar = '\f';
                    outBuffer.append(aChar);
                }
            } else
                outBuffer.append(aChar);
        }
        return outBuffer.toString();
    }
}

⌨️ 快捷键说明

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