You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ActionGroup.java 6.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. /*
  2. * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to deal
  6. * in the Software without restriction, including without limitation the rights
  7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. * copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. * SOFTWARE.
  21. */
  22. package com.dmdirc.actions;
  23. import com.dmdirc.config.prefs.PreferencesSetting;
  24. import java.util.ArrayList;
  25. import java.util.HashMap;
  26. import java.util.Iterator;
  27. import java.util.List;
  28. import java.util.Map;
  29. /**
  30. * Represents a group of actions, along with their meta-data.
  31. *
  32. * @author chris
  33. */
  34. public class ActionGroup implements Iterable<Action> {
  35. /**
  36. * A version number for this class. It should be changed whenever the class
  37. * structure is changed (or anything else that would prevent serialized
  38. * objects being unserialized with the new class).
  39. */
  40. private static final long serialVersionUID = 1;
  41. /** The actions in this group. */
  42. private final List<Action> actions = new ArrayList<Action>();
  43. /** The name of this action group. */
  44. private final String name;
  45. /** The description of this action group. */
  46. private String description = null;
  47. /** The author of this action group. */
  48. private String author = null;
  49. /** The component number of this action group (for updating). */
  50. private int component = -1;
  51. /** The version number of this action group. */
  52. private int version = -1;
  53. /** A list of settings used by this action group. */
  54. private final Map<String, PreferencesSetting> settings
  55. = new HashMap<String, PreferencesSetting>();
  56. /**
  57. * Creates a new instance of ActionGroup.
  58. *
  59. * @param name The name of this action group
  60. */
  61. public ActionGroup(final String name) {
  62. super();
  63. this.name = name;
  64. }
  65. /**
  66. * Retrieves the author of this ActionGroup.
  67. *
  68. * @return This action group's author, or null if the author isn't specified
  69. */
  70. public String getAuthor() {
  71. return author;
  72. }
  73. /**
  74. * Sets the author of this ActionGroup.
  75. *
  76. * @param author The new author for this action group
  77. */
  78. public void setAuthor(final String author) {
  79. this.author = author;
  80. }
  81. /**
  82. * Retrieves the description of this action group.
  83. *
  84. * @return This action group's description, or null if none is specified
  85. */
  86. public String getDescription() {
  87. return description;
  88. }
  89. /**
  90. * Sets the description for this action group.
  91. *
  92. * @param description The new description for this action group
  93. */
  94. public void setDescription(final String description) {
  95. this.description = description;
  96. }
  97. /**
  98. * Retrieves the name of this action group.
  99. *
  100. * @return This action group's name
  101. */
  102. public String getName() {
  103. return name;
  104. }
  105. /**
  106. * Retrieves a map settings used by this action group.
  107. *
  108. * @return A map of setting names to values
  109. */
  110. public Map<String, PreferencesSetting> getSettings() {
  111. return settings;
  112. }
  113. /**
  114. * Retrieves the version number of this action group.
  115. *
  116. * @return This action group's version number, or -1 if none is specified.
  117. */
  118. public int getVersion() {
  119. return version;
  120. }
  121. /**
  122. * Sets the version of this action group.
  123. *
  124. * @param version This action group's new version number.
  125. */
  126. public void setVersion(final int version) {
  127. this.version = version;
  128. }
  129. /**
  130. * Retrieves the addon site component number for this action group.
  131. *
  132. * @return The component number for this action group, or -1 if none is
  133. * specified.
  134. */
  135. public int getComponent() {
  136. return component;
  137. }
  138. /**
  139. * Sets the addon site component number for this action group.
  140. *
  141. * @param component The component number for this action group
  142. */
  143. public void setComponent(final int component) {
  144. this.component = component;
  145. }
  146. /**
  147. * Determines the size of this group.
  148. *
  149. * @return The size of this group
  150. */
  151. public int size() {
  152. return actions.size();
  153. }
  154. /**
  155. * Removes the specified action from this group.
  156. *
  157. * @param action The action to be removed
  158. */
  159. public void remove(final Action action) {
  160. actions.remove(action);
  161. }
  162. /** {@inheritDoc} */
  163. @Override
  164. public Iterator<Action> iterator() {
  165. return actions.iterator();
  166. }
  167. /**
  168. * Retrieves the action at the specified index.
  169. *
  170. * @param index The index of the action to return
  171. * @return The action at the specified index
  172. */
  173. public Action get(final int index) {
  174. return actions.get(index);
  175. }
  176. /**
  177. * Determines if this group contains the specified action.
  178. *
  179. * @param action The action to search for
  180. * @return True if the action is contained in this list, false otherwise
  181. */
  182. public boolean contains(final Action action) {
  183. return actions.contains(action);
  184. }
  185. /**
  186. * Removes all actions from this group, and removes all meta-data.
  187. */
  188. public void clear() {
  189. for (Action action : new ArrayList<Action>(actions)) {
  190. remove(action);
  191. }
  192. settings.clear();
  193. description = null;
  194. author = null;
  195. component = -1;
  196. version = -1;
  197. }
  198. /**
  199. * Adds the specified action to this group.
  200. *
  201. * @param action The action to be added
  202. */
  203. public void add(final Action action) {
  204. actions.add(action);
  205. }
  206. /**
  207. * Retrieves a copy of the list of all actions in this group.
  208. *
  209. * @return A list of actions in this group
  210. */
  211. public List<Action> getActions() {
  212. return new ArrayList<Action>(actions);
  213. }
  214. /**
  215. * Determines if this action group is delible or not.
  216. *
  217. * @return True if the group may be deleted, false if it may not.
  218. */
  219. public boolean isDelible() {
  220. return true;
  221. }
  222. }