开发者

Color of "mark occurrences" in vertical bar in Netbeans

When you select a variable in NetBeans 7, working with PHP (works with other langua开发者_JAVA百科ges too), the program highlights all the places inside the file where the same variable is used.

I know how to change the color of the actual highlighted text (in Options->Fonts & Colors->Syntax->PHP->Mark Occurrences), but NetBeans also marks the matches in a vertical bar to the right of the editor scrollbar. This is the color I want to change, because this bar also marks the diffs when using version control, and the "mark occurrences" matches are not very clear when there's a lot of diffs.


First I got the RGB color codes I needed to find, 175, 172, 102 (html #AFAC66)

Apparently, the color that is used to highlight occurrences in the vertical bar is hard coded in the Netbeans sources, so it is not possible to change it the settings or any configuration file.

Here is how the vertical bar looks by default when marking occurrences:

Color of "mark occurrences" in vertical bar in Netbeans

The PHP module gets the highlighting color from the class:
org.netbeans.modules.csl.editor.semantic.MarkOccurrencesHighlighter.java
The mentioned class is located in the module/jar:
$installation_folder/netbeans-8.0/ide/modules/org-netbeans-modules-csl-api.jar

You view the source of that class in http://hg.netbeans.org/, or you could use a decompiler.

To change the color, you could get the source and recompile the module, or you could just simply modify the bytecode. Personally, because I only wanted modify 3 values(RGB), I chose to alter the bytecode. To do this you can follow the next steps:

  1. Make a copy of org-netbeans-modules-csl-api.jar in another folder (I’m going to refer to that folder as $folder).
  2. Extract the class org.netbeans.modules.csl.editor.semantic.MarkOccurrencesHighlighter.class from org-netbeans-modules-csl-api.jar. For simplicity, be sure that you extract the package/folder hierarchy in the same folder ($folder) where the copy of the jar is located, so that you get:
    $folder/org/netbeans/modules/csl/editor/semantic/MarkOccurrencesHighlighter.class
    $folder/org-netbeans-modules-csl-api.jar
  3. Open the class in a decompiler, I used JD ( http://jd.benow.ca/ )
  4. Locate the code you want to modify (ES_COLOR):

    Color of "mark occurrences" in vertical bar in Netbeans

  5. Open the class in a bytecode editor, I used reJ ( http://rejava.sourceforge.net/ ), and locate the values 175, 172, 102. (You will have to change the opcode bipush to sipush if you want to use a value greater than 127)

    Color of "mark occurrences" in vertical bar in Netbeans

  6. Modify the values, I chose blue(0,0,255):

    Color of "mark occurrences" in vertical bar in Netbeans

  7. Save the modified .class, and verify with the decompiler that the values have been changed:

    Color of "mark occurrences" in vertical bar in Netbeans

  8. In a terminal or command line, navigate to $folder, and execute the following command to replace the modified class in the jar:
    jar -uf org-netbeans-modules-csl-api.jar org/netbeans/modules/csl/editor/semantic/MarkOccurrencesHighlighter.class
  9. Now, you can use the decompiler to verify that the jar was indeed modified with the altered .class
  10. Finally, you can copy the modified jar/module to the original location $installation_folder/netbeans-8.0/ide/modules/ or you can copy it to the $user_directory/modules folder. The latter seems better as it doesn’t modify the installation.
  11. Start Netbeans and enjoy the new color.

Here is how the vertical bar looks now when marking occurrences:

Color of "mark occurrences" in vertical bar in Netbeans

If you want to change the color that is used to highlight occurrences in the vertical bar for the Java module, you would have to modify another class org.netbeans.modules.java.editor.semantic.MarkOccurrencesHighlighter.java located inside $installation_folder/netbeans-8.0/java/modules/org-netbeans-modules-java-editor.jar, following the same steps.

If I missed something, or if there is an easier way to alter the colors shown in the vertical bar, feel free to add it.

(Tested with Netbeans 8.0)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