[prev in list] [next in list] [prev in thread] [next in thread] 

List:       jedit-cvs
Subject:    [ jEdit-commits ] SF.net SVN: jedit:[23449] jEdit/trunk
From:       kerik-sf () users ! sourceforge ! net
Date:       2014-03-30 19:14:28
Message-ID: E1WULBg-0007Kk-Sm () sfs-ml-4 ! v29 ! ch3 ! sourceforge ! com
[Download RAW message or body]

Revision: 23449
          http://sourceforge.net/p/jedit/svn/23449
Author:   kerik-sf
Date:     2014-03-30 19:14:26 +0000 (Sun, 30 Mar 2014)
Log Message:
-----------
apply patch #519 - Allow splash screen that is not always on top

Use a native splash screen when available, which doesn't stay
on top in my tests.

Modified Paths:
--------------
    jEdit/trunk/doc/CHANGES.txt
    jEdit/trunk/org/gjt/sp/jedit/GUIUtilities.java
    jEdit/trunk/org/gjt/sp/jedit/gui/SplashScreen.java
    jEdit/trunk/org/gjt/sp/jedit/icons/splash.png
    jEdit/trunk/org/gjt/sp/jedit/jedit.manifest

Modified: jEdit/trunk/doc/CHANGES.txt
===================================================================
--- jEdit/trunk/doc/CHANGES.txt	2014-03-30 10:42:10 UTC (rev 23448)
+++ jEdit/trunk/doc/CHANGES.txt	2014-03-30 19:14:26 UTC (rev 23449)
@@ -78,6 +78,8 @@
 
 - In plugin manager's install panel plugin dependencies are unchecked
   if they are not required (Eric Le Lay)
