01: package net.xoetrope.samples.controls;
02:
03: import java.awt.Frame;
04: import java.awt.event.MouseEvent;
05:
06: import net.xoetrope.awt.XButton;
07: import net.xoetrope.awt.XHotspotImage;
08: import net.xoetrope.awt.XLabel;
09: import net.xoetrope.xui.XPage;
10: import net.xoetrope.xui.XResourceManager;
11:
12: /**
13: * <p>Title: Xui</p>
14: * <p>Description: </p>
15: * <p>Copyright: Copyright (c) Xoetrope Ltd., 1998-2003</p>
16: * <p>Company: Xoetrope Ltd.</p>
17: * @author Xoetrope Ltd.
18: * @version 1.0
19: */
20:
21: public class HotspotSample extends XPage {
22: XButton closeButton;
23: XHotspotImage hsImage;
24: Frame frame;
25: XLabel statusLabel;
26:
27: public HotspotSample() {
28: frame = new Frame("Hotspot Sample");
29: frame.setLayout(null);
30: frame.setSize(640, 580);
31: String desc = "This example shows how the XHotspotImage control works. First create the XHotspotImage using";
32: desc += " the componentFactory and then read the hotspots from the ClassHotspots.xml file. This file contains the";
33: desc += " coordinates of the polygons where the hotspots will be located and an optional name which is associated";
34: desc += " with the hotspot";
35:
36: componentFactory.setParentComponent(frame);
37: componentFactory.addComponent(XPage.LABEL, 10, 50, 530, 80,
38: desc);
39: hsImage = (XHotspotImage) componentFactory.addComponent(
40: XPage.HOTSPOTIMAGE, 50, 130, 345, 331,
41: "classhierarchy.gif");
42: setupHotspots();
43: addMouseHandler(hsImage, "handleHotspotsClicks");
44:
45: statusLabel = (XLabel) componentFactory.addComponent(
46: XPage.LABEL, 400, 130, 100, 50,
47: "Click a hotspot to test");
48: closeButton = (XButton) componentFactory.addComponent(
49: XPage.BUTTON, 10, 550, 130, 25, "Close");
50: this .addMouseHandler(closeButton, "Close");
51: frame.setVisible(true);
52: frame.show();
53: }
54:
55: public void setupHotspots() {
56: try {
57: hsImage.read(XResourceManager.getBufferedReader(
58: "classhotspots.xml", null));
59: } catch (Exception ex) {
60: ex.printStackTrace();
61: }
62: }
63:
64: public void handleHotspotsClicks() {
65: if (wasMouseClicked()) {
66: String name = hsImage.getName(hsImage
67: .checkHotspot(((MouseEvent) getCurrentEvent())
68: .getPoint()));
69: statusLabel.setText(name + " was clicked");
70: }
71: }
72:
73: public static void main(String args[]) {
74: HotspotSample compSample = new HotspotSample();
75: }
76:
77: public void Close() {
78: if (wasMouseClicked()) {
79: frame.setVisible(false);
80: }
81: }
82: }
|