Package org.geoforge.guillc.panel

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

/*
*  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 javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.event.CaretEvent;
import javax.swing.event.CaretListener;
import javax.swing.event.DocumentListener;
import org.geoforge.guillc.textfield.GfrTfd;
import org.geoforge.guillc.textfield.GfrTfdAbs;

/**
*
* @author Amadeus.Sowerby
*
* email: Amadeus.Sowerby_AT_gmail.com
* ... please remove "_AT_" from the above string to get the right email address
*
* Should be refactored => remove "Sng"
*/
public class GfrPnlGrpTfdLbl extends GfrPnlGrpAbs
        implements CaretListener
{

   //-- beg static
   final static private int _CMP_HEIGHT_ = GfrTfdAbs.CMP_HEIGHT;
   //-- end static

   protected GfrTfd _tfdLeft; // !!! why "Left" !!! Q: located at right of label?

   protected GfrPnlLblHtml _pnlLblRight = null;// !!! why "Right" !!!

   protected GfrPnl _pnl = null;

   // added bantchao
   public String getValue()
   {
      String str = this._tfdLeft.getText();

      if (str == null)
         return null;

      return str.trim();
   }

   // addded bantchao
   public void setValue(String str)
   {
      if (this._tfdLeft != null)
         this._tfdLeft.setText(str);
   }

   @Override
   public void setEnabled(boolean bln)
   {
      super.setEnabled(bln);

      //--
      this._tfdLeft.setEnabled(bln);
   }

   public void setEditable(boolean bln)
   {

      //--
      this._tfdLeft.setEditable(bln);
   }

   //---
   private GfrPnlGrpTfdLbl(
           String strLabelWhat,
           String strTfdContent)
   {
      super(
              strLabelWhat,
              GfrPnlGrpTfdLbl._CMP_HEIGHT_);

      this._tfdLeft = new GfrTfd(strTfdContent);
      this._tfdLeft.addCaretListener((CaretListener) this);

      this._pnl = new GfrPnl();
   }

   public GfrPnlGrpTfdLbl(
           String strLabelWhat,
           String strTfdContent,
           String strRightWhat,
           int intWidthRight,
           String strToolTip)
   {
      this(
              strLabelWhat,
              strTfdContent,
              strRightWhat,
              intWidthRight);

      this.setTooltipTextToTexfield(strToolTip);
     
   }

   public GfrPnlGrpTfdLbl(
           String strLabelWhat,
           String strTfdContent,
           String strRightWhat,
           int intWidthRight)
   {
      this(
              strLabelWhat,
              strTfdContent);

      this._pnlLblRight = new GfrPnlLblHtml(
              strRightWhat,
              intWidthRight,
              GfrPnlGrpTfdLbl._CMP_HEIGHT_);

   }

   public GfrPnlGrpTfdLbl(
           String strLabelWhat,
           String strTfdContent,
           String strRightWhat,
           int intWidthRight,
           DocumentListener dlr)
   {
      this(
              strLabelWhat,
              strTfdContent,
              strRightWhat,
              intWidthRight);

      this._tfdLeft.getDocument().addDocumentListener(dlr);

   }

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

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

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

      if (this._pnlLblRight != null)
      {
         if (!this._pnlLblRight.init())
            return false;
      }


      this._pnl.setLayout(new BoxLayout(_pnl, BoxLayout.LINE_AXIS));

      this._pnl.add(this._tfdLeft);

      if (this._pnlLblRight != null)
      {
         this._pnl.add(Box.createRigidArea(new Dimension(5, 0)));
         this._pnl.add(this._pnlLblRight);
      }

      super.add(this._pnl);

      return true;
   }

   @Override
   public void destroy()
   {

      super.destroy();

      if (this._tfdLeft != null)
      {
         this._tfdLeft.destroy();
         this._tfdLeft = null;
      }
   }

   @Override
   public void caretUpdate(CaretEvent e)
   {
      super.firePanelUpdate();
   }

   final public void setTooltipTextToTexfield(String strToolTip)
   {
      if (strToolTip != null && strToolTip.length() > 0)
         this._tfdLeft.setToolTipText(strToolTip);

   }

}
TOP

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

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.