Bug 578735 - ImageAnalyzer taking too long to load images

With this patch, a large image like a screenshot loads in a few seconds
max, instead of >10 minutes.

An ArrayList is used to collect all ranges, which is then converted to
an Array to be passed to setStyleRanges(StyleRange[]).

Change-Id: Ic0007a959df39c9a987232f34799c59f375dc210
Signed-off-by: Joel Majano <jmajano@redhat.com>
Reviewed-on: https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/190779
Tested-by: Alexander Kurtakov <akurtako@redhat.com>
Reviewed-by: Alexander Kurtakov <akurtako@redhat.com>
diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/imageanalyzer/ImageAnalyzer.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/imageanalyzer/ImageAnalyzer.java
index 9be13e2..326e3d0 100644
--- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/imageanalyzer/ImageAnalyzer.java
+++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/imageanalyzer/ImageAnalyzer.java
@@ -1727,6 +1727,7 @@
 		String data = dataHexDump(dataText.getLineDelimiter());
 		dataText.setText(data);
 
+		ArrayList<StyleRange> ranges = new ArrayList<>();
 		// bold the first column all the way down
 		int index = 0;
 		while((index = data.indexOf(':', index+1)) != -1) {
@@ -1736,8 +1737,9 @@
 				start = index - ALPHA_CHARS;
 				length = ALPHA_CHARS;
 			}
-			dataText.setStyleRange(new StyleRange(start, length, dataText.getForeground(), dataText.getBackground(), SWT.BOLD));
+			ranges.add(new StyleRange(start, length, dataText.getForeground(), dataText.getBackground(), SWT.BOLD));
 		}
+		if(!ranges.isEmpty()) dataText.setStyleRanges(ranges.toArray(new StyleRange[0]));
 
 		statusLabel.setText("");