Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Keller2017-02-07 09:29:23 -0500
committerMarkus Keller2017-02-07 09:29:23 -0500
commit309e344297e853787f6274cb01f2bc89641d978f (patch)
tree81bfcf9f7a9f2b6b691818e7a40c575fd7d2f04f /examples
parent644f03408b60f4d64f3706a0fd599a6e8f957d73 (diff)
downloadeclipse.platform.swt-309e344297e853787f6274cb01f2bc89641d978f.tar.gz
eclipse.platform.swt-309e344297e853787f6274cb01f2bc89641d978f.tar.xz
eclipse.platform.swt-309e344297e853787f6274cb01f2bc89641d978f.zip
Bug 401015: Add support for styling hyperlinks in the Link widget
added missing support in ControlExample
Diffstat (limited to 'examples')
-rw-r--r--examples/org.eclipse.swt.examples/src/examples_control.properties1
-rw-r--r--examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/LinkTab.java78
2 files changed, 76 insertions, 3 deletions
diff --git a/examples/org.eclipse.swt.examples/src/examples_control.properties b/examples/org.eclipse.swt.examples/src/examples_control.properties
index b3586343e0..cba28732eb 100644
--- a/examples/org.eclipse.swt.examples/src/examples_control.properties
+++ b/examples/org.eclipse.swt.examples/src/examples_control.properties
@@ -229,6 +229,7 @@ Set_Unselected_Close_Visible = Close on Unselected Tabs
Set_Unselected_Image_Visible = Image on Unselected Tabs
Selection_Foreground_Color = Selection Foreground Color
Selection_Background_Color = Selection Background Color
+Link_Foreground_Color = Link Foreground Color
Set_Image = Set Image
Set_Top_Right = Set Top Right
Top_Right_Styles = Top Right Styles
diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/LinkTab.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/LinkTab.java
index 929fae7981..4019002e50 100644
--- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/LinkTab.java
+++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/LinkTab.java
@@ -11,15 +11,27 @@
package org.eclipse.swt.examples.controlexample;
-import org.eclipse.swt.*;
-import org.eclipse.swt.widgets.*;
-import org.eclipse.swt.layout.*;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Link;
+import org.eclipse.swt.widgets.TableItem;
+import org.eclipse.swt.widgets.Widget;
class LinkTab extends Tab {
/* Example widgets and groups that contain them */
Link link1;
Group linkGroup;
+ /* Controls and resources added to the "Fonts" group */
+ static final int LINK_FOREGROUND_COLOR = 3;
+ Color linkForegroundColor;
+
/**
* Creates the Tab within a given instance of ControlExample.
*/
@@ -68,6 +80,66 @@ class LinkTab extends Tab {
borderButton.setText("SWT.BORDER");
}
+ @Override
+ void createColorAndFontGroup () {
+ super.createColorAndFontGroup();
+
+ TableItem item = new TableItem(colorAndFontTable, SWT.None);
+ item.setText(ControlExample.getResourceString ("Link_Foreground_Color"));
+
+ shell.addDisposeListener(event -> {
+ if (linkForegroundColor != null) linkForegroundColor.dispose();
+ linkForegroundColor = null;
+ });
+ }
+
+ @Override
+ void changeFontOrColor(int index) {
+ switch (index) {
+ case LINK_FOREGROUND_COLOR: {
+ Color oldColor = linkForegroundColor;
+ if (oldColor == null) oldColor = link1.getLinkForeground();
+ colorDialog.setRGB(oldColor.getRGB());
+ RGB rgb = colorDialog.open();
+ if (rgb == null) return;
+ oldColor = linkForegroundColor;
+ linkForegroundColor = new Color (display, rgb);
+ setLinkForeground ();
+ if (oldColor != null) oldColor.dispose ();
+ }
+ break;
+ default:
+ super.changeFontOrColor(index);
+ }
+ }
+
+ void setLinkForeground () {
+ if (!instance.startup) {
+ link1.setLinkForeground(linkForegroundColor);
+ }
+ Color color = linkForegroundColor;
+ if (color == null) color = link1.getLinkForeground ();
+ TableItem item = colorAndFontTable.getItem(LINK_FOREGROUND_COLOR);
+ Image oldImage = item.getImage();
+ if (oldImage != null) oldImage.dispose();
+ item.setImage (colorImage(color));
+ }
+
+ @Override
+ void resetColorsAndFonts () {
+ super.resetColorsAndFonts ();
+ Color oldColor = linkForegroundColor;
+ linkForegroundColor = null;
+ setLinkForeground ();
+ if (oldColor != null) oldColor.dispose();
+ }
+
+ @Override
+ void setExampleWidgetState () {
+ super.setExampleWidgetState();
+ setLinkForeground ();
+ }
+
/**
* Gets the "Example" widget children.
*/

Back to the top