?? zscom_func.java
字號:
package wisesoft;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import com.borland.dx.dataset.*;
import com.borland.dx.sql.dataset.*;
import java.math.*;
import com.borland.dx.text.*;
import com.borland.dbswing.*;
import com.borland.jbcl.layout.*;
import java.text.Format;
import java.util.Calendar;
import java.lang.reflect.Field;
//import Padapt_Report.*;
//import Padapt_ToFiles.*;
import java.io.*;
/**
* <p>Title:工程常用函數(shù) </p>
* <p>Description:系統(tǒng)常用公用函數(shù),窗體顯示,消息框顯示,數(shù)據(jù)類型轉換等,豐富哈!!! </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author bear_king 熊運余
* @version 1.0
*/
public class ZSCom_Func
{
static Dialog m_FrameParent;
//==============================================================================
//列表的行號寬度
public static final int ROWHEADE_WIDTH =50;
//===============================================================================
//投影中心點的坐標和高度(用于計算限制區(qū)形狀)
public static double DEF_ORG_LONG = 102.0;
public static double DEF_ORG_LAT = 30.0;
public static int DEF_ORG_HEIGHT = 500;
public static int C_STANDARD_RADIUS = 10; //公里
public static int C_STANDARD_PCOUNT = 10; //點數(shù)
public static double PI = 3.1415926;
//================================================================================
//窗體顯示風格
public static int C_SHOW_CENTER=1;//顯示居中,查找窗體
public static int C_SHOW_MAX=0;//最大顯示
public static int C_SHOW_Standard=2;//居中,窗體大小不限制
public static int C_SHOW_SmallFind=3;//查詢小窗體
public static int C_SHOW_Default=6;//缺省對話框大小
public static int C_FINDDLG_WIDTH=500;//查找中窗體寬
public static int C_FINDDLG_HEIGHT=500;//查找中窗體高
public static int C_EDITDLG_WIDTH=900;//錄入窗體寬,缺省設置
public static int C_EDITDLG_HEIGHT=700;//錄入窗體高,缺省設置
public static int C_FIND_SMALLDLG_WIDTH=500;//查找中窗體寬
public static int C_FIND_SMALLDLG_HEIGHT=500;//查找中窗體高
//===================================================================================
/////////////////版本控制////////////
public static String Data_Version="V2.10";
/////////////////////////////
// 連接數(shù)據(jù)庫的信息
public static String[] m_strConnectDBInfo = {"", "", "", ""};
//設置光標顯示類型
public static Cursor C_WAIT_CURSOR = new Cursor(java.awt.Cursor.WAIT_CURSOR);
public static Cursor C_DEFAULT_CURSOR = new Cursor(java.awt.Cursor.DEFAULT_CURSOR);
// 字體大小
private static boolean m_bSameSize =true;// false;
private static int m_nFontSize = 12;
private static double m_FontRatio= 0.65;
public static String c_font_str="Dialog";
//設置界面背景顏色20031126
public static Color m_colorPanel= new Color(120, 200, 250);
public static Color m_EditBackcolor= new Color(255, 255, 255);//編輯框背景色
//一級父窗體20031126
public static JFrame C_Parent_Frame;
public static JDialog C_Parent_Dlg;//二級父窗體,對話框
//設置窗體背景顏色
public static Color m_backcolor= new Color(96, 149, 185);
public static Color m_oldbackcolor= new Color(174,178,195); //
//設置主要界面的標題
public static String C_MainWindow_Title="";//主窗體名稱
public static String C_SubWindow_Title="";//子窗體名稱
public static Dimension m_dimEditBtn = new Dimension(90, 28);//設置編輯按鈕大小
public static String m_strFontNameEditBtn = new String("Dialog");//設置編輯按鈕字體
public static int m_nFontSizeEditBtn = 12;//設置編輯按鈕字體大小
public ZSCom_Func() {
}
//顯示對話框大小、位置調(diào)整(),更改將顯示方法加入進去
public static void SetUserDlg(JDialog AForm,JComponent AParent,int ShowType)
{
int nComponentSize = AForm.getComponentCount();
AForm.setBackground(m_backcolor);
for(int i=0; i<nComponentSize; i++)
{
ZSCom_Func.setComponentFont((JComponent)AForm.getComponent(i));
}
AForm.pack();
switch(ShowType)
{
case 1://居中,標準查找窗體大小//Center
{
Dimension dlgSize = new Dimension();
dlgSize.width = C_FINDDLG_WIDTH;
dlgSize.height = C_FINDDLG_HEIGHT;
AForm.setSize(dlgSize);
Dimension frmSize = AParent.getSize();
Point loc = AParent.getLocationOnScreen();
//JOpctionPane.s
AForm.setLocation( (frmSize.width - dlgSize.width) / 2 + loc.x,
(frmSize.height - dlgSize.height) / 2 + loc.y);
}
break;
case 0://全屏大小//Max
{
Dimension frmSize = AParent.getSize();
Point loc = AParent.getLocationOnScreen();
AForm.setLocation(loc);
frmSize.height = frmSize.height-40;
frmSize.width = frmSize.width ;
AForm.setSize(frmSize);
}
break;
case 2://缺省大小,設計期大小//standard
{
Dimension dlgSize = AForm.getSize();
Dimension frmSize = AParent.getSize();
Point loc = AParent.getLocationOnScreen();
//JOpctionPane.s
AForm.setLocation( (frmSize.width - dlgSize.width) / 2 + loc.x,
(frmSize.height - dlgSize.height) / 2 + loc.y);
}
break;
case 3://查找小窗體,居中C_SHOW_SmallFind
{
Dimension dlgSize = new Dimension();
dlgSize.width = C_FIND_SMALLDLG_WIDTH;
dlgSize.height = C_FIND_SMALLDLG_HEIGHT;
AForm.setSize(dlgSize);
Dimension frmSize = AParent.getSize();
Point loc = AParent.getLocationOnScreen();
//JOpctionPane.s
AForm.setLocation( (frmSize.width - dlgSize.width) / 2 + loc.x,
(frmSize.height - dlgSize.height) / 2 + loc.y);
}
break;
case 4://查找小窗體,下拉,居左
{
Dimension dlgSize = new Dimension();
dlgSize.width = C_FIND_SMALLDLG_WIDTH;
dlgSize.height = C_FIND_SMALLDLG_HEIGHT;
AForm.setSize(dlgSize);
Dimension frmSize = AParent.getSize();
Point loc = AParent.getLocationOnScreen();
AForm.setLocation( (frmSize.width - dlgSize.width) / 2 + loc.x,
(frmSize.height - dlgSize.height) / 2 + loc.y);
}
break;
case 6://缺省大小//
{
Dimension frmSize = AParent.getSize();
Dimension dlgSize = AForm.getSize();
Point loc = AParent.getLocationOnScreen();
frmSize.height = frmSize.height;//1200 - 40;
frmSize.width = frmSize.width ;//1600;
dlgSize.height = C_EDITDLG_HEIGHT;//700
dlgSize.width = C_EDITDLG_WIDTH;//900
AForm.setLocation( (frmSize.width - dlgSize.width) / 2 + loc.x,
(frmSize.height - dlgSize.height) / 2 + loc.y);
AForm.setSize(dlgSize.width, dlgSize.height);
}
break;
}
AForm.setModal(true);
AForm.show();
}
public static void Showmessage(String str,String strtitle)
{
if(!isNull(C_Parent_Dlg))
JOptionPane.showMessageDialog(C_Parent_Dlg,str,strtitle, JOptionPane.INFORMATION_MESSAGE);
else
JOptionPane.showMessageDialog(C_Parent_Frame,str,strtitle, JOptionPane.INFORMATION_MESSAGE);
}
public static void Showmessage(String str,String strtitle,JDialog m_pFrm)
{
JOptionPane.showMessageDialog(m_pFrm,str,strtitle, JOptionPane.INFORMATION_MESSAGE);
}
public static void SetQuery(Database database,QueryDataSet Qry,String sqlStr)
{
QueryDescriptor m_QD = new QueryDescriptor(database, sqlStr);
Qry.setQuery(m_QD);
}
public static int sizeof(Object obj){
Class cla = obj.getClass();
if(cla.getName().equals("java.lang.Double"))
return 8;
else if(cla.getName().equals("java.lang.Integer"))
return 4;
else if(cla.getName().equals("java.lang.Byte"))
return 1;
else if(cla.getName().equals("java.lang.Float"))
return 4;
else if(cla.getName().equals("java.lang.Short"))
return 2;
else if(cla.getName().equals("java.lang.Long"))
return 8;
else return -1;
}
public static BigDecimal IntToBigdecimal (int i)
{
Variant m_variant=new Variant();
m_variant.setInt(i);
return m_variant.getAsBigDecimal();
}
public static int BigdecimalToInt (BigDecimal i)
{
Variant m_variant=new Variant();
m_variant.setBigDecimal(i);
return m_variant.getAsInt();
}
public static void SetUserFrm(JFrame AForm,JComponent AParent,int ShowType)
{
int nComponentSize = AForm.getComponentCount();
AForm.setBackground(m_backcolor);
for (int i = 0; i < nComponentSize; i++) {
setComponentFont( (JComponent) AForm.getComponent(i));
setComponentBackColor( (JComponent) AForm.getComponent(i));
// setComponentGridbagLayout((JComponent)AForm.getComponent(i));
}
switch(ShowType)
{
case 1://C_SHOW_CENTER://居中,標準查找窗體大小
{
Dimension dlgSize = new Dimension();
dlgSize.width = C_FINDDLG_WIDTH;
dlgSize.height = C_FINDDLG_HEIGHT;
AForm.setSize(dlgSize);
Dimension frmSize = AParent.getSize();
Point loc = AParent.getLocationOnScreen();
//JOpctionPane.s
AForm.setLocation( (frmSize.width - dlgSize.width) / 2 + loc.x,
(frmSize.height - dlgSize.height) / 2 + loc.y);
}
break;
case 0://C_SHOW_MAX://全屏大小
{
Dimension frmSize = AParent.getSize();
Point loc = AParent.getLocationOnScreen();
loc.y= loc.y;
loc.x= loc.x;
AForm.setLocation(loc);
frmSize.height = frmSize.height;
frmSize.width = frmSize.width ;
AForm.setSize(frmSize);
}
break;
case 2://C_SHOW_Standard 缺省大小,設計期大小
{
Dimension dlgSize = AForm.getSize();
Dimension frmSize = AParent.getSize();
Point loc = AParent.getLocationOnScreen();
//JOpctionPane.s
AForm.setLocation( (frmSize.width - dlgSize.width) / 2 + loc.x,
(frmSize.height - dlgSize.height) / 2 + loc.y);
}
break;
case 3://C_SHOW_SmallFind 查找小窗體,居中
{
Dimension dlgSize = new Dimension();
dlgSize.width = C_FIND_SMALLDLG_WIDTH;
dlgSize.height = C_FIND_SMALLDLG_HEIGHT;
AForm.setSize(dlgSize);
Dimension frmSize = AParent.getSize();
Point loc = AParent.getLocationOnScreen();
AForm.setLocation( (frmSize.width - dlgSize.width) / 2 + loc.x,
(frmSize.height - dlgSize.height) / 2 + loc.y);
}
break;
case 4://查找小窗體,下拉,居左
{
Dimension dlgSize = new Dimension();
dlgSize.width = C_FIND_SMALLDLG_WIDTH;
dlgSize.height = C_FIND_SMALLDLG_HEIGHT;
AForm.setSize(dlgSize);
Dimension frmSize = AParent.getSize();
Point loc = AParent.getLocationOnScreen();
AForm.setLocation( (frmSize.width - dlgSize.width) / 2 + loc.x,
(frmSize.height - dlgSize.height) / 2 + loc.y);
}
break;
}
//AForm.setUndecorated(true);
//AForm.setDefaultLookAndFeelDecorated(false);
AForm.show();
}
////////////////////////////////////////////////////////////////////////////////////////////////////
// added by jqf 2003.09.30
public static boolean deleteMessageDlg()
{
if (!isNull(C_Parent_Dlg))
{
if (JOptionPane.showConfirmDialog(C_Parent_Dlg, "確實要刪除嗎?", "刪除提示",
JOptionPane.YES_NO_OPTION) ==
JOptionPane.YES_OPTION) {
return true;
}
else {
return false;
}
}
else
{
if (JOptionPane.showConfirmDialog(C_Parent_Frame, "確實要刪除嗎?", "刪除提示",
JOptionPane.YES_NO_OPTION) ==
JOptionPane.YES_OPTION) {
return true;
}
else {
return false;
}
}
}
public static void setComponentGridbagLayout(JComponent component)
{
int nComponent = component.getComponentCount();
if(nComponent == 0)
{
return;
}
for(int i=0; i<nComponent; i++)
{
try
{
if( (component.getComponent(i).getClass().equals(JPanel.class) ||
component.getComponent(i).getClass().equals(Panel.class)) &&
((JComponent)component.getComponent(i)).getLayout().getClass().equals(XYLayout.class))
{
((JComponent)component.getComponent(i)).setLayout(new GridBagLayout());
component.getComponent(i).validate();
}
setComponentGridbagLayout((JComponent)component.getComponent(i));
}
catch(Exception ex)
{
// ex.printStackTrace();
}
}
}
public static void setComponentFont(JComponent component)
{
if(!m_bSameSize)
{
return;
}
int nComponent = component.getComponentCount();
if(nComponent == 0)
{
return;
}
for(int i=0; i<nComponent; i++)
{
try
{
setComponentFont( (JComponent) component.getComponent(i));
}
catch(Exception ex)
{
}
}
}
// 獲取經(jīng)度度數(shù)值
public static String getLongitudeDegree(String str)
{
int nLen = str.length();
int i;
String strLongigude;
if((str.charAt(0) == 'e' || str.charAt(0) == 'E') && nLen <= 2 || nLen < 3)
{
JOptionPane.showMessageDialog(C_Parent_Frame, "您輸入的經(jīng)度度數(shù)值錯誤", "錯誤提示", JOptionPane.INFORMATION_MESSAGE);
return "";
}
if(str.charAt(0) == 'e' || str.charAt(0) == 'E')
{
for(i=1; i<nLen; i++)
{
if(str.charAt(i) < '0' || str.charAt(i) > '9')
{
JOptionPane.showMessageDialog(C_Parent_Frame, "您輸入的經(jīng)度度數(shù)值錯誤", null, JOptionPane.INFORMATION_MESSAGE);
return "";
}
}
strLongigude = str.substring(1);
}
else
{
for(i=0; i<nLen; i++)
{
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -