2

我在 NetBeans 项目中使用 Flamingo Ribbon Bar,但我遇到了一个主要问题:有时(对不起,我不能更具体,因为我真的不知道如何始终如一地复制它)我得到以下异常:

Java.lang.IllegalArgumentException: No interpolator found for java.lang.Float:java.lang.Float
at org.pushingpixels.trident.TimelinePropertyBuilder.getFieldInfo(TimelinePropertyBuilder.java:257)
at org.pushingpixels.trident.Timeline.addPropertyToInterpolate(Timeline.java:353)
at org.pushingpixels.trident.Timeline.addPropertyToInterpolate(Timeline.java:363)
at org.pushingpixels.flamingo.internal.ui.ribbon.BasicRibbonBandUI.installUI(BasicRibbonBandUI.java:168)
at javax.swing.JComponent.setUI(Unknown Source)
at org.pushingpixels.flamingo.api.ribbon.AbstractRibbonBand.setUI(AbstractRibbonBand.java:232)
at org.pushingpixels.flamingo.api.ribbon.AbstractRibbonBand.updateUI(AbstractRibbonBand.java:245)
at org.pushingpixels.flamingo.api.ribbon.AbstractRibbonBand.<init>(AbstractRibbonBand.java:205)
at org.pushingpixels.flamingo.api.ribbon.JRibbonBand.<init>(JRibbonBand.java:169)
at com.pinkmatter.modules.flamingo.RibbonComponentFactory.createRibbonBand(RibbonComponentFactory.java:216)
at com.pinkmatter.modules.flamingo.RibbonComponentFactory.createRibbonBands(RibbonComponentFactory.java:207)
at com.pinkmatter.modules.flamingo.RibbonComponentFactory.createRibbonTask(RibbonComponentFactory.java:195)
at com.pinkmatter.modules.flamingo.LayerRibbonComponentProvider.addTaskPanes(LayerRibbonComponentProvider.java:101)
at com.pinkmatter.modules.flamingo.LayerRibbonComponentProvider.createRibbon(LayerRibbonComponentProvider.java:56)
at com.pinkmatter.modules.flamingo.Installer$2.run(Installer.java:69)
[catch] at org.netbeans.core.windows.WindowManagerImpl$Exclusive$1.run(WindowManagerImpl.java:1563)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

功能区栏未初始化(因此我的软件无法使用)。有时,如果我关闭它并重新启动它,它会正确启动,有时则不会。我对正在发生的事情一无所知。在某处我读到一些关于正在使用错误的类加载器的信息,但我现在真的找不到那个链接......有人可以帮忙吗?当然如果需要我可以提供更多细节

谢谢

4

2 回答 2

2

尽管接受的答案可以完成这项工作,但这不是正确的方法。基本上,以上是解决最初不应该/不存在的问题的解决方法。由于trident库的许多源代码和二进制文件传输,发生了一个非常重要的文件被遗漏的情况。从而像病毒一样传播错误。

该文件称为trident-plugin.properties,令人惊讶的是,其中存储了可用插值器的位置。

因此,明显的解决方法是将此文件添加到 META-INF 目录中受影响的包中。

为了快速参考,这里是它的内容:

UIToolkitHandler=org.pushingpixels.trident.swing.SwingToolkitHandler
PropertyInterpolatorSource=org.pushingpixels.trident.swing.AWTPropertyInterpolators

UIToolkitHandler=org.pushingpixels.trident.swt.SWTToolkitHandler
PropertyInterpolatorSource=org.pushingpixels.trident.swt.SWTPropertyInterpolators

UIToolkitHandler=org.pushingpixels.trident.android.AndroidToolkitHandler
PropertyInterpolatorSource=org.pushingpixels.trident.android.AndroidPropertyInterpolators

PropertyInterpolatorSource=org.pushingpixels.trident.interpolator.CorePropertyInterpolators
于 2016-10-08T00:40:17.503 回答
1

正如其他评论中所说,我找到了一个解决方案(很抱歉我没有早点提供)。

基本上,问题在于使用错误的类加载器来查找插值器。因此,我确保始终使用 System 类加载器进行实例化。为此,我修改了两个文件:

com.pinkmatter.modules.flamingo.RibbonComponentFactory.getOrCreateActionItem()

private static ActionItem getOrCreateActionItem(Lookup.Item<Object> item, String name,
        Map<String, ActionItem> actionMap,
        Map<String, FileObject> foMap) {
    ActionItem actionItem = actionMap.get(name);
    if (actionItem == null) {
        ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
        try {
            // Some ribbon resources use Trident which looks for resources not 
            // found by the org.netbeans.MainImpl$BootClassLoader. So we
            // switch to the org.netbeans.ModuleManager$SystemClassLoader.
            ClassLoader systemClassLoader = Lookup.getDefault().lookup(ClassLoader.class);
            Thread.currentThread().setContextClassLoader(systemClassLoader);
            if (Action.class.isAssignableFrom(item.getType())) {
            // Create an Action from an instance defined in the file object
            Action instance = (Action) item.getInstance();
                if (instance != null) {
                    actionItem = ActionItem.leaf((Action) instance);
                }
            } else if (JSeparator.class.isAssignableFrom(item.getType())) {
                // Create a Separator
                actionItem = ActionItem.separator();
                actionItem.setText(foMap.get(name).getName());
            } else if (JComponent.class.isAssignableFrom(item.getType())) {
                // Create a Ribbon component from an instance defined in the file object
                JComponent instance = (JComponent) item.getInstance();

                if (instance != null) {
                    actionItem = ActionItem.component((JComponent) instance);
                }
            }
        }
        finally {
            // Restore the original classloader
            Thread.currentThread().setContextClassLoader(originalClassLoader);
        } 
    } else {
        System.out.println(MessageFormat.format("WARNING: Unknown item: {0}", item.getType()));
    }
    if (actionItem != null) {
        addProperties(actionItem, foMap.get(name));
        actionMap.put(name, actionItem);
    }
    return actionItem;
}

方法相同com.pinkmatter.modules.flamingo.RibbonComponentFactory.createRibbonBand()

public AbstractRibbonBand createRibbonBand(ActionItem item) {
        //TODO icon
        JRibbonBand band = null;
        ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
        ClassLoader systemClassLoader = Lookup.getDefault().lookup(ClassLoader.class);
        Thread.currentThread().setContextClassLoader(systemClassLoader);
        try {
        String text = item.getValue("displayName") == null ? item.getText() : item.getValue("displayName").toString();
        band = new JRibbonBand(text, ResizableIcons.empty(), getDefaultAction(item));
        for (ActionItem child : item.getChildren()) {
            if (child.isSeparator()) {
                band.startGroup();
            } else if (child.getValue(ActionItem.DEFAULT_ACTION) != Boolean.TRUE) {
                addRibbonBandAction(band, child);
            }
        }
        band.setResizePolicies(Arrays.<RibbonBandResizePolicy>asList(
                new Mid2Mid(band.getControlPanel())));
        } finally {
            Thread.currentThread().setContextClassLoader(originalClassLoader);
        }
        return band;
    }

通过这两个更改,我不再对插值器有任何问题。希望这可以帮助。

于 2015-01-19T09:47:23.657 回答