/*
* 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.appogcecl.actioncontroller;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.logging.Logger;
import javax.swing.JInternalFrame;
import javax.swing.event.InternalFrameEvent;
import javax.swing.event.InternalFrameListener;
import org.geoforge.appogcecl.util.hashset.GfrHstFrmIntViewersPrsRun;
import org.geoforge.guillc.action.*;
import org.geoforge.guillc.dialog.GfrDlgCmdCancelOkConfirmAbs;
import org.geoforge.guillc.dialog.GfrDlgCmdCancelOkConfirmCloseWin;
import org.geoforge.guillc.dialog.GfrDlgCmdCancelOkConfirmSaveBeforeCloseWin;
import org.geoforge.guillc.internalframe.*;
import org.geoforge.guillc.menuitem.GfrMimAlrCloseSecFrmInt;
import org.geoforge.guillc.optionpane.GfrOptionPaneAbs;
import org.geoforge.java.util.logging.filehandler.FileHandlerLogger;
import org.geoforge.wrpbasprsdsp.viewer.GfrWrpDspSynViewer;
/**
*
* @author robert
*
* MEMO:
* . SerPlg & VolPlg both send internalFrameEvent
* . only SerPlg send ActionEvent
*/
public class AcrPlgIfrRun implements
InternalFrameListener,
ActionListener
{
// ----
// begin: instantiate logger for this class
final private static Logger _LOGGER_ = Logger.getLogger(AcrPlgIfrRun.class.getName());
static
{
AcrPlgIfrRun._LOGGER_.addHandler(FileHandlerLogger.s_getInstance());
}
// end: instantiate logger for this class
// ----
static private AcrPlgIfrRun _INSTANCE_ = null;
static public AcrPlgIfrRun getInstance()
{
if (AcrPlgIfrRun._INSTANCE_ == null)
AcrPlgIfrRun._INSTANCE_ = new AcrPlgIfrRun();
return AcrPlgIfrRun._INSTANCE_;
}
// ---
public void setEnabledActionsWindowsInternal(boolean bln)
{
GfrActDlgLloCloseAllWindowsInternal.s_getInstance().setEnabled(bln);
GfrActDlgLloTileWindowsInternal.s_getInstance().setEnabled(bln);
GfrActDlgLloTileHorizWindowsInternal.s_getInstance().setEnabled(bln);
GfrActDlgLloTileVertWindowsInternal.s_getInstance().setEnabled(bln);
GfrActDlgLloCascadeWindowsInternal.s_getInstance().setEnabled(bln);
}
@Override
public void actionPerformed(ActionEvent evtAction)
{
if (! (evtAction.getSource() instanceof GfrMimAlrCloseSecFrmInt))
{
String strError = "! (evtAction.getSource() instanceof GfrMimIcnCloseSecFrmInt), evtAction.getSource()=" + evtAction.getSource().getClass().toString();
AcrPlgIfrRun._LOGGER_.severe(strError);
GfrOptionPaneAbs.s_showDialogError(null, strError);
return;
}
// ---
GfrMimAlrCloseSecFrmInt mim = (GfrMimAlrCloseSecFrmInt) evtAction.getSource();
JInternalFrame ifrOwner = GfrIfrAbs.s_getInternalFrameOwner(mim);
if (ifrOwner == null)
{
String str = "ifrOwner == null";
AcrPlgIfrRun._LOGGER_.severe(str);
GfrOptionPaneAbs.s_showDialogError(null, str);
return;
}
if (ifrOwner instanceof GfrIfrWinViewRunIdRegSerSimplePlg)
{
try
{
_delete_((GfrIfrWinViewRunIdRegSerSimplePlg) ifrOwner);
}
catch(Exception exc)
{
exc.printStackTrace();
String str = exc.getMessage();
AcrPlgIfrRun._LOGGER_.severe(str);
GfrOptionPaneAbs.s_showDialogError(null, str);
}
return;
}
if (ifrOwner instanceof GfrIfrWinViewRunIdRegVolPlgAbs)
{
boolean blnCanSave = ((GfrIfrWinViewRunIdRegVolPlgAbs) ifrOwner).canSave();
if (blnCanSave)
{
if (this._confirmSaveBeforeCloseWindow_())
{
((GfrIfrWinViewRunIdRegVolPlgAbs) ifrOwner).doSave();
}
}
try
{
GfrWrpDspSynViewer.s_getInstance().delete(((GfrIfrWinViewRunIdAbs) ifrOwner).getUniqueId());
_delete_((GfrIfrWinViewRunAbs) ifrOwner);
}
catch(Exception exc)
{
exc.printStackTrace();
String str = exc.getMessage();
AcrPlgIfrRun._LOGGER_.severe(str);
GfrOptionPaneAbs.s_showDialogError(null, str);
}
return;
}
if (ifrOwner instanceof GfrIfrWinViewRunIdSpcPlgVolTloAbs) // not yet installed
{
boolean blnCanSave = ((GfrIfrWinViewRunIdSpcPlgVolTloAbs) ifrOwner).canSave();
if (blnCanSave)
{
if (this._confirmSaveBeforeCloseWindow_())
{
((GfrIfrWinViewRunIdSpcPlgVolTloAbs) ifrOwner).doSave();
}
}
try
{
GfrWrpDspSynViewer.s_getInstance().delete(((GfrIfrWinViewRunIdAbs) ifrOwner).getUniqueId());
_delete_((GfrIfrWinViewRunAbs) ifrOwner);
}
catch(Exception exc)
{
exc.printStackTrace();
String str = exc.getMessage();
AcrPlgIfrRun._LOGGER_.severe(str);
GfrOptionPaneAbs.s_showDialogError(null, str);
}
return;
}
if (ifrOwner instanceof GfrIfrWinViewRunIdRegSerPlgAbs)
{
try
{
GfrIfrWinViewRunIdRegSerAbs ifrSer = (GfrIfrWinViewRunIdRegSerAbs) ifrOwner;
ifrSer.releaseUnserializedObject();
ifrSer.deleteSerial(); // deleting recBounds, may be in try-catch !!!!!! created in line above !!!
GfrWrpDspSynViewer.s_getInstance().delete(ifrSer.getUniqueId());
_delete_((GfrIfrWinViewRunAbs) ifrOwner);
}
catch(Exception exc)
{
exc.printStackTrace();
String str = exc.getMessage();
AcrPlgIfrRun._LOGGER_.severe(str);
GfrOptionPaneAbs.s_showDialogError(null, str);
}
return;
}
String strError = "Uncaught, evtAction.getSource() instanceof GfrMimIcnCloseSecFrmInt";
AcrPlgIfrRun._LOGGER_.severe(strError);
GfrOptionPaneAbs.s_showDialogError(null, strError);
return;
}
@Override
public void internalFrameOpened(InternalFrameEvent e) {}
@Override
public void internalFrameClosed(InternalFrameEvent e) {}
@Override
public void internalFrameIconified(InternalFrameEvent e) {}
@Override
public void internalFrameDeiconified(InternalFrameEvent e) {}
@Override
public void internalFrameActivated(InternalFrameEvent e) {}
@Override
public void internalFrameDeactivated(InternalFrameEvent e) {}
@Override
public void internalFrameClosing(InternalFrameEvent evt)
{
Object objSource = evt.getSource();
try
{
/*
* Modified Amadeus => GfrIfrWinViewerSerPlg in GfrIfrWinViewerIdSerAbs
* !!! GfrIfrWinViewerIdSerAbs or GfrIfrWinViewerSerPlg?? => some Plugins Ifr derivate from
* GfrIfrWinViewerSerApp => uncaught exception.
*/
if (objSource instanceof GfrIfrWinViewRunIdRegSerAbs)
{
_delete_((GfrIfrWinViewRunAbs) objSource); // what about serialization ??????????????
return;
}
if (objSource instanceof GfrIfrWinViewRunSimplestVolPlg)
{
_delete_((GfrIfrWinViewRunAbs) objSource); // just doing stuff for GfrIfrWinViewerAbs
return;
}
if (objSource instanceof GfrIfrWinViewRunIdRegVolPlgAbs)
{
boolean blnCanSave = ((GfrIfrWinViewRunIdRegVolPlgAbs) objSource).canSave();
if (blnCanSave)
{
if (this._confirmSaveBeforeCloseWindow_())
{
((GfrIfrWinViewRunIdRegVolPlgAbs) objSource).doSave();
}
}
GfrWrpDspSynViewer.s_getInstance().delete(((GfrIfrWinViewRunIdAbs) objSource).getUniqueId());
_delete_((GfrIfrWinViewRunAbs) objSource);
return;
}
if (objSource instanceof GfrIfrWinViewRunIdSpcPlgVolTloAbs)
{
boolean blnCanSave = ((GfrIfrWinViewRunIdSpcPlgVolTloAbs) objSource).canSave();
if (blnCanSave)
{
if (this._confirmSaveBeforeCloseWindow_())
{
((GfrIfrWinViewRunIdSpcPlgVolTloAbs) objSource).doSave();
}
}
GfrWrpDspSynViewer.s_getInstance().delete(((GfrIfrWinViewRunIdAbs) objSource).getUniqueId());
_delete_((GfrIfrWinViewRunAbs) objSource);
return;
}
}
catch (Exception exc)
{
exc.printStackTrace();
String str = exc.getMessage();
AcrPlgIfrRun._LOGGER_.severe(str);
GfrOptionPaneAbs.s_showDialogError(null, str);
return;
}
String str = "uncaught action, evt.getSource().getClass().toString()=";
str += evt.getSource().getClass().toString();
AcrPlgIfrRun._LOGGER_.severe(str);
GfrOptionPaneAbs.s_showDialogError(null, str);
}
// ---
private AcrPlgIfrRun()
{
super();
}
private boolean _confirmSaveBeforeCloseWindow_()
{
GfrDlgCmdCancelOkConfirmAbs dlg = new GfrDlgCmdCancelOkConfirmSaveBeforeCloseWin();
dlg.init();
dlg.setVisible(true);
boolean blnCancelled = dlg.isCancelled();
dlg.destroy();
dlg = null;
if (blnCancelled)
return false;//Action cancelled by user
return true;
}
private boolean _confirmCloseWindow_()
{
GfrDlgCmdCancelOkConfirmAbs dlg = new GfrDlgCmdCancelOkConfirmCloseWin();
dlg.init();
dlg.setVisible(true);
boolean blnCancelled = dlg.isCancelled();
dlg.destroy();
dlg = null;
if (blnCancelled)
return false;//Action cancelled by user
return true;
}
private void _delete_(GfrIfrWinViewRunAbs ifr) throws Exception
{
ifr.removeInternalFrameListener(this);
if (! GfrHstFrmIntViewersPrsRun.s_getInstance().remove(ifr))
{
String str = "! GfrHstFrmIntViewersPrsRun.s_getInstance().remove(ifr)";
AcrPlgIfrRun._LOGGER_.severe(str);
throw new Exception(str);
}
if (ifr.isVisible())
ifr.setVisible(false);
ifr.destroy();
ifr.dispose(); // !!!!!!!!!!
ifr = null; // !!!!
if (GfrHstFrmIntViewersPrsRun.s_getInstance().size() < 1)
{
setEnabledActionsWindowsInternal(false);
// TODO: cascade
}
}
private void _delete_(GfrIfrWinViewRunIdRegSerSimplePlg ifr) throws Exception
{
ifr.releaseUnserializedObject();
ifr.deleteSerial(); // deleting recBounds, may be in try-catch !!!!!! created in line above !!!
GfrWrpDspSynViewer.s_getInstance().delete(ifr.getUniqueId());
_delete_((GfrIfrWinViewRunAbs) ifr);
}
// !!! redundant !!!
/*@Override
public void doneTaskNewViewerInternalFrame()
{
GfrActDlgLloCloseAllWindowsInternal.s_getInstance().setEnabled(true);
GfrActDlgLloTileWindowsInternal.s_getInstance().setEnabled(true);
GfrActDlgLloCascadeWindowsInternal.s_getInstance().setEnabled(true);
}*/
}