ASM #18870 - TextWS: Mixed case to upper case conversion can exceed 69 character maximum line length
Change-Id: Ic813d69454c37ba6591bdc8452e84997e3a940b2 Former-commit-id: 48ff4f6f84fe3a597d10f6c64386cc585724b906
This commit is contained in:
parent
4519a4b4ef
commit
5e9c1156dd
1 changed files with 74 additions and 32 deletions
|
@ -369,6 +369,7 @@ import com.raytheon.viz.ui.simulatedtime.SimulatedTimeOperations;
|
|||
* 06Jan2016 5225 randerso Fix problem with mixed case not getting converted to upper case
|
||||
* when multiple text editors are open on the same product.
|
||||
* Mar 17, 2016 RM 18727 D. Friedman Fix use of verification listener when entering and exiting editor.
|
||||
* Apr 15, 2016 RM 18870 D. Friedman Replace commas with ellipses only at start of edit and then word-wrap.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -4254,20 +4255,19 @@ public class TextEditorDialog extends CaveSWTDialog implements VerifyListener,
|
|||
// section
|
||||
setCurrentHeaderAndBody();
|
||||
|
||||
// if product is a WarnGen product and is not enabled for mixed case
|
||||
// transmission, replace all commas with ellipses
|
||||
if ((product != null) && warngenPils.contains(product.getNnnid())
|
||||
&& !MixedCaseProductSupport.isMixedCase(product.getNnnid())) {
|
||||
textEditor.setText(textEditor.getText()
|
||||
.replaceAll(", {0,1}", "..."));
|
||||
}
|
||||
|
||||
// Mark the uneditable warning text
|
||||
if (markUneditableText(textEditor)) {
|
||||
// Enable listener to monitor attempt to edit locked text
|
||||
verifyUndeditableText = true;
|
||||
}
|
||||
|
||||
// if product is a WarnGen product and is not enabled for mixed case
|
||||
// transmission, replace all commas with ellipses
|
||||
if ((product != null) && warngenPils.contains(product.getNnnid())
|
||||
&& !MixedCaseProductSupport.isMixedCase(product.getNnnid())) {
|
||||
replaceCommasWithEllipses(product);
|
||||
}
|
||||
|
||||
// Set the menu buttons to reflect the edit mode.
|
||||
editorButtonMenuStates(inEditMode);
|
||||
|
||||
|
@ -4295,6 +4295,60 @@ public class TextEditorDialog extends CaveSWTDialog implements VerifyListener,
|
|||
editHeader("warning", true);
|
||||
}
|
||||
|
||||
private void replaceCommasWithEllipses(StdTextProduct product) {
|
||||
boolean wasVerifying = verifyUndeditableText;
|
||||
try {
|
||||
verifyUndeditableText = false;
|
||||
/*
|
||||
* Performing wrapping as few times as possible to reduce the
|
||||
* chances of breaking the product format. Also, the location list
|
||||
* does not wrap properly unless all commas in the paragraph have
|
||||
* been changed to ellipses.
|
||||
*/
|
||||
Pattern p = Pattern.compile(", {0,1}");
|
||||
int pendingParagraphLineStart = -1;
|
||||
while (true) {
|
||||
String text = textEditor.getText();
|
||||
Matcher m = p.matcher(text);
|
||||
if (! m.find())
|
||||
break;
|
||||
int line = textEditor.getLineAtOffset(m.start());
|
||||
int paragraphLineStart = findParagraphStart(line);
|
||||
String lineText = textEditor.getLine(line);
|
||||
boolean lineNeedsWrap = lineText.length()
|
||||
- (m.end() - m.start()) + 3 > charWrapCol;
|
||||
if (pendingParagraphLineStart >= 0
|
||||
&& paragraphLineStart != pendingParagraphLineStart
|
||||
&& lineNeedsWrap) {
|
||||
wrapWholeParagraphAtLine(pendingParagraphLineStart);
|
||||
pendingParagraphLineStart = -1;
|
||||
// Line numbers may have changed so restart.
|
||||
continue;
|
||||
}
|
||||
textEditor.replaceTextRange(m.start(), m.end() - m.start(), "...");
|
||||
if (lineNeedsWrap) {
|
||||
pendingParagraphLineStart = paragraphLineStart;
|
||||
}
|
||||
}
|
||||
if (pendingParagraphLineStart >= 0) {
|
||||
wrapWholeParagraphAtLine(pendingParagraphLineStart);
|
||||
}
|
||||
} finally {
|
||||
verifyUndeditableText = wasVerifying;
|
||||
}
|
||||
}
|
||||
|
||||
void wrapWholeParagraphAtLine(int paragraphLineStart) {
|
||||
String line = textEditor.getLine(paragraphLineStart);
|
||||
// Avoid rewrapInternal early bailout check.
|
||||
if (line.length() < charWrapCol
|
||||
&& line.indexOf("...") == line.lastIndexOf("...")) {
|
||||
paragraphLineStart++;
|
||||
}
|
||||
int offset = textEditor.getOffsetAtLine(paragraphLineStart);
|
||||
rewrap(offset, offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel the editor mode.
|
||||
*
|
||||
|
@ -4402,16 +4456,6 @@ public class TextEditorDialog extends CaveSWTDialog implements VerifyListener,
|
|||
textEditor.setText(originalText);
|
||||
}
|
||||
|
||||
// if product is a WarnGen product and is not enabled for mixed case
|
||||
// transmission, replace all commas with ellipses
|
||||
StdTextProduct product = TextDisplayModel.getInstance()
|
||||
.getStdTextProduct(token);
|
||||
if ((product != null) && warngenPils.contains(product.getNnnid())
|
||||
&& !MixedCaseProductSupport.isMixedCase(product.getNnnid())) {
|
||||
textEditor.setText(textEditor.getText()
|
||||
.replaceAll(", {0,1}", "..."));
|
||||
}
|
||||
|
||||
markUneditableText(textEditor);
|
||||
|
||||
// Disable the lockable text listener since the application is no
|
||||
|
@ -7109,14 +7153,6 @@ public class TextEditorDialog extends CaveSWTDialog implements VerifyListener,
|
|||
|
||||
textEditor.append(textProduct);
|
||||
|
||||
// if product is a WarnGen product and is not enabled for mixed case
|
||||
// transmission, replace all commas with ellipses
|
||||
if (warngenPils.contains(product.getNnnid())
|
||||
&& !MixedCaseProductSupport.isMixedCase(product.getNnnid())) {
|
||||
textEditor.setText(textEditor.getText()
|
||||
.replaceAll(", {0,1}", "..."));
|
||||
}
|
||||
|
||||
markUneditableText(textEditor);
|
||||
|
||||
// Update text display model with the product that was
|
||||
|
@ -8038,7 +8074,10 @@ public class TextEditorDialog extends CaveSWTDialog implements VerifyListener,
|
|||
|
||||
paragraphStart = paragraphStart.toUpperCase();
|
||||
// is this the locations paragraph?
|
||||
if (paragraphStart.startsWith("* LOCATIONS")) {
|
||||
if (paragraphStart.startsWith("* LOCATIONS")
|
||||
|| paragraphStart.startsWith(("* SOME LOCATIONS"))
|
||||
|| paragraphStart.startsWith(("LOCATIONS IMPACTED"))
|
||||
|| paragraphStart.startsWith(("SOME LOCATIONS THAT"))) {
|
||||
inLocations = true;
|
||||
}
|
||||
|
||||
|
@ -8079,7 +8118,7 @@ public class TextEditorDialog extends CaveSWTDialog implements VerifyListener,
|
|||
}
|
||||
|
||||
if (line.length() <= charWrapCol) {
|
||||
extendShortLine(lineNumber, padding);
|
||||
extendShortLine(lineNumber, padding, inLocations);
|
||||
if (textEditor.getLine(lineNumber).length() <= charWrapCol) {
|
||||
// extended line is still short enough do not wrap
|
||||
if (lineNumber < endWrapLine) {
|
||||
|
@ -8110,8 +8149,9 @@ public class TextEditorDialog extends CaveSWTDialog implements VerifyListener,
|
|||
*
|
||||
* @param lineNumber
|
||||
* @param padding
|
||||
* @param inLocations
|
||||
*/
|
||||
private void extendShortLine(int lineNumber, final String padding) {
|
||||
private void extendShortLine(int lineNumber, final String padding, boolean inLocations) {
|
||||
// if the line is too short move the next line up
|
||||
// if there is a next line
|
||||
String line = textEditor.getLine(lineNumber);
|
||||
|
@ -8190,10 +8230,12 @@ public class TextEditorDialog extends CaveSWTDialog implements VerifyListener,
|
|||
String wordSpace = "";
|
||||
if (noSeparatorPattern.matcher(endLine).matches()
|
||||
&& noSeparatorPattern.matcher(startNextLine)
|
||||
.matches()) {
|
||||
.matches()
|
||||
&& (!inLocations || !line.endsWith("..."))) {
|
||||
// Put a space between words when merging the lines.
|
||||
wordSpace = " ";
|
||||
}
|
||||
|
||||
textEditor.replaceTextRange(newlinePosition, deleteLen,
|
||||
wordSpace);
|
||||
String afterReplace = textEditor.getText();
|
||||
|
@ -8207,7 +8249,7 @@ public class TextEditorDialog extends CaveSWTDialog implements VerifyListener,
|
|||
|
||||
// is this line still too short?
|
||||
if (textEditor.getLine(lineNumber).length() <= charWrapCol) {
|
||||
extendShortLine(lineNumber, padding);
|
||||
extendShortLine(lineNumber, padding, inLocations);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8460,7 +8502,7 @@ public class TextEditorDialog extends CaveSWTDialog implements VerifyListener,
|
|||
private void recompileRegex() {
|
||||
this.standardWrapRegex = Pattern.compile("( |..).{1,"
|
||||
+ (charWrapCol - 3) + "}(\\s|-)");
|
||||
this.locationsFirstRegex = Pattern.compile("^\\* LOCATIONS [^\\.]{1,"
|
||||
this.locationsFirstRegex = Pattern.compile("^(?:\\* (?:SOME )?LOCATIONS|LOCATIONS IMPACTED|SOME LOCATIONS THAT) [^\\.]{1,"
|
||||
+ (charWrapCol - 13) + "}\\s");
|
||||
this.locationsBodyRegex = Pattern.compile("(( |..).{1,"
|
||||
+ (charWrapCol - 5) + "}\\.\\.\\.)|(( |..).{1,"
|
||||
|
|
Loading…
Add table
Reference in a new issue