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

📄 jmmesgbox.java.svn-base

📁 梦界家园程序开发基底框架
💻 SVN-BASE
字号:
package jm.framework.gui ;

import java.awt.Component;
import java.util.HashMap;

import javax.swing.JOptionPane;

import jm.util.JM2DArray;
import jm.util.JMVector;

/**
 * @author Spook
 * @version 0.1.0
 */
public class JMMesgBox
{
    public static final String CLASS_NAME = "MESGBOX" ;
    public static final String S_WARING = "WARING" ;
    public static final String S_ERR = "ERR" ;
    public static final String S_SURE = "SURE" ;

    public static int TYPE_SURE = 0 ;
    public static int TYPE_WARING = 1 ;
    public static int TYPE_ERR = 2 ;
    public static int TYPE_INFO = 3 ;

    public static int DEFAULT_OPTION = JOptionPane.DEFAULT_OPTION ;
    public static int INFORMATION_MESSAGE = JOptionPane.INFORMATION_MESSAGE ;
    public static int QUESTION_MESSAGE = JOptionPane.QUESTION_MESSAGE ;
    public static int WARNING_MESSAGE = JOptionPane.WARNING_MESSAGE ;
    public static int ERROR_MESSAGE = JOptionPane.ERROR_MESSAGE ;
    public static int OK_CANCEL_OPTION = JOptionPane.OK_CANCEL_OPTION ;
    public static int YES_OPTION = JOptionPane.YES_OPTION ;
    public static int NO_OPTION = JOptionPane.NO_OPTION ;
    public static int OK_OPTION = JOptionPane.OK_OPTION ;
    public static int CANCEL_OPTION = JOptionPane.CANCEL_OPTION ;
    public static int CLOSED_OPTION = JOptionPane.CLOSED_OPTION ;
//    private SvServerTypes oSvServerTypes = null ;
    private HashMap<String , String> hMesageAll = null ;
    final String SYSTEM_ERROR_MESAGE = "僔僗僥儉偼旕忢偵岆傝偵塣峴偡傞丅" ;

    protected static Component oparComponent = null ;
    private static JMMesgBox instance = null ;
    public static synchronized JMMesgBox getInstance ( Component aoParComponent )
    {
 //       final String sMethod = "getInstance" ;
        try
        {
            oparComponent = aoParComponent ;
            if ( instance == null )
            {
                instance = new JMMesgBox () ;
            }
        }
        catch ( Exception e )
        {
//            SvServerTypes.printLog ( CLASS_NAME , sMethod , e ) ;
        }
        return instance ;
    }

    private JMMesgBox ()
    {
        final String sMethod = "MesgBox" ;
        try
        {
            hMesageAll = new HashMap<String , String> () ;
//            oSvServerTypes = SvServerTypes.getInstance () ;
//            getMasterFromDB () ;
//            getMasterFromXml ( oSvServerTypes.ERR_MESAGE_FILENAME ) ;
//System.out.println("hMesageAll===>"+hMesageAll);
//            if ( oSvServerTypes.SYSTEM_MODEL.equals ( SYSTEM_MODEL_WINDOW ) )
//            {
//                UIManager.setLookAndFeel ( UIManager.getSystemLookAndFeelClassName () ) ;
//            }
//            else if ( oSvServerTypes.SYSTEM_MODEL.equals ( SYSTEM_MODEL_JAVA ) )
//            {
//                UIManager.setLookAndFeel ( UIManager.getCrossPlatformLookAndFeelClassName () ) ;
//            }
//            else
//            {
//                UIManager.setLookAndFeel ( new MetalLookAndFeel () ) ;
//            }
        }
        catch ( Exception e )
        {
            System.out.println ( CLASS_NAME + "." + sMethod + "==>" + e.getMessage () ) ;
        }
    }

    public void reload ()
    {
        final String sMethod = "MesgBox" ;
        try
        {
            hMesageAll = new HashMap<String , String> () ;
//            oSvServerTypes = SvServerTypes.getInstance () ;
            getMasterFromDB () ;
//            getMasterFromXml ( oSvServerTypes.ERR_MESAGE_FILENAME ) ;
//System.out.println("hMesageAll===>"+hMesageAll);
        }
        catch ( Exception e )
        {
            System.out.println ( CLASS_NAME + "." + sMethod + "==>" + e.getMessage () ) ;
        }
    }

    /**
     * mMesgBox
     * @param astitle Title
     * @param asMesage  MesageVal
     * @return int
     */
    public int showMesgBox ( String astitle , String asMesage )
    {
        return JOptionPane.showConfirmDialog ( oparComponent ,
                                               asMesage ,
                                               astitle , JOptionPane.DEFAULT_OPTION ,
                                               JOptionPane.WARNING_MESSAGE ) ;
    }

