/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.viz.hydrocommon;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IEditorPart;
import com.raytheon.uf.common.dataplugin.PluginDataObject;
import com.raytheon.uf.common.dataplugin.grid.GridConstants;
import com.raytheon.uf.common.dataplugin.grid.GridRecord;
import com.raytheon.uf.common.dataplugin.shef.tables.Colorvalue;
import com.raytheon.uf.common.dataquery.requests.RequestConstraint;
import com.raytheon.uf.common.datastorage.records.FloatDataRecord;
import com.raytheon.uf.common.datastorage.records.IDataRecord;
import com.raytheon.uf.common.mpe.util.XmrgFile;
import com.raytheon.uf.common.ohd.AppsDefaults;
import com.raytheon.uf.common.util.FileUtil;
import com.raytheon.uf.viz.core.IDisplayPane;
import com.raytheon.uf.viz.core.catalog.LayerProperty;
import com.raytheon.uf.viz.core.datastructure.DataCubeContainer;
import com.raytheon.uf.viz.core.datastructure.LoopProperties;
import com.raytheon.uf.viz.core.drawables.IDescriptor;
import com.raytheon.uf.viz.core.drawables.ResourcePair;
import com.raytheon.uf.viz.core.exception.VizException;
import com.raytheon.uf.viz.core.map.IMapDescriptor;
import com.raytheon.uf.viz.core.rsc.AbstractVizResource;
import com.raytheon.uf.viz.core.rsc.GenericResourceData;
import com.raytheon.uf.viz.core.rsc.LoadProperties;
import com.raytheon.uf.viz.core.rsc.ResourceList;
import com.raytheon.viz.hydrocommon.colorscalemgr.HydroColorManager;
import com.raytheon.viz.hydrocommon.colorscalemgr.NamedColorSetGroup;
import com.raytheon.viz.hydrocommon.constants.FFGConstants.ResolutionLevel;
import com.raytheon.viz.hydrocommon.data.ArealData;
import com.raytheon.viz.hydrocommon.data.DamMaster;
import com.raytheon.viz.hydrocommon.data.GageData;
import com.raytheon.viz.hydrocommon.events.StationSelectionChangeEvent;
import com.raytheon.viz.hydrocommon.listeners.StationSelectionChangeListener;
import com.raytheon.viz.hydrocommon.resource.ArealFfgResourceData;
import com.raytheon.viz.hydrocommon.resource.FFGGridResourceData;
import com.raytheon.viz.hydrocommon.resource.GriddedArealFFGResourceData;
import com.raytheon.viz.hydrocommon.resource.MPELegendResource;
import com.raytheon.viz.hydrocommon.resource.MeanArealPrecipResource;
import com.raytheon.viz.hydrocommon.resource.RFCGriddedBasinFFGResourceData;
import com.raytheon.viz.hydrocommon.resource.TimeLapseResource;
import com.raytheon.viz.hydrocommon.resource.XmrgResource;
import com.raytheon.viz.hydrocommon.resource.XmrgResourceData;
import com.raytheon.viz.hydrocommon.util.HydroDialogStatus;
import com.raytheon.viz.hydrocommon.util.MPEColors;
import com.raytheon.viz.hydrocommon.whfslib.colorthreshold.GetColorValues;
import com.raytheon.viz.hydrocommon.whfslib.colorthreshold.NamedColorUseSet;
import com.raytheon.viz.ui.EditorUtil;
import com.raytheon.viz.ui.editor.AbstractEditor;
/**
* This class manages the interaction between the Hydro Perspective and the
* Hydro dialogs.
*
*
* SOFTWARE HISTORY
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Oct 23, 2008 1644 mpduff Initial creation
*
*
* @author mpduff
* @version 1.0
*/
public class HydroDisplayManager {
/** Singleton instance of this class */
private static HydroDisplayManager displayManager = null;
/** MPE application name */
public static final String MPE_APPLICATION_NAME = "hmapmpe";
/** Hydro application name */
public static final String HYDRO_APPLICATION_NAME = "hydroview";
/** The currently selected lid */
private GageData currentdata = null;
/** Draw Station Flag */
private boolean drawStation = false;
/** Font size */
private int fontSize = 10;
/** List of dam data */
private List damList = null;
/** The currently displayed resource */
private AbstractVizResource, ?> displayedResource;
/**
* The previously displayed resource.
*/
private AbstractVizResource, ?> previousResource = null;
/** List of NamedColorUseSet objects */
private static final List pColorSetGroup = MPEColors
.build_mpe_colors();
/**
* Display the Dam Id flag
*/
private boolean displayDamId = false;
/**
* Display the Dam Name flag
*/
private boolean displayDamName = false;
/**
* Display the Dam Icon flag
*/
private boolean displayDamIcon = false;
private String cvUse = null;
/**
* The Accumulation interval for the xmrg data, Also the number of frames
* for the time lapse mode
*/
private int accumInterval;
/**
* Date of the xmrg data
*/
private Date dataDate = null;
/**
* The display type
*/
private String displayType = null;
/** The xmrg resource */
private XmrgResource bestEstRsc = null;
/** The xmrg resource for WFO FFG grids */
private final XmrgResource ffgRsc = null;
/** The Time Lapse resource */
private TimeLapseResource timeLapseRsc = null;
/** Accumulate mode flag */
private boolean accumulate = true;
/** Time lapse mode flag */
private boolean timeLapseMode = false;
/** Display pane */
private IDisplayPane pane = null;
/** The mean areal precipitation resource */
private MeanArealPrecipResource map = null;
/** Display id flag */
private boolean ids = false;
/** Display label flag */
private boolean labels = false;
private MPELegendResource mpeLegend = null;
/** Flag for data type changed */
private boolean dataChanged = true;
/** Flag for Colors changed when changed by the Color Scale Manager */
private boolean colorChanged = true;
/** Current Selection Listener list */
private final ArrayList currentSelectionListenerList = new ArrayList();
/**
* User Id.
*/
private String userId = null;
/**
* The color use name.
*/
private String useName = null;
/**
* The duration for the color set.
*/
private int duration;
/**
* The gage color list.
*/
private List gageColorSet = null;
private List ffgColorSet = null;
private ResolutionLevel ffgResolution;
/* Private Constructor */
private HydroDisplayManager() {
}
/**
* Get an instance of this singleton.
*
* @return Instance of this class
*/
public static synchronized HydroDisplayManager getInstance() {
if (displayManager == null) {
displayManager = new HydroDisplayManager();
}
return displayManager;
}
/**
* Get the currently selected lid. If no lid selected display error message
* pop up.
*
* @return the current lid or null if nothing selected
*/
public boolean isCurrentLidSelected(Shell shell) {
if (getCurrentLid() == null) {
MessageDialog.openError(shell, "Invalid Selection",
"You must select a site first");
return false;
}
return true;
}
/**
* Get the currently selected location id.
*
* @return String The LID
*/
public String getCurrentLid() {
if (currentdata != null) {
return currentdata.getLid();
} else {
return null;
}
}
public void displayGriddedFFG(Date date, int dur, String paramAbr,
String rfc, ResolutionLevel resolution) {
IEditorPart part = EditorUtil.getActiveEditor();
if (part instanceof AbstractEditor) {
AbstractEditor ae = ((AbstractEditor) part);
pane = ae.getActiveDisplayPane();
IMapDescriptor md = (IMapDescriptor) pane.getDescriptor();
this.ffgResolution = resolution;
this.duration = dur;
ResourceList rl = md.getResourceList();
Iterator iter = rl.iterator();
while (iter.hasNext()) {
ResourcePair pair = iter.next();
if ((pair.getResource() != null)
&& (pair.getResource().getName() == "FFG")) {
pair.getResource().dispose();
rl.removeRsc(pair.getResource());
break;
}
}
previousResource = getDisplayedResource();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
// Get the Grib data
Map reqMap = new HashMap();
reqMap.put(GridConstants.PLUGIN_NAME, new RequestConstraint(
GridConstants.GRID));
reqMap.put(GridConstants.PARAMETER_ABBREVIATION,
new RequestConstraint(paramAbr));
reqMap.put("dataTime.refTime",
new RequestConstraint(sdf.format(date)));
reqMap.put(GridConstants.DATASET_ID, new RequestConstraint("FFG-"
+ rfc));
try {
LayerProperty lp = new LayerProperty();
lp.setNumberOfImages(9999);
lp.setEntryQueryParameters(reqMap, false);
List