@ -67,6 +67,7 @@ import java.net.URL;
import java.util.Iterator ;
import java.util.Iterator ;
import java.util.concurrent.Callable ;
import java.util.concurrent.Callable ;
import java.util.concurrent.ConcurrentLinkedQueue ;
import java.util.concurrent.ConcurrentLinkedQueue ;
import java.util.logging.Level ;
import java.util.logging.Logger ;
import java.util.logging.Logger ;
import org.netbeans.api.progress.ProgressHandle ;
import org.netbeans.api.progress.ProgressHandle ;
import org.netbeans.api.progress.ProgressHandleFactory ;
import org.netbeans.api.progress.ProgressHandleFactory ;
@ -74,9 +75,7 @@ import org.netbeans.spi.project.LookupProvider;
import org.openide.DialogDisplayer ;
import org.openide.DialogDisplayer ;
import org.openide.NotifyDescriptor ;
import org.openide.NotifyDescriptor ;
import org.openide.NotifyDescriptor.Confirmation ;
import org.openide.NotifyDescriptor.Confirmation ;
import org.openide.NotifyDescriptor.Message ;
import org.openide.awt.HtmlBrowser ;
import org.openide.awt.HtmlBrowser ;
import org.openide.awt.StatusDisplayer ;
import org.openide.loaders.DataObject ;
import org.openide.loaders.DataObject ;
import org.openide.util.Exceptions ;
import org.openide.util.Exceptions ;
import org.openide.util.HelpCtx ;
import org.openide.util.HelpCtx ;
@ -91,6 +90,8 @@ import org.openide.util.lookup.Lookups;
@SuppressWarnings ( "unchecked" )
@SuppressWarnings ( "unchecked" )
public class SceneApplication extends Application implements LookupProvider {
public class SceneApplication extends Application implements LookupProvider {
private static final Logger logger = Logger . getLogger ( SceneApplication . class . getName ( ) ) ;
private static boolean failMessageShown = false ;
private PointLight camLight ;
private PointLight camLight ;
private static SceneApplication application ;
private static SceneApplication application ;
@ -126,6 +127,7 @@ public class SceneApplication extends Application implements LookupProvider {
private ProgressHandle progressHandle = ProgressHandleFactory . createHandle ( "Opening SceneViewer.." ) ;
private ProgressHandle progressHandle = ProgressHandleFactory . createHandle ( "Opening SceneViewer.." ) ;
private String lastError = "" ;
private String lastError = "" ;
private boolean started = false ;
private boolean started = false ;
private boolean initFailed = false ;
private AwtPanel panel ;
private AwtPanel panel ;
private ViewPort overlayView ;
private ViewPort overlayView ;
boolean useCanvas = false ;
boolean useCanvas = false ;
@ -135,6 +137,7 @@ public class SceneApplication extends Application implements LookupProvider {
private FakeApplication fakeApp ;
private FakeApplication fakeApp ;
public SceneApplication ( ) {
public SceneApplication ( ) {
Logger . getLogger ( "com.jme3" ) . addHandler ( logHandler ) ;
progressHandle . start ( 7 ) ;
progressHandle . start ( 7 ) ;
useCanvas = "true" . equals ( NbPreferences . forModule ( Installer . class ) . get ( "use_lwjgl_canvas" , "false" ) ) ;
useCanvas = "true" . equals ( NbPreferences . forModule ( Installer . class ) . get ( "use_lwjgl_canvas" , "false" ) ) ;
try {
try {
@ -148,8 +151,6 @@ public class SceneApplication extends Application implements LookupProvider {
}
}
setSettings ( newSetting ) ;
setSettings ( newSetting ) ;
Logger . getLogger ( "com.jme3" ) . addHandler ( logHandler ) ;
setPauseOnLostFocus ( false ) ;
setPauseOnLostFocus ( false ) ;
if ( useCanvas ) {
if ( useCanvas ) {
@ -164,10 +165,8 @@ public class SceneApplication extends Application implements LookupProvider {
start ( ) ;
start ( ) ;
}
}
} catch ( Exception e ) {
} catch ( Exception e ) {
Exceptions . printStackTrace ( e ) ;
showStartupErrorMessage ( e ) ;
showStartupErrorMessage ( e ) ;
} catch ( Error e ) {
} catch ( Error e ) {
Exceptions . printStackTrace ( e ) ;
showStartupErrorMessage ( e ) ;
showStartupErrorMessage ( e ) ;
} finally {
} finally {
getProgressHandle ( ) . finish ( ) ;
getProgressHandle ( ) . finish ( ) ;
@ -220,10 +219,11 @@ public class SceneApplication extends Application implements LookupProvider {
@Override
@Override
public void initialize ( ) {
public void initialize ( ) {
thread = Thread . currentThread ( ) ;
if ( ! initFailed ) {
fakeApp . startFakeApp ( ) ;
try {
try {
super . initialize ( ) ;
super . initialize ( ) ;
thread = Thread . currentThread ( ) ;
fakeApp . startFakeApp ( ) ;
{
{
overlayView = getRenderManager ( ) . createMainView ( "Overlay" , cam ) ;
overlayView = getRenderManager ( ) . createMainView ( "Overlay" , cam ) ;
overlayView . setClearFlags ( false , true , false ) ;
overlayView . setClearFlags ( false , true , false ) ;
@ -267,28 +267,35 @@ public class SceneApplication extends Application implements LookupProvider {
inputManager . addMapping ( "MouseButtonMiddle" , new MouseButtonTrigger ( 2 ) ) ;
inputManager . addMapping ( "MouseButtonMiddle" , new MouseButtonTrigger ( 2 ) ) ;
inputManager . addMapping ( "MouseButtonRight" , new MouseButtonTrigger ( 1 ) ) ;
inputManager . addMapping ( "MouseButtonRight" , new MouseButtonTrigger ( 1 ) ) ;
started = true ;
started = true ;
} catch ( Exception e ) {
} catch ( Throwable e ) {
Exceptions . printStackTrace ( e ) ;
showStartupErrorMessage ( e ) ;
} catch ( Error e ) {
Exceptions . printStackTrace ( e ) ;
showStartupErrorMessage ( e ) ;
showStartupErrorMessage ( e ) ;
initFailed = true ;
if ( fakeApp ! = null ) {
fakeApp . stopFakeApp ( ) ;
}
} finally {
} finally {
getProgressHandle ( ) . finish ( ) ;
getProgressHandle ( ) . finish ( ) ;
}
}
}
}
}
@Override
@Override
public void destroy ( ) {
public void destroy ( ) {
fakeApp . stopFakeApp ( ) ;
fakeApp . stopFakeApp ( ) ;
initFailed = false ;
super . destroy ( ) ;
super . destroy ( ) ;
}
}
@Override
@Override
public void update ( ) {
public void update ( ) {
if ( ! started ) {
if ( ! started ) {
return ;
try {
runQueuedTasks ( ) ;
} catch ( Exception e ) {
getStateManager ( ) . update ( 0 ) ;
logger . log ( Level . INFO , "Exception calling Tasks:" , e ) ;
}
}
} else {
try {
try {
super . update ( ) ;
super . update ( ) ;
FakeApplication fakap = fakeApp ;
FakeApplication fakap = fakeApp ;
@ -332,6 +339,7 @@ public class SceneApplication extends Application implements LookupProvider {
handleError ( e . getMessage ( ) , e ) ;
handleError ( e . getMessage ( ) , e ) ;
}
}
}
}
}
//TODO: Lookup for Application
//TODO: Lookup for Application
public Lookup createAdditionalLookup ( Lookup baseContext ) {
public Lookup createAdditionalLookup ( Lookup baseContext ) {
@ -382,6 +390,10 @@ public class SceneApplication extends Application implements LookupProvider {
* @param request
* @param request
* /
* /
public void openScene ( final SceneRequest request ) {
public void openScene ( final SceneRequest request ) {
if ( failMessageShown ) {
NotifyUtil . show ( "Error starting OpenGL context!" , "Click here to go to troubleshooting web page." , MessageType . EXCEPTION , lst , 0 ) ;
return ;
}
closeScene ( currentSceneRequest , request ) ;
closeScene ( currentSceneRequest , request ) ;
java . awt . EventQueue . invokeLater ( new Runnable ( ) {
java . awt . EventQueue . invokeLater ( new Runnable ( ) {
public void run ( ) {
public void run ( ) {
@ -618,22 +630,26 @@ public class SceneApplication extends Application implements LookupProvider {
public void handleError ( String msg , Throwable t ) {
public void handleError ( String msg , Throwable t ) {
progressHandle . finish ( ) ;
progressHandle . finish ( ) ;
if ( msg = = null ) {
if ( msg = = null ) {
return ;
msg = t . getMessage ( ) ;
}
}
if ( ! started ) {
if ( ! started ) {
showStartupErrorMessage ( t ) ;
showStartupErrorMessage ( t ) ;
Exceptions . printStackTrace ( t ) ;
} else if ( lastError ! = null & & ! lastError . equals ( msg ) ) {
} else {
logger . log ( Level . SEVERE , msg , t ) ;
if ( lastError ! = null & & ! lastError . equals ( msg ) ) {
StatusDisplayer . getDefault ( ) . setStatusText ( "Error in Scene, check application log" ) ;
Exceptions . printStackTrace ( t ) ;
lastError = msg ;
lastError = msg ;
}
}
}
}
}
public static void showStartupErrorMessage ( Throwable exception ) {
public static void showStartupErrorMessage ( Throwable exception ) {
ActionListener lst = new ActionListener ( ) {
if ( failMessageShown ) {
logger . log ( Level . INFO , exception . getMessage ( ) , exception ) ;
return ;
}
failMessageShown = true ;
NotifyUtil . show ( "Error starting OpenGL context!" , "Click here to go to troubleshooting web page." , MessageType . EXCEPTION , lst , 0 ) ;
logger . log ( Level . INFO , exception . getMessage ( ) , exception ) ;
}
private static ActionListener lst = new ActionListener ( ) {
public void actionPerformed ( ActionEvent e ) {
public void actionPerformed ( ActionEvent e ) {
try {
try {
HtmlBrowser . URLDisplayer . getDefault ( ) . showURL ( new URL ( "http://jmonkeyengine.org/wiki/doku.php/sdk:troubleshooting" ) ) ;
HtmlBrowser . URLDisplayer . getDefault ( ) . showURL ( new URL ( "http://jmonkeyengine.org/wiki/doku.php/sdk:troubleshooting" ) ) ;
@ -642,8 +658,6 @@ public class SceneApplication extends Application implements LookupProvider {
}
}
}
}
} ;
} ;
NotifyUtil . show ( "Error starting OpenGL context!" , exception . getMessage ( ) + " - Click here to go to troubleshooting web page." , MessageType . EXCEPTION , lst , 0 ) ;
}
@Override
@Override
public RenderManager getRenderManager ( ) {
public RenderManager getRenderManager ( ) {