|
From: Christopher W. <caw...@us...> - 2006-05-05 21:45:10
|
Update of /cvsroot/rubyeclipse/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10971/src/org/rubypeople/rdt/internal/ui/text/ruby Modified Files: AbstractRubyScanner.java Log Message: add ability to set background color on a token basis (ticket #122) Index: AbstractRubyScanner.java =================================================================== RCS file: /cvsroot/rubyeclipse/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/AbstractRubyScanner.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** AbstractRubyScanner.java 12 Apr 2006 21:26:25 -0000 1.6 --- AbstractRubyScanner.java 5 May 2006 21:44:59 -0000 1.7 *************** *** 25,28 **** --- 25,29 ---- private String[] fPropertyNamesColor; + private String[] fPropertyNamesBgColor; private String[] fPropertyNamesBold; private String[] fPropertyNamesItalic; *************** *** 92,95 **** --- 93,97 ---- fPropertyNamesColor = getTokenProperties(); int length = fPropertyNamesColor.length; + fPropertyNamesBgColor = new String[length]; fPropertyNamesBold = new String[length]; fPropertyNamesItalic = new String[length]; *************** *** 98,101 **** --- 100,104 ---- for (int i= 0; i < length; i++) { + fPropertyNamesBgColor[i]= getBGKey(fPropertyNamesColor[i]); fPropertyNamesBold[i]= getBoldKey(fPropertyNamesColor[i]); fPropertyNamesItalic[i]= getItalicKey(fPropertyNamesColor[i]); *************** *** 107,113 **** for (int i = 0; i < length; i++) { if (fNeedsLazyColorLoading) ! addTokenWithProxyAttribute(fPropertyNamesColor[i], fPropertyNamesBold[i], fPropertyNamesItalic[i], fPropertyNamesStrikethrough[i], fPropertyNamesUnderline[i]); else ! addToken(fPropertyNamesColor[i], fPropertyNamesBold[i], fPropertyNamesItalic[i], fPropertyNamesStrikethrough[i], fPropertyNamesUnderline[i]); } --- 110,116 ---- for (int i = 0; i < length; i++) { if (fNeedsLazyColorLoading) ! addTokenWithProxyAttribute(fPropertyNamesColor[i], fPropertyNamesBgColor[i], fPropertyNamesBold[i], fPropertyNamesItalic[i], fPropertyNamesStrikethrough[i], fPropertyNamesUnderline[i]); else ! addToken(fPropertyNamesColor[i], fPropertyNamesBgColor[i], fPropertyNamesBold[i], fPropertyNamesItalic[i], fPropertyNamesStrikethrough[i], fPropertyNamesUnderline[i]); } *************** *** 118,121 **** --- 121,128 ---- return colorKey + PreferenceConstants.EDITOR_BOLD_SUFFIX; } + + protected String getBGKey(String colorKey) { + return colorKey + PreferenceConstants.EDITOR_BG_SUFFIX; + } protected String getItalicKey(String colorKey) { *************** *** 131,136 **** } ! private void addTokenWithProxyAttribute(String colorKey, String boldKey, String italicKey, String strikethroughKey, String underlineKey) { ! fTokenMap.put(colorKey, new Token(createTextAttribute(null, boldKey, italicKey, strikethroughKey, underlineKey))); } --- 138,143 ---- } ! private void addTokenWithProxyAttribute(String colorKey, String bgColorKey, String boldKey, String italicKey, String strikethroughKey, String underlineKey) { ! fTokenMap.put(colorKey, new Token(createTextAttribute(null, null, boldKey, italicKey, strikethroughKey, underlineKey))); } *************** *** 138,142 **** if (fNeedsLazyColorLoading && Display.getCurrent() != null) { for (int i = 0; i < fPropertyNamesColor.length; i++) { ! addToken(fPropertyNamesColor[i], fPropertyNamesBold[i], fPropertyNamesItalic[i], fPropertyNamesStrikethrough[i], fPropertyNamesUnderline[i]); } fNeedsLazyColorLoading = false; --- 145,149 ---- if (fNeedsLazyColorLoading && Display.getCurrent() != null) { for (int i = 0; i < fPropertyNamesColor.length; i++) { ! addToken(fPropertyNamesColor[i], fPropertyNamesBgColor[i], fPropertyNamesBold[i], fPropertyNamesItalic[i], fPropertyNamesStrikethrough[i], fPropertyNamesUnderline[i]); } fNeedsLazyColorLoading = false; *************** *** 144,150 **** } ! private void addToken(String colorKey, String boldKey, String italicKey, String strikethroughKey, String underlineKey) { if (fColorManager != null && colorKey != null && fColorManager.getColor(colorKey) == null) { RGB rgb = PreferenceConverter.getColor(fPreferenceStore, colorKey); if (fColorManager instanceof IColorManagerExtension) { IColorManagerExtension ext = (IColorManagerExtension) fColorManager; --- 151,171 ---- } ! private void addToken(String colorKey, String bgColorKey, String boldKey, String italicKey, String strikethroughKey, String underlineKey) { ! bindColor(colorKey); ! bindColor(bgColorKey); ! ! if (!fNeedsLazyColorLoading) ! fTokenMap.put(colorKey, new Token(createTextAttribute(colorKey, bgColorKey, boldKey, italicKey, strikethroughKey, underlineKey))); ! else { ! Token token = ((Token) fTokenMap.get(colorKey)); ! if (token != null) token.setData(createTextAttribute(colorKey, bgColorKey, boldKey, italicKey, strikethroughKey, underlineKey)); ! } ! } ! ! private void bindColor(String colorKey) { if (fColorManager != null && colorKey != null && fColorManager.getColor(colorKey) == null) { RGB rgb = PreferenceConverter.getColor(fPreferenceStore, colorKey); + if (rgb == PreferenceConverter.COLOR_DEFAULT_DEFAULT) return; + if (fColorManager instanceof IColorManagerExtension) { IColorManagerExtension ext = (IColorManagerExtension) fColorManager; *************** *** 153,163 **** } } - - if (!fNeedsLazyColorLoading) - fTokenMap.put(colorKey, new Token(createTextAttribute(colorKey, boldKey, italicKey, strikethroughKey, underlineKey))); - else { - Token token = ((Token) fTokenMap.get(colorKey)); - if (token != null) token.setData(createTextAttribute(colorKey, boldKey, italicKey, strikethroughKey, underlineKey)); - } } --- 174,177 ---- *************** *** 173,176 **** --- 187,192 ---- * @param colorKey * the color preference key + * @param colorKey + * the color preference key * @param boldKey * the bold preference key *************** *** 184,191 **** * @since 0.9.0 */ ! private TextAttribute createTextAttribute(String colorKey, String boldKey, String italicKey, String strikethroughKey, String underlineKey) { Color color= null; if (colorKey != null) color= fColorManager.getColor(colorKey); int style= fPreferenceStore.getBoolean(boldKey) ? SWT.BOLD : SWT.NORMAL; --- 200,211 ---- * @since 0.9.0 */ ! private TextAttribute createTextAttribute(String colorKey, String bgColorKey, String boldKey, String italicKey, String strikethroughKey, String underlineKey) { Color color= null; if (colorKey != null) color= fColorManager.getColor(colorKey); + + Color bgColor= null; + if (bgColorKey != null) + bgColor= fColorManager.getColor(bgColorKey); int style= fPreferenceStore.getBoolean(boldKey) ? SWT.BOLD : SWT.NORMAL; *************** *** 199,203 **** style |= TextAttribute.UNDERLINE; ! return new TextAttribute(color, null, style); } --- 219,223 ---- style |= TextAttribute.UNDERLINE; ! return new TextAttribute(color, bgColor, style); } *************** *** 213,216 **** --- 233,238 ---- if (fPropertyNamesColor[index].equals(p)) adaptToColorChange(token, event); + if (fPropertyNamesBgColor[index].equals(p)) + adaptToBgColorChange(token, event); else if (fPropertyNamesBold[index].equals(p)) adaptToStyleChange(token, event, SWT.BOLD); *************** *** 239,242 **** --- 261,272 ---- private void adaptToColorChange(Token token, PropertyChangeEvent event) { + adaptToSomeColorChange(token, event, true); + } + + private void adaptToBgColorChange(Token token, PropertyChangeEvent event) { + adaptToSomeColorChange(token, event, false); + } + + private void adaptToSomeColorChange(Token token, PropertyChangeEvent event, boolean isForeground) { RGB rgb = null; *************** *** 263,267 **** if (data instanceof TextAttribute) { TextAttribute oldAttr = (TextAttribute) data; ! token.setData(new TextAttribute(color, oldAttr.getBackground(), oldAttr.getStyle())); } } --- 293,306 ---- if (data instanceof TextAttribute) { TextAttribute oldAttr = (TextAttribute) data; ! Color foreGround; ! Color backGround; ! if (!isForeground) { ! foreGround = oldAttr.getForeground(); ! backGround = color; ! } else { ! foreGround = color; ! backGround = oldAttr.getBackground(); ! } ! token.setData(new TextAttribute(foreGround, backGround, oldAttr.getStyle())); } } *************** *** 272,276 **** int length = fPropertyNamesColor.length; for (int i = 0; i < length; i++) { ! if (property.equals(fPropertyNamesColor[i]) || property.equals(fPropertyNamesBold[i]) || property.equals(fPropertyNamesItalic[i]) || property.equals(fPropertyNamesStrikethrough[i]) || property.equals(fPropertyNamesUnderline[i])) return i; } } --- 311,315 ---- int length = fPropertyNamesColor.length; for (int i = 0; i < length; i++) { ! if (property.equals(fPropertyNamesColor[i]) || property.equals(fPropertyNamesBgColor[i]) || property.equals(fPropertyNamesBold[i]) || property.equals(fPropertyNamesItalic[i]) || property.equals(fPropertyNamesStrikethrough[i]) || property.equals(fPropertyNamesUnderline[i])) return i; } } |