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

📄 wiztype.java

📁 免疫遗传算法java语言版源程序
💻 JAVA
字号:
/**
 * IgaLib -> wizard
 * Copyright (C) 2001  Tosiki IGA , IgaLib project member
 *   (http://homepage2.nifty.com/igat/igapyon/index.html)
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package jp.ne.nifty.iga.tosiki.wizard;

import jp.ne.nifty.iga.tosiki.wizard.wiz.*;
import java.io.*;
import java.util.*;

/**
 * 僂傿僓乕僪偑埖偆宆偵娭偡傞儔僀僽儔儕<BR>
 * 側傞傋偔 "String" , "javax.swing.JCheckBox" 側偳偺婰弎傪偙偙偵廤栺偟偨偄偱偡丅
 */
public class WizType
{
	/**
	 * 擖椡偝傟偨暥帤楍曄悢僷僞乕儞暥帤楍傪 宆偵揔崌偡傞宍幃偵曄姺偡傞偨傔偺
	 * 暥帤楍僷僞乕儞傪僎僢僩偟傑偡丅<BR>
	 * 偙偺儊僜僢僪偼戝曄偵廳梫偱偡丅偲偄偆偺傕宆曄姺傪幚憰偟偰偄傞傕偺偩偐傜偱偡丅
	 * getType()側偳偱栠傞抣傪棙梡偟傑偡丅
	 * 応崌偵傛偭偰偼丄Type傪getWizAlterType()偱廋忺偡傞偙偲傕偁傝傑偡丅
	 *
	 *   @param String strSourceType 擖椡懁偺宆
	 *   @param String strTargetType 弌椡懁偺宆
	 *   @param String strSource     擖椡暥帤楍
	 *   @return String              曄姺屻暥帤楍丅曄姺晄擻偩偭偨応崌偼null丅
	 */
	public static final String getConvertPatternForType(String strSourceType,String strTargetType,String strSource)
	{
		if("boolean".equals(strSourceType))
		{
			if("boolean".equals(strTargetType))
			{
				return "("+strSource+")";
			}
			else if("char".equals(strTargetType))
			{
				return "("+strSource+"?'t':'f')";
			}
			else if("int".equals(strTargetType))
			{
				return "(1=="+strSource+")";
			}
			else if("String".equals(strTargetType))
			{
				return "("+strSource+"?\"t\":\"f\")";
			}
		}
		if("char".equals(strSourceType))
		{
			if("boolean".equals(strTargetType))
			{
				return "("+strSource+"=='t'?true:false)";
			}
			else if("char".equals(strTargetType))
			{
				return "("+strSource+")";
			}
			else if("int".equals(strTargetType))
			{
				return "((int)"+strSource+")";
			}
			else if("String".equals(strTargetType))
			{
				return "(\"\"+"+strSource+")";
			}
		}
		else if("int".equals(strSourceType))
		{
			if("boolean".equals(strTargetType))
			{
				return "(\"1\".equals("+strSource+")?true:false)";
			}
			else if("char".equals(strTargetType))
			{
				return "((int)"+strSource+")";
			}
			else if("int".equals(strTargetType))
			{
				return "("+strSource+")";
			}
			else if("String".equals(strTargetType))
			{
				return "(\"\"+"+strSource+")";
			}
		}
		else if("String".equals(strSourceType))
		{
			if("boolean".equals(strTargetType))
			{
				return "(\"true\".equals("+strSource+")?true:false)";
			}
			else if("char".equals(strTargetType))
			{
				return "("+strSource+".charAt(0))";
			}
			else if("int".equals(strTargetType))
			{
				return "(toInteger("+strSource+"))";
			}
			else if("String".equals(strTargetType))
			{
				return "("+strSource+")";
			}
			else if("java.math.BigDecimal".equals(strTargetType))
			{
				return "(new java.math.BigDecimal("+strSource+"))";
			}
		}
		else if("java.math.BigDecimal".equals(strSourceType))
		{
			if("String".equals(strTargetType))
			{
				return "(("+strSource+").toString())";
			}
			else if("java.math.BigDecimal".equals(strTargetType))
			{
				return "("+strSource+")";
			}
		}
		else if("javax.swing.JCheckBox".equals(strSourceType))
		{
			if("boolean".equals(strTargetType))
			{
				return "("+strSource+".isSelected())";
			}
		}
		else if("javax.swing.JTextField".equals(strSourceType))
		{
			if("String".equals(strTargetType))
			{
				return "("+strSource+".getText())";
			}
		}

		//System.out.println("\"getConvertPatternForType("+strSourceType+","+strTargetType+","+strSource+") is NOT supported.\"");
		return null;
	}

