Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorangelozerr2017-09-08 06:29:57 -0400
committerAlexander Kurtakov2017-10-31 07:46:30 -0400
commitf9705370b9d70e37481e4fea8bb8142695f17580 (patch)
tree44d2a491cfc91056738d62455f41e9cd8c0d8ada /examples
parentbb9bd43d337e12b945ea1794139c75671aab244c (diff)
downloadeclipse.platform.swt-f9705370b9d70e37481e4fea8bb8142695f17580.tar.gz
eclipse.platform.swt-f9705370b9d70e37481e4fea8bb8142695f17580.tar.xz
eclipse.platform.swt-f9705370b9d70e37481e4fea8bb8142695f17580.zip
Bug 522020 - Customize different line spacing of StyledText with
LineSpacingProvider Change-Id: I49be88a44178db1dc5a540a5cb5f3ede02f5688f Signed-off-by: angelozerr <angelo.zerr@gmail.com>
Diffstat (limited to 'examples')
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet368.java54
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet369.java55
2 files changed, 109 insertions, 0 deletions
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
new file mode 100644
index 0000000000..19b887e03c
--- /dev/null
+++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet368.java
@@ -0,0 +1,54 @@
+/**
+ * Copyright (c) 2017 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * 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
new file mode 100644
index 0000000000..ecd22ab363
--- /dev/null
+++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet369.java
@@ -0,0 +1,55 @@
+/**
+ * Copyright (c) 2017 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * 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();
+ }
+}

Back to the top