123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596 |
- /*
- * Copyright (c) 2006-2011 DMDirc Developers
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
- package com.dmdirc.actions;
-
- import com.dmdirc.Channel;
- import com.dmdirc.FrameContainer;
- import com.dmdirc.Query;
- import com.dmdirc.Server;
- import com.dmdirc.actions.interfaces.ActionComponent;
- import com.dmdirc.config.Identity;
- import com.dmdirc.logger.ErrorLevel;
- import com.dmdirc.logger.Logger;
- import com.dmdirc.parser.interfaces.ChannelClientInfo;
- import com.dmdirc.parser.interfaces.ClientInfo;
- import com.dmdirc.ui.interfaces.Window;
- import com.dmdirc.ui.messages.Styliser;
-
- import java.awt.Color;
- import java.awt.event.KeyEvent;
- import java.util.Calendar;
- import java.util.GregorianCalendar;
-
- import javax.swing.KeyStroke;
-
- /**
- * A CoreActionComponent represents a component of some object that the user can
- * use as the subject of a condition within an action.
- */
- public enum CoreActionComponent implements ActionComponent {
-
- /** Returns the name of the server. */
- SERVER_NAME {
- /** {@inheritDoc} */
- @Override
- public Object get(final Object argument) { return ((Server) argument).getAddress(); }
- /** {@inheritDoc} */
- @Override
- public Class<?> appliesTo() { return Server.class; }
- /** {@inheritDoc} */
- @Override
- public Class<?> getType() { return String.class; }
- /** {@inheritDoc} */
- @Override
- public String getName() { return "name"; }
- },
-
- /** Returns the network of the server. */
- SERVER_NETWORK {
- /** {@inheritDoc} */
- @Override
- @ComponentOptions(requireConnected = true)
- public Object get(final Object argument) { return ((Server) argument).getNetwork(); }
- /** {@inheritDoc} */
- @Override
- public Class<?> appliesTo() { return Server.class; }
- /** {@inheritDoc} */
- @Override
- public Class<?> getType() { return String.class; }
- /** {@inheritDoc} */
- @Override
- public String getName() { return "network"; }
- },
-
- /**
- * Returns the protocol of the server.
- *
- * @since 0.6.4
- */
- SERVER_PROTOCOL {
- /** {@inheritDoc} */
- @Override
- public Object get(final Object argument) { return ((Server) argument).getProtocol(); }
- /** {@inheritDoc} */
- @Override
- public Class<?> appliesTo() { return Server.class; }
- /** {@inheritDoc} */
- @Override
- public Class<?> getType() { return String.class; }
- /** {@inheritDoc} */
- @Override
- public String getName() { return "protocol"; }
- },
-
- /** Returns the away reason for the server. */
- SERVER_MYAWAYREASON {
- /** {@inheritDoc} */
- @Override
- public Object get(final Object argument) { return ((Server) argument).getAwayMessage(); }
- /** {@inheritDoc} */
- @Override
- public Class<?> appliesTo() { return Server.class; }
- /** {@inheritDoc} */
- @Override
- public Class<?> getType() { return String.class; }
- /** {@inheritDoc} */
- @Override
- public String getName() { return "away reason"; }
- },
-
- /** Returns the channel umodes for the server. */
- SERVER_CHANNELUMODES {
- /** {@inheritDoc} */
- @Override
- @ComponentOptions(requireConnected = true)
- public Object get(final Object argument) { return ((Server) argument).getParser().getChannelUserModes(); }
- /** {@inheritDoc} */
- @Override
- public Class<?> appliesTo() { return Server.class; }
- /** {@inheritDoc} */
- @Override
- public Class<?> getType() { return String.class; }
- /** {@inheritDoc} */
- @Override
- public String getName() { return "list of channel usermodes"; }
- },
-
- /** Returns the nickname for the server. */
- SERVER_MYNICKNAME {
- /** {@inheritDoc} */
- @Override
- @ComponentOptions(requireConnected = true)
- public Object get(final Object argument) {
- final Server server = (Server) argument;
-
- if (server == null || server.getParser() == null) {
- Logger.appError(ErrorLevel.LOW, "SERVER_MYNICKNAME.get() called with null element",
- new UnsupportedOperationException(
- server == null ? "Server was null"
- : server.getParser() == null ? "Parser was null"
- : "Unknown"
- ));
-
- return "null";
- } else {
- return server.getParser().getLocalClient().getNickname();
- }
- }
- /** {@inheritDoc} */
- @Override
- public Class<?> appliesTo() { return Server.class; }
- /** {@inheritDoc} */
- @Override
- public Class<?> getType() { return String.class; }
- /** {@inheritDoc} */
- @Override
- public String getName() { return "nickname"; }
- },
-
- /** Returns the name of the server. */
- SERVER_PROFILE {
- /** {@inheritDoc} */
- @Override
- public Object get(final Object argument) { return ((Server) argument).getProfile(); }
- /** {@inheritDoc} */
- @Override
- public Class<?> appliesTo() { return Server.class; }
- /** {@inheritDoc} */
- @Override
- public Class<?> getType() { return Identity.class; }
- /** {@inheritDoc} */
- @Override
- public String getName() { return "profile"; }
- },
-
- /** Returns the name of the channel. */
- CHANNEL_NAME {
- /** {@inheritDoc} */
- @Override
- public Object get(final Object argument) { return ((Channel) argument).getChannelInfo().getName(); }
- /** {@inheritDoc} */
- @Override
- public Class<?> appliesTo() { return Channel.class; }
- /** {@inheritDoc} */
- @Override
- public Class<?> getType() { return String.class; }
- /** {@inheritDoc} */
- @Override
- public String getName() { return "name"; }
- },
-
- /** Returns the notification colour of the channel. */
- CHANNEL_COLOUR {
- /** {@inheritDoc} */
- @Override
- public Object get(final Object argument) { return ((Channel) argument).getNotification(); }
- /** {@inheritDoc} */
- @Override
- public Class<?> appliesTo() { return Channel.class; }
- /** {@inheritDoc} */
- @Override
- public Class<?> getType() { return Color.class; }
- /** {@inheritDoc} */
- @Override
- public String getName() { return "notification colour"; }
- },
-
- /** Returns the name of a client. */
- CLIENT_NAME {
- /** {@inheritDoc} */
- @Override
- public Object get(final Object argument) { return ((ClientInfo) argument).getNickname(); }
- /** {@inheritDoc} */
- @Override
- public Class<?> appliesTo() { return ClientInfo.class; }
- /** {@inheritDoc} */
- @Override
- public Class<?> getType() { return String.class; }
- /** {@inheritDoc} */
- @Override
- public String getName() { return "nickname"; }
- },
-
- /** Returns the host of a client. */
- CLIENT_HOST {
- /** {@inheritDoc} */
- @Override
- public Object get(final Object argument) { return ((ClientInfo) argument).getHostname(); }
- /** {@inheritDoc} */
- @Override
- public Class<?> appliesTo() { return ClientInfo.class; }
- /** {@inheritDoc} */
- @Override
- public Class<?> getType() { return String.class; }
- /** {@inheritDoc} */
- @Override
- public String getName() { return "host"; }
- },
-
- /** Returns the name of a client. */
- USER_NAME {
- /** {@inheritDoc} */
- @Override
- public Object get(final Object argument) { return ((ChannelClientInfo) argument).getClient().getNickname(); }
- /** {@inheritDoc} */
- @Override
- public Class<?> appliesTo() { return ChannelClientInfo.class; }
- /** {@inheritDoc} */
- @Override
- public Class<?> getType() { return String.class; }
- /** {@inheritDoc} */
- @Override
- public String getName() { return "nickname"; }
- },
-
- /** Returns the modes of a client. */
- USER_MODES {
- /** {@inheritDoc} */
- @Override
- public Object get(final Object argument) { return ((ChannelClientInfo) argument).getAllModes(); }
- /** {@inheritDoc} */
- @Override
- public Class<?> appliesTo() { return ChannelClientInfo.class; }
- /** {@inheritDoc} */
- @Override
- public Class<?> getType() { return String.class; }
- /** {@inheritDoc} */
- @Override
- public String getName() { return "modes"; }
- },
-
- /** Returns the host of a client. */
- USER_HOST {
- /** {@inheritDoc} */
- @Override
- public Object get(final Object argument) { return ((ChannelClientInfo) argument).getClient().getHostname(); }
- /** {@inheritDoc} */
- @Override
- public Class<?> appliesTo() { return ChannelClientInfo.class; }
- /** {@inheritDoc} */
- @Override
- public Class<?> getType() { return String.class; }
- /** {@inheritDoc} */
- @Override
- public String getName() { return "host"; }
- },
-
- /** Returns the number of common channels the client is on. */
- USER_COMCHANS {
- /** {@inheritDoc} */
- @Override
- public Object get(final Object argument) { return Integer.valueOf(((ChannelClientInfo) argument).getClient().getChannelCount()); }
- /** {@inheritDoc} */
- @Override
- public Class<?> appliesTo() { return ChannelClientInfo.class; }
- /** {@inheritDoc} */
- @Override
- public Class<?> getType() { return Integer.class; }
- /** {@inheritDoc} */
- @Override
- public String getName() { return "number of common channels"; }
- },
-
- /** Returns the content of a string. */
- STRING_STRING {
- /** {@inheritDoc} */
- @Override
- public Object get(final Object argument) { return argument; }
- /** {@inheritDoc} */
- @Override
- public Class<?> appliesTo() { return String.class; }
- /** {@inheritDoc} */
- @Override
- public Class<?> getType() { return String.class; }
- /** {@inheritDoc} */
- @Override
- public String getName() { return "content"; }
- },
-
- /** Returns the content of a string, stripped of formatting. */
- STRING_STRIPPED {
- /** {@inheritDoc} */
- @Override
- public Object get(final Object argument) { return Styliser.stipControlCodes((String) argument); }
- /** {@inheritDoc} */
- @Override
- public Class<?> appliesTo() { return String.class; }
- /** {@inheritDoc} */
- @Override
- public Class<?> getType() { return String.class; }
- /** {@inheritDoc} */
- @Override
- public String getName() { return "content (without formatting)"; }
- },
-
- /** Returns the length of a string. */
- STRING_LENGTH {
- /** {@inheritDoc} */
- @Override
- public Object get(final Object argument) { return ((String) argument).length(); }
- /** {@inheritDoc} */
- @Override
- public Class<?> appliesTo() { return String.class; }
- /** {@inheritDoc} */
- @Override
- public Class<?> getType() { return Integer.class; }
- /** {@inheritDoc} */
- @Override
- public String getName() { return "length"; }
- },
-
- /** Returns the size of a string array. */
- STRINGARRAY_LENGTH {
- /** {@inheritDoc} */
- @Override
- public Object get(final Object argument) { return Integer.valueOf(((String[]) argument).length); }
- /** {@inheritDoc} */
- @Override
- public Class<?> appliesTo() { return String[].class; }
- /** {@inheritDoc} */
- @Override
- public Class<?> getType() { return Integer.class; }
- /** {@inheritDoc} */
- @Override
- public String getName() { return "size"; }
- },
-
- /** Returns the readable representation of a date. */
- CALENDAR_FULLSTRING {
- /** {@inheritDoc} */
- @Override
- public Object get(final Object argument) { return ((GregorianCalendar) argument).getTime().toString(); }
- /** {@inheritDoc} */
- @Override
- public Class<?> appliesTo() { return Calendar.class; }
- /** {@inheritDoc} */
- @Override
- public Class<?> getType() { return String.class; }
- /** {@inheritDoc} */
- @Override
- public String getName() { return "full date"; }
- },
-
- /** Returns the name of the key that was pressed. */
- KEYEVENT_KEYNAME {
- /** {@inheritDoc} */
- @Override
- public Object get(final Object argument) { return KeyEvent.getKeyText(((KeyStroke) argument).getKeyCode()); }
- /** {@inheritDoc} */
- @Override
- public Class<?> appliesTo() { return KeyStroke.class; }
- /** {@inheritDoc} */
- @Override
- public Class<?> getType() { return String.class; }
- /** {@inheritDoc} */
- @Override
- public String getName() { return "key name"; }
- },
-
- /** Returns the state of the control key for a key press event. */
- KEYEVENT_CTRLSTATE {
- /** {@inheritDoc} */
- @Override
- public Object get(final Object argument) {
- return Boolean.valueOf((((KeyStroke) argument).getModifiers() & KeyEvent.CTRL_DOWN_MASK) != 0);
- }
- /** {@inheritDoc} */
- @Override
- public Class<?> appliesTo() { return KeyStroke.class; }
- /** {@inheritDoc} */
- @Override
- public Class<?> getType() { return Boolean.class; }
- /** {@inheritDoc} */
- @Override
- public String getName() { return "control key state"; }
- },
-
- /** Returns the state of the shift key for a key press event. */
- KEYEVENT_SHIFTSTATE {
- /** {@inheritDoc} */
- @Override
- public Object get(final Object argument) {
- return Boolean.valueOf((((KeyStroke) argument).getModifiers() & KeyEvent.SHIFT_DOWN_MASK) != 0);
- }
- /** {@inheritDoc} */
- @Override
- public Class<?> appliesTo() { return KeyStroke.class; }
- /** {@inheritDoc} */
- @Override
- public Class<?> getType() { return Boolean.class; }
- /** {@inheritDoc} */
- @Override
- public String getName() { return "shift key state"; }
- },
-
- /** Returns the state of the shift key for a key press event. */
- KEYEVENT_ALTSTATE {
- /** {@inheritDoc} */
- @Override
- public Object get(final Object argument) {
- return Boolean.valueOf((((KeyStroke) argument).getModifiers() & KeyEvent.ALT_DOWN_MASK) != 0);
- }
- /** {@inheritDoc} */
- @Override
- public Class<?> appliesTo() { return KeyStroke.class; }
- /** {@inheritDoc} */
- @Override
- public Class<?> getType() { return Boolean.class; }
- /** {@inheritDoc} */
- @Override
- public String getName() { return "alt key state"; }
- },
-
- /** Returns the host of the query. */
- QUERY_HOST {
- /** {@inheritDoc} */
- @Override
- public Object get(final Object argument) { return ((Query) argument).getHost(); }
- /** {@inheritDoc} */
- @Override
- public Class<?> appliesTo() { return Query.class; }
- /** {@inheritDoc} */
- @Override
- public Class<?> getType() { return String.class; }
- /** {@inheritDoc} */
- @Override
- public String getName() { return "host"; }
- },
-
- /** Returns the host of the query. */
- QUERY_NICK {
- /** {@inheritDoc} */
- @Override
- public Object get(final Object argument) { return ((Query) argument).getName(); }
- /** {@inheritDoc} */
- @Override
- public Class<?> appliesTo() { return Query.class; }
- /** {@inheritDoc} */
- @Override
- public Class<?> getType() { return String.class; }
- /** {@inheritDoc} */
- @Override
- public String getName() { return "nick"; }
- },
-
- /** Returns the notification colour of the query. */
- QUERY_COLOUR {
- /** {@inheritDoc} */
- @Override
- public Object get(final Object argument) { return ((Query) argument).getNotification(); }
- /** {@inheritDoc} */
- @Override
- public Class<?> appliesTo() { return Query.class; }
- /** {@inheritDoc} */
- @Override
- public Class<?> getType() { return Color.class; }
- /** {@inheritDoc} */
- @Override
- public String getName() { return "notification colour"; }
- },
-
- /** The name of a window. */
- WINDOW_NAME {
- /** {@inheritDoc} */
- @Override
- public Object get(final Object argument) { return ((FrameContainer) argument).getName(); }
- /** {@inheritDoc} */
- @Override
- public Class<?> appliesTo() { return FrameContainer.class; }
- /** {@inheritDoc} */
- @Override
- public Class<?> getType() { return String.class; }
- /** {@inheritDoc} */
- @Override
- public String getName() { return "name"; }
- },
-
- /** Returns the notification colour of the window. */
- WINDOW_COLOUR {
- /** {@inheritDoc} */
- @Override
- public Object get(final Object argument) { return ((FrameContainer) argument).getNotification(); }
- /** {@inheritDoc} */
- @Override
- public Class<?> appliesTo() { return FrameContainer.class; }
- /** {@inheritDoc} */
- @Override
- public Class<?> getType() { return Color.class; }
- /** {@inheritDoc} */
- @Override
- public String getName() { return "notification colour"; }
- },
-
- /**
- * Returns the server of the window.
- *
- * @since 0.6.4
- */
- WINDOW_SERVER {
- /** {@inheritDoc} */
- @Override
- public Object get(final Object argument) { return ((Window) argument)
- .getContainer().getServer(); }
- /** {@inheritDoc} */
- @Override
- public Class<?> appliesTo() { return Window.class; }
- /** {@inheritDoc} */
- @Override
- public Class<?> getType() { return Server.class; }
- /** {@inheritDoc} */
- @Override
- public String getName() { return "server"; }
- },
-
- /** Returns the name of an identity. */
- IDENTITY_NAME {
- /** {@inheritDoc} */
- @Override
- public Object get(final Object argument) { return ((Identity) argument).getName(); }
- /** {@inheritDoc} */
- @Override
- public Class<?> appliesTo() { return Identity.class; }
- /** {@inheritDoc} */
- @Override
- public Class<?> getType() { return String.class; }
- /** {@inheritDoc} */
- @Override
- public String getName() { return "name"; }
- },
-
- /** Returns the value of an integer. */
- INTEGER_VALUE {
- /** {@inheritDoc} */
- @Override
- public Object get(final Object argument) { return (Integer) argument; }
- /** {@inheritDoc} */
- @Override
- public Class<?> appliesTo() { return Integer.class; }
- /** {@inheritDoc} */
- @Override
- public Class<?> getType() { return Integer.class; }
- /** {@inheritDoc} */
- @Override
- public String getName() { return "value"; }
- };
-
- }
|