View Javadoc

1   /*
2    * @(#) ScreenManager.java Apr 29, 2004
3    * 
4    * Copyright (c) 2003 Delft University of Technology Jaffalaan 5, 2628 BX Delft,
5    * the Netherlands All rights reserved.
6    * 
7    * This software is proprietary information of Delft University of Technology
8    * The code is published under the General Public License
9    */
10  package nl.tudelft.simulation.language.swing;
11  
12  import java.awt.DisplayMode;
13  import java.awt.GraphicsEnvironment;
14  import java.awt.Window;
15  
16  import javax.swing.JFrame;
17  
18  /***
19   * The ScreenManager class manages initializing and displaying full screen
20   * graphics mode.
21   * <p>
22   * (c) copyright 2004 <a href="http://www.simulation.tudelft.nl">Delft
23   * University of Technology </a>, the Netherlands. <br>
24   * See for project information <a href="http://www.simulation.tudelft.nl">
25   * www.simulation.tudelft.nl </a> <br>
26   * License of use: <a href="http://www.gnu.org/copyleft/gpl.html">General Public
27   * License (GPL) </a>, no warranty <br>
28   * 
29   * @version 1.0 Mar 18, 2004 <br>
30   * @author <a href="http://www.tbm.tudelft.nl/webstaf/stijnh/index.htm">
31   *         Stijn-Pieter van Houten </a>
32   */
33  public class ScreenManager
34  {
35  	/*** the environment */
36  	private GraphicsEnvironment environment;
37  
38  	/***
39  	 * Constructs a new ScreenManager.
40  	 */
41  	public ScreenManager()
42  	{
43  		super();
44  		this.environment = GraphicsEnvironment.getLocalGraphicsEnvironment();
45  	}
46  
47  	/***
48  	 * Method setFullScreen. Enters full screen mode and changes the display
49  	 * mode.
50  	 * 
51  	 * @param window The window to show full screen.
52  	 */
53  	public void setFullScreen(final JFrame window)
54  	{
55  		window.setUndecorated(true);
56  		window.setResizable(false);
57  		this.environment.getDefaultScreenDevice().setFullScreenWindow(window);
58  		if (this.environment.getDefaultScreenDevice()
59  				.isDisplayChangeSupported())
60  		{
61  			DisplayMode mode = new DisplayMode((int) this.environment
62  					.getMaximumWindowBounds().getWidth(),
63  					(int) this.environment.getMaximumWindowBounds().getWidth(),
64  					24, DisplayMode.REFRESH_RATE_UNKNOWN);
65  			this.environment.getDefaultScreenDevice().setDisplayMode(mode);
66  
67  		}
68  	}
69  
70  	/***
71  	 * Method getFullScreenWindow.
72  	 * 
73  	 * @return Returns the window currently used in full screen mode.
74  	 */
75  	public Window getFullScreenWindow()
76  	{
77  		return this.environment.getDefaultScreenDevice().getFullScreenWindow();
78  	}
79  
80  	/***
81  	 * Method restoreScreen. Restores the screen's display mode.
82  	 */
83  	public void restoreScreen()
84  	{
85  		Window window = this.environment.getDefaultScreenDevice()
86  				.getFullScreenWindow();
87  		if (window != null)
88  		{
89  			window.dispose();
90  		}
91  		this.environment.getDefaultScreenDevice().setFullScreenWindow(null);
92  	}
93  }