Issue #2394 - fixed color memory leaks.
Former-commit-id: 527924d7beeffeafd3c6b22eb48102b3bd9803d6
This commit is contained in:
parent
8d3e7e1ace
commit
ae3a827130
1 changed files with 109 additions and 104 deletions
|
@ -40,11 +40,9 @@ import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Scanner;
|
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
@ -331,6 +329,7 @@ import com.raytheon.viz.ui.dialogs.SWTMessageBox;
|
||||||
* 25July2013 15733 GHull Read font and color prefs from TextEditorCfg.
|
* 25July2013 15733 GHull Read font and color prefs from TextEditorCfg.
|
||||||
* 23Aug2013 DR 16514 D. Friedman Fix handling of completed product requests. Do not change
|
* 23Aug2013 DR 16514 D. Friedman Fix handling of completed product requests. Do not change
|
||||||
* command history or close browser window for "update obs".
|
* command history or close browser window for "update obs".
|
||||||
|
* 20Sep2013 #2394 lvenable Fixed color memory leaks.
|
||||||
*
|
*
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
|
@ -344,7 +343,7 @@ public class TextEditorDialog extends CaveSWTDialog implements VerifyListener,
|
||||||
/**
|
/**
|
||||||
* Handler used for messges.
|
* Handler used for messges.
|
||||||
*/
|
*/
|
||||||
private static final transient IUFStatusHandler statusHandler = UFStatus
|
private final IUFStatusHandler statusHandler = UFStatus
|
||||||
.getHandler(TextEditorDialog.class);
|
.getHandler(TextEditorDialog.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -379,8 +378,6 @@ public class TextEditorDialog extends CaveSWTDialog implements VerifyListener,
|
||||||
*/
|
*/
|
||||||
private static final int UPDATE_FG = SWT.COLOR_WHITE;
|
private static final int UPDATE_FG = SWT.COLOR_WHITE;
|
||||||
|
|
||||||
private final int HIGHLIGHT_BG = SWT.COLOR_RED;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The length of BEGIN_ELEMENT_TAG.
|
* The length of BEGIN_ELEMENT_TAG.
|
||||||
*/
|
*/
|
||||||
|
@ -1088,11 +1085,6 @@ public class TextEditorDialog extends CaveSWTDialog implements VerifyListener,
|
||||||
*/
|
*/
|
||||||
private SearchReplaceDlg searchReplaceDlg;
|
private SearchReplaceDlg searchReplaceDlg;
|
||||||
|
|
||||||
/**
|
|
||||||
* Flag to indicate if the document being edited has been modified.
|
|
||||||
*/
|
|
||||||
private boolean dirty = false;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Flag to indicate if the document being edited has been saved.
|
* Flag to indicate if the document being edited has been saved.
|
||||||
*/
|
*/
|
||||||
|
@ -1373,15 +1365,17 @@ public class TextEditorDialog extends CaveSWTDialog implements VerifyListener,
|
||||||
*/
|
*/
|
||||||
private boolean isPreviousLineWrapped;
|
private boolean isPreviousLineWrapped;
|
||||||
|
|
||||||
private Color textForeground;
|
/** Text foregraound color. */
|
||||||
|
private Color textForegroundClr;
|
||||||
|
|
||||||
private Color textBackground;
|
/** Text background color. */
|
||||||
|
private Color textBackgroundClr;
|
||||||
|
|
||||||
private Color highlightForeground;
|
/** Highlight foreground color. */
|
||||||
|
private Color highlightForegroundClr;
|
||||||
|
|
||||||
private Color highlightBackground;
|
/** Highlight background color. */
|
||||||
|
private Color highlightBackgroundClr;
|
||||||
// protected Color color;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor with additional cave style rules
|
* Constructor with additional cave style rules
|
||||||
|
@ -2417,41 +2411,41 @@ public class TextEditorDialog extends CaveSWTDialog implements VerifyListener,
|
||||||
* Method to preserve the spacing in a bulleted section of text. Only
|
* Method to preserve the spacing in a bulleted section of text. Only
|
||||||
* applies to VTEC warning (vtecAfosProductEnum) type products.
|
* applies to VTEC warning (vtecAfosProductEnum) type products.
|
||||||
*/
|
*/
|
||||||
private void PreserveBulletedTextSpacing(StyledText st) {
|
// private void PreserveBulletedTextSpacing(StyledText st) {
|
||||||
// Capture the input from the styled text widget.
|
// // Capture the input from the styled text widget.
|
||||||
String in = st.getText();
|
// String in = st.getText();
|
||||||
// New up a Scanner to use to parse the text in the editor.
|
// // New up a Scanner to use to parse the text in the editor.
|
||||||
Scanner sc = new Scanner(in).useDelimiter("\\n");
|
// Scanner sc = new Scanner(in).useDelimiter("\\n");
|
||||||
// Declare variables for processing the editor's contents.
|
// // Declare variables for processing the editor's contents.
|
||||||
int thisLine = -1;
|
// int thisLine = -1;
|
||||||
String whatMatched;
|
// String whatMatched;
|
||||||
|
//
|
||||||
// Process the editor's contents.
|
// // Process the editor's contents.
|
||||||
while (sc.hasNext()) {
|
// while (sc.hasNext()) {
|
||||||
whatMatched = sc.next();
|
// whatMatched = sc.next();
|
||||||
thisLine++;
|
// thisLine++;
|
||||||
if ((whatMatched != null) && (sc.hasNext())
|
// if ((whatMatched != null) && (sc.hasNext())
|
||||||
&& (whatMatched.startsWith("*"))) {
|
// && (whatMatched.startsWith("*"))) {
|
||||||
while (sc.hasNext()) {
|
// while (sc.hasNext()) {
|
||||||
whatMatched = sc.next();
|
// whatMatched = sc.next();
|
||||||
thisLine++;
|
// thisLine++;
|
||||||
if ((whatMatched != null)
|
// if ((whatMatched != null)
|
||||||
&& (!(whatMatched.startsWith(" ")))
|
// && (!(whatMatched.startsWith(" ")))
|
||||||
&& (!(whatMatched.equals("")))) {
|
// && (!(whatMatched.equals("")))) {
|
||||||
// Indent the bullet list entry by one space.
|
// // Indent the bullet list entry by one space.
|
||||||
// If operator enables word wrap they are responsible
|
// // If operator enables word wrap they are responsible
|
||||||
// for reformatting bullet list items that span lines.
|
// // for reformatting bullet list items that span lines.
|
||||||
st.setCaretOffset(st.getOffsetAtLine(thisLine));
|
// st.setCaretOffset(st.getOffsetAtLine(thisLine));
|
||||||
st.insert(" ");
|
// st.insert(" ");
|
||||||
} else if ((whatMatched != null)
|
// } else if ((whatMatched != null)
|
||||||
&& (whatMatched.equals(""))) {
|
// && (whatMatched.equals(""))) {
|
||||||
break; // The end of bullet list is detected.
|
// break; // The end of bullet list is detected.
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method to create selection sub-menu.
|
* Method to create selection sub-menu.
|
||||||
|
@ -2766,8 +2760,6 @@ public class TextEditorDialog extends CaveSWTDialog implements VerifyListener,
|
||||||
|
|
||||||
autoWrapCfg = JAXB.unmarshal(path, AutoWrapCfg.class);
|
autoWrapCfg = JAXB.unmarshal(path, AutoWrapCfg.class);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
IUFStatusHandler statusHandler = UFStatus
|
|
||||||
.getHandler(TextEditorDialog.class);
|
|
||||||
statusHandler.handle(Priority.ERROR,
|
statusHandler.handle(Priority.ERROR,
|
||||||
"Unable to parse Autowrap menu configuration.", e);
|
"Unable to parse Autowrap menu configuration.", e);
|
||||||
autoWrapCfg = new AutoWrapCfg();
|
autoWrapCfg = new AutoWrapCfg();
|
||||||
|
@ -3753,8 +3745,8 @@ public class TextEditorDialog extends CaveSWTDialog implements VerifyListener,
|
||||||
|
|
||||||
// textColorCfg = getTextColorCfg();
|
// textColorCfg = getTextColorCfg();
|
||||||
setDefaultTextColor(TextEditorCfg.getTextEditorCfg());
|
setDefaultTextColor(TextEditorCfg.getTextEditorCfg());
|
||||||
textEditor.setForeground(textForeground);
|
textEditor.setForeground(textForegroundClr);
|
||||||
textEditor.setBackground(textBackground);
|
textEditor.setBackground(textBackgroundClr);
|
||||||
|
|
||||||
textEditor.addSelectionListener(new SelectionListener() {
|
textEditor.addSelectionListener(new SelectionListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -3771,8 +3763,8 @@ public class TextEditorDialog extends CaveSWTDialog implements VerifyListener,
|
||||||
// String slctText = stylText.getSelectionText();
|
// String slctText = stylText.getSelectionText();
|
||||||
// int length = slctText.length();
|
// int length = slctText.length();
|
||||||
|
|
||||||
stylText.setSelectionBackground(highlightBackground);
|
stylText.setSelectionBackground(highlightBackgroundClr);
|
||||||
stylText.setSelectionForeground(highlightForeground);
|
stylText.setSelectionForeground(highlightForegroundClr);
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -3900,14 +3892,6 @@ public class TextEditorDialog extends CaveSWTDialog implements VerifyListener,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
textEditor.addModifyListener(new ModifyListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void modifyText(ModifyEvent e) {
|
|
||||||
// when we modify the text, we want to set the 'dirty' flag.
|
|
||||||
dirty = true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
textEditor.addMouseListener(new MouseListener() {
|
textEditor.addMouseListener(new MouseListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -3985,15 +3969,14 @@ public class TextEditorDialog extends CaveSWTDialog implements VerifyListener,
|
||||||
// return textColorsCfg;
|
// return textColorsCfg;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
private void setDefaultTextColor(TextEditorCfg txtClrCfg) {
|
private void setDefaultTextColor(TextEditorCfg txtClrCfg) {
|
||||||
textBackground = new Color(shell.getDisplay(),
|
textBackgroundClr = new Color(shell.getDisplay(),
|
||||||
txtClrCfg.getTextBackgroundColor());
|
txtClrCfg.getTextBackgroundColor());
|
||||||
textForeground = new Color(shell.getDisplay(),
|
textForegroundClr = new Color(shell.getDisplay(),
|
||||||
txtClrCfg.getTextForegroundColor());
|
txtClrCfg.getTextForegroundColor());
|
||||||
highlightBackground = new Color(shell.getDisplay(),
|
highlightBackgroundClr = new Color(shell.getDisplay(),
|
||||||
txtClrCfg.getHighlightTextBackgroundColor());
|
txtClrCfg.getHighlightTextBackgroundColor());
|
||||||
highlightForeground = new Color(shell.getDisplay(),
|
highlightForegroundClr = new Color(shell.getDisplay(),
|
||||||
txtClrCfg.getHighlightTextForegroundColor());
|
txtClrCfg.getHighlightTextForegroundColor());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4278,9 +4261,6 @@ public class TextEditorDialog extends CaveSWTDialog implements VerifyListener,
|
||||||
originalText = combineOriginalMessage();
|
originalText = combineOriginalMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
// update editor status flags
|
|
||||||
dirty = false;
|
|
||||||
|
|
||||||
if (originalText != null) {
|
if (originalText != null) {
|
||||||
textEditor.setText(originalText);
|
textEditor.setText(originalText);
|
||||||
}
|
}
|
||||||
|
@ -5128,7 +5108,6 @@ public class TextEditorDialog extends CaveSWTDialog implements VerifyListener,
|
||||||
boolean successful = saveEditedProduct(false, false, false);
|
boolean successful = saveEditedProduct(false, false, false);
|
||||||
if (successful) {
|
if (successful) {
|
||||||
// reset the editor status flags
|
// reset the editor status flags
|
||||||
dirty = false;
|
|
||||||
saved = true;
|
saved = true;
|
||||||
replaceWorkProductId();
|
replaceWorkProductId();
|
||||||
originalText = combineOriginalMessage();
|
originalText = combineOriginalMessage();
|
||||||
|
@ -5723,8 +5702,6 @@ public class TextEditorDialog extends CaveSWTDialog implements VerifyListener,
|
||||||
textEditor.setText("");
|
textEditor.setText("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// set editor status flags
|
|
||||||
dirty = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -5922,7 +5899,7 @@ public class TextEditorDialog extends CaveSWTDialog implements VerifyListener,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! isObsUpdated) {
|
if (!isObsUpdated) {
|
||||||
if (browser != null) {
|
if (browser != null) {
|
||||||
browser.close();
|
browser.close();
|
||||||
browser = null;
|
browser = null;
|
||||||
|
@ -6116,7 +6093,7 @@ public class TextEditorDialog extends CaveSWTDialog implements VerifyListener,
|
||||||
private void postExecute(boolean hasAttachment, boolean enterEditor,
|
private void postExecute(boolean hasAttachment, boolean enterEditor,
|
||||||
boolean validExecuteCommand, String attachedFilename) {
|
boolean validExecuteCommand, String attachedFilename) {
|
||||||
if (!this.isDisposed()) {
|
if (!this.isDisposed()) {
|
||||||
if (! productQueryJob.isExpectingRequests()) {
|
if (!productQueryJob.isExpectingRequests()) {
|
||||||
if (hasAttachment) {
|
if (hasAttachment) {
|
||||||
statusBarLabel.setText("Attachment: " + attachedFilename);
|
statusBarLabel.setText("Attachment: " + attachedFilename);
|
||||||
} else {
|
} else {
|
||||||
|
@ -7637,6 +7614,22 @@ public class TextEditorDialog extends CaveSWTDialog implements VerifyListener,
|
||||||
browser = null;
|
browser = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (textForegroundClr != null) {
|
||||||
|
textForegroundClr.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (textBackgroundClr != null) {
|
||||||
|
textBackgroundClr.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (highlightForegroundClr != null) {
|
||||||
|
highlightForegroundClr.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (highlightBackgroundClr != null) {
|
||||||
|
highlightBackgroundClr.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
inEditMode = false;
|
inEditMode = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8313,7 +8306,7 @@ public class TextEditorDialog extends CaveSWTDialog implements VerifyListener,
|
||||||
* @return
|
* @return
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
private static boolean isTextFile(File file) throws IOException {
|
private boolean isTextFile(File file) throws IOException {
|
||||||
boolean result = false;
|
boolean result = false;
|
||||||
|
|
||||||
byte[] bytesFromFile = getBytesFromFile(file);
|
byte[] bytesFromFile = getBytesFromFile(file);
|
||||||
|
@ -8335,35 +8328,47 @@ public class TextEditorDialog extends CaveSWTDialog implements VerifyListener,
|
||||||
* @return
|
* @return
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
private static byte[] getBytesFromFile(File file) throws IOException {
|
private byte[] getBytesFromFile(File file) throws IOException {
|
||||||
InputStream is = new FileInputStream(file);
|
InputStream is = null;
|
||||||
|
byte[] bytes = null;
|
||||||
|
|
||||||
// Get the size of the file
|
try {
|
||||||
long length = file.length();
|
is = new FileInputStream(file);
|
||||||
|
|
||||||
if (length > Integer.MAX_VALUE) {
|
// Get the size of the file
|
||||||
// File is too large
|
long length = file.length();
|
||||||
|
|
||||||
|
if (length > Integer.MAX_VALUE) {
|
||||||
|
// File is too large
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create the byte array to hold the data
|
||||||
|
bytes = new byte[(int) length];
|
||||||
|
|
||||||
|
// Read in the bytes
|
||||||
|
int offset = 0;
|
||||||
|
int numRead = 0;
|
||||||
|
while ((offset < bytes.length)
|
||||||
|
&& ((numRead = is
|
||||||
|
.read(bytes, offset, bytes.length - offset)) >= 0)) {
|
||||||
|
offset += numRead;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure all the bytes have been read in
|
||||||
|
if (offset < bytes.length) {
|
||||||
|
throw new IOException("Could not completely read file "
|
||||||
|
+ file.getName());
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
statusHandler.handle(Priority.PROBLEM,
|
||||||
|
"Error opening input stream.", ex);
|
||||||
|
} finally {
|
||||||
|
// Close the input stream and return bytes
|
||||||
|
if (is != null) {
|
||||||
|
is.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the byte array to hold the data
|
|
||||||
byte[] bytes = new byte[(int) length];
|
|
||||||
|
|
||||||
// Read in the bytes
|
|
||||||
int offset = 0;
|
|
||||||
int numRead = 0;
|
|
||||||
while ((offset < bytes.length)
|
|
||||||
&& ((numRead = is.read(bytes, offset, bytes.length - offset)) >= 0)) {
|
|
||||||
offset += numRead;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ensure all the bytes have been read in
|
|
||||||
if (offset < bytes.length) {
|
|
||||||
throw new IOException("Could not completely read file "
|
|
||||||
+ file.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Close the input stream and return bytes
|
|
||||||
is.close();
|
|
||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue