Package org.geoforge.guillc.popupmenu

Source Code of org.geoforge.guillc.popupmenu.GfrPmuCtlCtrFolderAbs

/*
*  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.popupmenu;

import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Enumeration;
import java.util.logging.Logger;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import javax.swing.tree.TreePath;
import org.geoforge.guillc.menuitem.GfrMimFolderAllAbs;
import org.geoforge.guillc.menuitem.GfrMimFolderAllCollapse;
import org.geoforge.guillc.menuitem.GfrMimFolderAllExpand;
import org.geoforge.guillc.optionpane.GfrOptionPaneAbs;
import org.geoforge.guillc.tree.GfrTreAbs;
import org.geoforge.guillc.treenode.GfrNodAbs;
import org.geoforge.java.util.logging.filehandler.FileHandlerLogger;

/**
*
* @author bantchao
*/
abstract public class GfrPmuCtlCtrFolderAbs extends GfrPmuCtlCtrAbs implements
        ActionListener
{
   // ----
   // begin: instantiate logger for this class

   final private static Logger _LOGGER_ = Logger.getLogger(GfrPmuCtlCtrFolderAbs.class.getName());
  
   static
   {
      GfrPmuCtlCtrFolderAbs._LOGGER_.addHandler(FileHandlerLogger.s_getInstance());
   }
   // end: instantiate logger for this class
   // ----
   transient private GfrMimFolderAllAbs _mimFolderAllExpand_ = null;
   transient protected GfrMimFolderAllAbs _mimFolderAllCollapse = null;
 
  
   protected GfrPmuCtlCtrFolderAbs(GfrTreAbs tree)
   {
      super(tree);
     
      this._mimFolderAllExpand_ = new GfrMimFolderAllExpand();
      this._mimFolderAllCollapse = new GfrMimFolderAllCollapse();
   }
  
   @Override
   public void show(Component invoker, int x, int y)
   {
      try
      {
         boolean blnEnableCollapse = super._tre.isAllowedFolderAllCollapse((GfrNodAbs) super._nod);
         this._mimFolderAllCollapse.setEnabled(blnEnableCollapse);        
        
         boolean blnEnableExpand = super._tre.isAllowedFolderAllExpand((GfrNodAbs) super._nod);
         this._mimFolderAllExpand_.setEnabled(blnEnableExpand);        
        
         super.show(invoker, x, y);
        
      }
      catch (Exception e)
      {
         GfrPmuCtlCtrFolderAbs._LOGGER_.info("exc caught, don't care");
      }
   }
  
   @Override
   public void actionPerformed(ActionEvent e)  
   {
      if (!(e.getSource() instanceof JMenuItem))
      {
         String str = "! (e.getSource() instanceof JMenuItem), :" + e.getSource().getClass().toString();
         GfrPmuCtlCtrFolderAbs._LOGGER_.severe(str);
         GfrOptionPaneAbs.s_showDialogError(null, str);
         return;
      }
     
      JMenuItem mimSource = (JMenuItem) e.getSource();
     
     
      if (mimSource instanceof GfrMimFolderAllExpand)
      {
         this._folderAllExpand_();
         return;
      }
     
      if (mimSource instanceof GfrMimFolderAllCollapse)
      {
         this._folderAllCollapse_();
         return;
      }
     
      String str = "uncaught menuItem, :" + mimSource.getText();
      GfrPmuCtlCtrFolderAbs._LOGGER_.severe(str);
      GfrOptionPaneAbs.s_showDialogError(null, str);
   }
  
  
  
   @Override
   public boolean init()
   {
      if (!super.init())
         return false;
     
      if (!this._mimFolderAllExpand_.init())
         return false;
     
      if (!this._mimFolderAllCollapse.init())
         return false;
     
      int intPos = 0; //
     
      super.add(this._mimFolderAllExpand_, intPos++);
      super.add(this._mimFolderAllCollapse, intPos++);
      JPopupMenu.Separator sep = new JPopupMenu.Separator();
      super.add(sep, intPos++); //choice: adding a separator, even if no additional stuff

      return true;
   }
  
   @Override
   public void destroy()  
   {
      super.destroy();
     
      if (this._mimFolderAllExpand_ != null)
      {
         this._mimFolderAllExpand_.destroy();
         this._mimFolderAllExpand_ = null;
      }
     
      if (this._mimFolderAllCollapse != null)
      {
         this._mimFolderAllCollapse.destroy();
         this._mimFolderAllCollapse = null;
      }
   }

   @Override
   public void loadTransient() throws Exception
   {
      super.loadTransient();
     
      this._mimFolderAllExpand_.loadTransient();
      this._mimFolderAllCollapse.loadTransient();
     
      this._mimFolderAllExpand_.addActionListener(this);
      this._mimFolderAllCollapse.addActionListener(this);
   }
  
   @Override
   public void releaseTransient() throws Exception
   {
      super.releaseTransient();
     
      this._mimFolderAllExpand_.removeActionListener(this);
      this._mimFolderAllCollapse.removeActionListener(this);
     
      this._mimFolderAllExpand_.releaseTransient();
      this._mimFolderAllCollapse.releaseTransient();
   }

   // beg private
   private void _folderAllExpand_()
   {     
      if (super._nod == null)
      {
         String str = "super._nod == null";
         GfrPmuCtlCtrFolderAbs._LOGGER_.severe(str);
         GfrOptionPaneAbs.s_showDialogError(null, str);
         return;
      }
     
      for (Enumeration e = super._nod.depthFirstEnumeration(); e.hasMoreElements();)
      {        
         GfrNodAbs tsaCur = (GfrNodAbs) e.nextElement();

         //if (tsaCur.isFolderNotLoaded())
         //  continue;

         TreePath tphCur = new TreePath(tsaCur.getPath());        
         super._tre.expandPath(tphCur);
      }
   }
  
   private void _folderAllCollapse_()
   {
      if (super._nod == null)
      {
         String str = "this._nod == null";
         GfrPmuCtlCtrFolderAbs._LOGGER_.severe(str);
         GfrOptionPaneAbs.s_showDialogError(null, str);
         return;
      }
     
      for (Enumeration e = super._nod.depthFirstEnumeration(); e.hasMoreElements();)
      {        
         GfrNodAbs tsaCur = (GfrNodAbs) e.nextElement();        
         TreePath tphCur = new TreePath(tsaCur.getPath());        
         super._tre.collapsePath(tphCur);
      }
   }
   // end private
}
TOP

Related Classes of org.geoforge.guillc.popupmenu.GfrPmuCtlCtrFolderAbs

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.