Fixed bug 375468: [preferences] Focus rectangle partially obscured for
checkboxes with links
diff --git a/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/TextEditorDefaultsPreferencePage.java b/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/TextEditorDefaultsPreferencePage.java
index aac9081..42e57c6 100644
--- a/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/TextEditorDefaultsPreferencePage.java
+++ b/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/TextEditorDefaultsPreferencePage.java
@@ -19,17 +19,11 @@
 import java.util.Set;
 
 import org.eclipse.swt.SWT;
-import org.eclipse.swt.accessibility.AccessibleAdapter;
-import org.eclipse.swt.accessibility.AccessibleEvent;
 import org.eclipse.swt.events.ModifyEvent;
 import org.eclipse.swt.events.ModifyListener;
-import org.eclipse.swt.events.MouseAdapter;
-import org.eclipse.swt.events.MouseEvent;
 import org.eclipse.swt.events.SelectionAdapter;
 import org.eclipse.swt.events.SelectionEvent;
 import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.events.TraverseEvent;
-import org.eclipse.swt.events.TraverseListener;
 import org.eclipse.swt.graphics.RGB;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
@@ -48,7 +42,6 @@
 import org.eclipse.core.runtime.Assert;
 import org.eclipse.core.runtime.IStatus;
 
-import org.eclipse.jface.action.LegacyActionTools;
 import org.eclipse.jface.dialogs.Dialog;
 import org.eclipse.jface.dialogs.DialogPage;
 import org.eclipse.jface.dialogs.IDialogConstants;
@@ -60,7 +53,6 @@
 import org.eclipse.jface.preference.PreferencePage;
 import org.eclipse.jface.resource.JFaceResources;
 import org.eclipse.jface.resource.StringConverter;
-import org.eclipse.jface.util.Util;
 
 import org.eclipse.ui.IWorkbench;
 import org.eclipse.ui.IWorkbenchPreferencePage;
@@ -848,8 +840,9 @@
 		addCheckBox(appearanceComposite, showMagnet, new BooleanDomain(), 0);
 
 		label= TextEditorMessages.TextEditorDefaultsPreferencePage_showWhitespaceCharacters;
+		String linkText= TextEditorMessages.TextEditorDefaultsPreferencePage_showWhitespaceCharactersLinkText;
 		Preference showWhitespaceCharacters= new Preference(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SHOW_WHITESPACE_CHARACTERS, label, null);
