/*
* Copyright (C) 2011-2014 GeoForge Project
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package org.geoforge.guillc;
import java.awt.*;
import javax.swing.JOptionPane;
import org.geoforge.java.awt.color.GfrColor;
import org.geoforge.java.awt.font.GfrUtilFont;
import org.geoforge.java.awt.keyeventdispatcher.GfrKeyEventDispatcherHotKeyForceExit;
import org.geoforge.guillc.frame.GfrFrmAbs;
import org.geoforge.java.enumeration.GfrEnuSystemPropertiesKeys;
import org.geoforge.lang.thread.GfrThr;
import org.geoforge.lang.util.GfrResBundleLang;
/**
*
* @author Amadeus.Sowerby
*
* email: Amadeus.Sowerby_AT_gmail.com
* ... please remove "_AT_" from the above string to get the right email address
*/
public abstract class GfrAppSpcAbs
{
final static public int F_INT_NB_TASK_SPLASH = 3; // initialize, manager, selector
// beg final static private
final static private Color _F_COL_TEXT_PROGRESS_ = new Color(80, 80, 80);
final static private int _F_INT_X_REC_SPLASH_ = 30;
final static private int _F_INT_W_REC_SPLASH_ = 100;
final static private int _F_INT_H_REC_SPLASH_ = 15;
final static private int _F_INT_PROGRESS_BAR_THICKNESS_ = 6;
final static private String _STR_REQUIRED_JVM_PREFIX_ = "1.6";
final static private String[] _STRS_REQUIRED_ARGUMENTS_VM_ =
{
GfrEnuSystemPropertiesKeys.VERSION_WORLDWIND.getLabel(),
GfrEnuSystemPropertiesKeys.VERSION_MANAGER_PLUGINS_ORG.getLabel(),
GfrEnuSystemPropertiesKeys.VERSION_MANAGER_PLUGINS_APPLI.getLabel()
};
// end final static private
// beg static
// allow to force an exit with hotkey
static
{
final KeyEventDispatcher ked = new GfrKeyEventDispatcherHotKeyForceExit();
KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(ked);
}
static
{
_s_checkJvm();
}
static
{
// begin: prerequisites, java -D[key]="[value]"
for (int i = 0; i < GfrAppSpcAbs._STRS_REQUIRED_ARGUMENTS_VM_.length; i++)
{
if (System.getProperty(GfrAppSpcAbs._STRS_REQUIRED_ARGUMENTS_VM_[i]) == null)
{
String str = "Missing VM argument: " + GfrAppSpcAbs._STRS_REQUIRED_ARGUMENTS_VM_[i] + ", exiting";
System.err.println(str);
JOptionPane.showMessageDialog(
null,
str,
"Error",
JOptionPane.ERROR_MESSAGE);
System.exit(1);
}
}
// end: prerequisites, java -D[key]="[value]"
}
//--
static private String _STR_MESSAGE_SPLASH_ =
GfrResBundleLang.s_getInstance().getValue("sentence.loadingPleaseWait"); // !!!
static protected SplashScreen _SSN = null;
static private int _INT_J_SPLASH_ = 0;
// beg static methods
// ----
static public void _s_setTextSplash(String str)
{
_INT_J_SPLASH_++;
_STR_MESSAGE_SPLASH_ = str + " ...";
}
static protected void _s_startSplash()
{
GfrAppSpcAbs._SSN = SplashScreen.getSplashScreen();
if (GfrAppSpcAbs._SSN == null)
return;
GfrThr thr = new GfrThr("splashScreen")
{
@Override
public void run()
{
_s_runSplash_();
}
};
thr.setPriority(Thread.MIN_PRIORITY);
thr.start();
//thr.setDaemon(true);
//Runtime.getRuntime().addShutdownHook(thr);
}
static private void _s_runSplash_()
{
try
{
while (true)
{
if (GfrAppSpcAbs._SSN == null)
break;
if (!GfrAppSpcAbs._SSN.isVisible())
return;
final Graphics2D g = (Graphics2D) GfrAppSpcAbs._SSN.createGraphics();
g.setFont(GfrUtilFont.s_get(Font.ITALIC, 14));
g.setColor(Color.BLACK);
g.drawRect(0, 0, (int) GfrAppSpcAbs._SSN.getSize().getWidth() - 1, (int) GfrAppSpcAbs._SSN.getSize().getHeight() - 1);
// rectangle at bottom of image
final Rectangle rect = new Rectangle(_F_INT_X_REC_SPLASH_,
GfrAppSpcAbs._SSN.getSize().height - 50,
_F_INT_W_REC_SPLASH_,
_F_INT_H_REC_SPLASH_);
final int f_intYProgressBar = rect.y + _F_INT_H_REC_SPLASH_ * 2;
// transparent background
g.setBackground(new Color(0, 0, 0, 0));
g.drawRect(0, 0, (int) GfrAppSpcAbs._SSN.getSize().getWidth() - 1, (int) GfrAppSpcAbs._SSN.getSize().getHeight() - 1);
g.clearRect(_F_INT_X_REC_SPLASH_, rect.y, _F_INT_W_REC_SPLASH_ * 3, _F_INT_H_REC_SPLASH_ * 3);
g.setColor(_F_COL_TEXT_PROGRESS_);
g.drawString(_STR_MESSAGE_SPLASH_, _F_INT_X_REC_SPLASH_, rect.y + _F_INT_H_REC_SPLASH_);
//g.setColor(GfrColor.RED);
int intW = _F_INT_W_REC_SPLASH_ * 3;
if (intW != 0)
{
intW /= (GfrAppSpcAbs.F_INT_NB_TASK_SPLASH + 1);
intW *= _INT_J_SPLASH_;
}
GradientPaint gradient = new GradientPaint(
0, f_intYProgressBar + 0, GfrColor.GREEN,
0, f_intYProgressBar + _F_INT_PROGRESS_BAR_THICKNESS_, GfrColor.GREEN_4);
g.setPaint(gradient);
g.fillRect(_F_INT_X_REC_SPLASH_,
f_intYProgressBar,
intW,
_F_INT_PROGRESS_BAR_THICKNESS_);
GfrAppSpcAbs._SSN.update();
try
{
Thread.sleep(4000);
}
catch (InterruptedException ex)
{
if (GfrAppSpcAbs._SSN != null)
{
if (GfrAppSpcAbs._SSN.isVisible())
GfrAppSpcAbs._SSN.close();
}
break;
}
catch (Exception ex)
{
if (GfrAppSpcAbs._SSN != null)
{
if (GfrAppSpcAbs._SSN.isVisible())
GfrAppSpcAbs._SSN.close();
}
break;
}
} // end while
}
catch (Exception exc)
{
//System.out.println("exc caught, don't care");
}
}
static private void _s_checkJvm()
{
String strVersionJvm = System.getProperty("java.version");
if (strVersionJvm.startsWith(GfrAppSpcAbs._STR_REQUIRED_JVM_PREFIX_ + "."))
return;
String strTitle = "Wrong Java Virtual Machine version";
// wrong
String strBody = "Sorry, this application requires Java VM ";
strBody += GfrAppSpcAbs._STR_REQUIRED_JVM_PREFIX_;
strBody += "\n";
strBody += "You are currently running Java VM ";
strBody += strVersionJvm;
strBody += "\n";
strBody += "Please contact your system administrator to point to the right Java VM.";
strBody += "\n";
strBody += "\n";
strBody += "... exiting";
JOptionPane.showMessageDialog(null, strBody, strTitle, JOptionPane.ERROR_MESSAGE);
System.exit(1);
}
// ---
abstract public void doConfirmExit();
abstract protected void _delayDoHelpBroker();
protected GfrFrmAbs _frm = null;
public GfrFrmAbs getFrame() { return this._frm; }
protected GfrAppSpcAbs()
{
super();
}
}