-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.kt
116 lines (99 loc) · 3.44 KB
/
main.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import bibliothek.gui.dock.common.CControl
import bibliothek.gui.dock.common.CGrid
import com.deflatedpickle.haruhi.api.Registry
import com.deflatedpickle.haruhi.api.constants.MenuCategory
import com.deflatedpickle.haruhi.api.plugin.DependencyComparator
import com.deflatedpickle.haruhi.api.plugin.Plugin
import com.deflatedpickle.haruhi.api.plugin.PluginType
import com.deflatedpickle.haruhi.api.util.ComponentPosition
import com.deflatedpickle.haruhi.component.PluginPanel
import com.deflatedpickle.haruhi.event.EventProgramFinishSetup
import com.deflatedpickle.haruhi.util.ClassGraphUtil
import com.deflatedpickle.haruhi.util.PluginUtil
import com.deflatedpickle.haruhi.util.RegistryUtil
import javax.swing.*
@Suppress("unused")
@Plugin(
value = "simple_plugin",
author = "DeflatedPickle",
version = "1.0.0",
type = PluginType.COMPONENT,
component = SimpleComponent::class
)
object SimplePlugin {
init {
EventProgramFinishSetup.addListener {
(RegistryUtil.get(MenuCategory.MENU.name)
?.get(MenuCategory.FILE.name) as JMenu).add("New")
}
}
}
object SimpleComponent : PluginPanel()
@Suppress("unused")
@Plugin(
value = "other_simple_plugin",
author = "DeflatedPickle",
version = "1.0.0",
type = PluginType.COMPONENT,
component = OtherSimpleComponent::class,
componentMinimizedPosition = ComponentPosition.EAST
)
object OtherSimplePlugin {
init {
EventProgramFinishSetup.addListener {
(RegistryUtil.get(MenuCategory.MENU.name)
?.get(MenuCategory.EDIT.name) as JMenu).add("Undo")
}
}
}
object OtherSimpleComponent : PluginPanel()
fun main() {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName())
PluginUtil.isInDev = true
val menuBar = JMenuBar()
val menuRegistry = object : Registry<String, JMenu>() {
init {
register(MenuCategory.FILE.name, JMenu("File"))
register(MenuCategory.EDIT.name, JMenu("Edit"))
}
override fun register(key: String, value: JMenu) {
super.register(key, value)
menuBar.add(value)
}
}
RegistryUtil.register(MenuCategory.MENU.name, menuRegistry)
// val tempRegistry = RegistryUtil.get(MenuCategory.MENU.name)
// tempRegistry?.register(MenuCategory.TOOLS.name, JMenu("Tools"))
val frame = JFrame()
frame.title = "Kotlin Example"
frame.jMenuBar = menuBar
val control = CControl(frame)
PluginUtil.control = control
val grid = CGrid(control)
PluginUtil.grid = grid
frame.add(control.contentArea)
ClassGraphUtil.refresh()
PluginUtil.discoverPlugins()
PluginUtil.discoveredPlugins.sortWith(DependencyComparator)
PluginUtil.loadPlugins {
PluginUtil.validateVersion(it) &&
PluginUtil.validateDescription(it) &&
PluginUtil.validateType(it) &&
// PluginUtil.validateDependencySlug(it) &&
PluginUtil.validateDependencyExistence(it)
}
for (plugin in PluginUtil.discoveredPlugins) {
if (plugin.component != Nothing::class) {
with(plugin.component.objectInstance!!) {
PluginUtil.createComponent(plugin, this)
}
}
}
EventProgramFinishSetup.trigger(true)
SwingUtilities.invokeLater {
frame.setLocationRelativeTo(null)
control.contentArea.deploy(grid)
frame.pack()
frame.isVisible = true
}
}