1 19 20 package org.netbeans.modules.editor.settings.storage; 21 22 import java.awt.Color ; 23 import java.net.URL ; 24 import java.util.Collection ; 25 import javax.swing.text.AttributeSet ; 26 import javax.swing.text.StyleConstants ; 27 import org.netbeans.api.editor.mimelookup.MimeLookup; 28 import org.netbeans.api.editor.mimelookup.MimePath; 29 import org.netbeans.api.editor.settings.EditorStyleConstants; 30 import org.netbeans.api.editor.settings.FontColorSettings; 31 import org.netbeans.core.startup.Main; 32 import org.netbeans.junit.NbTestCase; 33 import org.netbeans.modules.editor.settings.storage.api.EditorSettings; 34 import org.openide.util.Lookup; 35 36 40 public class FontColorSettingsImplTest extends NbTestCase { 41 42 public FontColorSettingsImplTest(String testName) { 43 super(testName); 44 } 45 46 protected void setUp() throws Exception { 47 super.setUp(); 48 49 EditorTestLookup.setLookup( 50 new URL [] { 51 getClass().getClassLoader().getResource( 52 "org/netbeans/modules/editor/settings/storage/test-layer.xml"), 53 getClass().getClassLoader().getResource( 54 "org/netbeans/modules/editor/settings/storage/layer.xml"), 55 }, 56 getWorkDir(), 57 new Object [] {}, 58 getClass().getClassLoader() 59 ); 60 61 Main.initializeURLFactory(); 65 } 66 67 public void testDefaults() { 68 MimePath mimePath = MimePath.parse("text/x-type-B"); 69 70 checkSingleAttribute(mimePath, "test-inheritance-coloring-1", StyleConstants.Background, 0xAA0000); 71 checkSingleAttribute(mimePath, "test-inheritance-coloring-2", StyleConstants.Background, 0xAA0000); 72 73 checkSingleAttribute(mimePath, "test-inheritance-coloring-A", StyleConstants.Background, 0xABCDEF); 74 checkSingleAttribute(mimePath, "test-inheritance-coloring-B", StyleConstants.Background, 0xABCDEF); 75 76 checkSingleAttribute(mimePath, "test-inheritance-coloring-X", StyleConstants.Background, 0xBB0000); 77 checkSingleAttribute(mimePath, "test-inheritance-coloring-Y", StyleConstants.Background, 0xBB0000); 78 } 79 80 public void testAllLanguagesTheCrapWay() { 81 Collection <AttributeSet > colorings = EditorSettings.getDefault().getFontColorSettings(new String [0]).getAllFontColors(EditorSettingsImpl.DEFAULT_PROFILE); 82 assertNotNull("Can't get colorings for all languages", colorings); 83 84 AttributeSet attribs = null; 85 for(AttributeSet coloring : colorings) { 86 String name = (String ) coloring.getAttribute(StyleConstants.NameAttribute); 87 if (name != null && name.equals("test-all-languages-set-all")) { 88 attribs = coloring; 89 break; 90 } 91 } 92 93 assertNotNull("Can't find test-all-languages-set-all coloring", attribs); 94 assertEquals("Wrong color", new Color (0x0A0B0C), attribs.getAttribute(StyleConstants.Background)); 95 assertEquals("Wrong color", new Color (0x0D0E0F), attribs.getAttribute(StyleConstants.Foreground)); 96 assertEquals("Wrong color", new Color (0x010203), attribs.getAttribute(StyleConstants.Underline)); 97 assertEquals("Wrong color", new Color (0x040506), attribs.getAttribute(StyleConstants.StrikeThrough)); 98 assertEquals("Wrong color", new Color (0x070809), attribs.getAttribute(EditorStyleConstants.WaveUnderlineColor)); 99 } 100 101 public void testAllLanguagesTheStandardWay() { 102 checkSingleAttribute(MimePath.EMPTY, "test-all-languages-set-all", StyleConstants.Background, 0x0A0B0C); 103 checkSingleAttribute(MimePath.EMPTY, "test-all-languages-set-all", StyleConstants.Foreground, 0x0D0E0F); 104 checkSingleAttribute(MimePath.EMPTY, "test-all-languages-set-all", StyleConstants.Underline, 0x010203); 105 checkSingleAttribute(MimePath.EMPTY, "test-all-languages-set-all", StyleConstants.StrikeThrough, 0x040506); 106 checkSingleAttribute(MimePath.EMPTY, "test-all-languages-set-all", EditorStyleConstants.WaveUnderlineColor, 0x070809); 107 } 108 109 private void checkSingleAttribute(MimePath mimePath, String coloringName, Object attributeKey, int rgb) { 110 Lookup lookup = MimeLookup.getLookup(mimePath); 111 112 FontColorSettings fcs = lookup.lookup(FontColorSettings.class); 113 assertNotNull("Can't find FontColorSettings", fcs); 114 115 AttributeSet attribs = fcs.getTokenFontColors(coloringName); 116 assertNotNull("Can't find " + coloringName + " coloring", attribs); 117 assertEquals("Wrong color", new Color (rgb), attribs.getAttribute(attributeKey)); 118 } 119 120 } 121 | Popular Tags |