From c328869516a6402307533c494d54ac3edacc98a1 Mon Sep 17 00:00:00 2001 From: Lee Venable Date: Mon, 7 Oct 2013 09:11:25 -0500 Subject: [PATCH] Issue #2436 - disposed of the sort color Former-commit-id: f27781b74e65a6b6228e21dee99f1128fe9f01a1 [formerly 8c8adf8be6855f3925da02eca48f258125a3d562] [formerly 9c97908f36e8703007b43872ba33ab8e95dfd56d] [formerly f27781b74e65a6b6228e21dee99f1128fe9f01a1 [formerly 8c8adf8be6855f3925da02eca48f258125a3d562] [formerly 9c97908f36e8703007b43872ba33ab8e95dfd56d] [formerly c4ddd46b44dd0e80d07530479f6cb413fb2c5f1b [formerly 9c97908f36e8703007b43872ba33ab8e95dfd56d [formerly 4545de35a0fdbfc5817a8725bf07ae0c405efb39]]]] Former-commit-id: c4ddd46b44dd0e80d07530479f6cb413fb2c5f1b Former-commit-id: ccbc44f9d3da16a8e78c7fca4daf3e7f8ec97402 [formerly 2ed106cac4a27e493a415aeff7473016ae9efb45] [formerly b50a8d2a19218358b07a31a6ee2f605c0ead6152 [formerly 46db8998a6fe521df6cfe3b419f2ba3e89331a66]] Former-commit-id: d130264f10b1958114f77cf64c39663d19c8c154 [formerly 1000147d0c319f5d4aa8a5285a5e3529d4621138] Former-commit-id: b0af7745a6f02230c332c2932aa98154a2c4b7e1 --- .../uf/viz/monitor/ui/dialogs/TableComp.java | 140 ++++++++++-------- 1 file changed, 76 insertions(+), 64 deletions(-) diff --git a/cave/com.raytheon.uf.viz.monitor/src/com/raytheon/uf/viz/monitor/ui/dialogs/TableComp.java b/cave/com.raytheon.uf.viz.monitor/src/com/raytheon/uf/viz/monitor/ui/dialogs/TableComp.java index baaa85e51c..df53549e3c 100644 --- a/cave/com.raytheon.uf.viz.monitor/src/com/raytheon/uf/viz/monitor/ui/dialogs/TableComp.java +++ b/cave/com.raytheon.uf.viz.monitor/src/com/raytheon/uf/viz/monitor/ui/dialogs/TableComp.java @@ -63,7 +63,8 @@ import com.raytheon.uf.viz.monitor.util.MonitorConfigConstants; * SOFTWARE HISTORY * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- - * Apr 7, 2009 lvenable Initial creation + * Apr 7, 2009 lvenable Initial creation + * Oct 7, 2013 #2436 lvenable Disposed of the sort color. * * * @@ -117,12 +118,16 @@ public abstract class TableComp extends Composite { protected int defaultColWidth; protected boolean columnMinimumSize = false; - + private int imageWidth = 0; + private int imageHeight = 0; + private int textWidth = 0; + private int textHeight = 0; - private Color sortColor; + + private Color sortColor; /** * A map that contains a table column and the sort direction. @@ -153,10 +158,10 @@ public abstract class TableComp extends Composite { * Initialize method. */ protected void init() { - tiFont = new Font(parent.getDisplay(), "Arial", 10, SWT.NORMAL); + tiFont = new Font(parent.getDisplay(), "Arial", 10, SWT.NORMAL); + + sortColor = new Color(parent.getDisplay(), 133, 104, 190); - sortColor = new Color(parent.getDisplay(), 133, 104, 190); - GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true); GridLayout gl = new GridLayout(1, false); gl.verticalSpacing = 2; @@ -166,7 +171,7 @@ public abstract class TableComp extends Composite { this.setLayoutData(gd); makeImageCalculations(); - + initData(); createSortImage(); @@ -185,6 +190,7 @@ public abstract class TableComp extends Composite { tiFont.dispose(); lineColor.dispose(); sortImage.dispose(); + sortColor.dispose(); } }); } @@ -206,10 +212,10 @@ public abstract class TableComp extends Composite { textHeight = gc.getFontMetrics().getHeight(); String[] columnKeys = getColumnKeys(appName); - - for ( String key : columnKeys ) { - String columnName = getColumnAttribteData(key).getColumnName(); - + + for (String key : columnKeys) { + String columnName = getColumnAttribteData(key).getColumnName(); + String[] nameArray = columnName.split("\n"); for (String tmpStr : nameArray) { @@ -224,7 +230,7 @@ public abstract class TableComp extends Composite { image.dispose(); } - /** + /** * Initialize the data. */ private void initData() { @@ -293,14 +299,14 @@ public abstract class TableComp extends Composite { } }); - - table.addMouseMoveListener(new MouseMoveListener () { - @Override - public void mouseMove(MouseEvent event) { - tableMouseHoverAction(event); - } + + table.addMouseMoveListener(new MouseMoveListener() { + @Override + public void mouseMove(MouseEvent event) { + tableMouseHoverAction(event); + } }); - + } /** @@ -338,13 +344,15 @@ public abstract class TableComp extends Composite { for (int j = 0; j < cols.length; j++) { cols[j].setImage(null); cols[j].setWidth(defaultColWidth); - cols[j].setText(getColumnAttribteData(colnkeys[j]).getColumnName()); + cols[j].setText(getColumnAttribteData(colnkeys[j]) + .getColumnName()); } /* * Set the sort image, pack the column and sort the data. */ - tc.setImage(getSortHeaderImage(getColumnAttribteData(sortCol).getColumnName())); + tc.setImage(getSortHeaderImage(getColumnAttribteData( + sortCol).getColumnName())); tc.setText(""); tc.pack(); @@ -356,17 +364,19 @@ public abstract class TableComp extends Composite { sortTableData(tc); } }); - + /** - * DR#10701: The first column is selected for - * sorting by default when a Zone table or Station - * table is first displayed (not for History table) + * DR#10701: The first column is selected for sorting by default + * when a Zone table or Station table is first displayed (not for + * History table) */ - if ( i == 0 ) { - if ( getColumnAttribteData(columns[i]).getSortDir() != SortDirection.None.getSortDir() ) { - tc.setText(""); - tc.setImage(getSortHeaderImage(getColumnAttribteData(columns[0]).getColumnName())); - } + if (i == 0) { + if (getColumnAttribteData(columns[i]).getSortDir() != SortDirection.None + .getSortDir()) { + tc.setText(""); + tc.setImage(getSortHeaderImage(getColumnAttribteData( + columns[0]).getColumnName())); + } } if (columnMinimumSize == true) { @@ -414,8 +424,8 @@ public abstract class TableComp extends Composite { for (int i = 0; i < cellData.length; i++) { ti.setText(i, cellData[i].displayString()); - Color c = new Color(parent.getDisplay(), cellData[i] - .getBackgroungRGB()); + Color c = new Color(parent.getDisplay(), + cellData[i].getBackgroungRGB()); ti.setBackground(i, c); c.dispose(); } @@ -462,12 +472,12 @@ public abstract class TableComp extends Composite { int columnIndex = getColumnIndex(appName, sortCol); - if ( sortCol == "SSZT_SwellPeriod" || sortCol == "SSZT_Swell2Period" ) { - if ( MonitorConfigConstants.isRankSwellPeriodHigh() ) { - sortDir = SWT.DOWN; - } else { - sortDir = SWT.UP; - } + if (sortCol == "SSZT_SwellPeriod" || sortCol == "SSZT_Swell2Period") { + if (MonitorConfigConstants.isRankSwellPeriodHigh()) { + sortDir = SWT.DOWN; + } else { + sortDir = SWT.UP; + } } tableData.setSortColumnAndDirection(columnIndex, sortDir); @@ -492,32 +502,34 @@ public abstract class TableComp extends Composite { gc.dispose(); } - + private Image getSortHeaderImage(String header) { - Image image = new Image(parent.getDisplay(), imageWidth, imageHeight); - GC gc = new GC(image); - gc.setFont(tiFont); - gc.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_WHITE)); - gc.setBackground(sortColor); - gc.fillRectangle(0, 0, imageWidth, imageHeight); - int xCoord = 0; - int yCoord = 0; - if ( header.indexOf("\n") > 0 ) { - String [] tmpArray = header.split("\n"); - int maxTextLen = tmpArray[0].length(); - for ( int j = 1; j < tmpArray.length; j++ ) { - if ( tmpArray[j].length() > maxTextLen ) { - maxTextLen = tmpArray[j].length(); - } - } - xCoord = Math.round( (imageWidth / 2) - (maxTextLen*textWidth / 2) ) - 2; - yCoord = 0; - } else { - xCoord = Math.round( (imageWidth / 2) - (header.length()*textWidth / 2) ) - 2; - yCoord = imageHeight / 2 - textHeight /2 - 1; - } - gc.drawText(header, xCoord, yCoord, true); - return image; + Image image = new Image(parent.getDisplay(), imageWidth, imageHeight); + GC gc = new GC(image); + gc.setFont(tiFont); + gc.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_WHITE)); + gc.setBackground(sortColor); + gc.fillRectangle(0, 0, imageWidth, imageHeight); + int xCoord = 0; + int yCoord = 0; + if (header.indexOf("\n") > 0) { + String[] tmpArray = header.split("\n"); + int maxTextLen = tmpArray[0].length(); + for (int j = 1; j < tmpArray.length; j++) { + if (tmpArray[j].length() > maxTextLen) { + maxTextLen = tmpArray[j].length(); + } + } + xCoord = Math + .round((imageWidth / 2) - (maxTextLen * textWidth / 2)) - 2; + yCoord = 0; + } else { + xCoord = Math.round((imageWidth / 2) + - (header.length() * textWidth / 2)) - 2; + yCoord = imageHeight / 2 - textHeight / 2 - 1; + } + gc.drawText(header, xCoord, yCoord, true); + return image; } /** @@ -591,7 +603,7 @@ public abstract class TableComp extends Composite { /** * Pack the table columns. */ - protected abstract void packColumns(); + protected abstract void packColumns(); protected abstract void tableColRightMouseAction(MouseEvent event);