Skip to content

Commit

Permalink
Updating the psudo splash to include content from the download manager
Browse files Browse the repository at this point in the history
  • Loading branch information
madhephaestus committed Oct 19, 2024
1 parent 4105cc6 commit 8b12f96
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 43 deletions.
126 changes: 93 additions & 33 deletions src/main/java/com/neuronrobotics/bowlerstudio/PsudoSplash.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,71 @@
import java.awt.EventQueue;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URL;

import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

import com.neuronrobotics.bowlerstudio.assets.StudioBuildInfo;
import com.neuronrobotics.bowlerstudio.scripting.DownloadManager;
import com.neuronrobotics.bowlerstudio.scripting.GitLogProgressMonitor;
import com.neuronrobotics.bowlerstudio.scripting.ScriptingEngine;
import com.neuronrobotics.video.OSUtil;

public class PsudoSplash implements GitLogProgressMonitor{
public class PsudoSplash implements GitLogProgressMonitor {
JFrame interfaceFrame;
private String message = "";
private String log = "";
private static URL resource = PsudoSplash.class.getResource("splash.png");

private static PsudoSplash singelton = null;

public static boolean isInitialized() {
return singelton != null;
}

public static PsudoSplash get() {
if (singelton == null)
singelton = new PsudoSplash();
return singelton;
}

public static void close() {
if (singelton != null)
singelton.closeSplashLocal();
singelton = null;

}

@Override
public void onUpdate(String update, Exception e) {
//e.printStackTrace(System.err);
log=update;
// e.printStackTrace(System.err);
log = update;
updateSplash();
System.out.println(update);
}

class CustomPanel extends JPanel {
private BufferedImage offscreenImage;
private Graphics2D offscreenGraphics;
private void createOffscreenImage() {
offscreenImage = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB);
offscreenGraphics = offscreenImage.createGraphics();
offscreenGraphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
}
@Override
public void addNotify() {
super.addNotify();
createOffscreenImage();
}

/**
*
*/
Expand Down Expand Up @@ -71,16 +109,35 @@ public Dimension getPreferredSize() {
return (new Dimension(image.getWidth(), image.getHeight()));
}

@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);

if (offscreenImage == null) {
createOffscreenImage();
}

// Clear the offscreen image with a fully transparent color
offscreenGraphics.setComposite(AlphaComposite.Clear);
offscreenGraphics.fillRect(0, 0, getWidth(), getHeight());
offscreenGraphics.setComposite(AlphaComposite.SrcOver);

// Your custom painting code goes here
paintCustomGraphics(offscreenGraphics);

// Draw the offscreen image onto the panel
((Graphics2D)g).setComposite(AlphaComposite.SrcOver);
g.drawImage(offscreenImage, 0, 0, this);
}
/*
* This is where the actual Painting Code for the JPanel/JComponent goes. Here
* we will draw the image. Here the first line super.paintComponent(...), means
* we want the JPanel to be drawn the usual Java way first, then later on we
* will add our image to it, by writing the other line, g.drawImage(...).
*/
@Override
protected void paintComponent(Graphics g) {
protected void paintCustomGraphics(Graphics g) {

super.paintComponent(g);
// super.paintComponent(g);
g.drawImage(image, 0, 0, this);
Graphics2D splashGraphics = (Graphics2D) g;
splashGraphics.setComposite(AlphaComposite.Clear);
Expand All @@ -94,7 +151,7 @@ protected void paintComponent(Graphics g) {
splashGraphics.setPaintMode();
splashGraphics.setColor(Color.WHITE);
splashGraphics.drawString(getMessage(), 65, 280);

splashGraphics.setComposite(AlphaComposite.Clear);
// splashGraphics.fillRect(65, 270, 200, 40);
splashGraphics.setPaintMode();
Expand All @@ -104,17 +161,16 @@ protected void paintComponent(Graphics g) {
}
}

public PsudoSplash() {
private PsudoSplash() {

EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
try {
// if(!OSUtil.isLinux())
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException ex) {
} catch (InstantiationException ex) {
} catch (IllegalAccessException ex) {
} catch (UnsupportedLookAndFeelException ex) {
} catch (Exception ex) {
ex.printStackTrace();
}

interfaceFrame = new JFrame("Loading BowlerStudio...");
Expand All @@ -137,19 +193,20 @@ public void run() {

}
});
while (interfaceFrame == null)
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// while (interfaceFrame == null)
// try {
// Thread.sleep(100);
// System.out.println("Waiting for spalsh...");
// } catch (InterruptedException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// try {
// Thread.sleep(100);
// } catch (InterruptedException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
}

// public void setIcon(Image img) {
Expand All @@ -163,17 +220,20 @@ boolean isVisableSplash() {
return false;
}

void closeSplashLocal() {
private void closeSplashLocal() {
if (interfaceFrame != null)
interfaceFrame.setVisible(false);
//ScriptingEngine.removeLogListener(this);
// ScriptingEngine.removeLogListener(this);

}

void updateSplash() {
if (interfaceFrame != null) {
interfaceFrame.invalidate();
interfaceFrame.repaint();
SwingUtilities.invokeLater(() -> {
interfaceFrame.invalidate();
interfaceFrame.repaint();
});

}
}

Expand All @@ -191,7 +251,8 @@ public void setMessage(String message) {
interfaceFrame.setVisible(true);
}
ScriptingEngine.addLogListener(this);
log="";
DownloadManager.addLogListener(this);
log = "";
}

public static URL getResource() {
Expand All @@ -202,5 +263,4 @@ public static void setResource(URL r) {
resource = r;
}


}
18 changes: 9 additions & 9 deletions src/main/java/com/neuronrobotics/bowlerstudio/SplashManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ public class SplashManager {
private static Graphics2D splashGraphics;

private static boolean loadFirst = true;
private static PsudoSplash psudo = null;

public static void closeSplash() {
if (isVisableSplash())
Expand All @@ -26,36 +25,37 @@ private static void closeSplashLocal() {
splashGraphics = null;
return;
}
psudo.closeSplashLocal();
PsudoSplash.close();
}

public static boolean isVisableSplash() {
if (BowlerStudio.splash != null)
return BowlerStudio.splash.isVisible();
if(psudo==null)
if(!PsudoSplash.isInitialized())
return false;
return psudo.isVisableSplash();
return PsudoSplash.get().isVisableSplash();
}

private static void updateSplash() {
psudo.updateSplash();
PsudoSplash.get().updateSplash();
}

public static void renderSplashFrame(int frame, String message) {
if (loadFirst) {
loadFirst = false;

initialize();
}
String string = frame + "% " + message;
System.err.println(" Splash Rendering " + frame + " " + message);
psudo.setMessage(string);
PsudoSplash.get().setMessage(string);
updateSplash();
}

private static void initialize() {

System.err.println("No splash screen availible!");
psudo = new PsudoSplash();

loadFirst = false;
}


}

0 comments on commit 8b12f96

Please sign in to comment.