001: package net.xoetrope.swt.demo;
002:
003: import net.xoetrope.swt.XButton;
004: import net.xoetrope.swt.XEdit;
005: import net.xoetrope.swt.XLabel;
006: import net.xoetrope.swt.XPanel;
007: import net.xoetrope.swt.XPassword;
008: import net.xoetrope.swt.XSwtPage;
009: import net.xoetrope.swt.XTextArea;
010: import net.xoetrope.swt.XToolBar;
011: import net.xoetrope.xui.data.XModel;
012:
013: public class CountryStory extends XSwtPage {
014:
015: // Constants
016:
017: public static final int width = 1024 - 14;
018: public static final int height = 768 - 39 - 19;
019: public static final int border = 40;
020:
021: // Attributes
022:
023: private int xOrigin = 0;
024: private int yOrigin = 0;
025: private int widthContent = width - 2 * border;
026: private int heightContent = height - 2 * border;
027:
028: private int toolHeight = 0;
029:
030: private String country;
031: private String story;
032:
033: private String username = null;
034: private String password = null;
035:
036: private XToolBar shellTB;
037: private XLabel borderTop, borderLeft, borderRight, borderBottom;
038: private XPanel storyP, buttonP, editP;
039: private XTextArea storyTA;
040: private XEdit usernameE;
041: private XPassword passwordP;
042:
043: // Constructor
044:
045: public CountryStory() {
046: country = project.getModel().getValueAsString("country");
047: XModel item = (XModel) project.getModel().get(
048: country + "/Informations/story");
049: story = item.getAttribValueAsString(item.getAttribute("story"));
050: }
051:
052: // Automatic Methods
053:
054: public void pageCreated() {
055: shellTB = (XToolBar) findComponent("shellTB");
056: borderTop = (XLabel) findComponent("borderTop");
057: borderLeft = (XLabel) findComponent("borderLeft");
058: borderRight = (XLabel) findComponent("borderRight");
059: borderBottom = (XLabel) findComponent("borderBottom");
060: initBorders();
061: storyTA = (XTextArea) findComponent("storyTA");
062: storyP = (XPanel) findComponent("storyP");
063: usernameE = (XEdit) findComponent("usernameE");
064: passwordP = (XPassword) findComponent("passwordP");
065: buttonP = (XPanel) findComponent("buttonP");
066: editP = (XPanel) findComponent("editP");
067: initContent();
068: }
069:
070: public void pageActivated() {
071: storyP.setVisible(true);
072: //storyB.setVisible( true );
073: }
074:
075: // Private Methods
076:
077: private void initBorders() {
078: toolHeight = shellTB.getBounds().height;
079: yOrigin = toolHeight;
080: heightContent -= toolHeight;
081: System.out.println("HeightContent : " + heightContent
082: + ", widthContent : " + widthContent);
083: borderTop.setBounds(xOrigin, yOrigin, width, border);
084: borderLeft.setBounds(xOrigin, yOrigin + border, border,
085: heightContent);
086: borderRight.setBounds(xOrigin + widthContent + border, yOrigin
087: + border, border, heightContent);
088: borderBottom.setBounds(xOrigin, yOrigin + heightContent
089: + border, width, border);
090: }
091:
092: private void initContent() {
093: storyTA.setBounds(xOrigin + border, yOrigin + border,
094: widthContent, 2 * heightContent / 3);
095: storyTA.setText(story);
096: storyP.setBounds(xOrigin + border, yOrigin + border + 2
097: * heightContent / 3, widthContent,
098: 2 * heightContent / 9);
099: buttonP.setBounds(xOrigin + border, yOrigin + border + 8
100: * heightContent / 9, widthContent, heightContent / 9);
101: editP.setBounds(xOrigin + border, yOrigin + border + 8
102: * heightContent / 9, widthContent, heightContent / 9);
103: setEditMode(false);
104: }
105:
106: private void setEditMode(boolean edit) {
107: storyTA.setEditable(edit);
108: storyP.setVisible(!edit);
109: buttonP.setVisible(!edit);
110: editP.setVisible(edit);
111: setVisibleLogin(username == null || username.equals(""));
112: }
113:
114: private void setVisibleLogin(boolean visible) {
115: storyP.setVisible(visible);
116: if (visible)
117: storyTA.setBounds(xOrigin + border, yOrigin + border,
118: widthContent, 2 * heightContent / 3);
119: else
120: storyTA.setBounds(xOrigin + border, yOrigin + border,
121: widthContent, 8 * heightContent / 9);
122: }
123:
124: // Events Methods
125:
126: public void goToPreviousPage() {
127: reInit();
128: cancelEdit();
129: pageMgr.showPrevious();
130: }
131:
132: public void goToHomePage() {
133: reInit();
134: cancelEdit();
135: project.getPageManager().showPage("Home");
136: }
137:
138: public void editStory() {
139: if (username == null || username.equals("")) {
140: username = usernameE.getText();
141: password = passwordP.getText();
142: }
143: if (Home.isValidEditor(username, password))
144: setEditMode(true);
145: else {
146: reInit();
147: showMessage("Identification failed",
148: "Your username or password are incorrect !");
149: }
150: }
151:
152: public void saveStory() {
153: story = storyTA.getText();
154: setEditMode(false);
155: }
156:
157: public void cancelEdit() {
158: storyTA.setText(story);
159: setEditMode(false);
160: }
161:
162: private void reInit() {
163: usernameE.setText("");
164: passwordP.setText("");
165: username = null;
166: password = null;
167: }
168:
169: // public void goToNextPage() {
170: // MouseEvent me = ( MouseEvent ) getCurrentEvent();
171: // System.out.println( "( " + me.x + ", " + me.y + " )" );
172: // int hotspotIdx = flag.checkHotspot( me );
173: // if( hotspotIdx > -1 ) {
174: // String s = flag.getName( hotspotIdx );
175: // XSwtPage page = ( XSwtPage )( ( XSwtTarget ) pageMgr.getTarget( "content" ) ).getChildComponent( 0 );
176: // String nextPage = ( String ) page.getAttribute( s.toLowerCase(), null );
177: // if( nextPage != null )
178: // project.getPageManager().showPage( nextPage );
179: // }
180: // }
181: }
|