Package org.geoforge.guillc.optionpane

Source Code of org.geoforge.guillc.optionpane.GfrOptionPaneAbs

/*
*  Copyright (C) 2011-2014 GeoForge Project
*
*  This program 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 3 of the License, or
*  (at your option) any later version.
*
*  This program 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 program.  If not, see <http://www.gnu.org/licenses/>.
*/

package org.geoforge.guillc.optionpane;

import java.awt.Component;
import java.awt.Dimension;
import java.io.File;
import javax.swing.JOptionPane;
import org.geoforge.guillc.dialog.DlgViewSrcFileTxtSys;
import org.geoforge.java.enumeration.GfrEnuSystemPropertiesKeys;
import org.geoforge.java.lang.string.GfrUtlString;
import org.geoforge.java.util.logging.filehandler.FileHandlerLogger;
import org.geoforge.lang.util.GfrResBundleLang;



/**
*
* @author bantchao
*
* email: bantchao_AT_gmail.com
* ... please remove "_AT_" from the above string to get the right email address
*
*/

abstract public class GfrOptionPaneAbs extends JOptionPane
{

    static public String s_showDialogQuestionInput(
                    Component cmpParent, // nil value allowed
                    String strTitle,
                    String strBody,
                    Object[] objsOption,
                    Object objInitialValue
                    )
    {
        // TODO: fix up persistency problem:
        /*
         * java.io.NotSerializableException: javax.swing.plaf.basic.BasicOptionPaneUI$ButtonAreaLayout
        */

        // beg tempo workaround

        cmpParent = null;

        // end tempo workaround

        return (String) JOptionPane.showInputDialog(
        cmpParent, strBody, strTitle, JOptionPane.QUESTION_MESSAGE, null,
        objsOption, objInitialValue);
    }

    static public boolean s_showDialogBringSecWin(
                    Component cmpParent,
                    String strTitleLong,
                    String strBody)
    {
        // TODO: fix up persistency problem:
        /*
         * java.io.NotSerializableException: javax.swing.plaf.basic.BasicOptionPaneUI$ButtonAreaLayout
        */

        // beg tempo workaround tbrl persistency

        // cmpParent = null;

        // end tempo workaround
       
        //if (cmpParent == null)
          //  cmpParent = GfrFrmAbs.s_getFrameOwner(1.s_getInstance());
      

            Object[] objsOption = {
               GfrResBundleLang.s_getInstance().getValue("word.ok"),
               "Bring secondary windows to front"};

            int intReply = JOptionPane.showOptionDialog(cmpParent, strBody, strTitleLong,
                JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE,
                null, objsOption, objsOption[0]);

            if (intReply == 1) // cancelButton or "X" on topRight
            {
                return true;
            }

            return false;
        }

    static public boolean s_showDialogDontShowAgain(
                    Component cmpParent,
                    String strTitleLong,
                    String strBody)
    {
        // TODO: fix up persistency problem:
        /*
         * java.io.NotSerializableException: javax.swing.plaf.basic.BasicOptionPaneUI$ButtonAreaLayout
        */

        // beg tempo workaround

        //cmpParent = null;
       
        //if (cmpParent == null)
            //cmpParent = GfrFrmAbs.s_getFrameOwner(PnlStatusBarMainGtr.s_getInstance());
       

        // end tempo workaround

            Object[] objsOption = {
               GfrResBundleLang.s_getInstance().getValue("word.ok"),
               "Don't show this again"};

            int intReply = JOptionPane.showOptionDialog(cmpParent, strBody, strTitleLong,
                JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE,
                null, objsOption, objsOption[0]);

            if (intReply == 1) // cancelButton or "X" on topRight
            {
                return true;
            }

            return false;
        }

    static public boolean s_showDialogConfirm(
                    Component cmpParent,
                    String strTitleLong,
                    String strBody)
    {
        // TODO: fix up persistency problem:
            /*
             * java.io.NotSerializableException: javax.swing.plaf.basic.BasicOptionPaneUI$ButtonAreaLayout
            */

        // beg tempo workaround

            //cmpParent = null;

        // end tempo workaround
       
        //if (cmpParent == null)
          //  cmpParent = GfrFrmAbs.s_getFrameOwner(PnlStatusBarMainGtr.s_getInstance());

        Object[] objsOption = {
           GfrResBundleLang.s_getInstance().getValue("word.ok"),
           GfrResBundleLang.s_getInstance().getValue("verb.cancel")};

        int intReply = JOptionPane.showOptionDialog(cmpParent, strBody, strTitleLong,
            JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE,
            null, objsOption, objsOption[0]);

        if (intReply==1 || intReply==-1) // cancelButton or "X" on topRight
        {
            return false;
        }

        if (intReply != 0)
        {
          // tbrl!
          return false;
        }

        return true;
    }


