Merge "Omaha #5239 Fix sizing issues with Make Hazards Dialog" into omaha_16.2.2

Former-commit-id: 1aaf74e7f8bf737110411fb456e2c69d1edb542e
This commit is contained in:
Ron Anderson 2016-01-18 15:54:05 -06:00 committed by Gerrit Code Review
commit fa5bca3ad3

View file

@ -39,8 +39,6 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job; import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.events.SelectionListener;
@ -53,7 +51,6 @@ import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Group;
@ -103,22 +100,23 @@ import com.raytheon.viz.ui.statusline.StatusStore;
/** /**
* Make Hazard Dialog * Make Hazard Dialog
* *
* <pre> * <pre>
* SOFTWARE HISTORY * SOFTWARE HISTORY
* Date Ticket# Engineer Description * Date Ticket# Engineer Description
* ------------ ---------- ----------- -------------------------- * ------------ ---------- ----------- --------------------------
* Jun 5, 2008 Eric Babin Initial Creation * Jun 5, 2008 Eric Babin Initial Creation
* Sep 27,2010 5813 gzhou get etn from param pattern hazXXXnnn * Sep 27,2010 5813 gzhou get etn from param pattern hazXXXnnn
* Feb 28,2012 14436 mli Add RP.S - Rip Current * Feb 28,2012 14436 mli Add RP.S - Rip Current
* Apr 03,2012 436 randerso Reworked dialog to be called by Python MakeHazard procedure * Apr 03,2012 436 randerso Reworked dialog to be called by Python MakeHazard procedure
* Apr 09,2012 436 randerso Merged RNK's MakeHazards_Elevation procedure * Apr 09,2012 436 randerso Merged RNK's MakeHazards_Elevation procedure
* May 30,2012 2028 randerso Cleaned up dialog layout * May 30,2012 2028 randerso Cleaned up dialog layout
* Nov 13,2014 646 lshi Fixed hard coded endTimeSlider's Max value * Nov 13,2014 646 lshi Fixed hard coded endTimeSlider's Max value
* Jul 30,2015 17770 lshi Add handling for AT, EP, CP and WP basins * Jul 30,2015 17770 lshi Add handling for AT, EP, CP and WP basins
* * Jan 14,2016 5239 randerso Fixed Zones included/not included labels not always visible
*
* </pre> * </pre>
* *
* @author ebabin * @author ebabin
* @version 1.0 * @version 1.0
*/ */
@ -130,8 +128,6 @@ public class MakeHazardDialog extends CaveSWTDialog implements
private static final String DEFAULT_MAP_COLOR = "red"; private static final String DEFAULT_MAP_COLOR = "red";
private static final int LEGEND_HEIGHT = 16;
private static final double DEFAULT_AREA_THRESHOLD = 0.10; private static final double DEFAULT_AREA_THRESHOLD = 0.10;
private static final String ZONES_MSG = "USING MAP SELECTIONS"; private static final String ZONES_MSG = "USING MAP SELECTIONS";
@ -167,7 +163,7 @@ public class MakeHazardDialog extends CaveSWTDialog implements
/** /**
* Used by hazard start and end Time. * Used by hazard start and end Time.
* *
*/ */
private int toHours = 96; private int toHours = 96;
@ -220,10 +216,6 @@ public class MakeHazardDialog extends CaveSWTDialog implements
private Composite topComp; private Composite topComp;
private Canvas excluded;
private Canvas included;
private Map<String, Integer> comboDict; private Map<String, Integer> comboDict;
private String currentHazardType; private String currentHazardType;
@ -234,13 +226,13 @@ public class MakeHazardDialog extends CaveSWTDialog implements
private org.eclipse.swt.widgets.List hazardGroupList; private org.eclipse.swt.widgets.List hazardGroupList;
private static final String[] WMO_TITLES = { private static final String[] WMO_TITLES = { "NATIONAL HURRICANE CENTER", // NHC
"NATIONAL HURRICANE CENTER", //NHC "NATIONAL WEATHER SERVICE TIYAN", // GUM
"NATIONAL WEATHER SERVICE TIYAN", //GUM "CENTRAL PACIFIC HURRICANE CENTER" // CPHC
"CENTRAL PACIFIC HURRICANE CENTER" //CPHC
}; };
private static final Map<String, String> BASINS = ImmutableMap.of("AT", "10", "EP", "20", "CP", "30", "WP", "40"); private static final Map<String, String> BASINS = ImmutableMap.of("AT",
"10", "EP", "20", "CP", "30", "WP", "40");
public MakeHazardDialog(Shell parent, DataManager dataManager, public MakeHazardDialog(Shell parent, DataManager dataManager,
String colorName, int defaultMapWidth, int timeScaleEndTime, String colorName, int defaultMapWidth, int timeScaleEndTime,
@ -372,13 +364,13 @@ public class MakeHazardDialog extends CaveSWTDialog implements
TimeRange timeRange = null; TimeRange timeRange = null;
Parm parm = null; Parm parm = null;
String parmName = null; String parmName = null;
if (parms != null && parms.length == 1) { if ((parms != null) && (parms.length == 1)) {
parm = parms[0]; parm = parms[0];
parmName = parm.getParmID().getParmName(); parmName = parm.getParmID().getParmName();
} }
// Check for an ETN or segment # // Check for an ETN or segment #
if (parmName != null && parmName.startsWith("haz")) { if ((parmName != null) && parmName.startsWith("haz")) {
// DR 5813 // DR 5813
// parmName example: hazXXXnnn // parmName example: hazXXXnnn
@ -387,7 +379,7 @@ public class MakeHazardDialog extends CaveSWTDialog implements
while (Character.isDigit(parmName.charAt(--index))) { while (Character.isDigit(parmName.charAt(--index))) {
} }
if (index < parmName.length() - 1) { if (index < (parmName.length() - 1)) {
String etn = parmName.substring(index + 1); String etn = parmName.substring(index + 1);
if (Integer.parseInt(etn) > 0) { if (Integer.parseInt(etn) > 0) {
this.etnSegNumberField.setText(etn); this.etnSegNumberField.setText(etn);
@ -397,7 +389,7 @@ public class MakeHazardDialog extends CaveSWTDialog implements
timeRange = determineTimeRange(parm); timeRange = determineTimeRange(parm);
if (parmName == null || !parmName.startsWith("haz")) { if ((parmName == null) || !parmName.startsWith("haz")) {
setTRSliders(timeRange); setTRSliders(timeRange);
return; return;
} }
@ -405,7 +397,7 @@ public class MakeHazardDialog extends CaveSWTDialog implements
IGridData[] grids = null; IGridData[] grids = null;
if (timeRange != null) { if (timeRange != null) {
grids = parm.getGridInventory(timeRange); grids = parm.getGridInventory(timeRange);
if (grids == null || grids.length != 1) { if ((grids == null) || (grids.length != 1)) {
timeRange = null; timeRange = null;
} else { } else {
timeRange = grids[0].getGridTime(); timeRange = grids[0].getGridTime();
@ -455,10 +447,10 @@ public class MakeHazardDialog extends CaveSWTDialog implements
updateTime(startHour, startTimeLabel); updateTime(startHour, startTimeLabel);
int endHour = (int) (endLong - zeroLong) / (60 * 60 * 1000); int endHour = (int) (endLong - zeroLong) / (60 * 60 * 1000);
if (endHour < startHour + 1) { if (endHour < (startHour + 1)) {
endHour = startHour + 1; endHour = startHour + 1;
} }
if (endHour > toHours + 1) { if (endHour > (toHours + 1)) {
statusHandler.handle(Priority.VERBOSE, statusHandler.handle(Priority.VERBOSE,
"Hazard end time is beyond date slider limit"); "Hazard end time is beyond date slider limit");
endHour = toHours + 1; endHour = toHours + 1;
@ -475,7 +467,7 @@ public class MakeHazardDialog extends CaveSWTDialog implements
* preview() process. Currently, we don't implement preview(), but we * preview() process. Currently, we don't implement preview(), but we
* probably will at some point in the future. When we do, we can get rid of * probably will at some point in the future. When we do, we can get rid of
* this method and let preview() do this for us like AWIPS I did. * this method and let preview() do this for us like AWIPS I did.
* *
* @param parm * @param parm
* @return * @return
*/ */
@ -484,7 +476,7 @@ public class MakeHazardDialog extends CaveSWTDialog implements
.getSpatialEditorTime(); .getSpatialEditorTime();
TimeRange timeRange = dataManager.getParmOp().getSelectionTimeRange(); TimeRange timeRange = dataManager.getParmOp().getSelectionTimeRange();
if (timeRange != null && timeRange.isValid()) { if ((timeRange != null) && timeRange.isValid()) {
if (!timeRange.contains(seTime)) { if (!timeRange.contains(seTime)) {
statusHandler statusHandler
.handle(Priority.PROBLEM, .handle(Priority.PROBLEM,
@ -495,7 +487,7 @@ public class MakeHazardDialog extends CaveSWTDialog implements
timeRange = null; timeRange = null;
if (parm != null) { if (parm != null) {
timeRange = parm.getParmState().getSelectedTimeRange(); timeRange = parm.getParmState().getSelectedTimeRange();
if (timeRange != null && !timeRange.isValid()) { if ((timeRange != null) && !timeRange.isValid()) {
timeRange = null; timeRange = null;
} }
} }
@ -508,9 +500,9 @@ public class MakeHazardDialog extends CaveSWTDialog implements
} }
} }
if (timeRange != null && parm != null) { if ((timeRange != null) && (parm != null)) {
IGridData[] grids = parm.getGridInventory(timeRange); IGridData[] grids = parm.getGridInventory(timeRange);
if (grids != null && grids.length > 1) { if ((grids != null) && (grids.length > 1)) {
// There should be a yes/no dialog pop up... // There should be a yes/no dialog pop up...
} }
} }
@ -522,7 +514,7 @@ public class MakeHazardDialog extends CaveSWTDialog implements
* Figure out the hazard type (i.e., "Winter Weather") and db tables to use, * Figure out the hazard type (i.e., "Winter Weather") and db tables to use,
* based on phen_sig. The same phensig sometimes appears in multiple hazard * based on phen_sig. The same phensig sometimes appears in multiple hazard
* types, so pick the one that draws from the most db tables. * types, so pick the one that draws from the most db tables.
* *
* @param phen_sig * @param phen_sig
*/ */
protected void pickDefaultCategory(String phen_sig) { protected void pickDefaultCategory(String phen_sig) {
@ -531,11 +523,11 @@ public class MakeHazardDialog extends CaveSWTDialog implements
Map<String, List<String>> hazDict = getHazardsDictionary(); Map<String, List<String>> hazDict = getHazardsDictionary();
for (Map.Entry<String, List<String>> entry : hazDict.entrySet()) { for (Map.Entry<String, List<String>> entry : hazDict.entrySet()) {
List<String> phenSigsForType = entry.getValue(); List<String> phenSigsForType = entry.getValue();
if (phenSigsForType != null && phenSigsForType.contains(phen_sig)) { if ((phenSigsForType != null) && phenSigsForType.contains(phen_sig)) {
String entryHazardType = entry.getKey(); String entryHazardType = entry.getKey();
List<String> entryHazTables = mapNames.get(entryHazardType); List<String> entryHazTables = mapNames.get(entryHazardType);
if (hazTables == null if ((hazTables == null)
|| hazTables.size() < entryHazTables.size()) { || (hazTables.size() < entryHazTables.size())) {
hazardType = entryHazardType; hazardType = entryHazardType;
hazTables = entryHazTables; hazTables = entryHazTables;
} }
@ -578,7 +570,7 @@ public class MakeHazardDialog extends CaveSWTDialog implements
* Create the hazard in response to the run or run/dismiss button. Indicate * Create the hazard in response to the run or run/dismiss button. Indicate
* whether the run succeeded so run/dismiss knows whether it's OK to close * whether the run succeeded so run/dismiss knows whether it's OK to close
* the dialog. * the dialog.
* *
* @return true if the hazard was created, false otherwise. * @return true if the hazard was created, false otherwise.
*/ */
private boolean doRunInternal(boolean dismiss) { private boolean doRunInternal(boolean dismiss) {
@ -698,7 +690,8 @@ public class MakeHazardDialog extends CaveSWTDialog implements
if (baseEtnCode != null) { if (baseEtnCode != null) {
nationalBase = baseEtnCode; nationalBase = baseEtnCode;
} else { } else {
statusHandler.warn("Undefined basin ID: " + baseETN + ", defaulting to AT"); statusHandler.warn("Undefined basin ID: " + baseETN
+ ", defaulting to AT");
} }
String stormNum = altFileName.substring(2, 4); String stormNum = altFileName.substring(2, 4);
tropicalETN = nationalBase + stormNum; tropicalETN = nationalBase + stormNum;
@ -869,37 +862,33 @@ public class MakeHazardDialog extends CaveSWTDialog implements
showMapLabelsButton.setText("Map Labels"); showMapLabelsButton.setText("Map Labels");
comp = new Composite(buttonComp, SWT.NONE); comp = new Composite(buttonComp, SWT.NONE);
layout = new GridLayout(1, false); layout = new GridLayout(2, false);
layout.marginHeight = 0; layout.marginHeight = 0;
layout.marginWidth = 0; layout.marginWidth = 0;
comp.setLayout(layout); comp.setLayout(layout);
layoutData = new GridData(SWT.FILL, SWT.FILL, true, true); layoutData = new GridData(SWT.RIGHT, SWT.FILL, true, true);
comp.setLayoutData(layoutData); comp.setLayoutData(layoutData);
excluded = new Canvas(comp, SWT.NONE); GC gc = new GC(getDisplay());
gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false); int height = gc.getFontMetrics().getHeight();
gd.heightHint = LEGEND_HEIGHT; gc.dispose();
excluded.setLayoutData(gd);
excluded.addPaintListener(new PaintListener() {
@Override Label label = new Label(comp, SWT.NONE);
public void paintControl(PaintEvent e) { label.setBackground(new Color(getDisplay(), zoneSelector
paintLegend(e.gc, zoneSelector.getNoZoneColor(), .getNoZoneColor()));
"Zones not included"); gd = new GridData(height, height);
} label.setLayoutData(gd);
});
included = new Canvas(comp, SWT.NONE); label = new Label(comp, SWT.NONE);
gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false); label.setText("Zones not included");
gd.heightHint = 16;
included.setLayoutData(gd);
included.addPaintListener(new PaintListener() {
@Override label = new Label(comp, SWT.NONE);
public void paintControl(PaintEvent e) { label.setBackground(new Color(getDisplay(), mapColor));
paintLegend(e.gc, mapColor, "Zones included"); gd = new GridData(height, height);
} label.setLayoutData(gd);
});
label = new Label(comp, SWT.NONE);
label.setText("Zones included");
showMapLabelsButton.addSelectionListener(new SelectionAdapter() { showMapLabelsButton.addSelectionListener(new SelectionAdapter() {
@Override @Override
@ -961,21 +950,6 @@ public class MakeHazardDialog extends CaveSWTDialog implements
usingLabel.setText(EDIT_AREA_MSG); usingLabel.setText(EDIT_AREA_MSG);
} }
private void paintLegend(GC gc, RGB color, String text) {
Color bg = new Color(getDisplay(), color);
gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_WHITE));
gc.setBackground(bg);
int height = gc.getFontMetrics().getHeight();
gc.fillRectangle(height, 0, height, height);
gc.drawRectangle(height, 0, height, height);
gc.setBackground(CAVEMode.getBackgroundColor());
gc.setForeground(CAVEMode.getForegroundColor());
gc.drawText(text, height * 2
+ gc.getFontMetrics().getAverageCharWidth(), 0);
bg.dispose();
}
private void createSelectHazardComponent(Composite hazardComp) { private void createSelectHazardComponent(Composite hazardComp) {
GridLayout gl = new GridLayout(2, false); GridLayout gl = new GridLayout(2, false);
gl.marginHeight = 0; gl.marginHeight = 0;
@ -998,7 +972,7 @@ public class MakeHazardDialog extends CaveSWTDialog implements
selectedHazardList = new org.eclipse.swt.widgets.List(hazardGroup, selectedHazardList = new org.eclipse.swt.widgets.List(hazardGroup,
SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.SINGLE); SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.SINGLE);
gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false); gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
gd.heightHint = selectedHazardList.getItemHeight() * 16 gd.heightHint = (selectedHazardList.getItemHeight() * 16)
+ selectedHazardList.getBorderWidth(); + selectedHazardList.getBorderWidth();
selectedHazardList.setLayoutData(gd); selectedHazardList.setLayoutData(gd);
@ -1035,8 +1009,8 @@ public class MakeHazardDialog extends CaveSWTDialog implements
hazardGroupList = new org.eclipse.swt.widgets.List(hazardTypeGroup, hazardGroupList = new org.eclipse.swt.widgets.List(hazardTypeGroup,
SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.SINGLE); SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.SINGLE);
gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false); gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
gd.heightHint = hazardGroupList.getItemHeight() gd.heightHint = (hazardGroupList.getItemHeight() * Math.min(12,
* Math.min(12, groups.size()) groups.size()))
+ hazardGroupList.getBorderWidth(); + hazardGroupList.getBorderWidth();
hazardGroupList.setLayoutData(gd); hazardGroupList.setLayoutData(gd);
hazardGroupList.addSelectionListener(selAdapt); hazardGroupList.addSelectionListener(selAdapt);
@ -1133,7 +1107,7 @@ public class MakeHazardDialog extends CaveSWTDialog implements
* Event handler for when the user moves the slider. This updates * Event handler for when the user moves the slider. This updates
* the slider label and changes the end time slider if the end time * the slider label and changes the end time slider if the end time
* is before the start time. * is before the start time.
* *
* @param e * @param e
* The event that caused this handler to be called. * The event that caused this handler to be called.
*/ */
@ -1181,7 +1155,7 @@ public class MakeHazardDialog extends CaveSWTDialog implements
gd.minimumWidth = 200; gd.minimumWidth = 200;
endTimeSlider.setLayoutData(gd); endTimeSlider.setLayoutData(gd);
toHours = this.timeScaleEndTime; //#646 toHours = this.timeScaleEndTime; // #646
endTimeSlider.setMinimum(1); endTimeSlider.setMinimum(1);
endTimeSlider.setMaximum(toHours + 1); endTimeSlider.setMaximum(toHours + 1);
endTimeSlider.setIncrement(1); endTimeSlider.setIncrement(1);
@ -1198,7 +1172,7 @@ public class MakeHazardDialog extends CaveSWTDialog implements
* Event handler for when the user moves the slider. This updates * Event handler for when the user moves the slider. This updates
* the slider label and changes the start time slider if the end * the slider label and changes the start time slider if the end
* time is before the start time. * time is before the start time.
* *
* @param e * @param e
* The event that caused this handler to be called. * The event that caused this handler to be called.
*/ */
@ -1315,7 +1289,7 @@ public class MakeHazardDialog extends CaveSWTDialog implements
* Add <code>selection</code> hours to <code>hazardStartTime</code> (that * Add <code>selection</code> hours to <code>hazardStartTime</code> (that
* is, the default starting time), and set the text of <code>label</code> to * is, the default starting time), and set the text of <code>label</code> to
* the result, formatted by <code>dateFormatter</code>. * the result, formatted by <code>dateFormatter</code>.
* *
* @param selection * @param selection
* The integer slider value selected by the user. * The integer slider value selected by the user.
* @param label * @param label
@ -1348,7 +1322,7 @@ public class MakeHazardDialog extends CaveSWTDialog implements
* Set the hazard type in the radio button control. If the hazard type is * Set the hazard type in the radio button control. If the hazard type is
* changed, the radio button selection listener will fire, changing and * changed, the radio button selection listener will fire, changing and
* clearing selectedHazardList as a side effect. * clearing selectedHazardList as a side effect.
* *
* @param hazardType * @param hazardType
* the hazard type to select. * the hazard type to select.
*/ */
@ -1368,7 +1342,7 @@ public class MakeHazardDialog extends CaveSWTDialog implements
if (laData != null) { if (laData != null) {
String label = eaName; String label = eaName;
String display = (String) laData.get(1); String display = (String) laData.get(1);
if (display != null && !display.isEmpty()) { if ((display != null) && !display.isEmpty()) {
label = display; label = display;
} }
leCombo.add(label); leCombo.add(label);
@ -1397,12 +1371,12 @@ public class MakeHazardDialog extends CaveSWTDialog implements
* Set the selection in selectedHazardList to the first item that starts * Set the selection in selectedHazardList to the first item that starts
* with phen_sig. If phen_sig is null or an empty string, clears all * with phen_sig. If phen_sig is null or an empty string, clears all
* selections. * selections.
* *
* @param phen_sig * @param phen_sig
* The phen_sig to select * The phen_sig to select
*/ */
public void setHazard(String phen_sig) { public void setHazard(String phen_sig) {
if (phen_sig == null || phen_sig.length() == 0) { if ((phen_sig == null) || (phen_sig.length() == 0)) {
selectedHazardList.deselectAll(); selectedHazardList.deselectAll();
return; return;
} }
@ -1443,7 +1417,7 @@ public class MakeHazardDialog extends CaveSWTDialog implements
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
List<String> zoneList = (List<String>) laData.get(2); List<String> zoneList = (List<String>) laData.get(2);
if (zoneList != null && !zoneList.isEmpty()) { if ((zoneList != null) && !zoneList.isEmpty()) {
Map<String, Integer> comboDict = new HashMap<String, Integer>( Map<String, Integer> comboDict = new HashMap<String, Integer>(
zoneList.size()); zoneList.size());
for (String z : zoneList) { for (String z : zoneList) {
@ -1481,7 +1455,7 @@ public class MakeHazardDialog extends CaveSWTDialog implements
List<String> zoneIdsToShow = getAreaList(grid2DBit); List<String> zoneIdsToShow = getAreaList(grid2DBit);
// Select the zones // Select the zones
if (zoneIdsToShow != null && zoneIdsToShow.size() > 0) { if ((zoneIdsToShow != null) && (zoneIdsToShow.size() > 0)) {
usingLabel.setText(ZONES_MSG); usingLabel.setText(ZONES_MSG);
for (String z : zoneIdsToShow) { for (String z : zoneIdsToShow) {
this.comboDict.put(z, 1); this.comboDict.put(z, 1);
@ -1500,7 +1474,7 @@ public class MakeHazardDialog extends CaveSWTDialog implements
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
* @see * @see
* com.raytheon.viz.gfe.ui.zoneselector.ZoneSelector.IZoneSelectionListener * com.raytheon.viz.gfe.ui.zoneselector.ZoneSelector.IZoneSelectionListener
* #zonesSelected() * #zonesSelected()