+
+- Use a native splash screen if available (patch #519 - Eric Le Lay)
 }}}
 {{{ Editing
 

Modified: jEdit/trunk/org/gjt/sp/jedit/GUIUtilities.java
===================================================================
--- jEdit/trunk/org/gjt/sp/jedit/GUIUtilities.java	2014-03-30 10:42:10 UTC (rev \
                23448)
+++ jEdit/trunk/org/gjt/sp/jedit/GUIUtilities.java	2014-03-30 19:14:26 UTC (rev \
23449) @@ -1970,7 +1970,22 @@
 	//{{{ showSplashScreen() method
 	static void showSplashScreen()
 	{
-		splash = new SplashScreen();
+		// Have to do it in the EDT, since it creates gui components
+		try
+		{
+			SwingUtilities.invokeAndWait(new Runnable()
+			{
+				public void run()
+				{
+					splash = new SplashScreen();
+				}
+			});
+		}
+		catch (Exception e)
+		{
+			Log.log(Log.ERROR, GUIUtilities.class,
+					"error displaying splash screen !",e);
+		}
 	} //}}}
 
 	//{{{ advanceSplashProgress() method

Modified: jEdit/trunk/org/gjt/sp/jedit/gui/SplashScreen.java
===================================================================
--- jEdit/trunk/org/gjt/sp/jedit/gui/SplashScreen.java	2014-03-30 10:42:10 UTC (rev \
                23448)
+++ jEdit/trunk/org/gjt/sp/jedit/gui/SplashScreen.java	2014-03-30 19:14:26 UTC (rev \
23449) @@ -1,6 +1,7 @@
 /*
  * SplashScreen.java - Splash screen
  * Copyright (C) 1998, 2004 Slava Pestov
+ * Copyright (C) 2014 Eric Le Lay
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -32,59 +33,77 @@
  */
 public class SplashScreen extends JComponent
 {
+	private static final long serialVersionUID = 1L;
+
 	//{{{ SplashScreen constructor
 	public SplashScreen()
 	{
-		setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
-		setBackground(Color.white);
+		realSplash = java.awt.SplashScreen.getSplashScreen();
+		fm = getFontMetrics(labelFont);
+		if(realSplash == null)
+		{
+			setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
+			setBackground(Color.white);
 
-		setFont(defaultFont);
-		fm = getFontMetrics(defaultFont);
-		image = getToolkit().getImage(
-			getClass().getResource("/org/gjt/sp/jedit/icons/splash.png"));
-		MediaTracker tracker = new MediaTracker(this);
-		tracker.addImage(image,0);
+			image = getToolkit().getImage(
+				getClass().getResource("/org/gjt/sp/jedit/icons/splash.png"));
+			MediaTracker tracker = new MediaTracker(this);
+			tracker.addImage(image,0);
 
-		try
+			try
+			{
+				tracker.waitForAll();
+			}
+			catch(Exception e)
+			{
+				Log.log(Log.ERROR,this,e);
+			}
+			Dimension screen = getToolkit().getScreenSize(); // sane default
+			win = new JWindow();
+			GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
+			GraphicsDevice[] gs = ge.getScreenDevices();
+			GraphicsDevice gd = gs[0];
+			if (gd != null)
+			{
+				GraphicsConfiguration gconf = gd.getDefaultConfiguration();
+				if (gconf != null)
+				{
+					Rectangle bounds = gconf.getBounds();
+					screen = new Dimension(bounds.width, bounds.height);
+				}
+			}
+			Dimension size = new Dimension(image.getWidth(this) + 2,
+				image.getHeight(this)+2);
+			win.setSize(size);
+			win.getContentPane().add(this, BorderLayout.CENTER);
+			win.setLocation((screen.width - size.width) / 2,
+				(screen.height - size.height) / 2);
+			win.validate();
+			win.setVisible(true);
+		}
+		else
 		{
-			tracker.waitForAll();
+			win = null;
+			image=null;
 		}
-		catch(Exception e)
+	} //}}}
+
+	//{{{ dispose() method
+	public void dispose()
+	{
+		if(realSplash==null)
 		{
-			Log.log(Log.ERROR,this,e);
+			win.dispose();
 		}
-		Dimension screen = getToolkit().getScreenSize(); // sane default
-		win = new JWindow();
-		GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
-		GraphicsDevice[] gs = ge.getScreenDevices();
-		GraphicsDevice gd = gs[0];
-		if (gd != null)
+		else
 		{
-			GraphicsConfiguration gconf = gd.getDefaultConfiguration();
-			if (gconf != null)
+			if(realSplash.isVisible())
 			{
-				Rectangle bounds = gconf.getBounds();
-				screen = new Dimension(bounds.width, bounds.height);
+				realSplash.close();
 			}
 		}
-		Dimension size = new Dimension(image.getWidth(this) + 2,
-			image.getHeight(this) + 2 + PROGRESS_HEIGHT);
-		win.setSize(size);
-
-		win.getContentPane().add(this, BorderLayout.CENTER);
-
-		win.setLocation((screen.width - size.width) / 2,
-			(screen.height - size.height) / 2);
-		win.validate();
-		win.setVisible(true);
 	} //}}}
 
-	//{{{ dispose() method
-	public void dispose()
-	{
-		win.dispose();
-	} //}}}
-
 	//{{{ advance() methods
 	public synchronized void advance()
 	{
@@ -92,16 +111,19 @@
 		progress++;
 		repaint();
 
-		// wait for it to be painted to ensure progress is updated
-		// continuously
-		try
+		if(realSplash == null)
 		{
-			wait();
+			// wait for it to be painted to ensure progress is updated
+			// continuously
+			try
+			{
+				wait();
+			}
+			catch(InterruptedException ie)
+			{
+				Log.log(Log.ERROR,this,ie);
+			}
 		}
-		catch(InterruptedException ie)
-		{
-			Log.log(Log.ERROR,this,ie);
-		}
 	}
 
 	public synchronized void advance(String label)
@@ -111,16 +133,19 @@
 		this.label = label;
 		repaint();
 
-		// wait for it to be painted to ensure progress is updated
-		// continuously
-		try
+		if(realSplash == null)
 		{
-			wait();
+			// wait for it to be painted to ensure progress is updated
+			// continuously
+			try
+			{
+				wait();
+			}
+			catch(InterruptedException ie)
+			{
+				Log.log(Log.ERROR,this,ie);
+			}
 		}
-		catch(InterruptedException ie)
-		{
-			Log.log(Log.ERROR,this,ie);
-		}
 	} //}}}
 
 	//{{{ logAdvanceTime() method
@@ -141,41 +166,82 @@
 		}
 	} //}}}
 
+	//{{{ repaint() method
+	@Override
+	public void repaint()
+	{
+		if(realSplash == null)
+		{
+			// fallback to the default code
+			super.repaint();
+			return;
+		}
+
+		Graphics2D g = realSplash.createGraphics();
+		if (g == null)
+		{
+			Log.log(Log.ERROR, SplashScreen.class,
+					"using native splash screen, but can't obtain graphics from it");
+			return;
+		}
+
+		Dimension size = realSplash.getSize();
+
+		// tell the splash screen the zone to repaint (everything)
+		g.setComposite(AlphaComposite.Clear);
+		g.fillRect(0,0,size.width,size.height);
+		g.setPaintMode();
+
+		doPaintContents(g, size);
+
+		realSplash.update();
+	} //}}}
+
 	//{{{ paintComponent() method
 	@Override
 	public synchronized void paintComponent(Graphics g)
 	{
 		Dimension size = getSize();
 
+		g.drawImage(image,1,1,this);
+
+		doPaintContents(g, size);
+
+		// for the wait() inside advance(...)
+		notify();
+	} //}}}
+
+	//{{{ doPaintContents() method
+	/**
+	 *  Code common to the native and swing splash screens
+	 */
+	private void doPaintContents(Graphics g, Dimension size)
+	{
 		g.setColor(Color.black);
 		g.drawRect(0,0,size.width - 1,size.height - 1);
 
-		g.drawImage(image,1,1,this);
-
-		// XXX: This should not be hardcoded
 		g.setColor(Color.white);
-		g.fillRect(1,image.getHeight(this) + 1,
-			((win.getWidth() - 2) * progress) / PROGRESS_COUNT, PROGRESS_HEIGHT);
+		g.fillRect(1,size.height - 1 - PROGRESS_HEIGHT,
+			((size.width - 2) * progress) / PROGRESS_COUNT, PROGRESS_HEIGHT);
 
 		g.setColor(Color.black);
 
 		if (label != null)
 		{
-			int drawOffsetX = (getWidth() - fm.stringWidth(label)) / 2;
-			int drawOffsetY = image.getHeight(this) + (PROGRESS_HEIGHT
-							      + fm.getAscent() + fm.getDescent()) / 2;
+			int drawOffsetX = (size.width - fm.stringWidth(label)) / 2;
+			int drawOffsetY = size.height - 2 - PROGRESS_HEIGHT
+					+ (PROGRESS_HEIGHT + fm.getAscent() + fm.getDescent()) / 2;
 
 			paintString(g, label, drawOffsetX, drawOffsetY);
 		}
 
 		String version = "version " + jEdit.getVersion();
 
-		int drawOffsetX = (getWidth() / 2) - (fm.stringWidth(version) / 2);
-		int drawOffsetY = image.getHeight(this) - fm.getDescent() - 2;
+		int drawOffsetX = (size.width / 2) - (fm.stringWidth(version) / 2);
+		int drawOffsetY = size.height - PROGRESS_HEIGHT - fm.getDescent() - 3;
 
 		paintString(g, version, drawOffsetX, drawOffsetY);
 
-		notify();
 	} //}}}
 
 	//{{{ paintString() method
@@ -202,9 +268,9 @@
 	private String lastLabel;
 	private long firstAdvanceTime = System.currentTimeMillis();
 	private long lastAdvanceTime = System.currentTimeMillis();
-	private Font defaultFont = new Font("Dialog",Font.PLAIN,10);
 	private Font labelFont = UIManager.getFont("Label.font").deriveFont(9.8f);
 	private Color versionColor1 = new Color(55, 55, 55);
 	private Color versionColor2 = new Color(255, 255, 255, 50);
+	private java.awt.SplashScreen realSplash;
 	//}}}
 }

Modified: jEdit/trunk/org/gjt/sp/jedit/icons/splash.png
===================================================================
(Binary files differ)

Modified: jEdit/trunk/org/gjt/sp/jedit/jedit.manifest
===================================================================
--- jEdit/trunk/org/gjt/sp/jedit/jedit.manifest	2014-03-30 10:42:10 UTC (rev 23448)
+++ jEdit/trunk/org/gjt/sp/jedit/jedit.manifest	2014-03-30 19:14:26 UTC (rev 23449)
@@ -1 +1,2 @@
 Main-Class: org.gjt.sp.jedit.jEdit
+SplashScreen-Image: org/gjt/sp/jedit/icons/splash.png

This was sent by the SourceForge.net collaborative development platform, the world's \
largest Open Source development site.


------------------------------------------------------------------------------
_______________________________________________
jEdit-CVS mailing list
jEdit-CVS@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jedit-cvs


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic