Package org.geoforge.guillc.panel

Source Code of org.geoforge.guillc.panel.GfrPnlKeyValueAbs

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

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.util.Set;
import java.util.logging.Logger;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import org.geoforge.guillc.label.GfrLbl;
import org.geoforge.lang.handler.IGfrHandlerLifeCycleObject;
import org.geoforge.java.util.logging.filehandler.FileHandlerLogger;

/**
*
* @author bantchao
*/
abstract public class GfrPnlKeyValueAbs extends PnlAbs
{
   // ----
   // begin: instantiate logger for this class

   final private static Logger _LOGGER_ = Logger.getLogger(GfrPnlKeyValueAbs.class.getName());

   static
   {
      GfrPnlKeyValueAbs._LOGGER_.addHandler(FileHandlerLogger.s_getInstance());
   }
   // end: instantiate logger for this class
   // ----
  
  
   /**
   tool used to align a vertical list of panelSelection
    *
    * !!! duplicated method
    **/
   public static boolean s_alignLabels(Set<GfrPnlKeyValueAbs> setPanels)
   {
       if (setPanels == null)
      {
         String str = "setPanels == null";
         GfrPnlKeyValueAbs._LOGGER_.severe(str);
         return false;
      }
      
       if (setPanels.size() < 2)
         return true;
      
       /** ----------------------------------
      equalizing the width of the labels
       **/
      int intMin = -1;
      int intPref = -1;
      int intMax = -1;

     
     
      for (GfrPnlKeyValueAbs pnlCur: setPanels)
      {
          JLabel lblCur = pnlCur.getLabel();

         int intMinCur = lblCur.getMinimumSize().width;

         if (intMinCur > intMin)
            intMin = intMinCur;

         int intMaxCur = lblCur.getMaximumSize().width;

         if (intMaxCur > intMax)
            intMax = intMaxCur;

         int intPrefCur = lblCur.getPreferredSize().width;

         if (intPrefCur > intPref)
            intPref = intPrefCur;
      }
     
      for (GfrPnlKeyValueAbs pnlCur: setPanels)
      {
          JLabel lblCur = pnlCur.getLabel();

         lblCur.setMinimumSize(new Dimension(intMin, lblCur.getMinimumSize().height));
         lblCur.setMaximumSize(new Dimension(intMax, lblCur.getMaximumSize().height));
         lblCur.setPreferredSize(new Dimension(intPref, lblCur.getPreferredSize().height));
      }
     
     
      // ending
      return true;
   }

   public JLabel getLabel()
   {
      return this._lbl_;
   }
   private GfrPnl _pnl_ = null;

   protected IGfrHandlerLifeCycleObject _objText = null;

   private GfrLbl _lbl_ = null;

   protected GfrPnlKeyValueAbs(String strKey)
   {
      super();

      this._pnl_ = new GfrPnl();
      this._pnl_.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 0));
      this._lbl_ = new GfrLbl(strKey);
   }

   @Override
   public boolean init()
   {
      if (!super.init())
         return false;

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

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

      this._lbl_.setHorizontalTextPosition(SwingConstants.RIGHT);
      this.setAlignmentX(LEFT_ALIGNMENT);


      this._pnl_.add(this._lbl_);
      this._pnl_.add((JComponent) this._objText);

      super.setLayout(new BorderLayout());
      super.add(this._pnl_, BorderLayout.CENTER);

      // ending
      return true;
   }
  
    @Override
   public void destroy()
   {
       if (this._pnl_ != null)
       {
           this._pnl_.destroy();
           this._pnl_ = null;
       }
      
       if (this._objText != null)
       {
           this._objText.destroy();
           this._objText = null;
       }
      
       if (this._lbl_ != null)
       {
           this._lbl_ = null;
       }
     
       super.destroy();
   }

   @Override
   public void loadTransient() throws Exception
   {
      //GfrPnlKeyValueAbs._LOGGER_.info("...");
   }

   @Override
   public void releaseTransient() throws Exception
   {
      //GfrPnlKeyValueAbs._LOGGER_.info("...");
   }
}
TOP

Related Classes of org.geoforge.guillc.panel.GfrPnlKeyValueAbs

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.