1 19 package org.netbeans.core.output2; 20 21 import java.awt.*; 22 import java.util.Arrays ; 23 24 52 final class IOEvent extends AWTEvent implements ActiveEvent { 53 static final int IO_EVENT_MASK = 0xF0000; 54 59 static final int CMD_CREATE = 0; 60 64 static final int CMD_OUTPUT_VISIBLE=1; 65 68 static final int CMD_INPUT_VISIBLE=2; 69 73 static final int CMD_ERR_VISIBLE=3; 74 77 static final int CMD_ERR_SEPARATED=4; 78 79 82 static final int CMD_FOCUS_TAKEN=5; 83 86 static final int CMD_SELECT=6; 87 90 static final int CMD_CLOSE=7; 91 95 static final int CMD_STREAM_CLOSED=8; 96 100 static final int CMD_RESET=9; 101 104 static final int CMD_SET_TOOLBAR_ACTIONS = 10; 105 108 static final int CMD_DETACH = 11; 109 110 113 static final int CMD_ICON = 12; 114 115 116 119 private static final int[] IDS = new int[] { 120 CMD_CREATE, 121 CMD_OUTPUT_VISIBLE, 122 CMD_INPUT_VISIBLE, 123 CMD_ERR_VISIBLE, 124 CMD_ERR_SEPARATED, 125 CMD_FOCUS_TAKEN, 126 CMD_SELECT, 127 CMD_CLOSE, 128 CMD_STREAM_CLOSED, 129 CMD_RESET, 130 CMD_SET_TOOLBAR_ACTIONS, 131 CMD_DETACH, 132 CMD_ICON 133 }; 134 135 138 private static final String [] CMDS = new String [] { 139 "CREATE", "OUTPUT_VISIBLE", "INPUT_VISIBLE", "ERR_VISIBLE", "ERR_SEPARATED", "FOCUS_TAKEN", "SELECT", "CLOSE", "STREAM_CLOSED", "RESET", "SET_TOOLBAR_ACTIONS", "DETACH" }; 152 153 156 private boolean value = false; 157 160 private Object data = null; 161 162 166 static int pendingCount = 0; 167 176 IOEvent(NbIO source, int command, boolean value) { 177 super(source == null ? new Object () : source, command + IO_EVENT_MASK); 179 assert Arrays.binarySearch (IDS, command) >= 0 : "Unknown command: " + command; consumed = false; 181 this.value = value; 182 pendingCount++; 183 } 184 185 192 IOEvent(NbIO source, int command, Object data) { 193 this (source, command, false); 194 this.data = data; 195 } 196 197 203 public int getCommand() { 204 return getID() - IO_EVENT_MASK; 205 } 206 207 212 public NbIO getIO() { 213 return getSource() instanceof NbIO ? (NbIO) getSource() : null; 214 } 215 216 222 public boolean getValue() { 223 return value; 224 } 225 226 232 public Object getData() { 233 return data; 234 } 235 236 241 public boolean isConsumed() { 242 return consumed; 243 } 244 245 249 public void consume() { 250 consumed = true; 251 } 252 253 public String toString() { 254 return "IOEvent@" + System.identityHashCode(this) + "-" + 255 cmdToString(getCommand()) + " on " + getIO() + 256 " value= " + getValue() + " data=" + getData(); } 258 259 public void dispatch() { 260 264 if (OutputWindow.DEFAULT != null) { 267 OutputWindow.DEFAULT.eventDispatched(this); 269 } 270 pendingCount--; 271 } 272 273 public static String cmdToString (int cmd) { 274 return CMDS[Arrays.binarySearch(IDS, cmd)]; 275 } 276 } 277 | Popular Tags |