package com;
|
|
import java.net.Inet4Address;
|
import java.net.InetAddress;
|
import java.net.NetworkInterface;
|
import java.text.DateFormat;
|
import java.text.ParseException;
|
import java.text.SimpleDateFormat;
|
import java.util.Date;
|
import java.util.Enumeration;
|
import java.util.Vector;
|
|
import javax.swing.JComboBox;
|
|
public class Com {
|
final public static int UploadData_ClientType_BS_CLI = 0;
|
final public static int UploadData_ClientType_CS_CLI = 1;
|
final public static int UploadData_ClientType_CS_SVR = 2;
|
|
public static final int EDIT_VIEW = 0;
|
public static final int EDIT_ADD = 1;
|
public static final int EDIT_MODIFY = 2;
|
|
public static final String DTF_YMDhms = "yyyy-MM-dd HH:mm:ss";
|
public static final String DTF_YMDhm = "yyyy-MM-dd HH:mm";
|
public static final String DTF_YMDh = "yyyy-MM-dd HH";
|
public static final String DTF_YMD = "yyyy-MM-dd";
|
public static final String DTF_hms = "HH:mm:ss";
|
public static final long DT_OFFSET = 3600*8*1000;
|
|
public static final String[] YesNoText = new String[] {
|
"·ñ",
|
"ÊÇ",
|
};
|
//final public static DateFormat DateTimeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
public static String get_DTF(Date dt, String format){
|
DateFormat dtf = new SimpleDateFormat(format);
|
return dtf.format(dt);
|
}
|
|
public static Date get_DT_FromStr(String dt, String format){
|
DateFormat dtf = new SimpleDateFormat(format);
|
Date date = new Date();
|
try {
|
date = dtf.parse(dt);
|
} catch (ParseException e) {
|
e.printStackTrace();
|
}
|
|
return date;
|
}
|
|
/**
|
* ÅжÏnumber²ÎÊýÊÇ·ñÊÇÕûÐÍÊý±íʾ·½Ê½
|
* @param number
|
* @return
|
*/
|
public static boolean isIntegerNumber(String number){
|
number = number.trim();
|
String intNumRegex = "\\-{0,1}\\d+"; //ÕûÊýµÄÕýÔò±í´ïʽ
|
if(number.matches(intNumRegex))
|
return true;
|
else
|
return false;
|
}
|
|
/**
|
* ÅжÏnumber²ÎÊýÊÇ·ñÊǸ¡µãÊý±íʾ·½Ê½
|
* @param numbe
|
* @return
|
*/
|
public static boolean isFloatPointNumber(String number){
|
number = number.trim();
|
String intNumRegex = "\\-{0,1}\\d+"; //ÕûÊýµÄÕýÔò±í´ïʽ
|
String pointPrefix = "(\\-|\\+){0,1}\\d*\\.\\d+"; //¸¡µãÊýµÄÕýÔò±í´ïʽ-СÊýµãÔÚÖмäÓëÇ°Ãæ
|
String pointSuffix = "(\\-|\\+){0,1}\\d+\\."; //¸¡µãÊýµÄÕýÔò±í´ïʽ-СÊýµãÔÚºóÃæ
|
if(number.matches(intNumRegex) || number.matches(pointPrefix) || number.matches(pointSuffix))
|
return true;
|
else
|
return false;
|
}
|
|
/**
|
* ÅжÏnumber²ÎÊýÊÇ·ñÊÇÈÕÆÚ±íʾ·½Ê½
|
* @param str
|
* @return
|
*/
|
public static boolean isValidDate(String str, String format) {
|
boolean convertSuccess = true;
|
try {
|
//DateTimeFormat.setLenient(false);
|
DateFormat dtf = new SimpleDateFormat(format);
|
dtf.parse(str);
|
} catch (ParseException e) {
|
convertSuccess = false;
|
}
|
return convertSuccess;
|
}
|
|
/**
|
*
|
* @param
|
* @return
|
*/
|
public static float[] sortData(float[] data, int len) {
|
float[] sort_data = new float[len];
|
for(int n=0; n<sort_data.length; n++)
|
sort_data[n] = data[n];
|
|
float tmp;
|
for(int n=0; n<sort_data.length; n++)
|
{
|
tmp = sort_data[n];
|
for(int m=n; m<sort_data.length; m++)
|
{
|
if(sort_data[n] > sort_data[m])
|
{
|
sort_data[n] = sort_data[m];
|
sort_data[m] = tmp;
|
tmp = sort_data[n];
|
}
|
}
|
}
|
|
return sort_data;
|
}
|
|
/**
|
*
|
* @param
|
* @return
|
*/
|
public static float getAvrageData(float[] data, int len) {
|
float sum_data = 0;
|
for(int n=0; n<len; n++)
|
sum_data += data[n];
|
|
return (sum_data/len);
|
}
|
|
/**
|
*
|
* @param
|
* @return
|
*/
|
/*
|
public static short CalCRC16(byte[] Pushdata, int length)
|
{
|
int Reg_CRC = 0xFFFF;
|
for(int i = 0; i<length; i ++)
|
{
|
Reg_CRC ^= Pushdata[i];
|
for (int j = 0; j<8; j++)
|
{
|
if((Reg_CRC & 0x0001) > 0)
|
Reg_CRC = (Reg_CRC>>1) ^ 0xA001;
|
else
|
Reg_CRC >>= 1;
|
}
|
}
|
return (short)(Reg_CRC&0xFFFF);
|
}
|
*/
|
/**
|
*
|
* @param
|
* @return
|
*/
|
static public String getLoacalHostIp()
|
{
|
Enumeration<?> allNetInterfaces = null;
|
try {
|
allNetInterfaces = NetworkInterface.getNetworkInterfaces();
|
} catch (java.net.SocketException e) {
|
e.printStackTrace();
|
}
|
|
while (allNetInterfaces.hasMoreElements())
|
{
|
NetworkInterface netInterface = (NetworkInterface) allNetInterfaces.nextElement();
|
System.out.println(netInterface.getName());
|
|
Enumeration<?> addresses = netInterface.getInetAddresses();
|
while (addresses.hasMoreElements())
|
{
|
InetAddress ip = (InetAddress) addresses.nextElement();
|
if (ip != null && ip instanceof Inet4Address)
|
{
|
System.out.println(netInterface.getName() + ": " + ip.getHostAddress());
|
if(netInterface.getName().contains("wlan0"))
|
{
|
return ip.getHostAddress();
|
}
|
}
|
}
|
}
|
|
return "127.0.0.1";
|
}
|
/**
|
*
|
* @param
|
* @return
|
*/
|
public static boolean getIPFromStr(String ipstr, byte ip[])
|
{
|
boolean res = false;
|
try
|
{
|
for(int n=0; n<3; n++)
|
{
|
int index = ipstr.indexOf('.');
|
if(index > 0)
|
ip[n] = (byte)Integer.parseInt(ipstr.substring(0, index));
|
|
ipstr = ipstr.substring(index+1);
|
}
|
ip[3] = (byte)Integer.parseInt(ipstr);
|
|
res = true;
|
}
|
catch(Exception e)
|
{
|
System.out.println(e.getMessage());
|
}
|
|
return res;
|
}
|
/**
|
*
|
* @param
|
* @return
|
*/
|
public static Object getComboBoxItemText(JComboBox<Object> cb, int it_index)
|
{
|
Object obj = "";
|
if(it_index < cb.getItemCount())
|
obj = cb.getItemAt(it_index);
|
|
return obj;
|
}
|
/**
|
*
|
* @param
|
* @return
|
*/
|
public static int getComboBoxItemIndex(JComboBox<String> cb_sex, String it_obj)
|
{
|
int it_index = -1;
|
for(int n=0; n<cb_sex.getItemCount(); n++)
|
{
|
if(cb_sex.getItemAt(n).equals(it_obj))
|
{
|
it_index = n;
|
break;
|
}
|
}
|
|
return it_index;
|
}
|
|
public static int getComboBoxItemIndex(String[] cb, String it_obj)
|
{
|
int it_index = -1;
|
for(int n=0; n<cb.length; n++)
|
{
|
if(cb[n].equals(it_obj))
|
{
|
it_index = n;
|
break;
|
}
|
}
|
|
return it_index;
|
}
|
|
public static String getAppPath() {
|
String app_path = System.getProperty("user.dir");
|
return app_path;
|
}
|
|
public static void copyTableRowData(Vector<Vector<Object>> src_vvo, Vector<Vector<Object>> target_vvo)
|
{
|
if((null != src_vvo) && (null != target_vvo)) {
|
if(target_vvo.size() < src_vvo.size()) {
|
for(int n=0; n<src_vvo.size(); n++) {
|
if(n < target_vvo.size()) {
|
target_vvo.setElementAt(src_vvo.get(n), n);
|
} else {
|
target_vvo.add(src_vvo.get(n));
|
}
|
}
|
} else {
|
for(int n=(target_vvo.size()-1); n>=0; n--) {
|
if(n >= src_vvo.size()) {
|
target_vvo.removeElementAt(n);
|
} else {
|
target_vvo.setElementAt(src_vvo.get(n), n);
|
}
|
}
|
}
|
}
|
}
|
}
|