    public int showMesgBox ( String asMsgid , int aiMsgType )
    {
        if ( aiMsgType == TYPE_SURE )
        {
            return JOptionPane.showConfirmDialog ( oparComponent ,
                getMesage ( asMsgid ) ,
                S_SURE ,
                JOptionPane.OK_CANCEL_OPTION ,
                JOptionPane.QUESTION_MESSAGE ) ;
        }
        else if ( aiMsgType == TYPE_WARING )
        {
            return JOptionPane.showConfirmDialog ( oparComponent ,
                getMesage ( asMsgid ) ,
                S_WARING ,
                JOptionPane.DEFAULT_OPTION ,
                JOptionPane.WARNING_MESSAGE ) ;
        }
        else if ( aiMsgType == TYPE_ERR )
        {
            return JOptionPane.showConfirmDialog ( oparComponent ,
                getMesage ( asMsgid ) ,
                S_ERR ,
                JOptionPane.DEFAULT_OPTION ,
                JOptionPane.ERROR_MESSAGE ) ;
        }
        return JOptionPane.showConfirmDialog ( oparComponent ,
                                               getMesage ( asMsgid ) ,
                                               getMesage ( S_SURE ) ,
                                               JOptionPane.DEFAULT_OPTION ,
                                               JOptionPane.INFORMATION_MESSAGE ) ;
    }

    public int showMesgBox ( String asMessage , String asTitle , int aiButtonType ,
                             int aiIconType )
    {
        return JOptionPane.showConfirmDialog ( oparComponent ,
                                               asMessage ,
                                               asTitle ,
                                               aiButtonType ,
                                               aiIconType ) ;
    }

    private String getMesage ( String asMesgId )
    {
//        final String sMethod = "getMesage" ;
        try
        {
            String msg = "";//JMCheck.trimStr ( "" + hMesageAll.get ( asMesgId.toUpperCase () ) ) ;
//            if ( msg.trim ().equals ( "" ) )return SYSTEM_ERROR_MESAGE ;
            return msg ;
        }
        catch ( Exception e )
        {
//            SvServerTypes.printLog ( CLASS_NAME , sMethod , e ) ;
            return SYSTEM_ERROR_MESAGE ;
        }
    }

    private void getMasterFromDB ()
        throws Exception
    {
            hMesageAll = new HashMap<String , String> () ;
            JMVector row = null ;
            JM2DArray oGamensTypes = getMasterDate () ;
            for ( int i = 0 ; i < oGamensTypes.rowCount () ; i++ )
            {
                //get from db
                row = oGamensTypes.getRowData ( i ) ;
                hMesageAll.put ( ( "" + row.get ( 0 ) ).toUpperCase () , "" + row.get ( 1 ) ) ;
            }

    }

    private synchronized JM2DArray getMasterDate ()
        throws Exception
    {
//            JMFolder oMasterDate = new JMFolder () ;
//
//            JMFolder oDataForm = new JMFolder () ;
//
//            JM2DArray oCon = new JM2DArray () ;

//            oDataForm.addItem ( SVC_DB_NAME , oSvServerTypes.CON_DB_NAME ) ;
//            oDataForm.addItem ( SVC_DB_ROLE , SVC_SELECT ) ;
//            oDataForm.addItem ( SVC_DB_SQL_ID , "ERMSG0" ) ;
//            oDataForm.addItem ( SVC_DB_SQL_CON , oCon ) ;
//
//            oMasterDate = ( new SocketServerCall () ).invoke ( oDataForm ) ;
//            if ( oMasterDate == null )
//            {
//                throw new Exception ( sMethod , "DB null" ) ;
//            }
//            boolean pbresult = oMasterDate.getBooleanValue ( DB_RESULT ) ;
//            if ( !pbresult )
//            {
//                throw new Exception ( sMethod , "DB err" ) ;
//            }
            return null;//oMasterDate.getJM2DArrayValue ( DB_RETURN ) ;
    }

    public synchronized void getMasterFromXml ( String xmlFileName )
    {
 //       final String sMethod = "MesgBox" ;
//            XmlCatch sysxml = new XmlCatch ( xmlFileName ) ;
//            HashMap dM = sysxml.getAllChildValue () ;
//            Map.Entry entry = null ;
//            String pathname = "" ;
//            for ( Iterator iter = dM.entrySet ().iterator () ; iter.hasNext () ; )
//            {
//                entry = ( Map.Entry ) iter.next () ;
////                pathname = JMCheck.trimStr ( "" + entry.getKey () ) ;
//                pathname = pathname.substring ( pathname.lastIndexOf ( "/" ) + 1 ) ;
//                hMesageAll.put ( pathname.toUpperCase () , "" + entry.getValue () ) ;
//            }
    }

}

⌨️ 快捷键说明

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