diff --git a/cave/com.raytheon.uf.viz.hpe/src/com/raytheon/uf/viz/hpe/rsc/HpeLabelResource.java b/cave/com.raytheon.uf.viz.hpe/src/com/raytheon/uf/viz/hpe/rsc/HpeLabelResource.java index 97793709d6..501e7eed14 100644 --- a/cave/com.raytheon.uf.viz.hpe/src/com/raytheon/uf/viz/hpe/rsc/HpeLabelResource.java +++ b/cave/com.raytheon.uf.viz.hpe/src/com/raytheon/uf/viz/hpe/rsc/HpeLabelResource.java @@ -22,8 +22,11 @@ package com.raytheon.uf.viz.hpe.rsc; import java.util.Collections; import java.util.Date; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; @@ -32,6 +35,7 @@ import org.eclipse.core.runtime.jobs.Job; import org.eclipse.swt.graphics.RGB; import com.raytheon.uf.common.dataplugin.grid.GridRecord; +import com.raytheon.uf.common.plugin.hpe.data.HpeLabelKey; import com.raytheon.uf.common.plugin.hpe.request.HpeLabelDataRequest; import com.raytheon.uf.common.plugin.hpe.request.HpeLabelDataResponse; import com.raytheon.uf.common.status.IUFStatusHandler; @@ -66,6 +70,7 @@ import com.raytheon.viz.grid.rsc.general.D2DGridResource; * ------------ ---------- ----------- -------------------------- * May 5, 2014 3026 mpduff Initial creation * Dec 16, 2014 3026 mpduff Change location of text + * Feb 13, 2015 4121 mpduff Change label caching. * * * @@ -80,8 +85,8 @@ public class HpeLabelResource extends private final IUFStatusHandler logger = UFStatus .getHandler(HpeLabelResource.class); - private final Map hpeTextCache = Collections - .synchronizedMap(new HashMap()); + private final Map hpeTextCache = Collections + .synchronizedMap(new HashMap()); private DrawableString drawableString = null; @@ -98,7 +103,16 @@ public class HpeLabelResource extends public void resourceChanged(ChangeType type, Object object) { if (type == ChangeType.DATA_REMOVE) { if (object instanceof DataTime) { - hpeTextCache.remove(((DataTime) object).getRefTime()); + Set> entrySet = hpeTextCache + .entrySet(); + Iterator> iter = entrySet.iterator(); + while (iter.hasNext()) { + Entry entry = iter.next(); + HpeLabelKey key = entry.getKey(); + if (key.getDate().equals(((DataTime) object).getRefTime())) { + iter.remove(); + } + } } } } @@ -163,7 +177,8 @@ public class HpeLabelResource extends } private String getText(Date date, String productId) { - String text = hpeTextCache.get(date); + HpeLabelKey key = new HpeLabelKey(productId, date); + String text = hpeTextCache.get(key); if (text == null) { dataJob.scheduleRetrieval(date, productId); } @@ -214,7 +229,8 @@ public class HpeLabelResource extends .sendRequest(req); Map data = response.getData(); for (Date d : data.keySet()) { - hpeTextCache.put(d, data.get(d)); + HpeLabelKey key = new HpeLabelKey(productId, d); + hpeTextCache.put(key, data.get(d)); } } catch (VizException e) { statusHandler.error(e.getLocalizedMessage(), e); @@ -223,4 +239,4 @@ public class HpeLabelResource extends return Status.OK_STATUS; } } -} +} \ No newline at end of file diff --git a/cave/com.raytheon.uf.viz.monitor.ffmp/src/com/raytheon/uf/viz/monitor/ffmp/ui/rsc/FFMPResource.java b/cave/com.raytheon.uf.viz.monitor.ffmp/src/com/raytheon/uf/viz/monitor/ffmp/ui/rsc/FFMPResource.java index 70e3c8620e..72fc7e34c6 100644 --- a/cave/com.raytheon.uf.viz.monitor.ffmp/src/com/raytheon/uf/viz/monitor/ffmp/ui/rsc/FFMPResource.java +++ b/cave/com.raytheon.uf.viz.monitor.ffmp/src/com/raytheon/uf/viz/monitor/ffmp/ui/rsc/FFMPResource.java @@ -81,6 +81,7 @@ import com.raytheon.uf.common.monitor.config.FFMPSourceConfigurationManager; import com.raytheon.uf.common.monitor.xml.DomainXML; import com.raytheon.uf.common.monitor.xml.ProductXML; import com.raytheon.uf.common.monitor.xml.SourceXML; +import com.raytheon.uf.common.plugin.hpe.data.HpeLabelKey; import com.raytheon.uf.common.plugin.hpe.request.HpeLabelDataRequest; import com.raytheon.uf.common.plugin.hpe.request.HpeLabelDataResponse; import com.raytheon.uf.common.status.IPerformanceStatusHandler; @@ -91,7 +92,6 @@ import com.raytheon.uf.common.status.UFStatus.Priority; import com.raytheon.uf.common.time.DataTime; import com.raytheon.uf.common.time.util.ITimer; import com.raytheon.uf.common.time.util.TimeUtil; -import com.raytheon.uf.common.util.StringUtil; import com.raytheon.uf.viz.core.DrawableLine; import com.raytheon.uf.viz.core.DrawableString; import com.raytheon.uf.viz.core.IDisplayPaneContainer; @@ -198,7 +198,8 @@ import com.vividsolutions.jts.geom.Point; * assignments. * Sep 23, 2014 3009 njensen Overrode recycleInternal() * Nov 10, 2014 3026 dhladky HPE BIAS displays. - * Dec 16, 2014 3026 mpduff Change location of text + * Dec 16, 2014 3026 mpduff Change location of text. + * Feb 13, 2015 4121 mpduff Change label caching. * * * @author dhladky @@ -268,6 +269,9 @@ public class FFMPResource extends /** HPE Constant */ private static final String HPE = "HPE"; + /** BiasHPE Constant */ + private static final String BHPE = "BHPE"; + /** the stream cross hatched area **/ private IWireframeShape streamOutlineShape = null; @@ -424,6 +428,8 @@ public class FFMPResource extends private DrawableString basinLocatorString = null; + private DrawableString hpeLabelString = null; + private RGB basinTraceColor = null; private RGB basinBoundaryColor = null; @@ -440,8 +446,12 @@ public class FFMPResource extends private boolean restoreTable = false; /** HPE bias source legend cache */ - private final Map hpeLegendMap = Collections - .synchronizedMap(new HashMap()); + private final Map hpeLegendMap = Collections + .synchronizedMap(new HashMap()); + + /** Lookup of Date to product ids displaying for that date */ + private final Map> hpeCacheLookup = Collections + .synchronizedMap(new HashMap>()); /** Flag denoting data as HPE */ private boolean isHpe; @@ -538,11 +548,30 @@ public class FFMPResource extends PluginDataObject[] pdos = (PluginDataObject[]) object; for (PluginDataObject pdo : pdos) { FFMPRecord ffmpRec = (FFMPRecord) pdo; - hpeLegendMap.remove(ffmpRec.getDataTime().getRefTime()); + Date date = ffmpRec.getDataTime().getRefTime(); + removeHpeLabels(date); } } else if (object instanceof DataTime) { DataTime dt = (DataTime) object; - hpeLegendMap.remove(dt.getRefTime()); + removeHpeLabels(dt.getRefTime()); + } + } + } + + /** + * Remove the labels in the cache for the given time and product. + * + * @param date + * The time to remove + * @param productId + * The product to remove + */ + private void removeHpeLabels(Date date) { + List products = hpeCacheLookup.remove(date); + if (products != null) { + for (String product : products) { + HpeLabelKey key = new HpeLabelKey(product, date); + hpeLegendMap.remove(key); } } } @@ -1253,12 +1282,19 @@ public class FFMPResource extends basinLocatorString.horizontalAlignment = HorizontalAlignment.CENTER; basinLocatorString.verticallAlignment = VerticalAlignment.MIDDLE; basinLocatorString.addTextStyle(TextStyle.BLANKED); + + hpeLabelString = new DrawableString("", getCapability( + ColorableCapability.class).getColor()); + hpeLabelString.font = font; + hpeLabelString.horizontalAlignment = HorizontalAlignment.CENTER; + hpeLabelString.verticallAlignment = VerticalAlignment.TOP; + } }); // Set flag for HPE data - isHpe = resourceData.siteKey.equalsIgnoreCase(HPE) - || resourceData.siteKey.equalsIgnoreCase("BHPE"); + isHpe = resourceData.dataKey.equalsIgnoreCase(HPE) + || resourceData.dataKey.equalsIgnoreCase(BHPE); } /** @@ -1479,6 +1515,24 @@ public class FFMPResource extends paintUpAndDownStream(aTarget, paintProps); } + // draw hpe strings if HPE + if (isHpe) { + // Paint the HPE bias source text if HPE + String text = getHpeText(paintTime.getRefTime()); + + if (text != null && text.trim().length() > 0) { + double[] pixel = paintProps.getView().getDisplayCoords( + new double[] { 110, 120 }, aTarget); + hpeLabelString + .setText(text, + getCapability(ColorableCapability.class) + .getColor()); + hpeLabelString.setCoordinates(pixel[0], pixel[1]); + aTarget.drawStrings(hpeLabelString); + + } + } + // always reset isQuery = false; } finally { @@ -1503,15 +1557,6 @@ public class FFMPResource extends .append(FFMPRecord.getFieldLongDescription(getField())); } - // Paint the HPE bias source text if HPE - if (isHpe && qpeRecord != null) { - String text = getText(paintTime.getRefTime()); - if (text != null) { - sb.append(StringUtil.NEWLINE); - sb.append(text); - } - } - fieldDescString.setText(sb.toString(), getCapability(ColorableCapability.class).getColor()); fieldDescString.setCoordinates(pixel[0], pixel[1]); @@ -4178,14 +4223,44 @@ public class FFMPResource extends * @param date * @return */ - private String getText(Date date) { - String text = hpeLegendMap.get(date); + private String getHpeText(Date date) { + List products = hpeCacheLookup.get(date); + if (products == null) { + products = new ArrayList(0); + } + HpeLabelKey key = new HpeLabelKey(); + key.setDate(date); + for (String product : products) { + key.setProductName(product); + } + String text = hpeLegendMap.get(key); if (text == null) { - FFMPRecord hpeQpeRecord = getQpeRecord(); + String wfo = null; + String siteKey = null; + String dataKey = null; + String sourceName = null; + + if (qpeRecord != null) { + wfo = qpeRecord.getWfo(); + siteKey = qpeRecord.getSiteKey(); + dataKey = qpeRecord.getDataKey(); + sourceName = qpeRecord.getSourceName(); + } else if (qpfRecord != null) { + wfo = qpfRecord.getWfo(); + siteKey = qpfRecord.getSiteKey(); + dataKey = qpfRecord.getDataKey(); + sourceName = qpfRecord.getSourceName(); + } else { + return ""; + } String productId = monitor.getProductID(paintTime.getRefTime(), - hpeQpeRecord.getWfo(), hpeQpeRecord.getSiteKey(), - hpeQpeRecord.getDataKey(), hpeQpeRecord.getSourceName()); + wfo, siteKey, dataKey, sourceName); dataJob.scheduleRetrieval(date, productId); + statusHandler.info("Loading product " + productId); + } + + if (text == null) { + text = ""; } return text; @@ -4237,7 +4312,12 @@ public class FFMPResource extends .sendRequest(req); Map data = response.getData(); for (Date d : data.keySet()) { - hpeLegendMap.put(d, data.get(d)); + HpeLabelKey key = new HpeLabelKey(productId, d); + hpeLegendMap.put(key, data.get(d)); + if (!hpeCacheLookup.containsKey(d)) { + hpeCacheLookup.put(d, new ArrayList()); + } + hpeCacheLookup.get(d).add(productId); } } catch (VizException e) { statusHandler.error(e.getLocalizedMessage(), e); diff --git a/edexOsgi/com.raytheon.uf.common.plugin.hpe/src/com/raytheon/uf/common/plugin/hpe/data/HpeLabelKey.java b/edexOsgi/com.raytheon.uf.common.plugin.hpe/src/com/raytheon/uf/common/plugin/hpe/data/HpeLabelKey.java new file mode 100644 index 0000000000..ec9f205fe9 --- /dev/null +++ b/edexOsgi/com.raytheon.uf.common.plugin.hpe/src/com/raytheon/uf/common/plugin/hpe/data/HpeLabelKey.java @@ -0,0 +1,148 @@ +/** + * 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.uf.common.plugin.hpe.data; + +import java.util.Date; + +/** + * An object to act as the HPE/BiasHPE text key + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Feb 11, 2015   4121     mpduff      Initial creation
+ * 
+ * 
+ * + * @author mpduff + * @version 1.0 + */ +public class HpeLabelKey { + /** Product Name */ + private String productName; + + /** Product date/time */ + private Date date; + + /** + * Default constructor. + */ + public HpeLabelKey() { + + } + + public HpeLabelKey(String productName, Date date) { + this.productName = productName; + this.date = date; + } + + /** + * @return the productName + */ + public String getProductName() { + return productName; + } + + /** + * @param productName + * the productName to set + */ + public void setProductName(String productName) { + this.productName = productName; + } + + /** + * @return the date + */ + public Date getDate() { + return date; + } + + /** + * @param date + * the date to set + */ + public void setDate(Date date) { + this.date = date; + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((date == null) ? 0 : date.hashCode()); + result = prime * result + + ((productName == null) ? 0 : productName.hashCode()); + return result; + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + HpeLabelKey other = (HpeLabelKey) obj; + if (date == null) { + if (other.date != null) { + return false; + } + } else if (!date.equals(other.date)) { + return false; + } + if (productName == null) { + if (other.productName != null) { + return false; + } + } else if (!productName.equals(other.productName)) { + return false; + } + return true; + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + return "HpeLabelKey [productName=" + productName + ", date=" + date + + "]"; + } +} \ No newline at end of file