Mercurial > cgi-bin > hgweb.cgi > ClipMan
comparison src/name/blackcap/clipman/Menus.kt @ 35:5f8475b37e23
Got it correctly enabling and disabling menu items.
author | David Barts <n5jrn@me.com> |
---|---|
date | Thu, 30 Jan 2020 20:21:42 -0800 |
parents | 0c6c18a733b7 |
children | fcf82e3b7e31 |
comparison
equal
deleted
inserted
replaced
34:376643a09b52 | 35:5f8475b37e23 |
---|---|
1 /* | 1 /* |
2 * Menu-related stuff, pertaining to both the menu bar and popup menus. | 2 * Menu-related stuff, pertaining to both the menu bar and popup menus. |
3 */ | 3 */ |
4 package name.blackcap.clipman | 4 package name.blackcap.clipman |
5 | 5 |
6 import java.awt.Container | |
6 import java.awt.Toolkit | 7 import java.awt.Toolkit |
7 import java.awt.event.ActionEvent | 8 import java.awt.event.ActionEvent |
8 import java.awt.event.ActionListener | 9 import java.awt.event.ActionListener |
9 import java.awt.event.KeyEvent | 10 import java.awt.event.KeyEvent |
10 import java.util.LinkedList | |
11 import javax.swing.* | 11 import javax.swing.* |
12 import kotlin.collections.HashSet | |
12 | 13 |
13 /** | 14 /** |
14 * Listen to actionEvents from both menu bar and popup menu selections. | 15 * Listen to actionEvents from both menu bar and popup menu selections. |
15 */ | 16 */ |
16 class MenuItemListener: ActionListener { | 17 class MenuItemListener: ActionListener { |
56 /** | 57 /** |
57 * Track menu items that require something to be selected in order | 58 * Track menu items that require something to be selected in order |
58 * to work, and allow them to be enabled and disabled en masse. | 59 * to work, and allow them to be enabled and disabled en masse. |
59 */ | 60 */ |
60 class SelectionRequired { | 61 class SelectionRequired { |
61 private val cache = LinkedList<JMenuItem>() | 62 private val controls = HashSet<JMenuItem>() |
63 /* private val parents = HashSet<Container>() */ | |
62 | 64 |
63 fun add(item: JMenuItem): JMenuItem { | 65 fun add(item: JMenuItem): JMenuItem { |
64 cache.add(item) | 66 controls.add(item) |
67 /* var p = item.parent | |
68 if (p != null) { | |
69 parents.add(p) | |
70 } */ | |
65 return item | 71 return item |
66 } | 72 } |
67 | 73 |
68 fun enable() { | 74 private fun setEnabled(state: Boolean) { |
69 cache.forEach { | 75 controls.forEach { |
70 it.setEnabled(true) | 76 it.setEnabled(state) |
71 } | 77 } |
78 /* parents.forEach { | |
79 it.validate() | |
80 } */ | |
72 } | 81 } |
73 | 82 |
74 fun disable() { | 83 fun enable() = setEnabled(true) |
75 cache.forEach { | 84 |
76 it.setEnabled(false) | 85 fun disable() = setEnabled(false) |
77 } | |
78 } | |
79 } | 86 } |
80 | 87 |
81 val anyRequired = SelectionRequired() | 88 val anyRequired = SelectionRequired() |
82 val styledRequired = SelectionRequired() | 89 val styledRequired = SelectionRequired() |
83 | 90 |