Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

ActionGroup.java 7.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. /*
  2. * Copyright (c) 2006-2011 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.Precondition;
  24. import com.dmdirc.config.prefs.PreferencesSetting;
  25. import com.dmdirc.logger.Logger;
  26. import com.dmdirc.updater.Version;
  27. import java.util.ArrayList;
  28. import java.util.HashMap;
  29. import java.util.Iterator;
  30. import java.util.List;
  31. import java.util.Map;
  32. /**
  33. * Represents a group of actions, along with their meta-data.
  34. */
  35. public class ActionGroup implements Iterable<Action> {
  36. /**
  37. * A version number for this class. It should be changed whenever the class
  38. * structure is changed (or anything else that would prevent serialized
  39. * objects being unserialized with the new class).
  40. */
  41. private static final long serialVersionUID = 1;
  42. /** The actions in this group. */
  43. private final List<Action> actions = new ArrayList<Action>();
  44. /** The name of this action group. */
  45. private final String name;
  46. /** The description of this action group. */
  47. private String description;
  48. /** The author of this action group. */
  49. private String author;
  50. /** The component number of this action group (for updating). */
  51. private int component = -1;
  52. /** The version of this action group. */
  53. private Version version;
  54. /** A list of settings used by this action group. */
  55. private final Map<String, PreferencesSetting> settings
  56. = new HashMap<String, PreferencesSetting>();
  57. /**
  58. * Creates a new instance of ActionGroup.
  59. *
  60. * @param name The name of this action group
  61. */
  62. public ActionGroup(final String name) {
  63. super();
  64. this.name = name;
  65. }
  66. /**
  67. * Retrieves the author of this ActionGroup.
  68. *
  69. * @return This action group's author, or null if the author isn't specified
  70. */
  71. public String getAuthor() {
  72. return author;
  73. }
  74. /**
  75. * Sets the author of this ActionGroup.
  76. *
  77. * @param author The new author for this action group
  78. */
  79. public void setAuthor(final String author) {
  80. this.author = author;
  81. }
  82. /**
  83. * Retrieves the description of this action group.
  84. *
  85. * @return This action group's description, or null if none is specified
  86. */
  87. public String getDescription() {
  88. return description;
  89. }
  90. /**
  91. * Sets the description for this action group.
  92. *
  93. * @param description The new description for this action group
  94. */
  95. public void setDescription(final String description) {
  96. this.description = description;
  97. }
  98. /**
  99. * Retrieves the name of this action group.
  100. *
  101. * @return This action group's name
  102. */
  103. public String getName() {
  104. return name;
  105. }
  106. /**
  107. * Retrieves a map settings used by this action group.
  108. *
  109. * @return A map of setting names to values
  110. */
  111. public Map<String, PreferencesSetting> getSettings() {
  112. return settings;
  113. }
  114. /**
  115. * Retrieves the version number of this action group.
  116. *
  117. * @return This action group's version number, or null if none is specified.
  118. * @since 0.6.4
  119. */
  120. public Version getVersion() {
  121. return version;
  122. }
  123. /**
  124. * Sets the version of this action group.
  125. *
  126. * @param version This action group's new version.
  127. * @since 0.6.4
  128. */
  129. public void setVersion(final Version version) {
  130. this.version = version;
  131. }
  132. /**
  133. * Retrieves the addon site component number for this action group.
  134. *
  135. * @return The component number for this action group, or -1 if none is
  136. * specified.
  137. */
  138. public int getComponent() {
  139. return component;
  140. }
  141. /**
  142. * Sets the addon site component number for this action group.
  143. *
  144. * @param component The component number for this action group
  145. */
  146. public void setComponent(final int component) {
  147. this.component = component;
  148. }
  149. /**
  150. * Determines the size of this group.
  151. *
  152. * @return The size of this group
  153. */
  154. public int size() {
  155. return actions.size();
  156. }
  157. /**
  158. * Removes the specified action from this group.
  159. *
  160. * @param action The action to be removed
  161. */
  162. public void remove(final Action action) {
  163. actions.remove(action);
  164. }
  165. /** {@inheritDoc} */
  166. @Override
  167. public Iterator<Action> iterator() {
  168. return actions.iterator();
  169. }
  170. /**
  171. * Retrieves the action at the specified index.
  172. *
  173. * @param index The index of the action to return
  174. * @return The action at the specified index
  175. */
  176. public Action get(final int index) {
  177. return actions.get(index);
  178. }
  179. /**
  180. * Determines if this group contains the specified action.
  181. *
  182. * @param action The action to search for
  183. * @return True if the action is contained in this list, false otherwise
  184. */
  185. public boolean contains(final Action action) {
  186. return actions.contains(action);
  187. }
  188. /**
  189. * Removes all actions from this group, and removes all meta-data.
  190. */
  191. public void clear() {
  192. for (Action action : new ArrayList<Action>(actions)) {
  193. remove(action);
  194. }
  195. settings.clear();
  196. description = null;
  197. author = null;
  198. version = null;
  199. component = -1;
  200. }
  201. /**
  202. * Adds the specified action to this group.
  203. *
  204. * @param action The action to be added
  205. */
  206. public void add(final Action action) {
  207. actions.add(action);
  208. }
  209. /**
  210. * Retrieves a copy of the list of all actions in this group.
  211. *
  212. * @return A list of actions in this group
  213. */
  214. public List<Action> getActions() {
  215. return new ArrayList<Action>(actions);
  216. }
  217. /**
  218. * Deletes an action from this group.
  219. *
  220. * @param action The action to be deleted
  221. * @since 0.6.3
  222. */
  223. @Precondition({
  224. "The specified action is non-null",
  225. "The specified action exists in this group"
  226. })
  227. @SuppressWarnings("deprecation")
  228. public void deleteAction(final Action action) {
  229. Logger.assertTrue(action != null);
  230. Logger.assertTrue(actions.contains(action));
  231. ActionManager.deleteAction(action);
  232. }
  233. /**
  234. * Determines if this action group is delible or not.
  235. *
  236. * @return True if the group may be deleted, false if it may not.
  237. */
  238. public boolean isDelible() {
  239. return true;
  240. }
  241. }