001:package com.xoetrope.xbb;
002:
003:import java.awt.Color;
004:import java.awt.event.ActionEvent;
005:import java.awt.event.ActionListener;
006:import java.util.Enumeration;
007:import java.util.Hashtable;
008:import java.util.Properties;
009:import java.util.prefs.Preferences;
010:import javax.swing.JComponent;
011:import javax.swing.SwingUtilities;
012:import javax.swing.Timer;
013:import javax.swing.border.LineBorder;
014:
015:import net.xoetrope.optional.annotation.Find;
016:
017:import net.xoetrope.swing.XButton;
018:import net.xoetrope.swing.XComboBox;
019:import net.xoetrope.swing.XImageButton;
020:import net.xoetrope.swing.XLabel;
021:import net.xoetrope.swing.XPanel;
022:import net.xoetrope.swing.XTabPanel;
023:import net.xoetrope.swing.app.XDockingApp;
024:import net.xoetrope.swing.docking.XDockable;
025:import net.xoetrope.swing.util.XGraphicsUtils;
026:
027:import net.xoetrope.xui.XPage;
028:import net.xoetrope.xui.XPageManager;
029:
030:import net.xoetrope.xui.data.XModel;
031:
032:import com.xoetrope.data.DatabasePreparationTask;
033:import com.xoetrope.data.PreparationListener;
034:import com.xoetrope.xbb.modules.ModuleManager;
035:
036:import com.xoetrope.swing.tabs.WrappingTabComponent;
037:import com.xoetrope.swing.helper.FadeInHelper;
038:
039:
040:/**
041: * A welcome page for XBB. The page performs some inital setup for languages
042: * and database loading
043: * <p> Copyright (c) Xoetrope Ltd., 2001-2007, This software is licensed under
044: * the GNU Public License (GPL), please see license.txt for more details. If
045: * you make commercial use of this software you must purchase a commercial
046: * license from Xoetrope.</p>
047: * @author luano
048: */
049:public class Welcome extends XPage implements PreparationListener
050:{
051: public static final boolean DEBUG = true;
052:
053: // Version numbering
054: public static final String BUILD_NUMBER = "18";
055: public static final String VERSION_NUMBER = "0";
056: public static final String DATABASE_VERSION_NUMBER = "112";
057:
058: // Activation control
059: private static boolean splashActivated = false;
060: private static boolean prepared = false;
061:
062: static Object connector;
063: private int tickCount;
064: private Timer timer;
065:
066: // Langage switch members
067: private Hashtable languages;
068: private String selectedLanguage;
069: private String defLangCode;
070: private static boolean inChangeLang = false;
071:
072: private XDockingApp dockingApp;
073:
074: private FadeInHelper animationHelper;
075:
076: @Find private XComboBox languageCombo;
077: @Find private XLabel loadingStatus, versionLabel, dbVersionLabel;
078: @Find private XButton loginBtn;
079: @Find private XTabPanel infoPanels;
080: @Find private XPanel guidesPanel, infoPanel;
081:
082: /** Creates a new instance of Welcome */
083: public Welcome()
084: {
085: Preferences dptPrefs = Preferences.userNodeForPackage( getClass());
086: defLangCode = dptPrefs.get( "defaultLanguage", "en" );
087: project.setStartupParam( "Language", defLangCode );
088: pageHelper.componentFactory.setResourceBundle( defLangCode );
089:
090: dockingApp = (XDockingApp)project.getAppFrame();
091: dockingApp.showExclusive( this , true );
092:
093: animationHelper = new FadeInHelper();
094: animationHelper.setAnaimationValueInc( 0.025F );
095: }
096:
097: public void pageCreated()
098: {
099: tickCount = 0;
100: infoPanel.setBorder( new LineBorder( Color.white, 10 ));
101: guidesPanel.setBorder( new LineBorder( Color.white, 10 ));
102:// infoPanels.setTabComponentAt( 0, new WrappingTabComponent( project, infoPanels, true ));
103:// infoPanels.setTabComponentAt( 1, new WrappingTabComponent( project, infoPanels, true ));
104:
105: SwingUtilities.invokeLater( new Runnable()
106: {
107: public void run()
108: {
109: XModel root = project.getModel();
110: if ( DEBUG ) {
111: root.set( "rs3/versionLabel", VERSION_NUMBER + "." + BUILD_NUMBER );
112: versionLabel.setText( VERSION_NUMBER + "." + BUILD_NUMBER );
113: }
114: else {
115: root.set( "rs3/versionLabel", VERSION_NUMBER );
116: ((XLabel)findComponent( "versionLabel" )).setText( VERSION_NUMBER );
117: }
118:
119: root.set( "rs3/dbVersionLabel", DATABASE_VERSION_NUMBER );
120: dbVersionLabel.setText( DATABASE_VERSION_NUMBER );
121:
122: root.set( "rs3/buildVersionLabel", BUILD_NUMBER );
123:
124: // Setup the language list
125: fillLanguageList();
126: }
127: });
128:
129: // Create a timer to show the status message and then hide it
130: timer = new Timer( 1000, new ActionListener()
131: {
132: public void actionPerformed( ActionEvent evt )
133: {
134: if ( connector != null ) {
135: // Wait three seconds
136: if ( tickCount++ > 2 ) {
137: timer.stop();
138: loadingStatus.setText( "" );
139: }
140: }
141: else
142: loadingStatus.setText( loadingStatus.getText() + "." );
143: }
144: });
145: timer.start();
146:
147: DatabasePreparationTask dbt = new DatabasePreparationTask();
148: dbt.prepare( project, this , "DATABASE_VERSION" );
149:
150: project.getPageManager().mapPageName( "START_PAGE", "Welcome" );
151: }
152:
153: public void pageAdded()
154: {
155: dockingApp = (XDockingApp)project.getAppFrame();
156: dockingApp.showExclusive( this , true );
157: }
158:
159: public void pageActivated()
160: {
161: changeLanguage();
162: }
163:
164: /**
165: * Read the language file and fill the language list
166: */
167: private void fillLanguageList()
168: {
169: try {
170: inChangeLang = true;
171: languages = new Hashtable();
172:
173: Properties props = new Properties();
174: String selectedLanguageName = null;
175: props.load( project.getInputStream( "LanguageList.properties" ));
176: Enumeration propNames = props.propertyNames();
177: while ( propNames.hasMoreElements() ) {
178: String languageName = (String)propNames.nextElement();
179: String languageCode = (String)props.get( languageName );
180: if ( languageCode.equals( defLangCode ))
181: selectedLanguageName = languageName;
182: languages.put( languageName, languageCode );
183: languageCombo.addItem( languageName );
184: }
185: if ( selectedLanguageName != null )
186: languageCombo.select( (Object)selectedLanguageName );
187: inChangeLang = false;
188: }
189: catch ( Exception ex ) {
190: }
191: }
192:
193: /**
194: * Respond to a change in the language list by resetting the language
195: */
196: public void changeLanguage()
197: {
198: if ( !inChangeLang ) {
199: inChangeLang = true;
200: String language = (String)languageCombo.getSelectedItem();
201: if ( language != null ) {
202: defLangCode = (String)languages.get( language );
203: Preferences dptPrefs = Preferences.userNodeForPackage( getClass());
204: dptPrefs.put( "defaultLanguage", defLangCode );
205: project.setStartupParam( "Language", defLangCode );
206:
207: pageHelper.componentFactory.setResourceBundle( defLangCode );
208: XPageManager pm = project.getPageManager();
209: pm.reset();
210: pm.showPage( "Welcome" );
211: updateBoundComponentValues();
212: }
213: inChangeLang = false;
214: }
215: }
216:
217: /**
218: * Login to the applications
219: */
220: public void login()
221: {
222: ModuleManager.getInstance();
223: dockingApp.showExclusive( this , false );
224: XDockable dockable = dockingApp.findDockable( this );
225: dockable.header.getParent().setVisible( false );
226: showPage( "AccountSummary", "content" );
227: }
228:
229: /**
230: * The info panel tab selection has changed
231: */
232: public void tabChanged()
233: {
234: int idx = infoPanels.getSelectedIndex();
235: animationHelper.animate( (JComponent)findComponent( "infoPanel" + ( idx + 1 ) + "top" ));
236: }
237:
238: /**
239: * Is the listener ready to receive the preparred object?
240: * @return true if the listener is ready for input
241: */
242: public boolean isReady()
243: {
244: return ( getStatus() >= XPage.ACTIVATED );
245: }
246:
247: /**
248: * The preparation, the database load, is complete and the login should be enabled
249: * @param o the prepared object
250: */
251: public void preparationCompleted( Object obj )
252: {
253: loginBtn.setEnabled( true );
254: XGraphicsUtils.vibrate( loginBtn );
255:
256: connector = obj;
257: loadingStatus.setText( project.getTranslator().translate( "Ready" ));
258: }
259:
260: /**
261: * An error was detected while performng the preparation task
262: * @param msg an error message
263: */
264: public void preparationFailed( String msg )
265: {
266: loginBtn.setEnabled( false );
267: timer.stop();
268: loadingStatus.setText( project.getTranslator().translate( msg + ", please contact the administrator" ));
269: }
270:}
|