Package org.geoforge.guillc.panel

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

/*
*  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.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Set;
import java.util.logging.Logger;
import javax.swing.JLabel;
import org.geoforge.guillc.handler.IGfrHandlerTaskTabDialog;
import org.geoforge.guillc.handler.IGfrHandlerValueChanged;
import org.geoforge.guillc.button.BtnReset;
import org.geoforge.guillc.checkbox.CbxSettingsApplyAll;
import org.geoforge.guillc.optionpane.GfrOptionPaneAbs;
import org.geoforge.java.util.logging.filehandler.FileHandlerLogger;

/**
*
* @author bantchao
*/
abstract public class PnlDspRowAbs extends PnlAbs implements
        IGfrHandlerValueChanged,
        IGfrHandlerTaskTabDialog,
        ActionListener // resetValue and other
{
    // ----
    // begin: instantiate logger for this class
    final static private Logger _LOGGER_ = Logger.getLogger(PnlDspRowAbs.class.getName());

    static
    {
        PnlDspRowAbs._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<PnlDspRowAbs> setPanels,
           double dblRatioWidthChoiceLabel)
   {
      if (setPanels == null)
      {
         String str = "setPanels == null";
         PnlDspRowAbs._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 (PnlDspRowAbs 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 (PnlDspRowAbs 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));
        
         /*
          * assign "choice's width" to be "intRatioWidthChoiceLabel" times larger than "label'width"
          */
   
         int widthMin = (int)(dblRatioWidthChoiceLabel*(double)intMin);
         int widthMax = (int)(dblRatioWidthChoiceLabel*(double)intMax);
         int widthPref = (int)(dblRatioWidthChoiceLabel*(double)intPref);
        
         PnlChoiceAbs pnlChoiceCur = pnlCur.getPanelChoice();
         pnlChoiceCur.setMinimumSize(new Dimension(widthMin, pnlChoiceCur.getMinimumSize().height));
         pnlChoiceCur.setMaximumSize(new Dimension(widthMax, pnlChoiceCur.getMaximumSize().height));
         pnlChoiceCur.setPreferredSize(new Dimension(widthPref, pnlChoiceCur.getPreferredSize().height));
      }

      // ----


      // ending
      return true;
   }
  
  
  
  
   protected PnlDspLabel _pnlLabel = null;
   protected PnlChoiceAbs _pnlChoice = null;
   protected BtnReset _btnReset =null;
  
   private CbxSettingsApplyAll _cbxApplyAll_ = null;
  
   // beg getter-setter
  
   public JLabel getLabel() { return this._pnlLabel.getLabel(); }
   public PnlChoiceAbs getPanelChoice() { return this._pnlChoice; }
  
   public boolean isApplyToAll() { return this._cbxApplyAll_.isSelected(); }
  
   // end getter-setter
  
  
   protected PnlDspRowAbs()
   {
      super();
     
      this._btnReset = new BtnReset((ActionListener) this);
      this._cbxApplyAll_ = new CbxSettingsApplyAll();
     
      super.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 0));
   }
  
   @Override
    public boolean hasChangedValue()
    {
       if (this._pnlChoice.hasChangedValue())
          return true;
      
      
       return false;
    }
  
   @Override
   public void doTaskTabDialog() throws Exception
   {
      this._pnlChoice.doTaskTabDialog();
     
      if (this._btnReset.isEnabled())
         this._btnReset.setEnabled(false);
   }
  
   @Override
   public void actionPerformed(ActionEvent e)
   {
      if (e.getSource() instanceof BtnReset)
      {
         this._pnlChoice.resetValue();
        
         return;
      }
    
      PnlDspRowAbs._LOGGER_.severe("Uncaught instance: " + e.getSource().getClass().toString());
      GfrOptionPaneAbs.s_showDialogError(null, "Uncaught instance: " + e.getSource().getClass().toString());
      System.exit(1);
   }
  
   @Override
   public boolean init()
   {
      if (! super.init())
         return false;
     
      if (! _pnlLabel.init())
         return  false;
     
      if (! _pnlChoice.init())
         return  false;
     
      if (! _btnReset.init())
         return  false;
     
      if (! _cbxApplyAll_.init())
         return  false;
     
      super.add(this._pnlLabel);
      super.add(this._pnlChoice);
      super.add(this._btnReset);
      super.add(this._cbxApplyAll_);
     
      return true;
   }
  
   @Override
   public void destroy()
   {
     
      super.destroy();
     
      if (this._pnlLabel != null)
      {
         this._pnlLabel.destroy();
         this._pnlLabel = null;
      }
     
      if (this._pnlChoice != null)
      {
         this._pnlChoice.destroy();
         this._pnlChoice = null;
      }
     
      if (this._btnReset != null)
      {
         this._btnReset.destroy();
         this._btnReset = null;
      }
     
      if (this._cbxApplyAll_ != null)
      {
         this._cbxApplyAll_.destroy();
         this._cbxApplyAll_ = null;
      }
     
   }
  
   @Override
   public void loadTransient() throws Exception
   {
   }

   @Override
   public void releaseTransient() throws Exception
   {
   }
}
TOP

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

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.