Package org.geoforge.guillc.internalframe

Source Code of org.geoforge.guillc.internalframe.GfrIfrWinViewRunIdRegSerAbs$FocusPropertyChangeListener

/*
*  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.internalframe;

import java.awt.*;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.logging.Logger;
import javax.swing.event.InternalFrameListener;
import org.geoforge.guillc.io.serial.GfrSerializeFrameSecViewerAbs;
import org.geoforge.io.handler.IGfrHandlerUnserializedObject;
import org.geoforge.java.util.logging.filehandler.FileHandlerLogger;
import sun.awt.AppContext;

/**
*
* @author bantchao
*
* email: bantchao_AT_gmail.comf
* ... please remove "_AT_" from the above string to get the right email address
*
*/

/*
* memo : Win means "Window"
*/
abstract public class GfrIfrWinViewRunIdRegSerAbs extends GfrIfrWinViewRunIdRegAbs implements
        IGfrHandlerUnserializedObject
{
   // ----
   // begin: instantiate logger for this class

   final static private Logger _LOGGER_ = Logger.getLogger(GfrIfrWinViewRunIdRegSerAbs.class.getName());

   static
   {
      GfrIfrWinViewRunIdRegSerAbs._LOGGER_.addHandler(FileHandlerLogger.s_getInstance());
   }

   // end: instantiate logger for this class
   // ----
  
  


   // called by unserialized final subclass
   abstract protected void _saveDisplay() throws Exception;

   protected GfrIfrWinViewRunIdRegSerAbs(
           int intWidthPref,
           int intHeightPref,
           InternalFrameListener ifrListenerController,
           String strUniqueId,
           String strUniqueName)
           throws Exception
   {
      super(intWidthPref, intHeightPref, ifrListenerController, strUniqueId, strUniqueName);

      GfrIfrWinViewRunIdRegSerAbs.addPropertyChangeListenerIfNecessary();
   }


   // memo: hidden source call
   private void readObject(ObjectInputStream ois)
           throws
           IOException,
           ClassNotFoundException
   {
      ois.defaultReadObject();
   }

   // memo: hidden source call
   private void writeObject(ObjectOutputStream oos) throws IOException
   {
      oos.defaultWriteObject();
   }

  

  

   @Override
   public void releaseUnserializedObject() throws Exception
   {
      this.releaseTransient();

      for (int i = 0; i < super.getComponentCount(); i++)
      {
         Component cmpCur = super.getComponent(i);

         if (cmpCur instanceof IGfrHandlerUnserializedObject)
         {
            IGfrHandlerUnserializedObject serCur = (IGfrHandlerUnserializedObject) cmpCur;
            serCur.releaseUnserializedObject();
         }
      }

      _saveBounds_();

      if (this._pnlContents != null)
         this._pnlContents.releaseUnserializedObject(); // OK
   }

   @Override
   public void loadUnserializedObject() throws Exception
   {
      this.loadTransient();

      for (int i = 0; i < super.getComponentCount(); i++)
      {
         Component cmpCur = super.getComponent(i);

         if (cmpCur instanceof IGfrHandlerUnserializedObject)
         {
            IGfrHandlerUnserializedObject serCur = (IGfrHandlerUnserializedObject) cmpCur;
            serCur.loadUnserializedObject();
         }
      }

      _setBoundsUnserialized_(); // !!!! if not found, just remain as is !!!!!!!!!!

      if (this._pnlContents != null)
         this._pnlContents.loadUnserializedObject()// OK
   }

  

   public void deleteSerial() throws Exception
   {
      GfrSerializeFrameSecViewerAbs.s_deleteBounds(
              (Object) this,
              super.getUniqueId());
   }

   private void _setBoundsUnserialized_()
   {
      try
      {
         Object objRectangle = GfrSerializeFrameSecViewerAbs.s_readBounds((Object) this, getUniqueId());

         if (objRectangle == null) // !!!
         {
            return;
         }

         if (!(objRectangle instanceof Rectangle))
         {
            GfrIfrWinViewRunIdRegSerAbs._LOGGER_.warning("! (objRectangle instanceof Rectangle)");
            return;
         }

         Rectangle recBounds = (Rectangle) objRectangle;
         super.setBounds(recBounds);
         super.setPreferredSize(new Dimension(recBounds.width, recBounds.height));

      }
      catch (Exception exc)
      {
         exc.printStackTrace();
         GfrIfrWinViewRunIdRegSerAbs._LOGGER_.warning(exc.getMessage());
      }
   }

 

   private void _saveBounds_()
   {
      // TODO
      //if (true) return;

      /*if (super.getState() == JFrame.ICONIFIED)
      {
      System.out.println("super.getState() == JFrame.ICONIFIED");
      return;
      }*/

      Rectangle recBounds = super.getBounds();

      if (recBounds == null)
         return;

      try
      {
         GfrSerializeFrameSecViewerAbs.writeBounds(
                 (Object) this,
                 getUniqueId(),
                 recBounds);
      }
      catch (Exception exc)
      {
         exc.printStackTrace();
      }
   }

   // beg bug-fix serial
   /*
    *
    * TBRL:
    * java.io.NotSerializableException: com.sun.opengl.impl.windows.WindowsOnscreenGLContext
    *
    * - field (class "javax.media.opengl.GLCanvas", name: "context", type: "class javax.media.opengl.GLContext")
   - object (class "org.geoforge.worldwind.awt.GfrWorldWindowGLCanvas", org.geoforge.worldwind.awt.GfrWorldWindowGLCanvas[canvas0,0,0,475x310,invalid,hidden])
   - field (class "javax.swing.JInternalFrame", name: "lastFocusOwner", type: "class java.awt.Component")
   - custom writeObject data (class "javax.swing.JInternalFrame")
   - root object (class "org.geoforge.guillcogceclgtc.internalframe.GfrIfrWinViewerTopsWwdEarthOgcEclGtc", org.geoforge.guillcogceclgtc.internalframe.GfrIfrWinViewerTopsWwdEarthOgcEclGtc[,0,0,511x407,invalid,layout=javax.swing.plaf.basic.BasicInternalFrameUI$Handler,alignmentX=0.0,alignmentY=0.0,border=javax.swing.plaf.metal.MetalBorders$InternalFrameBorder@376e523d,flags=264,maximumSize=,minimumSize=,preferredSize=java.awt.Dimension[width=400,height=300],closable=true,defaultCloseOperation=DO_NOTHING_ON_CLOSE,desktopIcon=javax.swing.JInternalFrame$JDesktopIcon[,0,0,160x31,invalid,layout=java.awt.BorderLayout,alignmentX=0.0,alignmentY=0.0,border=javax.swing.plaf.BorderUIResource$CompoundBorderUIResource@58070f11,flags=8,maximumSize=,minimumSize=,preferredSize=],frameIcon=file:/D:/robert/dev/geoforge/bck84/gfr/GfrIo/target/classes/res/images/internal/gfr/png/viewer_globe_16.png,iconable=true,isClosed=false,isIcon=false,isMaximum=false,isSelected=true,maximizable=true,opened=true,resizable=true,rootPane=javax.swing.JRootPane[,5,28,501x374,invalid,layout=javax.swing.JRootPane$RootLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=449,maximumSize=,minimumSize=,preferredSize=],rootPaneCheckingEnabled=true,title=Earth #1])
  
    */
   private static final Object PROPERTY_CHANGE_LISTENER_KEY = new Object(); // InternalFramePropertyChangeListener

   private static void addPropertyChangeListenerIfNecessary()
   {
      if (AppContext.getAppContext().get(PROPERTY_CHANGE_LISTENER_KEY)
              == null)
      {
         PropertyChangeListener focusListener =
                 new GfrIfrWinViewRunIdRegSerAbs.FocusPropertyChangeListener();

         AppContext.getAppContext().put(PROPERTY_CHANGE_LISTENER_KEY,
                 focusListener);

         KeyboardFocusManager.getCurrentKeyboardFocusManager().
                 addPropertyChangeListener(focusListener);
      }
   }

   private static class FocusPropertyChangeListener implements
           PropertyChangeListener
   {

      @Override
      public void propertyChange(PropertyChangeEvent e)
      {
         if (e.getPropertyName().compareToIgnoreCase("lastFocusOwner") == 0)
         {
            Object obj = e.getNewValue();

            if (obj instanceof org.geoforge.awt.java2d.MySurfaceAbs)
            {
               _invokeLaterFixUpBug_();
               return;
            }
         }

         if (e.getPropertyName().compareToIgnoreCase("permanentFocusOwner") == 0)
         {
            //GfrIfrAbs._LOGGER_.info("permanentFocusOwner: " + e.getNewValue());

            Object obj = e.getNewValue();

            if (obj instanceof org.geoforge.worldwind.awt.GfrWorldWindowGLCanvas)
            {
               // !!! big troubles out there !!!
               //GfrIfrAbs._LOGGER_.info("obj org.geoforge.worldwind.awt.GfrWorldWindowGLCanvas");
               _invokeLaterFixUpBug_();
               return;
            }

            if (obj instanceof java.awt.event.ActionListener)
            {
               // !!! big troubles out there !!!
               //GfrIfrAbs._LOGGER_.info("obj instanceof java.awt.event.ActionListener, obj.toString()" + obj.toString());
               //_invokeLaterFixUpBug_();
               return;
            }

            //
         }
      }

   }

   static private void _invokeLaterFixUpBug_()
   {
      javax.swing.SwingUtilities.invokeLater(new Runnable()
      {

         @Override
         public void run()
         {
            //GfrIfrAbs._LOGGER_.info("...");
            KeyboardFocusManager.getCurrentKeyboardFocusManager().upFocusCycle();
         }

      });
   }

   // end bug-fix serial
}
TOP

Related Classes of org.geoforge.guillc.internalframe.GfrIfrWinViewRunIdRegSerAbs$FocusPropertyChangeListener

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.