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.

CoreActionComponent.java 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * Copyright (c) 2006-2007 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 java.awt.Color;
  24. import com.dmdirc.Channel;
  25. import com.dmdirc.Server;
  26. import com.dmdirc.parser.ChannelClientInfo;
  27. /**
  28. * A CoreActionComponent represents a component of some object that the user can
  29. * use as the subject of a condition within an action.
  30. * @author chris
  31. */
  32. public enum CoreActionComponent implements ActionComponent {
  33. SERVER_NAME {
  34. public Object get(final Object argument) { return ((Server) argument).getName(); }
  35. public Class appliesTo() { return Server.class; }
  36. public Class getType() { return String.class; }
  37. public String getName() { return "name"; }
  38. },
  39. SERVER_NETWORK {
  40. public Object get(final Object argument) { return ((Server) argument).getNetwork(); }
  41. public Class appliesTo() { return Server.class; }
  42. public Class getType() { return String.class; }
  43. public String getName() { return "network"; }
  44. },
  45. CHANNEL_NAME {
  46. public Object get(final Object argument) { return ((Channel) argument).getChannelInfo().getName(); }
  47. public Class appliesTo() { return Channel.class; }
  48. public Class getType() { return String.class; }
  49. public String getName() { return "name"; }
  50. },
  51. CHANNEL_COLOUR {
  52. public Object get(final Object argument) { return ((Channel) argument).getNotification(); }
  53. public Class appliesTo() { return Channel.class; }
  54. public Class getType() { return Color.class; }
  55. public String getName() { return "notification colour"; }
  56. },
  57. USER_NAME {
  58. public Object get(final Object argument) { return ((ChannelClientInfo) argument).getNickname(); }
  59. public Class appliesTo() { return ChannelClientInfo.class; }
  60. public Class getType() { return String.class; }
  61. public String getName() { return "nickname"; }
  62. },
  63. USER_MODES {
  64. public Object get(final Object argument) { return ((ChannelClientInfo) argument).getChanModeStr(false); }
  65. public Class appliesTo() { return ChannelClientInfo.class; }
  66. public Class getType() { return String.class; }
  67. public String getName() { return "modes"; }
  68. },
  69. USER_HOST {
  70. public Object get(final Object argument) { return ((ChannelClientInfo) argument).getClient().getHost(); }
  71. public Class appliesTo() { return ChannelClientInfo.class; }
  72. public Class getType() { return String.class; }
  73. public String getName() { return "host"; }
  74. },
  75. STRING_STRING {
  76. public Object get(final Object argument) { return argument; }
  77. public Class appliesTo() { return String.class; }
  78. public Class getType() { return String.class; }
  79. public String getName() { return "content"; }
  80. },
  81. STRING_LENGTH {
  82. public Object get(final Object argument) { return ((String) argument).length(); }
  83. public Class appliesTo() { return String.class; }
  84. public Class getType() { return Integer.class; }
  85. public String getName() { return "length"; }
  86. },
  87. STRINGARRAY_LENGTH {
  88. public Object get(final Object argument) { return Integer.valueOf(((String[]) argument).length); }
  89. public Class appliesTo() { return String[].class; }
  90. public Class getType() { return Integer.class; }
  91. public String getName() { return "size"; }
  92. };
  93. /** {@inheritDoc} */
  94. public abstract Object get(Object argument);
  95. /** {@inheritDoc} */
  96. public abstract Class appliesTo();
  97. /** {@inheritDoc} */
  98. public abstract Class getType();
  99. /** {@inheritDoc} */
  100. public abstract String getName();
  101. }