Package org.geoforge.guillc.panel

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

/*
*  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 3 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, see <http://www.gnu.org/licenses/>.
*/

package org.geoforge.guillc.panel;

import gov.nasa.worldwind.geom.Position;
import java.awt.Dimension;
import java.text.DecimalFormat;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.event.CaretEvent;
import javax.swing.event.CaretListener;
import org.geoforge.guillc.combobox.GfrCmb;
import org.geoforge.guillc.textfield.GfrTfd;
import org.geoforge.lang.util.number.GfrDouble;

/**
*
* @author Amadeus.Sowerby
*
* email: Amadeus.Sowerby_AT_gmail.com ... please remove "_AT_" from the above
* string to get the right email address
*/
public class GfrPnlGrpEditCrdXY extends GfrPnlGrpAbs implements CaretListener
{

   //--
   //-- beg static
   private final static int _INT_SEP_ = 5;
   //-- end static
   //--
   //
   //--
   //--beg private fields
   private GfrTfd _tfdChoiceX_;
   private GfrTfd _tfdChoiceY_;
   private GfrPnl _pnlContent_;
   //--end private fields
   //--

   //--
   //--beg public methods
  
   public GfrPnlGrpEditCrdXY(String strWhat, Position pos)
   {
      super(
              strWhat,
              GfrCmb.INT_HEIGHT);

      this._tfdChoiceX_ = new GfrTfd();
      this._tfdChoiceY_ = new GfrTfd();
      this._pnlContent_ = new GfrPnl();

      setValue(pos);
      this._tfdChoiceX_.setEditable(false);
      this._tfdChoiceY_.setEditable(false);
   }
  
   public GfrPnlGrpEditCrdXY(String strWhat)
   {
      super(
              strWhat,
              GfrCmb.INT_HEIGHT);

      this._tfdChoiceX_ = new GfrTfd();
      this._tfdChoiceY_ = new GfrTfd();
      this._pnlContent_ = new GfrPnl();


      this._tfdChoiceX_.addCaretListener((CaretListener) this);
      this._tfdChoiceY_.addCaretListener((CaretListener) this);

   }

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

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

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

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

      int intTfdWidth = (super.getWidthContent() - _INT_SEP_ - 10) / 2;
      int intTfdWidthRes = (super.getWidthContent() - _INT_SEP_ - 10) % 2;
     
      //System.out.println(super.getWidthContent());
      //System.out.println(intTfdWidth);

      int tfdHeight = 20;

      Dimension dim = new Dimension(intTfdWidth, tfdHeight);
      Dimension dimRes = new Dimension(intTfdWidth + intTfdWidthRes, tfdHeight);

      this._tfdChoiceX_.setMinimumSize(dim);
      this._tfdChoiceY_.setMinimumSize(dimRes);
      this._tfdChoiceX_.setMaximumSize(dim);
      this._tfdChoiceY_.setMaximumSize(dimRes);
      this._tfdChoiceX_.setPreferredSize(dim);
      this._tfdChoiceY_.setPreferredSize(dimRes);

      this._pnlContent_.setLayout(new BoxLayout(this._pnlContent_, BoxLayout.LINE_AXIS));
      this._pnlContent_.add(this._tfdChoiceX_);
      this._pnlContent_.add(Box.createRigidArea(new Dimension(_INT_SEP_, 0)));
      this._pnlContent_.add(this._tfdChoiceY_);

      super.add(this._pnlContent_);

      return true;
   }
  
   public void setValue(Position pos)
   {
      final DecimalFormat df = new DecimalFormat("#.####");
     
      String strLat = df.format(pos.latitude.degrees);
      String strLon = df.format(pos.longitude.degrees);
      this._tfdChoiceX_.setText(strLat);
      this._tfdChoiceY_.setText(strLon);
   }

           // !!! why use Double class !!!
   public Double getXValue()
   {
      String strVal = _tfdChoiceX_.getText();

      return GfrDouble.valueOf(strVal);
   }

   public Double getYValue()
   {
      String strVal = _tfdChoiceY_.getText();

      return GfrDouble.valueOf(strVal);
   }

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

   public boolean isEmptyXCoordinate()
   {
      String strVal = _tfdChoiceX_.getText();

      if (strVal == null || strVal.length() < 1)
         return true;

      return false;
   }

   public boolean isEmptyYCoordinate()
   {
      String strVal = _tfdChoiceY_.getText();

      if (strVal == null || strVal.length() < 1)
         return true;

      return false;
   }

   public boolean hasYCoordinateError()
   {
      return (!this.isEmptyYCoordinate() && (this.getYValue() == null));
   }

   public boolean hasXCoordinateError()
   {
      return (!this.isEmptyXCoordinate() && (this.getXValue() == null));
   }
}
TOP

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

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.