Package org.geoforge.guillc.wwd.util

Source Code of org.geoforge.guillc.wwd.util.OurToolTipControllerPopAbs

/*
Copyright (C) 2001, 2009 United States Government
as represented by the Administrator of the
National Aeronautics and Space Administration.
All Rights Reserved.
*/

package org.geoforge.guillc.wwd.util;

import gov.nasa.worldwind.WorldWindow;
import gov.nasa.worldwind.avlist.AVKey;
import gov.nasa.worldwind.avlist.AVList;
import gov.nasa.worldwind.event.SelectEvent;
import javax.swing.JOptionPane;
import org.geoforge.guillc.panel.GfrPnlStatusBarAbs;
import org.geoforge.lang.util.GfrResBundleLang;
import org.geoforge.worldwind.awt.annotation.GfrCtrAnnCntImgs;
import org.geoforge.worldwind.render.GfrKeysRnd;

/**
* Controls display of tool tips on picked objects. Any shape implementing {@link AVList} can participate. Shapes
* provide tool tip text in their AVList for either or both of hover and rollover events. The keys associated with the
* text are specified to the constructor.
*
* @author tag
* @version $Id: OurToolTipControllerMain.java 14187 2010-12-03 09:28:19Z tgaskins $
*
* modified by bantchao
*/
abstract public class OurToolTipControllerPopAbs extends OurToolTipControllerAbs
{
   static private String _STR_TIP_CONTEXTUAL_MENU_ = null;
   static private String _STR_TIP_IMAGES_ANNOTATION_ = null;
  
   static
   {
      try
      {
         _STR_TIP_CONTEXTUAL_MENU_ = GfrResBundleLang.s_getInstance().getValue("sentence.mouseRightClickToContextMenu");
         _STR_TIP_IMAGES_ANNOTATION_ = GfrResBundleLang.s_getInstance().getValue("sentence.doubleMouseLeftClickToDisplayImages");
      }
     
      catch(Exception exc)
      {
         exc.printStackTrace();
         String str = exc.getMessage();
         System.err.println(str);
         str += "\n Exiting";
         JOptionPane.showMessageDialog(null, str, GfrResBundleLang.s_getInstance().getValue("word.error"), JOptionPane.ERROR_MESSAGE);
         System.exit(1);
      }
   }
  
  
  
  
   private GfrPnlStatusBarAbs _pnlStatus_ = null;

   /**
    * Create a controller for a specified {@link WorldWindow} that displays tool tips on hover and/or rollover.
    *
    * @param wwd         the World Window to monitor.
    * @param rolloverKey the key to use when looking up tool tip text from the shape's AVList when a rollover event
    *                    occurs. May be null, in which case a tool tip is not displayed for rollover events.
    * @param hoverKey    the key to use when looking up tool tip text from the shape's AVList when a hover event
    *                    occurs. May be null, in which case a tool tip is not displayed for hover events.
    */
   protected OurToolTipControllerPopAbs(
           GfrPnlStatusBarAbs pnlStatus,
           WorldWindow wwd)
   {
      super(wwd);
     
      this._pnlStatus_ = pnlStatus;
   }


   @Override
   protected void _handleRollover_(SelectEvent evt) throws Exception
   {
      super._handleRollover_(evt);

      String strValue = _getRolloverText_(evt);
     
      if (strValue == null)
         return;

      Object objTop = evt.getTopObject();
      AVList lstTop = (AVList) objTop;

      Boolean booIsContextualMenu = (Boolean) lstTop.getValue(GfrKeysRnd.STR_HAS_CONTEXTUAL_MENU);
      String strImagesAnnotation = lstTop.getStringValue(AVKey.DATA_TYPE);

      boolean blnIsContextualMenu = false;
      boolean blnIsImagesAnnotation = false;

      if (booIsContextualMenu != null)
      {
         blnIsContextualMenu = booIsContextualMenu.booleanValue();
      }
     
      if (strImagesAnnotation != null)
      {
         if (strImagesAnnotation.compareTo(GfrCtrAnnCntImgs.IMAGES) == 0)
            blnIsImagesAnnotation = true;
      }
     
      if (!blnIsContextualMenu && !blnIsImagesAnnotation)
         return;

      this._showMessageStatusIfAny_(blnIsContextualMenu, blnIsImagesAnnotation);
   }

   @Override
   protected void _handleHover_(SelectEvent event) throws Exception
   {
      super._handleHover_(event);
     
      String strHoverText = _getHoverText(event);

      if (strHoverText == null)
         return;
     

      AVList lstTop = (AVList) event.getTopObject();
      Boolean booIsContextualMenu = (Boolean) lstTop.getValue(GfrKeysRnd.STR_HAS_CONTEXTUAL_MENU);
      String strImagesAnnotation = lstTop.getStringValue(AVKey.DATA_TYPE);

      boolean blnIsContextualMenu = false;
      boolean blnIsImagesAnnotation = false;

      if (booIsContextualMenu != null)
      {
         blnIsContextualMenu = booIsContextualMenu.booleanValue();
      }
     
      if (strImagesAnnotation != null)
      {
         if (strImagesAnnotation.compareTo(GfrCtrAnnCntImgs.IMAGES) == 0)
            blnIsImagesAnnotation = true;
      }
     
      if (!blnIsContextualMenu && !blnIsImagesAnnotation)
         return;
     

      this._showMessageStatusIfAny_(blnIsContextualMenu, blnIsImagesAnnotation);

   }

   private void _showMessageStatusIfAny_(
           boolean blnIsContextualMenu,
           boolean blnIsImagesAnnotation)
   {
      String str = "";
     
      if (blnIsImagesAnnotation)
      {
         str += _STR_TIP_IMAGES_ANNOTATION_;
        
         if (blnIsContextualMenu)
            str += " - ";
      }
     
      if (blnIsContextualMenu)
         str += _STR_TIP_CONTEXTUAL_MENU_;
     
      if (str!=null && str.length()>1)
         this._pnlStatus_.setMessage(str);
   }

   @Override
   protected void _hideToolTip_()
   {
      super._hideToolTip_();
     
      this._pnlStatus_.setMessage("");
   }

  
}
TOP

Related Classes of org.geoforge.guillc.wwd.util.OurToolTipControllerPopAbs

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.