Issue #2427. Fixed memory leak for images

Former-commit-id: 5dcf4a00bc [formerly 012497bfef] [formerly 5dcf4a00bc [formerly 012497bfef] [formerly f0aba7be10 [formerly 770bfd43e07cd92c2c8a3d7b3d1a07eb6d8b1052]]]
Former-commit-id: f0aba7be10
Former-commit-id: 09f00e1d81 [formerly 0b08d2bb0e]
Former-commit-id: 001a2d3cfc
This commit is contained in:
Slav Korolev 2013-10-10 09:34:24 -04:00
parent 47ff31848c
commit 3271455caf

View file

@ -41,6 +41,7 @@ import org.eclipse.swt.widgets.Shell;
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jun 20, 2012 687 lvenable Initial creation
* Oct 10, 2013 2427 skorolev Fixed memory leak for images
*
* </pre>
*
@ -103,7 +104,8 @@ public class PriorityImages {
* Priority enumeration.
*/
public enum Priority {
Priority1(1, "Crit"), Priority2(2, "Warn"), Priority3(3, "Stat"), Priority4(4, "Info"), Priority5(5, "Gen");
Priority1(1, "Crit"), Priority2(2, "Warn"), Priority3(3, "Stat"), Priority4(
4, "Info"), Priority5(5, "Gen");
private int priNum;
@ -151,26 +153,38 @@ public class PriorityImages {
* Initialize method.
*/
private void init() {
priorityFont = new Font(parentShell.getDisplay(), "Monospace", 10, SWT.BOLD);
priorityFont = new Font(parentShell.getDisplay(), "Monospace", 10,
SWT.BOLD);
offWhite = new Color(parentShell.getDisplay(), 255, 255, 254);
calculateFontWidth();
parentShell.addDisposeListener(new DisposeListener() {
/*
* (non-Javadoc)
*
* @see
* org.eclipse.swt.events.DisposeListener#widgetDisposed(org.eclipse
* .swt.events.DisposeEvent)
*/
@Override
public void widgetDisposed(DisposeEvent e) {
for (Image i : colorImgs) {
i.dispose();
}
for (Image i : colorNumImgs) {
i.dispose();
}
for (Image i : colorNumNameImgs) {
i.dispose();
}
for (Image i : numImgs) {
i.dispose();
}
for (Image i : numNameImgs) {
i.dispose();
}
priorityFont.dispose();
offWhite.dispose();
}
});
@ -201,7 +215,8 @@ public class PriorityImages {
int whitePixel = idata.palette.getPixel(new RGB(255, 255, 255));
idata.transparentPixel = whitePixel;
Image transparentIdeaImage = new Image(parentShell.getDisplay(), idata);
Image transparentIdeaImage = new Image(parentShell.getDisplay(),
idata);
colorImgs[p.ordinal()] = transparentIdeaImage;
gc.dispose();
@ -221,15 +236,20 @@ public class PriorityImages {
* @param pri
* Priority.
*/
private void drawPriColorImage(GC gc, int imgWidth, int imgHeight, Priority pri) {
private void drawPriColorImage(GC gc, int imgWidth, int imgHeight,
Priority pri) {
gc.setBackground(getColrByPriority(pri));
gc.setForeground(getColrByPriority(pri));
gc.fillOval(imgWidth / 2 - imgHeight / 2, 1, imgHeight - 2, imgHeight - 2);
gc.fillOval(imgWidth / 2 - imgHeight / 2, 1, imgHeight - 2,
imgHeight - 2);
gc.setLineWidth(2);
gc.setBackground(parentShell.getDisplay().getSystemColor(SWT.COLOR_BLACK));
gc.setForeground(parentShell.getDisplay().getSystemColor(SWT.COLOR_BLACK));
gc.drawOval(imgWidth / 2 - imgHeight / 2, 1, imgHeight - 2, imgHeight - 2);
gc.setBackground(parentShell.getDisplay().getSystemColor(
SWT.COLOR_BLACK));
gc.setForeground(parentShell.getDisplay().getSystemColor(
SWT.COLOR_BLACK));
gc.drawOval(imgWidth / 2 - imgHeight / 2, 1, imgHeight - 2,
imgHeight - 2);
}
/**
@ -252,7 +272,8 @@ public class PriorityImages {
int whitePixel = idata.palette.getPixel(new RGB(255, 255, 255));
idata.transparentPixel = whitePixel;
Image transparentIdeaImage = new Image(parentShell.getDisplay(), idata);
Image transparentIdeaImage = new Image(parentShell.getDisplay(),
idata);
colorNumImgs[p.ordinal()] = transparentIdeaImage;
img.dispose();
@ -271,19 +292,25 @@ public class PriorityImages {
* @param pri
* Priority.
*/
private void drawPriColorNumImage(GC gc, int imgWidth, int imgHeight, Priority pri) {
private void drawPriColorNumImage(GC gc, int imgWidth, int imgHeight,
Priority pri) {
gc.setLineWidth(3);
gc.setBackground(offWhite);
gc.fillOval(imgWidth / 2 - imgHeight / 2, 1, imgHeight - 3, imgHeight - 3);
gc.fillOval(imgWidth / 2 - imgHeight / 2, 1, imgHeight - 3,
imgHeight - 3);
gc.setBackground(getColrByPriority(pri));
gc.setForeground(getColrByPriority(pri));
gc.drawOval(imgWidth / 2 - imgHeight / 2, 1, imgHeight - 3, imgHeight - 3);
gc.drawOval(imgWidth / 2 - imgHeight / 2, 1, imgHeight - 3,
imgHeight - 3);
gc.setBackground(parentShell.getDisplay().getSystemColor(SWT.COLOR_BLACK));
gc.setForeground(parentShell.getDisplay().getSystemColor(SWT.COLOR_BLACK));
gc.drawString(String.valueOf(pri.getPriorityNum()), imgWidth / 2 - fontWidth / 2, 2, true);
gc.setBackground(parentShell.getDisplay().getSystemColor(
SWT.COLOR_BLACK));
gc.setForeground(parentShell.getDisplay().getSystemColor(
SWT.COLOR_BLACK));
gc.drawString(String.valueOf(pri.getPriorityNum()), imgWidth / 2
- fontWidth / 2, 2, true);
}
/**
@ -310,7 +337,8 @@ public class PriorityImages {
int whitePixel = idata.palette.getPixel(new RGB(255, 255, 255));
idata.transparentPixel = whitePixel;
Image transparentIdeaImage = new Image(parentShell.getDisplay(), idata);
Image transparentIdeaImage = new Image(parentShell.getDisplay(),
idata);
colorNumNameImgs[p.ordinal()] = transparentIdeaImage;
img.dispose();
@ -329,7 +357,8 @@ public class PriorityImages {
* @param pri
* Priority.
*/
private void drawPriColorNumNameImage(GC gc, int imgWidth, int imgHeight, Priority pri) {
private void drawPriColorNumNameImage(GC gc, int imgWidth, int imgHeight,
Priority pri) {
gc.setLineWidth(3);
gc.setBackground(offWhite);
@ -339,8 +368,10 @@ public class PriorityImages {
gc.setForeground(getColrByPriority(pri));
gc.drawRoundRectangle(3, 1, imgWidth - 6, imgHeight - 3, 15, 15);
gc.setBackground(parentShell.getDisplay().getSystemColor(SWT.COLOR_BLACK));
gc.setForeground(parentShell.getDisplay().getSystemColor(SWT.COLOR_BLACK));
gc.setBackground(parentShell.getDisplay().getSystemColor(
SWT.COLOR_BLACK));
gc.setForeground(parentShell.getDisplay().getSystemColor(
SWT.COLOR_BLACK));
String s = pri.getPriorityNum() + dash + pri.priName;
int strPixels = s.length() * fontWidth / 2;
@ -368,7 +399,8 @@ public class PriorityImages {
int whitePixel = idata.palette.getPixel(new RGB(255, 255, 255));
idata.transparentPixel = whitePixel;
Image transparentIdeaImage = new Image(parentShell.getDisplay(), idata);
Image transparentIdeaImage = new Image(parentShell.getDisplay(),
idata);
numImgs[p.ordinal()] = transparentIdeaImage;
img.dispose();
@ -387,11 +419,15 @@ public class PriorityImages {
* @param pri
* Priority.
*/
private void drawPriNumImage(GC gc, int imgWidth, int imgHeight, Priority pri) {
private void drawPriNumImage(GC gc, int imgWidth, int imgHeight,
Priority pri) {
gc.setBackground(parentShell.getDisplay().getSystemColor(SWT.COLOR_BLACK));
gc.setForeground(parentShell.getDisplay().getSystemColor(SWT.COLOR_BLACK));
gc.drawString(String.valueOf(pri.getPriorityNum()), imgWidth / 2 - fontWidth / 2, 2, true);
gc.setBackground(parentShell.getDisplay().getSystemColor(
SWT.COLOR_BLACK));
gc.setForeground(parentShell.getDisplay().getSystemColor(
SWT.COLOR_BLACK));
gc.drawString(String.valueOf(pri.getPriorityNum()), imgWidth / 2
- fontWidth / 2, 2, true);
}
/**
@ -417,7 +453,8 @@ public class PriorityImages {
int whitePixel = idata.palette.getPixel(new RGB(255, 255, 255));
idata.transparentPixel = whitePixel;
Image transparentIdeaImage = new Image(parentShell.getDisplay(), idata);
Image transparentIdeaImage = new Image(parentShell.getDisplay(),
idata);
numNameImgs[p.ordinal()] = transparentIdeaImage;
img.dispose();
@ -436,9 +473,12 @@ public class PriorityImages {
* @param pri
* Priority.
*/
private void drawPriNumNameImage(GC gc, int imgWidth, int imgHeight, Priority pri) {
gc.setBackground(parentShell.getDisplay().getSystemColor(SWT.COLOR_BLACK));
gc.setForeground(parentShell.getDisplay().getSystemColor(SWT.COLOR_BLACK));
private void drawPriNumNameImage(GC gc, int imgWidth, int imgHeight,
Priority pri) {
gc.setBackground(parentShell.getDisplay().getSystemColor(
SWT.COLOR_BLACK));
gc.setForeground(parentShell.getDisplay().getSystemColor(
SWT.COLOR_BLACK));
String s = pri.getPriorityNum() + dash + pri.priName;
int strPixels = s.length() * fontWidth / 2;
@ -498,17 +538,13 @@ public class PriorityImages {
public Image getImage(Priority pri) {
if (selectedDisplay == PriorityDisplay.Color) {
return colorImgs[pri.ordinal()];
}
else if (selectedDisplay == PriorityDisplay.ColorNum) {
} else if (selectedDisplay == PriorityDisplay.ColorNum) {
return colorNumImgs[pri.ordinal()];
}
else if (selectedDisplay == PriorityDisplay.ColorNumName) {
} else if (selectedDisplay == PriorityDisplay.ColorNumName) {
return colorNumNameImgs[pri.ordinal()];
}
else if (selectedDisplay == PriorityDisplay.Num) {
} else if (selectedDisplay == PriorityDisplay.Num) {
return numImgs[pri.ordinal()];
}
else if (selectedDisplay == PriorityDisplay.NumName) {
} else if (selectedDisplay == PriorityDisplay.NumName) {
return numNameImgs[pri.ordinal()];
}
return colorImgs[pri.ordinal()];
@ -524,17 +560,13 @@ public class PriorityImages {
private Color getColrByPriority(Priority pri) {
if (pri == Priority.Priority1) {
return parentShell.getDisplay().getSystemColor(SWT.COLOR_RED);
}
else if (pri == Priority.Priority2) {
} else if (pri == Priority.Priority2) {
return parentShell.getDisplay().getSystemColor(SWT.COLOR_YELLOW);
}
else if (pri == Priority.Priority3) {
} else if (pri == Priority.Priority3) {
return parentShell.getDisplay().getSystemColor(SWT.COLOR_GREEN);
}
else if (pri == Priority.Priority4) {
} else if (pri == Priority.Priority4) {
return parentShell.getDisplay().getSystemColor(SWT.COLOR_GRAY);
}
else if (pri == Priority.Priority5) {
} else if (pri == Priority.Priority5) {
return parentShell.getDisplay().getSystemColor(SWT.COLOR_BLUE);
}