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