Initial Comit
This commit is contained in:
BIN
MenuManager/Files/1.bjl
Normal file
BIN
MenuManager/Files/1.bjl
Normal file
Binary file not shown.
87
MenuManager/Files/MenuManager.css
Normal file
87
MenuManager/Files/MenuManager.css
Normal file
@@ -0,0 +1,87 @@
|
||||
/* From: https://stackoverflow.com/questions/12299162/how-to-style-menu-button-and-menu-items */
|
||||
/* VARIABLE DEFINITIONS: Only these 4 variables have to be adjusted, the rest is copy-paste */
|
||||
* {
|
||||
-fx-my-menu-color: #263238; /* Change according to your needs */
|
||||
-fx-my-menu-color-highlighted: #455a64; /* Change according to your needs */
|
||||
-fx-my-menu-font-color: #FFFFFF; /* Change according to your needs */
|
||||
-fx-my-menu-font-color-highlighted: #FFFFFF; /* Change according to your needs */
|
||||
}
|
||||
|
||||
/* MENU BAR + Top-level MENU BUTTONS */
|
||||
/*** The menu bar itself ***/
|
||||
.menu-bar {
|
||||
-fx-background-color: -fx-my-menu-color;
|
||||
}
|
||||
|
||||
/*** Top-level menu itself (not selected / hovered) ***/
|
||||
.menu-bar > .container > .menu-button {
|
||||
-fx-background-color: -fx-my-menu-color;
|
||||
}
|
||||
|
||||
/*** Top-level menu's label (not selected / hovered) ***/
|
||||
.menu-bar > .container > .menu-button > .label {
|
||||
-fx-text-fill: -fx-my-menu-font-color;
|
||||
}
|
||||
|
||||
/*** Top-level menu's label (disabled) ***/
|
||||
.menu-bar > .container > .menu-button > .label:disabled {
|
||||
-fx-opacity: 1.0;
|
||||
}
|
||||
|
||||
/*** Top-level menu itself (selected / hovered) ***/
|
||||
.menu-bar > .container > .menu-button:hover,
|
||||
.menu-bar > .container > .menu-button:focused,
|
||||
.menu-bar > .container > .menu-button:showing {
|
||||
-fx-background-color: -fx-my-menu-color-highlighted;
|
||||
}
|
||||
|
||||
/*** Top-level menu's label (selected / hovered) ***/
|
||||
.menu-bar > .container > .menu-button:hover > .label,
|
||||
.menu-bar > .container > .menu-button:focused > .label,
|
||||
.menu-bar > .container > .menu-button:showing > .label {
|
||||
-fx-text-fill: -fx-my-menu-font-color-highlighted;
|
||||
}
|
||||
|
||||
/* MENU ITEM (children of a MENU BUTTON) */
|
||||
/*** The item itself (not hovered / focused) ***/
|
||||
.menu-item {
|
||||
-fx-background-color: -fx-my-menu-color;
|
||||
}
|
||||
|
||||
/*** The item's label (not hovered / focused) ***/
|
||||
.menu-item .label {
|
||||
-fx-text-fill: -fx-my-menu-font-color;
|
||||
}
|
||||
|
||||
/*** The item's label (disabled) ***/
|
||||
.menu-item .label:disabled {
|
||||
-fx-opacity: 1.0;
|
||||
}
|
||||
|
||||
/*** The item itself (hovered / focused) ***/
|
||||
.menu-item:focused, .menu-item:hovered {
|
||||
-fx-background-color: -fx-my-menu-color-highlighted;
|
||||
}
|
||||
|
||||
/*** The item's label (hovered / focused) ***/
|
||||
.menu-item:focused .label, .menu-item:hovered .label {
|
||||
-fx-text-fill: -fx-my-menu-font-color-highlighted;
|
||||
}
|
||||
|
||||
/* CONTEXT MENU */
|
||||
/*** The context menu that contains a menu's menu items ***/
|
||||
.context-menu {
|
||||
-fx-background-color: -fx-my-menu-color;
|
||||
}
|
||||
|
||||
|
||||
/* Menu manager mods */
|
||||
.mm-title {
|
||||
-fx-font-size: 16px;
|
||||
-fx-font-weight: bold;
|
||||
}
|
||||
.mm-menucustom-hidden:hover,
|
||||
.mm-menucustom-hidden:focused,
|
||||
.mm-menucustom-hidden:showing {
|
||||
-fx-background-color: Transparent;
|
||||
}
|
||||
BIN
MenuManager/Files/icon.png
Normal file
BIN
MenuManager/Files/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 14 KiB |
34
MenuManager/KeyCombinations.bas
Normal file
34
MenuManager/KeyCombinations.bas
Normal file
@@ -0,0 +1,34 @@
|
||||
B4J=true
|
||||
Group=Default Group
|
||||
ModulesStructureVersion=1
|
||||
Type=StaticCode
|
||||
Version=5.9
|
||||
@EndOfDesignText@
|
||||
'Static code module
|
||||
Sub Process_Globals
|
||||
Private fx As JFX
|
||||
Public Const KC_CONTROL As String = "Ctrl"
|
||||
Public Const KC_SHIFT As String = "Shift"
|
||||
Public Const KC_ALT As String = "Alt"
|
||||
Public Const KC_SHORTCUT As String = "Shortcut"
|
||||
End Sub
|
||||
|
||||
Private Sub List(ShortCut As String) 'ignore
|
||||
Dim JO As JavaObject
|
||||
JO.InitializeStatic("javafx.scene.input.KeyCombination.Modifier")
|
||||
Dim KC As JavaObject
|
||||
KC.InitializeStatic("javafx.scene.input.KeyCombination")
|
||||
Log(KC.GetFieldJO(ShortCut).RunMethod("toString",Null))
|
||||
End Sub
|
||||
|
||||
Public Sub GetKeyCombination(Combination() As String) As Object
|
||||
|
||||
Dim KC As JavaObject
|
||||
KC.InitializeStatic("javafx.scene.input.KeyCombination")
|
||||
Dim KCS As String
|
||||
For i = 0 To Combination.Length - 1
|
||||
If i > 0 Then KCS = KCS & "+"
|
||||
KCS = KCS & Combination(i)
|
||||
Next
|
||||
Return KCS
|
||||
End Sub
|
||||
136
MenuManager/MenuCheckBoxClass.bas
Normal file
136
MenuManager/MenuCheckBoxClass.bas
Normal file
@@ -0,0 +1,136 @@
|
||||
B4J=true
|
||||
Group=Default Group
|
||||
ModulesStructureVersion=1
|
||||
Type=Class
|
||||
Version=5.9
|
||||
@EndOfDesignText@
|
||||
Sub Class_Globals
|
||||
Private fx As JFX
|
||||
Private mModule As Object
|
||||
Private mEventName As String
|
||||
Private TJO As JavaObject
|
||||
Private ReturnEventName As String
|
||||
End Sub
|
||||
|
||||
'Initializes the object. You can add parameters to this method if needed.
|
||||
Public Sub Initialize(Module As Object,Event_Name As String,Text As String)
|
||||
mModule = Module
|
||||
mEventName = Event_Name
|
||||
TJO.InitializeNewInstance("javafx.scene.control.CheckMenuItem",Array(Text))
|
||||
TJO.RunMethod("setSelected",Array(True))
|
||||
Dim Event As Object = TJO.CreateEventFromUI("javafx.beans.value.ChangeListener","CBChanged",False)
|
||||
TJO.RunMethodJO("selectedProperty",Null).RunMethod("addListener",Array(Event))
|
||||
End Sub
|
||||
|
||||
'Checkbox Check Changed event pass back to creating module
|
||||
Private Sub CBChanged_Event(MethodName As String,Args() As Object) As Object
|
||||
If SubExists(mModule,mEventName & "_SelectedChanged") Then CallSub2(mModule,mEventName & "_SelectedChanged",Me)
|
||||
Return True
|
||||
End Sub
|
||||
|
||||
'Get the selected state for this menu item
|
||||
Public Sub GetSelected As Boolean
|
||||
Return TJO.RunMethod("isSelected",Null)
|
||||
End Sub
|
||||
|
||||
'Set the selected state for this menu item
|
||||
'Returns the menu item
|
||||
Public Sub SetSelected (Checked As Boolean) As MenuCheckBoxClass
|
||||
TJO.RunMethod("setSelected",Array(Checked))
|
||||
Return Me
|
||||
End Sub
|
||||
|
||||
'Set a Graphic for this menu item
|
||||
'Returns the menu item
|
||||
Public Sub SetGraphic(Graphic As Node) As MenuCheckBoxClass
|
||||
TJO.RunMethod("setGraphic",Array(Graphic))
|
||||
Return Me
|
||||
End Sub
|
||||
|
||||
'Get the graphic set on this menu item
|
||||
Public Sub GetGraphic As Node
|
||||
Return TJO.RunMethod("getGraphic",Null)
|
||||
End Sub
|
||||
|
||||
'Set a shortut key for this menu item
|
||||
'Returns the menu item
|
||||
Public Sub SetShortCutKey(Combination() As String) As MenuCheckBoxClass
|
||||
Dim KC As JavaObject
|
||||
KC.InitializeStatic("javafx.scene.input.KeyCombination")
|
||||
Dim KCS As String
|
||||
For i = 0 To Combination.Length - 1
|
||||
If i > 0 Then KCS = KCS & "+"
|
||||
KCS = KCS & Combination(i)
|
||||
Next
|
||||
TJO.RunMethod("setAccelerator",Array(KC.RunMethod("keyCombination",Array(KCS))))
|
||||
Return Me
|
||||
End Sub
|
||||
|
||||
'Set an alternate eventname
|
||||
Public Sub SetEventName (Name As String) As MenuCheckBoxClass
|
||||
ReturnEventName = Name
|
||||
Return Me
|
||||
End Sub
|
||||
|
||||
'get the alternate eventname
|
||||
Public Sub GetEventName As String
|
||||
Return ReturnEventName
|
||||
End Sub
|
||||
|
||||
'Get/Set the text on this menu item
|
||||
Sub getText As String
|
||||
Return TJO.RunMethod("getText",Null)
|
||||
End Sub
|
||||
Public Sub setText(Text As String)
|
||||
TJO.RunMethod("setText", Array(Text))
|
||||
End Sub
|
||||
|
||||
'Get the style class
|
||||
Public Sub getStyleClass As List
|
||||
Return TJO.RunMethod("getStyleClass",Null)
|
||||
End Sub
|
||||
|
||||
'Add a style class for this menuitem, checks it is not already added
|
||||
'Returns the menu item
|
||||
Public Sub SetStyleClass(Class As String) As MenuCheckBoxClass
|
||||
Dim L As List = getStyleClass
|
||||
Dim Pos As Int = L.IndexOf(Class)
|
||||
If Pos = -1 Then L.Add(Class)
|
||||
Return Me
|
||||
End Sub
|
||||
|
||||
'Set the enabled state for the menu item.
|
||||
'Returns the menu item
|
||||
Public Sub SetEnabled(Enabled As Boolean) As MenuCheckBoxClass
|
||||
TJO.RunMethod("setEnabled",Array(Enabled))
|
||||
Return Me
|
||||
End Sub
|
||||
|
||||
'Get the enabled state for the menu item
|
||||
Public Sub GetEnabled As Boolean
|
||||
Return TJO.RunMethod("getEnabled",Null)
|
||||
End Sub
|
||||
|
||||
'Set a tag for the menu item
|
||||
'Returns the menu item
|
||||
Public Sub SetTag(TTag As Object) As MenuCheckBoxClass
|
||||
TJO.RunMethod("setUserData",Array(TTag))
|
||||
Return Me
|
||||
End Sub
|
||||
|
||||
'Set a tag for the menu item
|
||||
Public Sub GetTag As Object
|
||||
Dim Tag As Object = TJO.RunMethod("getUserData",Null)
|
||||
If Tag = Null Then Tag = ""
|
||||
Return Tag
|
||||
End Sub
|
||||
|
||||
'Get the underlying Native menuitem as a JavaObject
|
||||
Public Sub AsJavaObject As JavaObject
|
||||
Return TJO
|
||||
End Sub
|
||||
|
||||
'Get the underlying Native menuitem as a JavaObject
|
||||
Public Sub AsObject As Object
|
||||
Return TJO
|
||||
End Sub
|
||||
167
MenuManager/MenuCustomClass.bas
Normal file
167
MenuManager/MenuCustomClass.bas
Normal file
@@ -0,0 +1,167 @@
|
||||
B4J=true
|
||||
Group=Default Group
|
||||
ModulesStructureVersion=1
|
||||
Type=Class
|
||||
Version=5.9
|
||||
@EndOfDesignText@
|
||||
Sub Class_Globals
|
||||
Private fx As JFX
|
||||
Private TJO As JavaObject
|
||||
Private mModule As Object
|
||||
Private mEventName As String
|
||||
Private ReturnEventName As String
|
||||
End Sub
|
||||
|
||||
'Initializes the object. You can add parameters to this method if needed.
|
||||
Public Sub Initialize(Module As Object,EventName As String,TNode As Node)
|
||||
mModule = Module
|
||||
mEventName = EventName
|
||||
TJO.InitializeNewInstance("javafx.scene.control.CustomMenuItem",Array(TNode))
|
||||
Dim O As Object = TJO.CreateEventFromUI("javafx.event.EventHandler","Action",Null)
|
||||
TJO.RunMethod("setOnAction",Array(O))
|
||||
End Sub
|
||||
|
||||
'Pass the menu action event to the calling module
|
||||
Private Sub Action_Event (MethodName As String, Args() As Object) As Object 'Ignore
|
||||
If SubExists(mModule, mEventName & "_Action") Then CallSub(mModule,mEventName & "_Action")
|
||||
End Sub
|
||||
|
||||
'Gets the value of the property content.
|
||||
Public Sub GetContent As Node
|
||||
Return TJO.RunMethod("getContent",Null)
|
||||
End Sub
|
||||
|
||||
'Gets the value of the property hideOnClick.
|
||||
Public Sub IsHideOnClick As Boolean
|
||||
Return TJO.RunMethod("isHideOnClick",Null)
|
||||
End Sub
|
||||
|
||||
'Sets the value of the property content.
|
||||
Public Sub SetContent(Value As Node) As MenuCustomClass
|
||||
TJO.RunMethod("setContent",Array As Object(Value))
|
||||
Return Me
|
||||
End Sub
|
||||
|
||||
'Sets the value of the property hideOnClick. Selecting MouseTransparent will make it non responsive to mouse hover and focus
|
||||
Public Sub SetHideOnClick(Value As Boolean,MouseTransparent As Boolean) As MenuCustomClass
|
||||
TJO.RunMethod("setHideOnClick",Array As Object(Value))
|
||||
|
||||
If Value Then
|
||||
RemoveStyle("mm-menucustom-hidden")
|
||||
Else
|
||||
If MouseTransparent Then AddStyle("mm-menucustom-hidden")
|
||||
End If
|
||||
|
||||
Dim L As List = TJO.RunMethodJO("getStyleClass",Null)
|
||||
For Each S As String In L
|
||||
Log(S)
|
||||
Next
|
||||
Return Me
|
||||
End Sub
|
||||
|
||||
|
||||
|
||||
'Set a Graphic on this menu item
|
||||
'Returns the menu item
|
||||
Public Sub SetGraphic(Graphic As Node) As MenuCustomClass
|
||||
TJO.RunMethod("setGraphic",Array(Graphic))
|
||||
Return Me
|
||||
End Sub
|
||||
|
||||
'Get the graphic set on this menu item
|
||||
Public Sub GetGraphic As Node
|
||||
Return TJO.RunMethod("getGraphic",Null)
|
||||
End Sub
|
||||
|
||||
'Set a shortcut key for this menu item
|
||||
'Returns the menu item
|
||||
Public Sub SetShortCutKey(Combination() As String) As MenuCustomClass
|
||||
Dim KC As JavaObject
|
||||
KC.InitializeStatic("javafx.scene.input.KeyCombination")
|
||||
Dim KCS As String
|
||||
For i = 0 To Combination.Length - 1
|
||||
If i > 0 Then KCS = KCS & "+"
|
||||
KCS = KCS & Combination(i)
|
||||
Next
|
||||
TJO.RunMethod("setAccelerator",Array(KC.RunMethod("keyCombination",Array(KCS))))
|
||||
Return Me
|
||||
End Sub
|
||||
|
||||
'Set the enabled state for this menu item
|
||||
'Returns the menu item
|
||||
Public Sub SetEnabled(Enabled As Boolean) As MenuCustomClass
|
||||
TJO.RunMethod("setEnabled",Array(Enabled))
|
||||
Return Me
|
||||
End Sub
|
||||
|
||||
'Get the enabled state for this menu item
|
||||
Public Sub GetEnabled As Boolean
|
||||
Return TJO.RunMethod("getEnabled",Null)
|
||||
End Sub
|
||||
|
||||
'Set an alternate event name for this menu item
|
||||
'Returns the menu item
|
||||
Public Sub SetEventName (Name As String) As MenuCustomClass
|
||||
ReturnEventName = Name
|
||||
Return Me
|
||||
End Sub
|
||||
|
||||
'Get the alternate Event name for this menu item
|
||||
Public Sub GetEventName As String
|
||||
Return ReturnEventName
|
||||
End Sub
|
||||
|
||||
'Get / Set the text of the menu item
|
||||
Sub getText As String
|
||||
Return TJO.RunMethod("getText",Null)
|
||||
End Sub
|
||||
Public Sub setText(Text As String)
|
||||
TJO.RunMethod("setText", Array(Text))
|
||||
End Sub
|
||||
|
||||
'Get the list of style classes set on this menu item
|
||||
Public Sub GetStyleClass As List
|
||||
Return TJO.RunMethod("getStyleClass",Null)
|
||||
End Sub
|
||||
|
||||
'Set a style class for this menu item, checks it is not already added
|
||||
'Returns the menu item
|
||||
Public Sub SetStyleClass(Class As String) As MenuCustomClass
|
||||
Dim L As List = GetStyleClass
|
||||
Dim Pos As Int = L.IndexOf(Class)
|
||||
If Pos = -1 Then L.Add(Class)
|
||||
Return Me
|
||||
End Sub
|
||||
|
||||
'Set a tag for this menu item
|
||||
'Returns the menu item
|
||||
Public Sub SetTag(TTag As Object) As MenuCustomClass
|
||||
TJO.RunMethod("setUserData",Array(TTag))
|
||||
Return Me
|
||||
End Sub
|
||||
|
||||
'Get the tag for this menu item
|
||||
Public Sub GetTag As Object
|
||||
Dim Tag As Object = TJO.RunMethod("getUserData",Null)
|
||||
If Tag = Null Then Tag = ""
|
||||
Return Tag
|
||||
End Sub
|
||||
|
||||
'Get the native menu item as a Javaobject
|
||||
Public Sub AsJavaObject As JavaObject
|
||||
Return TJO
|
||||
End Sub
|
||||
|
||||
'Get the native menu item as an object
|
||||
Public Sub AsObject As Object
|
||||
Return TJO
|
||||
End Sub
|
||||
|
||||
Private Sub AddStyle(Style As String)
|
||||
TJO.RunMethodJO("getStyleClass",Null).RunMethod("add",Array(Style))
|
||||
|
||||
End Sub
|
||||
|
||||
Private Sub RemoveStyle(Style As String)
|
||||
TJO.RunMethodJO("getStyleClass",Null).RunMethod("remove",Array(Style))
|
||||
End Sub
|
||||
132
MenuManager/MenuItemTextClass.bas
Normal file
132
MenuManager/MenuItemTextClass.bas
Normal file
@@ -0,0 +1,132 @@
|
||||
B4J=true
|
||||
Group=Default Group
|
||||
ModulesStructureVersion=1
|
||||
Type=Class
|
||||
Version=5.9
|
||||
@EndOfDesignText@
|
||||
Sub Class_Globals
|
||||
Private fx As JFX
|
||||
Private TJO As JavaObject
|
||||
Private MI As MenuItem
|
||||
Private mModule As Object
|
||||
Private mEventName As String
|
||||
Private ReturnEventName As String
|
||||
End Sub
|
||||
|
||||
'Initializes the object. You can add parameters to this method if needed.
|
||||
Public Sub Initialize(Module As Object,EventName As String,Text As String)
|
||||
mModule = Module
|
||||
mEventName = EventName
|
||||
MI.Initialize(Text,"MI")
|
||||
TJO = MI
|
||||
End Sub
|
||||
|
||||
'Pass the menu action event to the calling module
|
||||
Private Sub MI_Action
|
||||
If SubExists(mModule, mEventName & "_Action") Then CallSub(mModule,mEventName & "_Action")
|
||||
End Sub
|
||||
|
||||
'Set a Graphic on this menu item
|
||||
'Returns the menu item
|
||||
Public Sub SetGraphic(Graphic As Node) As MenuItemTextClass
|
||||
TJO.RunMethod("setGraphic",Array(Graphic))
|
||||
Return Me
|
||||
End Sub
|
||||
|
||||
'Get the graphic set on this menu item
|
||||
Public Sub GetGraphic As Node
|
||||
Return TJO.RunMethod("getGraphic",Null)
|
||||
End Sub
|
||||
|
||||
'Set a shortcut key for this menu item
|
||||
'Returns the menu item
|
||||
Public Sub SetShortCutKey(Combination() As String) As MenuItemTextClass
|
||||
Dim KC As JavaObject
|
||||
KC.InitializeStatic("javafx.scene.input.KeyCombination")
|
||||
Dim KCS As String
|
||||
For i = 0 To Combination.Length - 1
|
||||
If i > 0 Then KCS = KCS & "+"
|
||||
KCS = KCS & Combination(i)
|
||||
Next
|
||||
TJO.RunMethod("setAccelerator",Array(KC.RunMethod("keyCombination",Array(KCS))))
|
||||
Return Me
|
||||
End Sub
|
||||
|
||||
'Set the enabled state for this menu item
|
||||
'Returns the menu item
|
||||
Public Sub SetEnabled(Enabled As Boolean) As MenuItemTextClass
|
||||
MI.Enabled = Enabled
|
||||
Return Me
|
||||
End Sub
|
||||
|
||||
'Get the enabled state for this menu item
|
||||
Public Sub GetEnabled As Boolean
|
||||
Return MI.Enabled
|
||||
End Sub
|
||||
|
||||
'Set an alternate event name for this menu item
|
||||
'Returns the menu item
|
||||
Public Sub SetEventName (Name As String) As MenuItemTextClass
|
||||
ReturnEventName = Name
|
||||
Return Me
|
||||
End Sub
|
||||
|
||||
'Get the alternate Event name for this menu item
|
||||
Public Sub GetEventName As String
|
||||
Return ReturnEventName
|
||||
End Sub
|
||||
|
||||
'Get / Set the text of the menu item
|
||||
Sub getText As String
|
||||
Return TJO.RunMethod("getText",Null)
|
||||
End Sub
|
||||
Public Sub setText(Text As String)
|
||||
TJO.RunMethod("setText", Array(Text))
|
||||
End Sub
|
||||
|
||||
Public Sub SetMnemonicParsing(value As Boolean) As MenuItemTextClass
|
||||
TJO.RunMethod("setMnemonicParsing",Array(value))
|
||||
Return Me
|
||||
End Sub
|
||||
|
||||
Public Sub isMnemonicParsing As Boolean
|
||||
Return TJO.RunMethod("isMnemonicParsing",Null)
|
||||
End Sub
|
||||
|
||||
'Get the list of style classes set on this menu item
|
||||
Public Sub getStyleClass As List
|
||||
Return TJO.RunMethod("getStyleClass",Null)
|
||||
End Sub
|
||||
|
||||
'Set a style class for this menu item, checks it is not already added
|
||||
'Returns the menu item
|
||||
Public Sub SetStyleClass(Class As String) As MenuItemTextClass
|
||||
Dim L As List = getStyleClass
|
||||
Dim Pos As Int = L.IndexOf(Class)
|
||||
If Pos = -1 Then L.Add(Class)
|
||||
Return Me
|
||||
End Sub
|
||||
|
||||
'Set a tag for this menu item
|
||||
'Returns the menu item
|
||||
Public Sub SetTag(TTag As Object) As MenuItemTextClass
|
||||
MI.Tag = TTag
|
||||
Return Me
|
||||
End Sub
|
||||
|
||||
'Get the tag for this menu item
|
||||
Public Sub GetTag As Object
|
||||
Dim Tag As Object = TJO.RunMethod("getUserData",Null)
|
||||
If Tag = Null Then Tag = ""
|
||||
Return Tag
|
||||
End Sub
|
||||
|
||||
'Get the native menu item as a Javaobject
|
||||
Public Sub AsJavaObject As JavaObject
|
||||
Return TJO
|
||||
End Sub
|
||||
|
||||
'Get the native menu item as an object
|
||||
Public Sub AsObject As Object
|
||||
Return TJO
|
||||
End Sub
|
||||
289
MenuManager/MenuManager.b4j
Normal file
289
MenuManager/MenuManager.b4j
Normal file
@@ -0,0 +1,289 @@
|
||||
AppType=JavaFX
|
||||
Build1=Default,com.stevel05.menumanager
|
||||
File1=1.bjl
|
||||
File2=icon.png
|
||||
File3=MenuManager.css
|
||||
FileGroup1=Default Group
|
||||
FileGroup2=Default Group
|
||||
FileGroup3=Default Group
|
||||
Group=Default Group
|
||||
Library1=jcore
|
||||
Library2=jfx
|
||||
Library3=javaobject
|
||||
Module1=MenuManager
|
||||
Module2=MenuCheckBoxClass
|
||||
Module3=MenuManagerUtils
|
||||
Module4=KeyCombinations
|
||||
Module5=MenuItemTextClass
|
||||
Module6=MenuCustomClass
|
||||
NumberOfFiles=3
|
||||
NumberOfLibraries=3
|
||||
NumberOfModules=6
|
||||
Version=6.01
|
||||
@EndOfDesignText@
|
||||
#Region Project Attributes
|
||||
#MainFormWidth: 600
|
||||
#MainFormHeight: 400
|
||||
#LibraryName: jMenuManager
|
||||
#LibraryAuthor: Steve Laming
|
||||
#LibraryVersion: 0.03
|
||||
#End Region
|
||||
|
||||
'Requires B4j V5.9+
|
||||
|
||||
Sub Process_Globals
|
||||
Private fx As JFX
|
||||
Private MainForm As Form
|
||||
Private MenuBar1 As MenuBar
|
||||
Private ContextMenu1 As ContextMenu
|
||||
Private Label1 As Label
|
||||
Private DisabledIcon As MenuItemTextClass
|
||||
'Menumanager object need to be Global as they manage the callbacks throughout the life of the menu.
|
||||
Private FileMenu,HelpMenu,MMContext As MenuManager
|
||||
|
||||
End Sub
|
||||
|
||||
Sub AppStart (Form1 As Form, Args() As String)
|
||||
MainForm = Form1
|
||||
MainForm.RootPane.LoadLayout("1") 'Load the layout file.
|
||||
MainForm.Stylesheets.Add(File.GetUri(File.DirAssets,"MenuManager.css"))
|
||||
|
||||
BuildMenus
|
||||
MainForm.Show
|
||||
End Sub
|
||||
|
||||
Private Sub BuildMenus
|
||||
|
||||
MenuBar1.Menus.Clear
|
||||
|
||||
FileMenu.Initialize(Me,"Menu","File")
|
||||
|
||||
|
||||
'*******************************************************************************************************************
|
||||
'Items attached to the main menu
|
||||
'*******************************************************************************************************************
|
||||
Dim SubMenu2 As List = Array( _
|
||||
FileMenu.MenuCheckBox("Option 1").SetTag("Option 1"), _
|
||||
FileMenu.MenuSeparator, _
|
||||
FileMenu.MenuCheckBox("Option 2 Alternate Event Name").SetEventName("MCB").SetTag("Option 2"), _
|
||||
FileMenu.MenuCheckBox("Option 3").SetTag("Option 3").SetShortCutKey(Array As String(KeyCombinations.KC_CONTROL,KeyCombinations.KC_SHIFT,"K")))
|
||||
|
||||
DisabledIcon = FileMenu.MenuText("Item With MaterialIcon As Icon").SetTag("MA1").SetGraphic(FileMenu.NewMaterialIcon(Chr(0xE14B),fx.Colors.Red)).SetEnabled(False)
|
||||
|
||||
Dim SubMenu1 As List = Array( _
|
||||
FileMenu.MenuText("Item With ShortCut").SetTag("IWS1").SetShortCutKey(Array As String(KeyCombinations.KC_CONTROL,KeyCombinations.KC_SHIFT,"L")), _
|
||||
FileMenu.MenuText("Normal Item").SetTag("NIT1"), _
|
||||
FileMenu.MenuText("Item With FontAwesom As Icon").SetTag("FA1").SetGraphic(FileMenu.NewFontAwesome(Chr(0xF1E3),fx.Colors.Black)), _
|
||||
DisabledIcon, _
|
||||
FileMenu.MenuText("Enable above option").SetTag("EnableMA1"), _
|
||||
FileMenu.MenuText("Item With image As Icon").SetTag("Img1").SetGraphic(FileMenu.NewImage(File.DirAssets,"icon.png")), _
|
||||
FileMenu.MenuSeparator, _
|
||||
FileMenu.MenuSubMenu("Options",SubMenu2))
|
||||
|
||||
'
|
||||
'Add a menutitle, menuText, Seperator or CheckBox (you can add more see: https://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/MMContext.html
|
||||
'for items available
|
||||
'
|
||||
|
||||
'
|
||||
'Create the objects for the custom menuitems
|
||||
'
|
||||
Dim Lbl As Label
|
||||
Lbl.Initialize("")
|
||||
Lbl.Text = "Item with Tooltip"
|
||||
Lbl.TooltipText = "Tooltip for label"
|
||||
|
||||
Dim Lbl2 As Label
|
||||
Lbl2.Initialize("")
|
||||
Lbl2.Font = fx.CreateFontAwesome(15)
|
||||
Lbl2.Text = Chr(0xF0A1)
|
||||
Lbl2.TextColor = fx.Colors.black
|
||||
|
||||
Dim Lbl3 As Label
|
||||
Lbl3.Initialize("")
|
||||
Lbl3.Text = "another label with tooltip and Icon"
|
||||
Lbl3.TooltipText = "Another tooltip"
|
||||
Lbl3.TextColor = fx.Colors.black
|
||||
|
||||
'
|
||||
'An HBox is useful as it will align items horizontally without any effort.
|
||||
'Full Docs are here: https://docs.oracle.com/javase/8/javafx/api/javafx/scene/layout/HBox.html
|
||||
'The item with HBox is sent to a different Event callback as it needs to be unwrapped before it can be accessed.
|
||||
'
|
||||
Dim HBox As JavaObject
|
||||
HBox.InitializeNewInstance("javafx.scene.layout.HBox",Null)
|
||||
HBox.RunMethodJO("getChildren",Null).RunMethod("add",Array(Lbl2))
|
||||
HBox.RunMethodJO("getChildren",Null).RunMethod("add",Array(Lbl3))
|
||||
HBox.RunMethod("setSpacing",Array(10.0))
|
||||
|
||||
'
|
||||
'Add them along with submenu1 to the main menu
|
||||
'
|
||||
Dim MainMenu As List = Array As Object( _
|
||||
FileMenu.MenuSeparator, _
|
||||
FileMenu.MenuSubMenu("SubMenu1",SubMenu1), _
|
||||
FileMenu.MenuSeparator, _
|
||||
FileMenu.MenuText("Menuitem Alternate Event Name").SetTag("AEN").SetEventName("AltEN"), _
|
||||
FileMenu.MenuCustom(Lbl).SetTag("IWT"), _
|
||||
FileMenu.MenuCustom(HBox).SetTag("IWT2").SetEventName("HBox") _
|
||||
)
|
||||
|
||||
|
||||
|
||||
'*******************************************************************************************************************
|
||||
'Items attached to the help menu
|
||||
'*******************************************************************************************************************
|
||||
|
||||
HelpMenu.Initialize(Me,"Menu","Help")
|
||||
Dim Simple2 As List = HelpMenu.SimpleMenuList(Array As String("About"))
|
||||
|
||||
|
||||
|
||||
|
||||
'*******************************************************************************************************************
|
||||
'Build and add the menus to the menu bar
|
||||
'*******************************************************************************************************************
|
||||
|
||||
'Get the Menumanager to build the menus
|
||||
FileMenu.AddItems(MainMenu,True)
|
||||
HelpMenu.AddItems(Simple2,True)
|
||||
|
||||
'Add the built menus to the MenuBar
|
||||
MenuBar1.Menus.Add(FileMenu.Menu)
|
||||
MenuBar1.Menus.Add(HelpMenu.menu)
|
||||
|
||||
|
||||
'*******************************************************************************************************************
|
||||
'MMContext with submenus
|
||||
'*******************************************************************************************************************
|
||||
|
||||
MMContext.Initialize(Me,"MContext","")
|
||||
|
||||
'
|
||||
'Need to set the MENUTYPE for a context menu
|
||||
'
|
||||
MMContext.MenuType = MMContext.MENUTYPE_CONTEXTMENU
|
||||
|
||||
'
|
||||
'Note: of you want to change the state of a menu checkbox in code, you will need to keep a reference to it as a global variable,
|
||||
'the same goes for changing any attributes once the menus are built. See the disabledicon in the main menu.
|
||||
|
||||
Dim Lbl As Label
|
||||
Lbl.Initialize("")
|
||||
Lbl.Text = "Item with Tooltip"
|
||||
Lbl.TooltipText = "Tooltip for label"
|
||||
'
|
||||
Dim SubMenu2 As List = Array( _
|
||||
MMContext.MenuCheckBox("Option 1").SetTag("CM Option 1"), _
|
||||
MMContext.MenuSeparator, _
|
||||
MMContext.MenuCheckBox("Option 2").SetTag("CM Option 2"), _
|
||||
MMContext.MenuCheckBox("Option 3").SetTag("CM Option 3"))
|
||||
|
||||
Dim SubMenu1 As List = Array( _
|
||||
MMContext.MenuText("Item 2-1").SetTag("CM Item 2-1"), _
|
||||
MMContext.MenuSeparator, _
|
||||
MMContext.MenuSubMenu("SubMenu2",SubMenu2), _
|
||||
MMContext.MenuSeparator, _
|
||||
MMContext.MenuText("Item With image As Icon").SetTag("CM Img 1").SetGraphic(FileMenu.NewImage(File.DirAssets,"icon.png")))
|
||||
|
||||
Dim SimpleMenu As List = MMContext.SimpleMenuList(Array As String("Simple 1","Simple 2","-","Simple 3"))
|
||||
|
||||
Dim MenuContext As List = Array As Object( _
|
||||
MMContext.MenuTitle("MMContextTitle").SetHideOnClick(False,True), _
|
||||
MMContext.MenuSeparator, _
|
||||
MMContext.MenuSubMenu("SubMenu1",SubMenu1), _
|
||||
MMContext.MenuSubMenu("Simple Menu",SimpleMenu), _
|
||||
MMContext.MenuSeparator, _
|
||||
MMContext.MenuText("Menuitem 1").SetTag("CM MI 1"))
|
||||
|
||||
'
|
||||
'Add the menu to the menu manager for building
|
||||
'
|
||||
MMContext.AddItems(MenuContext,True)
|
||||
MMContext.AddItems(Array(MMContext.MenuCustom(Lbl)),False)
|
||||
|
||||
'
|
||||
'Assign the menu to the context menu, need to keep this as a global variable so we can call it when needed.
|
||||
'
|
||||
ContextMenu1 = MMContext.Menu
|
||||
|
||||
End Sub
|
||||
|
||||
'*******************************************************************************************************************
|
||||
'Menu Callbacks
|
||||
'*******************************************************************************************************************
|
||||
|
||||
Sub Menu_CustomAction(MC As MenuCustomClass)
|
||||
Dim L As Label = MC.GetContent
|
||||
Log("MainMenu Text Activated" & L.Text & " Tag " & MC.GetTag)
|
||||
End Sub
|
||||
|
||||
Sub HBox_CustomAction(MC As MenuCustomClass)
|
||||
Dim HBox As JavaObject = MC.GetContent
|
||||
Dim Children As List = HBox.RunMethod("getChildren",Null)
|
||||
Dim L As Label = Children.Get(1)
|
||||
Log("Menu Text Activated" & L.Text & " Tag " & MC.GetTag)
|
||||
End Sub
|
||||
|
||||
'
|
||||
'A menu item has been clicked
|
||||
'
|
||||
Sub Menu_Action(MI As MenuItemTextClass)
|
||||
Log("Menu Text Activated " & MI.Text & " Tag " & MI.GetTag)
|
||||
|
||||
'Enable and disable an item with graphic
|
||||
If MI.GetTag = "EnableMA1" Then
|
||||
If DisabledIcon.GetEnabled = False Then
|
||||
DisabledIcon.SetEnabled(True).SetGraphic(FileMenu.NewMaterialIcon(Chr(0xE876),fx.Colors.Green))
|
||||
MI.Text = "Disable Above Item"
|
||||
Else
|
||||
DisabledIcon.SetEnabled(False).SetGraphic(FileMenu.NewMaterialIcon(Chr(0xE14B),fx.Colors.Red)).SetEnabled(False)
|
||||
MI.Text = "Enable Above Item"
|
||||
End If
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Sub Menu_MenuOpening(M As Menu)
|
||||
Log(M & " opening")
|
||||
End Sub
|
||||
|
||||
'
|
||||
'A checkbox item has been clicked
|
||||
'
|
||||
Sub Menu_SelectedChanged(MCB As MenuCheckBoxClass)
|
||||
Log(MCB.Text & " Checked = " & MCB.GetSelected & " Tag " & MCB.getTag)
|
||||
End Sub
|
||||
|
||||
'
|
||||
'A menu item has been clicked (For alternate Event Name Test)
|
||||
'
|
||||
Sub AltEn_Action(MI As MenuItemTextClass)
|
||||
Log("Alternate EventName Activated Menu Text " & MI.Text & " Tag " & MI.GetTag)
|
||||
End Sub
|
||||
|
||||
|
||||
|
||||
'*******************************************************************************************************************
|
||||
'Show the context menu
|
||||
'*******************************************************************************************************************
|
||||
|
||||
'Show the MMContext if label1 is Right Clicked
|
||||
Sub Label1_MousePressed(EventData As MouseEvent)
|
||||
If EventData.SecondaryButtonDown Then MenuManagerUtils.AsJO(ContextMenu1).RunMethod("show",Array(Label1,"RIGHT",0.0,0.0))
|
||||
End Sub
|
||||
|
||||
|
||||
'*******************************************************************************************************************
|
||||
'Context Menu callbacks
|
||||
'*******************************************************************************************************************
|
||||
|
||||
'A checkbox item has been clicked (For alternate Event Name Test)
|
||||
Sub MContext_SelectedChanged(MCB As MenuCheckBoxClass)
|
||||
Log("6")
|
||||
Log("Context Menu Activated " & MCB.Text & " Checked = " & MCB.GetSelected & " Tag " & MCB.getTag)
|
||||
End Sub
|
||||
|
||||
Sub MContext_Action(MI As MenuItemTextClass)
|
||||
Log("7")
|
||||
Log("ContextMenu Text Activated " & MI.Text & " Tag " & MI.GetTag)
|
||||
End Sub
|
||||
23
MenuManager/MenuManager.b4j.meta
Normal file
23
MenuManager/MenuManager.b4j.meta
Normal file
@@ -0,0 +1,23 @@
|
||||
ModuleBookmarks0=
|
||||
ModuleBookmarks1=
|
||||
ModuleBookmarks2=
|
||||
ModuleBookmarks3=
|
||||
ModuleBookmarks4=
|
||||
ModuleBookmarks5=
|
||||
ModuleBookmarks6=
|
||||
ModuleBreakpoints0=
|
||||
ModuleBreakpoints1=
|
||||
ModuleBreakpoints2=
|
||||
ModuleBreakpoints3=
|
||||
ModuleBreakpoints4=
|
||||
ModuleBreakpoints5=
|
||||
ModuleBreakpoints6=
|
||||
ModuleClosedNodes0=
|
||||
ModuleClosedNodes1=
|
||||
ModuleClosedNodes2=
|
||||
ModuleClosedNodes3=
|
||||
ModuleClosedNodes4=
|
||||
ModuleClosedNodes5=
|
||||
ModuleClosedNodes6=
|
||||
SelectedBuild=0
|
||||
VisibleModules=1,2,3,4,5,6
|
||||
427
MenuManager/MenuManager.bas
Normal file
427
MenuManager/MenuManager.bas
Normal file
@@ -0,0 +1,427 @@
|
||||
B4J=true
|
||||
Group=Default Group
|
||||
ModulesStructureVersion=1
|
||||
Type=Class
|
||||
Version=5.9
|
||||
@EndOfDesignText@
|
||||
#Event: CustomAction(MC AS MenuCustomClass)
|
||||
#Event: Action(MI as MenuItemTextClass)
|
||||
#Event: SelectedChanged(MCB as MenuCheckBoxClass)
|
||||
#Event: MenuOpening(M as Menu)
|
||||
Sub Class_Globals
|
||||
Private fx As JFX
|
||||
Type MenuItemType(mType As String,Text As String)
|
||||
Type MenuSubMenuType(Title As String, SubMenu As List)
|
||||
|
||||
Public Const MENUTYPE_MENU As String = "menu"
|
||||
Public Const MENUTYPE_CONTEXTMENU As String = "context"
|
||||
Private mMenuType As String = MENUTYPE_MENU
|
||||
Private mMenuTitle As String
|
||||
Private CM As ContextMenu
|
||||
Private MU As Menu
|
||||
Private mModule As Object
|
||||
Private mEventName As String
|
||||
Private CustomNodeList As List
|
||||
End Sub
|
||||
|
||||
'Initializes the object
|
||||
'Default menuType is MENUTYPE_MENU
|
||||
Public Sub Initialize(Module As Object, EventName As String, MenuTitleText As String)
|
||||
mModule = Module
|
||||
mEventName = EventName
|
||||
mMenuTitle = MenuTitleText
|
||||
MU.Initialize(mMenuTitle,"MU")
|
||||
AddStyle(MU,Array As String(""))
|
||||
Dim MUJO As JavaObject = MU
|
||||
Dim O As Object = MUJO.CreateEventFromUI("javafx.event.EventHandler","MU",Null)
|
||||
MUJO.RunMethod("setOnShowing",Array(O))
|
||||
End Sub
|
||||
|
||||
'Get / Set MenuType one of the constants: MENUTYPE_MENU or MENUTYPE_CONTEXTMENU
|
||||
Public Sub setMenuType(MenuType As String)
|
||||
mMenuType = MenuType
|
||||
If mMenuType = MENUTYPE_CONTEXTMENU Then
|
||||
If CM.IsInitialized = False Then
|
||||
CM.Initialize("CM")
|
||||
AddStyle(CM,Array As String(""))
|
||||
End If
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Public Sub getMenuType As String
|
||||
Return mMenuType
|
||||
End Sub
|
||||
|
||||
|
||||
'Add text or Menuitems items to the menu, as an array, Pass a '-' to add a text seperator
|
||||
'<code>FM.AddItems(Array As String("Test","-","Test1"))</code>
|
||||
Public Sub AddItems(Items As List,Clear As Boolean)
|
||||
If mMenuType = MENUTYPE_CONTEXTMENU Then
|
||||
If Clear Then
|
||||
CM.MenuItems.Clear
|
||||
If CustomNodeList.IsInitialized Then CustomNodeList.Clear
|
||||
End If
|
||||
BuildContextMenu (Items)
|
||||
End If
|
||||
|
||||
If mMenuType = MENUTYPE_MENU Then
|
||||
If Clear Then MU.MenuItems.Clear
|
||||
BuildMenu(Items)
|
||||
End If
|
||||
|
||||
End Sub
|
||||
|
||||
Private Sub BuildMenu (Items As List)
|
||||
|
||||
'Populate the context menu
|
||||
For Each It As Object In Items
|
||||
If It Is MenuSubMenuType Then
|
||||
Dim SMT As MenuSubMenuType = It
|
||||
MU.MenuItems.Add(BuildSubMenu(SMT.Title,SMT.SubMenu))
|
||||
Else IF It Is MenuCheckBoxClass Then
|
||||
Dim MCB As MenuCheckBoxClass = It
|
||||
MU.MenuItems.Add(MCB.AsObject)
|
||||
Else If It Is MenuItemTextClass Then
|
||||
Dim MIT As MenuItemTextClass = It
|
||||
MU.MenuItems.Add(MIT.AsObject)
|
||||
Else IF It Is MenuCustomClass Then
|
||||
Dim CIT As MenuCustomClass = It
|
||||
MU.MenuItems.Add(CIT.AsObject)
|
||||
Else
|
||||
MU.MenuItems.Add(It)
|
||||
End If
|
||||
Next
|
||||
End Sub
|
||||
|
||||
|
||||
Private Sub BuildContextMenu (Items As List)
|
||||
'Populate the context menu
|
||||
For Each It As Object In Items
|
||||
If It Is MenuSubMenuType Then
|
||||
Dim SMT As MenuSubMenuType = It
|
||||
CM.MenuItems.Add(BuildSubMenu(SMT.Title,SMT.SubMenu))
|
||||
Else IF It Is MenuCheckBoxClass Then
|
||||
Dim MCB As MenuCheckBoxClass = It
|
||||
CM.MenuItems.Add(MCB.AsObject)
|
||||
Else If It Is MenuItemTextClass Then
|
||||
Dim MIT As MenuItemTextClass = It
|
||||
CM.MenuItems.Add(MIT.AsObject)
|
||||
Else IF It Is MenuCustomClass Then
|
||||
Dim CIT As MenuCustomClass = It
|
||||
CM.MenuItems.Add(CIT.AsObject)
|
||||
Else
|
||||
CM.MenuItems.Add(It)
|
||||
End If
|
||||
Next
|
||||
End Sub
|
||||
|
||||
'Build and return a submenu
|
||||
Private Sub BuildSubMenu(Title As String,Items As List) As Menu
|
||||
Dim M As Menu
|
||||
M.Initialize(Title,"MI")
|
||||
'Process the menu Items
|
||||
For Each It As Object In Items
|
||||
If It Is MenuSubMenuType Then
|
||||
Dim SMT As MenuSubMenuType = It
|
||||
M.MenuItems.Add(BuildSubMenu(SMT.Title,SMT.SubMenu))
|
||||
Else IF It Is MenuCheckBoxClass Then
|
||||
Dim MCB As MenuCheckBoxClass = It
|
||||
M.MenuItems.Add(MCB.AsObject)
|
||||
AddStyle(MCB.AsJavaObject,Array As String(""))
|
||||
Else If It Is MenuItemTextClass Then
|
||||
Dim MIT As MenuItemTextClass = It
|
||||
M.MenuItems.Add(MIT.AsObject)
|
||||
AddStyle(MIT.AsJavaObject,Array As String(""))
|
||||
Else IF It Is MenuCustomClass Then
|
||||
Dim CIT As MenuCustomClass = It
|
||||
M.MenuItems.Add(CIT.AsObject)
|
||||
AddStyle(CIT.AsJavaObject,Array As String(""))
|
||||
End If
|
||||
Next
|
||||
'Add a style to the SubMenu
|
||||
AddStyle(M,Array As String(""))
|
||||
Return M
|
||||
End Sub
|
||||
|
||||
Private Sub AddStyle(Target As JavaObject,Styles() As String)
|
||||
|
||||
Dim S() As String
|
||||
Dim MString As String
|
||||
|
||||
If mMenuType = MENUTYPE_MENU Then
|
||||
MString = "mm-menu"
|
||||
Else
|
||||
MString = "mm-cmenu"
|
||||
End If
|
||||
|
||||
Dim L As List = Target.RunMethodJO("getStyleClass",Null)
|
||||
If L.IndexOf(MString) = -1 Then
|
||||
Dim S(Styles.Length + 1) As String
|
||||
For i = 0 To Styles.Length -1
|
||||
S(i+1) = Styles(i)
|
||||
Next
|
||||
S(0) = MString
|
||||
Else
|
||||
S = Styles
|
||||
End If
|
||||
Target.RunMethodJO("getStyleClass",Null).RunMethod("addAll",Array(S))
|
||||
|
||||
End Sub
|
||||
|
||||
Public Sub getMenu As Object
|
||||
If mMenuType = MENUTYPE_CONTEXTMENU Then Return CM
|
||||
If mMenuType = MENUTYPE_MENU Then Return MU
|
||||
Return Null
|
||||
End Sub
|
||||
|
||||
'Menu item clicked, pass it back to the originating module
|
||||
Private Sub MI_Action
|
||||
Dim MI As MenuItemTextClass = Sender
|
||||
Dim EName As String = mEventName
|
||||
If MI.GetEventName <> "" Then EName = MI.GetEventName
|
||||
If SubExists(mModule,EName & "_Action") Then CallSub2(mModule,EName & "_Action",MI)
|
||||
End Sub
|
||||
|
||||
'Custom Menu item clicked, pass it back to the originating module
|
||||
Private Sub MC_Action
|
||||
Dim MC As MenuCustomClass = Sender
|
||||
Dim EName As String = mEventName
|
||||
If MC.GetEventName <> "" Then EName = MC.GetEventName
|
||||
If SubExists(mModule,EName & "_CustomAction") Then CallSub2(mModule,EName & "_CustomAction",MC)
|
||||
End Sub
|
||||
|
||||
Private Sub MU_Event (MethodName As String, Args() As Object)
|
||||
Dim M As Menu = Sender
|
||||
If SubExists(mModule,mEventName & "_MenuOpening") Then CallSub2(mModule,mEventName & "_MenuOpening",M)
|
||||
End Sub
|
||||
|
||||
Private Sub CB_SelectedChanged(MCB As MenuCheckBoxClass)
|
||||
Dim EName As String = mEventName
|
||||
If MCB.GetEventName <> "" Then EName = MCB.GetEventName
|
||||
If SubExists(mModule,EName &"_SelectedChanged") Then CallSub2(mModule,EName & "_SelectedChanged",MCB)
|
||||
End Sub
|
||||
|
||||
Private Sub CB_Action(MCB As MenuCheckBoxClass)
|
||||
Dim EName As String = mEventName
|
||||
If MCB.GetEventName <> "" Then EName = MCB.GetEventName
|
||||
If SubExists(mModule,EName &"_Action") Then CallSub2(mModule,EName & "_Action",MCB)
|
||||
End Sub
|
||||
|
||||
|
||||
'Create a simple menu List from a string array
|
||||
'Use '-' for a separator. Pass the result to MM.AddItems
|
||||
Public Sub SimpleMenuList(Simple() As String) As List
|
||||
Dim L As List
|
||||
L.Initialize
|
||||
For Each S As String In Simple
|
||||
If S = "-" Then
|
||||
L.Add(MenuSeparator)
|
||||
Else
|
||||
L.Add(MenuText(S))
|
||||
End If
|
||||
Next
|
||||
Return L
|
||||
End Sub
|
||||
|
||||
'Create a simple menu Array from a string array
|
||||
'No Seperators. Pass the result to MM.AddItems
|
||||
'Configure extras e.g. <code>A(2).SetTag("Tag 2")</code>
|
||||
Public Sub SimpleMenuArray(Simple() As String) As MenuItemTextClass()
|
||||
Dim A(Simple.length) As MenuItemTextClass
|
||||
For i = 0 To Simple.Length -1
|
||||
A(i) = MenuText(Simple(i))
|
||||
Next
|
||||
Return A
|
||||
End Sub
|
||||
|
||||
'Create a sub menu with title and content
|
||||
Public Sub MenuSubMenu(Title As String,SubMenu As List) As MenuSubMenuType
|
||||
Dim SM As MenuSubMenuType
|
||||
SM.Initialize
|
||||
SM.Title = Title
|
||||
SM.SubMenu = SubMenu
|
||||
' AddStyle(SM,Array As String(""))
|
||||
Return SM
|
||||
End Sub
|
||||
|
||||
'Create and return a SeperatorMenuItem Object
|
||||
Public Sub MenuSeparator As Object
|
||||
Dim JO As JavaObject
|
||||
JO.InitializeNewInstance("javafx.scene.control.SeparatorMenuItem",Null)
|
||||
'Add a style to the Separator
|
||||
' JO.RunMethodJO("getStyleClass",Null).RunMethod("add",Array("cmenu"))
|
||||
AddStyle(JO,Array As String("mm-separator"))
|
||||
Return JO
|
||||
End Sub
|
||||
|
||||
'Create and return a TextMenuItem Object
|
||||
Public Sub MenuText(Text As String) As MenuItemTextClass
|
||||
Dim MI As MenuItemTextClass
|
||||
MI.Initialize(Me,"MI",Text)
|
||||
'Add a style to the MenuItem
|
||||
' MI.ASJavaObject.RunMethodJO("getStyleClass",Null).RunMethod("addAll",Array(Array As String("cmenu","menutext")))
|
||||
AddStyle(MI.AsJavaObject,Array As String("mm-menutext"))
|
||||
Return MI
|
||||
End Sub
|
||||
|
||||
'Create and return a MenuCustom Object
|
||||
Public Sub MenuCustom(N As Node) As MenuCustomClass
|
||||
Dim MI As MenuCustomClass
|
||||
MI.Initialize(Me,"MC",N)
|
||||
If CustomNodeList.IsInitialized = False Then
|
||||
CustomNodeList.Initialize
|
||||
End If
|
||||
CustomNodeList.add(N)
|
||||
If mMenuType = MENUTYPE_MENU Then
|
||||
SetListener(MI,N)
|
||||
Else
|
||||
SetOnShownListener
|
||||
End If
|
||||
'Add a style to the MenuItem
|
||||
' MI.ASJavaObject.RunMethodJO("getStyleClass",Null).RunMethod("addAll",Array(Array As String("cmenu","menucustom")))
|
||||
AddStyle(MI.AsJavaObject,Array As String("mm-menucustom"))
|
||||
Return MI
|
||||
End Sub
|
||||
|
||||
'Adjust the width of custom object on a Context Menu
|
||||
Private Sub SetOnShownListener
|
||||
Dim JO As JavaObject
|
||||
JO = CM
|
||||
Dim O As Object = JO.CreateEventFromUI("javafx.event.EventHandler","OnShown",Null)
|
||||
JO.RunMethod("setOnShown",Array(O))
|
||||
Wait For (JO) OnShown_Event (MethodName As String, Args() As Object)
|
||||
Dim Width As Double = JO.RunMethod("getWidth",Null)
|
||||
For Each N As Node In CustomNodeList
|
||||
N.PrefWidth = Width
|
||||
Next
|
||||
End Sub
|
||||
|
||||
|
||||
'Need to set the width for custom views if we want a tooltip as the label won't necessarily take the whole width of the menu
|
||||
Private Sub SetListener(MI As MenuCustomClass,N As Node)
|
||||
|
||||
'Code from here: https://stackoverflow.com/questions/28699152/how-to-get-menu-or-menuitem-width-in-javafx
|
||||
Dim O As Object = MenuManagerUtils.AsJO(N).CreateEvent("javafx.beans.value.ChangeListener","PopupChanged",Null)
|
||||
Dim Parent As JavaObject
|
||||
Parent = MI.AsJavaObject.RunMethodJO("parentPopupProperty",Null)
|
||||
Parent.RunMethod("addListener",Array(O))
|
||||
|
||||
Wait For (N) PopupChanged_Event (MethodName As String, Args() As Object)
|
||||
|
||||
Dim ParentPopup As JavaObject
|
||||
Dim ParentPopupSkinProperty As JavaObject
|
||||
Dim MenuItemWidthProperty As JavaObject
|
||||
Dim MenuItemContainer As JavaObject
|
||||
ParentPopup = Args(2)
|
||||
ParentPopupSkinProperty = ParentPopup.RunMethodJO("skinProperty",Null)
|
||||
|
||||
Dim O As Object = ParentPopupSkinProperty.CreateEvent("javafx.beans.value.ChangeListener","PopupChanged1",Null)
|
||||
ParentPopupSkinProperty.RunMethod("addListener",Array(O))
|
||||
|
||||
Wait For (ParentPopupSkinProperty) PopupChanged1_Event (MethodName As String, Args() As Object)
|
||||
MenuItemContainer = getAssociatedNode(MI)
|
||||
MenuItemWidthProperty = MenuItemContainer.RunMethod("widthProperty",Null)
|
||||
Dim O As Object = MenuItemWidthProperty.CreateEvent("javafx.beans.value.ChangeListener","PopupChanged2",Null)
|
||||
MenuItemWidthProperty.RunMethod("addListener",Array(O))
|
||||
|
||||
Wait For (MenuItemWidthProperty) PopupChanged2_Event (MethodName As String, Args() As Object)
|
||||
|
||||
For Each N As Node In CustomNodeList
|
||||
N.PrefWidth = Args(2)
|
||||
Next
|
||||
End Sub
|
||||
|
||||
'Helper sub for the SetListener process
|
||||
Private Sub getAssociatedNode(MI As MenuCustomClass) As JavaObject
|
||||
Dim Menu As JavaObject
|
||||
Dim MenuSkin As JavaObject
|
||||
Dim Content As JavaObject
|
||||
Dim ItemsContainer As JavaObject
|
||||
Dim Children As List
|
||||
Dim MenuItemContainer As JavaObject
|
||||
|
||||
If mMenuType = MENUTYPE_MENU Then
|
||||
Menu = MI.AsJavaObject.RunMethod("getParentPopup",Null)
|
||||
MenuSkin = Menu.RunMethod("getSkin",Null)
|
||||
Content = MenuSkin.RunMethod("getNode",Null)
|
||||
ItemsContainer = Content.RunMethod("getItemsContainer",Null)
|
||||
Children = ItemsContainer.RunMethod("getChildrenUnmodifiable",Null)
|
||||
For Each Child As Node In Children
|
||||
If GetType(Child) = "com.sun.javafx.scene.control.skin.ContextMenuContent$MenuItemContainer" Then
|
||||
MenuItemContainer = Child
|
||||
If MenuItemContainer.RunMethod("getItem",Null) = MI.AsObject Then
|
||||
Return MenuItemContainer
|
||||
End If
|
||||
End If
|
||||
Next
|
||||
Else
|
||||
End If
|
||||
Return Null
|
||||
End Sub
|
||||
|
||||
|
||||
'Create and Return a CheckMenuItem and set a changelistener
|
||||
'SelectedCChanged(MSB As MenuCheckBoxClass)
|
||||
Public Sub MenuCheckBox(Text As String) As MenuCheckBoxClass
|
||||
Dim MCB As MenuCheckBoxClass
|
||||
MCB.Initialize(Me,"CB",Text)
|
||||
'Add a style to the Checkbox Menu Item
|
||||
AddStyle(MCB.AsJavaObject,Array As String("mm-checkbox"))
|
||||
Return MCB
|
||||
End Sub
|
||||
|
||||
'Create and return a MenuTitle Object, make it not hide when clicked
|
||||
Public Sub MenuTitle(Text As String) As MenuCustomClass
|
||||
Dim Lbl As Label
|
||||
Lbl.Initialize("")
|
||||
Lbl.Text = Text
|
||||
Dim MCC As MenuCustomClass
|
||||
MCC.Initialize(Me,"",Lbl)
|
||||
'Add a style to the MenuItem
|
||||
AddStyle(MCC.AsJavaObject,Array As String("mm-title"))
|
||||
Return MCC
|
||||
End Sub
|
||||
|
||||
'Create and return a Label containing the defined FontAwesome Character
|
||||
Public Sub NewFontAwesome(FA As Char,Color As Paint) As Node
|
||||
Dim L As Label
|
||||
L.Initialize("")
|
||||
L.Font = fx.CreateFontAwesome(12)
|
||||
L.Text = FA
|
||||
L.TextColor = Color
|
||||
AddStyle(L,Array As String("mm-graphic","mm-fa-lbl"))
|
||||
Return L
|
||||
End Sub
|
||||
|
||||
'Create and return a Label containing the defined MaterialIcon Character
|
||||
Public Sub NewMaterialIcon(FA As Char,Color As Paint) As Node
|
||||
Dim L As Label
|
||||
L.Initialize("")
|
||||
L.Font = fx.CreateMaterialIcons(12)
|
||||
L.Text = FA
|
||||
L.TextColor = Color
|
||||
AddStyle(L,Array As String("mm-graphic","mm-ma-lbl"))
|
||||
Return L
|
||||
End Sub
|
||||
|
||||
'Helper to create an image view from a filepath/filename to add to the menu item
|
||||
Public Sub NewImage(FilePath As String,FileName As String) As ImageView
|
||||
Dim Img As ImageView
|
||||
Img.Initialize("")
|
||||
Img.SetImage(fx.LoadImageSample(FilePath,FileName,16,16))
|
||||
AddStyle(Img,Array As String("mm-graphic-img"))
|
||||
Return Img
|
||||
End Sub
|
||||
|
||||
Public Sub SetStyleSheet(FilePath As String,FileName As String)
|
||||
|
||||
End Sub
|
||||
|
||||
'Get/Set a tag on the menumanager object
|
||||
Public Sub setTag(Tag As Object)
|
||||
MenuManagerUtils.AsJO(Me).runMethod("setUserData", Array(Tag))
|
||||
End Sub
|
||||
|
||||
Public Sub getTag As Object
|
||||
Return MenuManagerUtils.AsJO(Me).runMethod("getUserData", Null)
|
||||
End Sub
|
||||
16
MenuManager/MenuManagerUtils.bas
Normal file
16
MenuManager/MenuManagerUtils.bas
Normal file
@@ -0,0 +1,16 @@
|
||||
B4J=true
|
||||
Group=Default Group
|
||||
ModulesStructureVersion=1
|
||||
Type=StaticCode
|
||||
Version=5.9
|
||||
@EndOfDesignText@
|
||||
'Static code module
|
||||
#IgnoreWarnings: 12
|
||||
Sub Process_Globals
|
||||
Private fx As JFX
|
||||
End Sub
|
||||
|
||||
'Return a JavaObject
|
||||
Sub AsJO(JO As JavaObject) As JavaObject
|
||||
Return JO
|
||||
End Sub
|
||||
Reference in New Issue
Block a user