-		addCheckBoxWithLink(appearanceComposite, showWhitespaceCharacters, new BooleanDomain(), 0, new SelectionAdapter() {
+		addCheckBoxWithLink(appearanceComposite, showWhitespaceCharacters, linkText, new BooleanDomain(), 0, new SelectionAdapter() {
 			public void widgetSelected(SelectionEvent e) {
 				Dialog dialog= new WhitespaceCharacterPainterOptionsDialog(Display.getDefault().getActiveShell(), fOverlayStore);
 				dialog.open();
@@ -1137,7 +1130,7 @@
 		return checkBox;
 	}
 
-	Button addCheckBoxWithLink(Composite parent, final Preference preference, final Domain domain, int indentation, final SelectionListener listener) {
+	private Button addCheckBoxWithLink(Composite parent, final Preference preference, String linkText, final Domain domain, int indentation, final SelectionListener listener) {
 		GridData gd= new GridData(GridData.FILL, GridData.FILL, true, false);
 		gd.horizontalSpan= 3;
 		gd.horizontalIndent= indentation;
@@ -1153,63 +1146,29 @@
 
 		final Button checkBox= new Button(composite, SWT.CHECK);
 		checkBox.setFont(JFaceResources.getDialogFont());
+		checkBox.setText(preference.getName());
 		gd= new GridData(GridData.FILL, GridData.CENTER, false, false);
-		int offset= Util.isMac() ? -4 : Util.isLinux() ? -2 : /* Windows et al. */ 3;
-		gd.widthHint= checkBox.computeSize(SWT.DEFAULT, SWT.DEFAULT).x + offset;
 		checkBox.setLayoutData(gd);
 		checkBox.addSelectionListener(new SelectionAdapter() {
 			public void widgetSelected(SelectionEvent e) {
 				checkboxControlChanged(preference, domain, checkBox);
 			}
 		});
-		checkBox.getAccessible().addAccessibleListener(new AccessibleAdapter() {
-			public void getName(AccessibleEvent e) {
-				e.result= LegacyActionTools.removeMnemonics(preference.getName().replaceAll("</?[aA][^>]*>", "")); //$NON-NLS-1$ //$NON-NLS-2$
-			}
-		});
 
 		gd= new GridData(GridData.FILL, GridData.CENTER, false, false);
-
 		Link link= new Link(composite, SWT.NONE);
-		link.setText(preference.getName());
+		link.setText(linkText);
 		link.setLayoutData(gd);
-
-		// toggle checkbox when user clicks unlinked text in link:
-		final boolean[] linkSelected= { false };
-		link.addSelectionListener(new SelectionAdapter() {
-			public void widgetSelected(SelectionEvent e) {
-				linkSelected[0]= true;
-				if (listener != null) {
+		if (listener != null) {
+			link.addSelectionListener(new SelectionAdapter() {
+				public void widgetSelected(SelectionEvent e) {
 					listener.widgetSelected(e);
 				}
-			}
-		});
-		link.addMouseListener(new MouseAdapter() {
-			public void mouseDown(MouseEvent e) {
-				linkSelected[0]= false;
-			}
-			public void mouseUp(MouseEvent e) {
-				if (!linkSelected[0]) {
-					checkBox.setSelection(!checkBox.getSelection());
-					checkBox.setFocus();
-					linkSelected[0]= false;
-					checkboxControlChanged(preference, domain, checkBox);
-				}
-			}
-		});
-		link.addTraverseListener(new TraverseListener() {
-			public void keyTraversed(TraverseEvent e) {
-				if (e.detail == SWT.TRAVERSE_MNEMONIC && e.doit == true) {
-					e.detail= SWT.TRAVERSE_NONE;
-					checkBox.setSelection(!checkBox.getSelection());
-					checkBox.setFocus();
-					linkSelected[0]= false;
-					checkboxControlChanged(preference, domain, checkBox);
-				}
-			}
-		});
+			});
+		}
 
 		fInitializers.add(fInitializerFactory.create(preference, checkBox));
+
 		return checkBox;
 	}
 
diff --git a/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/TextEditorMessages.java b/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/TextEditorMessages.java
index 2110f27..b8dc451 100644
--- a/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/TextEditorMessages.java
+++ b/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/TextEditorMessages.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2011 IBM Corporation and others.
+ * Copyright (c) 2000, 2012 IBM Corporation and others.
  * 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
@@ -141,6 +141,7 @@
 	public static String TextEditorDefaultsPreferencePage_smartHomeEnd;
 	public static String TextEditorDefaultsPreferencePage_warn_if_derived;
 	public static String TextEditorDefaultsPreferencePage_showWhitespaceCharacters;
+	public static String TextEditorDefaultsPreferencePage_showWhitespaceCharactersLinkText;
 	public static String TextEditorDefaultsPreferencePage_showWhitespaceCharactersDialogInvalidInput;
 	public static String TextEditorDefaultsPreferencePage_showWhitespaceCharactersDialogTitle;
 	public static String TextEditorDefaultsPreferencePage_space;
diff --git a/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/TextEditorMessages.properties b/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/TextEditorMessages.properties
index 2d2eba9..3fe2520 100644
--- a/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/TextEditorMessages.properties
+++ b/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/TextEditorMessages.properties
@@ -1,5 +1,5 @@
 ###############################################################################
-# Copyright (c) 2000, 2011 IBM Corporation and others.
+# Copyright (c) 2000, 2012 IBM Corporation and others.
 # 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
@@ -45,7 +45,8 @@
 TextEditorDefaultsPreferencePage_range_indicator=Show &range indicator
 TextEditorDefaultsPreferencePage_warn_if_derived= War&n before editing a derived file
 TextEditorDefaultsPreferencePage_smartHomeEnd= &Smart caret positioning at line start and end
-TextEditorDefaultsPreferencePage_showWhitespaceCharacters= Sh&ow <a>whitespace characters</a>
+TextEditorDefaultsPreferencePage_showWhitespaceCharacters= Sh&ow whitespace characters
+TextEditorDefaultsPreferencePage_showWhitespaceCharactersLinkText= (<a>configure visibility</a>)
 TextEditorDefaultsPreferencePage_showWhitespaceCharactersDialogInvalidInput=''{0}'' is not a valid input.
 TextEditorDefaultsPreferencePage_showWhitespaceCharactersDialogTitle=Show Whitespace Characters
 TextEditorDefaultsPreferencePage_space=Space ( \u00b7 )