001: package net.xoetrope.swt.demo;
002:
003: import net.xoetrope.swt.XHotspotImage;
004: import net.xoetrope.swt.XLabel;
005: import net.xoetrope.swt.XSwtPage;
006: import net.xoetrope.swt.XSwtTarget;
007: import net.xoetrope.swt.XToolBar;
008: import org.eclipse.swt.events.MouseEvent;
009:
010: public class CountryFlag extends XSwtPage {
011:
012: // Constants
013:
014: public static final int width = 1024 - 14;
015: public static final int height = 768 - 39 - 19;
016: public static final int border = 40;
017:
018: // Attributes
019:
020: private int xOrigin = 0;
021: private int yOrigin = 0;
022: private int widthContent = width - 2 * border;
023: private int heightContent = height - 2 * border;
024:
025: private int toolHeight = 0;
026:
027: private String country;
028:
029: private XToolBar shellTB;
030: private XLabel borderTop, borderLeft, borderRight, borderBottom;
031: private XHotspotImage flag;
032:
033: // Constructor
034:
035: public CountryFlag() {
036: country = project.getModel().getValueAsString("country");
037: }
038:
039: // Automatic Methods
040:
041: public void pageCreated() {
042: shellTB = (XToolBar) findComponent("shellTB");
043: borderTop = (XLabel) findComponent("borderTop");
044: borderLeft = (XLabel) findComponent("borderLeft");
045: borderRight = (XLabel) findComponent("borderRight");
046: borderBottom = (XLabel) findComponent("borderBottom");
047: flag = (XHotspotImage) findComponent("flag");
048: initBorders();
049: initContent();
050: }
051:
052: public void pageActivated() {
053: }
054:
055: public String getFlag() {
056: return "countries/" + country.toLowerCase() + "/flag.jpg";
057: }
058:
059: // Private Methods
060:
061: private void initBorders() {
062: toolHeight = shellTB.getBounds().height;
063: yOrigin = toolHeight;
064: heightContent -= toolHeight;
065: System.out.println("HeightContent : " + heightContent
066: + ", widthContent : " + widthContent);
067: borderTop.setBounds(xOrigin, yOrigin, width, border);
068: borderLeft.setBounds(xOrigin, yOrigin + border, border,
069: heightContent);
070: borderRight.setBounds(xOrigin + widthContent + border, yOrigin
071: + border, border, heightContent);
072: borderBottom.setBounds(xOrigin, yOrigin + heightContent
073: + border, width, border);
074: }
075:
076: private void initContent() {
077: flag.setBounds(xOrigin + border, yOrigin + border,
078: widthContent, heightContent);
079: setupHotspots();
080: }
081:
082: private void setupHotspots() {
083: try {
084: flag.read(project.getBufferedReader("countries/"
085: + country.toLowerCase() + "/flaghotspots.xml",
086: "UTF8"));
087: } catch (Exception ex) {
088: ex.printStackTrace();
089: }
090: }
091:
092: // Events Methods
093:
094: public void goToPreviousPage() {
095: pageMgr.showPrevious();
096: }
097:
098: public void goToHomePage() {
099: project.getPageManager().showPage("Home");
100: }
101:
102: public void goToNextPage() {
103: MouseEvent me = (MouseEvent) getCurrentEvent();
104: System.out.println("( " + me.x + ", " + me.y + " )");
105: int hotspotIdx = flag.checkHotspot(me);
106: if (hotspotIdx > -1) {
107: String s = flag.getName(hotspotIdx);
108: XSwtPage page = (XSwtPage) ((XSwtTarget) pageMgr
109: .getTarget("content")).getChildComponent(0);
110: String nextPage = (String) page.getAttribute(s
111: .toLowerCase(), null);
112: if (nextPage != null)
113: project.getPageManager().showPage(nextPage);
114: }
115: }
116: }
|