/* */ package NET.worlds.console; /* */ /* */ import NET.worlds.scape.FrameEvent; /* */ import java.awt.Container; /* */ import java.awt.Dimension; /* */ import java.awt.Event; /* */ import java.awt.Graphics; /* */ import java.awt.PopupMenu; /* */ import java.awt.Rectangle; /* */ import java.awt.event.MouseEvent; /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ public class ImageButtons /* */ extends ImageCanvas /* */ implements FramePart, DialogDisabled /* */ { /* */ private static final long serialVersionUID = -1495360044843592740L; /* */ protected static final int BLANK = 0; /* */ protected static final int NORMAL = 1; /* */ protected static final int CURSED = 2; /* */ protected static final int DOWN = 3; /* */ private static final int TITLE = 0; /* */ private static final int BUTTON = 1; /* */ private int width; /* */ private int height; /* */ private Dimension ghostImageDimension; /* */ protected Rectangle[] buttons; /* */ private int[] types; /* 160 */ private boolean background = false; /* */ /* 162 */ private int cursedButton = -1; /* 163 */ private int clickedButton = -1; /* */ private boolean clickedButtonDown; /* */ private ImageButtonsCallback handler; /* */ private ImageButtonsCallback downUpHandler; /* */ private PopupMenu menu; /* */ private boolean isDialogDisabled; /* */ /* */ private void initEvents() /* */ { /* 172 */ enableEvents(16L); /* 173 */ enableEvents(32L); /* */ } /* */ /* */ protected ImageButtons() { /* 177 */ this.buttons = new Rectangle[0]; /* 178 */ initEvents(); /* */ } /* */ /* */ public ImageButtons(String imageName, int buttonWidth, int buttonHeight, ImageButtonsCallback handler) /* */ { /* 183 */ this(imageName, buttonWidth, intToInts(buttonHeight), handler); /* */ } /* */ /* */ /* */ /* */ /* */ /* */ /* */ public ImageButtons(String imageName, Rectangle[] buttonRects, ImageButtonsCallback handler) /* */ { /* 193 */ super(imageName); /* 194 */ this.handler = handler; /* 195 */ this.background = true; /* 196 */ setHotspots(buttonRects); /* 197 */ initEvents(); /* */ } /* */ /* */ /* */ /* */ /* */ /* */ public ImageButtons(String imageName, int buttonWidth, int[] buttonHeights, ImageButtonsCallback handler) /* */ { /* 206 */ super(imageName); /* 207 */ this.handler = handler; /* 208 */ this.buttons = new Rectangle[buttonHeights.length]; /* 209 */ this.types = new int[buttonHeights.length]; /* 210 */ int y = 0; /* 211 */ for (int i = 0; i < buttonHeights.length; i++) { /* 212 */ int h = buttonHeights[i]; /* */ int rh; /* 214 */ if (h > 0) { /* 215 */ int rh = h; /* 216 */ this.types[i] = 1; /* */ } else { /* 218 */ rh = -h; /* 219 */ this.types[i] = 0; /* */ } /* 221 */ this.buttons[i] = new Rectangle(0, y, buttonWidth, rh); /* 222 */ y += rh; /* */ } /* 224 */ this.ghostImageDimension = new Dimension(buttonWidth * 4, buttonHeights[0]); /* 225 */ initEvents(); /* */ } /* */ /* */ public void setHandler(ImageButtonsCallback handler) { /* 229 */ this.handler = handler; /* */ } /* */ /* */ public void setDownUpHandler(ImageButtonsCallback handler) { /* 233 */ this.downUpHandler = handler; /* */ } /* */ /* */ protected void setBackground(boolean background) { /* 237 */ this.background = background; /* */ } /* */ /* */ protected void setWidth(int width) { /* 241 */ this.width = width; /* */ } /* */ /* */ protected void setHeight(int height) { /* 245 */ this.height = height; /* */ } /* */ /* */ protected synchronized void setHotspots(Rectangle[] buttonRects) { /* 249 */ this.buttons = new Rectangle[buttonRects.length]; /* 250 */ this.types = new int[buttonRects.length]; /* 251 */ for (int i = 0; i < buttonRects.length; i++) { /* 252 */ this.types[i] = 1; /* 253 */ this.buttons[i] = new Rectangle(buttonRects[i]); /* */ } /* 255 */ this.cursedButton = -1; /* 256 */ this.clickedButton = -1; /* 257 */ this.clickedButtonDown = false; /* */ } /* */ /* */ public synchronized void paint(Graphics g) /* */ { /* 262 */ g.clipRect(0, 0, this.width, this.height); /* 263 */ if ((this.background) && (this.image_ != null)) { /* 264 */ g.drawImage(this.image_, -1 * this.width, 0, null); /* */ } /* 266 */ for (int i = 0; i < this.buttons.length; i++) { /* 267 */ int state = 1; /* 268 */ if (i == this.cursedButton) /* 269 */ state = 2; /* 270 */ if (i == this.clickedButton) /* 271 */ state = this.clickedButtonDown ? 3 : 1; /* 272 */ drawButton(g, i, state); /* */ } /* */ } /* */ /* */ public Dimension getPreferredSize() /* */ { /* 278 */ Dimension d = super.getPreferredSize(); /* 279 */ if ((d.width == 0) && (d.height == 0) && (this.ghostImageDimension != null)) /* 280 */ d = this.ghostImageDimension; /* 281 */ d = new Dimension(this.width = d.width / 4, this.height = d.height); /* 282 */ return d; /* */ } /* */ /* */ public Dimension getMinimumSize() /* */ { /* 287 */ return getPreferredSize(); /* */ } /* */ /* */ public void processMouseMotionEvent(MouseEvent e) /* */ { /* 292 */ if (!this.isDialogDisabled) { /* 293 */ switch (e.getID()) { /* */ case 503: /* */ case 506: /* 296 */ buttonAction(e.getX(), e.getY(), e.getID()); /* */ } /* */ /* */ } /* */ /* 301 */ super.processMouseEvent(e); /* */ } /* */ /* */ public void processMouseEvent(MouseEvent e) /* */ { /* 306 */ if (!this.isDialogDisabled) { /* 307 */ switch (e.getID()) { /* */ case 501: /* */ case 502: /* */ case 504: /* */ case 505: /* 312 */ buttonAction(e.getX(), e.getY(), e.getID()); /* */ } /* */ /* */ } /* */ /* 317 */ super.processMouseEvent(e); /* */ } /* */ /* */ @Deprecated /* */ public boolean mouseMove(Event e, int x, int y) /* */ { /* 323 */ return buttonAction(x, y, 503); /* */ } /* */ /* */ /* */ @Deprecated /* */ public boolean mouseDown(Event e, int x, int y) /* */ { /* 330 */ if ((e.modifiers & 0xC) != 0) /* 331 */ return false; /* 332 */ return buttonAction(x, y, 501); /* */ } /* */ /* */ /* */ @Deprecated /* */ public boolean mouseUp(Event e, int x, int y) /* */ { /* 339 */ if ((e.modifiers & 0xC) != 0) /* 340 */ return false; /* 341 */ return buttonAction(x, y, 502); /* */ } /* */ /* */ @Deprecated /* */ public boolean mouseDrag(Event e, int x, int y) /* */ { /* 347 */ return buttonAction(x, y, 506); /* */ } /* */ /* */ @Deprecated /* */ public boolean mouseEnter(Event e, int x, int y) /* */ { /* 353 */ return buttonAction(x, y, 504); /* */ } /* */ /* */ @Deprecated /* */ public boolean mouseExit(Event e, int x, int y) /* */ { /* 359 */ return buttonAction(x, y, 505); /* */ } /* */ /* */ @Deprecated /* */ public boolean handleEvent(Event event) /* */ { /* 365 */ if (this.isDialogDisabled) /* 366 */ return false; /* 367 */ return super.handleEvent(event); /* */ } /* */ /* */ protected Graphics drawButton(Graphics g, int button, int state) { /* 371 */ if (button != -1) { /* 372 */ Rectangle r = this.buttons[button]; /* */ /* */ /* */ /* 376 */ if ((this.image_ != null) && ((g != null) || ((g = getGraphics()) != null))) { /* 377 */ Graphics g1 = g.create(r.x, r.y, r.width, r.height); /* 378 */ g1.drawImage(this.image_, -state * this.width - r.x, -r.y, null); /* 379 */ g1.dispose(); /* */ } /* */ } /* 382 */ return g; /* */ } /* */ /* */ private synchronized boolean buttonAction(int x, int y, int action) { /* 386 */ return buttonAction(locateButton(x, y), action); /* */ } /* */ /* */ private int locateButton(int x, int y) { /* 390 */ for (int i = 0; i < this.buttons.length; i++) /* 391 */ if ((this.types[i] == 1) && (this.buttons[i].contains(x, y))) /* 392 */ return i; /* 393 */ return -1; /* */ } /* */ /* */ public void drawFirstButton(int state) { /* 397 */ if (this.buttons.length > 0) { /* 398 */ Graphics g = drawButton(null, 0, state); /* 399 */ if (g != null) /* 400 */ g.dispose(); /* */ } /* */ } /* */ /* */ public void drawNormal() { /* 405 */ drawFirstButton(1); /* */ } /* */ /* */ public void drawCursed() { /* 409 */ drawFirstButton(2); /* */ } /* */ /* */ public void drawDown() { /* 413 */ drawFirstButton(3); /* */ } /* */ /* */ boolean buttonAction(int button, int action) { /* 417 */ Graphics g = null; /* 418 */ if ((action == 503) || /* 419 */ (action == 504)) { /* 420 */ if (button != this.cursedButton) { /* 421 */ g = drawButton(g, this.cursedButton, 1); /* 422 */ g = drawButton(g, this.cursedButton = button, 2); /* */ } /* */ /* */ /* 426 */ if ((this.clickedButton != -1) && (this.clickedButton != button) && /* 427 */ (this.downUpHandler == null)) { /* 428 */ g = drawButton(g, this.clickedButton, 1); /* 429 */ this.clickedButtonDown = false; /* */ } /* 431 */ } else if (action == 505) { /* 432 */ if (this.cursedButton != -1) { /* 433 */ g = drawButton(g, this.cursedButton, 1); /* 434 */ this.cursedButton = -1; /* */ } /* */ /* */ /* 438 */ if ((this.downUpHandler == null) && /* 439 */ (this.clickedButton != -1) && (this.clickedButtonDown)) { /* 440 */ g = drawButton(g, this.clickedButton, 1); /* 441 */ this.clickedButtonDown = false; /* */ } /* */ } /* 444 */ else if (action == 501) /* */ { /* 446 */ if (this.clickedButton != -1) { /* 447 */ g = drawButton(g, this.clickedButton, 1); /* 448 */ if (this.downUpHandler != null) /* 449 */ this.downUpHandler.imageButtonsCallback(this, -1); /* 450 */ this.clickedButtonDown = false; /* */ } /* 452 */ if (this.cursedButton != -1) { /* 453 */ g = drawButton(g, this.cursedButton, 1); /* 454 */ this.cursedButton = -1; /* */ } /* 456 */ if ((this.clickedButton = button) != -1) { /* 457 */ g = drawButton(g, this.clickedButton, 3); /* 458 */ this.clickedButtonDown = true; /* */ /* */ /* 461 */ if (this.downUpHandler != null) /* 462 */ this.downUpHandler.imageButtonsCallback(this, button); /* */ } /* 464 */ } else if (action == 506) /* */ { /* 466 */ if ((this.downUpHandler == null) && (this.clickedButton != -1)) { /* 467 */ if (this.clickedButtonDown) { /* 468 */ if (button != this.clickedButton) { /* 469 */ g = drawButton(g, this.clickedButton, 1); /* 470 */ this.clickedButtonDown = false; /* */ } /* 472 */ } else if (button == this.clickedButton) { /* 473 */ g = drawButton(g, this.clickedButton, 3); /* 474 */ this.clickedButtonDown = true; /* */ } /* */ } /* 477 */ } else if (action == 502) { /* 478 */ this.cursedButton = button; /* 479 */ if (this.cursedButton != -1) { /* 480 */ g = drawButton(g, this.cursedButton, 2); /* */ } /* */ /* 483 */ if (this.clickedButtonDown) /* */ { /* 485 */ if (this.cursedButton != this.clickedButton) /* 486 */ g = drawButton(g, this.clickedButton, 1); /* 487 */ Object ret = this.handler.imageButtonsCallback(this, this.clickedButton); /* 488 */ if (((ret instanceof PopupMenu)) && (this.clickedButton != -1)) { /* 489 */ if (this.menu != null) /* 490 */ remove(this.menu); /* 491 */ add(this.menu = (PopupMenu)ret); /* 492 */ this.menu.show(this, this.buttons[this.clickedButton].x, /* 493 */ this.buttons[this.clickedButton].y + /* 494 */ this.buttons[this.clickedButton].height); /* */ } /* 496 */ if (this.downUpHandler != null) /* */ { /* */ /* 499 */ if (this.downUpHandler.imageButtonsCallback(this, -1) != null) /* 500 */ this.cursedButton = -1; /* */ } /* 502 */ this.clickedButtonDown = false; /* 503 */ this.clickedButton = -1; /* */ } /* */ } /* 506 */ if (g != null) { /* 507 */ g.dispose(); /* */ } /* 509 */ return true; /* */ } /* */ /* */ public static int[] intToInts(int value) { /* 513 */ int[] ret = new int[1]; /* 514 */ ret[0] = value; /* 515 */ return ret; /* */ } /* */ /* */ /* */ /* */ public void activate(Console c, Container f, Console prev) {} /* */ /* */ /* */ /* */ public void deactivate() {} /* */ /* */ /* */ /* */ @Deprecated /* */ public boolean action(Event event, Object what) /* */ { /* 531 */ return false; /* */ } /* */ /* */ public boolean handle(FrameEvent f) /* */ { /* 536 */ return false; /* */ } /* */ /* */ /* */ /* */ public void dialogDisable(boolean disable) /* */ { /* 543 */ if ((this.isDialogDisabled = disable)) { /* 544 */ this.cursedButton = -1; /* 545 */ this.clickedButton = -1; /* 546 */ this.clickedButtonDown = false; /* 547 */ repaint(); /* */ } /* */ } /* */ } /* Location: C:\Program Files (x86)\Worlds Inc\WorldsPlayer - Win7\lib\worlds.jar!\NET\worlds\console\ImageButtons.class * Java compiler version: 6 (50.0) * JD-Core Version: 0.7.1 */