package com.xoetrope.carousel.langed;
import java.net.URL;
import java.util.Date;
import java.util.prefs.Preferences;
//import com.websina.license.LicenseManager;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Frame;
import java.awt.Rectangle;
import java.awt.Toolkit;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JWindow;
import javax.swing.SwingUtilities;
import javax.swing.LookAndFeel;
import javax.swing.UIManager;
/**
* <p>Title: LanguageEditor</p>
* <p>Description: Language Resource Translation Utility</p>
* <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
* the GNU Public License (GPL), please see license.txt for more details. If
* you make commercial use of this software you must purchase a commercial
* license from Xoetrope.</p>
* <p> $Revision: 1.6 $</p>
* @author Luan O'Carroll
*/
public class LanguageEditorApplication
{
private JWindow splashScreen = null;
private boolean packFrame = false;
private LangFrame frame = null;
private static boolean validLicense = false;
private static final long twentyEightDays = 2419200000l; //1000*3600*24*28;
public static Font defaultFont;
static boolean isPlugin = false;
//Construct the application
public LanguageEditorApplication( Frame appFrame, boolean isApplication, boolean showSplash )
{
// Create and throw the splash screen up. Since this will
// physically throw bits on the screen, we need to do this
// on the GUI thread using invokeLater.
if ( showSplash )
createSplashScreen( appFrame );
init( isApplication );
validLicense = checkLicense();
if ( !validLicense ) {
JOptionPane.showMessageDialog( frame, "A valid license was not found.\r\n XTranslator will run in evaluation mode and you will not be able to save languages of more than 25 strings.\r\nYour evaluation is valid for a total of 28 days. A license can be purchased for http://www.xoetrope.net", "Licensing Error", JOptionPane.WARNING_MESSAGE );
try {
Preferences prefs = Preferences.userNodeForPackage( LangEdDesktop.class );
Date today = new Date();
Date defaultDate = new Date( today.getTime() + twentyEightDays );
String lastUsed = prefs.get( "expiry", Long.toHexString( defaultDate.getTime()));
Date expiryDate = new Date( Long.parseLong( lastUsed, 16 ));
if ( expiryDate.compareTo( today ) < 0 ) {
JOptionPane.showMessageDialog( frame, "No license was found and the evaluation period has expired.\r\nA license can be purchased for http://www.xoetrope.net", "Licensing Expired", JOptionPane.ERROR_MESSAGE );
System.exit( 0 );
}
prefs.put( "expiry", Long.toHexString( expiryDate.getTime()));
}
catch ( Exception ex ) {
System.exit( 0 );
}
}
}
private void init( boolean isApplication )
{
try {
if ( isApplication )
frame = new LangFrame();
}
catch (Exception ex) {
ex.printStackTrace();
}
//Validate frames that have preset sizes
//Pack frames that have useful preferred size info, e.g. from their layout
if ( frame != null ) {
if ( packFrame )
frame.pack();
else
frame.validate();
//Center the window
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = frame.getSize();
if ( frameSize.height > screenSize.height )
frameSize.height = screenSize.height;
if ( frameSize.width > screenSize.width )
frameSize.width = screenSize.width;
frame.setLocation( ( screenSize.width - frameSize.width ) / 2, ( screenSize.height - frameSize.height ) / 2 );
frame.setVisible( true );
}
}
//Main method
public static void main( String[] args )
{
LangFrame.isStandalone = true;
try {
UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName());
//UIManager.setLookAndFeel( new javax.swing.plaf.metal.MetalLookAndFeel());
// com.incors.plaf.kunststoff.KunststoffLookAndFeel lf = new com.incors.plaf.kunststoff.KunststoffLookAndFeel();
// lf.setCurrentTheme( new XoetropeTheme());
// lf.setCurrentGradientTheme( new XoetropeGradientTheme());
// UIManager.setLookAndFeel( lf );
}
catch(Exception e) {
e.printStackTrace();
}
LanguageEditorApplication le = new LanguageEditorApplication( null, true, true );
}
/**
* Show the spash screen while the rest of the demo loads
*/
public void createSplashScreen( Frame appFrame )
{
URL image = null;
JLabel splashLabel = null;
try {
LanguageEditorApplication.class.getResource( "/splash.jpg" );
splashLabel = new JLabel( new ImageIcon( image ));
}
catch( Exception e )
{
splashLabel = new JLabel();
}
Frame frame = appFrame;
if ( frame == null )
frame = new Frame();
splashScreen = new JWindow( frame );
splashScreen.getContentPane().add(splashLabel);
splashScreen.pack();
Rectangle screenRect = frame.getGraphicsConfiguration().getBounds();
splashScreen.setLocation( screenRect.x + screenRect.width/2 - splashScreen.getSize().width/2,
screenRect.y + screenRect.height/2 - splashScreen.getSize().height/2);
// do the following on the gui thread
SwingUtilities.invokeLater( new Runnable() {
public void run()
{
showSplashScreen();
}
});
new SplashSleeperThread( this ).start();
}
private void showSplashScreen()
{
if ( splashScreen != null ) {
splashScreen.setVisible( true );
splashScreen.repaint();
}
}
/**
* pop down the spash screen
*/
public void hideSplash()
{
if ( splashScreen != null ) {
splashScreen.setVisible( false );
splashScreen = null;
}
}
private boolean checkLicense()
{
// try {
// LicenseManager manager = null;
// try
// {
// java.net.URL url = LanguageEditor.class.getResource("/license.lic" );
// InputStream is = ClassLoader.getSystemResourceAsStream( "license.lic" );
// if ( is == null ) {
// System.out.println("License not loaded from stream");
// if ( url != null )
// return true;
// return false;
// }
//
// // first get a instance of the LicenseManager.
// manager= LicenseManager.getInstance();
// }
// catch(Exception exception)
// {
// System.out.println( "No license file found" );
// }
// // you then validate the license by calling isValid().
// boolean valid = manager.isValid();
//
// String localhost = manager.getFeature( "IP Address" );
// String application = manager.getFeature( "Product" );
// String userName = manager.getFeature( "User Name" );
// String licensee = manager.getFeature( "Licensee" );
// if ( valid ) {
// if ( application.indexOf( "XTranslator" ) != 0 )
// return false;
// if ( licensee.compareTo( "Danfoss A/S" ) == 0 ) {
// System.out.println( "The application is running under a license granted exclusively to Danfoss A/S, Nordborg, Denmark" );
// return true;
// }
//
// if (( InetAddress.getLocalHost().toString().indexOf( localhost ) < 0 ) && ( System.getProperty( "user.name" ).indexOf( userName ) < 0 )) {
// System.out.println( "The host name does not match the license file: " +userName + ":" +System.getProperty( "user.name" ) + ":" + InetAddress.getLocalHost().toString());
// return false;
// }
//
// System.out.println("License is valid: "+valid);
// // also you can get the days left by calling daysLeft().
// System.out.println("Days left: "+manager.daysLeft());
// return true;
// }
// else {
// System.out.println("license is invalid and so the program exits....");
// //exit the program
// }
// }
// catch (Exception ex) {
// ex.printStackTrace();
// }
// return false;
return true;
}
static boolean isEvaluation()
{
return !validLicense;
}
public void setDefaultFont( Font font )
{
defaultFont = font;
}
void setIsPlugin( boolean _isPlugin )
{
isPlugin = _isPlugin;
}
/**
* Set the default font for all the components in this container.
* @param cont the container
*/
public static void setDefaultFont( Container cont )
{
if ( defaultFont != null ) {
cont.setFont( defaultFont );
int numComponents = cont.getComponentCount();
for ( int i = 0; i < numComponents; i++ ) {
Component c = cont.getComponent( i );
if ( c instanceof Container )
setDefaultFont( ( Container )c );
else
c.setFont( defaultFont );
}
}
}
}
class SplashSleeperThread extends Thread
{
private LanguageEditorApplication langEditor;
public SplashSleeperThread( LanguageEditorApplication le )
{
langEditor = le;
}
public void run()
{
try {
sleep( 5000 );
}
catch ( InterruptedException ex ) {
}
langEditor.hideSplash();
}
}
|