Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jdt-ui-dev] Customizing java syntax colors [patch]

Hello all,

Attached is a patch and a sample color configuration file for java syntax
highlighting.  To install, change to the
<eclipse_home>/plugins/org.eclipse.jdt.ui directory, unzip the source (if
you haven't already), apply the patch, compile, update jdt.jar.  Edit the
colors.properties file to your liking and place it in the
<eclipse_home>/plugins/org.eclipse.jdt.ui directory.  Then restart eclipse.

Regards,
Jason

P.S.
To the Moderator: It would be much better to state up front that only list
subscribers can post to the list, rather than accepting messages for
moderation and then rejecting them hours later.
-- 
Jason Day                                       jasonday at
http://jasonday.home.att.net                    mediaone dot net
 
"Of course I'm paranoid, everyone is trying to kill me."
    -- Weyoun-6, Star Trek: Deep Space 9
# Java Editor color definitions.
# All keys below are defined in the file
#     org/eclipse/jdt/ui/text/IJavaColorConstants.java
# The values are the RGB values of the desired color in hex: RRGGBB

# IJavaColorConstants.JAVA_KEYWORD
# The color key for Java keywords in Java code.
java_keyword = 2A00FF

# IJavaColorConstants.JAVA_TYPE
# The color key for the Java built-in types such as int and char in Java code.
java_type = 2A00FF

# IJavaColorConstants.JAVA_STRING
# The color key for string and character literals in Java code.
java_string = 7F0055

# IJavaColorConstants.JAVA_DEFAULT
# The color key for everthing in Java code for which no other color is
# specified.
java_default = 000000

# IJavaColorConstants.JAVA_MULTI_LINE_COMMENT
# The color key for multi-line comments in Java code.
java_multi_line_comment = 3F7F5F

# IJavaColorConstants.JAVA_SINGLE_LINE_COMMENT
# The color key for single-line comments in Java code.
java_single_line_comment = 3F7F5F


# IJavaColorConstants.JAVADOC_KEYWORD
# The color key for JavaDoc keywords (<code>@foo</code>) in JavaDoc comments.
javadoc_keyword = 7F9FBF

# IJavaColorConstants.JAVADOC_TAG
# The color key for HTML tags (<code>&lt;foo&gt;</code>) in JavaDoc comments.
javadoc_tag = 7F7F9F

# IJavaColorConstants.JAVADOC_LINK
# The color key for JavaDoc links (<code>{foo}</code>) in JavaDoc comments.
javadoc_link = 3F3FBF

# IJavaColorConstants.JAVADOC_DEFAULT
# The color key for everthing in JavaDoc comments for which no other color
# is specified.
javadoc_default = 3F5FBF
diff -ur org.orig/eclipse/jdt/internal/ui/text/JavaColorManager.java org/eclipse/jdt/internal/ui/text/JavaColorManager.java
--- org.orig/eclipse/jdt/internal/ui/text/JavaColorManager.java	Wed Sep 26 14:16:28 2001
+++ org/eclipse/jdt/internal/ui/text/JavaColorManager.java	Mon Nov 12 14:46:00 2001
@@ -4,7 +4,9 @@
  * (c) Copyright IBM Corp. 2000, 2001.
  * All Rights Reserved.
  */
- 
+
+import java.net.URL;
+import java.util.Properties;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
@@ -16,10 +18,13 @@
 import org.eclipse.jdt.ui.text.IColorManager;
 import org.eclipse.jdt.ui.text.IJavaColorConstants;
 
+import org.eclipse.jdt.internal.ui.JavaPlugin;
+
 /**
  * Java color manager.
  */
 public class JavaColorManager implements IColorManager {
+	public static final String COLORS_PROPERTIES = "colors.properties";
 	
 	protected Map fKeyTable= new HashMap(10);
 	protected Map fDisplayTable= new HashMap(2);
@@ -82,26 +87,50 @@
 		return color;
 	}
 	protected void initializeColorMapping() {
-		
-//		put(IJavaColorConstants.JAVA_MULTI_LINE_COMMENT, new RGB(42, 127, 170));
-//		put(IJavaColorConstants.JAVA_SINGLE_LINE_COMMENT, new RGB(42, 127, 170));
-		put(IJavaColorConstants.JAVA_MULTI_LINE_COMMENT, new RGB(63, 127, 95));
-		put(IJavaColorConstants.JAVA_SINGLE_LINE_COMMENT, new RGB(63, 127, 95));
-		
-		put(IJavaColorConstants.JAVA_KEYWORD, new RGB(127, 0, 85));
-		put(IJavaColorConstants.JAVA_TYPE, new RGB(127, 0, 85));
-		put(IJavaColorConstants.JAVA_STRING, new RGB(42, 0, 255));
-		put(IJavaColorConstants.JAVA_DEFAULT, new RGB(0, 0, 0));
-		
-//		put(IJavaColorConstants.JAVADOC_KEYWORD, new RGB(127, 159, 95));
-//		put(IJavaColorConstants.JAVADOC_TAG, new RGB(127, 159, 95));
-//		put(IJavaColorConstants.JAVADOC_LINK, new RGB(159, 191, 95));
-//		put(IJavaColorConstants.JAVADOC_DEFAULT, new RGB(63, 127, 95));
-		
-		put(IJavaColorConstants.JAVADOC_KEYWORD, new RGB(127, 159, 191));
-		put(IJavaColorConstants.JAVADOC_TAG, new RGB(127, 127, 159));
-		put(IJavaColorConstants.JAVADOC_LINK, new RGB(63, 63, 191));
-		put(IJavaColorConstants.JAVADOC_DEFAULT, new RGB(63, 95, 191));
+		// Locate and open the colors properties file
+		Properties props = null;
+		try {
+			URL url = new URL (JavaPlugin.getDefault().getDescriptor().getInstallURL(), COLORS_PROPERTIES);
+			if (url != null) {
+				props = new java.util.Properties();
+				props.load (url.openStream());
+			}
+		}
+		catch (java.io.IOException e) {
+			JavaPlugin.log(e);
+		}
+
+		// If the colors properties file was found, then initialize the
+		// color map with the colors defined in the file.
+		if (props != null) {
+			for (Iterator iter = props.keySet().iterator(); iter.hasNext(); ) {
+				String key = (String)iter.next();
+				String s = (String)props.get (key);
+				try {
+					int rgb = Integer.parseInt (s, 16);
+					java.awt.Color c = new java.awt.Color (rgb);
+					put(key, new RGB(c.getRed(), c.getGreen(), c.getBlue()));
+				}
+				catch (NumberFormatException e) {
+					JavaPlugin.log (e);
+				}
+			}
+		}
+		else {
+			// Properties file not found, use defaults
+			put(IJavaColorConstants.JAVA_MULTI_LINE_COMMENT, new RGB(63, 127, 95));
+			put(IJavaColorConstants.JAVA_SINGLE_LINE_COMMENT, new RGB(63, 127, 95));
+		
+			put(IJavaColorConstants.JAVA_KEYWORD, new RGB(127, 0, 85));
+			put(IJavaColorConstants.JAVA_TYPE, new RGB(127, 0, 85));
+			put(IJavaColorConstants.JAVA_STRING, new RGB(42, 0, 255));
+			put(IJavaColorConstants.JAVA_DEFAULT, new RGB(0, 0, 0));
+		
+			put(IJavaColorConstants.JAVADOC_KEYWORD, new RGB(127, 159, 191));
+			put(IJavaColorConstants.JAVADOC_TAG, new RGB(127, 127, 159));
+			put(IJavaColorConstants.JAVADOC_LINK, new RGB(63, 63, 191));
+			put(IJavaColorConstants.JAVADOC_DEFAULT, new RGB(63, 95, 191));
+		}
 	}
 	public void put(String key, RGB rgb) {
 		fKeyTable.put(key, rgb);

Back to the top