package com; import java.lang.management.ManagementFactory; import java.lang.management.RuntimeMXBean; 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; import javax.swing.JTextField; 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 int CNT_MAX = 99999999; public static final String DTF_YMDhms_S = "yyyy-MM-dd HH:mm:ss.SSS"; 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[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 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 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 cb_sex, String it_obj) { int it_index = -1; for(int n=0; n> src_vvo, Vector> target_vvo) { if((null != src_vvo) && (null != target_vvo)) { if(target_vvo.size() < src_vvo.size()) { for(int n=0; n=0; n--) { if(n >= src_vvo.size()) { target_vvo.removeElementAt(n); } else { target_vvo.setElementAt(src_vvo.get(n), n); } } } } } public static int getPid() { RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean(); String name = runtime.getName(); // format: "pid@hostname" try { return Integer.parseInt(name.substring(0, name.indexOf('@'))); } catch (Exception e) { return -1; } } public static void setTFDocLimit(JTextField tf, int charlen, String str) { tf.setDocument(new LimitedDocument(charlen, str)); } }