本文整理汇总了Java中org.netbeans.api.editor.mimelookup.MimePath.parse方法的典型用法代码示例。如果您正苦于以下问题:Java MimePath.parse方法的具体用法?Java MimePath.parse怎么用?Java MimePath.parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.netbeans.api.editor.mimelookup.MimePath
的用法示例。
在下文中一共展示了MimePath.parse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testRemoveAll
import org.netbeans.api.editor.mimelookup.MimePath; //导入方法依赖的package包/类
public void testRemoveAll() throws IOException {
MimePath mimePath = MimePath.parse("text/x-type-A");
CodeTemplateSettingsImpl ctsi = CodeTemplateSettingsImpl.get(mimePath);
Map<String, CodeTemplateDescription> map = ctsi.getCodeTemplates();
assertNotNull("CodeTemplates map should not be null", map);
assertTrue("Code templates map should not be empty", map.size() > 0);
// Remove all code templates
ctsi.setCodeTemplates(Collections.<String, CodeTemplateDescription>emptyMap());
// Force loading from the files
//Map<String, CodeTemplateDescription> loadedMap = CodeTemplatesStorage.load(mimePath, false);
StorageImpl<String, CodeTemplateDescription> storage = new StorageImpl<String, CodeTemplateDescription>(new CodeTemplatesStorage(), null);
Map<String, CodeTemplateDescription> loadedMap = storage.load(mimePath, null, false);
assertNotNull("Can't load the map", loadedMap);
assertEquals("Some template were not removed", 0, loadedMap.size());
}
示例2: testInheritanceForEmbedded
import org.netbeans.api.editor.mimelookup.MimePath; //导入方法依赖的package包/类
public void testInheritanceForEmbedded() {
MimePath mimePath = MimePath.parse("text/x-type-B/text/x-type-A");
FontColorSettings fcs = MimeLookup.getLookup(mimePath).lookup(FontColorSettings.class);
AttributeSet attribsTypeA = fcs.getTokenFontColors("test-inheritance-typeA-specific");
assertNotNull("Can't find coloring defined for text/x-type-A", attribsTypeA);
assertEquals("Wrong bgColor in coloring defined for text/x-type-A", new Color(0xAA0000), attribsTypeA.getAttribute(StyleConstants.Background));
AttributeSet attribsTypeB = fcs.getTokenFontColors("test-inheritance-typeB-specific");
assertNull("Shouldn't find coloring defined for text/x-type-B", attribsTypeB);
// assertEquals("Wrong bgColor in coloring defined for text/x-type-B", new Color(0xBB0000), attribsTypeB.getAttribute(StyleConstants.Background));
AttributeSet attribsBoth = fcs.getTokenFontColors("test-inheritance-typeA-typeB");
assertNotNull("Can't find coloring defined for both typeA and typeB", attribsBoth);
assertEquals("Wrong bgColor in coloring defined for both typeA typeB", new Color(0xAAAA00), attribsBoth.getAttribute(StyleConstants.Background));
AttributeSet attribsEmbedded = fcs.getTokenFontColors("test-inheritance-typeA-embedded-in-typeB");
assertNotNull("Can't find coloring defined for typeA embedded in typeB", attribsEmbedded);
assertEquals("Wrong bgColor in coloring defined for typeA embedded in typeB", new Color(0xAABB00), attribsEmbedded.getAttribute(StyleConstants.Background));
}
示例3: getFullMimePath
import org.netbeans.api.editor.mimelookup.MimePath; //导入方法依赖的package包/类
private static MimePath getFullMimePath(Document document, int offset) {
String langPath = null;
if (document instanceof AbstractDocument) {
AbstractDocument adoc = (AbstractDocument)document;
adoc.readLock();
try {
List<TokenSequence<?>> list = TokenHierarchy.get(document).embeddedTokenSequences(offset, true);
if (list.size() > 1) {
langPath = list.get(list.size() - 1).languagePath().mimePath();
}
} finally {
adoc.readUnlock();
}
}
if (langPath == null) {
langPath = NbEditorUtilities.getMimeType(document);
}
if (langPath != null) {
return MimePath.parse(langPath);
} else {
return null;
}
}
示例4: getCustomActions
import org.netbeans.api.editor.mimelookup.MimePath; //导入方法依赖的package包/类
protected Action[] getCustomActions() {
MimePath mimePath = MimePath.parse(getContentType());
Preferences prefs = MimeLookup.getLookup(mimePath).lookup(Preferences.class);
@SuppressWarnings("unchecked")
List<? extends Action> customActions = (List<? extends Action>) SettingsConversions.callFactory(
prefs, mimePath, EditorPreferencesKeys.CUSTOM_ACTION_LIST, null); //NOI18N
if (LOG.isLoggable(Level.FINE)) {
LOG.fine(EditorPreferencesKeys.CUSTOM_ACTION_LIST + " for '" + getContentType() + "' {"); //NOI18N
if (customActions != null) {
for(Action a : customActions) {
LOG.fine(" " + a); //NOI18N
}
}
LOG.fine("} End of " + EditorPreferencesKeys.CUSTOM_ACTION_LIST + " for '" + getContentType() + "'"); //NOI18N
}
return customActions == null ? null : customActions.toArray(new Action[customActions.size()]);
}
示例5: testClassLookuping
import org.netbeans.api.editor.mimelookup.MimePath; //导入方法依赖的package包/类
public void testClassLookuping() throws IOException{
MimePath mp = MimePath.parse("text/x-java/text/html/text/xml");
Lookup lookup = MimeLookup.getLookup(mp);
PopupActions popup = (PopupActions) lookup.lookup(PopupActions.class);
List list = popup.getPopupActions();
checkPopupItemPresence(lookup, RenameAction.class, true);
gc();
int size = assertSize("", Arrays.asList( new Object[] {lookup} ), 10000000, getFilter());
for (int i=0; i<30; i++){
popup = (PopupActions) lookup.lookup(PopupActions.class);
list = popup.getPopupActions();
checkPopupItemPresence(lookup, RenameAction.class, true);
}
gc();
assertSize("", size + 20, lookup);
}
示例6: reindent
import org.netbeans.api.editor.mimelookup.MimePath; //导入方法依赖的package包/类
public void reindent() throws BadLocationException {
if(context == null)
return;
MimePath mimePath = MimePath.parse (context.mimePath ());
if(mimePath == null)
return;
Language language = Language.find (mimePath.getMimeType (0));
if(language == null)
return;
LanguagePath languagePath = LanguagePath.get (language);
if(languagePath == null)
return;
for (int i = 1; i < mimePath.size(); i++) {
languagePath = languagePath.embedded(Language.find(mimePath.getMimeType(i)));
}
XMLLexerFormatter formatter = new XMLLexerFormatter(languagePath);
formatter.reformat(context);
}
示例7: getFormatter
import org.netbeans.api.editor.mimelookup.MimePath; //导入方法依赖的package包/类
private synchronized Formatter getFormatter() {
if (formatter == null) {
// XXX: Carefull here, generally context.mimePath() != mimeType. This
// task's factory was created for a top level language (mimeType), but the task
// itself can be used for an embedded language.
// If the task is used for the document itself (not an embedded
// section) Context.mimePath() == mimeType.
// However, if it is used for an embedded section the Context.mimePath() gives
// the mime path (languege path) of that section. Which is generally
// something like 'application/x-httpd-eruby/text/x-ruby'. While the
// task was registered for 'text/x-ruby'.
// Therefore with the __current__ implementation of MimeLookupInitializerImpl
// we can simply take the last component of Context.mimePath().
MimePath mimePath = MimePath.parse(context.mimePath());
mimeType = mimePath.size() > 1 ? mimePath.getMimeType(mimePath.size() - 1) : mimePath.getPath();
Language language = LanguageRegistry.getInstance().getLanguageByMimeType(mimeType);
formatter = language.getFormatter();
}
return formatter;
}
示例8: setMenu
import org.netbeans.api.editor.mimelookup.MimePath; //导入方法依赖的package包/类
protected @Override void setMenu(){
super.setMenu();
JTextComponent c = getComponent();
MimePath mimePath = c == null ? MimePath.EMPTY : MimePath.parse(DocumentUtilities.getMimeType(c));
Preferences prefs = MimeLookup.getLookup(mimePath).lookup(Preferences.class);
boolean visible = prefs.getBoolean(SimpleValueNames.TOOLBAR_VISIBLE_PROP, EditorPreferencesDefaults.defaultToolbarVisible);
SHOW_TOOLBAR_MENU.setState(visible);
}
示例9: getLookup
import org.netbeans.api.editor.mimelookup.MimePath; //导入方法依赖的package包/类
/** You can call it, but it's probably not what you want. */
public @Override Lookup getLookup(MimePath mimePath) {
synchronized (MAP) {
List<String> paths = Collections.singletonList(mimePath.getPath());
try {
Method m = MimePath.class.getDeclaredMethod("getInheritedPaths", String.class, String.class); //NOI18N
m.setAccessible(true);
@SuppressWarnings("unchecked")
List<String> ret = (List<String>) m.invoke(mimePath, null, null);
paths = ret;
} catch (Exception e) {
throw new IllegalStateException("Can't call org.netbeans.api.editor.mimelookup.MimePath.getInheritedPaths method.", e); //NOI18N
}
List<Lookup> lookups = new ArrayList<Lookup>(paths.size());
for(String path : paths) {
MimePath mp = MimePath.parse(path);
Lkp lookup = MAP.get(mp);
if (lookup == null) {
lookup = new Lkp();
MAP.put(mp, lookup);
}
lookups.add(lookup);
}
return new ProxyLookup(lookups.toArray(new Lookup [lookups.size()]));
}
}
示例10: testHierarchyRootInheritance
import org.netbeans.api.editor.mimelookup.MimePath; //导入方法依赖的package包/类
public void testHierarchyRootInheritance() throws Exception {
// Create the mime path folders and add some instance
TestUtilities.createFile(getWorkDir(), "Editors/text/x-jsp/text/x-java/");
TestUtilities.createFile(getWorkDir(), "Editors/org-netbeans-modules-editor-mimelookup-impl-DummySettingImpl.instance");
TestUtilities.sleepForWhile();
{
Lookup lookup = new SwitchLookup(MimePath.parse(""));
Collection instances = lookup.lookupAll(DummySetting.class);
assertEquals("Wrong number of instances", 1, instances.size());
assertEquals("Wrong instance", DummySettingImpl.class, instances.iterator().next().getClass());
}
{
Lookup jspLookup = new SwitchLookup(MimePath.parse("text/x-jsp"));
Collection jspInstances = jspLookup.lookupAll(DummySetting.class);
assertEquals("Wrong number of instances", 1, jspInstances.size());
assertEquals("Wrong instance", DummySettingImpl.class, jspInstances.iterator().next().getClass());
}
{
Lookup javaLookup = new SwitchLookup(MimePath.parse("text/x-jsp/text/x-java"));
Collection javaInstances = javaLookup.lookupAll(DummySetting.class);
assertEquals("Wrong number of instances", 1, javaInstances.size());
assertEquals("Wrong instance", DummySettingImpl.class, javaInstances.iterator().next().getClass());
}
}
示例11: findTextModel
import org.netbeans.api.editor.mimelookup.MimePath; //导入方法依赖的package包/类
private DocumentModel findTextModel(JTextComponent comp) {
String mime = DocumentUtilities.getMimeType(comp);
MimePath mp = MimePath.parse(mime);
if (!"text/xml".equals(mp.getInheritedType())) { // NOI18N
return null;
}
try {
DocumentModel mod = DocumentModel.getDocumentModel(comp.getDocument());
return mod;
} catch (DocumentModelException ex) {
Exceptions.printStackTrace(ex);
return null;
}
}
示例12: getKeymap
import org.netbeans.api.editor.mimelookup.MimePath; //导入方法依赖的package包/类
public MultiKeymap getKeymap() {
synchronized (KEYMAPS_AND_ACTIONS_LOCK) {
MimePath mimePath = MimePath.parse(getContentType());
MultiKeymap km = (MultiKeymap)kitKeymaps.get(mimePath);
if (km == null) { // keymap not yet constructed
// construct new keymap
km = new MultiKeymap("Keymap for " + mimePath.getPath()); // NOI18N
// retrieve key bindings for this kit and super kits
KeyBindingSettings kbs = MimeLookup.getLookup(mimePath).lookup(KeyBindingSettings.class);
List<org.netbeans.api.editor.settings.MultiKeyBinding> mkbList = kbs.getKeyBindings();
List<JTextComponent.KeyBinding> editorMkbList = new ArrayList<JTextComponent.KeyBinding>();
for(org.netbeans.api.editor.settings.MultiKeyBinding mkb : mkbList) {
List<KeyStroke> keyStrokes = mkb.getKeyStrokeList();
MultiKeyBinding editorMkb = new MultiKeyBinding(keyStrokes.toArray(new KeyStroke[keyStrokes.size()]), mkb.getActionName());
editorMkbList.add(editorMkb);
}
// go through all levels and collect key bindings
km.load(editorMkbList.toArray(new JTextComponent.KeyBinding[editorMkbList.size()]), getActionMap());
km.setDefaultAction(getActionMap().get(defaultKeyTypedAction));
kitKeymaps.put(mimePath, km);
}
return km;
}
}
示例13: executeInstallActions
import org.netbeans.api.editor.mimelookup.MimePath; //导入方法依赖的package包/类
protected void executeInstallActions(JEditorPane c) {
MimePath mimePath = MimePath.parse(getContentType());
Preferences prefs = MimeLookup.getLookup(mimePath).lookup(Preferences.class);
@SuppressWarnings("unchecked")
List<String> actionNamesList = (List<String>) SettingsConversions.callFactory(
prefs, mimePath, EditorPreferencesKeys.KIT_INSTALL_ACTION_NAME_LIST, null); //NOI18N
List<Action> actionsList = translateActionNameList(actionNamesList); // translate names to actions
for (Action a : actionsList) {
a.actionPerformed(new ActionEvent(c, ActionEvent.ACTION_PERFORMED, "")); // NOI18N
}
}
示例14: testUserChangesOverrideDefaults
import org.netbeans.api.editor.mimelookup.MimePath; //导入方法依赖的package包/类
public void testUserChangesOverrideDefaults() {
MimePath mimePath = MimePath.parse("text/x-type-A");
CodeTemplateSettingsImpl ctsi = CodeTemplateSettingsImpl.get(mimePath);
Map<String, CodeTemplateDescription> map = ctsi.getCodeTemplates();
assertNotNull("CodeTemplates map should not be null", map);
assertEquals("Wrong number of code templates", 2, map.size());
checkCodeTemplate(map, "module1", null, "module1", null);
checkCodeTemplate(map, "user1", null, "user1", null);
CodeTemplateDescription ct = map.get("module2");
assertNull("'module2' code template should be removed", ct);
}
示例15: testMultipleFiles
import org.netbeans.api.editor.mimelookup.MimePath; //导入方法依赖的package包/类
public void testMultipleFiles() throws IOException {
EditorSettingsStorage<Collection<KeyStroke>, MultiKeyBinding> ess = EditorSettingsStorage.<Collection<KeyStroke>, MultiKeyBinding>get(KeyMapsStorage.ID);
MimePath mimePath = MimePath.parse("text/x-type-A");
Map<Collection<KeyStroke>, MultiKeyBinding> keybindings = ess.load(mimePath, "MyProfileXyz", true); //NOI18N
assertNotNull("Keybindings map should not be null", keybindings);
assertEquals("Wrong number of keybindings", 5, keybindings.size());
checkMapConsistency(keybindings);
checkKeybinding(keybindings, "test-action-1", "D-1 A");
checkKeybinding(keybindings, "test-action-2", "D-2 A");
checkKeybinding(keybindings, "test-action-2", "D-2 B");
checkKeybinding(keybindings, "test-action-4", "D-4 B");
checkKeybinding(keybindings, "test-action-5", "D-5 B");
}