	/**
	 * 戙擖偺暥帤楍僷僞乕儞傪庢摼偟傑偡丅<BR>
	 * 側偍丄婎杮揑偵偼 帠慜偵宆偑挷惍偝傟偰偄傞傕偺偲偺慜採偺幚憰偱偡丅
	 */
	public static final String getLoadPatternForType(String strTargetType,String strSource)
	{
		if("javax.swing.JCheckBox".equals(strTargetType))
		{
			return ".setSelected("+strSource+")";
		}
		else if("javax.swing.JTextField".equals(strTargetType))
		{
			return ".setText("+strSource+")";
		}
		else
		{
			return "="+strSource;
		}
	}

	/**
	 * 僂傿僓乕僪偺埖偆婎杮宆傊偲宆傪撉傒懼偊傑偡丅
	 */
	public static final String getWizAlterType(String strType)
	{
		if("javax.swing.JCheckBox".equals(strType))
		{
			return "boolean";
		}
		else if("javax.swing.JTextField".equals(strType))
		{
			return "String";
		}
		return strType;
	}

	/**
	 * 梌偊傜傟偨宆偑Java尵岅偵偍偗傞
	 * 僾儕儈僥傿僽宆偐偳偆偐傪僠僃僢僋偟傑偡丅
	 */
	public static final boolean isJavaPremitiveType(String strType)
	{
		if("boolean".equals(strType)
		|| "char".equals(strType)
		|| "int".equals(strType))
		{
			return true;
		}
		else
		{
			return false;
		}
	}

	/**
	 * 梌偊傜傟偨宆偑僜乕僗僐乕僪僂傿僓乕僪偵偍偗傞
	 * 僾儕儈僥傿僽宆偐偳偆偐傪僠僃僢僋偟傑偡丅
	 */
	public static final boolean isWizPremitiveType(String strType)
	{
		if("boolean".equals(strType)
		|| "char".equals(strType)
		|| "int".equals(strType)
		|| "String".equals(strType)
		|| "java.math.BigDecimal".equals(strType)
		|| "javax.swing.JCheckBox".equals(strType)
		|| "javax.swing.JTextField".equals(strType))
		{
			return true;
		}
		else
		{
			return false;
		}
	}

	/**
	 * 梌偊傜傟偨僼傿乕儖僪偺帺暘傑偨偼巕偺宆偑
	 * 僜乕僗僐乕僪僂傿僓乕僪偵偍偗傞僾儕儈僥傿僽宆偐偳偆偐傪僠僃僢僋偟傑偡丅
	 */
	public static final boolean isWizPremitiveTypeWithChild(JSourceCodeWizardField field)
	{
		if("boolean".equals(field.getType())
		|| "char".equals(field.getType())
		|| "int".equals(field.getType())
		|| "String".equals(field.getType())
		|| "java.math.BigDecimal".equals(field.getType())
		|| "javax.swing.JCheckBox".equals(field.getType())
		|| "javax.swing.JTextField".equals(field.getType()))
		{
			return true;
		}
		else if("boolean".equals(field.getChild())
		|| "char".equals(field.getChild())
		|| "int".equals(field.getChild())
		|| "String".equals(field.getChild())
		|| "java.math.BigDecimal".equals(field.getChild())
		|| "javax.swing.JCheckBox".equals(field.getChild())
		|| "javax.swing.JTextField".equals(field.getChild()))
		{
			// 巕儕僗僩偼僔儕傾儔僀僘壜擻
			return true;
		}
		else
		{
			return false;
		}
	}
}

⌨️ 快捷键说明

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