Skip to content

Commit

Permalink
Added registries
Browse files Browse the repository at this point in the history
  • Loading branch information
DeflatedPickle committed Aug 8, 2020
1 parent 35865cf commit 536a33d
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 14 deletions.
45 changes: 39 additions & 6 deletions example/src/main/kotlin/main.kt
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
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.api.util.ComponentPositionNormal
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 javax.swing.JFrame
import javax.swing.SwingUtilities
import javax.swing.UIManager
import com.deflatedpickle.haruhi.util.RegistryUtil
import javax.swing.*

@Suppress("unused")
@Plugin(
Expand All @@ -20,7 +21,14 @@ import javax.swing.UIManager
type = PluginType.COMPONENT,
component = SimpleComponent::class
)
object SimplePlugin
object SimplePlugin {
init {
EventProgramFinishSetup.addListener {
(RegistryUtil.get(MenuCategory.MENU.name)
?.get(MenuCategory.FILE.name) as JMenu).add("New")
}
}
}
object SimpleComponent : PluginPanel()

@Suppress("unused")
Expand All @@ -32,16 +40,39 @@ object SimpleComponent : PluginPanel()
component = OtherSimpleComponent::class,
componentMinimizedPosition = ComponentPosition.EAST
)
object OtherSimplePlugin
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 frame = JFrame()
frame.title = "Kotlin Example"
frame.jMenuBar = menuBar

val control = CControl(frame)
PluginUtil.control = control
Expand Down Expand Up @@ -69,6 +100,8 @@ fun main() {
}
}

EventProgramFinishSetup.trigger(true)

SwingUtilities.invokeLater {
frame.setLocationRelativeTo(null)

Expand Down
18 changes: 10 additions & 8 deletions library/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
plugins {
id 'java'
id 'java-library'

id 'org.jetbrains.kotlin.jvm'
id 'org.jetbrains.kotlin.plugin.serialization'

Expand All @@ -16,26 +18,26 @@ dependencies {
implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime:0.20.0"

// Logging
compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.11.1'
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.11.1'
compile 'org.apache.logging.log4j:log4j-api:2.11.1'
compile 'org.apache.logging.log4j:log4j-core:2.11.1'

// Utility
implementation 'com.github.javadev:underscore:1.55'
api 'com.github.javadev:underscore:1.55'

// Events
implementation 'com.github.Fylipp:easy-events:v1.1.0'
api 'com.github.Fylipp:easy-events:v1.1.0'

// Allows for plugin loading
implementation 'io.github.classgraph:classgraph:4.8.85'
api 'io.github.classgraph:classgraph:4.8.85'

// Fuzzy searching
implementation 'me.xdrop:fuzzywuzzy:1.2.0'
api 'me.xdrop:fuzzywuzzy:1.2.0'

// Docking framework
implementation 'org.dockingframes:docking-frames-common:1.1.1'
api 'org.dockingframes:docking-frames-common:1.1.1'

// Extended Swing widgets
implementation 'org.swinglabs:swingx:1.6.1'
api 'org.swinglabs:swingx:1.6.1'
}

compileKotlin {
Expand Down
15 changes: 15 additions & 0 deletions library/src/main/kotlin/com/deflatedpickle/haruhi/api/Registry.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.deflatedpickle.haruhi.api

import com.deflatedpickle.haruhi.api.registry.Registry

open class Registry<K, V> : Registry<K, V> {
private val items = mutableMapOf<K, V>()

override fun register(key: K, value: V) {
this.items[key] = value
}

override fun has(key: K): Boolean = this.items.containsKey(key)
override fun get(key: K): V? = this.items[key]
override fun getAll(): Map<K, V> = this.items
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.deflatedpickle.haruhi.api.constants

@Suppress("unused")
enum class MenuCategory {
MENU,
FILE,
HOME,
EDIT,
SEARCH,
FORMAT,
SHARE,
VIEW,
NAVIGATE,
ENCODING,
LANGUAGE,
IMAGE,
LAYERS,
ADJUSTMENTS,
EFFECTS,
CODE,
ANALYZE,
REFACTOR,
SETTINGS,
TOOLS,
VCS,
MACRO,
RUN,
PLUGINS,
WINDOW,
HELP
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.deflatedpickle.haruhi.api.constants

@Suppress("unused")
enum class MenuItems {
NEW,
OPEN,
RELOAD,
SAVE,
SAVE_AS,
SAVE_COPY,
SAVE_COPY_AS,
SAVE_ALL,
RENAME,
LOAD_SESSION,
SAVE_SESSION,
PAGE_SETUP,
PRINT,
PRINT_NOW,
EMPTY_RECENT_LIST,
EXIT,

UNDO,
REDO,
CUT,
COPY,
PASTE,
DELETE,
FIND,
FIND_NEXT,
REPLACE,
GO_TO,
SELECT_ALL,
BEGIN_END_SELECT,
TIME_DATE,

WORD_WRAP,
FONT,

STATUS_BAR,

VIEW_HELP,
ABOUT,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.deflatedpickle.haruhi.api.registry

interface Registry<K, V> {
fun register(key: K, value: V)
fun has(key: K): Boolean
fun get(key: K): V?
fun getAll(): Map<K, V>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.deflatedpickle.haruhi.util

import com.deflatedpickle.haruhi.api.Registry

object RegistryUtil : Registry<String, Registry<String, *>>()

0 comments on commit 536a33d

Please sign in to comment.