|
|
|
@ -1,9 +1,22 @@
|
|
|
|
|
package com.fine.theme.light.ui.laf; |
|
|
|
|
|
|
|
|
|
import com.fine.theme.icon.UrlIconResource; |
|
|
|
|
import com.fine.theme.icon.plugin.PluginIconManager; |
|
|
|
|
import com.fine.theme.icon.plugin.PluginIconSet; |
|
|
|
|
import com.formdev.flatlaf.FlatLaf; |
|
|
|
|
import com.formdev.flatlaf.util.SystemInfo; |
|
|
|
|
import com.fr.design.ExtraDesignClassManager; |
|
|
|
|
import com.fr.design.fun.LazyIconProvider; |
|
|
|
|
import com.fr.general.ComparatorUtils; |
|
|
|
|
import com.fr.general.GeneralContext; |
|
|
|
|
import com.fr.plugin.manage.PluginFilter; |
|
|
|
|
import com.fr.plugin.observer.PluginEvent; |
|
|
|
|
import com.fr.plugin.observer.PluginEventListener; |
|
|
|
|
import com.fr.plugin.observer.PluginEventType; |
|
|
|
|
|
|
|
|
|
import javax.swing.PopupFactory; |
|
|
|
|
import java.util.Set; |
|
|
|
|
import java.util.function.BiConsumer; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Fine designer new look and feel |
|
|
|
@ -18,6 +31,21 @@ public abstract class FineLaf extends FlatLaf {
|
|
|
|
|
|
|
|
|
|
private static final String NAME = "FineLaf"; |
|
|
|
|
|
|
|
|
|
private static void handlePluginEvent(PluginEvent event, LazyIconProvider.THEME category, |
|
|
|
|
BiConsumer<LazyIconProvider, PluginIconSet> operation) { |
|
|
|
|
Set<LazyIconProvider> set = event.getContext().getRuntime().get(LazyIconProvider.MARK_STRING); |
|
|
|
|
dealWithPluginIcon(set, category, operation); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static void dealWithPluginIcon(Set<LazyIconProvider> set, LazyIconProvider.THEME category, |
|
|
|
|
BiConsumer<LazyIconProvider, PluginIconSet> operation) { |
|
|
|
|
for (LazyIconProvider provider : set) { |
|
|
|
|
if (!ComparatorUtils.equals(provider.themeCategory(), category)) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
operation.accept(provider, new PluginIconSet(new UrlIconResource(provider.jsonPath()), provider.iconId2Path())); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public String getName() { |
|
|
|
@ -53,4 +81,48 @@ public abstract class FineLaf extends FlatLaf {
|
|
|
|
|
System.setProperty("flatlaf.menuBarEmbedded", "false"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 适配插件图标 Icon |
|
|
|
|
* @param category 图标 Icon 分类 {@link LazyIconProvider.THEME} |
|
|
|
|
*/ |
|
|
|
|
public static void insertIconProvider(LazyIconProvider.THEME category) { |
|
|
|
|
Set<LazyIconProvider> set = ExtraDesignClassManager.getInstance().getArray(LazyIconProvider.MARK_STRING); |
|
|
|
|
dealWithPluginIcon(set, category, (provider, iconSet) -> PluginIconManager.addSet(provider.pluginId(), iconSet)); |
|
|
|
|
listenerPlugins(category); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static void listenerPlugins(LazyIconProvider.THEME category) { |
|
|
|
|
//注册插件监听
|
|
|
|
|
PluginFilter filter = context -> context.contain(LazyIconProvider.MARK_STRING); |
|
|
|
|
|
|
|
|
|
PluginEventListener insert = new PluginEventListener() { |
|
|
|
|
@Override |
|
|
|
|
public void on(PluginEvent event) { |
|
|
|
|
handlePluginEvent(event, category, (provider, iconSet) -> PluginIconManager.addSet(provider.pluginId(), iconSet)); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
PluginEventListener update = new PluginEventListener() { |
|
|
|
|
@Override |
|
|
|
|
public void on(PluginEvent event) { |
|
|
|
|
handlePluginEvent(event, category, (provider, iconSet) -> PluginIconManager.updateSet(provider.pluginId(), iconSet)); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
PluginEventListener remove = new PluginEventListener() { |
|
|
|
|
@Override |
|
|
|
|
public void on(PluginEvent event) { |
|
|
|
|
handlePluginEvent(event, category, (provider, iconSet) -> PluginIconManager.removeSet(provider.pluginId())); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
GeneralContext.listenPlugin(PluginEventType.AfterRun, insert, filter); |
|
|
|
|
GeneralContext.listenPlugin(PluginEventType.AfterInstall, insert, filter); |
|
|
|
|
GeneralContext.listenPlugin(PluginEventType.AfterUpdate, update, filter); |
|
|
|
|
GeneralContext.listenPlugin(PluginEventType.AfterActive, update, filter); |
|
|
|
|
GeneralContext.listenPlugin(PluginEventType.AfterForbid, remove, filter); |
|
|
|
|
GeneralContext.listenPlugin(PluginEventType.AfterUninstall, remove, filter); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|