From 09d6775293856a6c55bdf2652f9a375e966d9612 Mon Sep 17 00:00:00 2001 From: Lee Venable Date: Mon, 9 Sep 2013 16:54:49 -0500 Subject: [PATCH] Issue #2349 - Fixed font memory leaks Former-commit-id: 0816c3e7c7d02842694fb2237186400037151b68 [formerly 02651018f2d7761bc910cd4b1ea9a201fb3f4ad3 [formerly e81149f65d944f9898509a6ff03b063662a88882]] Former-commit-id: 02651018f2d7761bc910cd4b1ea9a201fb3f4ad3 Former-commit-id: 6b171d20dbd6dc7a4327efccd8250521f25cede2 --- .../hydro/appsdefaults/GetAppsDefaults.java | 9 + .../hydro/staffgage/StaffGageCanvasComp.java | 995 +++++++++--------- .../StationReportingStatusDlg.java | 11 +- .../ratingcurve/RatingCurveCanvasComp.java | 12 + 4 files changed, 541 insertions(+), 486 deletions(-) diff --git a/cave/com.raytheon.viz.hydro/src/com/raytheon/viz/hydro/appsdefaults/GetAppsDefaults.java b/cave/com.raytheon.viz.hydro/src/com/raytheon/viz/hydro/appsdefaults/GetAppsDefaults.java index 5899735e2f..81f9a418f1 100644 --- a/cave/com.raytheon.viz.hydro/src/com/raytheon/viz/hydro/appsdefaults/GetAppsDefaults.java +++ b/cave/com.raytheon.viz.hydro/src/com/raytheon/viz/hydro/appsdefaults/GetAppsDefaults.java @@ -46,6 +46,7 @@ import com.raytheon.viz.ui.dialogs.CaveSWTDialog; * ------------ ---------- ----------- -------------------------- * Jan 26, 2011 mpduff Initial creation * Dec 07, 2012 1353 rferrel Make dialog non-blocking. + * 09 Sep 2013 #2349 lvenable Fixed Font memory leak. * * * @@ -168,6 +169,14 @@ public class GetAppsDefaults extends CaveSWTDialog { }); } + @Override + protected void disposed() { + if (font != null) { + font.dispose(); + font = null; + } + } + private void gad() { String token = searchField.getText(); if ((token != null) && (token.length() > 0)) { diff --git a/cave/com.raytheon.viz.hydro/src/com/raytheon/viz/hydro/staffgage/StaffGageCanvasComp.java b/cave/com.raytheon.viz.hydro/src/com/raytheon/viz/hydro/staffgage/StaffGageCanvasComp.java index 8746f7df98..ac164623dd 100644 --- a/cave/com.raytheon.viz.hydro/src/com/raytheon/viz/hydro/staffgage/StaffGageCanvasComp.java +++ b/cave/com.raytheon.viz.hydro/src/com/raytheon/viz/hydro/staffgage/StaffGageCanvasComp.java @@ -21,6 +21,8 @@ package com.raytheon.viz.hydro.staffgage; import org.eclipse.swt.SWT; +import org.eclipse.swt.events.DisposeEvent; +import org.eclipse.swt.events.DisposeListener; import org.eclipse.swt.events.PaintEvent; import org.eclipse.swt.events.PaintListener; import org.eclipse.swt.graphics.Font; @@ -42,31 +44,31 @@ import org.eclipse.swt.widgets.Composite; * Gage Window. * 02 Feb 2011 4383 lbousaidi added calcMaxStage and calcMinStage * routines, also added several conditions - * for the drawing on gage - * + * for the drawing on gage + * 09 Sep 2013 #2349 lvenable Fixed Font memory leak. + * * * * @author lvenable * @version 1.0 - * + * */ -public class StaffGageCanvasComp extends Composite -{ +public class StaffGageCanvasComp extends Composite { /** * Parent composite. */ private Composite parent; - + /** * Canvas font. */ private Font canvasFont; - + /** * Canvas width. */ private final int CANVAS_WIDTH = 440; - + /** * Canvas height. */ @@ -76,598 +78,623 @@ public class StaffGageCanvasComp extends Composite * Width of the gage. */ private final int GAGE_WIDTH = 50; - + /** * X coordinate of the canvas middle. */ private final int CANVAS_MID_WIDTH = CANVAS_WIDTH / 2; - + /** * X coordinate of the gage's left side. */ - private final int GAGE_LEFT_X = CANVAS_MID_WIDTH - (GAGE_WIDTH/2); - + private final int GAGE_LEFT_X = CANVAS_MID_WIDTH - (GAGE_WIDTH / 2); + /** * X coordinate of the gage's right side. */ private final int GAGE_RIGHT_X = GAGE_LEFT_X + GAGE_WIDTH; - + /** * Height of the gage. */ private final int GAGE_HEIGHT = CANVAS_HEIGHT - 40; - + /** - * Number of pixels between the top of the gage and the top of - * the canvas. + * Number of pixels between the top of the gage and the top of the canvas. */ private final int GAGE_PIX_FROM_TOP = 20; - + /** * Length of the large hash mark. */ private final int LARGE_HASH_MARK = 10; - + /** * Length of the small hash mark. */ private final int SMALL_HASH_MARK = 3; - + /** * X coordinate of the labels on the left side of the gage. */ private final int LEFT_LABEL_XCOORD = 5; - + /** * X coordinate of the vertical stage line. */ private final int VERT_STAGE_LINE_XCOORD = 100; - + /** - * X coordinate of the stage label on the left side - * of the gage. + * X coordinate of the stage label on the left side of the gage. */ private final int LEFT_STAGE_LABEL_XCOORD = 120; - + /** * Canvas displaying the staff gage. */ private Canvas stageCanvas; - + /** * Gage data to be displayed. */ private StaffGageData gageData; - + /** * No STAGE Data Available string. */ - private static final String noDataString="STAGE DATA UNAVAILABLE FOR STAFF GAGE DISPLAY."; - + private static final String noDataString = "STAGE DATA UNAVAILABLE FOR STAFF GAGE DISPLAY."; + /** * maximum stage default value */ - public static final int DEFAULT_MAX = 0; - + public static final int DEFAULT_MAX = 0; + /** * minimum stage default value */ - public static final int DEFAULT_MIN = 0; - + public static final int DEFAULT_MIN = 0; + /** * Constructor. - * @param parent Parent composite. - * @param gageData Gage data to be displayed. + * + * @param parent + * Parent composite. + * @param gageData + * Gage data to be displayed. */ - public StaffGageCanvasComp(Composite parent, StaffGageData gageData) - { + public StaffGageCanvasComp(Composite parent, StaffGageData gageData) { super(parent, SWT.NONE); - - this.parent = parent; + + this.parent = parent; this.gageData = gageData; - + init(); this.pack(); } - + /** * Initialize the canvas, layout, and font. */ - private void init() - { + private void init() { this.setLayout(new RowLayout()); - + canvasFont = new Font(parent.getDisplay(), "Monospace", 10, SWT.NORMAL); - + setupCanvas(); + + parent.addDisposeListener(new DisposeListener() { + @Override + public void widgetDisposed(DisposeEvent e) { + if (canvasFont != null) { + canvasFont.dispose(); + canvasFont = null; + } + } + }); } - + /** * Setup the canvas so it can be used. */ - private void setupCanvas() - { + private void setupCanvas() { stageCanvas = new Canvas(parent, SWT.DOUBLE_BUFFERED); stageCanvas.setLayoutData(new GridData(CANVAS_WIDTH, CANVAS_HEIGHT)); - stageCanvas.addPaintListener(new PaintListener() - { - public void paintControl(PaintEvent e) - { + stageCanvas.addPaintListener(new PaintListener() { + public void paintControl(PaintEvent e) { drawStaffGage(e); } }); } - + /** * Update the Staff Gage data and redraw the canvas. - * @param gageData Staff Gage data. + * + * @param gageData + * Staff Gage data. */ - public void updateStaffGageData(StaffGageData gageData) - { - + public void updateStaffGageData(StaffGageData gageData) { + this.gageData = gageData; - + stageCanvas.redraw(); } - + /** * Draw the staff gage information on the canvas. - * @param e Paint event. + * + * @param e + * Paint event. */ - private void drawStaffGage(PaintEvent e) - { - // Get the flood , stage and action stage numbers. - + private void drawStaffGage(PaintEvent e) { + // Get the flood , stage and action stage numbers. + double recordStg = Double.valueOf(gageData.getRecordStage()); double majorStg = Double.valueOf(gageData.getMajorCatStage()); double moderStg = Double.valueOf(gageData.getModCatStage()); - double minorStg = Double.valueOf(gageData.getMinorCatStage()); + double minorStg = Double.valueOf(gageData.getMinorCatStage()); double floodStgNum = Double.valueOf(gageData.getFloodStage()); double actionStgNum = Double.valueOf(gageData.getActionStage()); - double BankFullStg= Double.valueOf(gageData.getBankfullStage()); - double zeroDatum= Double.valueOf(gageData.getZeroDatum()); - - //-------------------------------------------------------------- + double BankFullStg = Double.valueOf(gageData.getBankfullStage()); + double zeroDatum = Double.valueOf(gageData.getZeroDatum()); + + // -------------------------------------------------------------- // NOTE: the max and min stage values will need to be calculated - //-------------------------------------------------------------- + // -------------------------------------------------------------- double maxStageVal = calcMaxStage(); - double minStageVal= calcMinStage( ); - + double minStageVal = calcMinStage(); + e.gc.setFont(canvasFont); - int fontMid = (int)(e.gc.getFontMetrics().getHeight() / 2); - - e.gc.setBackground(parent.getDisplay().getSystemColor( - SWT.COLOR_BLACK)); - + int fontMid = (int) (e.gc.getFontMetrics().getHeight() / 2); + + e.gc.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_BLACK)); + e.gc.fillRectangle(0, 0, CANVAS_WIDTH, CANVAS_HEIGHT); - - // if Stage missing Draw the missing error message - - if ((maxStageVal == DEFAULT_MAX )&& (minStageVal == DEFAULT_MIN)) { - - e.gc.setForeground(parent.getDisplay().getSystemColor( + + // if Stage missing Draw the missing error message + + if ((maxStageVal == DEFAULT_MAX) && (minStageVal == DEFAULT_MIN)) { + + e.gc.setForeground(parent.getDisplay().getSystemColor( SWT.COLOR_WHITE)); - int label_X = CANVAS_WIDTH - 400 ; - int label_Y= CANVAS_HEIGHT/2 ; - e.gc.drawString(noDataString, label_X, label_Y- fontMid, true); - - return; - - } else { - - double maxPixValue = GAGE_HEIGHT + GAGE_PIX_FROM_TOP; + int label_X = CANVAS_WIDTH - 400; + int label_Y = CANVAS_HEIGHT / 2; + e.gc.drawString(noDataString, label_X, label_Y - fontMid, true); + + return; + + } else { + + double maxPixValue = GAGE_HEIGHT + GAGE_PIX_FROM_TOP; double numHashs = maxStageVal - minStageVal; - double pixelsPerInc = GAGE_HEIGHT / numHashs; - - //----------------------------------------------------------------- + double pixelsPerInc = GAGE_HEIGHT / numHashs; + + // ----------------------------------------------------------------- // Create RED area on GAGE representing the area above flood stage - //----------------------------------------------------------------- + // ----------------------------------------------------------------- if (floodStgNum > 0.0) { - e.gc.setBackground(parent.getDisplay().getSystemColor( - SWT.COLOR_RED)); - - e.gc.fillRectangle(GAGE_LEFT_X, GAGE_PIX_FROM_TOP, - GAGE_WIDTH, GAGE_HEIGHT); + e.gc.setBackground(parent.getDisplay().getSystemColor( + SWT.COLOR_RED)); + + e.gc.fillRectangle(GAGE_LEFT_X, GAGE_PIX_FROM_TOP, GAGE_WIDTH, + GAGE_HEIGHT); } - //---------------------------------------------------------------- + // ---------------------------------------------------------------- // Create YELLOW areas on gage only if an action stage is defined - //---------------------------------------------------------------- - if (actionStgNum > 0.0) { - - double ActionFloodStg = (floodStgNum > 0.0) ? floodStgNum : maxStageVal; - - int yCoord1 = (int)(maxPixValue - Math.round((( ActionFloodStg - minStageVal) * pixelsPerInc))); - - e.gc.setBackground(parent.getDisplay().getSystemColor( - SWT.COLOR_YELLOW)); - - e.gc.fillRectangle(GAGE_LEFT_X, yCoord1 , - GAGE_WIDTH, GAGE_HEIGHT - yCoord1 + GAGE_PIX_FROM_TOP); - } - - //------------------------------------------------------ - // Create GREEN area on gage, this color is always drawn - //------------------------------------------------------ - - double floodActionMax =0.0; + // ---------------------------------------------------------------- if (actionStgNum > 0.0) { - floodActionMax = actionStgNum ; - } else if (floodStgNum > 0.0 ) { - floodActionMax = floodStgNum; - } else { - floodActionMax = maxStageVal; + + double ActionFloodStg = (floodStgNum > 0.0) ? floodStgNum + : maxStageVal; + + int yCoord1 = (int) (maxPixValue - Math + .round(((ActionFloodStg - minStageVal) * pixelsPerInc))); + + e.gc.setBackground(parent.getDisplay().getSystemColor( + SWT.COLOR_YELLOW)); + + e.gc.fillRectangle(GAGE_LEFT_X, yCoord1, GAGE_WIDTH, + GAGE_HEIGHT - yCoord1 + GAGE_PIX_FROM_TOP); } - - int yCoord2 = (int)(maxPixValue - Math.round(((floodActionMax - minStageVal) * pixelsPerInc))); + + // ------------------------------------------------------ + // Create GREEN area on gage, this color is always drawn + // ------------------------------------------------------ + + double floodActionMax = 0.0; + if (actionStgNum > 0.0) { + floodActionMax = actionStgNum; + } else if (floodStgNum > 0.0) { + floodActionMax = floodStgNum; + } else { + floodActionMax = maxStageVal; + } + + int yCoord2 = (int) (maxPixValue - Math + .round(((floodActionMax - minStageVal) * pixelsPerInc))); e.gc.setBackground(parent.getDisplay().getSystemColor( - SWT.COLOR_GREEN)); - - e.gc.fillRectangle(GAGE_LEFT_X, yCoord2, - GAGE_WIDTH, GAGE_HEIGHT - yCoord2 + GAGE_PIX_FROM_TOP); - - //------------------------------------------ - // Draw WHITE rectangle around gage - //------------------------------------------ - e.gc.setForeground(parent.getDisplay().getSystemColor( - SWT.COLOR_WHITE)); - - e.gc.drawRectangle(GAGE_LEFT_X, GAGE_PIX_FROM_TOP, - GAGE_WIDTH, GAGE_HEIGHT); - - //---------------------------------------- - // Draw gage hash marks - //---------------------------------------- - double counter = 0.0; - - for (int x = (int)minStageVal; x <= maxStageVal; ++x) - { - int yCoord = (int)(maxPixValue - Math.round((counter * pixelsPerInc))); - - if (x%5 == 0) - { - // draw big hash - e.gc.drawLine(GAGE_RIGHT_X, yCoord, GAGE_RIGHT_X + LARGE_HASH_MARK, yCoord); - e.gc.drawLine(GAGE_LEFT_X, yCoord, GAGE_LEFT_X - LARGE_HASH_MARK, yCoord); - } - else - { - // draw little hash - e.gc.drawLine(GAGE_RIGHT_X, yCoord, GAGE_RIGHT_X + SMALL_HASH_MARK, yCoord); - e.gc.drawLine(GAGE_LEFT_X, yCoord, GAGE_LEFT_X - SMALL_HASH_MARK, yCoord); - } - - counter += 1.0; - } - - //------------------------------------- - // Draw labels - //------------------------------------- - - // - // Draw record label - // - double recordY = recordStg - minStageVal; - - int recordYCoord = (int)(maxPixValue - Math.round((recordY * pixelsPerInc))); - - if (recordStg > 0.0 ) { - e.gc.drawString("Record", LEFT_LABEL_XCOORD, - recordYCoord - fontMid, true); //1 - if ( majorStg > 0.0) { - e.gc.drawLine(VERT_STAGE_LINE_XCOORD, recordYCoord, - VERT_STAGE_LINE_XCOORD + LARGE_HASH_MARK, recordYCoord); - } - double recDbl = 0.0; - if (!gageData.getZeroDatum().equals(StaffGageDlg.MISSING)) { - recDbl = recordStg + zeroDatum; - } - - String recStr = String.format("%7.2f", recDbl); - e.gc.drawString(recStr, LEFT_STAGE_LABEL_XCOORD, - recordYCoord - fontMid, true); - - e.gc.drawString(gageData.getRecordStage(), GAGE_RIGHT_X + LARGE_HASH_MARK * 2, - recordYCoord - fontMid, true); - } - // - // Draw minimum label - // - int minYCoord = (int)(maxPixValue); - - e.gc.drawString(String.valueOf(minStageVal), GAGE_RIGHT_X + LARGE_HASH_MARK * 2, - minYCoord - fontMid, true); - - double minDbl = minStageVal; - if (!gageData.getZeroDatum().equals(StaffGageDlg.MISSING)) { - minDbl = minStageVal + zeroDatum; - } - - String minStr = String.format("%7.2f", minDbl); - e.gc.drawString(minStr, LEFT_STAGE_LABEL_XCOORD, - minYCoord - fontMid, true); - - // - // Draw maximum label - // - int maxYCoord = (int)(GAGE_PIX_FROM_TOP); - e.gc.drawString(String.valueOf(maxStageVal), GAGE_RIGHT_X + LARGE_HASH_MARK * 2, - maxYCoord - fontMid, true); - - double maxDbl = maxStageVal; - if (!gageData.getZeroDatum().equals(StaffGageDlg.MISSING)) { - maxDbl = maxStageVal + zeroDatum; - } - - String maxStr = String.format("%7.2f", maxDbl); - e.gc.drawString(maxStr, LEFT_STAGE_LABEL_XCOORD, - maxYCoord - fontMid, true); - - // - // Draw Major Category - // - double majorY = majorStg - minStageVal; - - int majorYCoord = (int)(maxPixValue - Math.round((majorY * pixelsPerInc))); - - if (majorStg > 0.0) { - e.gc.drawString("Major", LEFT_LABEL_XCOORD, - majorYCoord - fontMid, true); - if (moderStg > 0.0) { - e.gc.drawLine(VERT_STAGE_LINE_XCOORD, majorYCoord, - VERT_STAGE_LINE_XCOORD + LARGE_HASH_MARK, majorYCoord); - } - double majDbl=0.0; - if (!gageData.getZeroDatum().equals(StaffGageDlg.MISSING)) { - majDbl = majorStg + zeroDatum; - } - - String majStr = String.format("%7.2f", majDbl); - e.gc.drawString(majStr, LEFT_STAGE_LABEL_XCOORD, - majorYCoord - fontMid, true); - - e.gc.drawString(gageData.getMajorCatStage(), GAGE_RIGHT_X + LARGE_HASH_MARK * 2, - majorYCoord - fontMid, true); - } - // - // Draw Moderate Category - // - double moderY = moderStg - minStageVal; - - int modYCoord = (int)(maxPixValue - Math.round((moderY * pixelsPerInc))); - - if (moderStg > 0.0) { - e.gc.drawString("Moderate", LEFT_LABEL_XCOORD, - modYCoord - fontMid, true); - if (minorStg > 0.0) { - e.gc.drawLine(VERT_STAGE_LINE_XCOORD, modYCoord, - VERT_STAGE_LINE_XCOORD + LARGE_HASH_MARK, modYCoord); - } - - double modDbl =0.0; - if (!gageData.getZeroDatum().equals(StaffGageDlg.MISSING)) { - modDbl = moderStg + zeroDatum; - } - - String modStr = String.format("%7.2f", modDbl); - e.gc.drawString(modStr, LEFT_STAGE_LABEL_XCOORD,modYCoord - fontMid, true); - e.gc.drawString(gageData.getModCatStage(), GAGE_RIGHT_X + LARGE_HASH_MARK * 2, - modYCoord - fontMid, true); - } - - // Draw Minor Category - // - - double minorY = minorStg - minStageVal; - - int minorYCoord = (int)(maxPixValue - Math.round((minorY * pixelsPerInc))); - - if (minorStg > 0.0) { - e.gc.drawString("Minor", LEFT_LABEL_XCOORD, - minorYCoord - fontMid, true); - if (moderStg > 0.0) { - e.gc.drawLine(VERT_STAGE_LINE_XCOORD, minorYCoord, - VERT_STAGE_LINE_XCOORD + LARGE_HASH_MARK, minorYCoord); - } - double minorDbl = 0.0; - if (!gageData.getZeroDatum().equals(StaffGageDlg.MISSING)) { - minorDbl = minorStg + zeroDatum; - } - - String minorStr = String.format("%7.2f", minorDbl); - e.gc.drawString(minorStr, LEFT_STAGE_LABEL_XCOORD, - minorYCoord - fontMid, true); - - e.gc.drawString(gageData.getMinorCatStage(), GAGE_RIGHT_X + LARGE_HASH_MARK * 2, - minorYCoord - fontMid, true); - } - - // Draw vertical stage line - // - - if ( minorStg > 0.0 && majorStg > 0.0 ) { - e.gc.drawLine(VERT_STAGE_LINE_XCOORD, minorYCoord, - VERT_STAGE_LINE_XCOORD, majorYCoord); - } - - // draw the line from rec to major in case the record is - // outside the major value - if (recordStg > 0.0 && majorStg > 0.0) { - e.gc.drawLine(VERT_STAGE_LINE_XCOORD, recordYCoord, - VERT_STAGE_LINE_XCOORD, majorYCoord); - } - // - // Draw flood stage - // - double floodY = floodStgNum - minStageVal; - - int floodYCoord = (int)(maxPixValue - Math.round((floodY * pixelsPerInc))); - if (floodStgNum > 0.0) { - String floodStr = String.valueOf(gageData.getFloodStage()) + " Flood Stg"; - e.gc.drawString(floodStr, GAGE_RIGHT_X + LARGE_HASH_MARK * 2, - floodYCoord - fontMid, true); - } - // Draw action stage - - double actionY = actionStgNum - minStageVal; - - int actionYCoord = (int)(maxPixValue - Math.round((actionY * pixelsPerInc))); - - if (actionStgNum > 0.0) { - String actionStr = String.valueOf(gageData.getActionStage()) + " Action Stg"; - e.gc.drawString(actionStr, GAGE_RIGHT_X + LARGE_HASH_MARK * 2, - actionYCoord - fontMid, true); - - double actionDbl =0.0; - if (!gageData.getZeroDatum().equals(StaffGageDlg.MISSING)) { - actionDbl = actionStgNum + zeroDatum; - } - String actionStr1 = String.format("%7.2f", actionDbl); - e.gc.drawString(actionStr1, LEFT_STAGE_LABEL_XCOORD, - actionYCoord - fontMid, true); - } - // Draw Bankfull stage - - double BankFullStgY = BankFullStg - minStageVal; - - int BankFullYCoord = (int)(maxPixValue - Math.round(( BankFullStgY* pixelsPerInc))); - - if (BankFullStg > 0.0) { - String BankFullStr = String.valueOf(gageData.getBankfullStage()) ; - e.gc.drawString(BankFullStr, GAGE_RIGHT_X + LARGE_HASH_MARK * 2, - BankFullYCoord - fontMid, true); - - double bankfDbl =0.0; - if (!gageData.getZeroDatum().equals(StaffGageDlg.MISSING)) { - bankfDbl = BankFullStg + zeroDatum ; - } - - String bankfStr = String.format("%7.2f", bankfDbl); - e.gc.drawString(bankfStr, LEFT_STAGE_LABEL_XCOORD, - BankFullYCoord - fontMid, true); - } - } - } + SWT.COLOR_GREEN)); + + e.gc.fillRectangle(GAGE_LEFT_X, yCoord2, GAGE_WIDTH, GAGE_HEIGHT + - yCoord2 + GAGE_PIX_FROM_TOP); + + // ------------------------------------------ + // Draw WHITE rectangle around gage + // ------------------------------------------ + e.gc.setForeground(parent.getDisplay().getSystemColor( + SWT.COLOR_WHITE)); + + e.gc.drawRectangle(GAGE_LEFT_X, GAGE_PIX_FROM_TOP, GAGE_WIDTH, + GAGE_HEIGHT); + + // ---------------------------------------- + // Draw gage hash marks + // ---------------------------------------- + double counter = 0.0; + + for (int x = (int) minStageVal; x <= maxStageVal; ++x) { + int yCoord = (int) (maxPixValue - Math + .round((counter * pixelsPerInc))); + + if (x % 5 == 0) { + // draw big hash + e.gc.drawLine(GAGE_RIGHT_X, yCoord, GAGE_RIGHT_X + + LARGE_HASH_MARK, yCoord); + e.gc.drawLine(GAGE_LEFT_X, yCoord, GAGE_LEFT_X + - LARGE_HASH_MARK, yCoord); + } else { + // draw little hash + e.gc.drawLine(GAGE_RIGHT_X, yCoord, GAGE_RIGHT_X + + SMALL_HASH_MARK, yCoord); + e.gc.drawLine(GAGE_LEFT_X, yCoord, GAGE_LEFT_X + - SMALL_HASH_MARK, yCoord); + } + + counter += 1.0; + } + + // ------------------------------------- + // Draw labels + // ------------------------------------- + + // + // Draw record label + // + double recordY = recordStg - minStageVal; + + int recordYCoord = (int) (maxPixValue - Math + .round((recordY * pixelsPerInc))); + + if (recordStg > 0.0) { + e.gc.drawString("Record", LEFT_LABEL_XCOORD, recordYCoord + - fontMid, true); // 1 + if (majorStg > 0.0) { + e.gc.drawLine(VERT_STAGE_LINE_XCOORD, recordYCoord, + VERT_STAGE_LINE_XCOORD + LARGE_HASH_MARK, + recordYCoord); + } + double recDbl = 0.0; + if (!gageData.getZeroDatum().equals(StaffGageDlg.MISSING)) { + recDbl = recordStg + zeroDatum; + } + + String recStr = String.format("%7.2f", recDbl); + e.gc.drawString(recStr, LEFT_STAGE_LABEL_XCOORD, recordYCoord + - fontMid, true); + + e.gc.drawString(gageData.getRecordStage(), GAGE_RIGHT_X + + LARGE_HASH_MARK * 2, recordYCoord - fontMid, true); + } + // + // Draw minimum label + // + int minYCoord = (int) (maxPixValue); + + e.gc.drawString(String.valueOf(minStageVal), GAGE_RIGHT_X + + LARGE_HASH_MARK * 2, minYCoord - fontMid, true); + + double minDbl = minStageVal; + if (!gageData.getZeroDatum().equals(StaffGageDlg.MISSING)) { + minDbl = minStageVal + zeroDatum; + } + + String minStr = String.format("%7.2f", minDbl); + e.gc.drawString(minStr, LEFT_STAGE_LABEL_XCOORD, minYCoord + - fontMid, true); + + // + // Draw maximum label + // + int maxYCoord = (int) (GAGE_PIX_FROM_TOP); + e.gc.drawString(String.valueOf(maxStageVal), GAGE_RIGHT_X + + LARGE_HASH_MARK * 2, maxYCoord - fontMid, true); + + double maxDbl = maxStageVal; + if (!gageData.getZeroDatum().equals(StaffGageDlg.MISSING)) { + maxDbl = maxStageVal + zeroDatum; + } + + String maxStr = String.format("%7.2f", maxDbl); + e.gc.drawString(maxStr, LEFT_STAGE_LABEL_XCOORD, maxYCoord + - fontMid, true); + + // + // Draw Major Category + // + double majorY = majorStg - minStageVal; + + int majorYCoord = (int) (maxPixValue - Math + .round((majorY * pixelsPerInc))); + + if (majorStg > 0.0) { + e.gc.drawString("Major", LEFT_LABEL_XCOORD, majorYCoord + - fontMid, true); + if (moderStg > 0.0) { + e.gc.drawLine(VERT_STAGE_LINE_XCOORD, majorYCoord, + VERT_STAGE_LINE_XCOORD + LARGE_HASH_MARK, + majorYCoord); + } + double majDbl = 0.0; + if (!gageData.getZeroDatum().equals(StaffGageDlg.MISSING)) { + majDbl = majorStg + zeroDatum; + } + + String majStr = String.format("%7.2f", majDbl); + e.gc.drawString(majStr, LEFT_STAGE_LABEL_XCOORD, majorYCoord + - fontMid, true); + + e.gc.drawString(gageData.getMajorCatStage(), GAGE_RIGHT_X + + LARGE_HASH_MARK * 2, majorYCoord - fontMid, true); + } + // + // Draw Moderate Category + // + double moderY = moderStg - minStageVal; + + int modYCoord = (int) (maxPixValue - Math + .round((moderY * pixelsPerInc))); + + if (moderStg > 0.0) { + e.gc.drawString("Moderate", LEFT_LABEL_XCOORD, modYCoord + - fontMid, true); + if (minorStg > 0.0) { + e.gc.drawLine(VERT_STAGE_LINE_XCOORD, modYCoord, + VERT_STAGE_LINE_XCOORD + LARGE_HASH_MARK, modYCoord); + } + + double modDbl = 0.0; + if (!gageData.getZeroDatum().equals(StaffGageDlg.MISSING)) { + modDbl = moderStg + zeroDatum; + } + + String modStr = String.format("%7.2f", modDbl); + e.gc.drawString(modStr, LEFT_STAGE_LABEL_XCOORD, modYCoord + - fontMid, true); + e.gc.drawString(gageData.getModCatStage(), GAGE_RIGHT_X + + LARGE_HASH_MARK * 2, modYCoord - fontMid, true); + } + + // Draw Minor Category + // + + double minorY = minorStg - minStageVal; + + int minorYCoord = (int) (maxPixValue - Math + .round((minorY * pixelsPerInc))); + + if (minorStg > 0.0) { + e.gc.drawString("Minor", LEFT_LABEL_XCOORD, minorYCoord + - fontMid, true); + if (moderStg > 0.0) { + e.gc.drawLine(VERT_STAGE_LINE_XCOORD, minorYCoord, + VERT_STAGE_LINE_XCOORD + LARGE_HASH_MARK, + minorYCoord); + } + double minorDbl = 0.0; + if (!gageData.getZeroDatum().equals(StaffGageDlg.MISSING)) { + minorDbl = minorStg + zeroDatum; + } + + String minorStr = String.format("%7.2f", minorDbl); + e.gc.drawString(minorStr, LEFT_STAGE_LABEL_XCOORD, minorYCoord + - fontMid, true); + + e.gc.drawString(gageData.getMinorCatStage(), GAGE_RIGHT_X + + LARGE_HASH_MARK * 2, minorYCoord - fontMid, true); + } + + // Draw vertical stage line + // + + if (minorStg > 0.0 && majorStg > 0.0) { + e.gc.drawLine(VERT_STAGE_LINE_XCOORD, minorYCoord, + VERT_STAGE_LINE_XCOORD, majorYCoord); + } + + // draw the line from rec to major in case the record is + // outside the major value + if (recordStg > 0.0 && majorStg > 0.0) { + e.gc.drawLine(VERT_STAGE_LINE_XCOORD, recordYCoord, + VERT_STAGE_LINE_XCOORD, majorYCoord); + } + // + // Draw flood stage + // + double floodY = floodStgNum - minStageVal; + + int floodYCoord = (int) (maxPixValue - Math + .round((floodY * pixelsPerInc))); + if (floodStgNum > 0.0) { + String floodStr = String.valueOf(gageData.getFloodStage()) + + " Flood Stg"; + e.gc.drawString(floodStr, GAGE_RIGHT_X + LARGE_HASH_MARK * 2, + floodYCoord - fontMid, true); + } + // Draw action stage + + double actionY = actionStgNum - minStageVal; + + int actionYCoord = (int) (maxPixValue - Math + .round((actionY * pixelsPerInc))); + + if (actionStgNum > 0.0) { + String actionStr = String.valueOf(gageData.getActionStage()) + + " Action Stg"; + e.gc.drawString(actionStr, GAGE_RIGHT_X + LARGE_HASH_MARK * 2, + actionYCoord - fontMid, true); + + double actionDbl = 0.0; + if (!gageData.getZeroDatum().equals(StaffGageDlg.MISSING)) { + actionDbl = actionStgNum + zeroDatum; + } + String actionStr1 = String.format("%7.2f", actionDbl); + e.gc.drawString(actionStr1, LEFT_STAGE_LABEL_XCOORD, + actionYCoord - fontMid, true); + } + // Draw Bankfull stage + + double BankFullStgY = BankFullStg - minStageVal; + + int BankFullYCoord = (int) (maxPixValue - Math + .round((BankFullStgY * pixelsPerInc))); + + if (BankFullStg > 0.0) { + String BankFullStr = String + .valueOf(gageData.getBankfullStage()); + e.gc.drawString(BankFullStr, + GAGE_RIGHT_X + LARGE_HASH_MARK * 2, BankFullYCoord + - fontMid, true); + + double bankfDbl = 0.0; + if (!gageData.getZeroDatum().equals(StaffGageDlg.MISSING)) { + bankfDbl = BankFullStg + zeroDatum; + } + + String bankfStr = String.format("%7.2f", bankfDbl); + e.gc.drawString(bankfStr, LEFT_STAGE_LABEL_XCOORD, + BankFullYCoord - fontMid, true); + } + } + } + /** - * calculate minimum stage value + * calculate minimum stage value **/ - - public double calcMinStage( ) { - double minStageVal= DEFAULT_MIN; - double lMin=0.0; - double tmpMin = 0.0; - /* - Compare min to each of the significant stage - values and determine the minimum. - */ - if ((Double.valueOf(gageData.getMinorCatStage()) < minStageVal ) - && (Double.valueOf(gageData.getMinorCatStage()) > 0.0)) - minStageVal = Double.valueOf(gageData.getMinorCatStage()); - - if ((Double.valueOf(gageData.getModCatStage()) < minStageVal) - && (Double.valueOf(gageData.getModCatStage()) > 0.0)) - minStageVal = Double.valueOf(gageData.getModCatStage()); - - if ((Double.valueOf(gageData.getMajorCatStage()) < minStageVal) - && (Double.valueOf(gageData.getMajorCatStage()) > 0.0)) - minStageVal = Double.valueOf(gageData.getMajorCatStage()); - if ((Double.valueOf(gageData.getRecordStage()) < minStageVal) - && (Double.valueOf(gageData.getRecordStage()) > 0.0)) - minStageVal = Double.valueOf(gageData.getRecordStage()); + public double calcMinStage() { + double minStageVal = DEFAULT_MIN; + double lMin = 0.0; + double tmpMin = 0.0; + /* + * Compare min to each of the significant stage values and determine the + * minimum. + */ + if ((Double.valueOf(gageData.getMinorCatStage()) < minStageVal) + && (Double.valueOf(gageData.getMinorCatStage()) > 0.0)) + minStageVal = Double.valueOf(gageData.getMinorCatStage()); - if ((Double.valueOf(gageData.getFloodStage()) < minStageVal) - && (Double.valueOf(gageData.getFloodStage()) > 0.0)) - minStageVal = Double.valueOf(gageData.getFloodStage()); + if ((Double.valueOf(gageData.getModCatStage()) < minStageVal) + && (Double.valueOf(gageData.getModCatStage()) > 0.0)) + minStageVal = Double.valueOf(gageData.getModCatStage()); - if (( Double.valueOf(gageData.getActionStage()) < minStageVal) - && (Double.valueOf(gageData.getActionStage()) > 0.0)) - minStageVal = Double.valueOf(gageData.getActionStage()); + if ((Double.valueOf(gageData.getMajorCatStage()) < minStageVal) + && (Double.valueOf(gageData.getMajorCatStage()) > 0.0)) + minStageVal = Double.valueOf(gageData.getMajorCatStage()); + + if ((Double.valueOf(gageData.getRecordStage()) < minStageVal) + && (Double.valueOf(gageData.getRecordStage()) > 0.0)) + minStageVal = Double.valueOf(gageData.getRecordStage()); + + if ((Double.valueOf(gageData.getFloodStage()) < minStageVal) + && (Double.valueOf(gageData.getFloodStage()) > 0.0)) + minStageVal = Double.valueOf(gageData.getFloodStage()); + + if ((Double.valueOf(gageData.getActionStage()) < minStageVal) + && (Double.valueOf(gageData.getActionStage()) > 0.0)) + minStageVal = Double.valueOf(gageData.getActionStage()); + + if ((Double.valueOf(gageData.getBankfullStage()) < minStageVal) + && (Double.valueOf(gageData.getBankfullStage()) > 0.0)) + minStageVal = Double.valueOf(gageData.getBankfullStage()); + + // Round to the nearest multiple of five (5) - if (( Double.valueOf(gageData.getBankfullStage()) < minStageVal) - && (Double.valueOf(gageData.getBankfullStage())> 0.0)) - minStageVal = Double.valueOf(gageData.getBankfullStage()); - - //Round to the nearest multiple of five (5) - if ((minStageVal > 0.0) && (minStageVal < DEFAULT_MIN)) { - tmpMin = minStageVal; - lMin = (long) Math.floor (minStageVal / 5); - minStageVal = lMin * 5; - - //extend the max value if min value and the nearest stage are within 1.0 ft of each other - - if ((tmpMin - minStageVal) < 1.0) { - minStageVal -= 2.0; - } - - } else { - minStageVal=0.0; - } - - return minStageVal; - } - /** - * calculate maximum stage value - **/ - - public double calcMaxStage( ) { - - double maxStageVal= DEFAULT_MAX; - double lMax=0.0; - double tmpMax = 0.0; - /* - Compare max to each of the significant stage values and - determine the maximum. - */ - if ((Double.valueOf(gageData.getMinorCatStage()) > maxStageVal ) - && (Double.valueOf(gageData.getMinorCatStage()) > 0.0)) - maxStageVal = Double.valueOf(gageData.getMinorCatStage()); - - if ((Double.valueOf(gageData.getModCatStage()) > maxStageVal) - && (Double.valueOf(gageData.getModCatStage()) > 0.0)) - maxStageVal = Double.valueOf(gageData.getModCatStage()); - - if ((Double.valueOf(gageData.getMajorCatStage()) > maxStageVal) - && (Double.valueOf(gageData.getMajorCatStage()) > 0.0)) - maxStageVal = Double.valueOf(gageData.getMajorCatStage()); + tmpMin = minStageVal; + lMin = (long) Math.floor(minStageVal / 5); + minStageVal = lMin * 5; - if ((Double.valueOf(gageData.getRecordStage()) > maxStageVal) - && (Double.valueOf(gageData.getRecordStage()) > 0.0)) - maxStageVal = Double.valueOf(gageData.getRecordStage()); + // extend the max value if min value and the nearest stage are + // within 1.0 ft of each other - if ((Double.valueOf(gageData.getFloodStage()) > maxStageVal) - && (Double.valueOf(gageData.getFloodStage()) > 0.0)) - maxStageVal = Double.valueOf(gageData.getFloodStage()); + if ((tmpMin - minStageVal) < 1.0) { + minStageVal -= 2.0; + } - if (( Double.valueOf(gageData.getActionStage()) > maxStageVal) - && (Double.valueOf(gageData.getActionStage()) > 0.0)) - maxStageVal = Double.valueOf(gageData.getActionStage()); - - if (( Double.valueOf(gageData.getBankfullStage()) > maxStageVal) - && (Double.valueOf(gageData.getBankfullStage())> 0.0)) - maxStageVal = Double.valueOf(gageData.getBankfullStage()); - - if ( maxStageVal > DEFAULT_MAX ) { - tmpMax = maxStageVal; - lMax = (long)Math.floor (maxStageVal / 5); - maxStageVal = (lMax + 1) * 5; - - /* - If the max value and the nearest stage are within 1.0 ft of - each other, extend the max value. - */ - if ((maxStageVal - tmpMax ) < 1.0) { - maxStageVal += 2.0; - } - + } else { + minStageVal = 0.0; } - - return maxStageVal; + + return minStageVal; } - + + /** + * calculate maximum stage value + **/ + + public double calcMaxStage() { + + double maxStageVal = DEFAULT_MAX; + double lMax = 0.0; + double tmpMax = 0.0; + /* + * Compare max to each of the significant stage values and determine the + * maximum. + */ + if ((Double.valueOf(gageData.getMinorCatStage()) > maxStageVal) + && (Double.valueOf(gageData.getMinorCatStage()) > 0.0)) + maxStageVal = Double.valueOf(gageData.getMinorCatStage()); + + if ((Double.valueOf(gageData.getModCatStage()) > maxStageVal) + && (Double.valueOf(gageData.getModCatStage()) > 0.0)) + maxStageVal = Double.valueOf(gageData.getModCatStage()); + + if ((Double.valueOf(gageData.getMajorCatStage()) > maxStageVal) + && (Double.valueOf(gageData.getMajorCatStage()) > 0.0)) + maxStageVal = Double.valueOf(gageData.getMajorCatStage()); + + if ((Double.valueOf(gageData.getRecordStage()) > maxStageVal) + && (Double.valueOf(gageData.getRecordStage()) > 0.0)) + maxStageVal = Double.valueOf(gageData.getRecordStage()); + + if ((Double.valueOf(gageData.getFloodStage()) > maxStageVal) + && (Double.valueOf(gageData.getFloodStage()) > 0.0)) + maxStageVal = Double.valueOf(gageData.getFloodStage()); + + if ((Double.valueOf(gageData.getActionStage()) > maxStageVal) + && (Double.valueOf(gageData.getActionStage()) > 0.0)) + maxStageVal = Double.valueOf(gageData.getActionStage()); + + if ((Double.valueOf(gageData.getBankfullStage()) > maxStageVal) + && (Double.valueOf(gageData.getBankfullStage()) > 0.0)) + maxStageVal = Double.valueOf(gageData.getBankfullStage()); + + if (maxStageVal > DEFAULT_MAX) { + tmpMax = maxStageVal; + lMax = (long) Math.floor(maxStageVal / 5); + maxStageVal = (lMax + 1) * 5; + + /* + * If the max value and the nearest stage are within 1.0 ft of each + * other, extend the max value. + */ + if ((maxStageVal - tmpMax) < 1.0) { + maxStageVal += 2.0; + } + + } + + return maxStageVal; + } + } - - - - \ No newline at end of file diff --git a/cave/com.raytheon.viz.hydro/src/com/raytheon/viz/hydro/stationreporting/StationReportingStatusDlg.java b/cave/com.raytheon.viz.hydro/src/com/raytheon/viz/hydro/stationreporting/StationReportingStatusDlg.java index 1cbc7c57b1..c2e3768524 100644 --- a/cave/com.raytheon.viz.hydro/src/com/raytheon/viz/hydro/stationreporting/StationReportingStatusDlg.java +++ b/cave/com.raytheon.viz.hydro/src/com/raytheon/viz/hydro/stationreporting/StationReportingStatusDlg.java @@ -69,6 +69,7 @@ import com.raytheon.viz.ui.dialogs.CaveSWTDialog; * 21 Feb 2010 2915 mpduff Fixed Time Zone problem. * 23 Feb 2010 4303 mpduff Changed the "missing" date display to be N/A. * 16 Apr 2013 1790 rferrel Make dialog non-blocking. + * 09 Sep 2013 #2349 lvenable Fixed Font memory leak. * * * @@ -195,7 +196,13 @@ public class StationReportingStatusDlg extends CaveSWTDialog { */ @Override protected void disposed() { - font.dispose(); + if (font != null) { + font.dispose(); + } + + if (controlFont != null) { + controlFont.dispose(); + } } /* @@ -632,7 +639,7 @@ public class StationReportingStatusDlg extends CaveSWTDialog { for (StationReportingData currData : obsForLid) { String entry = String .format("%-8s %-3s %-5d %-4s %-2s %-17s %-8.2f %-2s %-2s %-2s %-11s %-16s %-16s", // - currData.getLid(), // + currData.getLid(), // currData.getPe(),// currData.getDur(), // currData.getTs(), // diff --git a/cave/com.raytheon.viz.hydrocommon/src/com/raytheon/viz/hydrocommon/ratingcurve/RatingCurveCanvasComp.java b/cave/com.raytheon.viz.hydrocommon/src/com/raytheon/viz/hydrocommon/ratingcurve/RatingCurveCanvasComp.java index 079161915a..f3bfee6259 100644 --- a/cave/com.raytheon.viz.hydrocommon/src/com/raytheon/viz/hydrocommon/ratingcurve/RatingCurveCanvasComp.java +++ b/cave/com.raytheon.viz.hydrocommon/src/com/raytheon/viz/hydrocommon/ratingcurve/RatingCurveCanvasComp.java @@ -22,6 +22,8 @@ package com.raytheon.viz.hydrocommon.ratingcurve; import java.util.List; import org.eclipse.swt.SWT; +import org.eclipse.swt.events.DisposeEvent; +import org.eclipse.swt.events.DisposeListener; import org.eclipse.swt.events.MouseEvent; import org.eclipse.swt.events.MouseListener; import org.eclipse.swt.events.MouseMoveListener; @@ -44,6 +46,7 @@ import org.eclipse.swt.widgets.Composite; * ------------ ---------- ----------- -------------------------- * Sep 8, 2008 lvenable Initial creation * Jul 15, 2013 2088 rferrel Code clean part of non-blocking dialogs. + * 09 Sep 2013 #2349 lvenable Fixed Font memory leak. * * * @@ -279,6 +282,15 @@ public class RatingCurveCanvasComp extends Canvas { calcMaxStageMaxFlow(); calcPixelsPerIncrement(); setupCanvas(); + + parent.addDisposeListener(new DisposeListener() { + @Override + public void widgetDisposed(DisposeEvent e) { + if (canvasFont != null) { + canvasFont.dispose(); + } + } + }); } /**