Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 90043 Details for
Bug 219393
[Viewers] StyledCellLabelProvider update
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
JDT UI patch
colored-labels-jdt.txt (text/plain), 141.43 KB, created by
Martin Aeschlimann
on 2008-02-19 04:14:04 EST
(
hide
)
Description:
JDT UI patch
Filename:
MIME Type:
Creator:
Martin Aeschlimann
Created:
2008-02-19 04:14:04 EST
Size:
141.43 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.ui >Index: ui refactoring/org/eclipse/jdt/internal/ui/refactoring/nls/search/NLSSearchResultLabelProvider2.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui refactoring/org/eclipse/jdt/internal/ui/refactoring/nls/search/NLSSearchResultLabelProvider2.java,v >retrieving revision 1.9 >diff -u -r1.9 NLSSearchResultLabelProvider2.java >--- ui refactoring/org/eclipse/jdt/internal/ui/refactoring/nls/search/NLSSearchResultLabelProvider2.java 24 Aug 2007 11:17:45 -0000 1.9 >+++ ui refactoring/org/eclipse/jdt/internal/ui/refactoring/nls/search/NLSSearchResultLabelProvider2.java 18 Feb 2008 17:57:15 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2007 IBM Corporation and others. >+ * Copyright (c) 2000, 2008 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 >@@ -15,6 +15,9 @@ > > import org.eclipse.swt.graphics.Image; > >+import org.eclipse.jface.viewers.StyledString; >+import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider; >+ > import org.eclipse.search.ui.text.AbstractTextSearchViewPage; > > import org.eclipse.jdt.ui.JavaElementLabels; >@@ -22,11 +25,9 @@ > import org.eclipse.jdt.internal.ui.search.TextSearchLabelProvider; > import org.eclipse.jdt.internal.ui.viewsupport.AppearanceAwareLabelProvider; > import org.eclipse.jdt.internal.ui.viewsupport.ColoredJavaElementLabels; >-import org.eclipse.jdt.internal.ui.viewsupport.ColoredString; >-import org.eclipse.jdt.internal.ui.viewsupport.IRichLabelProvider; > > >-class NLSSearchResultLabelProvider2 extends TextSearchLabelProvider implements IRichLabelProvider { >+class NLSSearchResultLabelProvider2 extends TextSearchLabelProvider implements IStyledLabelProvider { > > private AppearanceAwareLabelProvider fLabelProvider; > >@@ -35,23 +36,21 @@ > fLabelProvider= new AppearanceAwareLabelProvider(JavaElementLabels.ALL_POST_QUALIFIED, 0); > } > >+ public StyledString getStyledText(Object element) { >+ return getColoredLabelWithCounts(element, internalGetText(element)); >+ } >+ >+ > /* (non-Javadoc) > * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object) > */ > public String getText(Object element) { > return getLabelWithCounts(element, internalGetText(element).toString()); > } >- >- /* (non-Javadoc) >- * @see org.eclipse.jdt.internal.ui.viewsupport.IRichLabelProvider#getRichTextLabel(java.lang.Object) >- */ >- public ColoredString getRichTextLabel(Object element) { >- return getColoredLabelWithCounts(element, internalGetText(element)); >- } >- >- private ColoredString internalGetText(Object element) { >+ >+ private StyledString internalGetText(Object element) { > String description; >- ColoredString elementLabel; >+ StyledString elementLabel; > > if (element instanceof FileEntry) { > FileEntry fileEntry= (FileEntry) element; >@@ -65,12 +64,12 @@ > description= NLSSearchMessages.NLSSearchResultLabelProvider2_undefinedKeys; > elementLabel= ColoredJavaElementLabels.getTextLabel(element, JavaElementLabels.ALL_POST_QUALIFIED | ColoredJavaElementLabels.COLORIZE); > } >- return new ColoredString(description).append(' ').append(elementLabel); >+ return new StyledString(description).append(' ').append(elementLabel); > } > >- private ColoredString getPropertiesName(IFile propertiesFile) { >+ private StyledString getPropertiesName(IFile propertiesFile) { > String path= propertiesFile.getFullPath().removeLastSegments(1).makeRelative().toString(); >- return new ColoredString(propertiesFile.getName()).append(" - " + path, ColoredJavaElementLabels.QUALIFIER_STYLE); //$NON-NLS-1$ >+ return new StyledString(propertiesFile.getName()).append(" - " + path, ColoredJavaElementLabels.QUALIFIER_STYLE); //$NON-NLS-1$ > } > > /* >Index: ui/org/eclipse/jdt/internal/ui/browsing/PackagesViewLabelProvider.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/browsing/PackagesViewLabelProvider.java,v >retrieving revision 1.25 >diff -u -r1.25 PackagesViewLabelProvider.java >--- ui/org/eclipse/jdt/internal/ui/browsing/PackagesViewLabelProvider.java 8 May 2007 09:15:46 -0000 1.25 >+++ ui/org/eclipse/jdt/internal/ui/browsing/PackagesViewLabelProvider.java 18 Feb 2008 17:57:15 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2007 IBM Corporation and others. >+ * Copyright (c) 2000, 2008 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 >@@ -18,6 +18,7 @@ > import org.eclipse.swt.graphics.Image; > > import org.eclipse.jface.resource.ImageDescriptor; >+import org.eclipse.jface.viewers.StyledString; > > import org.eclipse.jdt.core.IPackageFragment; > import org.eclipse.jdt.core.JavaModelException; >@@ -27,7 +28,6 @@ > import org.eclipse.jdt.internal.ui.JavaPlugin; > import org.eclipse.jdt.internal.ui.JavaPluginImages; > import org.eclipse.jdt.internal.ui.viewsupport.AppearanceAwareLabelProvider; >-import org.eclipse.jdt.internal.ui.viewsupport.ColoredString; > import org.eclipse.jdt.internal.ui.viewsupport.ImageDescriptorRegistry; > import org.eclipse.jdt.internal.ui.viewsupport.JavaElementImageProvider; > import org.eclipse.jdt.internal.ui.viewsupport.TreeHierarchyLayoutProblemsDecorator; >@@ -119,13 +119,12 @@ > /* (non-Javadoc) > * @see org.eclipse.jdt.internal.ui.viewsupport.JavaUILabelProvider#getRichTextLabel(java.lang.Object) > */ >- public ColoredString getRichTextLabel(Object element) { >+ public StyledString getStyledText(Object element) { > if (element instanceof IPackageFragment || element instanceof LogicalPackage) >- return new ColoredString(getText(element)); >- return super.getRichTextLabel(element); >+ return new StyledString(getText(element)); >+ return super.getStyledText(element); > } > >- > private String getText(IPackageFragment fragment) { > if (isFlatView()) > return getFlatText(fragment); >Index: ui/org/eclipse/jdt/internal/ui/packageview/PackageExplorerLabelProvider.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/packageview/PackageExplorerLabelProvider.java,v >retrieving revision 1.28 >diff -u -r1.28 PackageExplorerLabelProvider.java >--- ui/org/eclipse/jdt/internal/ui/packageview/PackageExplorerLabelProvider.java 29 May 2007 18:41:43 -0000 1.28 >+++ ui/org/eclipse/jdt/internal/ui/packageview/PackageExplorerLabelProvider.java 18 Feb 2008 17:57:15 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2007 IBM Corporation and others. >+ * Copyright (c) 2000, 2008 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 >@@ -22,6 +22,7 @@ > import org.eclipse.swt.graphics.Image; > > import org.eclipse.jface.resource.ImageDescriptor; >+import org.eclipse.jface.viewers.StyledString; > > import org.eclipse.ui.IWorkingSet; > >@@ -30,7 +31,6 @@ > import org.eclipse.jdt.ui.JavaElementLabels; > > import org.eclipse.jdt.internal.ui.viewsupport.AppearanceAwareLabelProvider; >-import org.eclipse.jdt.internal.ui.viewsupport.ColoredString; > import org.eclipse.jdt.internal.ui.viewsupport.JavaElementImageProvider; > > /** >@@ -60,14 +60,14 @@ > } > > /* (non-Javadoc) >- * @see org.eclipse.jdt.internal.ui.viewsupport.JavaUILabelProvider#getRichTextLabel(java.lang.Object) >+ * @see org.eclipse.jdt.internal.ui.viewsupport.JavaUILabelProvider#getStyledText(java.lang.Object) > */ >- public ColoredString getRichTextLabel(Object element) { >+ public StyledString getStyledText(Object element) { > String text= getSpecificText(element); > if (text != null) { >- return new ColoredString(decorateText(text, element)); >+ return new StyledString(decorateText(text, element)); > } >- return super.getRichTextLabel(element); >+ return super.getStyledText(element); > } > > private String getSpecificText(Object element) { >Index: ui/org/eclipse/jdt/internal/ui/search/SearchLabelProvider.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/search/SearchLabelProvider.java,v >retrieving revision 1.16 >diff -u -r1.16 SearchLabelProvider.java >--- ui/org/eclipse/jdt/internal/ui/search/SearchLabelProvider.java 3 Dec 2007 14:40:49 -0000 1.16 >+++ ui/org/eclipse/jdt/internal/ui/search/SearchLabelProvider.java 18 Feb 2008 17:57:15 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2007 IBM Corporation and others. >+ * Copyright (c) 2000, 2008 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 >@@ -26,6 +26,7 @@ > import org.eclipse.jface.viewers.ILabelProvider; > import org.eclipse.jface.viewers.ILabelProviderListener; > import org.eclipse.jface.viewers.LabelProviderChangedEvent; >+import org.eclipse.jface.viewers.StyledString; > > import org.eclipse.ui.preferences.ScopedPreferenceStore; > >@@ -44,7 +45,6 @@ > import org.eclipse.jdt.internal.ui.JavaPlugin; > import org.eclipse.jdt.internal.ui.viewsupport.AppearanceAwareLabelProvider; > import org.eclipse.jdt.internal.ui.viewsupport.ColoredJavaElementLabels; >-import org.eclipse.jdt.internal.ui.viewsupport.ColoredString; > > public abstract class SearchLabelProvider extends AppearanceAwareLabelProvider { > >@@ -122,11 +122,11 @@ > return res; > } > >- protected final ColoredString getColoredLabelWithCounts(Object element, ColoredString coloredName) { >+ protected final StyledString getColoredLabelWithCounts(Object element, StyledString coloredName) { > String name= coloredName.getString(); > String decorated= getLabelWithCounts(element, name); > if (decorated.length() > name.length()) { >- ColoredJavaElementLabels.decorateColoredString(coloredName, decorated, ColoredJavaElementLabels.COUNTER_STYLE); >+ ColoredJavaElementLabels.decorateStyledString(coloredName, decorated, ColoredJavaElementLabels.COUNTER_STYLE); > } > return coloredName; > } >Index: ui/org/eclipse/jdt/internal/ui/search/OccurrencesSearchLabelProvider.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/search/OccurrencesSearchLabelProvider.java,v >retrieving revision 1.13 >diff -u -r1.13 OccurrencesSearchLabelProvider.java >--- ui/org/eclipse/jdt/internal/ui/search/OccurrencesSearchLabelProvider.java 14 Feb 2008 14:21:01 -0000 1.13 >+++ ui/org/eclipse/jdt/internal/ui/search/OccurrencesSearchLabelProvider.java 18 Feb 2008 17:57:15 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2007 IBM Corporation and others. >+ * Copyright (c) 2000, 2008 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 >@@ -13,6 +13,10 @@ > > import org.eclipse.swt.graphics.Image; > >+import org.eclipse.jface.viewers.StyledString; >+import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider; >+import org.eclipse.jface.viewers.StyledString.Style; >+ > import org.eclipse.search.ui.text.AbstractTextSearchViewPage; > import org.eclipse.search.ui.text.Match; > >@@ -20,11 +24,8 @@ > > import org.eclipse.jdt.internal.ui.JavaPluginImages; > import org.eclipse.jdt.internal.ui.viewsupport.ColoredJavaElementLabels; >-import org.eclipse.jdt.internal.ui.viewsupport.ColoredString; >-import org.eclipse.jdt.internal.ui.viewsupport.IRichLabelProvider; >-import org.eclipse.jdt.internal.ui.viewsupport.ColoredString.Style; > >-class OccurrencesSearchLabelProvider extends TextSearchLabelProvider implements IRichLabelProvider { >+class OccurrencesSearchLabelProvider extends TextSearchLabelProvider implements IStyledLabelProvider { > > public OccurrencesSearchLabelProvider(AbstractTextSearchViewPage page) { > super(page); >@@ -37,13 +38,6 @@ > return getLabelWithCounts(element, internalGetText(element)); > } > >- /* (non-Javadoc) >- * @see org.eclipse.jdt.internal.ui.viewsupport.IRichLabelProvider#getRichTextLabel(java.lang.Object) >- */ >- public ColoredString getRichTextLabel(Object element) { >- return getColoredLabelWithCounts(element, internalGetRichText(element)); >- } >- > private String getLineNumberLabel(JavaElementLine element) { > return Messages.format(SearchMessages.OccurrencesSearchLabelProvider_line_number, new Integer(element.getLine())); > } >@@ -53,14 +47,14 @@ > return getLineNumberLabel(jel) + jel.getLineContents(); > } > >- private ColoredString internalGetRichText(Object element) { >+ private StyledString internalGetRichText(Object element) { > JavaElementLine jel= (JavaElementLine) element; > > String lineNumberString= getLineNumberLabel(jel); > > Style highlightStyle= ColoredJavaElementLabels.HIGHLIGHT_STYLE; > >- ColoredString res= new ColoredString(); >+ StyledString res= new StyledString(); > res.append(lineNumberString, ColoredJavaElementLabels.QUALIFIER_STYLE); > res.append(jel.getLineContents()); > Match[] matches= getPage().getInput().getMatches(jel); >@@ -95,4 +89,11 @@ > } > return JavaPluginImages.get(JavaPluginImages.IMG_OBJS_SEARCH_OCCURRENCE); > } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider#getStyledText(java.lang.Object) >+ */ >+ public StyledString getStyledText(Object element) { >+ return getColoredLabelWithCounts(element, internalGetRichText(element)); >+ } > } >Index: ui/org/eclipse/jdt/internal/ui/search/PostfixLabelProvider.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/search/PostfixLabelProvider.java,v >retrieving revision 1.19 >diff -u -r1.19 PostfixLabelProvider.java >--- ui/org/eclipse/jdt/internal/ui/search/PostfixLabelProvider.java 29 May 2007 18:41:42 -0000 1.19 >+++ ui/org/eclipse/jdt/internal/ui/search/PostfixLabelProvider.java 18 Feb 2008 17:57:15 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2007 IBM Corporation and others. >+ * Copyright (c) 2000, 2008 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 >@@ -13,6 +13,7 @@ > import org.eclipse.swt.graphics.Image; > > import org.eclipse.jface.viewers.ITreeContentProvider; >+import org.eclipse.jface.viewers.StyledString; > > import org.eclipse.jdt.core.IClassFile; > import org.eclipse.jdt.core.ICompilationUnit; >@@ -22,7 +23,6 @@ > import org.eclipse.jdt.ui.JavaElementLabels; > > import org.eclipse.jdt.internal.ui.viewsupport.ColoredJavaElementLabels; >-import org.eclipse.jdt.internal.ui.viewsupport.ColoredString; > > public class PostfixLabelProvider extends SearchLabelProvider { > private ITreeContentProvider fContentProvider; >@@ -88,12 +88,12 @@ > } > > /* (non-Javadoc) >- * @see org.eclipse.jdt.internal.ui.viewsupport.IRichLabelProvider#getRichTextLabel(java.lang.Object) >+ * @see org.eclipse.jdt.internal.ui.viewsupport.JavaUILabelProvider#getStyledText(java.lang.Object) > */ >- public ColoredString getRichTextLabel(Object element) { >- ColoredString coloredString= getColoredLabelWithCounts(element, super.getRichTextLabel(element)); >- coloredString.append(getQualification(element), ColoredJavaElementLabels.QUALIFIER_STYLE); >- return coloredString; >+ public StyledString getStyledText(Object element) { >+ StyledString StyledString= getColoredLabelWithCounts(element, super.getStyledText(element)); >+ StyledString.append(getQualification(element), ColoredJavaElementLabels.QUALIFIER_STYLE); >+ return StyledString; > } > > } >Index: ui/org/eclipse/jdt/internal/ui/search/SortingLabelProvider.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/search/SortingLabelProvider.java,v >retrieving revision 1.16 >diff -u -r1.16 SortingLabelProvider.java >--- ui/org/eclipse/jdt/internal/ui/search/SortingLabelProvider.java 3 Dec 2007 14:39:29 -0000 1.16 >+++ ui/org/eclipse/jdt/internal/ui/search/SortingLabelProvider.java 18 Feb 2008 17:57:15 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2007 IBM Corporation and others. >+ * Copyright (c) 2000, 2008 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 >@@ -14,13 +14,14 @@ > > import org.eclipse.swt.graphics.Image; > >+import org.eclipse.jface.viewers.StyledString; >+ > import org.eclipse.jdt.core.IImportDeclaration; > import org.eclipse.jdt.core.IJavaElement; > > import org.eclipse.jdt.ui.JavaElementLabels; > > import org.eclipse.jdt.internal.ui.viewsupport.ColoredJavaElementLabels; >-import org.eclipse.jdt.internal.ui.viewsupport.ColoredString; > > public class SortingLabelProvider extends SearchLabelProvider { > >@@ -64,21 +65,21 @@ > } > > /* (non-Javadoc) >- * @see org.eclipse.jdt.internal.ui.viewsupport.JavaUILabelProvider#getRichTextLabel(java.lang.Object) >+ * @see org.eclipse.jdt.internal.ui.viewsupport.JavaUILabelProvider#getStyledText(java.lang.Object) > */ >- public ColoredString getRichTextLabel(Object element) { >+ public StyledString getStyledText(Object element) { > if (element instanceof IImportDeclaration) > element= ((IImportDeclaration)element).getParent().getParent(); > >- ColoredString text= super.getRichTextLabel(element); >+ StyledString text= super.getStyledText(element); > if (text.length() > 0) { >- ColoredString countLabel= getColoredLabelWithCounts(element, text); >+ StyledString countLabel= getColoredLabelWithCounts(element, text); > if (fCurrentOrder == SHOW_ELEMENT_CONTAINER) { > countLabel.append(getPostQualification(element), ColoredJavaElementLabels.QUALIFIER_STYLE); > } > return countLabel; > } >- return new ColoredString(getParticipantText(element)); >+ return new StyledString(getParticipantText(element)); > } > > private String getPostQualification(Object element) { >Index: ui/org/eclipse/jdt/internal/ui/search/TextSearchLabelProvider.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/search/TextSearchLabelProvider.java,v >retrieving revision 1.10 >diff -u -r1.10 TextSearchLabelProvider.java >--- ui/org/eclipse/jdt/internal/ui/search/TextSearchLabelProvider.java 24 Aug 2007 11:17:45 -0000 1.10 >+++ ui/org/eclipse/jdt/internal/ui/search/TextSearchLabelProvider.java 18 Feb 2008 17:57:15 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2007 IBM Corporation and others. >+ * Copyright (c) 2000, 2008 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 >@@ -11,13 +11,13 @@ > package org.eclipse.jdt.internal.ui.search; > > import org.eclipse.jface.viewers.LabelProvider; >+import org.eclipse.jface.viewers.StyledString; > > import org.eclipse.search.ui.text.AbstractTextSearchViewPage; > > import org.eclipse.jdt.internal.corext.util.Messages; > > import org.eclipse.jdt.internal.ui.viewsupport.ColoredJavaElementLabels; >-import org.eclipse.jdt.internal.ui.viewsupport.ColoredString; > > public abstract class TextSearchLabelProvider extends LabelProvider { > >@@ -31,11 +31,11 @@ > return fPage; > } > >- protected final ColoredString getColoredLabelWithCounts(Object element, ColoredString coloredName) { >+ protected final StyledString getColoredLabelWithCounts(Object element, StyledString coloredName) { > String name= coloredName.getString(); > String decorated= getLabelWithCounts(element, name); > if (decorated.length() > name.length()) { >- ColoredJavaElementLabels.decorateColoredString(coloredName, decorated, ColoredJavaElementLabels.COUNTER_STYLE); >+ ColoredJavaElementLabels.decorateStyledString(coloredName, decorated, ColoredJavaElementLabels.COUNTER_STYLE); > } > return coloredName; > } >Index: plugin.xml >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/plugin.xml,v >retrieving revision 1.789 >diff -u -r1.789 plugin.xml >--- plugin.xml 6 Feb 2008 14:26:03 -0000 1.789 >+++ plugin.xml 18 Feb 2008 17:57:14 -0000 >@@ -980,7 +980,7 @@ > label="%coloredLabels.qualifier.label" > categoryId="org.eclipse.jdt.ui.presentation" > value="COLOR_DARK_GRAY" >- id="org.eclipse.jdt.ui.ColoredLabels.qualifier"> >+ id="QUALIFIER_COLOR"> > <description> > %coloredLabels.qualifier.description > </description> >@@ -989,7 +989,7 @@ > label="%coloredLabels.decorations.label" > categoryId="org.eclipse.jdt.ui.presentation" > value="149,125,71" >- id="org.eclipse.jdt.ui.ColoredLabels.decorations"> >+ id="DECORATIONS_COLOR"> > <description> > %coloredLabels.decorations.description > </description> >@@ -998,7 +998,7 @@ > label="%coloredLabels.counter.label" > categoryId="org.eclipse.jdt.ui.presentation" > value="0,127,174" >- id="org.eclipse.jdt.ui.ColoredLabels.counter"> >+ id="COUNTER_COLOR"> > <description> > %coloredLabels.counter.description > </description> >Index: ui/org/eclipse/jdt/internal/ui/viewsupport/OwnerDrawSupport.java >=================================================================== >RCS file: ui/org/eclipse/jdt/internal/ui/viewsupport/OwnerDrawSupport.java >diff -N ui/org/eclipse/jdt/internal/ui/viewsupport/OwnerDrawSupport.java >--- ui/org/eclipse/jdt/internal/ui/viewsupport/OwnerDrawSupport.java 14 Feb 2008 14:21:01 -0000 1.20 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,160 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2007 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 >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * IBM Corporation - initial API and implementation >- *******************************************************************************/ >-package org.eclipse.jdt.internal.ui.viewsupport; >- >-import org.eclipse.swt.SWT; >-import org.eclipse.swt.custom.StyleRange; >-import org.eclipse.swt.graphics.Color; >-import org.eclipse.swt.graphics.Font; >-import org.eclipse.swt.graphics.GC; >-import org.eclipse.swt.graphics.Image; >-import org.eclipse.swt.graphics.Rectangle; >-import org.eclipse.swt.graphics.TextLayout; >-import org.eclipse.swt.widgets.Control; >-import org.eclipse.swt.widgets.Display; >-import org.eclipse.swt.widgets.Event; >-import org.eclipse.swt.widgets.Item; >-import org.eclipse.swt.widgets.Listener; >-import org.eclipse.swt.widgets.TableItem; >-import org.eclipse.swt.widgets.TreeItem; >- >-import org.eclipse.jface.window.Window; >- >-/** >- * Adding owner draw support to a control >- */ >-public abstract class OwnerDrawSupport implements Listener { >- >- private TextLayout fTextLayout; >- private final Control fControl; >- >- public OwnerDrawSupport(Control control) { >- fControl= control; >- fTextLayout= new TextLayout(control.getDisplay()); >- fTextLayout.setOrientation(Window.getDefaultOrientation()); >- >- control.addListener(SWT.PaintItem, this); >- control.addListener(SWT.EraseItem, this); >- control.addListener(SWT.Dispose, this); >- } >- >- /** >- * Return the colored label for the given item. >- * @param item the item to return the colored label for >- * @return the colored string >- */ >- public abstract ColoredString getColoredLabel(Item item); >- >- /** >- * Return the color for the given style >- * @param colorName the name of the color >- * @param display the current display >- * @return the color >- */ >- public abstract Color getColor(String colorName, Display display); >- >- /* (non-Javadoc) >- * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event) >- */ >- public void handleEvent(Event event) { >- if (event.type == SWT.PaintItem) { >- performPaint(event); >- } else if (event.type == SWT.EraseItem) { >- performErase(event); >- } else if (event.type == SWT.Dispose) { >- dispose(); >- } >- } >- >- private void performErase(Event event) { >- event.detail &= ~SWT.FOREGROUND; >- } >- >- private void performPaint(Event event) { >- Item item= (Item) event.item; >- GC gc= event.gc; >- >- ColoredString coloredLabel= getColoredLabel(item); >- boolean isSelected= (event.detail & SWT.SELECTED) != 0; >- if (item instanceof TreeItem) { >- TreeItem treeItem= (TreeItem) item; >- Image image = treeItem.getImage(event.index); >- if (image != null) { >- processImage(image, gc, treeItem.getImageBounds(event.index)); >- } >- Rectangle textBounds= treeItem.getTextBounds(event.index); >- Font font= treeItem.getFont(event.index); >- processColoredLabel(coloredLabel, gc, textBounds, isSelected, font); >- >- Rectangle bounds= treeItem.getBounds(); >- if ((event.detail & SWT.FOCUSED) != 0) { >- gc.drawFocus(bounds.x, bounds.y, bounds.width, bounds.height); >- } >- } else if (item instanceof TableItem) { >- TableItem tableItem= (TableItem) item; >- Image image = tableItem.getImage(event.index); >- if (image != null) { >- processImage(image, gc, tableItem.getImageBounds(event.index)); >- } >- Rectangle textBounds= tableItem.getTextBounds(event.index); >- Font font= tableItem.getFont(event.index); >- processColoredLabel(coloredLabel, gc, textBounds, isSelected, font); >- >- Rectangle bounds= tableItem.getBounds(); >- if ((event.detail & SWT.FOCUSED) != 0) { >- gc.drawFocus(bounds.x, bounds.y, bounds.width, bounds.height); >- } >- } >- } >- >- private void processImage(Image image, GC gc, Rectangle imageBounds) { >- Rectangle bounds= image.getBounds(); >- int x= imageBounds.x + Math.max(0, (imageBounds.width - bounds.width) / 2); >- int y= imageBounds.y + Math.max(0, (imageBounds.height - bounds.height) / 2); >- gc.drawImage(image, x, y); >- } >- >- private void processColoredLabel(ColoredString richLabel, GC gc, Rectangle textBounds, boolean isSelected, Font font) { >- String text= richLabel.getString(); >- fTextLayout.setText(text); >- fTextLayout.setFont(font); >- >- // apply the styled ranges only when element is not selected >- StyleRange[] styleRanges= richLabel.getStyleRanges(); >- for (int i= 0; i < styleRanges.length; i++) { >- StyleRange styleRange= styleRanges[i]; >- if (isSelected) { >- styleRange.foreground= null; >- styleRange.background= null; >- } >- fTextLayout.setStyle(styleRange, styleRange.start, styleRange.start + styleRange.length - 1); >- } >- >- Rectangle bounds= fTextLayout.getBounds(); >- int x= textBounds.x; >- int y = textBounds.y + Math.max(0, (textBounds.height - bounds.height) / 2); >- >- fTextLayout.draw(gc, x, y); >- fTextLayout.setText(""); // clear all ranges //$NON-NLS-1$ >- } >- >- public void dispose() { >- if (fTextLayout != null) { >- fTextLayout.dispose(); >- fTextLayout= null; >- } >- if (!fControl.isDisposed()) { >- fControl.removeListener(SWT.PaintItem, this); >- fControl.removeListener(SWT.EraseItem, this); >- fControl.removeListener(SWT.Dispose, this); >- } >- } >-} >Index: ui/org/eclipse/jdt/internal/ui/viewsupport/JavaUILabelProvider.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/viewsupport/JavaUILabelProvider.java,v >retrieving revision 1.29 >diff -u -r1.29 JavaUILabelProvider.java >--- ui/org/eclipse/jdt/internal/ui/viewsupport/JavaUILabelProvider.java 29 May 2007 18:41:49 -0000 1.29 >+++ ui/org/eclipse/jdt/internal/ui/viewsupport/JavaUILabelProvider.java 18 Feb 2008 17:57:15 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2007 IBM Corporation and others. >+ * Copyright (c) 2000, 2008 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 >@@ -26,10 +26,12 @@ > import org.eclipse.jface.viewers.ILabelProvider; > import org.eclipse.jface.viewers.ILabelProviderListener; > import org.eclipse.jface.viewers.LabelProviderChangedEvent; >+import org.eclipse.jface.viewers.StyledString; >+import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider; > > import org.eclipse.jdt.ui.JavaElementLabels; > >-public class JavaUILabelProvider implements ILabelProvider, IColorProvider, IRichLabelProvider { >+public class JavaUILabelProvider implements ILabelProvider, IColorProvider, IStyledLabelProvider { > > protected ListenerList fListeners = new ListenerList(); > >@@ -171,14 +173,14 @@ > return decorateText(result, element); > } > >- public ColoredString getRichTextLabel(Object element) { >- ColoredString string= ColoredJavaElementLabels.getTextLabel(element, evaluateTextFlags(element) | ColoredJavaElementLabels.COLORIZE); >+ public StyledString getStyledText(Object element) { >+ StyledString string= ColoredJavaElementLabels.getTextLabel(element, evaluateTextFlags(element) | ColoredJavaElementLabels.COLORIZE); > if (string.length() == 0 && (element instanceof IStorage)) { >- string= new ColoredString(fStorageLabelProvider.getText(element)); >+ string= new StyledString(fStorageLabelProvider.getText(element)); > } > String decorated= decorateText(string.getString(), element); > if (decorated != null) { >- return ColoredJavaElementLabels.decorateColoredString(string, decorated, ColoredJavaElementLabels.DECORATIONS_STYLE); >+ return ColoredJavaElementLabels.decorateStyledString(string, decorated, ColoredJavaElementLabels.DECORATIONS_STYLE); > } > return string; > } >@@ -279,4 +281,5 @@ > } > } > >+ > } >Index: ui/org/eclipse/jdt/internal/ui/viewsupport/IRichLabelProvider.java >=================================================================== >RCS file: ui/org/eclipse/jdt/internal/ui/viewsupport/IRichLabelProvider.java >diff -N ui/org/eclipse/jdt/internal/ui/viewsupport/IRichLabelProvider.java >--- ui/org/eclipse/jdt/internal/ui/viewsupport/IRichLabelProvider.java 14 Mar 2007 14:33:14 -0000 1.1 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,19 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2000, 2007 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 >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * IBM Corporation - initial API and implementation >- *******************************************************************************/ >-package org.eclipse.jdt.internal.ui.viewsupport; >- >-import org.eclipse.jface.viewers.ILabelProvider; >- >-public interface IRichLabelProvider extends ILabelProvider { >- >- ColoredString getRichTextLabel(Object object); >- >-} >Index: ui/org/eclipse/jdt/internal/ui/viewsupport/ColoredJavaElementLabels.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/viewsupport/ColoredJavaElementLabels.java,v >retrieving revision 1.12 >diff -u -r1.12 ColoredJavaElementLabels.java >--- ui/org/eclipse/jdt/internal/ui/viewsupport/ColoredJavaElementLabels.java 14 Feb 2008 14:21:01 -0000 1.12 >+++ ui/org/eclipse/jdt/internal/ui/viewsupport/ColoredJavaElementLabels.java 18 Feb 2008 17:57:15 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2007 IBM Corporation and others. >+ * Copyright (c) 2000, 2008 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 >@@ -15,10 +15,8 @@ > import org.eclipse.core.resources.IProject; > import org.eclipse.core.resources.IResource; > >-import org.eclipse.swt.graphics.TextStyle; >- >-import org.eclipse.jface.resource.ColorRegistry; >-import org.eclipse.jface.resource.JFaceResources; >+import org.eclipse.jface.viewers.StyledString; >+import org.eclipse.jface.viewers.StyledString.Style; > > import org.eclipse.ui.model.IWorkbenchAdapter; > >@@ -54,37 +52,15 @@ > import org.eclipse.jdt.internal.ui.JavaPlugin; > import org.eclipse.jdt.internal.ui.JavaUIMessages; > import org.eclipse.jdt.internal.ui.packageview.ClassPathContainer; >-import org.eclipse.jdt.internal.ui.viewsupport.ColoredString.Style; > > public class ColoredJavaElementLabels { >- >- public static class DefaultStyle extends Style { >- private final String fForegroundColorName; >- private final String fBackgroundColorName; >- >- public DefaultStyle(String foregroundColorName, String backgroundColorName) { >- fForegroundColorName= foregroundColorName; >- fBackgroundColorName= backgroundColorName; >- } >- >- public void applyStyles(TextStyle textStyle) { >- ColorRegistry colorRegistry= JFaceResources.getColorRegistry(); >- if (fForegroundColorName != null) { >- textStyle.foreground= colorRegistry.get(fForegroundColorName); >- } >- if (fBackgroundColorName != null) { >- textStyle.background= colorRegistry.get(fBackgroundColorName); >- } >- } >- } >- > >- public static final Style QUALIFIER_STYLE= new DefaultStyle(ColoredViewersManager.QUALIFIER_COLOR_NAME, null); >- public static final Style COUNTER_STYLE= new DefaultStyle(ColoredViewersManager.COUNTER_COLOR_NAME, null); >- public static final Style DECORATIONS_STYLE= new DefaultStyle(ColoredViewersManager.DECORATIONS_COLOR_NAME, null); >+ public static final Style QUALIFIER_STYLE= StyledString.QUALIFIER_STYLE; >+ public static final Style COUNTER_STYLE= StyledString.COUNTER_STYLE; >+ public static final Style DECORATIONS_STYLE= StyledString.DECORATIONS_STYLE; > >- public static final Style HIGHLIGHT_STYLE= new DefaultStyle(null, ColoredViewersManager.HIGHLIGHT_BG_COLOR_NAME); >- public static final Style HIGHLIGHT_WRITE_STYLE= new DefaultStyle(null, ColoredViewersManager.HIGHLIGHT_WRITE_BG_COLOR_NAME); >+ public static final Style HIGHLIGHT_STYLE= StyledString.createColorRegistryStyle(null, ColoredViewersManager.HIGHLIGHT_BG_COLOR_NAME); >+ public static final Style HIGHLIGHT_WRITE_STYLE= StyledString.createColorRegistryStyle(null, ColoredViewersManager.HIGHLIGHT_WRITE_BG_COLOR_NAME); > > private static final Style APPENDED_TYPE_STYLE= DECORATIONS_STYLE; > >@@ -104,16 +80,16 @@ > * @param flags The rendering flags > * @return Returns the label or the empty string if the object type is not supported. > */ >- public static ColoredString getTextLabel(Object obj, long flags) { >+ public static StyledString getTextLabel(Object obj, long flags) { > if (obj instanceof IJavaElement) { > return getElementLabel((IJavaElement) obj, flags); > } else if (obj instanceof IResource) { >- return new ColoredString(((IResource) obj).getName()); >+ return new StyledString(((IResource) obj).getName()); > } else if (obj instanceof ClassPathContainer) { > ClassPathContainer container= (ClassPathContainer) obj; > return getContainerEntryLabel(container.getClasspathEntry().getPath(), container.getJavaProject()); > } >- return new ColoredString(JavaElementLabels.getTextLabel(obj, flags)); >+ return new StyledString(JavaElementLabels.getTextLabel(obj, flags)); > } > > /** >@@ -122,8 +98,8 @@ > * @param flags The rendering flags. > * @return the label of the Java element > */ >- public static ColoredString getElementLabel(IJavaElement element, long flags) { >- ColoredString result= new ColoredString(); >+ public static StyledString getElementLabel(IJavaElement element, long flags) { >+ StyledString result= new StyledString(); > getElementLabel(element, flags, result); > return result; > } >@@ -134,7 +110,7 @@ > * @param flags The rendering flags. > * @param result The buffer to append the resulting label to. > */ >- public static void getElementLabel(IJavaElement element, long flags, ColoredString result) { >+ public static void getElementLabel(IJavaElement element, long flags, StyledString result) { > int type= element.getElementType(); > IPackageFragmentRoot root= null; > >@@ -199,12 +175,12 @@ > } > > /** >- * Appends the label for a method to a {@link ColoredString}. Considers the M_* flags. >+ * Appends the label for a method to a {@link StyledString}. Considers the M_* flags. > * @param method The element to render. > * @param flags The rendering flags. Flags with names starting with 'M_' are considered. > * @param result The buffer to append the resulting label to. > */ >- public static void getMethodLabel(IMethod method, long flags, ColoredString result) { >+ public static void getMethodLabel(IMethod method, long flags, StyledString result) { > try { > BindingKey resolvedKey= getFlag(flags, JavaElementLabels.USE_RESOLVED) && method.isResolved() ? new BindingKey(method.getKey()) : null; > String resolvedSig= (resolvedKey != null) ? resolvedKey.toSignature() : null; >@@ -392,11 +368,11 @@ > } > } > >- private static void getCategoryLabel(IMember member, long flags, ColoredString result) throws JavaModelException { >+ private static void getCategoryLabel(IMember member, long flags, StyledString result) throws JavaModelException { > String[] categories= member.getCategories(); > if (categories.length > 0) { > int offset= result.length(); >- ColoredString categoriesBuf= new ColoredString(); >+ StyledString categoriesBuf= new StyledString(); > for (int i= 0; i < categories.length; i++) { > if (i > 0) > categoriesBuf.append(JavaUIMessages.JavaElementLabels_category_separator_string); >@@ -416,7 +392,7 @@ > * @param flags flags with render options > * @param result the resulting string buffer > */ >- private static void getTypeParametersLabel(ITypeParameter[] typeParameters, long flags, ColoredString result) { >+ private static void getTypeParametersLabel(ITypeParameter[] typeParameters, long flags, StyledString result) { > if (typeParameters.length > 0) { > result.append('<'); > for (int i = 0; i < typeParameters.length; i++) { >@@ -430,12 +406,12 @@ > } > > /** >- * Appends the label for a field to a {@link ColoredString}. Considers the F_* flags. >+ * Appends the label for a field to a {@link StyledString}. Considers the F_* flags. > * @param field The element to render. > * @param flags The rendering flags. Flags with names starting with 'F_' are considered. > * @param result The buffer to append the resulting label to. > */ >- public static void getFieldLabel(IField field, long flags, ColoredString result) { >+ public static void getFieldLabel(IField field, long flags, StyledString result) { > try { > > if (getFlag(flags, JavaElementLabels.F_PRE_TYPE_SIGNATURE) && field.exists() && !Flags.isEnum(field.getFlags())) { >@@ -487,12 +463,12 @@ > } > > /** >- * Appends the label for a local variable to a {@link ColoredString}. >+ * Appends the label for a local variable to a {@link StyledString}. > * @param localVariable The element to render. > * @param flags The rendering flags. Flags with names starting with 'F_' are considered. > * @param result The buffer to append the resulting label to. > */ >- public static void getLocalVariableLabel(ILocalVariable localVariable, long flags, ColoredString result) { >+ public static void getLocalVariableLabel(ILocalVariable localVariable, long flags, StyledString result) { > if (getFlag(flags, JavaElementLabels.F_PRE_TYPE_SIGNATURE)) { > getTypeSignatureLabel(localVariable.getTypeSignature(), flags, result); > result.append(' '); >@@ -522,12 +498,12 @@ > } > > /** >- * Appends the label for a initializer to a {@link ColoredString}. Considers the I_* flags. >+ * Appends the label for a initializer to a {@link StyledString}. Considers the I_* flags. > * @param initializer The element to render. > * @param flags The rendering flags. Flags with names starting with 'I_' are considered. > * @param result The buffer to append the resulting label to. > */ >- public static void getInitializerLabel(IInitializer initializer, long flags, ColoredString result) { >+ public static void getInitializerLabel(IInitializer initializer, long flags, StyledString result) { > // qualification > if (getFlag(flags, JavaElementLabels.I_FULLY_QUALIFIED)) { > getTypeLabel(initializer.getDeclaringType(), JavaElementLabels.T_FULLY_QUALIFIED | (flags & QUALIFIER_FLAGS), result); >@@ -546,7 +522,7 @@ > } > } > >- private static void getTypeSignatureLabel(String typeSig, long flags, ColoredString result) { >+ private static void getTypeSignatureLabel(String typeSig, long flags, StyledString result) { > int sigKind= Signature.getTypeSignatureKind(typeSig); > switch (sigKind) { > case Signature.BASE_TYPE_SIGNATURE: >@@ -590,7 +566,7 @@ > } > } > >- private static void getTypeArgumentSignaturesLabel(String[] typeArgsSig, long flags, ColoredString result) { >+ private static void getTypeArgumentSignaturesLabel(String[] typeArgsSig, long flags, StyledString result) { > if (typeArgsSig.length > 0) { > result.append('<'); > for (int i = 0; i < typeArgsSig.length; i++) { >@@ -609,7 +585,7 @@ > * @param flags flags with render options > * @param result the resulting string buffer > */ >- private static void getTypeParameterSignaturesLabel(String[] typeParamSigs, long flags, ColoredString result) { >+ private static void getTypeParameterSignaturesLabel(String[] typeParamSigs, long flags, StyledString result) { > if (typeParamSigs.length > 0) { > result.append('<'); > for (int i = 0; i < typeParamSigs.length; i++) { >@@ -624,12 +600,12 @@ > > > /** >- * Appends the label for a type to a {@link ColoredString}. Considers the T_* flags. >+ * Appends the label for a type to a {@link StyledString}. Considers the T_* flags. > * @param type The element to render. > * @param flags The rendering flags. Flags with names starting with 'T_' are considered. > * @param result The buffer to append the resulting label to. > */ >- public static void getTypeLabel(IType type, long flags, ColoredString result) { >+ public static void getTypeLabel(IType type, long flags, StyledString result) { > > if (getFlag(flags, JavaElementLabels.T_FULLY_QUALIFIED)) { > IPackageFragment pack= type.getPackageFragment(); >@@ -722,12 +698,12 @@ > } > > /** >- * Appends the label for a import container, import or package declaration to a {@link ColoredString}. Considers the D_* flags. >+ * Appends the label for a import container, import or package declaration to a {@link StyledString}. Considers the D_* flags. > * @param declaration The element to render. > * @param flags The rendering flags. Flags with names starting with 'D_' are considered. > * @param result The buffer to append the resulting label to. > */ >- public static void getDeclarationLabel(IJavaElement declaration, long flags, ColoredString result) { >+ public static void getDeclarationLabel(IJavaElement declaration, long flags, StyledString result) { > if (getFlag(flags, JavaElementLabels.D_QUALIFIED)) { > IJavaElement openable= (IJavaElement) declaration.getOpenable(); > if (openable != null) { >@@ -755,12 +731,12 @@ > } > > /** >- * Appends the label for a class file to a {@link ColoredString}. Considers the CF_* flags. >+ * Appends the label for a class file to a {@link StyledString}. Considers the CF_* flags. > * @param classFile The element to render. > * @param flags The rendering flags. Flags with names starting with 'CF_' are considered. > * @param result The buffer to append the resulting label to. > */ >- public static void getClassFileLabel(IClassFile classFile, long flags, ColoredString result) { >+ public static void getClassFileLabel(IClassFile classFile, long flags, StyledString result) { > if (getFlag(flags, JavaElementLabels.CF_QUALIFIED)) { > IPackageFragment pack= (IPackageFragment) classFile.getParent(); > if (!pack.isDefaultPackage()) { >@@ -781,12 +757,12 @@ > } > > /** >- * Appends the label for a compilation unit to a {@link ColoredString}. Considers the CU_* flags. >+ * Appends the label for a compilation unit to a {@link StyledString}. Considers the CU_* flags. > * @param cu The element to render. > * @param flags The rendering flags. Flags with names starting with 'CU_' are considered. > * @param result The buffer to append the resulting label to. > */ >- public static void getCompilationUnitLabel(ICompilationUnit cu, long flags, ColoredString result) { >+ public static void getCompilationUnitLabel(ICompilationUnit cu, long flags, StyledString result) { > if (getFlag(flags, JavaElementLabels.CU_QUALIFIED)) { > IPackageFragment pack= (IPackageFragment) cu.getParent(); > if (!pack.isDefaultPackage()) { >@@ -807,12 +783,12 @@ > } > > /** >- * Appends the label for a package fragment to a {@link ColoredString}. Considers the P_* flags. >+ * Appends the label for a package fragment to a {@link StyledString}. Considers the P_* flags. > * @param pack The element to render. > * @param flags The rendering flags. Flags with names starting with P_' are considered. > * @param result The buffer to append the resulting label to. > */ >- public static void getPackageFragmentLabel(IPackageFragment pack, long flags, ColoredString result) { >+ public static void getPackageFragmentLabel(IPackageFragment pack, long flags, StyledString result) { > if (getFlag(flags, JavaElementLabels.P_QUALIFIED)) { > getPackageFragmentRootLabel((IPackageFragmentRoot) pack.getParent(), JavaElementLabels.ROOT_QUALIFIED, result); > result.append('/'); >@@ -837,19 +813,19 @@ > } > > /** >- * Appends the label for a package fragment root to a {@link ColoredString}. Considers the ROOT_* flags. >+ * Appends the label for a package fragment root to a {@link StyledString}. Considers the ROOT_* flags. > * @param root The element to render. > * @param flags The rendering flags. Flags with names starting with ROOT_' are considered. > * @param result The buffer to append the resulting label to. > */ >- public static void getPackageFragmentRootLabel(IPackageFragmentRoot root, long flags, ColoredString result) { >+ public static void getPackageFragmentRootLabel(IPackageFragmentRoot root, long flags, StyledString result) { > if (root.isArchive()) > getArchiveLabel(root, flags, result); > else > getFolderLabel(root, flags, result); > } > >- private static void getArchiveLabel(IPackageFragmentRoot root, long flags, ColoredString result) { >+ private static void getArchiveLabel(IPackageFragmentRoot root, long flags, StyledString result) { > // Handle variables different > if (getFlag(flags, JavaElementLabels.ROOT_VARIABLE) && getVariableLabel(root, flags, result)) > return; >@@ -860,7 +836,7 @@ > getInternalArchiveLabel(root, flags, result); > } > >- private static boolean getVariableLabel(IPackageFragmentRoot root, long flags, ColoredString result) { >+ private static boolean getVariableLabel(IPackageFragmentRoot root, long flags, StyledString result) { > try { > IClasspathEntry rawEntry= root.getRawClasspathEntry(); > if (rawEntry != null && rawEntry.getEntryKind() == IClasspathEntry.CPE_VARIABLE) { >@@ -898,7 +874,7 @@ > return false; > } > >- private static void getExternalArchiveLabel(IPackageFragmentRoot root, long flags, ColoredString result) { >+ private static void getExternalArchiveLabel(IPackageFragmentRoot root, long flags, StyledString result) { > IPath path= root.getPath(); > if (getFlag(flags, JavaElementLabels.REFERENCED_ROOT_POST_QUALIFIED)) { > int segements= path.segmentCount(); >@@ -920,7 +896,7 @@ > } > } > >- private static void getInternalArchiveLabel(IPackageFragmentRoot root, long flags, ColoredString result) { >+ private static void getInternalArchiveLabel(IPackageFragmentRoot root, long flags, StyledString result) { > IResource resource= root.getResource(); > boolean rootQualified= getFlag(flags, JavaElementLabels.ROOT_QUALIFIED); > boolean referencedQualified= getFlag(flags, JavaElementLabels.REFERENCED_ROOT_POST_QUALIFIED) && isReferenced(root); >@@ -944,7 +920,7 @@ > } > } > >- private static void getFolderLabel(IPackageFragmentRoot root, long flags, ColoredString result) { >+ private static void getFolderLabel(IPackageFragmentRoot root, long flags, StyledString result) { > IResource resource= root.getResource(); > boolean rootQualified= getFlag(flags, JavaElementLabels.ROOT_QUALIFIED); > boolean referencedQualified= getFlag(flags, JavaElementLabels.REFERENCED_ROOT_POST_QUALIFIED) && isReferenced(root); >@@ -1000,7 +976,7 @@ > * @param project The project the container is resolved in. > * @return Returns the label of the classpath container > */ >- public static ColoredString getContainerEntryLabel(IPath containerPath, IJavaProject project) { >+ public static StyledString getContainerEntryLabel(IPath containerPath, IJavaProject project) { > try { > IClasspathContainer container= JavaCore.getClasspathContainer(containerPath, project); > String description= null; >@@ -1014,7 +990,7 @@ > } > } > if (description != null) { >- ColoredString str= new ColoredString(description); >+ StyledString str= new StyledString(description); > if (containerPath.segmentCount() > 0 && JavaRuntime.JRE_CONTAINER.equals(containerPath.segment(0))) { > int index= description.indexOf('['); > if (index != -1) { >@@ -1026,17 +1002,17 @@ > } catch (JavaModelException e) { > // ignore > } >- return new ColoredString(containerPath.toString()); >+ return new StyledString(containerPath.toString()); > } > >- public static ColoredString decorateColoredString(ColoredString string, String decorated, Style color) { >+ public static StyledString decorateStyledString(StyledString string, String decorated, Style color) { > String label= string.getString(); > int originalStart= decorated.indexOf(label); > if (originalStart == -1) { >- return new ColoredString(decorated); // the decorator did something wild >+ return new StyledString(decorated); // the decorator did something wild > } > if (originalStart > 0) { >- ColoredString newString= new ColoredString(decorated.substring(0, originalStart), color); >+ StyledString newString= new StyledString(decorated.substring(0, originalStart), color); > newString.append(string); > string= newString; > } >Index: ui/org/eclipse/jdt/internal/ui/viewsupport/DecoratingJavaLabelProvider.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/viewsupport/DecoratingJavaLabelProvider.java,v >retrieving revision 1.16 >diff -u -r1.16 DecoratingJavaLabelProvider.java >--- ui/org/eclipse/jdt/internal/ui/viewsupport/DecoratingJavaLabelProvider.java 16 Nov 2007 09:17:24 -0000 1.16 >+++ ui/org/eclipse/jdt/internal/ui/viewsupport/DecoratingJavaLabelProvider.java 18 Feb 2008 17:57:15 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2007 IBM Corporation and others. >+ * Copyright (c) 2000, 2008 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 >@@ -15,6 +15,8 @@ > import org.eclipse.jface.viewers.ILabelDecorator; > import org.eclipse.jface.viewers.ILabelProvider; > import org.eclipse.jface.viewers.LabelDecorator; >+import org.eclipse.jface.viewers.StyledString; >+import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider; > > import org.eclipse.ui.PlatformUI; > >@@ -22,7 +24,7 @@ > > import org.eclipse.jdt.internal.ui.packageview.HierarchicalDecorationContext; > >-public class DecoratingJavaLabelProvider extends DecoratingLabelProvider implements IRichLabelProvider { >+public class DecoratingJavaLabelProvider extends DecoratingLabelProvider implements IStyledLabelProvider { > > /** > * Decorating label provider for Java. Combines a JavaUILabelProvider >@@ -74,31 +76,27 @@ > } > > /* (non-Javadoc) >- * @see org.eclipse.jdt.internal.ui.viewsupport.IRichLabelProvider#getRichTextLabel(Object) >+ * @see org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider#getStyledText(java.lang.Object) > */ >- public ColoredString getRichTextLabel(Object element) { >+ public StyledString getStyledText(Object element) { >+ > ILabelProvider labelProvider= getLabelProvider(); >- if (labelProvider instanceof IRichLabelProvider) { >- // get a rich label from the label decorator >- IRichLabelProvider richLabelProvider= (IRichLabelProvider) labelProvider; >- ColoredString richLabel= richLabelProvider.getRichTextLabel(element); >- if (richLabel != null) { >- String decorated= null; >- ILabelDecorator labelDecorator= getLabelDecorator(); >- if (labelDecorator != null) { >- if (labelDecorator instanceof LabelDecorator) { >- decorated= ((LabelDecorator) labelDecorator).decorateText(richLabel.getString(), element, getDecorationContext()); >- } else { >- decorated= labelDecorator.decorateText(richLabel.getString(), element); >- } >+ if (labelProvider instanceof IStyledLabelProvider) { >+ StyledString styledString= ((IStyledLabelProvider) labelProvider).getStyledText(element); >+ >+ String decorated= null; >+ ILabelDecorator labelDecorator= getLabelDecorator(); >+ if (labelDecorator != null) { >+ if (labelDecorator instanceof LabelDecorator) { >+ decorated= ((LabelDecorator) labelDecorator).decorateText(styledString.getString(), element, getDecorationContext()); >+ } else { >+ decorated= labelDecorator.decorateText(styledString.getString(), element); > } >- if (decorated != null) { >- return ColoredJavaElementLabels.decorateColoredString(richLabel, decorated, ColoredJavaElementLabels.DECORATIONS_STYLE); >- } >- return richLabel; >+ } >+ if (decorated != null) { >+ return ColoredJavaElementLabels.decorateStyledString(styledString, decorated, ColoredJavaElementLabels.DECORATIONS_STYLE); > } > } >- return null; >+ return new StyledString(getText(element)); > } >- > } >Index: ui/org/eclipse/jdt/internal/ui/viewsupport/ColoringLabelProvider.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/viewsupport/ColoringLabelProvider.java,v >retrieving revision 1.3 >diff -u -r1.3 ColoringLabelProvider.java >--- ui/org/eclipse/jdt/internal/ui/viewsupport/ColoringLabelProvider.java 14 Feb 2008 17:19:25 -0000 1.3 >+++ ui/org/eclipse/jdt/internal/ui/viewsupport/ColoringLabelProvider.java 18 Feb 2008 17:57:15 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2007 IBM Corporation and others. >+ * Copyright (c) 2000, 2008 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 >@@ -10,29 +10,17 @@ > *******************************************************************************/ > package org.eclipse.jdt.internal.ui.viewsupport; > >-import org.eclipse.swt.custom.StyleRange; >-import org.eclipse.swt.graphics.Color; >-import org.eclipse.swt.graphics.Font; > import org.eclipse.swt.graphics.Image; > >-import org.eclipse.jface.resource.ColorRegistry; >-import org.eclipse.jface.resource.JFaceResources; > import org.eclipse.jface.viewers.ColumnViewer; >-import org.eclipse.jface.viewers.IColorProvider; >-import org.eclipse.jface.viewers.IFontProvider; >+import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider; > import org.eclipse.jface.viewers.ILabelProvider; >-import org.eclipse.jface.viewers.ILabelProviderListener; >-import org.eclipse.jface.viewers.SimpleStyledCellLabelProvider; > import org.eclipse.jface.viewers.ViewerColumn; > >-public class ColoringLabelProvider extends SimpleStyledCellLabelProvider implements ILabelProvider { >- >- private ILabelProvider fLabelProvider; >- private ColorRegistry fRegistry; >- >- public ColoringLabelProvider(ILabelProvider labelProvider) { >- fLabelProvider= labelProvider; >- fRegistry= JFaceResources.getColorRegistry(); >+public class ColoringLabelProvider extends DelegatingStyledCellLabelProvider implements ILabelProvider { >+ >+ public ColoringLabelProvider(IStyledLabelProvider labelProvider) { >+ super(labelProvider); > } > > public void initialize(ColumnViewer viewer, ViewerColumn column) { >@@ -41,17 +29,7 @@ > > super.initialize(viewer, column); > } >- >- public void addListener(ILabelProviderListener listener) { >- super.addListener(listener); >- fLabelProvider.addListener(listener); >- } >- >- public void removeListener(ILabelProviderListener listener) { >- super.removeListener(listener); >- fLabelProvider.removeListener(listener); >- } >- >+ > public void dispose() { > super.dispose(); > ColoredViewersManager.uninstall(this); >@@ -72,53 +50,12 @@ > } > } > >- protected LabelPresentationInfo getLabelPresentationInfo(Object element) { >- Image image= fLabelProvider.getImage(element); >- Font defaultFont= null; >- >- if (fLabelProvider instanceof IFontProvider) { >- IFontProvider fontProvider= (IFontProvider) fLabelProvider; >- defaultFont= fontProvider.getFont(element); >- } >- Color foreground= null; >- Color background= null; >- if (fLabelProvider instanceof IColorProvider) { >- IColorProvider colorProvider= (IColorProvider) fLabelProvider; >- foreground= colorProvider.getForeground(element); >- background= colorProvider.getBackground(element); >- } >- String text; >- StyleRange[] ranges; >- ColoredString label= getRichTextLabel(element); >- if (label != null) { >- text= label.getString(); >- ranges= label.getStyleRanges(); >- } else { >- text= fLabelProvider.getText(element); >- ranges= new StyleRange[0]; >- } >- return new LabelPresentationInfo(text, ranges, image, defaultFont, foreground, background); >- } >- >- >- private ColoredString getRichTextLabel(Object element) { >- if (fLabelProvider instanceof IRichLabelProvider) { >- // get a rich label >- IRichLabelProvider richLabelProvider= (IRichLabelProvider) fLabelProvider; >- ColoredString richLabel= richLabelProvider.getRichTextLabel(element); >- if (richLabel != null) { >- return richLabel; >- } >- } >- return null; >- } >- > public Image getImage(Object element) { >- return fLabelProvider.getImage(element); >+ return getStyledStringProvider().getImage(element); > } > > public String getText(Object element) { >- return fLabelProvider.getText(element); >+ return getStyledStringProvider().getStyledText(element).getString(); > } > > } >Index: ui/org/eclipse/jdt/internal/ui/viewsupport/ColoredViewersManager.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/viewsupport/ColoredViewersManager.java,v >retrieving revision 1.9 >diff -u -r1.9 ColoredViewersManager.java >--- ui/org/eclipse/jdt/internal/ui/viewsupport/ColoredViewersManager.java 7 Feb 2008 18:08:43 -0000 1.9 >+++ ui/org/eclipse/jdt/internal/ui/viewsupport/ColoredViewersManager.java 18 Feb 2008 17:57:15 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2007 IBM Corporation and others. >+ * Copyright (c) 2000, 2008 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 >@@ -16,7 +16,7 @@ > > import org.eclipse.swt.widgets.Display; > >-import org.eclipse.jface.resource.ColorRegistry; >+import org.eclipse.jface.preference.JFacePreferences; > import org.eclipse.jface.resource.JFaceResources; > import org.eclipse.jface.util.IPropertyChangeListener; > import org.eclipse.jface.util.PropertyChangeEvent; >@@ -31,9 +31,10 @@ > */ > public static final String PREF_COLORED_LABELS= "colored_labels_in_views"; //$NON-NLS-1$ > >- public static final String QUALIFIER_COLOR_NAME= "org.eclipse.jdt.ui.ColoredLabels.qualifier"; //$NON-NLS-1$ >- public static final String DECORATIONS_COLOR_NAME= "org.eclipse.jdt.ui.ColoredLabels.decorations"; //$NON-NLS-1$ >- public static final String COUNTER_COLOR_NAME= "org.eclipse.jdt.ui.ColoredLabels.counter"; //$NON-NLS-1$ >+ public static final String QUALIFIER_COLOR_NAME= JFacePreferences.QUALIFIER_COLOR; >+ public static final String DECORATIONS_COLOR_NAME= JFacePreferences.DECORATIONS_COLOR; >+ public static final String COUNTER_COLOR_NAME= JFacePreferences.COUNTER_COLOR; >+ > public static final String INHERITED_COLOR_NAME= "org.eclipse.jdt.ui.ColoredLabels.inherited"; //$NON-NLS-1$ > > public static final String HIGHLIGHT_BG_COLOR_NAME= "org.eclipse.jdt.ui.ColoredLabels.match_highlight"; //$NON-NLS-1$ >@@ -42,12 +43,9 @@ > private static ColoredViewersManager fgInstance= new ColoredViewersManager(); > > private Set fManagedLabelProviders; >- >- private ColorRegistry fColorRegisty; >- >+ > public ColoredViewersManager() { > fManagedLabelProviders= new HashSet(); >- fColorRegisty= JFaceResources.getColorRegistry(); > } > > public void installColoredLabels(ColoringLabelProvider labelProvider) { >@@ -57,7 +55,7 @@ > if (fManagedLabelProviders.isEmpty()) { > // first lp installed > PreferenceConstants.getPreferenceStore().addPropertyChangeListener(this); >- fColorRegisty.addListener(this); >+ JFaceResources.getColorRegistry().addListener(this); > } > fManagedLabelProviders.add(labelProvider); > } >@@ -68,7 +66,7 @@ > > if (fManagedLabelProviders.isEmpty()) { > PreferenceConstants.getPreferenceStore().removePropertyChangeListener(this); >- fColorRegisty.removeListener(this); >+ JFaceResources.getColorRegistry().removeListener(this); > // last viewer uninstalled > } > } >Index: ui/org/eclipse/jdt/internal/ui/viewsupport/ColoredString.java >=================================================================== >RCS file: ui/org/eclipse/jdt/internal/ui/viewsupport/ColoredString.java >diff -N ui/org/eclipse/jdt/internal/ui/viewsupport/ColoredString.java >--- ui/org/eclipse/jdt/internal/ui/viewsupport/ColoredString.java 14 Feb 2008 14:25:41 -0000 1.10 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,369 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2000, 2008 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 >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * IBM Corporation - initial API and implementation >- *******************************************************************************/ >-package org.eclipse.jdt.internal.ui.viewsupport; >- >-import java.util.ArrayList; >-import java.util.List; >- >-import org.eclipse.swt.custom.StyleRange; >-import org.eclipse.swt.graphics.TextStyle; >- >-/** >- * Represents a string with styled ranges. All ranges mark substrings of the string and do not overlap. >- * Styles are represented by {@link Style}. >- * >- * The styled string can be modified: >- * <ul> >- * <li>new strings with styles can be appended</li> >- * <li>styles can by applied to to the existing string</li> >- * </ul> >- * >- * <p> >- * This class may be instantiated; it is not intended to be subclassed. >- * </p> >- * >- */ >-public class ColoredString { >- >- /** >- * Represents a style that can be associated to one ore more ranges in the {@link ColoredString} >- * >- */ >- public static abstract class Style { >- >- /** >- * Applies the styles represented by this object to the given textStyle. >- * >- * @param textStyle the {@link TextStyle} to modify >- */ >- public abstract void applyStyles(TextStyle textStyle); >- } >- >- private static final StyleRange[] EMPTY= new StyleRange[0]; >- >- private StringBuffer fBuffer; >- private StyleRunList fStyleRuns; >- >- /** >- * Creates an empty {@link ColoredString}. >- */ >- public ColoredString() { >- fBuffer= new StringBuffer(); >- fStyleRuns= null; >- } >- >- /** >- * Creates an {@link ColoredString} initialized with a string without a style associated. >- * >- * @param string the string >- */ >- public ColoredString(String string) { >- this(string, null); >- } >- >- /** >- * Creates an {@link ColoredString} initialized with a string and a style. >- * >- * @param string the string >- * @param style the style of the text or <code>null</code> to not associated a style. >- */ >- public ColoredString(String string, Style style) { >- this(); >- append(string, style); >- } >- >- /** >- * Returns the string of this {@link ColoredString}. >- * >- * @return the current string of this {@link ColoredString}. >- */ >- public String getString() { >- return fBuffer.toString(); >- } >- >- /** >- * Returns the length of the string of this {@link ColoredString}. >- * >- * @return the length of the current string >- */ >- public int length() { >- return fBuffer.length(); >- } >- >- /** >- * Appends a string to the {@link ColoredString}. The appended string will have no style associated. >- * >- * @param string the string to append. >- * @return returns a reference to this object. >- */ >- public ColoredString append(String string) { >- return append(string, null); >- } >- >- /** >- * Appends a character to the {@link ColoredString}. The appended character will have no style associated. >- * >- * @param ch the character to append. >- * @return returns a reference to this object. >- */ >- public ColoredString append(char ch) { >- return append(String.valueOf(ch), null); >- } >- >- /** >- * Appends a string with styles to the {@link ColoredString}. >- * >- * @param string the string to append. >- * @return returns a reference to this object. >- */ >- public ColoredString append(ColoredString string) { >- if (string.length() == 0) { >- return this; >- } >- >- int offset= fBuffer.length(); >- fBuffer.append(string.getString()); >- >- List otherRuns= string.fStyleRuns; >- if (otherRuns != null && !otherRuns.isEmpty()) { >- for (int i= 0; i < otherRuns.size(); i++) { >- StyleRun curr= (StyleRun) otherRuns.get(i); >- if (i == 0 && curr.offset != 0) { >- appendStyleRun(null, offset); // appended string will start with the default color >- } >- appendStyleRun(curr.style, offset + curr.offset); >- } >- } else { >- appendStyleRun(null, offset); // appended string will start with the default color >- } >- return this; >- } >- >- /** >- * Appends a character with a style to the {@link ColoredString}. The appended character will >- * have the given style associated. >- * >- * @param ch the character to append. >- * @param style the style to of the character to append or <code>null</code> if no style should be >- * associated to the string. >- * @return returns a reference to this object. >- */ >- public ColoredString append(char ch, Style style) { >- return append(String.valueOf(ch), style); >- } >- >- /** >- * Appends a string with a style to the {@link ColoredString}. The appended string will >- * have the given style associated. >- * >- * @param string the string to append. >- * @param style the style to of the string to append or <code>null</code> if no style should be >- * associated to the string. >- * @return returns a reference to this object. >- */ >- public ColoredString append(String string, Style style) { >- if (string.length() == 0) >- return this; >- >- int offset= fBuffer.length(); // the length before appending >- fBuffer.append(string); >- appendStyleRun(style, offset); >- return this; >- } >- >- /** >- * Sets a style to the given source range. The range must be subrange of actual string of this {@link ColoredString}. >- * Styles previously set for that range will be overwritten. >- * >- * @param offset the start offset of the range >- * @param length the length of the range >- * @param style the style to set >- * >- * @throws StringIndexOutOfBoundsException if <code>start</code> is >- * less than zero, or if offset plus length is greater than the length of this object. >- */ >- public void setStyle(int offset, int length, Style style) { >- if (offset < 0 || offset + length > fBuffer.length()) { >- throw new StringIndexOutOfBoundsException("Invalid offset (" + offset + ") or length (" + length + ")"); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ >- } >- if (length == 0) { >- return; >- } >- if (!hasRuns() || getLastRun().offset <= offset) { >- appendStyleRun(style, offset); >- if (offset + length != fBuffer.length()) { >- appendStyleRun(null, offset + length); >- } >- return; >- } >- >- int endRun= findRun(offset + length); >- if (endRun >= 0) { >- // run with the same end index, nothing to change >- } else { >- endRun= -(endRun + 1); >- if (offset + length < fBuffer.length()) { >- Style prevStyle= endRun > 0 ? fStyleRuns.getRun(endRun - 1).style : null; >- fStyleRuns.add(endRun, new StyleRun(offset + length, prevStyle)); >- } >- } >- >- int startRun= findRun(offset); >- if (startRun >= 0) { >- // run with the same start index >- StyleRun styleRun= fStyleRuns.getRun(startRun); >- styleRun.style= style; >- } else { >- startRun= -(startRun + 1); >- >- Style prevStyle= startRun > 0 ? fStyleRuns.getRun(startRun - 1).style : null; >- if (isDifferentStyle(prevStyle, style) || (startRun == 0 && style != null)) { >- fStyleRuns.add(startRun, new StyleRun(offset, style)); >- endRun++; // endrun is moved one back >- } else { >- startRun--; // we use the previous >- } >- } >- if (startRun + 1 < endRun) { >- fStyleRuns.removeRange(startRun + 1, endRun); >- } >- } >- >- /** >- * Returns {@link StyleRange} for all applied styles to this string >- * >- * @return an array of all {@link StyleRange} applied to this string. >- */ >- public StyleRange[] getStyleRanges() { >- if (hasRuns()) { >- ArrayList res= new ArrayList(); >- >- List styleRuns= getStyleRuns(); >- int offset= 0; >- Style style= null; >- for (int i= 0; i < styleRuns.size(); i++) { >- StyleRun curr= (StyleRun) styleRuns.get(i); >- if (isDifferentStyle(curr.style, style)) { >- if (curr.offset > offset && style != null) { >- res.add(createStyleRange(offset, curr.offset, style)); >- } >- offset= curr.offset; >- style= curr.style; >- } >- } >- if (fBuffer.length() > offset && style != null) { >- res.add(createStyleRange(offset, fBuffer.length(), style)); >- } >- return (StyleRange[]) res.toArray(new StyleRange[res.size()]); >- } >- return EMPTY; >- } >- >- private int findRun(int offset) { >- // method assumes that fStyleRuns is not null >- int low= 0; >- int high= fStyleRuns.size() - 1; >- while (low <= high) { >- int mid = (low + high) / 2; >- StyleRun styleRun= fStyleRuns.getRun(mid); >- if (styleRun.offset < offset) { >- low = mid + 1; >- } else if (styleRun.offset > offset) { >- high = mid - 1; >- } else { >- return mid; // key found >- } >- } >- return -(low + 1); // key not found. >- } >- >- private StyleRange createStyleRange(int start, int end, Style style) { >- StyleRange styleRange= new StyleRange(); >- styleRange.start= start; >- styleRange.length= end - start; >- style.applyStyles(styleRange); >- return styleRange; >- } >- >- >- /* (non-Javadoc) >- * @see java.lang.Object#toString() >- */ >- public String toString() { >- return fBuffer.toString(); >- } >- >- private boolean hasRuns() { >- return fStyleRuns != null && !fStyleRuns.isEmpty(); >- } >- >- private void appendStyleRun(Style style, int offset) { >- StyleRun lastRun= getLastRun(); >- if (lastRun != null && lastRun.offset == offset) { >- lastRun.style= style; >- return; >- } >- >- if (lastRun == null && style != null || lastRun != null && isDifferentStyle(style, lastRun.style)) { >- getStyleRuns().add(new StyleRun(offset, style)); >- } >- } >- >- private boolean isDifferentStyle(Style style1, Style style2) { >- if (style1 == null) { >- return style2 != null; >- } >- return !style1.equals(style2); >- } >- >- private StyleRun getLastRun() { >- if (fStyleRuns == null || fStyleRuns.isEmpty()) { >- return null; >- } >- return fStyleRuns.getRun(fStyleRuns.size() - 1); >- } >- >- private List getStyleRuns() { >- if (fStyleRuns == null) >- fStyleRuns= new StyleRunList(); >- return fStyleRuns; >- } >- >- private static class StyleRun { >- public int offset; >- public Style style; >- >- public StyleRun(int offset, Style style) { >- this.offset= offset; >- this.style= style; >- } >- >- public String toString() { >- return "Offset " + offset + ", style: " + style.toString(); //$NON-NLS-1$//$NON-NLS-2$ >- } >- } >- >- private static class StyleRunList extends ArrayList { >- private static final long serialVersionUID= 123L; >- >- public StyleRunList() { >- super(3); >- } >- >- public StyleRun getRun(int index) { >- return (StyleRun) get(index); >- } >- >- public void removeRange(int fromIndex, int toIndex) { >- super.removeRange(fromIndex, toIndex); >- } >- } >-} >Index: ui/org/eclipse/jdt/internal/ui/typehierarchy/MethodsLabelProvider.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/typehierarchy/MethodsLabelProvider.java,v >retrieving revision 1.12 >diff -u -r1.12 MethodsLabelProvider.java >--- ui/org/eclipse/jdt/internal/ui/typehierarchy/MethodsLabelProvider.java 15 May 2007 14:58:15 -0000 1.12 >+++ ui/org/eclipse/jdt/internal/ui/typehierarchy/MethodsLabelProvider.java 18 Feb 2008 17:57:15 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2007 IBM Corporation and others. >+ * Copyright (c) 2000, 2008 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 >@@ -16,6 +16,7 @@ > import org.eclipse.jface.util.IPropertyChangeListener; > import org.eclipse.jface.util.PropertyChangeEvent; > import org.eclipse.jface.viewers.LabelProviderChangedEvent; >+import org.eclipse.jface.viewers.StyledString; > > import org.eclipse.jdt.core.IJavaElement; > import org.eclipse.jdt.core.IMember; >@@ -29,7 +30,6 @@ > import org.eclipse.jdt.ui.JavaElementLabels; > > import org.eclipse.jdt.internal.ui.viewsupport.AppearanceAwareLabelProvider; >-import org.eclipse.jdt.internal.ui.viewsupport.ColoredString; > import org.eclipse.jdt.internal.ui.viewsupport.ColoredViewersManager; > > /** >@@ -102,13 +102,15 @@ > } > > /* (non-Javadoc) >- * @see org.eclipse.jdt.internal.ui.viewsupport.JavaUILabelProvider#getRichTextLabel(java.lang.Object) >+ * @see org.eclipse.jdt.internal.ui.viewsupport.JavaUILabelProvider#getStyledText(java.lang.Object) > */ >- public ColoredString getRichTextLabel(Object element) { >- ColoredString text= super.getRichTextLabel(element); >+ public StyledString getStyledText(Object element) { >+ StyledString text= super.getStyledText(element); > String qualifier= getQualifier(element); > if (qualifier != null) { >- return new ColoredString(qualifier).append(text); >+ StyledString StyledString= new StyledString(qualifier); >+ StyledString.append(text); >+ return StyledString; > } > return text; > >Index: ui/org/eclipse/jdt/internal/ui/callhierarchy/CallHierarchyLabelProvider.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/callhierarchy/CallHierarchyLabelProvider.java,v >retrieving revision 1.15 >diff -u -r1.15 CallHierarchyLabelProvider.java >--- ui/org/eclipse/jdt/internal/ui/callhierarchy/CallHierarchyLabelProvider.java 29 May 2007 18:41:42 -0000 1.15 >+++ ui/org/eclipse/jdt/internal/ui/callhierarchy/CallHierarchyLabelProvider.java 18 Feb 2008 17:57:15 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2007 IBM Corporation and others. >+ * Copyright (c) 2000, 2008 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 >@@ -16,6 +16,7 @@ > import org.eclipse.swt.graphics.Image; > > import org.eclipse.jface.viewers.ILabelDecorator; >+import org.eclipse.jface.viewers.StyledString; > > import org.eclipse.ui.model.IWorkbenchAdapter; > >@@ -26,7 +27,6 @@ > > import org.eclipse.jdt.internal.ui.viewsupport.AppearanceAwareLabelProvider; > import org.eclipse.jdt.internal.ui.viewsupport.ColoredJavaElementLabels; >-import org.eclipse.jdt.internal.ui.viewsupport.ColoredString; > import org.eclipse.jdt.internal.ui.viewsupport.JavaElementImageProvider; > > class CallHierarchyLabelProvider extends AppearanceAwareLabelProvider { >@@ -70,16 +70,16 @@ > } > > /* (non-Javadoc) >- * @see org.eclipse.jdt.internal.ui.viewsupport.JavaUILabelProvider#getRichTextLabel(java.lang.Object) >+ * @see org.eclipse.jdt.internal.ui.viewsupport.JavaUILabelProvider#getStyledText(java.lang.Object) > */ >- public ColoredString getRichTextLabel(Object element) { >+ public StyledString getStyledText(Object element) { > if (element instanceof MethodWrapper && ((MethodWrapper) element).getMember() != null) { > MethodWrapper wrapper= (MethodWrapper) element; > String decorated= getElementLabel(wrapper); >- ColoredString text= super.getRichTextLabel(wrapper.getMember()); >- return ColoredJavaElementLabels.decorateColoredString(text, decorated, ColoredJavaElementLabels.COUNTER_STYLE); >+ StyledString text= super.getStyledText(wrapper.getMember()); >+ return ColoredJavaElementLabels.decorateStyledString(text, decorated, ColoredJavaElementLabels.COUNTER_STYLE); > } >- return new ColoredString(getSpecialLabel(element)); >+ return new StyledString(getSpecialLabel(element)); > } > > private String getSpecialLabel(Object element) { >Index: ui/org/eclipse/jdt/internal/ui/javaeditor/breadcrumb/BreadcrumbItemDropDown.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/breadcrumb/BreadcrumbItemDropDown.java,v >retrieving revision 1.12 >diff -u -r1.12 BreadcrumbItemDropDown.java >--- ui/org/eclipse/jdt/internal/ui/javaeditor/breadcrumb/BreadcrumbItemDropDown.java 15 Feb 2008 10:48:38 -0000 1.12 >+++ ui/org/eclipse/jdt/internal/ui/javaeditor/breadcrumb/BreadcrumbItemDropDown.java 18 Feb 2008 17:57:15 -0000 >@@ -49,7 +49,6 @@ > import org.eclipse.jdt.internal.ui.JavaPluginImages; > import org.eclipse.jdt.internal.ui.javaeditor.breadcrumb.FilteredTable.Direction; > import org.eclipse.jdt.internal.ui.javaeditor.breadcrumb.FilteredTable.INavigateListener; >-import org.eclipse.jdt.internal.ui.viewsupport.ColoringLabelProvider; > > > /** >@@ -234,7 +233,7 @@ > return false; > } > }); >- viewer.setLabelProvider(new ColoringLabelProvider(fLabelProvider)); >+ viewer.setLabelProvider(fLabelProvider); > viewer.setComparator(new JavaElementComparator()); > viewer.setInput(fParent.getInput()); > >Index: ui/org/eclipse/jdt/internal/ui/dialogs/FilteredTypesSelectionDialog.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/dialogs/FilteredTypesSelectionDialog.java,v >retrieving revision 1.34 >diff -u -r1.34 FilteredTypesSelectionDialog.java >--- ui/org/eclipse/jdt/internal/ui/dialogs/FilteredTypesSelectionDialog.java 14 Feb 2008 14:21:01 -0000 1.34 >+++ ui/org/eclipse/jdt/internal/ui/dialogs/FilteredTypesSelectionDialog.java 18 Feb 2008 17:57:15 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2007 IBM Corporation and others. >+ * Copyright (c) 2000, 2008 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 >@@ -32,15 +32,11 @@ > > import org.eclipse.swt.events.DisposeEvent; > import org.eclipse.swt.events.DisposeListener; >-import org.eclipse.swt.graphics.Color; > import org.eclipse.swt.graphics.Image; > import org.eclipse.swt.layout.GridData; > import org.eclipse.swt.widgets.Composite; > import org.eclipse.swt.widgets.Control; >-import org.eclipse.swt.widgets.Display; >-import org.eclipse.swt.widgets.Item; > import org.eclipse.swt.widgets.Shell; >-import org.eclipse.swt.widgets.Table; > import org.eclipse.swt.widgets.Text; > > import org.eclipse.jface.action.Action; >@@ -60,6 +56,8 @@ > import org.eclipse.jface.viewers.ISelection; > import org.eclipse.jface.viewers.LabelProvider; > import org.eclipse.jface.viewers.LabelProviderChangedEvent; >+import org.eclipse.jface.viewers.StyledString; >+import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider; > > import org.eclipse.jface.text.ITextSelection; > >@@ -114,10 +112,6 @@ > import org.eclipse.jdt.internal.ui.search.JavaSearchScopeFactory; > import org.eclipse.jdt.internal.ui.util.ExceptionHandler; > import org.eclipse.jdt.internal.ui.util.TypeNameMatchLabelProvider; >-import org.eclipse.jdt.internal.ui.viewsupport.ColoredJavaElementLabels; >-import org.eclipse.jdt.internal.ui.viewsupport.ColoredString; >-import org.eclipse.jdt.internal.ui.viewsupport.ColoredViewersManager; >-import org.eclipse.jdt.internal.ui.viewsupport.OwnerDrawSupport; > import org.eclipse.jdt.internal.ui.workingsets.WorkingSetFilterActionGroup; > > /** >@@ -529,55 +523,6 @@ > super.configureShell(shell); > PlatformUI.getWorkbench().getHelpSystem().setHelp(shell, IJavaHelpContextIds.TYPE_SELECTION_DIALOG2); > } >- >- protected Control createContents(Composite parent) { >- Control contents= super.createContents(parent); >- if (ColoredViewersManager.showColoredLabels()) { >- if (contents instanceof Composite) { >- Table listControl= findTableControl((Composite) contents); >- if (listControl != null) { >- installOwnerDraw(listControl); >- } >- } >- } >- return contents; >- } >- >- private void installOwnerDraw(Table tableControl) { >- new OwnerDrawSupport(tableControl) { // installs the owner draw listeners >- public ColoredString getColoredLabel(Item item) { >- String text= item.getText(); >- ColoredString str= new ColoredString(text); >- int index= text.indexOf('-'); >- if (index != -1) { >- str.setStyle(index, str.length() - index, ColoredJavaElementLabels.QUALIFIER_STYLE); >- } >- return str; >- } >- >- public Color getColor(String foregroundColorName, Display display) { >- return PlatformUI.getWorkbench().getThemeManager().getCurrentTheme().getColorRegistry().get(foregroundColorName); >- } >- }; >- } >- >- private Table findTableControl(Composite composite) { >- Control[] children= composite.getChildren(); >- for (int i= 0; i < children.length; i++) { >- Control curr= children[i]; >- if (curr instanceof Table) { >- return (Table) curr; >- } else if (curr instanceof Composite) { >- Table res= findTableControl((Composite) curr); >- if (res != null) { >- return res; >- } >- } >- } >- return null; >- } >- >- > > /* > * (non-Javadoc) >@@ -796,7 +741,7 @@ > /** > * A <code>LabelProvider</code> for (the table of) types. > */ >- private class TypeItemLabelProvider extends LabelProvider implements ILabelDecorator { >+ private class TypeItemLabelProvider extends LabelProvider implements ILabelDecorator, IStyledLabelProvider { > > private boolean fContainerInfo; > private LocalResourceManager fImageManager; >@@ -884,6 +829,19 @@ > return fTypeInfoUtil.getQualifiedText((TypeNameMatch) element); > } > >+ /* (non-Javadoc) >+ * @see org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider#getStyledText(java.lang.Object) >+ */ >+ public StyledString getStyledText(Object element) { >+ String text= getText(element); >+ StyledString string= new StyledString(text); >+ int index= text.indexOf(JavaElementLabels.CONCAT_STRING); >+ if (index != -1) { >+ string.setStyle(index, text.length() - index, StyledString.QUALIFIER_STYLE); >+ } >+ return string; >+ } >+ > } > > /** >Index: ui/org/eclipse/jdt/internal/ui/javaeditor/JavaEditorBreadcrumb.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaEditorBreadcrumb.java,v >retrieving revision 1.8 >diff -u -r1.8 JavaEditorBreadcrumb.java >--- ui/org/eclipse/jdt/internal/ui/javaeditor/JavaEditorBreadcrumb.java 25 Jan 2008 13:11:35 -0000 1.8 >+++ ui/org/eclipse/jdt/internal/ui/javaeditor/JavaEditorBreadcrumb.java 18 Feb 2008 17:57:15 -0000 >@@ -64,9 +64,7 @@ > import org.eclipse.jdt.internal.ui.javaeditor.breadcrumb.BreadcrumbViewer; > import org.eclipse.jdt.internal.ui.javaeditor.breadcrumb.EditorBreadcrumb; > import org.eclipse.jdt.internal.ui.viewsupport.AppearanceAwareLabelProvider; >-import org.eclipse.jdt.internal.ui.viewsupport.ColoredString; > import org.eclipse.jdt.internal.ui.viewsupport.DecoratingJavaLabelProvider; >-import org.eclipse.jdt.internal.ui.viewsupport.IRichLabelProvider; > import org.eclipse.jdt.internal.ui.viewsupport.JavaElementImageProvider; > import org.eclipse.jdt.internal.ui.viewsupport.ResourceToItemsMapper; > >@@ -164,7 +162,7 @@ > } > } > >- private static final class JavaBreadcrumbLabelProvider implements ILabelProvider, IRichLabelProvider, IViewerLabelProvider { >+ private static final class JavaBreadcrumbLabelProvider implements ILabelProvider, IViewerLabelProvider { > > private final DecoratingJavaLabelProvider fParent; > >@@ -216,13 +214,6 @@ > } > > /* >- * @see org.eclipse.jdt.internal.ui.viewsupport.IRichLabelProvider#getRichTextLabel(java.lang.Object) >- */ >- public ColoredString getRichTextLabel(Object object) { >- return fParent.getRichTextLabel(object); >- } >- >- /* > * @see org.eclipse.jface.viewers.IViewerLabelProvider#updateLabel(org.eclipse.jface.viewers.ViewerLabel, java.lang.Object) > */ > public void updateLabel(ViewerLabel label, Object element) { >#P org.eclipse.jdt.junit >Index: src/org/eclipse/jdt/internal/junit/ui/TestSessionLabelProvider.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/ui/TestSessionLabelProvider.java,v >retrieving revision 1.13 >diff -u -r1.13 TestSessionLabelProvider.java >--- src/org/eclipse/jdt/internal/junit/ui/TestSessionLabelProvider.java 13 Feb 2008 18:34:12 -0000 1.13 >+++ src/org/eclipse/jdt/internal/junit/ui/TestSessionLabelProvider.java 18 Feb 2008 17:57:18 -0000 >@@ -19,10 +19,10 @@ > > import org.eclipse.jface.viewers.LabelProvider; > import org.eclipse.jface.viewers.LabelProviderChangedEvent; >+import org.eclipse.jface.viewers.StyledString; >+import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider; > > import org.eclipse.jdt.internal.ui.viewsupport.ColoredJavaElementLabels; >-import org.eclipse.jdt.internal.ui.viewsupport.ColoredString; >-import org.eclipse.jdt.internal.ui.viewsupport.IRichLabelProvider; > > import org.eclipse.jdt.junit.model.ITestCaseElement; > import org.eclipse.jdt.junit.model.ITestElement; >@@ -34,7 +34,7 @@ > import org.eclipse.jdt.internal.junit.model.TestSuiteElement; > import org.eclipse.jdt.internal.junit.model.TestElement.Status; > >-public class TestSessionLabelProvider extends LabelProvider implements IRichLabelProvider { >+public class TestSessionLabelProvider extends LabelProvider implements IStyledLabelProvider { > > private final TestRunnerViewPart fTestRunnerPart; > private final int fLayoutMode; >@@ -54,15 +54,12 @@ > timeFormat.setMinimumIntegerDigits(1); > } > >- /* (non-Javadoc) >- * @see org.eclipse.jdt.internal.ui.viewsupport.IRichLabelProvider#getRichTextLabel(java.lang.Object) >- */ >- public ColoredString getRichTextLabel(Object element) { >+ public StyledString getStyledText(Object element) { > String label= getSimpleLabel(element); > if (label == null) { >- return new ColoredString(element.toString()); >+ return new StyledString(element.toString()); > } >- ColoredString text= new ColoredString(label); >+ StyledString text= new StyledString(label); > > ITestElement testElement= (ITestElement) element; > if (fLayoutMode == TestRunnerViewPart.LAYOUT_HIERARCHICAL) { >@@ -70,7 +67,7 @@ > String testKindDisplayName= fTestRunnerPart.getTestKindDisplayName(); > if (testKindDisplayName != null) { > String decorated= Messages.format(JUnitMessages.TestSessionLabelProvider_testName_JUnitVersion, new Object[] { label, testKindDisplayName }); >- text= ColoredJavaElementLabels.decorateColoredString(text, decorated, ColoredJavaElementLabels.QUALIFIER_STYLE); >+ text= ColoredJavaElementLabels.decorateStyledString(text, decorated, ColoredJavaElementLabels.QUALIFIER_STYLE); > } > } > >@@ -78,16 +75,16 @@ > if (element instanceof ITestCaseElement) { > String className= ((ITestCaseElement) element).getTestClassName(); > String decorated= Messages.format(JUnitMessages.TestSessionLabelProvider_testMethodName_className, new Object[] { label, className }); >- text= ColoredJavaElementLabels.decorateColoredString(text, decorated, ColoredJavaElementLabels.QUALIFIER_STYLE); >+ text= ColoredJavaElementLabels.decorateStyledString(text, decorated, ColoredJavaElementLabels.QUALIFIER_STYLE); > } > } > return addElapsedTime(text, testElement.getElapsedTimeInSeconds()); > } > >- private ColoredString addElapsedTime(ColoredString coloredString, double time) { >- String string= coloredString.getString(); >+ private StyledString addElapsedTime(StyledString StyledString, double time) { >+ String string= StyledString.getString(); > String decorated= addElapsedTime(string, time); >- return ColoredJavaElementLabels.decorateColoredString(coloredString, decorated, ColoredJavaElementLabels.COUNTER_STYLE); >+ return ColoredJavaElementLabels.decorateStyledString(StyledString, decorated, ColoredJavaElementLabels.COUNTER_STYLE); > } > > private String addElapsedTime(String string, double time) { >#P org.eclipse.jdt.ui.tests >Index: ui/org/eclipse/jdt/ui/tests/core/ColoredStringsTest.java >=================================================================== >RCS file: ui/org/eclipse/jdt/ui/tests/core/ColoredStringsTest.java >diff -N ui/org/eclipse/jdt/ui/tests/core/ColoredStringsTest.java >--- ui/org/eclipse/jdt/ui/tests/core/ColoredStringsTest.java 14 Feb 2008 14:21:04 -0000 1.1 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,798 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2000, 2005 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 >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * IBM Corporation - initial API and implementation >- *******************************************************************************/ >-package org.eclipse.jdt.ui.tests.core; >- >-import junit.framework.Test; >-import junit.framework.TestCase; >-import junit.framework.TestSuite; >- >-import org.eclipse.swt.SWT; >-import org.eclipse.swt.custom.StyleRange; >-import org.eclipse.swt.graphics.TextStyle; >- >-import org.eclipse.jdt.internal.ui.viewsupport.ColoredString; >-import org.eclipse.jdt.internal.ui.viewsupport.ColoredString.Style; >- >-public class ColoredStringsTest extends TestCase { >- >- public static class TestStyle extends Style { >- >- public final int borderStyle; >- >- public TestStyle(int borderStyle) { >- this.borderStyle= borderStyle; >- } >- >- public void applyStyles(TextStyle textStyle) { >- textStyle.borderStyle= borderStyle; >- } >- } >- >- public static final TestStyle STYLE1= new TestStyle(SWT.BORDER_DOT); >- public static final TestStyle STYLE2= new TestStyle(SWT.BORDER_DASH); >- >- >- public static Test allTests() { >- return new TestSuite(ColoredStringsTest.class); >- } >- >- public static Test suite() { >- return allTests(); >- } >- >- public void testEmpty() { >- ColoredString coloredString= new ColoredString(); >- >- String str= ""; >- >- assertEquals(str.length(), coloredString.length()); >- assertEquals(str, coloredString.getString()); >- assertEquals(coloredString.getStyleRanges().length, 0); >- } >- >- public void testAppendString1() { >- ColoredString coloredString= new ColoredString(); >- >- String str= "Hello"; >- >- coloredString.append(str, STYLE1); >- >- assertEquals(str.length(), coloredString.length()); >- assertEquals(str, coloredString.getString()); >- StyleRange[] styleRanges= coloredString.getStyleRanges(); >- assertEquals(1, styleRanges.length); >- >- assertEquals(styleRanges[0], STYLE1, 0, str.length()); >- } >- >- public void testAppendString2() { >- ColoredString coloredString= new ColoredString(); >- >- String str1= "Hello"; >- String str2= "You"; >- coloredString.append(str1); >- coloredString.append(str2, STYLE1); >- >- String res= str1 + str2; >- >- assertEquals(res.length(), coloredString.length()); >- assertEquals(res, coloredString.getString()); >- StyleRange[] styleRanges= coloredString.getStyleRanges(); >- assertEquals(1, styleRanges.length); >- assertEquals(styleRanges[0], STYLE1, str1.length(), str2.length()); >- } >- >- public void testAppendString3() { >- ColoredString coloredString= new ColoredString(); >- >- String str1= "Hello"; >- String str2= "You"; >- coloredString.append(str1, STYLE1); >- coloredString.append(str2); >- >- String res= str1 + str2; >- >- assertEquals(res.length(), coloredString.length()); >- assertEquals(res, coloredString.getString()); >- StyleRange[] styleRanges= coloredString.getStyleRanges(); >- assertEquals(1, styleRanges.length); >- assertEquals(styleRanges[0], STYLE1, 0, str1.length()); >- } >- >- public void testAppendString4() { >- ColoredString coloredString= new ColoredString(); >- >- String str1= "Hello"; >- String str2= "You"; >- coloredString.append(str1); >- coloredString.append(str2, STYLE1); >- coloredString.append(str2, STYLE1); >- >- String res= str1 + str2 + str2; >- >- assertEquals(res.length(), coloredString.length()); >- assertEquals(res, coloredString.getString()); >- StyleRange[] styleRanges= coloredString.getStyleRanges(); >- assertEquals(1, styleRanges.length); >- assertEquals(styleRanges[0], STYLE1, str1.length(), str2.length() * 2); >- } >- >- public void testAppendString5() { >- ColoredString coloredString= new ColoredString(); >- >- String str1= "Hello"; >- String str2= "You"; >- String str3= "Me"; >- coloredString.append(str1); >- coloredString.append(str2, STYLE1); >- coloredString.append(str3, STYLE2); >- >- String res= str1 + str2 + str3; >- >- assertEquals(res.length(), coloredString.length()); >- assertEquals(res, coloredString.getString()); >- StyleRange[] styleRanges= coloredString.getStyleRanges(); >- assertEquals(2, styleRanges.length); >- assertEquals(styleRanges[0], STYLE1, str1.length(), str2.length()); >- assertEquals(styleRanges[1], STYLE2, str1.length() + str2.length(), str3.length()); >- } >- >- public void testAppendString6() { >- ColoredString coloredString= new ColoredString(); >- >- String str1= "Hello"; >- String str2= "You"; >- String str3= "Me"; >- coloredString.append(str1, STYLE1); >- coloredString.append(str2); >- coloredString.append(str3, STYLE2); >- >- String res= str1 + str2 + str3; >- >- assertEquals(res.length(), coloredString.length()); >- assertEquals(res, coloredString.getString()); >- StyleRange[] styleRanges= coloredString.getStyleRanges(); >- assertEquals(2, styleRanges.length); >- assertEquals(styleRanges[0], STYLE1, 0, str1.length()); >- assertEquals(styleRanges[1], STYLE2, str1.length() + str2.length(), str3.length()); >- } >- >- public void testAppendString7() { >- ColoredString coloredString= new ColoredString(); >- >- String str1= "Hello"; >- String str2= ""; >- String str3= "Me"; >- coloredString.append(str1, STYLE1); >- coloredString.append(str2, STYLE2); >- coloredString.append(str3, STYLE1); >- >- String res= str1 + str2 + str3; >- >- assertEquals(res.length(), coloredString.length()); >- assertEquals(res, coloredString.getString()); >- StyleRange[] styleRanges= coloredString.getStyleRanges(); >- assertEquals(1, styleRanges.length); >- assertEquals(styleRanges[0], STYLE1, 0, res.length()); >- } >- >- public void testAppendChar1() { >- ColoredString coloredString= new ColoredString(); >- >- coloredString.append('H', STYLE1); >- coloredString.append('2', STYLE2); >- coloredString.append('O', STYLE1); >- >- String res= "H2O"; >- >- assertEquals(res.length(), coloredString.length()); >- assertEquals(res, coloredString.getString()); >- StyleRange[] styleRanges= coloredString.getStyleRanges(); >- assertEquals(3, styleRanges.length); >- assertEquals(styleRanges[0], STYLE1, 0, 1); >- assertEquals(styleRanges[1], STYLE2, 1, 1); >- assertEquals(styleRanges[2], STYLE1, 2, 1); >- } >- >- public void testAppendChar2() { >- ColoredString coloredString= new ColoredString(); >- >- coloredString.append('H', STYLE1); >- coloredString.append('2'); >- coloredString.append('O', STYLE2); >- >- String res= "H2O"; >- >- assertEquals(res.length(), coloredString.length()); >- assertEquals(res, coloredString.getString()); >- StyleRange[] styleRanges= coloredString.getStyleRanges(); >- assertEquals(2, styleRanges.length); >- assertEquals(styleRanges[0], STYLE1, 0, 1); >- assertEquals(styleRanges[1], STYLE2, 2, 1); >- } >- >- public void testAppendColoredString1() { >- ColoredString other= new ColoredString(); >- >- String str2= "You"; >- String str3= "Me"; >- other.append(str2, STYLE1); >- other.append(str3, STYLE2); >- >- String str1= "We"; >- >- ColoredString coloredString= new ColoredString(str1); >- coloredString.append(other); >- >- String res= str1 + str2 + str3; >- >- assertEquals(res.length(), coloredString.length()); >- assertEquals(res, coloredString.getString()); >- StyleRange[] styleRanges= coloredString.getStyleRanges(); >- assertEquals(2, styleRanges.length); >- assertEquals(styleRanges[0], STYLE1, str1.length(), str2.length()); >- assertEquals(styleRanges[1], STYLE2, str1.length() + str2.length(), str3.length()); >- } >- >- public void testAppendColoredString2() { >- ColoredString other= new ColoredString(); >- >- String str2= "You"; >- String str3= "Me"; >- other.append(str2, STYLE1); >- other.append(str3, STYLE2); >- >- String str1= "We"; >- >- ColoredString coloredString= new ColoredString(str1, STYLE1); >- coloredString.append(other); >- >- String res= str1 + str2 + str3; >- >- assertEquals(res.length(), coloredString.length()); >- assertEquals(res, coloredString.getString()); >- StyleRange[] styleRanges= coloredString.getStyleRanges(); >- assertEquals(2, styleRanges.length); >- assertEquals(styleRanges[0], STYLE1, 0, str1.length() + str2.length()); >- assertEquals(styleRanges[1], STYLE2, str1.length() + str2.length(), str3.length()); >- } >- >- public void testAppendColoredString3() { >- >- ColoredString other= new ColoredString(); >- >- String str2= "You"; >- String str3= "Me"; >- other.append(str2); >- other.append(str3, STYLE2); >- >- String str1= "We"; >- >- ColoredString coloredString= new ColoredString(str1, STYLE1); >- coloredString.append(other); >- >- String res= str1 + str2 + str3; >- >- assertEquals(res.length(), coloredString.length()); >- assertEquals(res, coloredString.getString()); >- StyleRange[] styleRanges= coloredString.getStyleRanges(); >- assertEquals(2, styleRanges.length); >- assertEquals(styleRanges[0], STYLE1, 0, str1.length()); >- assertEquals(styleRanges[1], STYLE2, str1.length() + str2.length(), str3.length()); >- } >- >- public void testAppendColoredString4() { >- >- ColoredString other= new ColoredString(); >- >- String str2= "You"; >- String str3= "Me"; >- other.append(str2, STYLE2); >- other.append(str3); >- >- String str1= "We"; >- >- ColoredString coloredString= new ColoredString(str1, STYLE1); >- coloredString.append(other); >- >- String res= str1 + str2 + str3; >- >- assertEquals(res.length(), coloredString.length()); >- assertEquals(res, coloredString.getString()); >- StyleRange[] styleRanges= coloredString.getStyleRanges(); >- assertEquals(2, styleRanges.length); >- assertEquals(styleRanges[0], STYLE1, 0, str1.length()); >- assertEquals(styleRanges[1], STYLE2, str1.length(), str2.length()); >- } >- >- public void testAppendColoredString5() { >- ColoredString other= new ColoredString(); >- >- String str2= "You"; >- String str3= "Me"; >- other.append(str2); >- other.append(str3, STYLE1); >- >- String str1= "We"; >- >- ColoredString coloredString= new ColoredString(str1); >- coloredString.append(other); >- >- String res= str1 + str2 + str3; >- >- assertEquals(res.length(), coloredString.length()); >- assertEquals(res, coloredString.getString()); >- StyleRange[] styleRanges= coloredString.getStyleRanges(); >- assertEquals(1, styleRanges.length); >- assertEquals(styleRanges[0], STYLE1, str1.length() + str2.length(), str3.length()); >- } >- >- public void testSetStyle1() { >- String str1= "One"; >- String str2= "Two"; >- String str3= "Three"; >- >- String res= str1 + str2 + str3; >- >- ColoredString coloredString= new ColoredString(); >- coloredString.append(res); >- >- coloredString.setStyle(0, str1.length(), STYLE1); >- >- assertEquals(res.length(), coloredString.length()); >- assertEquals(res, coloredString.getString()); >- StyleRange[] styleRanges= coloredString.getStyleRanges(); >- assertEquals(1, styleRanges.length); >- assertEquals(styleRanges[0], STYLE1, 0, str1.length()); >- } >- >- public void testSetStyle2() { >- >- String str1= "One"; >- String str2= "Two"; >- String str3= "Three"; >- >- String res= str1 + str2 + str3; >- >- ColoredString coloredString= new ColoredString(); >- coloredString.append(res); >- >- coloredString.setStyle(str1.length(), str2.length(), STYLE1); >- >- assertEquals(res.length(), coloredString.length()); >- assertEquals(res, coloredString.getString()); >- StyleRange[] styleRanges= coloredString.getStyleRanges(); >- assertEquals(1, styleRanges.length); >- assertEquals(styleRanges[0], STYLE1, str1.length(), str2.length()); >- } >- >- public void testSetStyle3() { >- >- String str1= "One"; >- String str2= "Two"; >- String str3= "Three"; >- >- String res= str1 + str2 + str3; >- >- ColoredString coloredString= new ColoredString(); >- coloredString.append(res); >- >- coloredString.setStyle(str1.length(), res.length() - str1.length(), STYLE1); >- >- assertEquals(res.length(), coloredString.length()); >- assertEquals(res, coloredString.getString()); >- StyleRange[] styleRanges= coloredString.getStyleRanges(); >- assertEquals(1, styleRanges.length); >- assertEquals(styleRanges[0], STYLE1, str1.length(), res.length() - str1.length()); >- } >- >- public void testSetStyle4() { >- >- String str1= "One"; >- String str2= "Two"; >- String str3= "Three"; >- >- String res= str1 + str2 + str3; >- >- ColoredString coloredString= new ColoredString(); >- coloredString.append(res); >- >- coloredString.setStyle(0, res.length(), STYLE1); >- >- assertEquals(res.length(), coloredString.length()); >- assertEquals(res, coloredString.getString()); >- StyleRange[] styleRanges= coloredString.getStyleRanges(); >- assertEquals(1, styleRanges.length); >- assertEquals(styleRanges[0], STYLE1, 0, res.length()); >- } >- >- public void testSetStyle5() { >- >- String str1= "One"; >- String str2= "Two"; >- String str3= "Three"; >- >- String res= str1 + str2 + str3; >- >- ColoredString coloredString= new ColoredString(); >- coloredString.append(res); >- >- coloredString.setStyle(0, res.length(), null); >- >- assertEquals(res.length(), coloredString.length()); >- assertEquals(res, coloredString.getString()); >- StyleRange[] styleRanges= coloredString.getStyleRanges(); >- assertEquals(0, styleRanges.length); >- } >- >- public void testSetStyle6() { >- >- String str1= "One"; >- String str2= "Two"; >- >- String res= str1 + str2; >- >- ColoredString coloredString= new ColoredString(str1, STYLE1); >- coloredString.append(str2); >- >- coloredString.setStyle(str1.length(), str2.length(), STYLE2); >- >- assertEquals(res.length(), coloredString.length()); >- assertEquals(res, coloredString.getString()); >- StyleRange[] styleRanges= coloredString.getStyleRanges(); >- assertEquals(2, styleRanges.length); >- assertEquals(styleRanges[0], STYLE1, 0, str1.length()); >- assertEquals(styleRanges[1], STYLE2, str1.length(), str2.length()); >- } >- >- public void testSetStyle7() { >- >- String str1= "One"; >- String str2= "Two"; >- >- String res= str1 + str2; >- >- ColoredString coloredString= new ColoredString(str1); >- coloredString.append(str2, STYLE1); >- >- coloredString.setStyle(0, str1.length(), STYLE2); >- >- assertEquals(res.length(), coloredString.length()); >- assertEquals(res, coloredString.getString()); >- StyleRange[] styleRanges= coloredString.getStyleRanges(); >- assertEquals(2, styleRanges.length); >- assertEquals(styleRanges[0], STYLE2, 0, str1.length()); >- assertEquals(styleRanges[1], STYLE1, str1.length(), str2.length()); >- } >- >- public void testSetStyle8() { >- >- String str1= "One"; >- String str2= "Two"; >- >- String res= str1 + str2; >- >- ColoredString coloredString= new ColoredString(); >- coloredString.append(str1, STYLE1); >- coloredString.append(str2, STYLE2); >- >- coloredString.setStyle(0, str1.length(), STYLE2); >- >- assertEquals(res.length(), coloredString.length()); >- assertEquals(res, coloredString.getString()); >- StyleRange[] styleRanges= coloredString.getStyleRanges(); >- assertEquals(1, styleRanges.length); >- assertEquals(styleRanges[0], STYLE2, 0, res.length()); >- } >- >- public void testSetStyle9() { >- >- String str1= "One"; >- String str2= "Two"; >- >- String res= str1 + str2; >- >- ColoredString coloredString= new ColoredString(); >- coloredString.append(str1, STYLE1); >- coloredString.append(str2, STYLE2); >- >- coloredString.setStyle(0, res.length(), null); >- >- assertEquals(res.length(), coloredString.length()); >- assertEquals(res, coloredString.getString()); >- StyleRange[] styleRanges= coloredString.getStyleRanges(); >- assertEquals(0, styleRanges.length); >- } >- >- public void testSetStyle10() { >- >- String str1= "One"; >- String str2= "Two"; >- >- String res= str1 + str2; >- >- ColoredString coloredString= new ColoredString(); >- coloredString.append(str1, STYLE1); >- coloredString.append(str2, STYLE2); >- >- coloredString.setStyle(1, res.length() - 2, null); >- >- assertEquals(res.length(), coloredString.length()); >- assertEquals(res, coloredString.getString()); >- StyleRange[] styleRanges= coloredString.getStyleRanges(); >- assertEquals(2, styleRanges.length); >- >- assertEquals(styleRanges[0], STYLE1, 0, 1); >- assertEquals(styleRanges[1], STYLE2, res.length() - 1, 1); >- } >- >- public void testSetStyle11() { >- >- String str1= "One"; >- String str2= "Two"; >- >- String res= str1 + str2; >- >- ColoredString coloredString= new ColoredString(); >- coloredString.append(str1, STYLE1); >- coloredString.append(str2, STYLE2); >- >- coloredString.setStyle(1, res.length() - 1, STYLE1); >- >- assertEquals(res.length(), coloredString.length()); >- assertEquals(res, coloredString.getString()); >- StyleRange[] styleRanges= coloredString.getStyleRanges(); >- assertEquals(1, styleRanges.length); >- >- assertEquals(styleRanges[0], STYLE1, 0, res.length()); >- } >- >- public void testSetStyle12() { >- >- String str1= "One"; >- String str2= "Two"; >- >- String res= str1 + str2; >- >- ColoredString coloredString= new ColoredString(); >- coloredString.append(str1, STYLE1); >- coloredString.append(str2, STYLE2); >- >- coloredString.setStyle(0, res.length() - 1, STYLE2); >- >- assertEquals(res.length(), coloredString.length()); >- assertEquals(res, coloredString.getString()); >- StyleRange[] styleRanges= coloredString.getStyleRanges(); >- assertEquals(1, styleRanges.length); >- >- assertEquals(styleRanges[0], STYLE2, 0, res.length()); >- } >- >- public void testSetStyle13() { >- >- String str1= "One"; >- String str2= "Two"; >- >- String res= str1 + str2; >- >- ColoredString coloredString= new ColoredString(); >- coloredString.append(str1, STYLE1); >- coloredString.append(str2, STYLE2); >- >- coloredString.setStyle(1, res.length() - 2, STYLE1); >- >- assertEquals(res.length(), coloredString.length()); >- assertEquals(res, coloredString.getString()); >- StyleRange[] styleRanges= coloredString.getStyleRanges(); >- assertEquals(2, styleRanges.length); >- >- assertEquals(styleRanges[0], STYLE1, 0, res.length() - 1); >- assertEquals(styleRanges[1], STYLE2, res.length() - 1, 1); >- } >- >- public void testSetStyle14() { >- >- String str1= "One"; >- String str2= "Two"; >- >- String res= str1 + str2; >- >- ColoredString coloredString= new ColoredString(); >- coloredString.append(str1, STYLE1); >- coloredString.append(str2, STYLE2); >- >- coloredString.setStyle(1, res.length() - 2, STYLE2); >- >- assertEquals(res.length(), coloredString.length()); >- assertEquals(res, coloredString.getString()); >- StyleRange[] styleRanges= coloredString.getStyleRanges(); >- assertEquals(2, styleRanges.length); >- >- assertEquals(styleRanges[0], STYLE1, 0, 1); >- assertEquals(styleRanges[1], STYLE2, 1, res.length() - 1); >- } >- >- public void testSetStyle15() { >- >- String str1= "One"; >- String str2= "Two"; >- >- String res= str1 + str2; >- >- ColoredString coloredString= new ColoredString(); >- coloredString.append(str1, null); >- coloredString.append(str2, STYLE2); >- >- coloredString.setStyle(0, 1, STYLE1); >- >- assertEquals(res.length(), coloredString.length()); >- assertEquals(res, coloredString.getString()); >- StyleRange[] styleRanges= coloredString.getStyleRanges(); >- assertEquals(2, styleRanges.length); >- >- assertEquals(styleRanges[0], STYLE1, 0, 1); >- assertEquals(styleRanges[1], STYLE2, str1.length(), str2.length()); >- } >- >- public void testSetStyle16() { >- >- String res= "H2O"; >- >- ColoredString coloredString= new ColoredString(); >- coloredString.append('H', null); >- coloredString.append('2', STYLE1); >- coloredString.append('O', STYLE2); >- >- coloredString.setStyle(0, res.length(), STYLE1); >- >- assertEquals(res.length(), coloredString.length()); >- assertEquals(res, coloredString.getString()); >- StyleRange[] styleRanges= coloredString.getStyleRanges(); >- assertEquals(1, styleRanges.length); >- >- assertEquals(styleRanges[0], STYLE1, 0, res.length()); >- } >- >- public void testSetStyle17() { >- >- String res= "H2O"; >- >- ColoredString coloredString= new ColoredString(); >- coloredString.append('H', null); >- coloredString.append('2', STYLE1); >- coloredString.append('O', STYLE2); >- >- coloredString.setStyle(0, res.length(), null); >- >- assertEquals(res.length(), coloredString.length()); >- assertEquals(res, coloredString.getString()); >- StyleRange[] styleRanges= coloredString.getStyleRanges(); >- assertEquals(0, styleRanges.length); >- } >- >- public void testSetStyle18() { >- String res= "H2OH2O"; >- >- ColoredString coloredString= new ColoredString(); >- coloredString.append('H', null); >- coloredString.append('2', STYLE1); >- coloredString.append('O', STYLE2); >- coloredString.append('H', null); >- coloredString.append('2', STYLE2); >- coloredString.append('O', STYLE1); >- >- coloredString.setStyle(1, res.length() - 2, STYLE1); >- >- assertEquals(res.length(), coloredString.length()); >- assertEquals(res, coloredString.getString()); >- StyleRange[] styleRanges= coloredString.getStyleRanges(); >- assertEquals(1, styleRanges.length); >- >- assertEquals(styleRanges[0], STYLE1, 1, res.length() - 1); >- } >- >- public void testSetStyle19() { >- String res= "O2O2O2O2O2O2"; >- >- ColoredString coloredString= new ColoredString(); >- coloredString.append("O2", null); >- coloredString.append("O2", STYLE1); >- coloredString.append("O2", STYLE2); >- coloredString.append("O2", STYLE1); >- coloredString.append("O2", STYLE2); >- coloredString.append("O2", null); >- >- coloredString.setStyle(1, res.length() - 2, STYLE1); >- >- assertEquals(res.length(), coloredString.length()); >- assertEquals(res, coloredString.getString()); >- StyleRange[] styleRanges= coloredString.getStyleRanges(); >- assertEquals(1, styleRanges.length); >- >- assertEquals(styleRanges[0], STYLE1, 1, res.length() - 2); >- } >- >- public void testSetStyle20() { >- String res= "O2O2O2O2O2O2"; >- >- ColoredString coloredString= new ColoredString(); >- coloredString.append("O2", null); >- coloredString.append("O2", STYLE1); >- coloredString.append("O2", STYLE2); >- coloredString.append("O2", STYLE1); >- coloredString.append("O2", STYLE2); >- coloredString.append("O2", null); >- >- coloredString.setStyle(3, 6, null); >- >- assertEquals(res.length(), coloredString.length()); >- assertEquals(res, coloredString.getString()); >- StyleRange[] styleRanges= coloredString.getStyleRanges(); >- assertEquals(2, styleRanges.length); >- >- assertEquals(styleRanges[0], STYLE1, 2, 1); >- assertEquals(styleRanges[1], STYLE2, 9, 1); >- } >- >- public void testSetStyle21() { >- String res= "O2O2O2O2O2O2"; >- >- ColoredString coloredString= new ColoredString(); >- coloredString.append("O2", null); >- coloredString.append("O2", STYLE1); >- coloredString.append("O2", STYLE2); >- coloredString.append("O2", STYLE1); >- coloredString.append("O2", STYLE2); >- coloredString.append("O2", null); >- >- coloredString.setStyle(3, 6, STYLE1); >- coloredString.setStyle(3, 6, null); >- >- assertEquals(res.length(), coloredString.length()); >- assertEquals(res, coloredString.getString()); >- StyleRange[] styleRanges= coloredString.getStyleRanges(); >- assertEquals(2, styleRanges.length); >- >- assertEquals(styleRanges[0], STYLE1, 2, 1); >- assertEquals(styleRanges[1], STYLE2, 9, 1); >- } >- >- public void testCombination1() { >- String str1= "One"; >- String str2= "Two"; >- >- String res= str1 + str2 + str1; >- >- ColoredString coloredString= new ColoredString(); >- coloredString.append(str1, null); >- coloredString.append(str2, STYLE2); >- >- coloredString.setStyle(str1.length(), str2.length(), STYLE1); >- >- coloredString.append(str1, STYLE1); >- >- assertEquals(res.length(), coloredString.length()); >- assertEquals(res, coloredString.getString()); >- StyleRange[] styleRanges= coloredString.getStyleRanges(); >- assertEquals(1, styleRanges.length); >- >- assertEquals(styleRanges[0], STYLE1, str1.length(), str2.length() + str1.length()); >- } >- >- >- private void assertEquals(StyleRange range, TestStyle style, int offset, int length) { >- assertEquals(offset, range.start); >- assertEquals(length, range.length); >- assertEquals(style.borderStyle, range.borderStyle); >- } >- >- >-} >\ No newline at end of file >Index: ui/org/eclipse/jdt/ui/tests/core/StyledStringTest.java >=================================================================== >RCS file: ui/org/eclipse/jdt/ui/tests/core/StyledStringTest.java >diff -N ui/org/eclipse/jdt/ui/tests/core/StyledStringTest.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ ui/org/eclipse/jdt/ui/tests/core/StyledStringTest.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,798 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 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 >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.jdt.ui.tests.core; >+ >+import junit.framework.Test; >+import junit.framework.TestCase; >+import junit.framework.TestSuite; >+ >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.custom.StyleRange; >+import org.eclipse.swt.graphics.TextStyle; >+ >+import org.eclipse.jface.viewers.StyledString; >+import org.eclipse.jface.viewers.StyledString.Style; >+ >+public class StyledStringTest extends TestCase { >+ >+ public static class TestStyle extends Style { >+ >+ public final int borderStyle; >+ >+ public TestStyle(int borderStyle) { >+ this.borderStyle= borderStyle; >+ } >+ >+ public void applyStyles(TextStyle textStyle) { >+ textStyle.borderStyle= borderStyle; >+ } >+ } >+ >+ public static final TestStyle STYLE1= new TestStyle(SWT.BORDER_DOT); >+ public static final TestStyle STYLE2= new TestStyle(SWT.BORDER_DASH); >+ >+ >+ public static Test allTests() { >+ return new TestSuite(StyledStringTest.class); >+ } >+ >+ public static Test suite() { >+ return allTests(); >+ } >+ >+ public void testEmpty() { >+ StyledString StyledString= new StyledString(); >+ >+ String str= ""; >+ >+ assertEquals(str.length(), StyledString.length()); >+ assertEquals(str, StyledString.getString()); >+ assertEquals(StyledString.getStyleRanges().length, 0); >+ } >+ >+ public void testAppendString1() { >+ StyledString StyledString= new StyledString(); >+ >+ String str= "Hello"; >+ >+ StyledString.append(str, STYLE1); >+ >+ assertEquals(str.length(), StyledString.length()); >+ assertEquals(str, StyledString.getString()); >+ StyleRange[] styleRanges= StyledString.getStyleRanges(); >+ assertEquals(1, styleRanges.length); >+ >+ assertEquals(styleRanges[0], STYLE1, 0, str.length()); >+ } >+ >+ public void testAppendString2() { >+ StyledString StyledString= new StyledString(); >+ >+ String str1= "Hello"; >+ String str2= "You"; >+ StyledString.append(str1); >+ StyledString.append(str2, STYLE1); >+ >+ String res= str1 + str2; >+ >+ assertEquals(res.length(), StyledString.length()); >+ assertEquals(res, StyledString.getString()); >+ StyleRange[] styleRanges= StyledString.getStyleRanges(); >+ assertEquals(1, styleRanges.length); >+ assertEquals(styleRanges[0], STYLE1, str1.length(), str2.length()); >+ } >+ >+ public void testAppendString3() { >+ StyledString StyledString= new StyledString(); >+ >+ String str1= "Hello"; >+ String str2= "You"; >+ StyledString.append(str1, STYLE1); >+ StyledString.append(str2); >+ >+ String res= str1 + str2; >+ >+ assertEquals(res.length(), StyledString.length()); >+ assertEquals(res, StyledString.getString()); >+ StyleRange[] styleRanges= StyledString.getStyleRanges(); >+ assertEquals(1, styleRanges.length); >+ assertEquals(styleRanges[0], STYLE1, 0, str1.length()); >+ } >+ >+ public void testAppendString4() { >+ StyledString StyledString= new StyledString(); >+ >+ String str1= "Hello"; >+ String str2= "You"; >+ StyledString.append(str1); >+ StyledString.append(str2, STYLE1); >+ StyledString.append(str2, STYLE1); >+ >+ String res= str1 + str2 + str2; >+ >+ assertEquals(res.length(), StyledString.length()); >+ assertEquals(res, StyledString.getString()); >+ StyleRange[] styleRanges= StyledString.getStyleRanges(); >+ assertEquals(1, styleRanges.length); >+ assertEquals(styleRanges[0], STYLE1, str1.length(), str2.length() * 2); >+ } >+ >+ public void testAppendString5() { >+ StyledString StyledString= new StyledString(); >+ >+ String str1= "Hello"; >+ String str2= "You"; >+ String str3= "Me"; >+ StyledString.append(str1); >+ StyledString.append(str2, STYLE1); >+ StyledString.append(str3, STYLE2); >+ >+ String res= str1 + str2 + str3; >+ >+ assertEquals(res.length(), StyledString.length()); >+ assertEquals(res, StyledString.getString()); >+ StyleRange[] styleRanges= StyledString.getStyleRanges(); >+ assertEquals(2, styleRanges.length); >+ assertEquals(styleRanges[0], STYLE1, str1.length(), str2.length()); >+ assertEquals(styleRanges[1], STYLE2, str1.length() + str2.length(), str3.length()); >+ } >+ >+ public void testAppendString6() { >+ StyledString StyledString= new StyledString(); >+ >+ String str1= "Hello"; >+ String str2= "You"; >+ String str3= "Me"; >+ StyledString.append(str1, STYLE1); >+ StyledString.append(str2); >+ StyledString.append(str3, STYLE2); >+ >+ String res= str1 + str2 + str3; >+ >+ assertEquals(res.length(), StyledString.length()); >+ assertEquals(res, StyledString.getString()); >+ StyleRange[] styleRanges= StyledString.getStyleRanges(); >+ assertEquals(2, styleRanges.length); >+ assertEquals(styleRanges[0], STYLE1, 0, str1.length()); >+ assertEquals(styleRanges[1], STYLE2, str1.length() + str2.length(), str3.length()); >+ } >+ >+ public void testAppendString7() { >+ StyledString StyledString= new StyledString(); >+ >+ String str1= "Hello"; >+ String str2= ""; >+ String str3= "Me"; >+ StyledString.append(str1, STYLE1); >+ StyledString.append(str2, STYLE2); >+ StyledString.append(str3, STYLE1); >+ >+ String res= str1 + str2 + str3; >+ >+ assertEquals(res.length(), StyledString.length()); >+ assertEquals(res, StyledString.getString()); >+ StyleRange[] styleRanges= StyledString.getStyleRanges(); >+ assertEquals(1, styleRanges.length); >+ assertEquals(styleRanges[0], STYLE1, 0, res.length()); >+ } >+ >+ public void testAppendChar1() { >+ StyledString StyledString= new StyledString(); >+ >+ StyledString.append('H', STYLE1); >+ StyledString.append('2', STYLE2); >+ StyledString.append('O', STYLE1); >+ >+ String res= "H2O"; >+ >+ assertEquals(res.length(), StyledString.length()); >+ assertEquals(res, StyledString.getString()); >+ StyleRange[] styleRanges= StyledString.getStyleRanges(); >+ assertEquals(3, styleRanges.length); >+ assertEquals(styleRanges[0], STYLE1, 0, 1); >+ assertEquals(styleRanges[1], STYLE2, 1, 1); >+ assertEquals(styleRanges[2], STYLE1, 2, 1); >+ } >+ >+ public void testAppendChar2() { >+ StyledString StyledString= new StyledString(); >+ >+ StyledString.append('H', STYLE1); >+ StyledString.append('2'); >+ StyledString.append('O', STYLE2); >+ >+ String res= "H2O"; >+ >+ assertEquals(res.length(), StyledString.length()); >+ assertEquals(res, StyledString.getString()); >+ StyleRange[] styleRanges= StyledString.getStyleRanges(); >+ assertEquals(2, styleRanges.length); >+ assertEquals(styleRanges[0], STYLE1, 0, 1); >+ assertEquals(styleRanges[1], STYLE2, 2, 1); >+ } >+ >+ public void testAppendStyledString1() { >+ StyledString other= new StyledString(); >+ >+ String str2= "You"; >+ String str3= "Me"; >+ other.append(str2, STYLE1); >+ other.append(str3, STYLE2); >+ >+ String str1= "We"; >+ >+ StyledString StyledString= new StyledString(str1); >+ StyledString.append(other); >+ >+ String res= str1 + str2 + str3; >+ >+ assertEquals(res.length(), StyledString.length()); >+ assertEquals(res, StyledString.getString()); >+ StyleRange[] styleRanges= StyledString.getStyleRanges(); >+ assertEquals(2, styleRanges.length); >+ assertEquals(styleRanges[0], STYLE1, str1.length(), str2.length()); >+ assertEquals(styleRanges[1], STYLE2, str1.length() + str2.length(), str3.length()); >+ } >+ >+ public void testAppendStyledString2() { >+ StyledString other= new StyledString(); >+ >+ String str2= "You"; >+ String str3= "Me"; >+ other.append(str2, STYLE1); >+ other.append(str3, STYLE2); >+ >+ String str1= "We"; >+ >+ StyledString StyledString= new StyledString(str1, STYLE1); >+ StyledString.append(other); >+ >+ String res= str1 + str2 + str3; >+ >+ assertEquals(res.length(), StyledString.length()); >+ assertEquals(res, StyledString.getString()); >+ StyleRange[] styleRanges= StyledString.getStyleRanges(); >+ assertEquals(2, styleRanges.length); >+ assertEquals(styleRanges[0], STYLE1, 0, str1.length() + str2.length()); >+ assertEquals(styleRanges[1], STYLE2, str1.length() + str2.length(), str3.length()); >+ } >+ >+ public void testAppendStyledString3() { >+ >+ StyledString other= new StyledString(); >+ >+ String str2= "You"; >+ String str3= "Me"; >+ other.append(str2); >+ other.append(str3, STYLE2); >+ >+ String str1= "We"; >+ >+ StyledString StyledString= new StyledString(str1, STYLE1); >+ StyledString.append(other); >+ >+ String res= str1 + str2 + str3; >+ >+ assertEquals(res.length(), StyledString.length()); >+ assertEquals(res, StyledString.getString()); >+ StyleRange[] styleRanges= StyledString.getStyleRanges(); >+ assertEquals(2, styleRanges.length); >+ assertEquals(styleRanges[0], STYLE1, 0, str1.length()); >+ assertEquals(styleRanges[1], STYLE2, str1.length() + str2.length(), str3.length()); >+ } >+ >+ public void testAppendStyledString4() { >+ >+ StyledString other= new StyledString(); >+ >+ String str2= "You"; >+ String str3= "Me"; >+ other.append(str2, STYLE2); >+ other.append(str3); >+ >+ String str1= "We"; >+ >+ StyledString StyledString= new StyledString(str1, STYLE1); >+ StyledString.append(other); >+ >+ String res= str1 + str2 + str3; >+ >+ assertEquals(res.length(), StyledString.length()); >+ assertEquals(res, StyledString.getString()); >+ StyleRange[] styleRanges= StyledString.getStyleRanges(); >+ assertEquals(2, styleRanges.length); >+ assertEquals(styleRanges[0], STYLE1, 0, str1.length()); >+ assertEquals(styleRanges[1], STYLE2, str1.length(), str2.length()); >+ } >+ >+ public void testAppendStyledString5() { >+ StyledString other= new StyledString(); >+ >+ String str2= "You"; >+ String str3= "Me"; >+ other.append(str2); >+ other.append(str3, STYLE1); >+ >+ String str1= "We"; >+ >+ StyledString StyledString= new StyledString(str1); >+ StyledString.append(other); >+ >+ String res= str1 + str2 + str3; >+ >+ assertEquals(res.length(), StyledString.length()); >+ assertEquals(res, StyledString.getString()); >+ StyleRange[] styleRanges= StyledString.getStyleRanges(); >+ assertEquals(1, styleRanges.length); >+ assertEquals(styleRanges[0], STYLE1, str1.length() + str2.length(), str3.length()); >+ } >+ >+ public void testSetStyle1() { >+ String str1= "One"; >+ String str2= "Two"; >+ String str3= "Three"; >+ >+ String res= str1 + str2 + str3; >+ >+ StyledString StyledString= new StyledString(); >+ StyledString.append(res); >+ >+ StyledString.setStyle(0, str1.length(), STYLE1); >+ >+ assertEquals(res.length(), StyledString.length()); >+ assertEquals(res, StyledString.getString()); >+ StyleRange[] styleRanges= StyledString.getStyleRanges(); >+ assertEquals(1, styleRanges.length); >+ assertEquals(styleRanges[0], STYLE1, 0, str1.length()); >+ } >+ >+ public void testSetStyle2() { >+ >+ String str1= "One"; >+ String str2= "Two"; >+ String str3= "Three"; >+ >+ String res= str1 + str2 + str3; >+ >+ StyledString StyledString= new StyledString(); >+ StyledString.append(res); >+ >+ StyledString.setStyle(str1.length(), str2.length(), STYLE1); >+ >+ assertEquals(res.length(), StyledString.length()); >+ assertEquals(res, StyledString.getString()); >+ StyleRange[] styleRanges= StyledString.getStyleRanges(); >+ assertEquals(1, styleRanges.length); >+ assertEquals(styleRanges[0], STYLE1, str1.length(), str2.length()); >+ } >+ >+ public void testSetStyle3() { >+ >+ String str1= "One"; >+ String str2= "Two"; >+ String str3= "Three"; >+ >+ String res= str1 + str2 + str3; >+ >+ StyledString StyledString= new StyledString(); >+ StyledString.append(res); >+ >+ StyledString.setStyle(str1.length(), res.length() - str1.length(), STYLE1); >+ >+ assertEquals(res.length(), StyledString.length()); >+ assertEquals(res, StyledString.getString()); >+ StyleRange[] styleRanges= StyledString.getStyleRanges(); >+ assertEquals(1, styleRanges.length); >+ assertEquals(styleRanges[0], STYLE1, str1.length(), res.length() - str1.length()); >+ } >+ >+ public void testSetStyle4() { >+ >+ String str1= "One"; >+ String str2= "Two"; >+ String str3= "Three"; >+ >+ String res= str1 + str2 + str3; >+ >+ StyledString StyledString= new StyledString(); >+ StyledString.append(res); >+ >+ StyledString.setStyle(0, res.length(), STYLE1); >+ >+ assertEquals(res.length(), StyledString.length()); >+ assertEquals(res, StyledString.getString()); >+ StyleRange[] styleRanges= StyledString.getStyleRanges(); >+ assertEquals(1, styleRanges.length); >+ assertEquals(styleRanges[0], STYLE1, 0, res.length()); >+ } >+ >+ public void testSetStyle5() { >+ >+ String str1= "One"; >+ String str2= "Two"; >+ String str3= "Three"; >+ >+ String res= str1 + str2 + str3; >+ >+ StyledString StyledString= new StyledString(); >+ StyledString.append(res); >+ >+ StyledString.setStyle(0, res.length(), null); >+ >+ assertEquals(res.length(), StyledString.length()); >+ assertEquals(res, StyledString.getString()); >+ StyleRange[] styleRanges= StyledString.getStyleRanges(); >+ assertEquals(0, styleRanges.length); >+ } >+ >+ public void testSetStyle6() { >+ >+ String str1= "One"; >+ String str2= "Two"; >+ >+ String res= str1 + str2; >+ >+ StyledString StyledString= new StyledString(str1, STYLE1); >+ StyledString.append(str2); >+ >+ StyledString.setStyle(str1.length(), str2.length(), STYLE2); >+ >+ assertEquals(res.length(), StyledString.length()); >+ assertEquals(res, StyledString.getString()); >+ StyleRange[] styleRanges= StyledString.getStyleRanges(); >+ assertEquals(2, styleRanges.length); >+ assertEquals(styleRanges[0], STYLE1, 0, str1.length()); >+ assertEquals(styleRanges[1], STYLE2, str1.length(), str2.length()); >+ } >+ >+ public void testSetStyle7() { >+ >+ String str1= "One"; >+ String str2= "Two"; >+ >+ String res= str1 + str2; >+ >+ StyledString StyledString= new StyledString(str1); >+ StyledString.append(str2, STYLE1); >+ >+ StyledString.setStyle(0, str1.length(), STYLE2); >+ >+ assertEquals(res.length(), StyledString.length()); >+ assertEquals(res, StyledString.getString()); >+ StyleRange[] styleRanges= StyledString.getStyleRanges(); >+ assertEquals(2, styleRanges.length); >+ assertEquals(styleRanges[0], STYLE2, 0, str1.length()); >+ assertEquals(styleRanges[1], STYLE1, str1.length(), str2.length()); >+ } >+ >+ public void testSetStyle8() { >+ >+ String str1= "One"; >+ String str2= "Two"; >+ >+ String res= str1 + str2; >+ >+ StyledString StyledString= new StyledString(); >+ StyledString.append(str1, STYLE1); >+ StyledString.append(str2, STYLE2); >+ >+ StyledString.setStyle(0, str1.length(), STYLE2); >+ >+ assertEquals(res.length(), StyledString.length()); >+ assertEquals(res, StyledString.getString()); >+ StyleRange[] styleRanges= StyledString.getStyleRanges(); >+ assertEquals(1, styleRanges.length); >+ assertEquals(styleRanges[0], STYLE2, 0, res.length()); >+ } >+ >+ public void testSetStyle9() { >+ >+ String str1= "One"; >+ String str2= "Two"; >+ >+ String res= str1 + str2; >+ >+ StyledString StyledString= new StyledString(); >+ StyledString.append(str1, STYLE1); >+ StyledString.append(str2, STYLE2); >+ >+ StyledString.setStyle(0, res.length(), null); >+ >+ assertEquals(res.length(), StyledString.length()); >+ assertEquals(res, StyledString.getString()); >+ StyleRange[] styleRanges= StyledString.getStyleRanges(); >+ assertEquals(0, styleRanges.length); >+ } >+ >+ public void testSetStyle10() { >+ >+ String str1= "One"; >+ String str2= "Two"; >+ >+ String res= str1 + str2; >+ >+ StyledString StyledString= new StyledString(); >+ StyledString.append(str1, STYLE1); >+ StyledString.append(str2, STYLE2); >+ >+ StyledString.setStyle(1, res.length() - 2, null); >+ >+ assertEquals(res.length(), StyledString.length()); >+ assertEquals(res, StyledString.getString()); >+ StyleRange[] styleRanges= StyledString.getStyleRanges(); >+ assertEquals(2, styleRanges.length); >+ >+ assertEquals(styleRanges[0], STYLE1, 0, 1); >+ assertEquals(styleRanges[1], STYLE2, res.length() - 1, 1); >+ } >+ >+ public void testSetStyle11() { >+ >+ String str1= "One"; >+ String str2= "Two"; >+ >+ String res= str1 + str2; >+ >+ StyledString StyledString= new StyledString(); >+ StyledString.append(str1, STYLE1); >+ StyledString.append(str2, STYLE2); >+ >+ StyledString.setStyle(1, res.length() - 1, STYLE1); >+ >+ assertEquals(res.length(), StyledString.length()); >+ assertEquals(res, StyledString.getString()); >+ StyleRange[] styleRanges= StyledString.getStyleRanges(); >+ assertEquals(1, styleRanges.length); >+ >+ assertEquals(styleRanges[0], STYLE1, 0, res.length()); >+ } >+ >+ public void testSetStyle12() { >+ >+ String str1= "One"; >+ String str2= "Two"; >+ >+ String res= str1 + str2; >+ >+ StyledString StyledString= new StyledString(); >+ StyledString.append(str1, STYLE1); >+ StyledString.append(str2, STYLE2); >+ >+ StyledString.setStyle(0, res.length() - 1, STYLE2); >+ >+ assertEquals(res.length(), StyledString.length()); >+ assertEquals(res, StyledString.getString()); >+ StyleRange[] styleRanges= StyledString.getStyleRanges(); >+ assertEquals(1, styleRanges.length); >+ >+ assertEquals(styleRanges[0], STYLE2, 0, res.length()); >+ } >+ >+ public void testSetStyle13() { >+ >+ String str1= "One"; >+ String str2= "Two"; >+ >+ String res= str1 + str2; >+ >+ StyledString StyledString= new StyledString(); >+ StyledString.append(str1, STYLE1); >+ StyledString.append(str2, STYLE2); >+ >+ StyledString.setStyle(1, res.length() - 2, STYLE1); >+ >+ assertEquals(res.length(), StyledString.length()); >+ assertEquals(res, StyledString.getString()); >+ StyleRange[] styleRanges= StyledString.getStyleRanges(); >+ assertEquals(2, styleRanges.length); >+ >+ assertEquals(styleRanges[0], STYLE1, 0, res.length() - 1); >+ assertEquals(styleRanges[1], STYLE2, res.length() - 1, 1); >+ } >+ >+ public void testSetStyle14() { >+ >+ String str1= "One"; >+ String str2= "Two"; >+ >+ String res= str1 + str2; >+ >+ StyledString StyledString= new StyledString(); >+ StyledString.append(str1, STYLE1); >+ StyledString.append(str2, STYLE2); >+ >+ StyledString.setStyle(1, res.length() - 2, STYLE2); >+ >+ assertEquals(res.length(), StyledString.length()); >+ assertEquals(res, StyledString.getString()); >+ StyleRange[] styleRanges= StyledString.getStyleRanges(); >+ assertEquals(2, styleRanges.length); >+ >+ assertEquals(styleRanges[0], STYLE1, 0, 1); >+ assertEquals(styleRanges[1], STYLE2, 1, res.length() - 1); >+ } >+ >+ public void testSetStyle15() { >+ >+ String str1= "One"; >+ String str2= "Two"; >+ >+ String res= str1 + str2; >+ >+ StyledString StyledString= new StyledString(); >+ StyledString.append(str1, null); >+ StyledString.append(str2, STYLE2); >+ >+ StyledString.setStyle(0, 1, STYLE1); >+ >+ assertEquals(res.length(), StyledString.length()); >+ assertEquals(res, StyledString.getString()); >+ StyleRange[] styleRanges= StyledString.getStyleRanges(); >+ assertEquals(2, styleRanges.length); >+ >+ assertEquals(styleRanges[0], STYLE1, 0, 1); >+ assertEquals(styleRanges[1], STYLE2, str1.length(), str2.length()); >+ } >+ >+ public void testSetStyle16() { >+ >+ String res= "H2O"; >+ >+ StyledString StyledString= new StyledString(); >+ StyledString.append('H', null); >+ StyledString.append('2', STYLE1); >+ StyledString.append('O', STYLE2); >+ >+ StyledString.setStyle(0, res.length(), STYLE1); >+ >+ assertEquals(res.length(), StyledString.length()); >+ assertEquals(res, StyledString.getString()); >+ StyleRange[] styleRanges= StyledString.getStyleRanges(); >+ assertEquals(1, styleRanges.length); >+ >+ assertEquals(styleRanges[0], STYLE1, 0, res.length()); >+ } >+ >+ public void testSetStyle17() { >+ >+ String res= "H2O"; >+ >+ StyledString StyledString= new StyledString(); >+ StyledString.append('H', null); >+ StyledString.append('2', STYLE1); >+ StyledString.append('O', STYLE2); >+ >+ StyledString.setStyle(0, res.length(), null); >+ >+ assertEquals(res.length(), StyledString.length()); >+ assertEquals(res, StyledString.getString()); >+ StyleRange[] styleRanges= StyledString.getStyleRanges(); >+ assertEquals(0, styleRanges.length); >+ } >+ >+ public void testSetStyle18() { >+ String res= "H2OH2O"; >+ >+ StyledString StyledString= new StyledString(); >+ StyledString.append('H', null); >+ StyledString.append('2', STYLE1); >+ StyledString.append('O', STYLE2); >+ StyledString.append('H', null); >+ StyledString.append('2', STYLE2); >+ StyledString.append('O', STYLE1); >+ >+ StyledString.setStyle(1, res.length() - 2, STYLE1); >+ >+ assertEquals(res.length(), StyledString.length()); >+ assertEquals(res, StyledString.getString()); >+ StyleRange[] styleRanges= StyledString.getStyleRanges(); >+ assertEquals(1, styleRanges.length); >+ >+ assertEquals(styleRanges[0], STYLE1, 1, res.length() - 1); >+ } >+ >+ public void testSetStyle19() { >+ String res= "O2O2O2O2O2O2"; >+ >+ StyledString StyledString= new StyledString(); >+ StyledString.append("O2", null); >+ StyledString.append("O2", STYLE1); >+ StyledString.append("O2", STYLE2); >+ StyledString.append("O2", STYLE1); >+ StyledString.append("O2", STYLE2); >+ StyledString.append("O2", null); >+ >+ StyledString.setStyle(1, res.length() - 2, STYLE1); >+ >+ assertEquals(res.length(), StyledString.length()); >+ assertEquals(res, StyledString.getString()); >+ StyleRange[] styleRanges= StyledString.getStyleRanges(); >+ assertEquals(1, styleRanges.length); >+ >+ assertEquals(styleRanges[0], STYLE1, 1, res.length() - 2); >+ } >+ >+ public void testSetStyle20() { >+ String res= "O2O2O2O2O2O2"; >+ >+ StyledString StyledString= new StyledString(); >+ StyledString.append("O2", null); >+ StyledString.append("O2", STYLE1); >+ StyledString.append("O2", STYLE2); >+ StyledString.append("O2", STYLE1); >+ StyledString.append("O2", STYLE2); >+ StyledString.append("O2", null); >+ >+ StyledString.setStyle(3, 6, null); >+ >+ assertEquals(res.length(), StyledString.length()); >+ assertEquals(res, StyledString.getString()); >+ StyleRange[] styleRanges= StyledString.getStyleRanges(); >+ assertEquals(2, styleRanges.length); >+ >+ assertEquals(styleRanges[0], STYLE1, 2, 1); >+ assertEquals(styleRanges[1], STYLE2, 9, 1); >+ } >+ >+ public void testSetStyle21() { >+ String res= "O2O2O2O2O2O2"; >+ >+ StyledString StyledString= new StyledString(); >+ StyledString.append("O2", null); >+ StyledString.append("O2", STYLE1); >+ StyledString.append("O2", STYLE2); >+ StyledString.append("O2", STYLE1); >+ StyledString.append("O2", STYLE2); >+ StyledString.append("O2", null); >+ >+ StyledString.setStyle(3, 6, STYLE1); >+ StyledString.setStyle(3, 6, null); >+ >+ assertEquals(res.length(), StyledString.length()); >+ assertEquals(res, StyledString.getString()); >+ StyleRange[] styleRanges= StyledString.getStyleRanges(); >+ assertEquals(2, styleRanges.length); >+ >+ assertEquals(styleRanges[0], STYLE1, 2, 1); >+ assertEquals(styleRanges[1], STYLE2, 9, 1); >+ } >+ >+ public void testCombination1() { >+ String str1= "One"; >+ String str2= "Two"; >+ >+ String res= str1 + str2 + str1; >+ >+ StyledString StyledString= new StyledString(); >+ StyledString.append(str1, null); >+ StyledString.append(str2, STYLE2); >+ >+ StyledString.setStyle(str1.length(), str2.length(), STYLE1); >+ >+ StyledString.append(str1, STYLE1); >+ >+ assertEquals(res.length(), StyledString.length()); >+ assertEquals(res, StyledString.getString()); >+ StyleRange[] styleRanges= StyledString.getStyleRanges(); >+ assertEquals(1, styleRanges.length); >+ >+ assertEquals(styleRanges[0], STYLE1, str1.length(), str2.length() + str1.length()); >+ } >+ >+ >+ private void assertEquals(StyleRange range, TestStyle style, int offset, int length) { >+ assertEquals(offset, range.start); >+ assertEquals(length, range.length); >+ assertEquals(style.borderStyle, range.borderStyle); >+ } >+ >+ >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 219393
:
90042
|
90043
|
90363
|
90364
|
90747