Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Pazderski2019-05-18 07:43:55 -0400
committerPaul Pazderski2019-05-19 09:23:41 -0400
commit15e8030feaca590954db1954c4d5f1f21d7d14db (patch)
tree7303f0b232b8fec0fe16f75eb9bfb17f73674f82
parent3813245f0c061a9e05c57a0703282ea3394e84c4 (diff)
downloadeclipse.platform.swt-15e8030feaca590954db1954c4d5f1f21d7d14db.tar.gz
eclipse.platform.swt-15e8030feaca590954db1954c4d5f1f21d7d14db.tar.xz
eclipse.platform.swt-15e8030feaca590954db1954c4d5f1f21d7d14db.zip
Bug 547304 - [cleanup] Fix wrong line delimiters
This updates all Java files with wrong or mixed line delimiters to use Unix style delimiters. The change includes only whitespace formatting and no code changes. Change-Id: I4cf29fcedaaa5ee7efc0fb68e6b22aecb17812ce
-rw-r--r--bundles/org.eclipse.swt.tools/JavadocBasher/org/eclipse/swt/tools/internal/JavadocBasher.java1014
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/MouseNavigator.java588
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextLineSpacingProvider.java68
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/com/win32/FileDialogVtbl.java86
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/com/win32/ShellItemVtbl.java48
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet364.java126
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet365.java936
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet366.java216
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet368.java108
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet369.java110
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet374.java94
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet375.java252
-rw-r--r--tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug531634_LogoffListener.java132
-rw-r--r--tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_StyledTextLineSpacingProvider.java172
-rw-r--r--tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_StyledText_VariableLineHeight.java514
15 files changed, 2232 insertions, 2232 deletions
diff --git a/bundles/org.eclipse.swt.tools/JavadocBasher/org/eclipse/swt/tools/internal/JavadocBasher.java b/bundles/org.eclipse.swt.tools/JavadocBasher/org/eclipse/swt/tools/internal/JavadocBasher.java
index 0e055fc1e4..e955362c41 100644
--- a/bundles/org.eclipse.swt.tools/JavadocBasher/org/eclipse/swt/tools/internal/JavadocBasher.java
+++ b/bundles/org.eclipse.swt.tools/JavadocBasher/org/eclipse/swt/tools/internal/JavadocBasher.java
@@ -1,508 +1,508 @@
-package org.eclipse.swt.tools.internal;
-
-import java.io.*;
-import java.util.*;
-import java.util.Map.*;
-
-import org.eclipse.jdt.core.dom.*;
-import org.eclipse.jface.text.*;
-
-/**
- * Bashes the javadoc from one source tree into another. Only produces new
- * source files for compilation units that have changed.
- *
- * How to use: 1) make sure you have the latest org.eclipse.swt (master branch)
- * in your workspace, and that you have no outstanding org.eclipse.swt changes
- * 2) create a Bugzilla bug called
- * "Do the annual javadoc/copyright bash for x.x" 3) make a version (tag) of the
- * org.eclipse.swt project before you bash here is a sample tag name:
- * BEFORE_JAVADOC_BASH_FOR_43RC3 use the Bugzilla bug for the tag comment 4)
- * modify the code in main, below, so that 'workspaceDir' and 'outputDir' point
- * to the (git) directory that contains org.eclipse.swt in your workspace,
- * typically C:/git/eclipse.platform.swt/bundles (prior to 3.8/4.2, these
- * pointed to the workspace directory) 5) make sure 'sourceSubdir' (usually
- * win32), 'targetSubdirs' (all others), and 'folders' are correct (note: there
- * are typically a few new targetSubdirs and folders every year... although
- * nothing new for 4.3) 6) run JavadocBasher (for a more verbose output, set
- * fVerbose to true) 7) refresh (F5) the org.eclipse.swt project inside eclipse
- * 8) search for *** in console output to see results of API consistency
- * checking 9) synchronize, carefully reviewing every change. Watch out for: -
- * duplicated comments - // comments that have been removed (if they appear
- * before a javadoc comment) 10) use the Bugzilla bug as the commit comment for
- * javadoc and copyright bash commits 11) make a version of the org.eclipse.swt
- * project after bashing (use tag name AFTER_...)
- *
- * 12) Copyright bash (tag before and after): NOTE: JavadocBasher does not fix
- * copyrights. Use the "Fix Copyrights" tool in org.eclipse.releng.tools for
- * that (always fix copyrights after bash). Use Help->Install New Software... to
- * install "Releng Tools" from the "Eclipse Project Updates" site (for release -
- * 1). Select org.eclipse.swt project and choose "Fix Copyrights" from the
- * context menu. See http://wiki.eclipse.org/Development_Resources/
- * How_to_Use_Eclipse_Copyright_Tool for more info. NOTE: The copyright tool
- * takes about 45 minutes to run (for SWT). NOTE 2: Check console for possible
- * errors/warnings, refresh (F5), synchronize, and browse all changes. Use
- * keyboard (Ctrl+.) for next diff instead of mouse (keyboard is faster because
- * there are fewer focus changes). Only use git History view as needed - if it
- * is open and linked with editor, it gets bogged down and lags behind. NOTE 3:
- * SWT anomalies that confuse the tool: - Some ns*.h files in
- * Mozilla/common/library do not contain the word "copyright" so the tool tries
- * to add one - don't keep it (the text is fine as-is). - Other ns*.h files in
- * Mozilla/common/library have a copyright line that should not be updated
- * (Initial Developer) - don't keep the change suggested by the tool (the text
- * is fine as-is). - The ns*.java and some other *.java files in
- * internal/mozilla have 2 copyright lines and the tool tries to change the 1st
- * - don't keep the 1st change (Netscape 1998-2015), but update the 2nd (IBM)
- * manually.
- *
- * NOTE: JavadocBasher now does a fairly good job of checking API consistency.
- * We used to use org.eclipse.swt.diff for API consistency checking, but it was
- * difficult to maintain.
+package org.eclipse.swt.tools.internal;
+
+import java.io.*;
+import java.util.*;
+import java.util.Map.*;
+
+import org.eclipse.jdt.core.dom.*;
+import org.eclipse.jface.text.*;
+
+/**
+ * Bashes the javadoc from one source tree into another. Only produces new
+ * source files for compilation units that have changed.
+ *
+ * How to use: 1) make sure you have the latest org.eclipse.swt (master branch)
+ * in your workspace, and that you have no outstanding org.eclipse.swt changes
+ * 2) create a Bugzilla bug called
+ * "Do the annual javadoc/copyright bash for x.x" 3) make a version (tag) of the
+ * org.eclipse.swt project before you bash here is a sample tag name:
+ * BEFORE_JAVADOC_BASH_FOR_43RC3 use the Bugzilla bug for the tag comment 4)
+ * modify the code in main, below, so that 'workspaceDir' and 'outputDir' point
+ * to the (git) directory that contains org.eclipse.swt in your workspace,
+ * typically C:/git/eclipse.platform.swt/bundles (prior to 3.8/4.2, these
+ * pointed to the workspace directory) 5) make sure 'sourceSubdir' (usually
+ * win32), 'targetSubdirs' (all others), and 'folders' are correct (note: there
+ * are typically a few new targetSubdirs and folders every year... although
+ * nothing new for 4.3) 6) run JavadocBasher (for a more verbose output, set
+ * fVerbose to true) 7) refresh (F5) the org.eclipse.swt project inside eclipse
+ * 8) search for *** in console output to see results of API consistency
+ * checking 9) synchronize, carefully reviewing every change. Watch out for: -
+ * duplicated comments - // comments that have been removed (if they appear
+ * before a javadoc comment) 10) use the Bugzilla bug as the commit comment for
+ * javadoc and copyright bash commits 11) make a version of the org.eclipse.swt
+ * project after bashing (use tag name AFTER_...)
+ *
+ * 12) Copyright bash (tag before and after): NOTE: JavadocBasher does not fix
+ * copyrights. Use the "Fix Copyrights" tool in org.eclipse.releng.tools for
+ * that (always fix copyrights after bash). Use Help->Install New Software... to
+ * install "Releng Tools" from the "Eclipse Project Updates" site (for release -
+ * 1). Select org.eclipse.swt project and choose "Fix Copyrights" from the
+ * context menu. See http://wiki.eclipse.org/Development_Resources/
+ * How_to_Use_Eclipse_Copyright_Tool for more info. NOTE: The copyright tool
+ * takes about 45 minutes to run (for SWT). NOTE 2: Check console for possible
+ * errors/warnings, refresh (F5), synchronize, and browse all changes. Use
+ * keyboard (Ctrl+.) for next diff instead of mouse (keyboard is faster because
+ * there are fewer focus changes). Only use git History view as needed - if it
+ * is open and linked with editor, it gets bogged down and lags behind. NOTE 3:
+ * SWT anomalies that confuse the tool: - Some ns*.h files in
+ * Mozilla/common/library do not contain the word "copyright" so the tool tries
+ * to add one - don't keep it (the text is fine as-is). - Other ns*.h files in
+ * Mozilla/common/library have a copyright line that should not be updated
+ * (Initial Developer) - don't keep the change suggested by the tool (the text
+ * is fine as-is). - The ns*.java and some other *.java files in
+ * internal/mozilla have 2 copyright lines and the tool tries to change the 1st
+ * - don't keep the 1st change (Netscape 1998-2015), but update the 2nd (IBM)
+ * manually.
+ *
+ * NOTE: JavadocBasher now does a fairly good job of checking API consistency.
+ * We used to use org.eclipse.swt.diff for API consistency checking, but it was
+ * difficult to maintain.
*/
-public class JavadocBasher {
- static final boolean fVerbose = false; // set to true for verbose output
- List<String> fBashed;
- List<String> fUnchanged;
- List<String> fSkipped;
-
- public JavadocBasher() {
- fBashed = new ArrayList<>();
- fUnchanged = new ArrayList<>();
- fSkipped = new ArrayList<>();
- }
-
- public static class Edit {
- int start, length;
- String text;
-
- public Edit(int start, int length, String text) {
- this.start = start;
- this.length = length;
- this.text = text;
- }
- }
-
- public static void main(String[] args) {
- String workspaceDir = ".."; // use forward slashes, no final slash
- String outputDir = ".."; // can point to another directory for debugging
- String[] folders = new String[] { // commented folders do not need to be
- // bashed
- "Eclipse SWT", "Eclipse SWT Accessibility",
- "Eclipse SWT AWT",
- "Eclipse SWT Browser",
- // "Eclipse SWT Custom Widgets",
- "Eclipse SWT Drag and Drop", "Eclipse SWT Effects",
- // "Eclipse SWT OLE Win32",
- "Eclipse SWT OpenGL",
- // "Eclipse SWT PI",
- "Eclipse SWT Printing", "Eclipse SWT Program",
- "Eclipse SWT Theme", "Eclipse SWT WebKit", };
- String sourceSubdir = "win32";
- String[] targetSubdirs = new String[] { "cairo", // used by gtk
- "cocoa",
- // "common",
- // "common_j2me",
- // "common_j2se",
- "emulated", "emulated/bidi", // used by carbon, cocoa
- "emulated/coolbar", // used by cocoa, gtk
- "emulated/expand", // used by cocoa
- "emulated/taskbar", // used by gtk
- "emulated/tooltip", // used by cocoa (?!)
- "glx", // used by gtk
- "gtk"
- };
-
- System.out.println("==== Start Bashing ====");
- int totalBashed = 0;
- for (int t = 0; t < targetSubdirs.length; t++) {
- for (int f = 0; f < folders.length; f++) {
- String targetSubdir = folders[f] + "/" + targetSubdirs[t];
- File source = new File(workspaceDir + "/org.eclipse.swt/"
- + folders[f] + "/" + sourceSubdir);
- File target = new File(workspaceDir + "/org.eclipse.swt/"
- + targetSubdir);
- File out = new File(outputDir + "/org.eclipse.swt/"
- + targetSubdir);
- JavadocBasher basher = new JavadocBasher();
- System.out.println("\n==== Start Bashing " + targetSubdir);
- basher.bashJavaSourceTree(source, target, out);
- List<String> bashedList = basher.getBashed();
- basher.status("Bashed", bashedList, targetSubdir);
- if (bashedList.size() > 0) {
- totalBashed += bashedList.size();
- if (fVerbose)
- basher.status("Didn't change", basher.getUnchanged(),
- targetSubdir);
- basher.status("Skipped", basher.getSkipped(), targetSubdir);
- }
- System.out.println("==== Done Bashing " + targetSubdir);
- }
- }
- System.out.println("\n==== Done Bashing (Bashed " + totalBashed
- + " files in total) - Be sure to Refresh (F5) project(s) ====");
- }
-
- void status(String label, List<String> list, String targetSubdir) {
- int count = list.size();
- System.out.println(label + " " + count
- + ((count == 1) ? " file" : " files") + " in " + targetSubdir
- + ((count > 0) ? ":" : "."));
- if (count > 0) {
- for(String s : list)
- System.out.println(label + ": " + s);
- System.out.println();
- }
- }
-
- char[] readFile(File file) {
- try (Reader in = new FileReader(file)) {
- CharArrayWriter storage = new CharArrayWriter();
- char[] chars = new char[8192];
- int read = in.read(chars);
- while (read > 0) {
- storage.write(chars, 0, read);
- storage.flush();
- read = in.read(chars);
- }
- return storage.toCharArray();
- } catch (IOException ioe) {
- System.out.println("*** Could not read " + file);
- }
- return null;
- }
-
- void writeFile(char[] contents, File file) {
- try (Writer out = new FileWriter(file)) {
- out.write(contents);
- out.flush();
- } catch (IOException ioe) {
- System.out.println("*** Could not write to " + file);
- if (fVerbose) {
- System.out.println("<dump filename=\"" + file + "\">");
- System.out.println(contents);
- System.out.println("</dump>");
- }
- }
- }
-
- void bashJavaSourceTree(File sourceDir, File targetDir, File outDir) {
- if (fVerbose)
- System.out.println("Reading source javadoc from " + sourceDir);
- if (!sourceDir.exists()) {
- System.out.println("Source: " + sourceDir + " was missing");
- return;
- }
- if (!targetDir.exists()) {
- System.out.println("Target: " + targetDir + " was missing");
- return;
- }
-
- String[] list = sourceDir.list();
- if (list != null) {
- int count = list.length;
- for (int i = 0; i < count; i++) {
- String filename = list[i];
- if (filename.equals("CVS") || filename.equals("internal")
- || filename.equals("library"))
- continue;
- File source = new File(sourceDir, filename);
- File target = new File(targetDir, filename);
- File out = new File(outDir, filename);
- if (source.exists() && target.exists()) {
- if (source.isDirectory()) {
- if (target.isDirectory()) {
- bashJavaSourceTree(source, target, out);
- } else {
- System.out.println("*** " + target
- + " should have been a directory.");
- }
- } else {
- if (filename.toLowerCase().endsWith(".java")) {
- bashFile(source, target, out);
- } else {
- fSkipped.add(source + " (not a java file)");
- }
- }
- } else {
- if (source.exists()) {
- fSkipped.add(target + " (does not exist)");
- } else {
- fSkipped.add(source + " (does not exist)");
- }
- }
- }
- }
- }
-
-
- void bashFile(final File source, final File target, File out) {
- char[] contents = readFile(source);
- if (contents == null) return;
- ASTParser parser = ASTParser.newParser(AST.JLS8);
- final Document sourceDocument = new Document(new String(contents));
- parser.setSource(contents);
- CompilationUnit sourceUnit = (CompilationUnit)parser.createAST(null);
-
- contents = readFile(target);
- if (contents == null) return;
- String targetContents = new String(contents);
- final Document targetDocument = new Document(targetContents);
- parser.setSource(contents);
- CompilationUnit targetUnit = (CompilationUnit)parser.createAST(null);
-
- final HashMap<String, String> comments = new HashMap<>();
- sourceUnit.accept(new ASTVisitor() {
- String prefix = "";
- @Override
- public boolean visit(Block node) {
- return false;
- }
- @Override
- public boolean visit(VariableDeclarationFragment node) {
- FieldDeclaration field = (FieldDeclaration)node.getParent();
- int mods = field.getModifiers();
- if (Modifier.isPublic(mods) || Modifier.isProtected(mods)) {
- Javadoc javadoc = field.getJavadoc();
- if (field.fragments().size() > 1 && javadoc != null) {
- System.err.println("Field declaration with multiple variables is not supported. -> " + source + " " + node.getName().getFullyQualifiedName());
- }
- try {
- String key = prefix + "." + node.getName().getFullyQualifiedName();
- comments.put(key, javadoc != null ? sourceDocument.get(javadoc.getStartPosition(), getJavadocLength(sourceDocument, javadoc)) : "");
- } catch (BadLocationException e) {}
- return true;
- }
- return false;
- }
- @Override
- public boolean visit(MethodDeclaration node) {
- int mods = node.getModifiers();
- if (Modifier.isPublic(mods) || Modifier.isProtected(mods)) {
- Javadoc javadoc = node.getJavadoc();
- try {
- String key = prefix + "." + node.getName().getFullyQualifiedName();
- for (Iterator<SingleVariableDeclaration> iterator = node.parameters().iterator(); iterator.hasNext();) {
- SingleVariableDeclaration param = iterator.next();
- key += param.getType().toString();
- }
- comments.put(key, javadoc != null ? sourceDocument.get(javadoc.getStartPosition(), getJavadocLength(sourceDocument, javadoc)) : "");
- } catch (BadLocationException e) {}
- return true;
- }
- return false;
- }
- @Override
- public boolean visit(TypeDeclaration node) {
- int mods = node.getModifiers();
- if (Modifier.isPublic(mods) || Modifier.isProtected(mods)) {
- Javadoc javadoc = node.getJavadoc();
- try {
- String key = prefix + "." + node.getName().getFullyQualifiedName();
- comments.put(key, javadoc != null ? sourceDocument.get(javadoc.getStartPosition(), getJavadocLength(sourceDocument, javadoc)) : "");
- } catch (BadLocationException e) {}
- prefix = node.getName().getFullyQualifiedName();
- return true;
- }
- return false;
- }
- });
-
-
- final List<Edit> edits = new ArrayList<>();
- targetUnit.accept(new ASTVisitor() {
- String prefix = "";
- @Override
- public boolean visit(Block node) {
- return false;
- }
- @Override
- public boolean visit(VariableDeclarationFragment node) {
- FieldDeclaration field = (FieldDeclaration)node.getParent();
- int mods = field.getModifiers();
- if (Modifier.isPublic(mods) || Modifier.isProtected(mods)) {
- Javadoc javadoc = field.getJavadoc();
- if (field.fragments().size() > 1 && javadoc != null) {
- System.err.println("Field declaration with multiple variables is not supported. -> " + target + " " + node.getName().getFullyQualifiedName());
- }
- String key = prefix + "." + node.getName().getFullyQualifiedName();
- String newComment = comments.get(key);
- if (newComment != null) {
- comments.remove(key);
- if (javadoc != null) {
- edits.add(new Edit(javadoc.getStartPosition(), getJavadocLength(targetDocument, javadoc), newComment));
- } else {
- edits.add(new Edit(field.getStartPosition(), 0, newComment));
- }
- }
- return true;
- }
- return false;
- }
- @Override
- public boolean visit(MethodDeclaration node) {
- int mods = node.getModifiers();
- if (Modifier.isPublic(mods) || Modifier.isProtected(mods)) {
- Javadoc javadoc = node.getJavadoc();
- String key = prefix + "." + node.getName().getFullyQualifiedName();
- for (Iterator<SingleVariableDeclaration> iterator = node.parameters().iterator(); iterator.hasNext();) {
- SingleVariableDeclaration param = iterator.next();
- key += param.getType().toString();
- }
- String newComment = comments.get(key);
- if (newComment != null) {
- comments.remove(key);
- if (javadoc != null) {
- edits.add(new Edit(javadoc.getStartPosition(), getJavadocLength(targetDocument, javadoc), newComment));
- } else {
- edits.add(new Edit(node.getStartPosition(), 0, newComment));
- }
- }
- return true;
- }
- return false;
- }
- @Override
- public boolean visit(TypeDeclaration node) {
- int mods = node.getModifiers();
- if (Modifier.isPublic(mods) || Modifier.isProtected(mods)) {
- Javadoc javadoc = node.getJavadoc();
- String key = prefix + "." + node.getName().getFullyQualifiedName();
- String newComment = comments.get(key);
- if (newComment != null) {
- comments.remove(key);
- if (javadoc != null) {
- edits.add(new Edit(javadoc.getStartPosition(), getJavadocLength(targetDocument, javadoc), newComment));
- } else {
- edits.add(new Edit(node.getStartPosition(), 0, newComment));
- }
- }
- prefix = node.getName().getFullyQualifiedName();
- return true;
- }
- return false;
- }
- });
-
- for (int i = edits.size() - 1; i >=0 ; i--) {
- Edit edit = edits.get(i);
- try {
- targetDocument.replace(edit.start, edit.length, edit.text);
- } catch (BadLocationException e) {
- e.printStackTrace();
- }
- }
- /* Rudimentary API consistency checker.
- * This assumes that:
- * a) the sourceSubdir (typically win32) API is correct
- * b) all sourceSubdir API classes, methods and fields do have a comment
- * c) names that are in the filter list are never API,
- * or they are old API that is defined in the super on some platforms
- */
- if (comments.size() > 0) {
- String [] filter = new String [] {
- "Color.win32_newDeviceint",
- "Cursor.win32_newDeviceint",
- "Device.hPalette",
- "Font.win32_newDevicelong",
- "FontData.data",
- "FontData.win32_newLOGFONTfloat",
- "FontMetrics.handle",
- "FontMetrics.win32_newTEXTMETRIC",
- "GC.win32_newlongGCData",
- "GC.win32_newDrawableGCData",
- "Image.win32_newDeviceintlong",
- "Pattern.handle",
- "Region.win32_newDeviceint",
- "Control.handle",
- "Display.getSystemFont",
- "Display.msg",
- "Menu.handle",
- "Shell.win32_newDisplaylong",
- "Accessible.internal_WM_GETOBJECTlonglong",
- "TransferData.result",
- "TransferData.stgmedium",
- "TransferData.pIDataObject",
- "TransferData.formatetc",
- "Printer.handle",
- "Printer.checkDevice",
- "TableDragSourceEffect.dragFinishedDragSourceEvent",
- "TableDragSourceEffect.dragStartDragSourceEvent",
- "TableDropTargetEffect.dragOverDropTargetEvent",
- "TableDropTargetEffect.dragEnterDropTargetEvent",
- "TableDropTargetEffect.dragLeaveDropTargetEvent",
- "Transfer.validateObject",
- "TransferData.result",
- "TransferData.stgmedium",
- "TransferData.pIDataObject",
- "TransferData.formatetc",
- "TreeDragSourceEffect.dragFinishedDragSourceEvent",
- "TreeDragSourceEffect.dragStartDragSourceEvent",
- "TreeDropTargetEffect.dragLeaveDropTargetEvent",
- "TreeDropTargetEffect.dragEnterDropTargetEvent",
- "TreeDropTargetEffect.dragOverDropTargetEvent",
- "Printer.createDeviceData",
- "Printer.internal_dispose_GClongGCData",
- "Printer.release",
- "Printer.destroy",
- "Image.handle",
- "Display.getClientArea",
- "TreeItem.handle",
- };
- for (Entry<String, String> entry: comments.entrySet()) {
- String name = entry.getKey();
- if (entry.getValue().length() > 0){
- int i = 0;
- for (i = 0; i < filter.length; i++) {
- if (name.equals(filter[i])) break;
- }
- if (i >= filter.length) {
- System.err.println("***No target for " + name);
- }
- }
- }
- }
-
- String newContents = targetDocument.get();
- if (!targetContents.equals(newContents)) {
- if (makeDirectory(out.getParentFile())) {
- writeFile(newContents.toCharArray(), out);
- fBashed.add(target.toString());
- } else {
- System.out.println("*** Could not create " + out.getParent());
- }
- } else {
- fUnchanged.add(target.toString());
- }
- }
-
- int getJavadocLength(Document sourceDocument, Javadoc javadoc) {
- return skipWhitespace(sourceDocument, javadoc.getStartPosition() + javadoc.getLength()) - javadoc.getStartPosition();
- }
-
- int skipWhitespace(Document doc, int offset) {
- try {
- while (Character.isWhitespace(doc.getChar(offset))){
- offset++;
- }
- } catch (BadLocationException e) {
- }
- return offset;
- }
-
- boolean makeDirectory(File directory) {
- if (directory.exists())
- return true;
- return directory.mkdirs();
- }
-
- List<String> getBashed() {
- return fBashed;
- }
-
- List<String> getUnchanged() {
- return fUnchanged;
- }
-
- List<String> getSkipped() {
- return fSkipped;
- }
-}
+public class JavadocBasher {
+ static final boolean fVerbose = false; // set to true for verbose output
+ List<String> fBashed;
+ List<String> fUnchanged;
+ List<String> fSkipped;
+
+ public JavadocBasher() {
+ fBashed = new ArrayList<>();
+ fUnchanged = new ArrayList<>();
+ fSkipped = new ArrayList<>();
+ }
+
+ public static class Edit {
+ int start, length;
+ String text;
+
+ public Edit(int start, int length, String text) {
+ this.start = start;
+ this.length = length;
+ this.text = text;
+ }
+ }
+
+ public static void main(String[] args) {
+ String workspaceDir = ".."; // use forward slashes, no final slash
+ String outputDir = ".."; // can point to another directory for debugging
+ String[] folders = new String[] { // commented folders do not need to be
+ // bashed
+ "Eclipse SWT", "Eclipse SWT Accessibility",
+ "Eclipse SWT AWT",
+ "Eclipse SWT Browser",
+ // "Eclipse SWT Custom Widgets",
+ "Eclipse SWT Drag and Drop", "Eclipse SWT Effects",
+ // "Eclipse SWT OLE Win32",
+ "Eclipse SWT OpenGL",
+ // "Eclipse SWT PI",
+ "Eclipse SWT Printing", "Eclipse SWT Program",
+ "Eclipse SWT Theme", "Eclipse SWT WebKit", };
+ String sourceSubdir = "win32";
+ String[] targetSubdirs = new String[] { "cairo", // used by gtk
+ "cocoa",
+ // "common",
+ // "common_j2me",
+ // "common_j2se",
+ "emulated", "emulated/bidi", // used by carbon, cocoa
+ "emulated/coolbar", // used by cocoa, gtk
+ "emulated/expand", // used by cocoa
+ "emulated/taskbar", // used by gtk
+ "emulated/tooltip", // used by cocoa (?!)
+ "glx", // used by gtk
+ "gtk"
+ };
+
+ System.out.println("==== Start Bashing ====");
+ int totalBashed = 0;
+ for (int t = 0; t < targetSubdirs.length; t++) {
+ for (int f = 0; f < folders.length; f++) {
+ String targetSubdir = folders[f] + "/" + targetSubdirs[t];
+ File source = new File(workspaceDir + "/org.eclipse.swt/"
+ + folders[f] + "/" + sourceSubdir);
+ File target = new File(workspaceDir + "/org.eclipse.swt/"
+ + targetSubdir);
+ File out = new File(outputDir + "/org.eclipse.swt/"
+ + targetSubdir);
+ JavadocBasher basher = new JavadocBasher();
+ System.out.println("\n==== Start Bashing " + targetSubdir);
+ basher.bashJavaSourceTree(source, target, out);
+ List<String> bashedList = basher.getBashed();
+ basher.status("Bashed", bashedList, targetSubdir);
+ if (bashedList.size() > 0) {
+ totalBashed += bashedList.size();
+ if (fVerbose)
+ basher.status("Didn't change", basher.getUnchanged(),
+ targetSubdir);
+ basher.status("Skipped", basher.getSkipped(), targetSubdir);
+ }
+ System.out.println("==== Done Bashing " + targetSubdir);
+ }
+ }
+ System.out.println("\n==== Done Bashing (Bashed " + totalBashed
+ + " files in total) - Be sure to Refresh (F5) project(s) ====");
+ }
+
+ void status(String label, List<String> list, String targetSubdir) {
+ int count = list.size();
+ System.out.println(label + " " + count
+ + ((count == 1) ? " file" : " files") + " in " + targetSubdir
+ + ((count > 0) ? ":" : "."));
+ if (count > 0) {
+ for(String s : list)
+ System.out.println(label + ": " + s);
+ System.out.println();
+ }
+ }
+
+ char[] readFile(File file) {
+ try (Reader in = new FileReader(file)) {
+ CharArrayWriter storage = new CharArrayWriter();
+ char[] chars = new char[8192];
+ int read = in.read(chars);
+ while (read > 0) {
+ storage.write(chars, 0, read);
+ storage.flush();
+ read = in.read(chars);
+ }
+ return storage.toCharArray();
+ } catch (IOException ioe) {
+ System.out.println("*** Could not read " + file);
+ }
+ return null;
+ }
+
+ void writeFile(char[] contents, File file) {
+ try (Writer out = new FileWriter(file)) {
+ out.write(contents);
+ out.flush();
+ } catch (IOException ioe) {
+ System.out.println("*** Could not write to " + file);
+ if (fVerbose) {
+ System.out.println("<dump filename=\"" + file + "\">");
+ System.out.println(contents);
+ System.out.println("</dump>");
+ }
+ }
+ }
+
+ void bashJavaSourceTree(File sourceDir, File targetDir, File outDir) {
+ if (fVerbose)
+ System.out.println("Reading source javadoc from " + sourceDir);
+ if (!sourceDir.exists()) {
+ System.out.println("Source: " + sourceDir + " was missing");
+ return;
+ }
+ if (!targetDir.exists()) {
+ System.out.println("Target: " + targetDir + " was missing");
+ return;
+ }
+
+ String[] list = sourceDir.list();
+ if (list != null) {
+ int count = list.length;
+ for (int i = 0; i < count; i++) {
+ String filename = list[i];
+ if (filename.equals("CVS") || filename.equals("internal")
+ || filename.equals("library"))
+ continue;
+ File source = new File(sourceDir, filename);
+ File target = new File(targetDir, filename);
+ File out = new File(outDir, filename);
+ if (source.exists() && target.exists()) {
+ if (source.isDirectory()) {
+ if (target.isDirectory()) {
+ bashJavaSourceTree(source, target, out);
+ } else {
+ System.out.println("*** " + target
+ + " should have been a directory.");
+ }
+ } else {
+ if (filename.toLowerCase().endsWith(".java")) {
+ bashFile(source, target, out);
+ } else {
+ fSkipped.add(source + " (not a java file)");
+ }
+ }
+ } else {
+ if (source.exists()) {
+ fSkipped.add(target + " (does not exist)");
+ } else {
+ fSkipped.add(source + " (does not exist)");
+ }
+ }
+ }
+ }
+ }
+
+
+ void bashFile(final File source, final File target, File out) {
+ char[] contents = readFile(source);
+ if (contents == null) return;
+ ASTParser parser = ASTParser.newParser(AST.JLS8);
+ final Document sourceDocument = new Document(new String(contents));
+ parser.setSource(contents);
+ CompilationUnit sourceUnit = (CompilationUnit)parser.createAST(null);
+
+ contents = readFile(target);
+ if (contents == null) return;
+ String targetContents = new String(contents);
+ final Document targetDocument = new Document(targetContents);
+ parser.setSource(contents);
+ CompilationUnit targetUnit = (CompilationUnit)parser.createAST(null);
+
+ final HashMap<String, String> comments = new HashMap<>();
+ sourceUnit.accept(new ASTVisitor() {
+ String prefix = "";
+ @Override
+ public boolean visit(Block node) {
+ return false;
+ }
+ @Override
+ public boolean visit(VariableDeclarationFragment node) {
+ FieldDeclaration field = (FieldDeclaration)node.getParent();
+ int mods = field.getModifiers();
+ if (Modifier.isPublic(mods) || Modifier.isProtected(mods)) {
+ Javadoc javadoc = field.getJavadoc();
+ if (field.fragments().size() > 1 && javadoc != null) {
+ System.err.println("Field declaration with multiple variables is not supported. -> " + source + " " + node.getName().getFullyQualifiedName());
+ }
+ try {
+ String key = prefix + "." + node.getName().getFullyQualifiedName();
+ comments.put(key, javadoc != null ? sourceDocument.get(javadoc.getStartPosition(), getJavadocLength(sourceDocument, javadoc)) : "");
+ } catch (BadLocationException e) {}
+ return true;
+ }
+ return false;
+ }
+ @Override
+ public boolean visit(MethodDeclaration node) {
+ int mods = node.getModifiers();
+ if (Modifier.isPublic(mods) || Modifier.isProtected(mods)) {
+ Javadoc javadoc = node.getJavadoc();
+ try {
+ String key = prefix + "." + node.getName().getFullyQualifiedName();
+ for (Iterator<SingleVariableDeclaration> iterator = node.parameters().iterator(); iterator.hasNext();) {
+ SingleVariableDeclaration param = iterator.next();
+ key += param.getType().toString();
+ }
+ comments.put(key, javadoc != null ? sourceDocument.get(javadoc.getStartPosition(), getJavadocLength(sourceDocument, javadoc)) : "");
+ } catch (BadLocationException e) {}
+ return true;
+ }
+ return false;
+ }
+ @Override
+ public boolean visit(TypeDeclaration node) {
+ int mods = node.getModifiers();
+ if (Modifier.isPublic(mods) || Modifier.isProtected(mods)) {
+ Javadoc javadoc = node.getJavadoc();
+ try {
+ String key = prefix + "." + node.getName().getFullyQualifiedName();
+ comments.put(key, javadoc != null ? sourceDocument.get(javadoc.getStartPosition(), getJavadocLength(sourceDocument, javadoc)) : "");
+ } catch (BadLocationException e) {}
+ prefix = node.getName().getFullyQualifiedName();
+ return true;
+ }
+ return false;
+ }
+ });
+
+
+ final List<Edit> edits = new ArrayList<>();
+ targetUnit.accept(new ASTVisitor() {
+ String prefix = "";
+ @Override
+ public boolean visit(Block node) {
+ return false;
+ }
+ @Override
+ public boolean visit(VariableDeclarationFragment node) {
+ FieldDeclaration field = (FieldDeclaration)node.getParent();
+ int mods = field.getModifiers();
+ if (Modifier.isPublic(mods) || Modifier.isProtected(mods)) {
+ Javadoc javadoc = field.getJavadoc();
+ if (field.fragments().size() > 1 && javadoc != null) {
+ System.err.println("Field declaration with multiple variables is not supported. -> " + target + " " + node.getName().getFullyQualifiedName());
+ }
+ String key = prefix + "." + node.getName().getFullyQualifiedName();
+ String newComment = comments.get(key);
+ if (newComment != null) {
+ comments.remove(key);
+ if (javadoc != null) {
+ edits.add(new Edit(javadoc.getStartPosition(), getJavadocLength(targetDocument, javadoc), newComment));
+ } else {
+ edits.add(new Edit(field.getStartPosition(), 0, newComment));
+ }
+ }
+ return true;
+ }
+ return false;
+ }
+ @Override
+ public boolean visit(MethodDeclaration node) {
+ int mods = node.getModifiers();
+ if (Modifier.isPublic(mods) || Modifier.isProtected(mods)) {
+ Javadoc javadoc = node.getJavadoc();
+ String key = prefix + "." + node.getName().getFullyQualifiedName();
+ for (Iterator<SingleVariableDeclaration> iterator = node.parameters().iterator(); iterator.hasNext();) {
+ SingleVariableDeclaration param = iterator.next();
+ key += param.getType().toString();
+ }
+ String newComment = comments.get(key);
+ if (newComment != null) {
+ comments.remove(key);
+ if (javadoc != null) {
+ edits.add(new Edit(javadoc.getStartPosition(), getJavadocLength(targetDocument, javadoc), newComment));
+ } else {
+ edits.add(new Edit(node.getStartPosition(), 0, newComment));
+ }
+ }
+ return true;
+ }
+ return false;
+ }
+ @Override
+ public boolean visit(TypeDeclaration node) {
+ int mods = node.getModifiers();
+ if (Modifier.isPublic(mods) || Modifier.isProtected(mods)) {
+ Javadoc javadoc = node.getJavadoc();
+ String key = prefix + "." + node.getName().getFullyQualifiedName();
+ String newComment = comments.get(key);
+ if (newComment != null) {
+ comments.remove(key);
+ if (javadoc != null) {
+ edits.add(new Edit(javadoc.getStartPosition(), getJavadocLength(targetDocument, javadoc), newComment));
+ } else {
+ edits.add(new Edit(node.getStartPosition(), 0, newComment));
+ }
+ }
+ prefix = node.getName().getFullyQualifiedName();
+ return true;
+ }
+ return false;
+ }
+ });
+
+ for (int i = edits.size() - 1; i >=0 ; i--) {
+ Edit edit = edits.get(i);
+ try {
+ targetDocument.replace(edit.start, edit.length, edit.text);
+ } catch (BadLocationException e) {
+ e.printStackTrace();
+ }
+ }
+ /* Rudimentary API consistency checker.
+ * This assumes that:
+ * a) the sourceSubdir (typically win32) API is correct
+ * b) all sourceSubdir API classes, methods and fields do have a comment
+ * c) names that are in the filter list are never API,
+ * or they are old API that is defined in the super on some platforms
+ */
+ if (comments.size() > 0) {
+ String [] filter = new String [] {
+ "Color.win32_newDeviceint",
+ "Cursor.win32_newDeviceint",
+ "Device.hPalette",
+ "Font.win32_newDevicelong",
+ "FontData.data",
+ "FontData.win32_newLOGFONTfloat",
+ "FontMetrics.handle",
+ "FontMetrics.win32_newTEXTMETRIC",
+ "GC.win32_newlongGCData",
+ "GC.win32_newDrawableGCData",
+ "Image.win32_newDeviceintlong",
+ "Pattern.handle",
+ "Region.win32_newDeviceint",
+ "Control.handle",
+ "Display.getSystemFont",
+ "Display.msg",
+ "Menu.handle",
+ "Shell.win32_newDisplaylong",
+ "Accessible.internal_WM_GETOBJECTlonglong",
+ "TransferData.result",
+ "TransferData.stgmedium",
+ "TransferData.pIDataObject",
+ "TransferData.formatetc",
+ "Printer.handle",
+ "Printer.checkDevice",
+ "TableDragSourceEffect.dragFinishedDragSourceEvent",
+ "TableDragSourceEffect.dragStartDragSourceEvent",
+ "TableDropTargetEffect.dragOverDropTargetEvent",
+ "TableDropTargetEffect.dragEnterDropTargetEvent",
+ "TableDropTargetEffect.dragLeaveDropTargetEvent",
+ "Transfer.validateObject",
+ "TransferData.result",
+ "TransferData.stgmedium",
+ "TransferData.pIDataObject",
+ "TransferData.formatetc",
+ "TreeDragSourceEffect.dragFinishedDragSourceEvent",
+ "TreeDragSourceEffect.dragStartDragSourceEvent",
+ "TreeDropTargetEffect.dragLeaveDropTargetEvent",
+ "TreeDropTargetEffect.dragEnterDropTargetEvent",
+ "TreeDropTargetEffect.dragOverDropTargetEvent",
+ "Printer.createDeviceData",
+ "Printer.internal_dispose_GClongGCData",
+ "Printer.release",
+ "Printer.destroy",
+ "Image.handle",
+ "Display.getClientArea",
+ "TreeItem.handle",
+ };
+ for (Entry<String, String> entry: comments.entrySet()) {
+ String name = entry.getKey();
+ if (entry.getValue().length() > 0){
+ int i = 0;
+ for (i = 0; i < filter.length; i++) {
+ if (name.equals(filter[i])) break;
+ }
+ if (i >= filter.length) {
+ System.err.println("***No target for " + name);
+ }
+ }
+ }
+ }
+
+ String newContents = targetDocument.get();
+ if (!targetContents.equals(newContents)) {
+ if (makeDirectory(out.getParentFile())) {
+ writeFile(newContents.toCharArray(), out);
+ fBashed.add(target.toString());
+ } else {
+ System.out.println("*** Could not create " + out.getParent());
+ }
+ } else {
+ fUnchanged.add(target.toString());
+ }
+ }
+
+ int getJavadocLength(Document sourceDocument, Javadoc javadoc) {
+ return skipWhitespace(sourceDocument, javadoc.getStartPosition() + javadoc.getLength()) - javadoc.getStartPosition();
+ }
+
+ int skipWhitespace(Document doc, int offset) {
+ try {
+ while (Character.isWhitespace(doc.getChar(offset))){
+ offset++;
+ }
+ } catch (BadLocationException e) {
+ }
+ return offset;
+ }
+
+ boolean makeDirectory(File directory) {
+ if (directory.exists())
+ return true;
+ return directory.mkdirs();
+ }
+
+ List<String> getBashed() {
+ return fBashed;
+ }
+
+ List<String> getUnchanged() {
+ return fUnchanged;
+ }
+
+ List<String> getSkipped() {
+ return fSkipped;
+ }
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/MouseNavigator.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/MouseNavigator.java
index 784b942612..1857d0f043 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/MouseNavigator.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/MouseNavigator.java
@@ -1,294 +1,294 @@
-/**
- * Copyright (c) 2019 Laurent CARON.
- *
- * This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License 2.0
- * which accompanies this distribution, and is available at
- * https://www.eclipse.org/legal/epl-2.0/
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
- * Laurent CARON (laurent.caron at gmail dot com) - initial API and implementation (bug 542777)
- */
-package org.eclipse.swt.custom;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.widgets.*;
-
-/**
- * This class add the following behaviour to <code>StyledText</code> widgets:<br/>
- * When the user clicks on the wheel, a circle with arrows appears. When the user moves the mouse,
- * the StyledText content is scrolled (on the right or on the left for horizontal movements, up or down for vertical movements).<br/>
- *
- * @since 3.110
- */
-class MouseNavigator {
- private final StyledText parent;
- boolean navigationActivated = false;
- private GC gc;
- private static final int CIRCLE_RADIUS = 15;
- private static final int CENTRAL_POINT_RADIUS = 2;
- private Point originalMouseLocation;
- private final Listener mouseDownListener, mouseUpListener, paintListener, mouseMoveListener, focusOutListener;
- private boolean hasHBar, hasVBar;
- private Cursor previousCursor;
-
- MouseNavigator(final StyledText styledText) {
- if (styledText == null) {
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- }
- if (styledText.isDisposed()) {
- SWT.error(SWT.ERROR_WIDGET_DISPOSED);
- }
- parent = styledText;
-
- mouseDownListener = (event) -> {
- onMouseDown(event);
- };
- parent.addListener(SWT.MouseDown, mouseDownListener);
-
- mouseUpListener = (event) -> {
- onMouseUp(event);
- };
- parent.addListener(SWT.MouseUp, mouseUpListener);
-
- paintListener = (event) -> {
- onPaint(event);
- };
- parent.addListener(SWT.Paint, paintListener);
-
- mouseMoveListener = (event) -> {
- onMouseMove(event);
- };
- parent.addListener(SWT.MouseMove, mouseMoveListener);
-
- focusOutListener = (event) -> {
- onFocusOut(event);
- };
- parent.addListener(SWT.FocusOut, focusOutListener);
- }
-
- void onMouseDown(Event e) {
- if ((e.button != 2) || navigationActivated) {
- return;
- }
-
- if (!parent.isVisible() || !parent.getEnabled() || parent.middleClickPressed) {
- return;
- }
-
- // Widget has no bar or bars are not enabled
- initBarState();
-
- if (!hasHBar && !hasVBar) {
- return;
- }
-
- navigationActivated = true;
- previousCursor = parent.getCursor();
- parent.setCursor(parent.getDisplay().getSystemCursor(SWT.CURSOR_ARROW));
- originalMouseLocation = getMouseLocation();
- parent.redraw();
- }
-
- private void initBarState() {
- hasHBar = computeHasHorizontalBar();
- hasVBar = computeHasVerticalBar();
- }
-
- private boolean computeHasHorizontalBar() {
- final ScrollBar horizontalBar = parent.getHorizontalBar();
- final boolean hasHorizontalBar = horizontalBar != null && horizontalBar.isVisible();
- final boolean exceedHorizontalSpace = parent.computeSize(SWT.DEFAULT, SWT.DEFAULT).x > parent.getSize().x;
- return hasHorizontalBar && exceedHorizontalSpace;
- }
-
- private boolean computeHasVerticalBar() {
- final ScrollBar verticalBar = parent.getVerticalBar();
- final boolean hasVerticalBar = verticalBar != null && verticalBar.isEnabled();
- final boolean exceedVerticalSpace = parent.computeSize(SWT.DEFAULT, SWT.DEFAULT).y > parent.getSize().y;
- return hasVerticalBar && exceedVerticalSpace;
- }
-
- private void onMouseUp(Event e) {
- if ((computeDist() < CIRCLE_RADIUS) && (computeDist() >= 0)) {
- return;
- }
- deactivate();
- }
-
- public int computeDist() {
- if (originalMouseLocation == null) {
- return -1;
- }
- final Point mouseLocation = getMouseLocation();
- final int deltaX = originalMouseLocation.x - mouseLocation.x;
- final int deltaY = originalMouseLocation.y - mouseLocation.y;
- final int dist = (int) Math.sqrt(deltaX * deltaX + deltaY * deltaY);
- return dist;
- }
-
- private void deactivate() {
- parent.setCursor(previousCursor);
- navigationActivated = false;
- originalMouseLocation = null;
- parent.redraw();
- }
-
- private void onFocusOut(Event e) {
- deactivate();
- }
-
- private void onMouseMove(Event e) {
- if (!navigationActivated) {
- return;
- }
-
- final Point mouseLocation = getMouseLocation();
- final int deltaX = originalMouseLocation.x - mouseLocation.x;
- final int deltaY = originalMouseLocation.y - mouseLocation.y;
- final int dist = (int) Math.sqrt(deltaX * deltaX + deltaY * deltaY);
- if (dist < CIRCLE_RADIUS) {
- return;
- }
-
- parent.setRedraw(false);
- if (hasHBar) {
- final ScrollBar bar = parent.getHorizontalBar();
- bar.setSelection((int) (bar.getSelection() - deltaX * .1));
- fireSelectionEvent(e, bar);
- }
-
- if (hasVBar) {
- final ScrollBar bar = parent.getVerticalBar();
- bar.setSelection((int) (bar.getSelection() - deltaY * .1));
- fireSelectionEvent(e, bar);
- }
- parent.setRedraw(true);
- parent.redraw();
- }
-
- private void fireSelectionEvent(final Event e, final ScrollBar bar) {
- final Event event = new Event();
- event.widget = bar;
- event.display = parent.getDisplay();
- event.type = SWT.Selection;
- event.time = e.time;
-
- for (final Listener selectionListener : bar.getListeners(SWT.Selection)) {
- selectionListener.handleEvent(event);
- }
- }
-
- private Point getMouseLocation() {
- final Point cursorLocation = Display.getCurrent().getCursorLocation();
- final Point relativeCursorLocation = parent.toControl(cursorLocation);
- return relativeCursorLocation;
- }
-
- private void onPaint(final Event e) {
- if (!navigationActivated) {
- return;
- }
-
- final Rectangle rect = parent.getClientArea();
- if (rect.width == 0 || rect.height == 0) {
- return;
- }
- gc = e.gc;
- gc.setAntialias(SWT.ON);
- gc.setAdvanced(true);
-
- final Color oldForegroundColor = gc.getForeground();
- final Color oldBackgroundColor = gc.getBackground();
- gc.setBackground(parent.getForeground());
-
- drawCircle();
- drawCentralPoint();
-
- drawArrows();
-
- gc.setForeground(oldForegroundColor);
- gc.setBackground(oldBackgroundColor);
- }
-
- private void drawCircle() {
- gc.setBackground(parent.getBackground());
- gc.setForeground(parent.getForeground());
- gc.setAlpha(200);
- gc.fillOval(originalMouseLocation.x - CIRCLE_RADIUS, originalMouseLocation.y - CIRCLE_RADIUS, CIRCLE_RADIUS * 2, CIRCLE_RADIUS * 2);
- gc.setBackground(parent.getForeground());
- gc.setAlpha(255);
- gc.drawOval(originalMouseLocation.x - CIRCLE_RADIUS, originalMouseLocation.y - CIRCLE_RADIUS, CIRCLE_RADIUS * 2, CIRCLE_RADIUS * 2);
- }
-
- private void drawCentralPoint() {
- gc.fillOval(originalMouseLocation.x - CENTRAL_POINT_RADIUS, originalMouseLocation.y - CENTRAL_POINT_RADIUS, CENTRAL_POINT_RADIUS * 2, CENTRAL_POINT_RADIUS * 2);
- }
-
- private void drawArrows() {
- gc.setLineWidth(2);
- if (hasHBar) {
- drawHorizontalArrows();
- }
- if (hasVBar) {
- drawVerticalArrows();
- }
- }
-
- private void drawHorizontalArrows() {
- final int[] points = new int[6];
- // Left
- points[0] = originalMouseLocation.x - 6;
- points[1] = originalMouseLocation.y + 3;
- points[2] = originalMouseLocation.x - 9;
- points[3] = originalMouseLocation.y;
- points[4] = originalMouseLocation.x - 6;
- points[5] = originalMouseLocation.y - 3;
- gc.drawPolyline(points);
-
- // Right
- points[0] = originalMouseLocation.x + 7;
- points[1] = originalMouseLocation.y + 3;
- points[2] = originalMouseLocation.x + 10;
- points[3] = originalMouseLocation.y;
- points[4] = originalMouseLocation.x + 7;
- points[5] = originalMouseLocation.y - 3;
- gc.drawPolyline(points);
- }
-
- private void drawVerticalArrows() {
- final int[] points = new int[6];
- // Upper
- points[0] = originalMouseLocation.x - 3;
- points[1] = originalMouseLocation.y - 6;
- points[2] = originalMouseLocation.x;
- points[3] = originalMouseLocation.y - 10;
- points[4] = originalMouseLocation.x + 3;
- points[5] = originalMouseLocation.y - 6;
- gc.drawPolyline(points);
-
- // Lower
- points[0] = originalMouseLocation.x - 3;
- points[1] = originalMouseLocation.y + 7;
- points[2] = originalMouseLocation.x;
- points[3] = originalMouseLocation.y + 11;
- points[4] = originalMouseLocation.x + 3;
- points[5] = originalMouseLocation.y + 7;
- gc.drawPolyline(points);
-
- }
-
- void dispose() {
- if (parent.isDisposed()) {
- return;
- }
- parent.removeListener(SWT.MouseDown, mouseDownListener);
- parent.removeListener(SWT.MouseUp, mouseUpListener);
- parent.removeListener(SWT.Paint, paintListener);
- parent.removeListener(SWT.MouseMove, mouseMoveListener);
- parent.removeListener(SWT.MouseExit, focusOutListener);
- }
-}
+/**
+ * Copyright (c) 2019 Laurent CARON.
+ *
+ * This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Laurent CARON (laurent.caron at gmail dot com) - initial API and implementation (bug 542777)
+ */
+package org.eclipse.swt.custom;
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.widgets.*;
+
+/**
+ * This class add the following behaviour to <code>StyledText</code> widgets:<br/>
+ * When the user clicks on the wheel, a circle with arrows appears. When the user moves the mouse,
+ * the StyledText content is scrolled (on the right or on the left for horizontal movements, up or down for vertical movements).<br/>
+ *
+ * @since 3.110
+ */
+class MouseNavigator {
+ private final StyledText parent;
+ boolean navigationActivated = false;
+ private GC gc;
+ private static final int CIRCLE_RADIUS = 15;
+ private static final int CENTRAL_POINT_RADIUS = 2;
+ private Point originalMouseLocation;
+ private final Listener mouseDownListener, mouseUpListener, paintListener, mouseMoveListener, focusOutListener;
+ private boolean hasHBar, hasVBar;
+ private Cursor previousCursor;
+
+ MouseNavigator(final StyledText styledText) {
+ if (styledText == null) {
+ SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ }
+ if (styledText.isDisposed()) {
+ SWT.error(SWT.ERROR_WIDGET_DISPOSED);
+ }
+ parent = styledText;
+
+ mouseDownListener = (event) -> {
+ onMouseDown(event);
+ };
+ parent.addListener(SWT.MouseDown, mouseDownListener);
+
+ mouseUpListener = (event) -> {
+ onMouseUp(event);
+ };
+ parent.addListener(SWT.MouseUp, mouseUpListener);
+
+ paintListener = (event) -> {
+ onPaint(event);
+ };
+ parent.addListener(SWT.Paint, paintListener);
+
+ mouseMoveListener = (event) -> {
+ onMouseMove(event);
+ };
+ parent.addListener(SWT.MouseMove, mouseMoveListener);
+
+ focusOutListener = (event) -> {
+ onFocusOut(event);
+ };
+ parent.addListener(SWT.FocusOut, focusOutListener);
+ }
+
+ void onMouseDown(Event e) {
+ if ((e.button != 2) || navigationActivated) {
+ return;
+ }
+
+ if (!parent.isVisible() || !parent.getEnabled() || parent.middleClickPressed) {
+ return;
+ }
+
+ // Widget has no bar or bars are not enabled
+ initBarState();
+
+ if (!hasHBar && !hasVBar) {
+ return;
+ }
+
+ navigationActivated = true;
+ previousCursor = parent.getCursor();
+ parent.setCursor(parent.getDisplay().getSystemCursor(SWT.CURSOR_ARROW));
+ originalMouseLocation = getMouseLocation();
+ parent.redraw();
+ }
+
+ private void initBarState() {
+ hasHBar = computeHasHorizontalBar();
+ hasVBar = computeHasVerticalBar();
+ }
+
+ private boolean computeHasHorizontalBar() {
+ final ScrollBar horizontalBar = parent.getHorizontalBar();
+ final boolean hasHorizontalBar = horizontalBar != null && horizontalBar.isVisible();
+ final boolean exceedHorizontalSpace = parent.computeSize(SWT.DEFAULT, SWT.DEFAULT).x > parent.getSize().x;
+ return hasHorizontalBar && exceedHorizontalSpace;
+ }
+
+ private boolean computeHasVerticalBar() {
+ final ScrollBar verticalBar = parent.getVerticalBar();
+ final boolean hasVerticalBar = verticalBar != null && verticalBar.isEnabled();
+ final boolean exceedVerticalSpace = parent.computeSize(SWT.DEFAULT, SWT.DEFAULT).y > parent.getSize().y;
+ return hasVerticalBar && exceedVerticalSpace;
+ }
+
+ private void onMouseUp(Event e) {
+ if ((computeDist() < CIRCLE_RADIUS) && (computeDist() >= 0)) {
+ return;
+ }
+ deactivate();
+ }
+
+ public int computeDist() {
+ if (originalMouseLocation == null) {
+ return -1;
+ }
+ final Point mouseLocation = getMouseLocation();
+ final int deltaX = originalMouseLocation.x - mouseLocation.x;
+ final int deltaY = originalMouseLocation.y - mouseLocation.y;
+ final int dist = (int) Math.sqrt(deltaX * deltaX + deltaY * deltaY);
+ return dist;
+ }
+
+ private void deactivate() {
+ parent.setCursor(previousCursor);
+ navigationActivated = false;
+ originalMouseLocation = null;
+ parent.redraw();
+ }
+
+ private void onFocusOut(Event e) {
+ deactivate();
+ }
+
+ private void onMouseMove(Event e) {
+ if (!navigationActivated) {
+ return;
+ }
+
+ final Point mouseLocation = getMouseLocation();
+ final int deltaX = originalMouseLocation.x - mouseLocation.x;
+ final int deltaY = originalMouseLocation.y - mouseLocation.y;
+ final int dist = (int) Math.sqrt(deltaX * deltaX + deltaY * deltaY);
+ if (dist < CIRCLE_RADIUS) {
+ return;
+ }
+
+ parent.setRedraw(false);
+ if (hasHBar) {
+ final ScrollBar bar = parent.getHorizontalBar();
+ bar.setSelection((int) (bar.getSelection() - deltaX * .1));
+ fireSelectionEvent(e, bar);
+ }
+
+ if (hasVBar) {
+ final ScrollBar bar = parent.getVerticalBar();
+ bar.setSelection((int) (bar.getSelection() - deltaY * .1));
+ fireSelectionEvent(e, bar);
+ }
+ parent.setRedraw(true);
+ parent.redraw();
+ }
+
+ private void fireSelectionEvent(final Event e, final ScrollBar bar) {
+ final Event event = new Event();
+ event.widget = bar;
+ event.display = parent.getDisplay();
+ event.type = SWT.Selection;
+ event.time = e.time;
+
+ for (final Listener selectionListener : bar.getListeners(SWT.Selection)) {
+ selectionListener.handleEvent(event);
+ }
+ }
+
+ private Point getMouseLocation() {
+ final Point cursorLocation = Display.getCurrent().getCursorLocation();
+ final Point relativeCursorLocation = parent.toControl(cursorLocation);
+ return relativeCursorLocation;
+ }
+
+ private void onPaint(final Event e) {
+ if (!navigationActivated) {
+ return;
+ }
+
+ final Rectangle rect = parent.getClientArea();
+ if (rect.width == 0 || rect.height == 0) {
+ return;
+ }
+ gc = e.gc;
+ gc.setAntialias(SWT.ON);
+ gc.setAdvanced(true);
+
+ final Color oldForegroundColor = gc.getForeground();
+ final Color oldBackgroundColor = gc.getBackground();
+ gc.setBackground(parent.getForeground());
+
+ drawCircle();
+ drawCentralPoint();
+
+ drawArrows();
+
+ gc.setForeground(oldForegroundColor);
+ gc.setBackground(oldBackgroundColor);
+ }
+
+ private void drawCircle() {
+ gc.setBackground(parent.getBackground());
+ gc.setForeground(parent.getForeground());
+ gc.setAlpha(200);
+ gc.fillOval(originalMouseLocation.x - CIRCLE_RADIUS, originalMouseLocation.y - CIRCLE_RADIUS, CIRCLE_RADIUS * 2, CIRCLE_RADIUS * 2);
+ gc.setBackground(parent.getForeground());
+ gc.setAlpha(255);
+ gc.drawOval(originalMouseLocation.x - CIRCLE_RADIUS, originalMouseLocation.y - CIRCLE_RADIUS, CIRCLE_RADIUS * 2, CIRCLE_RADIUS * 2);
+ }
+
+ private void drawCentralPoint() {
+ gc.fillOval(originalMouseLocation.x - CENTRAL_POINT_RADIUS, originalMouseLocation.y - CENTRAL_POINT_RADIUS, CENTRAL_POINT_RADIUS * 2, CENTRAL_POINT_RADIUS * 2);
+ }
+
+ private void drawArrows() {
+ gc.setLineWidth(2);
+ if (hasHBar) {
+ drawHorizontalArrows();
+ }
+ if (hasVBar) {
+ drawVerticalArrows();
+ }
+ }
+
+ private void drawHorizontalArrows() {
+ final int[] points = new int[6];
+ // Left
+ points[0] = originalMouseLocation.x - 6;
+ points[1] = originalMouseLocation.y + 3;
+ points[2] = originalMouseLocation.x - 9;
+ points[3] = originalMouseLocation.y;
+ points[4] = originalMouseLocation.x - 6;
+ points[5] = originalMouseLocation.y - 3;
+ gc.drawPolyline(points);
+
+ // Right
+ points[0] = originalMouseLocation.x + 7;
+ points[1] = originalMouseLocation.y + 3;
+ points[2] = originalMouseLocation.x + 10;
+ points[3] = originalMouseLocation.y;
+ points[4] = originalMouseLocation.x + 7;
+ points[5] = originalMouseLocation.y - 3;
+ gc.drawPolyline(points);
+ }
+
+ private void drawVerticalArrows() {
+ final int[] points = new int[6];
+ // Upper
+ points[0] = originalMouseLocation.x - 3;
+ points[1] = originalMouseLocation.y - 6;
+ points[2] = originalMouseLocation.x;
+ points[3] = originalMouseLocation.y - 10;
+ points[4] = originalMouseLocation.x + 3;
+ points[5] = originalMouseLocation.y - 6;
+ gc.drawPolyline(points);
+
+ // Lower
+ points[0] = originalMouseLocation.x - 3;
+ points[1] = originalMouseLocation.y + 7;
+ points[2] = originalMouseLocation.x;
+ points[3] = originalMouseLocation.y + 11;
+ points[4] = originalMouseLocation.x + 3;
+ points[5] = originalMouseLocation.y + 7;
+ gc.drawPolyline(points);
+
+ }
+
+ void dispose() {
+ if (parent.isDisposed()) {
+ return;
+ }
+ parent.removeListener(SWT.MouseDown, mouseDownListener);
+ parent.removeListener(SWT.MouseUp, mouseUpListener);
+ parent.removeListener(SWT.Paint, paintListener);
+ parent.removeListener(SWT.MouseMove, mouseMoveListener);
+ parent.removeListener(SWT.MouseExit, focusOutListener);
+ }
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextLineSpacingProvider.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextLineSpacingProvider.java
index 8d0474677b..430a77d6b4 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextLineSpacingProvider.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextLineSpacingProvider.java
@@ -1,37 +1,37 @@
-/**
- * Copyright (c) 2017 Angelo ZERR.
+/**
+ * Copyright (c) 2017 Angelo ZERR.
*
- * This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License 2.0
- * which accompanies this distribution, and is available at
+ * This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
- * SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
- * Angelo Zerr <angelo.zerr@gmail.com> - Customize different line spacing of StyledText - Bug 522020
- */
-package org.eclipse.swt.custom;
-
-/**
- * Line spacing provider used to customize different line spacing for some lines
- * of {@link StyledText}
- *
- * @since 3.107
- */
-@FunctionalInterface
-public interface StyledTextLineSpacingProvider {
-
- /**
- * Returns the line spacing of the given line index and null otherwise. In this
- * case, it will use the {@link StyledText#getLineSpacing()}.
- *
- * @param lineIndex
- * line index.
- * @return the line spacing of the given line index and null otherwise. In this
- * case, it will use the {@link StyledText#getLineSpacing()}.
- * @since 3.107
- */
- Integer getLineSpacing(int lineIndex);
-
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Angelo Zerr <angelo.zerr@gmail.com> - Customize different line spacing of StyledText - Bug 522020
+ */
+package org.eclipse.swt.custom;
+
+/**
+ * Line spacing provider used to customize different line spacing for some lines
+ * of {@link StyledText}
+ *
+ * @since 3.107
+ */
+@FunctionalInterface
+public interface StyledTextLineSpacingProvider {
+
+ /**
+ * Returns the line spacing of the given line index and null otherwise. In this
+ * case, it will use the {@link StyledText#getLineSpacing()}.
+ *
+ * @param lineIndex
+ * line index.
+ * @return the line spacing of the given line index and null otherwise. In this
+ * case, it will use the {@link StyledText#getLineSpacing()}.
+ * @since 3.107
+ */
+ Integer getLineSpacing(int lineIndex);
+
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/com/win32/FileDialogVtbl.java b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/com/win32/FileDialogVtbl.java
index a9f8bdf8e2..bc69d3574d 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/com/win32/FileDialogVtbl.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/com/win32/FileDialogVtbl.java
@@ -1,47 +1,47 @@
-/*******************************************************************************
- * Copyright (c) 2017 Martin Karpisek and others.
+/*******************************************************************************
+ * Copyright (c) 2017 Martin Karpisek and others.
*
- * This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License 2.0
- * which accompanies this distribution, and is available at
+ * This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
- * SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
- * Martin Karpisek <martin.karpisek@gmail.com> - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.internal.com.win32;
-
-/**
- * Function number constants for IFileDialog COM interface
- */
-public class FileDialogVtbl{
- public static final int QUERY_INTERFACE = 0;
- public static final int ADD_REF = 1;
- public static final int RELEASE = 2;
- public static final int SHOW = 3;
- public static final int SET_FILE_TYPES = 4;
- public static final int SET_FILE_TYPE_INDEX = 5;
- public static final int GET_FILE_TYPE_INDEX = 6;
- public static final int ADVISE = 7;
- public static final int UNADVISE = 8;
- public static final int SET_OPTIONS = 9;
- public static final int GET_OPTIONS = 10;
- public static final int SET_DEFAULT_FOLDER = 11;
- public static final int SET_FOLDER = 12;
- public static final int GET_FOLDER = 13;
- public static final int GET_CURRENT_SELECTION = 14;
- public static final int SET_FILE_NAME = 15;
- public static final int GET_FILE_NAME = 16;
- public static final int SET_TITLE = 17;
- public static final int SET_OK_BUTTON_LABEL = 18;
- public static final int SET_FILE_NAME_LABEL = 19;
- public static final int GET_RESULT = 20;
- public static final int ADD_PLACE = 21;
- public static final int SET_DEFAULT_EXTENSION = 22;
- public static final int CLOSE = 23;
- public static final int SET_CLIENT_GUID = 24;
- public static final int CLEAR_CLIENT_DATA = 25;
- public static final int SET_FILTER = 26;
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Martin Karpisek <martin.karpisek@gmail.com> - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.swt.internal.com.win32;
+
+/**
+ * Function number constants for IFileDialog COM interface
+ */
+public class FileDialogVtbl{
+ public static final int QUERY_INTERFACE = 0;
+ public static final int ADD_REF = 1;
+ public static final int RELEASE = 2;
+ public static final int SHOW = 3;
+ public static final int SET_FILE_TYPES = 4;
+ public static final int SET_FILE_TYPE_INDEX = 5;
+ public static final int GET_FILE_TYPE_INDEX = 6;
+ public static final int ADVISE = 7;
+ public static final int UNADVISE = 8;
+ public static final int SET_OPTIONS = 9;
+ public static final int GET_OPTIONS = 10;
+ public static final int SET_DEFAULT_FOLDER = 11;
+ public static final int SET_FOLDER = 12;
+ public static final int GET_FOLDER = 13;
+ public static final int GET_CURRENT_SELECTION = 14;
+ public static final int SET_FILE_NAME = 15;
+ public static final int GET_FILE_NAME = 16;
+ public static final int SET_TITLE = 17;
+ public static final int SET_OK_BUTTON_LABEL = 18;
+ public static final int SET_FILE_NAME_LABEL = 19;
+ public static final int GET_RESULT = 20;
+ public static final int ADD_PLACE = 21;
+ public static final int SET_DEFAULT_EXTENSION = 22;
+ public static final int CLOSE = 23;
+ public static final int SET_CLIENT_GUID = 24;
+ public static final int CLEAR_CLIENT_DATA = 25;
+ public static final int SET_FILTER = 26;
} \ No newline at end of file
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/com/win32/ShellItemVtbl.java b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/com/win32/ShellItemVtbl.java
index 4ab2c96ef5..44d16a2605 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/com/win32/ShellItemVtbl.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/com/win32/ShellItemVtbl.java
@@ -1,28 +1,28 @@
-/*******************************************************************************
- * Copyright (c) 2017 Martin Karpisek and others.
+/*******************************************************************************
+ * Copyright (c) 2017 Martin Karpisek and others.
*
- * This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License 2.0
- * which accompanies this distribution, and is available at
+ * This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
- * SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
- * Martin Karpisek <martin.karpisek@gmail.com> - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.internal.com.win32;
-
-/**
- * Function number constants for IShellItem COM interface
- */
-public class ShellItemVtbl{
- public static final int QUERY_INTERFACE = 0;
- public static final int ADD_REF = 1;
- public static final int RELEASE = 2;
- public static final int BIND_TO_HANDLER = 3;
- public static final int GET_PARENT = 4;
- public static final int GET_DISPLAY_NAME = 5;
- public static final int GET_ATTRIBUTES = 6;
- public static final int COMPARE = 7;
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Martin Karpisek <martin.karpisek@gmail.com> - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.swt.internal.com.win32;
+
+/**
+ * Function number constants for IShellItem COM interface
+ */
+public class ShellItemVtbl{
+ public static final int QUERY_INTERFACE = 0;
+ public static final int ADD_REF = 1;
+ public static final int RELEASE = 2;
+ public static final int BIND_TO_HANDLER = 3;
+ public static final int GET_PARENT = 4;
+ public static final int GET_DISPLAY_NAME = 5;
+ public static final int GET_ATTRIBUTES = 6;
+ public static final int COMPARE = 7;
} \ No newline at end of file
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet364.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet364.java
index 4a2afa0ef2..50046eeeb6 100644
--- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet364.java
+++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet364.java
@@ -1,66 +1,66 @@
-/*******************************************************************************
- * Copyright (c) 2013 IBM Corporation and others.
+/*******************************************************************************
+ * Copyright (c) 2013 IBM Corporation and others.
*
- * This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License 2.0
- * which accompanies this distribution, and is available at
+ * This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
- * SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.snippets;
-
-/*
- * BIDI example snippet: Set the text direction independent of the widget orientation.
- *
- * Note: This snippet currently only works on Windows.
- *
- * For a list of all SWT example snippets see
- * http://www.eclipse.org/swt/snippets/
- */
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.layout.*;
-import org.eclipse.swt.widgets.*;
-
-public class Snippet364 {
-
- public static void main(String[] args) {
- Display display = new Display();
- Shell shell = new Shell(display);
- shell.setLayout(new GridLayout(1, false));
-
- Image i = new Image(display, Snippet364.class.getResourceAsStream("eclipse.png"));
- Button b = new Button(shell, SWT.PUSH | SWT.LEFT_TO_RIGHT);
- b.setText("Button LEFT_TO_RIGHT...");
- b.setImage(i);
-
- Button b2 = new Button(shell, SWT.PUSH | SWT.RIGHT_TO_LEFT);
- b2.setText("Button RIGHT_TO_LEFT...");
- b2.setImage(i);
-
- new Label(shell, SWT.NONE).setText("with FLIP_TEXT_DIRECTION:");
-
- Button b3 = new Button(shell, SWT.PUSH | SWT.LEFT_TO_RIGHT | SWT.FLIP_TEXT_DIRECTION);
- b3.setText("Button LEFT_TO_RIGHT...");
- b3.setImage(i);
-
- Button b4 = new Button(shell, SWT.PUSH | SWT.RIGHT_TO_LEFT | SWT.FLIP_TEXT_DIRECTION);
- b4.setText("Button RIGHT_TO_LEFT...");
- b4.setImage(i);
-
- shell.pack();
- shell.open();
- while (!shell.isDisposed()) {
- if (!display.readAndDispatch())
- display.sleep();
- }
- display.dispose();
- i.dispose();
- }
-
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.swt.snippets;
+
+/*
+ * BIDI example snippet: Set the text direction independent of the widget orientation.
+ *
+ * Note: This snippet currently only works on Windows.
+ *
+ * For a list of all SWT example snippets see
+ * http://www.eclipse.org/swt/snippets/
+ */
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.layout.*;
+import org.eclipse.swt.widgets.*;
+
+public class Snippet364 {
+
+ public static void main(String[] args) {
+ Display display = new Display();
+ Shell shell = new Shell(display);
+ shell.setLayout(new GridLayout(1, false));
+
+ Image i = new Image(display, Snippet364.class.getResourceAsStream("eclipse.png"));
+ Button b = new Button(shell, SWT.PUSH | SWT.LEFT_TO_RIGHT);
+ b.setText("Button LEFT_TO_RIGHT...");
+ b.setImage(i);
+
+ Button b2 = new Button(shell, SWT.PUSH | SWT.RIGHT_TO_LEFT);
+ b2.setText("Button RIGHT_TO_LEFT...");
+ b2.setImage(i);
+
+ new Label(shell, SWT.NONE).setText("with FLIP_TEXT_DIRECTION:");
+
+ Button b3 = new Button(shell, SWT.PUSH | SWT.LEFT_TO_RIGHT | SWT.FLIP_TEXT_DIRECTION);
+ b3.setText("Button LEFT_TO_RIGHT...");
+ b3.setImage(i);
+
+ Button b4 = new Button(shell, SWT.PUSH | SWT.RIGHT_TO_LEFT | SWT.FLIP_TEXT_DIRECTION);
+ b4.setText("Button RIGHT_TO_LEFT...");
+ b4.setImage(i);
+
+ shell.pack();
+ shell.open();
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch())
+ display.sleep();
+ }
+ display.dispose();
+ i.dispose();
+ }
+
+}
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet365.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet365.java
index e6b8d04a5a..dfda156c5b 100644
--- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet365.java
+++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet365.java
@@ -1,471 +1,471 @@
-/*******************************************************************************
- * Copyright (c) 2015, 2016 IBM Corporation and others.
+/*******************************************************************************
+ * Copyright (c) 2015, 2016 IBM Corporation and others.
*
- * This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License 2.0
- * which accompanies this distribution, and is available at
+ * This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
- * SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.snippets;
-import static org.eclipse.swt.events.SelectionListener.*;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.custom.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.layout.*;
-import org.eclipse.swt.widgets.*;
-
-/**
- * Transparent Background example snippet: Set transparent background.
- *
- * For a list of all SWT example snippets see
- * http://www.eclipse.org/swt/snippets/
- */
-public class Snippet365 {
- static Image oldImage;
- static Image newImage;
-
- // Containers
- static Composite containerGroup;
- static Canvas canvas;
- static Composite composite;
- static Group group;
- static Sash sash;
-
- // Native
- static Composite nativeGroup;
- static Button buttonCheckBox;
- static ToolBar toolBar;
- static CoolBar coolBar;
- static Label label;
- static Link link;
- static Scale scale;
- static Button radio;
- static Button check;
- static Button push;
-
- // Custom
- static Composite customGroup;
- static CLabel cLabel;
- static StyledText styledText;
- static SashForm sashForm;
- static CTabFolder cTab;
- static CTabFolder gradientCTab;
-
- // Item
- static Composite itemGroup;
- static TabFolder tabFolder;
- static Table table;
- static Tree tree;
- static ExpandBar expandBar;
-
- // As Designed
- static Composite defaultBackgroundGroup;
- static Text text;
- static Combo combo;
- static ProgressBar progressBar;
- static DateTime dateTime;
- static Slider slider;
- static List list;
- static CCombo ccombo;
-
- public static void main(String[] args) {
- final Display display = new Display();
- final Shell shell = new Shell(display);
- shell.setText("Snippet365 - Transparent Background");
- RowLayout layout = new RowLayout(SWT.VERTICAL);
- layout.spacing = 20;
- layout.marginWidth = 10;
- layout.marginHeight = 10;
- shell.setLayout(layout);
- // Standard color background for Shell
- // shell.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
-
- // Gradient background for Shell
- shell.addListener(SWT.Resize, event -> {
- Rectangle rect = shell.getClientArea();
- Image newImage = new Image(display, Math.max(1, rect.width), 1);
- GC gc = new GC(newImage);
- gc.setForeground(display.getSystemColor(SWT.COLOR_BLUE));
- gc.setBackground(display.getSystemColor(SWT.COLOR_GREEN));
- gc.fillGradientRectangle(rect.x, rect.y, rect.width, 1, false);
- gc.dispose();
- shell.setBackgroundImage(newImage);
- if (oldImage != null)
- oldImage.dispose();
- oldImage = newImage;
- });
-
- // Transparent
- buttonCheckBox = new Button(shell, SWT.CHECK | SWT.None);
- buttonCheckBox.setText("SET TRANSPARENT");
- buttonCheckBox.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
- buttonCheckBox.setSelection(false);
- buttonCheckBox.addSelectionListener(widgetSelectedAdapter( e-> {
- boolean transparent = ((Button) e.getSource()).getSelection();
- if (transparent) {
- // ContainerGroup
- containerGroup.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
- canvas.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
- composite.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
- tabFolder.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
- for (TabItem item : tabFolder.getItems()) {
- item.getControl().setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
- }
-
- // Native
- nativeGroup.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
- toolBar.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
- coolBar.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
- label.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
- link.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
- scale.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
- radio.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
- check.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
- group.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
- sash.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
- slider.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
- list.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
-
- // Custom
- customGroup.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
- cLabel.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
- cTab.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_TRANSPARENT));
- gradientCTab.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_TRANSPARENT));
- sashForm.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_TRANSPARENT));
- for (Control control : sashForm.getChildren()) {
- control.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_TRANSPARENT));
- }
- // Default
- push.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
- defaultBackgroundGroup.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
- combo.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
- progressBar.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
- dateTime.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
- ccombo.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
- text.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
- styledText.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
- expandBar.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
- table.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
- tree.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
-
- // ItemGroup
- itemGroup.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
- } else {
- // Native
- nativeGroup.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
- toolBar.setBackground(null);
- coolBar.setBackground(null);
- label.setBackground(null);
- link.setBackground(null);
- scale.setBackground(null);
- RGB rgb = display.getSystemColor(SWT.COLOR_CYAN).getRGB();
- radio.setBackground(new Color(display, new RGBA(rgb.red, rgb.blue, rgb.green, 255)));
- check.setBackgroundImage(getBackgroundImage(display));
- group.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
- sash.setBackground(display.getSystemColor(SWT.COLOR_DARK_CYAN));
- slider.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
- list.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
- text.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
-
- // ContainerGroup
- containerGroup.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
- canvas.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
- composite.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
- tabFolder.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
- for (TabItem item : tabFolder.getItems()) {
- item.getControl().setBackground(display.getSystemColor(SWT.COLOR_CYAN));
- }
- // Custom
- customGroup.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
- cLabel.setBackground((Color) null);
- styledText.setBackground((Color) null);
- sashForm.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
- for (Control control : sashForm.getChildren()) {
- control.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
- }
- cTab.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
-
- gradientCTab.setBackground(
- new Color[] { display.getSystemColor(SWT.COLOR_RED),
- display.getSystemColor(SWT.COLOR_WHITE) }, new int[] { 90 }, true);
-
- // Default
- defaultBackgroundGroup.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
- push.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
- combo.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
- ccombo.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
- dateTime.setBackground(null);
- progressBar.setBackground(null);
- expandBar.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
- table.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
- tree.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
-
- // ItemGroup
- itemGroup.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
- }
-
- }));
-
- // ContainerGroup
- containerGroup = new Composite(shell, SWT.NONE);
- containerGroup.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
- containerGroup.setToolTipText("CONTAINER");
- layout = new RowLayout();
- layout.spacing = 20;
- containerGroup.setLayout(layout);
-
- // Native
- nativeGroup = new Composite(shell, SWT.NONE);
- nativeGroup.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
- nativeGroup.setToolTipText("NATIVE");
- layout = new RowLayout();
- layout.spacing = 20;
- nativeGroup.setLayout(layout);
-
- // Custom
- customGroup = new Composite(shell, SWT.NONE);
- customGroup.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
- customGroup.setToolTipText("CUSTOM");
- layout = new RowLayout();
- layout.spacing = 20;
- customGroup.setLayout(layout);
-
- // AsDesigned
- defaultBackgroundGroup = new Composite(shell, SWT.NONE);
- defaultBackgroundGroup.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
- defaultBackgroundGroup.setToolTipText("Default Background");
- layout = new RowLayout();
- layout.spacing = 20;
- defaultBackgroundGroup.setLayout(layout);
-
- // ItemGroup
- itemGroup = new Composite(shell, SWT.NONE);
- itemGroup.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
- itemGroup.setToolTipText("ITEM");
- layout = new RowLayout();
- layout.spacing = 20;
- itemGroup.setLayout(layout);
-
- // Label
- label = new Label(nativeGroup, SWT.NONE);
- label.setText("Label");
-
- // Radio button
- radio = new Button(nativeGroup, SWT.RADIO);
- radio.setText("Radio Button");
- radio.setSelection(true);
- radio.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
-
- // Checkbox button with image
- check = new Button(nativeGroup, SWT.CHECK);
- check.setText("CheckBox Image");
- check.setSelection(true);
- check.setBackgroundImage(getBackgroundImage(display));
-
- // Push Button
- push = new Button(defaultBackgroundGroup, SWT.PUSH);
- push.setText("Push Button");
-
- // Toolbar
- toolBar = new ToolBar(nativeGroup, SWT.FLAT);
- toolBar.pack();
- ToolItem item = new ToolItem(toolBar, SWT.PUSH);
- item.setText("ToolBar_Item");
-
- // Coolbar
- coolBar = new CoolBar(nativeGroup, SWT.BORDER);
- for (int i=0; i<2; i++) {
- CoolItem item2 = new CoolItem (coolBar, SWT.NONE);
- Button button = new Button (coolBar, SWT.PUSH);
- button.setText ("Button " + i);
- Point size = button.computeSize (SWT.DEFAULT, SWT.DEFAULT);
- item2.setPreferredSize (item2.computeSize (size.x, size.y));
- item2.setControl (button);
- }
- // Scale
- scale = new Scale(nativeGroup, SWT.None);
- scale.setMaximum(100);
- scale.setSelection(20);
-
- // Link
- link = new Link(nativeGroup, SWT.NONE);
- link.setText("<a>Sample link</a>");
-
- // List
- list = new List(nativeGroup, SWT.BORDER);
- list.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
- list.add("List_one");
- list.add("List_two");
- list.add("List_three");
- list.add("List_four");
-
- // Canvas
- canvas = new Canvas (containerGroup, SWT.NONE);
- canvas.setToolTipText("Canvas");
- canvas.addPaintListener(e -> {
- GC gc = e.gc;
- gc.setForeground(display.getSystemColor(SWT.COLOR_RED));
- gc.drawRectangle(e.x+1, e.y+1, e.width-2, e.height-2);
- gc.drawArc(2, 2, e.width-4, e.height-4, 0, 360);
- });
-
- // Composite
- composite = new Composite(containerGroup, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
- composite.setToolTipText("Composite");
-
- // TabFolder
- tabFolder = new TabFolder(containerGroup, SWT.BORDER);
- tabFolder.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
- for (int i=0; i < 2; i++) {
- TabItem tabItem = new TabItem (tabFolder, SWT.NONE);
- tabItem.setText ("TabItem " + i);
- Label label = new Label (tabFolder, SWT.PUSH);
- label.setText ("Page " + i);
- tabItem.setControl (label);
- tabItem.getControl().setBackground(display.getSystemColor(SWT.COLOR_CYAN));
- }
- tabFolder.pack ();
-
- // Group
- group = new Group(containerGroup, SWT.NONE);
- group.setText("Group");
-
- // Sash
- sash = new Sash(containerGroup, SWT.HORIZONTAL | SWT.BORDER);
- sash.setBackground(display.getSystemColor(SWT.COLOR_DARK_CYAN));
- sash.setLayoutData(new RowData(100, 100));
- sash.setToolTipText("Sash");
-
- // SashForm
- sashForm = new SashForm(containerGroup, SWT.HORIZONTAL | SWT.BORDER);
- Label leftLabel = new Label(sashForm, SWT.NONE);
- leftLabel.setText("SashForm\nLeft\n...\n...\n...\n...\n...");
- Label rightLabel = new Label(sashForm, SWT.NONE);
- rightLabel.setText("SashForm\nRight\n...\n...\n...\n...\n...");
-
- // DateTime
- dateTime = new DateTime(defaultBackgroundGroup, SWT.NONE);
- dateTime.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
-
- // Text
- text = new Text(nativeGroup, SWT.BORDER);
- text.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
- text.setText("text");
-
- // ProgressBar
- progressBar = new ProgressBar(defaultBackgroundGroup, SWT.NONE);
- progressBar.setMaximum(100);
- progressBar.setSelection(80);
-
- // Combo
- combo = new Combo(defaultBackgroundGroup, SWT.BORDER);
- combo.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
- combo.add("combo");
- combo.setText("combo");
-
- // Slider
- slider = new Slider(nativeGroup, SWT.HORIZONTAL | SWT.BORDER);
- slider.setSelection(20);
- slider.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
-
- // CCombo
- ccombo = new CCombo(defaultBackgroundGroup, SWT.BORDER);
- ccombo.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
- ccombo.add("ccombo");
- ccombo.setText("ccombo");
-
- // CLable
- cLabel = new CLabel(customGroup, SWT.NONE);
- cLabel.setText("CLabel");
-
- // Text
- styledText = new StyledText(customGroup, SWT.BORDER);
- styledText.setFont(new Font(display, "Tahoma", 18, SWT.BOLD | SWT.ITALIC));
- styledText.setForeground(display.getSystemColor(SWT.COLOR_DARK_BLUE));
- styledText.setText("Styled Text");
- styledText.append("\n");
- styledText.append("Example_string");
- styledText.append("\n");
- styledText.append("One_Two");
- styledText.append("\n");
- styledText.append("Two_Three");
-
- // CTabFolder
- cTab = new CTabFolder(containerGroup, SWT.BORDER);
- for (int i = 0; i < 2; i++) {
- CTabItem cTabItem = new CTabItem(cTab, SWT.CLOSE, i);
- cTabItem.setText("CTabItem " + (i + 1));
- }
- cTab.setSelection(0);
-
- // Gradient CTabFolder
- gradientCTab = new CTabFolder(customGroup, SWT.BORDER);
- gradientCTab.setBackground(
- new Color[] { display.getSystemColor(SWT.COLOR_WHITE), display.getSystemColor(SWT.COLOR_RED) },
- new int[] { 90 }, true);
- for (int i = 0; i < 2; i++) {
- CTabItem cTabItem = new CTabItem(gradientCTab, SWT.CLOSE, i);
- cTabItem.setText("CTabItem " + (i + 1));
- }
- gradientCTab.setSelection(0);
-
- // Table
- table = new Table(itemGroup, SWT.V_SCROLL);
- table.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
- table.setLinesVisible(true);
- table.setHeaderVisible(true);
- TableItem tableItem = new TableItem(table, SWT.NONE);
- tableItem.setText("TableItem - One");
- tableItem = new TableItem(table, SWT.NONE);
- tableItem.setText("TableItem - Two");
-
- // Tree
- tree = new Tree(itemGroup, SWT.NONE);
- TreeItem treeItem = new TreeItem (tree, SWT.NONE);
- treeItem.setText("Parent");
- TreeItem childItem = new TreeItem (treeItem, SWT.NONE);
- childItem.setText("Child1");
- childItem = new TreeItem (treeItem, SWT.NONE);
- childItem.setText("Child2");
- treeItem.setExpanded(true);
- tree.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
-
- // ExpandBar
- expandBar = new ExpandBar (itemGroup, SWT.V_SCROLL);
- expandBar.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
- for (int i = 1; i <= 2; i++) {
- ExpandItem item1 = new ExpandItem(expandBar, SWT.NONE, 0);
- item1.setText("Expand_Bar_Entry " + i);
- item1.setExpanded(true);
- item1.setHeight(20);
- }
-
- shell.open();
- shell.pack();
- while (!shell.isDisposed()) {
- if (!display.readAndDispatch())
- display.sleep();
- }
- display.dispose();
- }
-
- private static Image getBackgroundImage(final Display display) {
- if (newImage == null) {
- Rectangle rect = new Rectangle(0, 0, 115, 5);
- newImage = new Image(display, Math.max(1, rect.width), 1);
- GC gc = new GC(newImage);
- gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
- gc.setBackground(display.getSystemColor(SWT.COLOR_RED));
- gc.fillGradientRectangle(rect.x, rect.y, rect.width, 1, false);
- gc.dispose();
- }
- return newImage;
- }
-
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.swt.snippets;
+import static org.eclipse.swt.events.SelectionListener.*;
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.custom.*;
+import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.layout.*;
+import org.eclipse.swt.widgets.*;
+
+/**
+ * Transparent Background example snippet: Set transparent background.
+ *
+ * For a list of all SWT example snippets see
+ * http://www.eclipse.org/swt/snippets/
+ */
+public class Snippet365 {
+ static Image oldImage;
+ static Image newImage;
+
+ // Containers
+ static Composite containerGroup;
+ static Canvas canvas;
+ static Composite composite;
+ static Group group;
+ static Sash sash;
+
+ // Native
+ static Composite nativeGroup;
+ static Button buttonCheckBox;
+ static ToolBar toolBar;
+ static CoolBar coolBar;
+ static Label label;
+ static Link link;
+ static Scale scale;
+ static Button radio;
+ static Button check;
+ static Button push;
+
+ // Custom
+ static Composite customGroup;
+ static CLabel cLabel;
+ static StyledText styledText;
+ static SashForm sashForm;
+ static CTabFolder cTab;
+ static CTabFolder gradientCTab;
+
+ // Item
+ static Composite itemGroup;
+ static TabFolder tabFolder;
+ static Table table;
+ static Tree tree;
+ static ExpandBar expandBar;
+
+ // As Designed
+ static Composite defaultBackgroundGroup;
+ static Text text;
+ static Combo combo;
+ static ProgressBar progressBar;
+ static DateTime dateTime;
+ static Slider slider;
+ static List list;
+ static CCombo ccombo;
+
+ public static void main(String[] args) {
+ final Display display = new Display();
+ final Shell shell = new Shell(display);
+ shell.setText("Snippet365 - Transparent Background");
+ RowLayout layout = new RowLayout(SWT.VERTICAL);
+ layout.spacing = 20;
+ layout.marginWidth = 10;
+ layout.marginHeight = 10;
+ shell.setLayout(layout);
+ // Standard color background for Shell
+ // shell.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
+
+ // Gradient background for Shell
+ shell.addListener(SWT.Resize, event -> {
+ Rectangle rect = shell.getClientArea();
+ Image newImage = new Image(display, Math.max(1, rect.width), 1);
+ GC gc = new GC(newImage);
+ gc.setForeground(display.getSystemColor(SWT.COLOR_BLUE));
+ gc.setBackground(display.getSystemColor(SWT.COLOR_GREEN));
+ gc.fillGradientRectangle(rect.x, rect.y, rect.width, 1, false);
+ gc.dispose();
+ shell.setBackgroundImage(newImage);
+ if (oldImage != null)
+ oldImage.dispose();
+ oldImage = newImage;
+ });
+
+ // Transparent
+ buttonCheckBox = new Button(shell, SWT.CHECK | SWT.None);
+ buttonCheckBox.setText("SET TRANSPARENT");
+ buttonCheckBox.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+ buttonCheckBox.setSelection(false);
+ buttonCheckBox.addSelectionListener(widgetSelectedAdapter( e-> {
+ boolean transparent = ((Button) e.getSource()).getSelection();
+ if (transparent) {
+ // ContainerGroup
+ containerGroup.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+ canvas.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+ composite.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+ tabFolder.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+ for (TabItem item : tabFolder.getItems()) {
+ item.getControl().setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+ }
+
+ // Native
+ nativeGroup.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+ toolBar.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+ coolBar.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+ label.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+ link.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+ scale.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+ radio.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+ check.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+ group.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+ sash.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+ slider.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+ list.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+
+ // Custom
+ customGroup.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+ cLabel.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+ cTab.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_TRANSPARENT));
+ gradientCTab.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_TRANSPARENT));
+ sashForm.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_TRANSPARENT));
+ for (Control control : sashForm.getChildren()) {
+ control.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_TRANSPARENT));
+ }
+ // Default
+ push.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+ defaultBackgroundGroup.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+ combo.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+ progressBar.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+ dateTime.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+ ccombo.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+ text.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+ styledText.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+ expandBar.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+ table.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+ tree.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+
+ // ItemGroup
+ itemGroup.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+ } else {
+ // Native
+ nativeGroup.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
+ toolBar.setBackground(null);
+ coolBar.setBackground(null);
+ label.setBackground(null);
+ link.setBackground(null);
+ scale.setBackground(null);
+ RGB rgb = display.getSystemColor(SWT.COLOR_CYAN).getRGB();
+ radio.setBackground(new Color(display, new RGBA(rgb.red, rgb.blue, rgb.green, 255)));
+ check.setBackgroundImage(getBackgroundImage(display));
+ group.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
+ sash.setBackground(display.getSystemColor(SWT.COLOR_DARK_CYAN));
+ slider.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
+ list.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
+ text.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
+
+ // ContainerGroup
+ containerGroup.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
+ canvas.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
+ composite.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
+ tabFolder.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
+ for (TabItem item : tabFolder.getItems()) {
+ item.getControl().setBackground(display.getSystemColor(SWT.COLOR_CYAN));
+ }
+ // Custom
+ customGroup.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
+ cLabel.setBackground((Color) null);
+ styledText.setBackground((Color) null);
+ sashForm.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
+ for (Control control : sashForm.getChildren()) {
+ control.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
+ }
+ cTab.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
+
+ gradientCTab.setBackground(
+ new Color[] { display.getSystemColor(SWT.COLOR_RED),
+ display.getSystemColor(SWT.COLOR_WHITE) }, new int[] { 90 }, true);
+
+ // Default
+ defaultBackgroundGroup.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
+ push.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
+ combo.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
+ ccombo.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
+ dateTime.setBackground(null);
+ progressBar.setBackground(null);
+ expandBar.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
+ table.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
+ tree.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
+
+ // ItemGroup
+ itemGroup.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
+ }
+
+ }));
+
+ // ContainerGroup
+ containerGroup = new Composite(shell, SWT.NONE);
+ containerGroup.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
+ containerGroup.setToolTipText("CONTAINER");
+ layout = new RowLayout();
+ layout.spacing = 20;
+ containerGroup.setLayout(layout);
+
+ // Native
+ nativeGroup = new Composite(shell, SWT.NONE);
+ nativeGroup.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
+ nativeGroup.setToolTipText("NATIVE");
+ layout = new RowLayout();
+ layout.spacing = 20;
+ nativeGroup.setLayout(layout);
+
+ // Custom
+ customGroup = new Composite(shell, SWT.NONE);
+ customGroup.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
+ customGroup.setToolTipText("CUSTOM");
+ layout = new RowLayout();
+ layout.spacing = 20;
+ customGroup.setLayout(layout);
+
+ // AsDesigned
+ defaultBackgroundGroup = new Composite(shell, SWT.NONE);
+ defaultBackgroundGroup.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
+ defaultBackgroundGroup.setToolTipText("Default Background");
+ layout = new RowLayout();
+ layout.spacing = 20;
+ defaultBackgroundGroup.setLayout(layout);
+
+ // ItemGroup
+ itemGroup = new Composite(shell, SWT.NONE);
+ itemGroup.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
+ itemGroup.setToolTipText("ITEM");
+ layout = new RowLayout();
+ layout.spacing = 20;
+ itemGroup.setLayout(layout);
+
+ // Label
+ label = new Label(nativeGroup, SWT.NONE);
+ label.setText("Label");
+
+ // Radio button
+ radio = new Button(nativeGroup, SWT.RADIO);
+ radio.setText("Radio Button");
+ radio.setSelection(true);
+ radio.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
+
+ // Checkbox button with image
+ check = new Button(nativeGroup, SWT.CHECK);
+ check.setText("CheckBox Image");
+ check.setSelection(true);
+ check.setBackgroundImage(getBackgroundImage(display));
+
+ // Push Button
+ push = new Button(defaultBackgroundGroup, SWT.PUSH);
+ push.setText("Push Button");
+
+ // Toolbar
+ toolBar = new ToolBar(nativeGroup, SWT.FLAT);
+ toolBar.pack();
+ ToolItem item = new ToolItem(toolBar, SWT.PUSH);
+ item.setText("ToolBar_Item");
+
+ // Coolbar
+ coolBar = new CoolBar(nativeGroup, SWT.BORDER);
+ for (int i=0; i<2; i++) {
+ CoolItem item2 = new CoolItem (coolBar, SWT.NONE);
+ Button button = new Button (coolBar, SWT.PUSH);
+ button.setText ("Button " + i);
+ Point size = button.computeSize (SWT.DEFAULT, SWT.DEFAULT);
+ item2.setPreferredSize (item2.computeSize (size.x, size.y));
+ item2.setControl (button);
+ }
+ // Scale
+ scale = new Scale(nativeGroup, SWT.None);
+ scale.setMaximum(100);
+ scale.setSelection(20);
+
+ // Link
+ link = new Link(nativeGroup, SWT.NONE);
+ link.setText("<a>Sample link</a>");
+
+ // List
+ list = new List(nativeGroup, SWT.BORDER);
+ list.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
+ list.add("List_one");
+ list.add("List_two");
+ list.add("List_three");
+ list.add("List_four");
+
+ // Canvas
+ canvas = new Canvas (containerGroup, SWT.NONE);
+ canvas.setToolTipText("Canvas");
+ canvas.addPaintListener(e -> {
+ GC gc = e.gc;
+ gc.setForeground(display.getSystemColor(SWT.COLOR_RED));
+ gc.drawRectangle(e.x+1, e.y+1, e.width-2, e.height-2);
+ gc.drawArc(2, 2, e.width-4, e.height-4, 0, 360);
+ });
+
+ // Composite
+ composite = new Composite(containerGroup, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
+ composite.setToolTipText("Composite");
+
+ // TabFolder
+ tabFolder = new TabFolder(containerGroup, SWT.BORDER);
+ tabFolder.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
+ for (int i=0; i < 2; i++) {
+ TabItem tabItem = new TabItem (tabFolder, SWT.NONE);
+ tabItem.setText ("TabItem " + i);
+ Label label = new Label (tabFolder, SWT.PUSH);
+ label.setText ("Page " + i);
+ tabItem.setControl (label);
+ tabItem.getControl().setBackground(display.getSystemColor(SWT.COLOR_CYAN));
+ }
+ tabFolder.pack ();
+
+ // Group
+ group = new Group(containerGroup, SWT.NONE);
+ group.setText("Group");
+
+ // Sash
+ sash = new Sash(containerGroup, SWT.HORIZONTAL | SWT.BORDER);
+ sash.setBackground(display.getSystemColor(SWT.COLOR_DARK_CYAN));
+ sash.setLayoutData(new RowData(100, 100));
+ sash.setToolTipText("Sash");
+
+ // SashForm
+ sashForm = new SashForm(containerGroup, SWT.HORIZONTAL | SWT.BORDER);
+ Label leftLabel = new Label(sashForm, SWT.NONE);
+ leftLabel.setText("SashForm\nLeft\n...\n...\n...\n...\n...");
+ Label rightLabel = new Label(sashForm, SWT.NONE);
+ rightLabel.setText("SashForm\nRight\n...\n...\n...\n...\n...");
+
+ // DateTime
+ dateTime = new DateTime(defaultBackgroundGroup, SWT.NONE);
+ dateTime.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
+
+ // Text
+ text = new Text(nativeGroup, SWT.BORDER);
+ text.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
+ text.setText("text");
+
+ // ProgressBar
+ progressBar = new ProgressBar(defaultBackgroundGroup, SWT.NONE);
+ progressBar.setMaximum(100);
+ progressBar.setSelection(80);
+
+ // Combo
+ combo = new Combo(defaultBackgroundGroup, SWT.BORDER);
+ combo.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
+ combo.add("combo");
+ combo.setText("combo");
+
+ // Slider
+ slider = new Slider(nativeGroup, SWT.HORIZONTAL | SWT.BORDER);
+ slider.setSelection(20);
+ slider.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
+
+ // CCombo
+ ccombo = new CCombo(defaultBackgroundGroup, SWT.BORDER);
+ ccombo.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
+ ccombo.add("ccombo");
+ ccombo.setText("ccombo");
+
+ // CLable
+ cLabel = new CLabel(customGroup, SWT.NONE);
+ cLabel.setText("CLabel");
+
+ // Text
+ styledText = new StyledText(customGroup, SWT.BORDER);
+ styledText.setFont(new Font(display, "Tahoma", 18, SWT.BOLD | SWT.ITALIC));
+ styledText.setForeground(display.getSystemColor(SWT.COLOR_DARK_BLUE));
+ styledText.setText("Styled Text");
+ styledText.append("\n");
+ styledText.append("Example_string");
+ styledText.append("\n");
+ styledText.append("One_Two");
+ styledText.append("\n");
+ styledText.append("Two_Three");
+
+ // CTabFolder
+ cTab = new CTabFolder(containerGroup, SWT.BORDER);
+ for (int i = 0; i < 2; i++) {
+ CTabItem cTabItem = new CTabItem(cTab, SWT.CLOSE, i);
+ cTabItem.setText("CTabItem " + (i + 1));
+ }
+ cTab.setSelection(0);
+
+ // Gradient CTabFolder
+ gradientCTab = new CTabFolder(customGroup, SWT.BORDER);
+ gradientCTab.setBackground(
+ new Color[] { display.getSystemColor(SWT.COLOR_WHITE), display.getSystemColor(SWT.COLOR_RED) },
+ new int[] { 90 }, true);
+ for (int i = 0; i < 2; i++) {
+ CTabItem cTabItem = new CTabItem(gradientCTab, SWT.CLOSE, i);
+ cTabItem.setText("CTabItem " + (i + 1));
+ }
+ gradientCTab.setSelection(0);
+
+ // Table
+ table = new Table(itemGroup, SWT.V_SCROLL);
+ table.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
+ table.setLinesVisible(true);
+ table.setHeaderVisible(true);
+ TableItem tableItem = new TableItem(table, SWT.NONE);
+ tableItem.setText("TableItem - One");
+ tableItem = new TableItem(table, SWT.NONE);
+ tableItem.setText("TableItem - Two");
+
+ // Tree
+ tree = new Tree(itemGroup, SWT.NONE);
+ TreeItem treeItem = new TreeItem (tree, SWT.NONE);
+ treeItem.setText("Parent");
+ TreeItem childItem = new TreeItem (treeItem, SWT.NONE);
+ childItem.setText("Child1");
+ childItem = new TreeItem (treeItem, SWT.NONE);
+ childItem.setText("Child2");
+ treeItem.setExpanded(true);
+ tree.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
+
+ // ExpandBar
+ expandBar = new ExpandBar (itemGroup, SWT.V_SCROLL);
+ expandBar.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
+ for (int i = 1; i <= 2; i++) {
+ ExpandItem item1 = new ExpandItem(expandBar, SWT.NONE, 0);
+ item1.setText("Expand_Bar_Entry " + i);
+ item1.setExpanded(true);
+ item1.setHeight(20);
+ }
+
+ shell.open();
+ shell.pack();
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch())
+ display.sleep();
+ }
+ display.dispose();
+ }
+
+ private static Image getBackgroundImage(final Display display) {
+ if (newImage == null) {
+ Rectangle rect = new Rectangle(0, 0, 115, 5);
+ newImage = new Image(display, Math.max(1, rect.width), 1);
+ GC gc = new GC(newImage);
+ gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
+ gc.setBackground(display.getSystemColor(SWT.COLOR_RED));
+ gc.fillGradientRectangle(rect.x, rect.y, rect.width, 1, false);
+ gc.dispose();
+ }
+ return newImage;
+ }
+
+}
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet366.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet366.java
index 6eadd58556..6215bc0a17 100644
--- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet366.java
+++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet366.java
@@ -1,111 +1,111 @@
-/*******************************************************************************
- * Copyright (c) 2015, 2016 Red Hat Inc.
+/*******************************************************************************
+ * Copyright (c) 2015, 2016 Red Hat Inc.
*
- * This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License 2.0
- * which accompanies this distribution, and is available at
+ * This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
- * SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
- * Red Hat Inc - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.snippets;
-
-import java.util.concurrent.atomic.*;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.layout.*;
-import org.eclipse.swt.widgets.*;
-
-/**
- * Buttons with various arrows and methods that affect arrow directions.
- *
- * For a list of all SWT example snippets see
- * http://www.eclipse.org/swt/snippets/
- */
-public class Snippet366 {
- static Display display = new Display();
- static Shell shell = new Shell(display);
-
- public static void main (String [] args) {
- shell.setLayout (new RowLayout ());
-
- makeArrowGroup ();
- makeAlignGroup ();
- makeOrientationGroup ();
-
- shell.pack ();
- shell.open ();
- while (!shell.isDisposed ()) {
- if (!display.readAndDispatch ())
- display.sleep ();
- }
- display.dispose ();
- }
-
- private static void makeOrientationGroup () {
- Group orientationGroup = new Group (shell, SWT.None);
- orientationGroup.setLayout (new RowLayout ());
- orientationGroup.setText ("Orientation group");
-
- final AtomicInteger prevDir = new AtomicInteger (0);
- final Button alignmentButton = new Button (orientationGroup, SWT.ARROW | SWT.RIGHT);
- alignmentButton.addListener (SWT.MouseDown, event -> {
- switch (prevDir.get ()) {
- case 0:
- alignmentButton.setOrientation (SWT.LEFT_TO_RIGHT);
- prevDir.set (1);
- break;
- case 1:
- alignmentButton.setOrientation (SWT.RIGHT_TO_LEFT);
- prevDir.set (0);
- break;
- default:
- break;
- }
- });
- }
-
- private static void makeAlignGroup () {
- Group alignGroup = new Group (shell, SWT.None);
- alignGroup.setLayout (new RowLayout ());
- alignGroup.setText ("Alignment group");
-
- final AtomicInteger prevDir = new AtomicInteger (0);
- final Button alignmentButton = new Button (alignGroup, SWT.ARROW | SWT.UP);
- alignmentButton.addListener (SWT.MouseDown, event -> {
- switch (prevDir.get ()) {
- case 0:
- alignmentButton.setAlignment (SWT.RIGHT);
- prevDir.set (1);
- break;
- case 1:
- alignmentButton.setAlignment (SWT.DOWN);
- prevDir.set (2);
- break;
- case 2:
- alignmentButton.setAlignment (SWT.LEFT);
- prevDir.set (3);
- break;
- case 3:
- alignmentButton.setAlignment (SWT.UP);
- prevDir.set (0);
- default:
- break;
- }
- });
- }
-
- private static void makeArrowGroup () {
- Group arrowGroup = new Group(shell, SWT.None);
- arrowGroup.setText ("Arrow group");
- arrowGroup.setLayout (new RowLayout ());
-
- new Button (arrowGroup, SWT.ARROW | SWT.LEFT);
- new Button (arrowGroup, SWT.ARROW | SWT.RIGHT);
- new Button (arrowGroup, SWT.ARROW | SWT.UP);
- new Button (arrowGroup, SWT.ARROW | SWT.DOWN);
- }
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Red Hat Inc - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.swt.snippets;
+
+import java.util.concurrent.atomic.*;
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.layout.*;
+import org.eclipse.swt.widgets.*;
+
+/**
+ * Buttons with various arrows and methods that affect arrow directions.
+ *
+ * For a list of all SWT example snippets see
+ * http://www.eclipse.org/swt/snippets/
+ */
+public class Snippet366 {
+ static Display display = new Display();
+ static Shell shell = new Shell(display);
+
+ public static void main (String [] args) {
+ shell.setLayout (new RowLayout ());
+
+ makeArrowGroup ();
+ makeAlignGroup ();
+ makeOrientationGroup ();
+
+ shell.pack ();
+ shell.open ();
+ while (!shell.isDisposed ()) {
+ if (!display.readAndDispatch ())
+ display.sleep ();
+ }
+ display.dispose ();
+ }
+
+ private static void makeOrientationGroup () {
+ Group orientationGroup = new Group (shell, SWT.None);
+ orientationGroup.setLayout (new RowLayout ());
+ orientationGroup.setText ("Orientation group");
+
+ final AtomicInteger prevDir = new AtomicInteger (0);
+ final Button alignmentButton = new Button (orientationGroup, SWT.ARROW | SWT.RIGHT);
+ alignmentButton.addListener (SWT.MouseDown, event -> {
+ switch (prevDir.get ()) {
+ case 0:
+ alignmentButton.setOrientation (SWT.LEFT_TO_RIGHT);
+ prevDir.set (1);
+ break;
+ case 1:
+ alignmentButton.setOrientation (SWT.RIGHT_TO_LEFT);
+ prevDir.set (0);
+ break;
+ default:
+ break;
+ }
+ });
+ }
+
+ private static void makeAlignGroup () {
+ Group alignGroup = new Group (shell, SWT.None);
+ alignGroup.setLayout (new RowLayout ());
+ alignGroup.setText ("Alignment group");
+
+ final AtomicInteger prevDir = new AtomicInteger (0);
+ final Button alignmentButton = new Button (alignGroup, SWT.ARROW | SWT.UP);
+ alignmentButton.addListener (SWT.MouseDown, event -> {
+ switch (prevDir.get ()) {
+ case 0:
+ alignmentButton.setAlignment (SWT.RIGHT);
+ prevDir.set (1);
+ break;
+ case 1:
+ alignmentButton.setAlignment (SWT.DOWN);
+ prevDir.set (2);
+ break;
+ case 2:
+ alignmentButton.setAlignment (SWT.LEFT);
+ prevDir.set (3);
+ break;
+ case 3:
+ alignmentButton.setAlignment (SWT.UP);
+ prevDir.set (0);
+ default:
+ break;
+ }
+ });
+ }
+
+ private static void makeArrowGroup () {
+ Group arrowGroup = new Group(shell, SWT.None);
+ arrowGroup.setText ("Arrow group");
+ arrowGroup.setLayout (new RowLayout ());
+
+ new Button (arrowGroup, SWT.ARROW | SWT.LEFT);
+ new Button (arrowGroup, SWT.ARROW | SWT.RIGHT);
+ new Button (arrowGroup, SWT.ARROW | SWT.UP);
+ new Button (arrowGroup, SWT.ARROW | SWT.DOWN);
+ }
+}
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet368.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet368.java
index e3906e06b6..b30c3737a7 100644
--- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet368.java
+++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet368.java
@@ -1,57 +1,57 @@
-/**
- * Copyright (c) 2017 Angelo ZERR.
+/**
+ * Copyright (c) 2017 Angelo ZERR.
*
- * This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License 2.0
- * which accompanies this distribution, and is available at
+ * This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
- * SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
- * Angelo Zerr <angelo.zerr@gmail.com> - Customize different line spacing of StyledText - Bug 522020
- */
-package org.eclipse.swt.snippets;
-
-/*
- * example snippet: customize line spacing provider
- *
- * For a list of all SWT example snippets see
- * http://www.eclipse.org/swt/snippets/
- *
- * @since 3.107
- */
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.StyledText;
-import org.eclipse.swt.layout.FillLayout;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Shell;
-
-public class Snippet368 {
-
- public static void main(String[] args) throws Exception {
- Display display = new Display();
- Shell shell = new Shell(display);
- shell.setLayout(new FillLayout());
- shell.setText("Customize line spacing provider");
-
- StyledText text = new StyledText(shell, SWT.BORDER | SWT.V_SCROLL);
- text.setText("a\nb\nc\nd");
- text.setLineSpacingProvider(lineIndex -> {
- if (lineIndex == 0) {
- return 10;
- } else if (lineIndex == 1) {
- return 30;
- }
- return null;
- });
-
- shell.pack();
- shell.open();
- while (!shell.isDisposed()) {
- if (!display.readAndDispatch())
- display.sleep();
- }
- display.dispose();
- }
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Angelo Zerr <angelo.zerr@gmail.com> - Customize different line spacing of StyledText - Bug 522020
+ */
+package org.eclipse.swt.snippets;
+
+/*
+ * example snippet: customize line spacing provider
+ *
+ * For a list of all SWT example snippets see
+ * http://www.eclipse.org/swt/snippets/
+ *
+ * @since 3.107
+ */
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+
+public class Snippet368 {
+
+ public static void main(String[] args) throws Exception {
+ Display display = new Display();
+ Shell shell = new Shell(display);
+ shell.setLayout(new FillLayout());
+ shell.setText("Customize line spacing provider");
+
+ StyledText text = new StyledText(shell, SWT.BORDER | SWT.V_SCROLL);
+ text.setText("a\nb\nc\nd");
+ text.setLineSpacingProvider(lineIndex -> {
+ if (lineIndex == 0) {
+ return 10;
+ } else if (lineIndex == 1) {
+ return 30;
+ }
+ return null;
+ });
+
+ shell.pack();
+ shell.open();
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch())
+ display.sleep();
+ }
+ display.dispose();
+ }
+}
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet369.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet369.java
index 3a134c753d..159e3a94e4 100644
--- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet369.java
+++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet369.java
@@ -1,58 +1,58 @@
-/**
- * Copyright (c) 2017 Angelo ZERR.
+/**
+ * Copyright (c) 2017 Angelo ZERR.
*
- * This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License 2.0
- * which accompanies this distribution, and is available at
+ * This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
- * SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
- * Angelo Zerr <angelo.zerr@gmail.com> - Customize different line spacing of StyledText - Bug 522020
- */
-package org.eclipse.swt.snippets;
-
-/*
- * example snippet: line spacing provider in action
- *
- * For a list of all SWT example snippets see
- * http://www.eclipse.org/swt/snippets/
- *
- * @since 3.107
- */
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.StyledText;
-import org.eclipse.swt.layout.FillLayout;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Shell;
-
-public class Snippet369 {
-
- public static void main(String[] args) throws Exception {
- Display display = new Display();
- Shell shell = new Shell(display);
- shell.setLayout(new FillLayout());
- shell.setText("Line spacing provider in action");
-
- StyledText text = new StyledText(shell, SWT.BORDER | SWT.V_SCROLL);
- text.setText("// Type your custom line spacing \n10\n5\nabcd\n20\nefgh");
-
- text.setLineSpacingProvider(lineIndex -> {
- String line = text.getLine(lineIndex).trim();
- try {
- return Integer.parseInt(line);
- } catch(NumberFormatException e) {
- return null;
- }
- });
-
- shell.pack();
- shell.open();
- while (!shell.isDisposed()) {
- if (!display.readAndDispatch())
- display.sleep();
- }
- display.dispose();
- }
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Angelo Zerr <angelo.zerr@gmail.com> - Customize different line spacing of StyledText - Bug 522020
+ */
+package org.eclipse.swt.snippets;
+
+/*
+ * example snippet: line spacing provider in action
+ *
+ * For a list of all SWT example snippets see
+ * http://www.eclipse.org/swt/snippets/
+ *
+ * @since 3.107
+ */
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+
+public class Snippet369 {
+
+ public static void main(String[] args) throws Exception {
+ Display display = new Display();
+ Shell shell = new Shell(display);
+ shell.setLayout(new FillLayout());
+ shell.setText("Line spacing provider in action");
+
+ StyledText text = new StyledText(shell, SWT.BORDER | SWT.V_SCROLL);
+ text.setText("// Type your custom line spacing \n10\n5\nabcd\n20\nefgh");
+
+ text.setLineSpacingProvider(lineIndex -> {
+ String line = text.getLine(lineIndex).trim();
+ try {
+ return Integer.parseInt(line);
+ } catch(NumberFormatException e) {
+ return null;
+ }
+ });
+
+ shell.pack();
+ shell.open();
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch())
+ display.sleep();
+ }
+ display.dispose();
+ }
+}
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet374.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet374.java
index 1a3081ff3c..ed31cbbf8c 100644
--- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet374.java
+++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet374.java
@@ -1,50 +1,50 @@
-/**
- * Copyright (c) 2018 Angelo ZERR.
+/**
+ * Copyright (c) 2018 Angelo ZERR.
*
- * This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License 2.0
- * which accompanies this distribution, and is available at
+ * This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
- * SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
- * Angelo Zerr <angelo.zerr@gmail.com> - [StyledText] Allow to define a top margin for a given line or range - Bug 539618
- */
-package org.eclipse.swt.snippets;
-
-/*
- * example snippet: customize line vertical indent
- *
- * For a list of all SWT example snippets see
- * http://www.eclipse.org/swt/snippets/
- *
- * @since 3.108
- */
-import org.eclipse.swt.*;
-import org.eclipse.swt.custom.*;
-import org.eclipse.swt.layout.*;
-import org.eclipse.swt.widgets.*;
-
-public class Snippet374 {
-
- public static void main(String[] args) throws Exception {
- Display display = new Display();
- Shell shell = new Shell(display);
- shell.setLayout(new FillLayout());
- shell.setText("Customize line vertical indent");
-
- StyledText text = new StyledText(shell, SWT.BORDER | SWT.V_SCROLL);
- text.setWordWrap(true);
- text.setText("word1 word2 word3 word4");
- text.setLineVerticalIndent(0, 20);
-
- shell.pack();
- shell.open();
- while (!shell.isDisposed()) {
- if (!display.readAndDispatch())
- display.sleep();
- }
- display.dispose();
- }
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Angelo Zerr <angelo.zerr@gmail.com> - [StyledText] Allow to define a top margin for a given line or range - Bug 539618
+ */
+package org.eclipse.swt.snippets;
+
+/*
+ * example snippet: customize line vertical indent
+ *
+ * For a list of all SWT example snippets see
+ * http://www.eclipse.org/swt/snippets/
+ *
+ * @since 3.108
+ */
+import org.eclipse.swt.*;
+import org.eclipse.swt.custom.*;
+import org.eclipse.swt.layout.*;
+import org.eclipse.swt.widgets.*;
+
+public class Snippet374 {
+
+ public static void main(String[] args) throws Exception {
+ Display display = new Display();
+ Shell shell = new Shell(display);
+ shell.setLayout(new FillLayout());
+ shell.setText("Customize line vertical indent");
+
+ StyledText text = new StyledText(shell, SWT.BORDER | SWT.V_SCROLL);
+ text.setWordWrap(true);
+ text.setText("word1 word2 word3 word4");
+ text.setLineVerticalIndent(0, 20);
+
+ shell.pack();
+ shell.open();
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch())
+ display.sleep();
+ }
+ display.dispose();
+ }
+}
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet375.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet375.java
index 8124677526..c21ba17c7e 100644
--- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet375.java
+++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet375.java
@@ -1,126 +1,126 @@
-/**
- * Copyright (c) 2019 Laurent CARON.
- *
- * This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License 2.0
- * which accompanies this distribution, and is available at
- * https://www.eclipse.org/legal/epl-2.0/
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
- * Laurent CARON (laurent.caron at gmail dot com) - initial API and implementation (bug 542777)
- */
-package org.eclipse.swt.snippets;
-
-import java.util.*;
-
-/*
- * Example snippet: mouse navigation for Styled Text Widget
- *
- * For a list of all SWT example snippets see
- * http://www.eclipse.org/swt/snippets/
- * @since 3.110
- */
-import org.eclipse.swt.*;
-import org.eclipse.swt.custom.*;
-import org.eclipse.swt.layout.*;
-import org.eclipse.swt.widgets.*;
-
-public class Snippet375 {
-
- public static void main(String[] args) throws Exception {
- final Display display = new Display();
- final Shell shell = new Shell(display);
- shell.setLayout(new GridLayout(1, false));
-
- final StringBuilder sb = new StringBuilder();
- final Random random = new Random(2546);
- for (int i = 0; i < 200; i++) {
- sb.append("Very very long text about ").append(random.nextInt(2000)).append("\t");
- if (i % 10 == 0) {
- sb.append("\n");
- }
- }
-
- // H SCROLL
- final Label lbl1 = new Label(shell, SWT.NONE);
- lbl1.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, true, false));
- lbl1.setText("Horizontal Scroll");
-
- final StyledText txt1 = new StyledText(shell, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL);
- txt1.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
- txt1.setText(sb.toString());
- txt1.setMouseNavigatorEnabled(true);
-
- // V_SCROLL
- final Label lbl2 = new Label(shell, SWT.NONE);
- lbl2.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, true, false));
- lbl2.setText("Vertical Scroll");
-
- final StyledText txt2 = new StyledText(shell, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL);
- txt2.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
- txt2.setText(sb.toString());
- txt2.setMouseNavigatorEnabled(true);
-
- // H SCROLL & V_SCROLL
- final Label lbl3 = new Label(shell, SWT.NONE);
- lbl3.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, true, false));
- lbl3.setText("Horizontal and Vertical Scroll");
-
- final StyledText txt3 = new StyledText(shell, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
- txt3.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
-
- txt3.setText(sb.toString());
- txt3.setMouseNavigatorEnabled(true);
-
- final Button enableDisableButton = new Button(shell, SWT.PUSH);
- enableDisableButton.setLayoutData(new GridData(GridData.END, GridData.FILL, true, false));
- enableDisableButton.setText("Disable Mouse Navigation");
- enableDisableButton.addListener(SWT.Selection, e -> {
- if (txt3.getMouseNavigatorEnabled()) {
- enableDisableButton.setText("Enable Mouse Navigation");
- } else {
- enableDisableButton.setText("Disable Mouse Navigation");
- }
- txt3.setMouseNavigatorEnabled(!txt3.getMouseNavigatorEnabled());
- });
-
- // Disabled Scroll at start
- final Label lbl4 = new Label(shell, SWT.NONE);
- lbl4.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, true, false));
- lbl4.setText("No scroll at start");
-
- final StyledText txt4 = new StyledText(shell, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
- final GridData gd = new GridData(GridData.FILL, GridData.FILL, true, true);
- gd.minimumHeight = 100;
- txt4.setLayoutData(gd);
-
- txt4.setText("Disabled scroll");
- txt4.setMouseNavigatorEnabled(true);
-
- // Disabled Scroll
- final Label lbl5 = new Label(shell, SWT.NONE);
- lbl5.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, true, false));
- lbl5.setText("No scroll");
-
- final StyledText txt5 = new StyledText(shell, SWT.MULTI | SWT.BORDER);
- final GridData gd5 = new GridData(GridData.FILL, GridData.FILL, true, true);
- gd5.minimumHeight = 100;
- txt5.setLayoutData(gd5);
-
- txt5.setText("No scroll");
- txt5.setMouseNavigatorEnabled(true);
-
- shell.setSize(800, 600);
- shell.open();
-
- while (!shell.isDisposed()) {
- if (!display.readAndDispatch()) {
- display.sleep();
- }
- }
-
- display.dispose();
- }
-}
+/**
+ * Copyright (c) 2019 Laurent CARON.
+ *
+ * This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Laurent CARON (laurent.caron at gmail dot com) - initial API and implementation (bug 542777)
+ */
+package org.eclipse.swt.snippets;
+
+import java.util.*;
+
+/*
+ * Example snippet: mouse navigation for Styled Text Widget
+ *
+ * For a list of all SWT example snippets see
+ * http://www.eclipse.org/swt/snippets/
+ * @since 3.110
+ */
+import org.eclipse.swt.*;
+import org.eclipse.swt.custom.*;
+import org.eclipse.swt.layout.*;
+import org.eclipse.swt.widgets.*;
+
+public class Snippet375 {
+
+ public static void main(String[] args) throws Exception {
+ final Display display = new Display();
+ final Shell shell = new Shell(display);
+ shell.setLayout(new GridLayout(1, false));
+
+ final StringBuilder sb = new StringBuilder();
+ final Random random = new Random(2546);
+ for (int i = 0; i < 200; i++) {
+ sb.append("Very very long text about ").append(random.nextInt(2000)).append("\t");
+ if (i % 10 == 0) {
+ sb.append("\n");
+ }
+ }
+
+ // H SCROLL
+ final Label lbl1 = new Label(shell, SWT.NONE);
+ lbl1.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, true, false));
+ lbl1.setText("Horizontal Scroll");
+
+ final StyledText txt1 = new StyledText(shell, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL);
+ txt1.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
+ txt1.setText(sb.toString());
+ txt1.setMouseNavigatorEnabled(true);
+
+ // V_SCROLL
+ final Label lbl2 = new Label(shell, SWT.NONE);
+ lbl2.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, true, false));
+ lbl2.setText("Vertical Scroll");
+
+ final StyledText txt2 = new StyledText(shell, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL);
+ txt2.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
+ txt2.setText(sb.toString());
+ txt2.setMouseNavigatorEnabled(true);
+
+ // H SCROLL & V_SCROLL
+ final Label lbl3 = new Label(shell, SWT.NONE);
+ lbl3.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, true, false));
+ lbl3.setText("Horizontal and Vertical Scroll");
+
+ final StyledText txt3 = new StyledText(shell, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
+ txt3.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
+
+ txt3.setText(sb.toString());
+ txt3.setMouseNavigatorEnabled(true);
+
+ final Button enableDisableButton = new Button(shell, SWT.PUSH);
+ enableDisableButton.setLayoutData(new GridData(GridData.END, GridData.FILL, true, false));
+ enableDisableButton.setText("Disable Mouse Navigation");
+ enableDisableButton.addListener(SWT.Selection, e -> {
+ if (txt3.getMouseNavigatorEnabled()) {
+ enableDisableButton.setText("Enable Mouse Navigation");
+ } else {
+ enableDisableButton.setText("Disable Mouse Navigation");
+ }
+ txt3.setMouseNavigatorEnabled(!txt3.getMouseNavigatorEnabled());
+ });
+
+ // Disabled Scroll at start
+ final Label lbl4 = new Label(shell, SWT.NONE);
+ lbl4.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, true, false));
+ lbl4.setText("No scroll at start");
+
+ final StyledText txt4 = new StyledText(shell, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
+ final GridData gd = new GridData(GridData.FILL, GridData.FILL, true, true);
+ gd.minimumHeight = 100;
+ txt4.setLayoutData(gd);
+
+ txt4.setText("Disabled scroll");
+ txt4.setMouseNavigatorEnabled(true);
+
+ // Disabled Scroll
+ final Label lbl5 = new Label(shell, SWT.NONE);
+ lbl5.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, true, false));
+ lbl5.setText("No scroll");
+
+ final StyledText txt5 = new StyledText(shell, SWT.MULTI | SWT.BORDER);
+ final GridData gd5 = new GridData(GridData.FILL, GridData.FILL, true, true);
+ gd5.minimumHeight = 100;
+ txt5.setLayoutData(gd5);
+
+ txt5.setText("No scroll");
+ txt5.setMouseNavigatorEnabled(true);
+
+ shell.setSize(800, 600);
+ shell.open();
+
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch()) {
+ display.sleep();
+ }
+ }
+
+ display.dispose();
+ }
+}
diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug531634_LogoffListener.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug531634_LogoffListener.java
index 4e75c0a3be..f12fb68657 100644
--- a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug531634_LogoffListener.java
+++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug531634_LogoffListener.java
@@ -1,66 +1,66 @@
-/*******************************************************************************
- * Copyright (c) 2019 Syntevo and others. All rights reserved.
- * The contents of this file are made available under the terms
- * of the GNU Lesser General Public License (LGPL) Version 2.1 that
- * accompanies this distribution (lgpl-v21.txt). The LGPL is also
- * available at http://www.gnu.org/licenses/lgpl.html. If the version
- * of the LGPL at http://www.gnu.org is different to the version of
- * the LGPL accompanying this distribution and there is any conflict
- * between the two license versions, the terms of the LGPL accompanying
- * this distribution shall govern.
- *
- * Contributors:
- * Syntevo - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.tests.gtk.snippets;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.layout.FillLayout;
-import org.eclipse.swt.widgets.*;
-
-public class Bug531634_LogoffListener {
- private static boolean isUserClosed = false;
-
- public static void main (String [] args) {
- Display display = new Display ();
-
- Shell shell = new Shell (display);
- shell.setLayout(new FillLayout());
- shell.setSize(300, 200);
-
- display.addListener(SWT.Close, event -> {
- MessageBox dialog = new MessageBox(shell, SWT.ICON_QUESTION | SWT.YES | SWT.NO);
- dialog.setMessage("QueryEndSession received.\nGive 'ready' hint? Time limit to answer is 1 sec");
- int answer = dialog.open();
- event.doit = (SWT.YES == answer);
- });
-
- display.addListener(SWT.Dispose, event -> {
- if (!isUserClosed && !shell.isDisposed()) {
- MessageBox dialog = new MessageBox(shell, SWT.ICON_INFORMATION);
- dialog.setMessage("EndSession received.\nI will exit when you close this box. Time limit is 10 sec.");
- dialog.open();
- }
- });
-
- final Label label = new Label(shell, SWT.WRAP | SWT.CENTER);
- label.setText("\n\n\nWhen you logoff/shutdown, I will give you messages on 'QueryEndSession' and 'EndSession'");
-
- // The first version of the patch had deadlock when System.exit() was called in response to UI action.
- // This happened because 'SWT.Close' is called from inside 'OS.g_main_context_iteration' and
- // Platform.lock is held by main thread, locking all OS.xxx calls from other threads.
- shell.addListener(SWT.Close, event -> {
- isUserClosed = true;
- display.dispose();
- System.exit(0);
- });
-
- shell.open ();
-
- while (!shell.isDisposed()) {
- if (!display.readAndDispatch ()) display.sleep ();
- }
-
- display.dispose ();
- }
-}
+/*******************************************************************************
+ * Copyright (c) 2019 Syntevo and others. All rights reserved.
+ * The contents of this file are made available under the terms
+ * of the GNU Lesser General Public License (LGPL) Version 2.1 that
+ * accompanies this distribution (lgpl-v21.txt). The LGPL is also
+ * available at http://www.gnu.org/licenses/lgpl.html. If the version
+ * of the LGPL at http://www.gnu.org is different to the version of
+ * the LGPL accompanying this distribution and there is any conflict
+ * between the two license versions, the terms of the LGPL accompanying
+ * this distribution shall govern.
+ *
+ * Contributors:
+ * Syntevo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.swt.tests.gtk.snippets;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.*;
+
+public class Bug531634_LogoffListener {
+ private static boolean isUserClosed = false;
+
+ public static void main (String [] args) {
+ Display display = new Display ();
+
+ Shell shell = new Shell (display);
+ shell.setLayout(new FillLayout());
+ shell.setSize(300, 200);
+
+ display.addListener(SWT.Close, event -> {
+ MessageBox dialog = new MessageBox(shell, SWT.ICON_QUESTION | SWT.YES | SWT.NO);
+ dialog.setMessage("QueryEndSession received.\nGive 'ready' hint? Time limit to answer is 1 sec");
+ int answer = dialog.open();
+ event.doit = (SWT.YES == answer);
+ });
+
+ display.addListener(SWT.Dispose, event -> {
+ if (!isUserClosed && !shell.isDisposed()) {
+ MessageBox dialog = new MessageBox(shell, SWT.ICON_INFORMATION);
+ dialog.setMessage("EndSession received.\nI will exit when you close this box. Time limit is 10 sec.");
+ dialog.open();
+ }
+ });
+
+ final Label label = new Label(shell, SWT.WRAP | SWT.CENTER);
+ label.setText("\n\n\nWhen you logoff/shutdown, I will give you messages on 'QueryEndSession' and 'EndSession'");
+
+ // The first version of the patch had deadlock when System.exit() was called in response to UI action.
+ // This happened because 'SWT.Close' is called from inside 'OS.g_main_context_iteration' and
+ // Platform.lock is held by main thread, locking all OS.xxx calls from other threads.
+ shell.addListener(SWT.Close, event -> {
+ isUserClosed = true;
+ display.dispose();
+ System.exit(0);
+ });
+
+ shell.open ();
+
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch ()) display.sleep ();
+ }
+
+ display.dispose ();
+ }
+}
diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_StyledTextLineSpacingProvider.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_StyledTextLineSpacingProvider.java
index f9fb56e2ac..774ccc9133 100644
--- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_StyledTextLineSpacingProvider.java
+++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_StyledTextLineSpacingProvider.java
@@ -1,89 +1,89 @@
-/**
- * Copyright (c) 2017 Angelo ZERR.
+/**
+ * Copyright (c) 2017 Angelo ZERR.
*
- * This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License 2.0
- * which accompanies this distribution, and is available at
+ * This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
- * SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
- * Angelo Zerr <angelo.zerr@gmail.com> - Customize different line spacing of StyledText - Bug 522020
- */
-package org.eclipse.swt.tests.junit;
-
-import static org.junit.Assert.assertArrayEquals;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.StyledText;
-import org.eclipse.swt.custom.StyledTextLineSpacingProvider;
-import org.eclipse.swt.widgets.Shell;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * Automated Test Suite for class
- * org.eclipse.swt.custom.StyledTextLineSpacingProvider
- *
- * @see org.eclipse.swt.custom.StyledTextLineSpacingProvider
- */
-public class Test_org_eclipse_swt_custom_StyledTextLineSpacingProvider {
-
- class IntegerLineSpacingProvider implements StyledTextLineSpacingProvider {
-
- @Override
- public Integer getLineSpacing(int lineIndex) {
- try {
- String text = styledText.getLine(lineIndex);
- return Integer.parseInt(text);
- } catch (Exception e) {
- return null;
- }
- }
- }
-
- Shell shell;
- StyledText styledText;
-
- @Before
- public void setUp() {
- shell = new Shell();
- styledText = new StyledText(shell, SWT.NULL);
- }
-
- @Test
- public void test_setLineSpacingProvider() {
- styledText.setText("a\n45\nc\n57");
- // Tests with none line spacing provider
- assertLineSpacingEquals(0, 0, 0, 0, 0);
- // Tests with integer line spacing provider
- styledText.setLineSpacingProvider(new IntegerLineSpacingProvider());
- assertLineSpacingEquals(0, 0, 45, 0, 57);
- // Tests with reset line spacing provider
- styledText.setLineSpacingProvider(null);
- assertLineSpacingEquals(0, 0, 0, 0, 0);
- }
-
- @Test
- public void test_replaceTextRange() {
- styledText.setText("a\n45\nc\n57");
- styledText.setLineSpacingProvider(new IntegerLineSpacingProvider());
- assertLineSpacingEquals(0, 0, 45, 0, 57);
- // Replace 45 with b
- styledText.replaceTextRange(2, 2, "b");
- assertLineSpacingEquals(0, 0, 0, 0, 57);
- // Replace b with 45
- styledText.replaceTextRange(2, 1, "45");
- assertLineSpacingEquals(0, 0, 45, 0, 57);
- }
-
- private void assertLineSpacingEquals(int... expecteds) {
- int lineHeight = styledText.getLineHeight();
- int[] actuals = new int[expecteds.length];
- for (int i = 0; i < expecteds.length; i++) {
- actuals[i] = styledText.getLinePixel(i) - ((i > 0) ? styledText.getLinePixel(i - 1) + lineHeight : 0);
- }
- assertArrayEquals(expecteds, actuals);
- }
-}
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Angelo Zerr <angelo.zerr@gmail.com> - Customize different line spacing of StyledText - Bug 522020
+ */
+package org.eclipse.swt.tests.junit;
+
+import static org.junit.Assert.assertArrayEquals;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.custom.StyledTextLineSpacingProvider;
+import org.eclipse.swt.widgets.Shell;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Automated Test Suite for class
+ * org.eclipse.swt.custom.StyledTextLineSpacingProvider
+ *
+ * @see org.eclipse.swt.custom.StyledTextLineSpacingProvider
+ */
+public class Test_org_eclipse_swt_custom_StyledTextLineSpacingProvider {
+
+ class IntegerLineSpacingProvider implements StyledTextLineSpacingProvider {
+
+ @Override
+ public Integer getLineSpacing(int lineIndex) {
+ try {
+ String text = styledText.getLine(lineIndex);
+ return Integer.parseInt(text);
+ } catch (Exception e) {
+ return null;
+ }
+ }
+ }
+
+ Shell shell;
+ StyledText styledText;
+
+ @Before
+ public void setUp() {
+ shell = new Shell();
+ styledText = new StyledText(shell, SWT.NULL);
+ }
+
+ @Test
+ public void test_setLineSpacingProvider() {
+ styledText.setText("a\n45\nc\n57");
+ // Tests with none line spacing provider
+ assertLineSpacingEquals(0, 0, 0, 0, 0);
+ // Tests with integer line spacing provider
+ styledText.setLineSpacingProvider(new IntegerLineSpacingProvider());
+ assertLineSpacingEquals(0, 0, 45, 0, 57);
+ // Tests with reset line spacing provider
+ styledText.setLineSpacingProvider(null);
+ assertLineSpacingEquals(0, 0, 0, 0, 0);
+ }
+
+ @Test
+ public void test_replaceTextRange() {
+ styledText.setText("a\n45\nc\n57");
+ styledText.setLineSpacingProvider(new IntegerLineSpacingProvider());
+ assertLineSpacingEquals(0, 0, 45, 0, 57);
+ // Replace 45 with b
+ styledText.replaceTextRange(2, 2, "b");
+ assertLineSpacingEquals(0, 0, 0, 0, 57);
+ // Replace b with 45
+ styledText.replaceTextRange(2, 1, "45");
+ assertLineSpacingEquals(0, 0, 45, 0, 57);
+ }
+
+ private void assertLineSpacingEquals(int... expecteds) {
+ int lineHeight = styledText.getLineHeight();
+ int[] actuals = new int[expecteds.length];
+ for (int i = 0; i < expecteds.length; i++) {
+ actuals[i] = styledText.getLinePixel(i) - ((i > 0) ? styledText.getLinePixel(i - 1) + lineHeight : 0);
+ }
+ assertArrayEquals(expecteds, actuals);
+ }
+}
diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_StyledText_VariableLineHeight.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_StyledText_VariableLineHeight.java
index e187c29148..e70e77e420 100644
--- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_StyledText_VariableLineHeight.java
+++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_StyledText_VariableLineHeight.java
@@ -1,261 +1,261 @@
-/**
- * Copyright (c) 2018 Angelo ZERR.
+/**
+ * Copyright (c) 2018 Angelo ZERR.
*
- * This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License 2.0
- * which accompanies this distribution, and is available at
+ * This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
- * SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
- * Angelo Zerr <angelo.zerr@gmail.com> - StyledText.setStyleRange resets less cache - Bug 530019
- */
-package org.eclipse.swt.tests.junit;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.StyleRange;
-import org.eclipse.swt.custom.StyledText;
-import org.eclipse.swt.graphics.Font;
-import org.eclipse.swt.graphics.FontData;
-import org.eclipse.swt.graphics.TextLayout;
-import org.eclipse.swt.widgets.Shell;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * Automated Test Suite for class org.eclipse.swt.custom.StyledText to check there is no regression with Bug 530019
- *
- * @see org.eclipse.swt.custom.StyledText
- */
-public class Test_org_eclipse_swt_custom_StyledText_VariableLineHeight {
-
- Shell shell;
- StyledText styledText;
-
- @Before
- public void setUp() {
- shell = new Shell();
- styledText = new StyledText(shell, SWT.NULL);
- styledText.setLineSpacingProvider(l -> 0);
- }
-
- @After
- public void tearDown() {
- shell.dispose();
- }
-
- @Test
- public void testRise() {
- styledText.setText("a\nb\nc\nd");
- int length = styledText.getCharCount();
-
- // No style
- assertVariableLineHeightEquals(0, 0);
-
- // style with rise=1
- StyleRange style = new StyleRange();
- style.start = 0;
- style.length = length;
- style.rise = 1;
- styledText.replaceStyleRanges(0, length, new StyleRange[] { style });
- assertVariableLineHeightEquals(1, 0);
-
- // style with rise=0
- style = new StyleRange();
- style.start = 0;
- style.length = length;
- style.rise = 0;
- styledText.replaceStyleRanges(0, length, new StyleRange[] { style });
- assertVariableLineHeightEquals(0, 0);
-
- // style with rise=2
- style = new StyleRange();
- style.start = 0;
- style.length = length;
- style.rise = 2;
- styledText.replaceStyleRanges(0, length, new StyleRange[] { style });
- assertVariableLineHeightEquals(2, 0);
-
- // style with rise=2 again
- style = new StyleRange();
- style.start = 0;
- style.length = length;
- style.rise = 2;
- styledText.replaceStyleRanges(0, length, new StyleRange[] { style });
- assertVariableLineHeightEquals(2, 0);
- }
-
- @Test
- public void testFont() {
- styledText.setText("a\nb\nc\nd");
-
- // Create little, big font
- Font initialFont = styledText.getFont();
- FontData[] fontData = initialFont.getFontData();
- for (int i = 0; i < fontData.length; i++) {
- fontData[i].setHeight(24);
- }
- Font bigFont = new Font(styledText.getDisplay(), fontData);
- fontData = initialFont.getFontData();
- for (int i = 0; i < fontData.length; i++) {
- fontData[i].setHeight(fontData[i].getHeight() - 1);
- }
- Font littleFont = new Font(styledText.getDisplay(), fontData);
-
- int length = styledText.getCharCount();
-
- // No style
- assertVariableLineHeightEquals(0, 0);
-
- // style with big font
- StyleRange style = new StyleRange();
- style.start = 0;
- style.length = length;
- style.foreground = styledText.getDisplay().getSystemColor(SWT.COLOR_BLUE);
- style.font = bigFont;
- styledText.replaceStyleRanges(0, length, new StyleRange[] { style });
- assertVariableLineHeightEquals(0, 0, bigFont);
-
- // style with no font
- style = new StyleRange();
- style.start = 0;
- style.length = length;
- style.foreground = styledText.getDisplay().getSystemColor(SWT.COLOR_BLUE);
- style.font = null;
- styledText.replaceStyleRanges(0, length, new StyleRange[] { style });
- assertVariableLineHeightEquals(0, 0);
-
- // style with big font
- style = new StyleRange();
- style.start = 0;
- style.length = length;
- style.foreground = styledText.getDisplay().getSystemColor(SWT.COLOR_BLUE);
- style.font = bigFont;
- styledText.replaceStyleRanges(0, length, new StyleRange[] { style });
- assertVariableLineHeightEquals(0, 0, bigFont);
-
- // style with little font
- style = new StyleRange();
- style.start = 0;
- style.length = length;
- style.foreground = styledText.getDisplay().getSystemColor(SWT.COLOR_BLUE);
- style.font = littleFont;
- styledText.replaceStyleRanges(0, length, new StyleRange[] { style });
- assertVariableLineHeightEquals(0, 0);
-
- // style with no font
- style = new StyleRange();
- style.start = 0;
- style.length = length;
- style.foreground = styledText.getDisplay().getSystemColor(SWT.COLOR_BLUE);
- style.font = null;
- styledText.replaceStyleRanges(0, length, new StyleRange[] { style });
- assertVariableLineHeightEquals(0, 0);
-
- // style with little font
- style = new StyleRange();
- style.start = 0;
- style.length = length;
- style.foreground = styledText.getDisplay().getSystemColor(SWT.COLOR_BLUE);
- style.font = littleFont;
- styledText.replaceStyleRanges(0, length, new StyleRange[] { style });
- assertVariableLineHeightEquals(0, 0);
-
- bigFont.dispose();
- littleFont.dispose();
- }
-
- @Test
- public void testLittleFontSeveralRanges() {
- styledText.setText("abc\nd");
-
- // Create little, big font
- Font initialFont = styledText.getFont();
- FontData[] fontData = initialFont.getFontData();
- for (int i = 0; i < fontData.length; i++) {
- fontData[i].setHeight(fontData[i].getHeight() / 2);
- }
- Font littleFont1 = new Font(styledText.getDisplay(), fontData);
- fontData = initialFont.getFontData();
- for (int i = 0; i < fontData.length; i++) {
- fontData[i].setHeight(fontData[i].getHeight() / 4);
- }
- Font littleFont2 = new Font(styledText.getDisplay(), fontData);
-
- StyleRange[] ranges = new StyleRange[2];
- ranges[0] = new StyleRange();
- ranges[0].start = 0;
- ranges[0].length = 1;
- ranges[0].font = littleFont1;
-
- ranges[1] = new StyleRange();
- ranges[1].start = 1;
- ranges[1].length = 1;
- ranges[1].font = littleFont2;
-
- styledText.replaceStyleRanges(0, 3,ranges);
- // 2 little fonts, line height is the height of the default font of StyledText
- assertVariableLineHeightEquals(0, 0);
-
- littleFont1.dispose();
- littleFont2.dispose();
- }
-
- @Test
- public void testBigFontSeveralRanges() {
- styledText.setText("abc\nd");
-
- // Create little, big font
- Font initialFont = styledText.getFont();
- FontData[] fontData = initialFont.getFontData();
- for (int i = 0; i < fontData.length; i++) {
- fontData[i].setHeight(fontData[i].getHeight() * 2);
- }
- Font bigFont = new Font(styledText.getDisplay(), fontData);
- fontData = initialFont.getFontData();
- for (int i = 0; i < fontData.length; i++) {
- fontData[i].setHeight(fontData[i].getHeight() / 2);
- }
- Font littleFont = new Font(styledText.getDisplay(), fontData);
-
-
- StyleRange[] ranges = new StyleRange[2];
- ranges[0] = new StyleRange();
- ranges[0].start = 0;
- ranges[0].length = 1;
- ranges[0].font = bigFont;
-
- ranges[1] = new StyleRange();
- ranges[1].start = 1;
- ranges[1].length = 1;
- ranges[1].font = littleFont;
-
- styledText.replaceStyleRanges(0, 3,ranges);
- // line height is the height of the big font
- assertVariableLineHeightEquals(0, 0, bigFont);
-
- bigFont.dispose();
- littleFont.dispose();
- }
-
- private void assertVariableLineHeightEquals(int expected, int lineIndex) {
- assertVariableLineHeightEquals(expected, lineIndex, null);
- }
-
- private void assertVariableLineHeightEquals(int expected, int lineIndex, Font font) {
- int fontHeight = styledText.getLineHeight();
- if (font != null) {
- TextLayout layout = new TextLayout(font.getDevice());
- layout.setFont(font);
- layout.setText("a");
- fontHeight = layout.getBounds().height;
- layout.dispose();
- }
- int actual = styledText.getLinePixel(lineIndex + 1) - styledText.getLinePixel(lineIndex) - fontHeight;
- Assert.assertEquals(expected, actual);
- }
-
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Angelo Zerr <angelo.zerr@gmail.com> - StyledText.setStyleRange resets less cache - Bug 530019
+ */
+package org.eclipse.swt.tests.junit;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.StyleRange;
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.FontData;
+import org.eclipse.swt.graphics.TextLayout;
+import org.eclipse.swt.widgets.Shell;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Automated Test Suite for class org.eclipse.swt.custom.StyledText to check there is no regression with Bug 530019
+ *
+ * @see org.eclipse.swt.custom.StyledText
+ */
+public class Test_org_eclipse_swt_custom_StyledText_VariableLineHeight {
+
+ Shell shell;
+ StyledText styledText;
+
+ @Before
+ public void setUp() {
+ shell = new Shell();
+ styledText = new StyledText(shell, SWT.NULL);
+ styledText.setLineSpacingProvider(l -> 0);
+ }
+
+ @After
+ public void tearDown() {
+ shell.dispose();
+ }
+
+ @Test
+ public void testRise() {
+ styledText.setText("a\nb\nc\nd");
+ int length = styledText.getCharCount();
+
+ // No style
+ assertVariableLineHeightEquals(0, 0);
+
+ // style with rise=1
+ StyleRange style = new StyleRange();
+ style.start = 0;
+ style.length = length;
+ style.rise = 1;
+ styledText.replaceStyleRanges(0, length, new StyleRange[] { style });
+ assertVariableLineHeightEquals(1, 0);
+
+ // style with rise=0
+ style = new StyleRange();
+ style.start = 0;
+ style.length = length;
+ style.rise = 0;
+ styledText.replaceStyleRanges(0, length, new StyleRange[] { style });
+ assertVariableLineHeightEquals(0, 0);
+
+ // style with rise=2
+ style = new StyleRange();
+ style.start = 0;
+ style.length = length;
+ style.rise = 2;
+ styledText.replaceStyleRanges(0, length, new StyleRange[] { style });
+ assertVariableLineHeightEquals(2, 0);
+
+ // style with rise=2 again
+ style = new StyleRange();
+ style.start = 0;
+ style.length = length;
+ style.rise = 2;
+ styledText.replaceStyleRanges(0, length, new StyleRange[] { style });
+ assertVariableLineHeightEquals(2, 0);
+ }
+
+ @Test
+ public void testFont() {
+ styledText.setText("a\nb\nc\nd");
+
+ // Create little, big font
+ Font initialFont = styledText.getFont();
+ FontData[] fontData = initialFont.getFontData();
+ for (int i = 0; i < fontData.length; i++) {
+ fontData[i].setHeight(24);
+ }
+ Font bigFont = new Font(styledText.getDisplay(), fontData);
+ fontData = initialFont.getFontData();
+ for (int i = 0; i < fontData.length; i++) {
+ fontData[i].setHeight(fontData[i].getHeight() - 1);
+ }
+ Font littleFont = new Font(styledText.getDisplay(), fontData);
+
+ int length = styledText.getCharCount();
+
+ // No style
+ assertVariableLineHeightEquals(0, 0);
+
+ // style with big font
+ StyleRange style = new StyleRange();
+ style.start = 0;
+ style.length = length;
+ style.foreground = styledText.getDisplay().getSystemColor(SWT.COLOR_BLUE);
+ style.font = bigFont;
+ styledText.replaceStyleRanges(0, length, new StyleRange[] { style });
+ assertVariableLineHeightEquals(0, 0, bigFont);
+
+ // style with no font
+ style = new StyleRange();
+ style.start = 0;
+ style.length = length;
+ style.foreground = styledText.getDisplay().getSystemColor(SWT.COLOR_BLUE);
+ style.font = null;
+ styledText.replaceStyleRanges(0, length, new StyleRange[] { style });
+ assertVariableLineHeightEquals(0, 0);
+
+ // style with big font
+ style = new StyleRange();
+ style.start = 0;
+ style.length = length;
+ style.foreground = styledText.getDisplay().getSystemColor(SWT.COLOR_BLUE);
+ style.font = bigFont;
+ styledText.replaceStyleRanges(0, length, new StyleRange[] { style });
+ assertVariableLineHeightEquals(0, 0, bigFont);
+
+ // style with little font
+ style = new StyleRange();
+ style.start = 0;
+ style.length = length;
+ style.foreground = styledText.getDisplay().getSystemColor(SWT.COLOR_BLUE);
+ style.font = littleFont;
+ styledText.replaceStyleRanges(0, length, new StyleRange[] { style });
+ assertVariableLineHeightEquals(0, 0);
+
+ // style with no font
+ style = new StyleRange();
+ style.start = 0;
+ style.length = length;
+ style.foreground = styledText.getDisplay().getSystemColor(SWT.COLOR_BLUE);
+ style.font = null;
+ styledText.replaceStyleRanges(0, length, new StyleRange[] { style });
+ assertVariableLineHeightEquals(0, 0);
+
+ // style with little font
+ style = new StyleRange();
+ style.start = 0;
+ style.length = length;
+ style.foreground = styledText.getDisplay().getSystemColor(SWT.COLOR_BLUE);
+ style.font = littleFont;
+ styledText.replaceStyleRanges(0, length, new StyleRange[] { style });
+ assertVariableLineHeightEquals(0, 0);
+
+ bigFont.dispose();
+ littleFont.dispose();
+ }
+
+ @Test
+ public void testLittleFontSeveralRanges() {
+ styledText.setText("abc\nd");
+
+ // Create little, big font
+ Font initialFont = styledText.getFont();
+ FontData[] fontData = initialFont.getFontData();
+ for (int i = 0; i < fontData.length; i++) {
+ fontData[i].setHeight(fontData[i].getHeight() / 2);
+ }
+ Font littleFont1 = new Font(styledText.getDisplay(), fontData);
+ fontData = initialFont.getFontData();
+ for (int i = 0; i < fontData.length; i++) {
+ fontData[i].setHeight(fontData[i].getHeight() / 4);
+ }
+ Font littleFont2 = new Font(styledText.getDisplay(), fontData);
+
+ StyleRange[] ranges = new StyleRange[2];
+ ranges[0] = new StyleRange();
+ ranges[0].start = 0;
+ ranges[0].length = 1;
+ ranges[0].font = littleFont1;
+
+ ranges[1] = new StyleRange();
+ ranges[1].start = 1;
+ ranges[1].length = 1;
+ ranges[1].font = littleFont2;
+
+ styledText.replaceStyleRanges(0, 3,ranges);
+ // 2 little fonts, line height is the height of the default font of StyledText
+ assertVariableLineHeightEquals(0, 0);
+
+ littleFont1.dispose();
+ littleFont2.dispose();
+ }
+
+ @Test
+ public void testBigFontSeveralRanges() {
+ styledText.setText("abc\nd");
+
+ // Create little, big font
+ Font initialFont = styledText.getFont();
+ FontData[] fontData = initialFont.getFontData();
+ for (int i = 0; i < fontData.length; i++) {
+ fontData[i].setHeight(fontData[i].getHeight() * 2);
+ }
+ Font bigFont = new Font(styledText.getDisplay(), fontData);
+ fontData = initialFont.getFontData();
+ for (int i = 0; i < fontData.length; i++) {
+ fontData[i].setHeight(fontData[i].getHeight() / 2);
+ }
+ Font littleFont = new Font(styledText.getDisplay(), fontData);
+
+
+ StyleRange[] ranges = new StyleRange[2];
+ ranges[0] = new StyleRange();
+ ranges[0].start = 0;
+ ranges[0].length = 1;
+ ranges[0].font = bigFont;
+
+ ranges[1] = new StyleRange();
+ ranges[1].start = 1;
+ ranges[1].length = 1;
+ ranges[1].font = littleFont;
+
+ styledText.replaceStyleRanges(0, 3,ranges);
+ // line height is the height of the big font
+ assertVariableLineHeightEquals(0, 0, bigFont);
+
+ bigFont.dispose();
+ littleFont.dispose();
+ }
+
+ private void assertVariableLineHeightEquals(int expected, int lineIndex) {
+ assertVariableLineHeightEquals(expected, lineIndex, null);
+ }
+
+ private void assertVariableLineHeightEquals(int expected, int lineIndex, Font font) {
+ int fontHeight = styledText.getLineHeight();
+ if (font != null) {
+ TextLayout layout = new TextLayout(font.getDevice());
+ layout.setFont(font);
+ layout.setText("a");
+ fontHeight = layout.getBounds().height;
+ layout.dispose();
+ }
+ int actual = styledText.getLinePixel(lineIndex + 1) - styledText.getLinePixel(lineIndex) - fontHeight;
+ Assert.assertEquals(expected, actual);
+ }
+
} \ No newline at end of file

Back to the top