1 19 20 21 package org.netbeans.modules.properties.syntax; 22 23 24 import java.awt.Font ; 25 import java.awt.Color ; 26 import java.awt.SystemColor ; 27 import java.util.*; 28 29 import org.netbeans.editor.AcceptorFactory; 30 import org.netbeans.editor.Settings; 31 import org.netbeans.editor.SettingsNames; 32 import org.netbeans.editor.SettingsUtil; 33 import org.netbeans.editor.Coloring; 34 import org.netbeans.editor.SettingsDefaults; 35 import org.netbeans.editor.BaseKit; 36 import org.netbeans.editor.TokenContext; 37 import org.netbeans.editor.TokenContextPath; 38 import org.netbeans.editor.TokenCategory; 39 40 41 46 public class PropertiesSettingsInitializer extends Settings.AbstractInitializer { 47 48 49 public static final String NAME = "properties-settings-initializer"; 50 51 52 53 public PropertiesSettingsInitializer() { 54 super(NAME); 55 } 56 57 58 59 public void updateSettingsMap(Class kitClass, Map settingsMap) { 60 61 if(kitClass == BaseKit.class) { 63 new PropertiesTokenColoringInitializer().updateSettingsMap(kitClass, settingsMap); 64 } else if(kitClass == PropertiesKit.class) { 65 settingsMap.put(PropertiesOptions.SHADOW_TABLE_CELL_PROP, new Color (SystemColor.controlHighlight.getRGB())); 67 68 settingsMap.put(SettingsNames.ABBREV_MAP, new TreeMap()); 69 70 settingsMap.put(SettingsNames.IDENTIFIER_ACCEPTOR, AcceptorFactory.JAVA_IDENTIFIER); 71 72 SettingsUtil.updateListSetting(settingsMap, SettingsNames.TOKEN_CONTEXT_LIST, 73 new TokenContext[] { 74 PropertiesTokenContext.context 75 } 76 ); 77 } 78 } 79 80 81 82 private static class PropertiesTokenColoringInitializer extends SettingsUtil.TokenColoringInitializer { 83 84 85 private static final Font boldFont = SettingsDefaults.defaultFont.deriveFont(Font.BOLD); 86 87 private static final Font italicFont = SettingsDefaults.defaultFont.deriveFont(Font.ITALIC); 88 89 90 private static final Coloring keyColoring = new Coloring(boldFont, Coloring.FONT_MODE_APPLY_STYLE, Color.blue, null); 91 92 private static final Coloring valueColoring = new Coloring(null, Color.magenta, null); 93 94 private static final Coloring commentColoring = new Coloring(null, Color.gray, null); 96 97 private static final Coloring emptyColoring = new Coloring(null, null, null); 98 99 100 101 public PropertiesTokenColoringInitializer() { 102 super(PropertiesTokenContext.context); 103 } 104 105 106 107 public Object getTokenColoring(TokenContextPath tokenContextPath, 108 TokenCategory tokenIDOrCategory, boolean printingSet) { 109 110 if(!printingSet) { 111 int tokenID = tokenIDOrCategory.getNumericID(); 112 113 if(tokenID == PropertiesTokenContext.KEY_ID) { 114 return keyColoring; 115 } else if(tokenID == PropertiesTokenContext.VALUE_ID) { 116 return valueColoring; 117 } else if(tokenID == PropertiesTokenContext.LINE_COMMENT_ID) { 118 return commentColoring; 119 } else if(tokenID == PropertiesTokenContext.EQ_ID 120 || tokenID == PropertiesTokenContext.TEXT_ID) { 121 return emptyColoring; 122 } 123 } else { return SettingsUtil.defaultPrintColoringEvaluator; 125 } 126 127 return null; 128 } 129 130 } 132 } 133 | Popular Tags |