AbstractActions 的枚举集包装器
我想在运行时将一系列 Swing 操作加载到容器中,并通过常量名称访问它们,就像使用枚举一样。这样做的目的是限制可能的操作并提高可读性。
最初,我正在考虑一种动态枚举(请参阅 http ://blog.xebia.com/2009/04/02/dynamic-enums-in-java/),但正如 Java Drinker 下面指出的那样,这是不必要的,因为操作保持不变。
理想情况下,我想要做的是一种包含 AbstractAction 实例的包装器,这些实例可以启用/禁用,并且能够通过符号名称引用每个操作。
编辑:问题已重新表述。
I'd like to load a series of Swing Actions into a container at runtime and access them by a constant name as is possible with an Enum. The purpose of this would be to both restrict the Actions possible and also improve readability.
Initially, I was considering a sort of dynamic enum (see http://blog.xebia.com/2009/04/02/dynamic-enums-in-java/) but as Java Drinker points out below this is unnecessary since the actions remain unchanged.
Ideally, what I'd like to do is a sort of wrapper that contains AbstractAction
instances which could be enabled/disabled and be able to refer to each action through a symbolic name.
Edit: Question has been reformulated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以这样做:
然后正如其他人所说,将枚举与 EnumSet 或 EnumMap 结合使用。就我个人而言,我认为它并没有比仅仅拥有一些没有枚举的命名字段有更大的价值。
我认为您真正想要的是某种像这样的操作注册表:
实施留作练习。
You can do something like this:
And then as others have said, use the enum in conjunction with an EnumSet or EnumMap. Personally, I don't see a huge value in it over just having a few named fields without an enum.
I think what you really want is some kind of Action registry like this:
Implementation left as an exercise.