001: package xui.samples.carousel.components;
002:
003: import com.xoetrope.swing.XAudio;
004: import com.xoetrope.swing.XBreadcrumbBar;
005: import com.xoetrope.swing.XEasterEgg;
006: import com.xoetrope.swing.XHyperLabel;
007: import java.awt.Component;
008: import java.awt.event.ActionEvent;
009: import java.awt.event.ActionListener;
010: import java.util.Date;
011: import java.util.prefs.Preferences;
012: import javax.swing.SwingUtilities;
013: import net.xoetrope.optional.annotation.Find;
014: import net.xoetrope.optional.data.sql.DataConnection;
015: import net.xoetrope.swing.XDialog;
016: import net.xoetrope.xui.*;
017: import net.xoetrope.xui.build.BuildProperties;
018: import xui.samples.carousel.database.PreparationTask;
019: import xui.samples.carousel.database.Prepared;
020:
021: /**
022: * Welcome o the demo. This class controls access to other parts of the demo and
023: * does some work setting up resources shcuh as the database
024: * <p>Copyright: Xoetrope Ltd. (c) 2001-2006</p>
025: * <p>License: see license.txt</p>
026: * <p>$Revision: 1.6 $</p>
027: */
028: public class Welcome extends XPage implements Prepared {
029: private static boolean splashActivated = false;
030: private XEasterEgg admin;
031: private String defLangCode;
032: private XAudio audio;
033: private DataConnection connection;
034: private static XBreadcrumbBar breadcrumb;
035: @Find
036: private XHyperLabel licenceLabel;
037:
038: public Welcome() {
039: if (BuildProperties.DEBUG) {
040: // net.xoetrope.debug.DebugLogger.enableZone( "TRANSLATION", false );
041: // net.xoetrope.debug.DebugLogger.enableZone( "RESOURCES", false );
042: }
043:
044: // Setup the localization
045: Preferences rsPrefs = Preferences
046: .userNodeForPackage(getClass());
047: defLangCode = rsPrefs.get("defaultLanguage", "en");
048: project.setStartupParam("Language", defLangCode);
049: pageHelper.componentFactory.setResourceBundle(defLangCode);
050:
051: // Show the splash screen
052: // Fix: pre JDK6 the corners of dialog are not transparent
053: if (!splashActivated) {
054: showSplashScreen(true);
055: splashActivated = true;
056: }
057:
058: prepare();
059: }
060:
061: /**
062: * All the components have been instantiated
063: */
064: public void pageCreated() {
065: // Find some references
066: audio = (XAudio) findComponent("audio");
067: admin = (XEasterEgg) findComponent("admin");
068: admin.setPassword("password");
069: admin.setCallback(this , "showAdmin");
070:
071: breadcrumb = new XBreadcrumbBar();
072: breadcrumb.addLink("Welcome", "Welcome");
073:
074: licenceLabel.setStyle("base");
075: licenceLabel.setText("Xoetrope Licence");
076: licenceLabel.addActionListener(new ActionListener() {
077: public void actionPerformed(ActionEvent e) {
078: showLicense();
079: }
080: });
081: }
082:
083: // Splash screen methods -----------------------------------------------------
084: /**
085: * This method sets up a thread correponding to the splash screen. The splash
086: * screen waits for the background thread to complete which is fired off when
087: * the app starts so as to load the database. If the background thread has
088: * already completed the thread sleeps for a few seconds
089: * @param modal boolean should be true
090: * @return XDialog with the splashScreen
091: */
092: private XDialog showSplashScreen(boolean modal) {
093: final XDialog popupDialog = (XDialog) project.getPageManager()
094: .loadPage("Splash");
095: final XPage this Page = this ;
096: final boolean isModal = modal;
097: final String loading = this .translate("SplashTitle");
098:
099: SwingUtilities.invokeLater(new Runnable() {
100: public void run() {
101: popupDialog.setModal(isModal);
102: // Force the dialog to calculate its size
103: popupDialog.pack();
104: popupDialog.setSaveOnClose(false);
105: popupDialog.setVisible(true);
106:
107: new Thread() {
108: public void run() {
109: Thread.currentThread().setPriority(
110: Thread.NORM_PRIORITY - 1);
111: long startTime = new Date().getTime();
112: try {
113: while ((new Date().getTime() - startTime) < 3000L) {
114: popupDialog.repaint();
115: // Update a status text if there is one
116: // - use SwingUtilities.invokeLater to put the update
117: // onto the EDT
118: Thread.currentThread().sleep(100);
119: }
120: } catch (Exception ex) {
121: System.out.println(ex.getMessage());
122: }
123: if (popupDialog.isShowing())
124: pageMgr.showPage("Welcome", null);
125: popupDialog.closeDlg();
126: }
127: }.start();
128:
129: popupDialog.setCaption(loading);
130: popupDialog.showDialog(this Page);
131: }
132: });
133: return popupDialog;
134: }
135:
136: // End of splash screen methods ----------------------------------------------
137:
138: /**
139: * Show the xuiPowered dialog
140: */
141: public void xuiPowered() {
142: if (wasMouseClicked()) {
143: audio.start();
144: XDialog popupDialog = (XDialog) pageMgr.loadPage("About");
145: popupDialog.setCaption(translate("ABOUT_TITLE"));
146: popupDialog.pack();
147: popupDialog.showDialog(this );
148: }
149: }
150:
151: /**
152: * Show the line charts example
153: */
154: public void showAdmin() {
155: showMessage("EasterEgg invoked",
156: "This is only a demo application, there is not admin function.");
157: }
158:
159: /**
160: * Show the line charts example
161: */
162: public void showPage() {
163: audio.start();
164: String destination = ((String) getAttribute("dest",
165: ((Component) getCurrentEvent().getSource()).getName()));
166: breadcrumb.addLink(destination, destination);
167: pageMgr.showPage(destination);
168: }
169:
170: /**
171: * Show the license dialog
172: */
173: public void showLicense() {
174: XDialog popupDialog = (XDialog) pageMgr.loadPage("License",
175: false);
176: popupDialog.setCaption(translate("License"));
177: popupDialog.pack();
178: popupDialog.showDialog(this );
179: }
180:
181: // Database setup code -------------------------------------------------------
182: /**
183: * Begin preparation of the database
184: */
185: public void prepare() {
186: try {
187: PreparationTask preparator = (PreparationTask) Class
188: .forName(
189: "xui.samples.carousel.database.DatabasePreparationTask")
190: .newInstance();
191: preparator.prepare(this , project);
192: } catch (Exception ex) {
193: ex.printStackTrace();
194: }
195: }
196:
197: public static XBreadcrumbBar getBreadcrumb() {
198: return breadcrumb;
199: }
200:
201: /**
202: * A callback method, the database is now ready
203: */
204: public void prepared(Object conn) {
205: connection = (DataConnection) conn;
206: // For a more significant application it might be necessary to disable some
207: // controls while the app loads and now that the resource loading has
208: // completed you could enable the disabled components. A status text
209: // might also be updated to provide the user with progress
210: // The next few lines could be used to provide such a feature
211: // ((XImageButton)findComponent( "nextBtn" )).setEnabled( true );
212:
213: // statusLabel.setForeground( Color.blue );
214: // statusLabel.setText( translate( "WelcomeReady" ));
215: }
216: // End database setup --------------------------------------------------------
217: }
|