001: package net.xoetrope.swt.demo;
002:
003: import java.util.ArrayList;
004: import net.xoetrope.swt.XImage;
005: import net.xoetrope.swt.XSwtPage;
006: import net.xoetrope.swt.XLabel;
007: import net.xoetrope.swt.XImageMap;
008: import net.xoetrope.swt.XPanel;
009: import net.xoetrope.swt.XSwtTarget;
010: import org.eclipse.swt.events.MouseEvent;
011:
012: public class Home extends XSwtPage {
013:
014: // Constants
015:
016: public static final int width = 1024 - 14;
017: public static final int height = 768 - 39 - 19;
018: public static final int border = 0;
019: public static final int widthContent = width - 2 * border;
020: public static final int heightContent = height - 2 * border;
021:
022: // Editors
023:
024: public static ArrayList editors;
025:
026: // Attributes
027:
028: private int xOrigin = 0;
029: private int yOrigin = 0;
030:
031: private XLabel title, split;
032: private XPanel left, right;
033: private XImage celtic, benfica, ajax, om, napoli, liverpool, barca,
034: dortmund;
035: private XImageMap europe;
036:
037: // Constructor
038:
039: public Home() {
040: editors = new ArrayList();
041: String tab[] = { "admin", "football" };
042: editors.add(tab);
043: }
044:
045: // Automatic Methods
046:
047: public void pageCreated() {
048: title = (XLabel) findComponent("title");
049: split = (XLabel) findComponent("split");
050: left = (XPanel) findComponent("left");
051: celtic = (XImage) findComponent("celtic");
052: benfica = (XImage) findComponent("benfica");
053: ajax = (XImage) findComponent("ajax");
054: om = (XImage) findComponent("om");
055: europe = (XImageMap) findComponent("europe");
056: right = (XPanel) findComponent("right");
057: napoli = (XImage) findComponent("napoli");
058: liverpool = (XImage) findComponent("liverpool");
059: barca = (XImage) findComponent("barca");
060: dortmund = (XImage) findComponent("dortmund");
061: initContent();
062: }
063:
064: public void pageActivated() {
065: }
066:
067: // Private Methods
068:
069: private void initBorders() {
070: }
071:
072: private void initContent() {
073:
074: title.setBounds(xOrigin, yOrigin, widthContent,
075: heightContent / 15);
076: split.setBounds(xOrigin, yOrigin + heightContent / 15,
077: widthContent, heightContent / 20);
078: int y = yOrigin + 7 * heightContent / 60;
079: int h = 53 * heightContent / 60;
080: left.setBounds(xOrigin, y, widthContent / 6, h);
081: celtic.setBounds(0, 0, widthContent / 6, h / 4);
082: benfica.setBounds(0, h / 4, widthContent / 6, h / 4);
083: ajax.setBounds(0, h / 2, widthContent / 6, h / 4);
084: om.setBounds(0, 3 * h / 4, widthContent / 6, h / 4);
085: europe.setBounds(xOrigin + widthContent / 6, y,
086: 2 * widthContent / 3, h);
087: setupHotspots();
088: right.setBounds(xOrigin + 5 * widthContent / 6, y,
089: widthContent / 6, h);
090: napoli.setBounds(0, 0, widthContent / 6, h / 4);
091: liverpool.setBounds(0, h / 4, widthContent / 6, h / 4);
092: barca.setBounds(0, h / 2, widthContent / 6, h / 4);
093: dortmund.setBounds(0, 3 * h / 4, widthContent / 6, h / 4);
094:
095: //(( XLabel ) findComponent( "foo" )).setBounds( 0, 0, widthContent / 6, h / 4 );
096: }
097:
098: private void setupHotspots() {
099: try {
100: europe.read(project.getBufferedReader("europehotspots.xml",
101: "UTF8"));
102: } catch (Exception ex) {
103: ex.printStackTrace();
104: }
105: }
106:
107: // Events Methods
108:
109: public void exit() {
110: System.exit(0);
111: }
112:
113: public void showBelgium() {
114: show("Belgium");
115: }
116:
117: public void showEngland() {
118: show("England");
119: }
120:
121: public void showFrance() {
122: show("France");
123: }
124:
125: public void showGermany() {
126: show("Germany");
127: }
128:
129: public void showIreland() {
130: show("Ireland");
131: }
132:
133: public void showItaly() {
134: show("Italy");
135: }
136:
137: public void showNetherland() {
138: show("Netherland");
139: }
140:
141: public void showPortugal() {
142: show("Portugal");
143: }
144:
145: public void showScotland() {
146: show("Scotland");
147: }
148:
149: public void showSpain() {
150: show("Spain");
151: }
152:
153: public void showSwitzerland() {
154: show("Switzerland");
155: }
156:
157: public void showApplication() {
158: showMessage("About XUI International Soccer Manager...",
159: "This application showcases the use of SWT and XUI.");
160: }
161:
162: public void showAuthor() {
163: showMessage(
164: "About The Author...",
165: "This application has been implemented by Romain LOUIS, a student at EPU,\nSI Dept (Sophia-Antipolis, France), during a 3 month internship at Xoetrope.");
166: }
167:
168: public void goToChampionship() {
169: MouseEvent me = (MouseEvent) getCurrentEvent();
170: int hotspotIdx = europe.checkHotspot(me);
171: if (hotspotIdx > -1) {
172: String s = europe.getName(hotspotIdx);
173: show(s);
174: }
175: }
176:
177: private void show(String country) {
178: if (country.equals("England"))
179: showPage(country);
180: else
181: showMessage(
182: "Bad selection",
183: "The "
184: + country
185: + " football championship has not been created yet !");
186: }
187:
188: private void showPage(String country) {
189: XSwtPage page = (XSwtPage) ((XSwtTarget) pageMgr
190: .getTarget("content")).getChildComponent(0);
191: String nextPage = (String) page.getAttribute("next", null);
192: if (nextPage != null) {
193: project.getModel().set("country", country);
194: project.getPageManager().showPage(nextPage);
195: }
196: }
197:
198: // Static Methods
199:
200: public static boolean isValidEditor(String username, String password) {
201: for (int i = 0; i < editors.size(); i++) {
202: String tab[] = (String[]) editors.get(i);
203: if (tab[0].equals(username) && tab[1].equals(password))
204: return true;
205: }
206: return false;
207: }
208: }
|