Package org.geoforge.java.awt.dialog

Source Code of org.geoforge.java.awt.dialog.GfrAwtDialogAbs

/*
*  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.java.awt.dialog;

import java.awt.Dialog;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.Label;
import java.awt.Panel;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.Window;
import org.geoforge.java.awt.event.windowadapter.GfrAwtWindowAdapter;

/**
*
* @author Amadeus.Sowerby
*
* email: Amadeus.Sowerby_AT_gmail.com
* ... please remove "_AT_" from the above string to get the right email address
*/
abstract public class GfrAwtDialogAbs extends Dialog
{

   private String _strText_ = null;

   protected Panel _pnlCommand = null;

   public GfrAwtDialogAbs(
         Frame owner,
         String title,
         boolean modal,
         String strText)
   {
      super(owner, title, modal);


      this._strText_ = strText;

      this._pnlCommand = new Panel();


      GfrAwtWindowAdapter adapterWindow = new GfrAwtWindowAdapter((Window) this);
      super.addWindowListener(adapterWindow);


      super.setLayout(new GridLayout(0, 1, 0, 0));

      String[] strs = this._strText_.split("\n");


      int intCountLine = 0;

      final int f_intMaxCountLine = 10;
      final int f_intSizeDisplayLine = 100;

      boolean blnTextFullyDisplayed = true;



      for (int i = 0; i < strs.length; i++)
      {
         if (!blnTextFullyDisplayed)
            break;


         strs[i] = strs[i].trim();

         if (strs[i].length() < f_intSizeDisplayLine)
         {
            Label lblMessage = new Label(strs[i]);

            if (intCountLine < f_intMaxCountLine)
            {
               super.add(lblMessage);
               intCountLine++;
            }
            else
            {
               blnTextFullyDisplayed = false;
               break;
            }
         }
         else
         {
            String strMessageRemaining = strs[i];

            while (strMessageRemaining.length() > 0)
            {
               if (!blnTextFullyDisplayed)
                  break;


               if (strMessageRemaining.length() > f_intSizeDisplayLine - 1)
               {
                  String strCur = strMessageRemaining.substring(0, f_intSizeDisplayLine - 1);

                  if (intCountLine < f_intMaxCountLine)
                  {
                     strCur = strCur.trim();
                     Label lblMessageCur = new Label(strCur);
                     super.add(lblMessageCur);
                     intCountLine++;
                     strMessageRemaining = strMessageRemaining.substring(f_intSizeDisplayLine - 1);
                     continue;
                  }
                  else
                  {
                     blnTextFullyDisplayed = false;
                     break;
                  }


               }
               else
               {

                  if (intCountLine < f_intMaxCountLine)
                  {
                     strMessageRemaining = strMessageRemaining.trim();
                     Label lblMessageCur = new Label(strMessageRemaining);
                     super.add(lblMessageCur);
                     intCountLine++;
                     strMessageRemaining = "";
                  }
                  else
                  {
                     blnTextFullyDisplayed = false;
                     break;
                  }
               }
            }

            if (!blnTextFullyDisplayed)
            {
               Label lblMessageCur = new Label("(...), Showing only " + f_intMaxCountLine + " lines.");
               super.add(lblMessageCur);
            }
         }


      }

      super.setIconImage(null);


      super.setMinimumSize(new Dimension(300, 10));

      int intLocationX = 0;
      int intLocationY = 0;

      Dimension dimThis = super.getSize();

      if (super.getOwner() != null)
      {
         // locate dialog to the center
         Dimension dimParent = super.getOwner().getSize();
         Point pl = super.getOwner().getLocation();

         intLocationX = pl.x + ((int) (dimParent.getWidth() - dimThis.getWidth())) / 2;
         intLocationY = pl.y + ((int) (dimParent.getHeight() - dimThis.getHeight())) / 2;


      }
      else
      {
         Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();

         intLocationX = (int) ((dimension.getWidth() - dimThis.getWidth()) / 2);
         intLocationY = (int) ((dimension.getHeight() - dimThis.getHeight()) / 2);
      }

      super.setLocation(
            intLocationX,
            intLocationY);



   }
}
TOP

Related Classes of org.geoforge.java.awt.dialog.GfrAwtDialogAbs

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.