    static public void s_showDialogWarning(
                     Component cmpParent,
                     String strBody)
     {
        strBody = GfrUtlString.s_formatExceptionMessageForDialog(strBody);
       
        // TODO: fix up persistency problem:
            /*
             * java.io.NotSerializableException: javax.swing.plaf.basic.BasicOptionPaneUI$ButtonAreaLayout
            */

        // beg tempo workaround

        //cmpParent = null;

        // end tempo workaround
        
        //if (cmpParent == null)
          //  cmpParent = GfrFrmAbs.s_getFrameOwner(PnlStatusBarMainGtr.s_getInstance());

        String strTitleLong = System.getProperty(GfrEnuSystemPropertiesKeys.NAME_LONG_APPLI.getLabel());
        strTitleLong += " - " + GfrResBundleLang.s_getInstance().getValue("word.warning");

       
       
        JOptionPane.showMessageDialog(cmpParent,
                        strBody,
                        strTitleLong,
            JOptionPane.WARNING_MESSAGE);
     }


  static public void s_showDialogInfo(
                     Component cmpParent,
                     String strBody)
   {
       strBody = GfrUtlString.s_formatExceptionMessageForDialog(strBody);
     
      // TODO: fix up persistency problem:
         /*
            * java.io.NotSerializableException: javax.swing.plaf.basic.BasicOptionPaneUI$ButtonAreaLayout
         */

      // beg tempo workaround

      //cmpParent = null;

      // end tempo workaround

      //if (cmpParent == null)
         //  cmpParent = GfrFrmAbs.s_getFrameOwner(PnlStatusBarMainGtr.s_getInstance());

      String strTitleLong = System.getProperty(GfrEnuSystemPropertiesKeys.NAME_LONG_APPLI.getLabel());
      strTitleLong += " - " + "information";



      JOptionPane.showMessageDialog(cmpParent,
                     strBody,
                     strTitleLong,
         JOptionPane.INFORMATION_MESSAGE);
   }

static public void s_showDialogError(
                 Component cmpParent,
                 String strBody)
{
     // TODO: fix up persistency problem:
            /*
             * java.io.NotSerializableException: javax.swing.plaf.basic.BasicOptionPaneUI$ButtonAreaLayout
            */

        // beg tempo workaround

        //cmpParent = null;

        // end tempo workaround
    
     //if (cmpParent == null)
       //     cmpParent = GfrFrmAbs.s_getFrameOwner(PnlStatusBarMainGtr.s_getInstance());

        String strTitleAppli = System.getProperty(GfrEnuSystemPropertiesKeys.NAME_LONG_APPLI.getLabel());


        String strTitle = null;

        if (strTitleAppli == null) // should never appear
            strTitle = GfrResBundleLang.s_getInstance().getValue("word.error");
        else
            strTitle = strTitleAppli + " - " + GfrResBundleLang.s_getInstance().getValue("word.error");

        File fle = new File(FileHandlerLogger.s_getPathAbsFileLogJava());

        String strPathAbsLog = null;

        if (fle.exists())
        {

                if (fle.canRead())
                {
                        if (fle.length() > 0)
                                strPathAbsLog = fle.getAbsolutePath();
                }
        }

        Object[] objsOption = null;

        if (strPathAbsLog == null)
        {
            objsOption = new Object[1];
        }

        else
        {
            objsOption = new Object[2];
            objsOption[1] = "SHOW LOG";

            strBody += "\n\n";
            strBody += "Log file path:";
            strBody += "\n" + "  " + strPathAbsLog + "\n";
        }

        objsOption[0] = GfrResBundleLang.s_getInstance().getValue("verb.close");

         strBody = GfrUtlString.s_formatExceptionMessageForDialog(strBody);
       
        int intRetVal = JOptionPane.showOptionDialog(cmpParent, strBody, strTitle,
                JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE,
                null, objsOption, objsOption[0]);

        if (intRetVal == 1)
        {
            DlgViewSrcFileTxtSys dlg = new  DlgViewSrcFileTxtSys(cmpParent, strTitleAppli);

            if (! dlg.init())
            {
                // TBRL
                return;
            }

            Dimension dim = new Dimension(500, 400);
            dlg.setPreferredSize(dim);

            if (! dlg.show(fle))
            {
                // TBRL
                return;
            }
        }
    }

}
TOP

Related Classes of org.geoforge.guillc.optionpane.GfrOptionPaneAbs

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.