Issue #1984 - Save images for table columns so they don't throw errors in Windows.

Change-Id: I42bb4549664296abde66d5904b0ce1739ba6232c

Former-commit-id: 3f26818dfeb006393598af41faf33cac6957d3e0
This commit is contained in:
Lee Venable 2013-06-04 15:46:05 -05:00
parent 2bb9f1ceec
commit 187a4e9b17
5 changed files with 75 additions and 60 deletions

View file

@ -69,6 +69,10 @@ import com.raytheon.uf.viz.monitor.ffmp.xml.FFMPTableColumnXML;
* Mar 15,2012 DR 14406 gzhang Fixing QPF Column Title Missing
* Mar 20,2012 DR 14250 gzhang Eliminating column Missing values
* Aug 01, 2012 14168 mpduff Only allow filtering if ColorCell is true
* Jun 04, 2013 #1984 lvenable Save images instead of disposing them when setting
* the table column images. This is to fix the Windows
* issue on the images being blank and throwing errors.
* Also cleaned up some code.
* </pre>
*
* @author lvenable
@ -149,12 +153,15 @@ public abstract class FFMPTable extends Composite {
protected int textHeight = 0;
private String centeredAggregateKey;
private ArrayList<Integer> indexArray = new ArrayList<Integer>();
private Point extent = new Point(0, 0);
/**
* Array of images displayed in the table columns.
*/
protected List<Image> columnImgs = new ArrayList<Image>();
/**
* Constructor.
*
@ -212,6 +219,7 @@ public abstract class FFMPTable extends Composite {
lineColor.dispose();
columnFont.dispose();
sortColor.dispose();
disposeColumnImages();
}
});
}
@ -677,10 +685,7 @@ public abstract class FFMPTable extends Composite {
}
}
imageWidth = maxTextLength * textWidth + EXTRA_COLUMN_WIDTH;// DR14406:
// old value
// 6 too
// small
imageWidth = maxTextLength * textWidth + EXTRA_COLUMN_WIDTH;
imageHeight = textHeight * 2;
gc.dispose();
@ -699,6 +704,8 @@ public abstract class FFMPTable extends Composite {
TableColumn tc;
disposeColumnImages();
// Loop over the column name keys
for (int i = 0; i < colNameKeys.length; i++) {
String colName = ffmpTableCfgData
@ -716,7 +723,6 @@ public abstract class FFMPTable extends Composite {
// Set the background color to the sort color if that column is
// sorted.
// if (table.indexOf(tc) == ffmpConfig.getStartSortIndex()) {
if (tc == sortedTableColumn) {
gc.setBackground(sortColor);
}
@ -731,47 +737,45 @@ public abstract class FFMPTable extends Composite {
int xCoord = 0;
int yCoord = 0;
if (colName.indexOf("\n") > 0) {
int maxTextLen = 0;
String[] tmpArray = colName.split("\n");
for (int j = 0; j < tmpArray.length; j++) {
// if (tmpArray[j].length() > maxTextLen) {
// maxTextLen = tmpArray[j].length();
// }
// }
/*
* Fixes for DR14406
*/
xCoord = Math.round((imageWidth / 2)
- (tmpArray[j].length() /*
* DR14406: old value:
* maxTextLen
*/* textWidth / 2));
yCoord = j * (textHeight + 1);// DR14406: old value 0 is
// only for the 1st line
gc.drawText(tmpArray[j], xCoord, yCoord, true);// DR14406:
// draw each
// line
// separately
- (tmpArray[j].length() * textWidth / 2));
yCoord = j * (textHeight + 1);
gc.drawText(tmpArray[j], xCoord, yCoord, true);
}
} else {
xCoord = Math.round((imageWidth / 2)
- (colName.length() * textWidth / 2));
yCoord = imageHeight / 2 - textHeight / 2 - 1;
gc.drawText(colName, xCoord, yCoord, true);// DR14406: draw text
// with a single line
gc.drawText(colName, xCoord, yCoord, true);
}
// System.out.println("Column name = " + colName);
// DR14406: move the below text drawing code into the if-else blocks
// gc.drawText(colName, xCoord, yCoord, true);
gc.dispose();
tc.setImage(img);
// Dispose of the image
img.dispose();
columnImgs.add(img);
}
}
/**
* Dispose of all the table column images and clear the array of images.
*/
protected void disposeColumnImages() {
for (Image img : columnImgs) {
if (img != null) {
img.dispose();
}
}
columnImgs.clear();
}
/**
* Get the list of visible table columns.
*
@ -818,8 +822,7 @@ public abstract class FFMPTable extends Composite {
tCols[i].setWidth(defaultColWidth);
}
setQPFColName(tCols[i], col);// DR14406: set QPF title with
// quicker response
setQPFColName(tCols[i], col);
} else {
tCols[i].setWidth(0);
}
@ -835,14 +838,6 @@ public abstract class FFMPTable extends Composite {
showHideTableColumns(attrData);
}
public void setCenteredAggregationKey(Object key) {
if (key instanceof Long) {
this.centeredAggregateKey = String.valueOf(key);
} else {
this.centeredAggregateKey = (String) key;
}
}
/**
* Handle the mouse button down on the table.
*

View file

@ -120,6 +120,7 @@ import com.raytheon.viz.ui.dialogs.ICloseCallback;
* Mar 29, 2013 1790 rferrel Bug fix for non-blocking dialogs.
* Apr 15, 2013 1904 mpduff Remove calls to reset FFMPConfig.
* Apr 25, 2013 1902 mpduff Fixed Thresholds dialog on multiple opens, needed an isDisposed check.
* Jun 04, 2013 #1984 lvenable removed unnecessary code.
* </pre>
*
* @author lvenable
@ -1751,8 +1752,6 @@ public class FfmpBasinTableDlg extends CaveSWTDialog implements
if (!ffmpTable.isDisposed()) {
this.mainTableData = tData;
ffmpTable.clearTableSelection();
ffmpTable
.setCenteredAggregationKey(resource.centeredAggregationKey);
ffmpTable.setTableData(mainTableData);
resetCursor();
shell.pack();

View file

@ -45,7 +45,9 @@ import com.raytheon.uf.viz.monitor.scan.commondialogs.IRequestTrendGraphData;
* ------------ ---------- ----------- --------------------------
* Dec 3, 2009 #3039 lvenable Initial creation
* Apr 29, 2013 #1945 lvenable Code cleanup for SCAN performance.
*
* Jun 04, 2013 #1984 lvenable Save images instead of disposing them when setting
* the table column images. This is to fix the Windows
* issue on the images being blank and throwing errors.
* </pre>
*
* @author lvenable
@ -227,6 +229,8 @@ public class SCANCellTableComp extends SCANTableTrendGraphLayer {
TableColumn[] tCols = table.getColumns();
disposeColumnImages();
for (int i = 0; i < tCols.length; i++) {
String colName = (String) tCols[i].getData();
Image img = new Image(this.getDisplay(), imageWidth, imageHeight);
@ -287,7 +291,7 @@ public class SCANCellTableComp extends SCANTableTrendGraphLayer {
gc.dispose();
tCols[i].setImage(img);
img.dispose();
columnImgs.add(img);
}
}
}

View file

@ -56,7 +56,9 @@ import com.raytheon.uf.viz.monitor.scan.commondialogs.TimeHeightDlg;
* Dec 3, 2009 #3039 lvenable Initial creation
* Apr 26, 2013 #1945 lvenable Improved SCAN performance, reworked
* some bad code, and some code cleanup.
*
* Jun 04, 2013 #1984 lvenable Save images instead of disposing them when setting
* the table column images. This is to fix the Windows
* issue on the images being blank and throwing errors.
* </pre>
*
* @author lvenable
@ -95,6 +97,8 @@ public class SCANDmdTableComp extends SCANTableTrendGraphLayer implements
TableColumn[] tCols = table.getColumns();
disposeColumnImages();
for (int i = 0; i < tCols.length; i++) {
String colName = (String) tCols[i].getData();
Image img = new Image(this.getDisplay(), imageWidth, imageHeight);
@ -141,7 +145,7 @@ public class SCANDmdTableComp extends SCANTableTrendGraphLayer implements
gc.dispose();
tCols[i].setImage(img);
img.dispose();
columnImgs.add(img);
}
}

View file

@ -22,6 +22,7 @@ package com.raytheon.uf.viz.monitor.scan.tables;
import java.awt.Toolkit;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Set;
import java.util.Timer;
import java.util.TimerTask;
@ -76,6 +77,10 @@ import com.raytheon.uf.viz.monitor.scan.tables.SCANAlarmAlertManager.AlertedAlar
* 03/15/2012 13939 Mike Duff For a SCAN Alarms issue
* Apr 29, 2013 #1945 lvenable Improved SCAN performance, reworked
* some bad code, and some code cleanup.
* Jun 04, 2013 #1984 lvenable Save images instead of disposing them when setting
* the table column images. This is to fix the Windows
* issue on the images being blank and throwing errors.
* Also cleaned up some code.
*
* </pre>
*
@ -151,6 +156,11 @@ public abstract class SCANTable extends Composite {
protected Point prevMousePt = new Point(-9999, -9999);
/**
* Array of images used for the table columns.
*/
protected List<Image> columnImgs = new ArrayList<Image>();
/**
* Last sorted column index. This is set to -2 because sortedColumnIndex is
* set to -1 and they should not have the same initial value at start up.
@ -221,6 +231,7 @@ public abstract class SCANTable extends Composite {
tiFont.dispose();
columnFont.dispose();
lineColor.dispose();
disposeColumnImages();
}
});
}
@ -237,15 +248,6 @@ public abstract class SCANTable extends Composite {
gd.heightHint = 175;
gd.widthHint = scanCfg.getDefaultTableWidth(scanTable);
boolean[] visCols = scanCfg.getVisibleColumns(scanTable);
int tableWidth = 0;
for (boolean b : visCols) {
if (b) {
tableWidth += defaultColWidth;
}
}
table = new Table(this, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
table.setLayoutData(gd);
table.setHeaderVisible(true);
@ -317,7 +319,6 @@ public abstract class SCANTable extends Composite {
public void mouseDown(MouseEvent event) {
tableMouseDownAction(event);
}
});
table.addMouseMoveListener(new MouseMoveListener() {
@ -770,8 +771,6 @@ public abstract class SCANTable extends Composite {
int maxColNameExtent = 0;
// TODO - use font extents
textWidth = gc.getFontMetrics().getAverageCharWidth();
textHeight = gc.getFontMetrics().getHeight();
@ -1060,6 +1059,8 @@ public abstract class SCANTable extends Composite {
TableColumn[] tCols = table.getColumns();
disposeColumnImages();
for (int i = 0; i < tCols.length; i++) {
String colName = (String) tCols[i].getData();
Image img = new Image(this.getDisplay(), imageWidth, imageHeight);
@ -1097,10 +1098,23 @@ public abstract class SCANTable extends Composite {
gc.dispose();
tCols[i].setImage(img);
img.dispose();
columnImgs.add(img);
}
}
/**
* Dispose of all the table column images and clear the array of images.
*/
protected void disposeColumnImages() {
for (Image img : columnImgs) {
if (img != null) {
img.dispose();
}
}
columnImgs.clear();
}
/**
* When the mouse enters the cell on the table this method is call to
* determine how to handle the action.
@ -1177,7 +1191,6 @@ public abstract class SCANTable extends Composite {
}
Rectangle rect;
// rect = item.getBounds(table.getColumnCount() - 1);
rect = item.getBounds(scanCfg.getCountyColumnIndex(scanTable));
if ((scanCfg.showTips(scanTable) == false)