Package org.geoforge.guillc.menu

Source Code of org.geoforge.guillc.menu.GfrMenFleExitSpcAppPrtAbs

/*
*  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 2
*  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, write to the Free Software
*  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

package org.geoforge.guillc.menu;





import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import org.geoforge.guillc.menuitem.GfrMimAlrPrintFrame;
import org.geoforge.guillc.menuitem.GfrMimAbs;

/**
*
* @author bantchao
*
* email: bantchao_AT_gmail.com
* ... please remove "_AT_" from the above string to get the right email address
*
*
*/
abstract public class GfrMenFleExitSpcAppPrtAbs extends GfrMenFleExitSpcAppAbs implements
        ChangeListener
{
  
    protected GfrMimAbs _mimNew = null;
    protected GfrMimAbs _mimOpenFromList = null;
    protected GfrMimAbs _mimOpenFromHist = null;
    protected GfrMimAbs _mimOpenLast = null;
   
    private JMenu _menOpen_ = null;
    private GfrMimAbs _mimPrint_ = null; // memo: protected in order to get location in subclasses

    protected GfrMenFleExitSpcAppPrtAbs(String strSentenceOpen)
    {
        super();

        this._mimPrint_ = new GfrMimAlrPrintFrame();
        this._menOpen_ = new JMenu(strSentenceOpen);
        this._menOpen_.setEnabled(false);
    }
   
    /*
     * MEMO: at this step, contains
     *
     * . exitMenuItem
     *
     */
    @Override
    public boolean init()
    {
        if (! super.init())
            return false;

        if (! this._mimNew.init())
            return false;

        if (! this._mimOpenLast.init())
            return false;
       
        if (! this._mimOpenFromHist.init())
            return false;
       
        if (! this._mimOpenFromList.init())
            return false;
       
        if (!this._mimPrint_.init())
         return false;


        // ---
        int intId = 0;

        super.add(this._mimNew, intId++);
        super.add(this._menOpen_, intId++);
        super.insertSeparator(intId++);
        super.add(this._mimPrint_, intId++);
        super.insertSeparator(intId++);
       
        // beg sub-menu
        this._menOpen_.add(this._mimOpenLast);
        this._menOpen_.add(this._mimOpenFromHist);
        this._menOpen_.add(this._mimOpenFromList);
        this._mimOpenLast.addChangeListener((ChangeListener) this);
        this._mimOpenFromHist.addChangeListener((ChangeListener) this);
        this._mimOpenFromList.addChangeListener((ChangeListener) this);
        // end sub-menu

        return true;
    }


    @Override
    public void destroy()
    {
        super.destroy();
       
        if (this._mimPrint_ != null)
         {
            this._mimPrint_.destroy();
            this._mimPrint_ = null;
         }

        if (this._mimNew != null)
        {
            this._mimNew.destroy();
            this._mimNew = null;
        }
       
        if (this._mimOpenLast != null)
        {
            this._mimOpenLast.removeChangeListener(this);
            this._mimOpenLast.destroy();
            this._mimOpenLast = null;
        }
       
        if (this._mimOpenFromHist != null)
        {
            this._mimOpenFromHist.removeChangeListener(this);
            this._mimOpenFromHist.destroy();
            this._mimOpenFromHist = null;
        }

        if (this._mimOpenFromList != null)
        {
            this._mimOpenFromList.removeChangeListener(this);
            this._mimOpenFromList.destroy();
            this._mimOpenFromList = null;
        }
       
        this._menOpen_ = null;
    }

   @Override
   public void stateChanged(ChangeEvent e)
   {
      if (! (e.getSource() instanceof JMenuItem))
         return;
     
      if (this._mimOpenFromHist.isEnabled())
      {
         this._menOpen_.setEnabled(true);
         return;
      }
     
      if (this._mimOpenFromList.isEnabled())
      {
         this._menOpen_.setEnabled(true);
         return;
      }
     
      if (this._mimOpenLast.isEnabled())
      {
         this._menOpen_.setEnabled(true);
         return;
      }
     
      this._menOpen_.setEnabled(false);
   }
}
TOP

Related Classes of org.geoforge.guillc.menu.GfrMenFleExitSpcAppPrtAbs

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.