• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Main repository of MikuMikuStudio


Commit MetaInfo

修订版ecff93d6b9cd0f084a69a59dcb7809f761defc60 (tree)
时间2004-01-25 11:14:38
作者mojomonkey <mojomonkey@75d0...>
Commitermojomonkey

Log Message

Eric the Reds Changes: Improved display settings detection.

git-svn-id: http://jmonkeyengine.googlecode.com/svn/trunk@277 75d07b2b-3a1a-0410-a2c5-0572b91ccdca

更改概述

差异

--- a/src/com/jme/system/DisplaySystem.java
+++ b/src/com/jme/system/DisplaySystem.java
@@ -55,111 +55,123 @@ import com.jme.widget.font.WidgetFont;
5555 * @see com.jme.renderer.Renderer
5656 *
5757 * @author Mark Powell
58- * @version $Id: DisplaySystem.java,v 1.8 2004-01-22 21:48:55 mojomonkey Exp $
58+ * @version $Id: DisplaySystem.java,v 1.9 2004-01-25 02:14:38 mojomonkey Exp $
5959 */
6060 public abstract class DisplaySystem {
61- private static DisplaySystem display;
62- protected int width, height;
63-
64- /**
65- * The list of current implemented rendering APIs that subclass Display.
66- */
67- public static final String[] rendererNames = {"LWJGL"};
68-
69- /**
70- *
71- * <code>getDisplaySystem</code> is a factory method that creates the
72- * appropriate display system specified by the key parameter. If the
73- * key given is not a valid identifier for a specific display system,
74- * null is returned. For valid display systems see the
75- * <code>rendererNames</code> array.
76- * @param key the display system to use.
77- * @return the appropriate display system specified by the key.
78- */
79- public static DisplaySystem getDisplaySystem(String key) {
80- if("LWJGL".equalsIgnoreCase(key)) {
81- display = new LWJGLDisplaySystem();
82- return display;
83- }
84-
85- return null;
86- }
87-
88- public static DisplaySystem getDisplaySystem() {
89- return display;
90- }
91-
92- public int getWidth() {
93- return width;
94- }
95-
96- public int getHeight() {
97- return height;
98- }
99-
100- public abstract void setTitle(String title);
101-
102- /**
103- * <code>createWindow</code> creates a window with the desired settings.
104- * The width and height defined by w and h define the size of the window
105- * if fullscreen is false, otherwise it defines the resolution of the
106- * fullscreen display. The color depth is defined by bpp. The
107- * implementing class should only allow 16, 24, and 32. The monitor
108- * frequency is defined by the frq parameter and should not exceed the
109- * capabilities of the connected hardware, the implementing class should
110- * attempt to assure this does not happen. Lastly, the boolean flag fs
111- * determines if the display should be windowed or fullscreen. If false,
112- * windowed is chosen. This window will be placed in the center of the
113- * screen initially. If true fullscreen mode will be entered with the
114- * appropriate settings.
115- * @param w the width/horizontal resolution of the display.
116- * @param h the height/vertical resolution of the display.
117- * @param bpp the color depth of the display.
118- * @param frq the frequency of refresh of the display.
119- * @param fs flag determining if fullscreen is to be used or not. True will
120- * use fullscreen, false will use windowed mode.
121- */
122- public abstract void createWindow(int w, int h, int bpp, int frq, boolean fs);
123-
124- /**
125- * <code>getRenderer</code> returns the <code>Renderer</code> implementation
126- * that is compatible with the chosen <code>DisplaySystem</code>. For
127- * example, if <code>LWJGLDisplaySystem</code> is used, the returned
128- * <code>Renderer</code> will be </code>LWJGLRenderer</code>.
129- * @see com.jme.renderer.Renderer
130- * @return the appropriate <code>Renderer</code> implementation that is
131- * compatible with the used <code>DisplaySystem</code>.
132- */
133- public abstract Renderer getRenderer();
134-
135- /**
136- * <code>isCreated</code> returns the current status of the display
137- * system. If the window and renderer are created, true is returned,
138- * otherwise false.
139- *
140- * @return whether the display system is created.
141- */
142- public abstract boolean isCreated();
143-
144- /**
145- * <code>isClosing</code> notifies if the window is currently closing.
146- * This could be caused via the application itself or external interrupts
147- * such as alt-f4 etc.
148- * @return true if the window is closing, false otherwise.
149- */
150- public abstract boolean isClosing();
151-
152- /**
153- * <code>reset</code> cleans up the display system for closing or restarting.
154- *
155- */
156- public abstract void reset();
157-
158- /**
159- * @param fontName - name of the font to loaded
160- * @return an instance of the requested font, null of
161- * the isn't loaded.
162- */
163- public abstract WidgetFont getFont(String fontName);
164-
61+ private static DisplaySystem display;
62+ protected int width, height;
63+
64+ /**
65+ * The list of current implemented rendering APIs that subclass Display.
66+ */
67+ public static final String[] rendererNames = { "LWJGL" };
68+
69+ /**
70+ *
71+ * <code>getDisplaySystem</code> is a factory method that creates the
72+ * appropriate display system specified by the key parameter. If the
73+ * key given is not a valid identifier for a specific display system,
74+ * null is returned. For valid display systems see the
75+ * <code>rendererNames</code> array.
76+ * @param key the display system to use.
77+ * @return the appropriate display system specified by the key.
78+ */
79+ public static DisplaySystem getDisplaySystem(String key) {
80+ if ("LWJGL".equalsIgnoreCase(key)) {
81+ display = new LWJGLDisplaySystem();
82+ return display;
83+ }
84+
85+ return null;
86+ }
87+
88+ public static DisplaySystem getDisplaySystem() {
89+ return display;
90+ }
91+
92+ public int getWidth() {
93+ return width;
94+ }
95+
96+ public int getHeight() {
97+ return height;
98+ }
99+
100+ /**
101+ * <code>isValidDisplayMode</code> determines if the given parameters constitute
102+ * a valid display mode on this system. Returning true does not necessarily
103+ * guarantee that the system is capable of running in the specified display mode,
104+ * merely that it <i>believes</i> it is possible.
105+ * @param width the width/horizontal resolution of the display.
106+ * @param height the height/vertical resolution of the display.
107+ * @param bpp the bit depth of the display.
108+ * @param freq the frequency of refresh of the display (in Hz).
109+ */
110+ public abstract boolean isValidDisplayMode(int width, int height, int bpp, int freq);
111+
112+ public abstract void setTitle(String title);
113+
114+ /**
115+ * <code>createWindow</code> creates a window with the desired settings.
116+ * The width and height defined by w and h define the size of the window
117+ * if fullscreen is false, otherwise it defines the resolution of the
118+ * fullscreen display. The color depth is defined by bpp. The
119+ * implementing class should only allow 16, 24, and 32. The monitor
120+ * frequency is defined by the frq parameter and should not exceed the
121+ * capabilities of the connected hardware, the implementing class should
122+ * attempt to assure this does not happen. Lastly, the boolean flag fs
123+ * determines if the display should be windowed or fullscreen. If false,
124+ * windowed is chosen. This window will be placed in the center of the
125+ * screen initially. If true fullscreen mode will be entered with the
126+ * appropriate settings.
127+ * @param w the width/horizontal resolution of the display.
128+ * @param h the height/vertical resolution of the display.
129+ * @param bpp the color depth of the display.
130+ * @param frq the frequency of refresh of the display.
131+ * @param fs flag determining if fullscreen is to be used or not. True will
132+ * use fullscreen, false will use windowed mode.
133+ */
134+ public abstract void createWindow(int w, int h, int bpp, int frq, boolean fs);
135+
136+ /**
137+ * <code>getRenderer</code> returns the <code>Renderer</code> implementation
138+ * that is compatible with the chosen <code>DisplaySystem</code>. For
139+ * example, if <code>LWJGLDisplaySystem</code> is used, the returned
140+ * <code>Renderer</code> will be </code>LWJGLRenderer</code>.
141+ * @see com.jme.renderer.Renderer
142+ * @return the appropriate <code>Renderer</code> implementation that is
143+ * compatible with the used <code>DisplaySystem</code>.
144+ */
145+ public abstract Renderer getRenderer();
146+
147+ /**
148+ * <code>isCreated</code> returns the current status of the display
149+ * system. If the window and renderer are created, true is returned,
150+ * otherwise false.
151+ *
152+ * @return whether the display system is created.
153+ */
154+ public abstract boolean isCreated();
155+
156+ /**
157+ * <code>isClosing</code> notifies if the window is currently closing.
158+ * This could be caused via the application itself or external interrupts
159+ * such as alt-f4 etc.
160+ * @return true if the window is closing, false otherwise.
161+ */
162+ public abstract boolean isClosing();
163+
164+ /**
165+ * <code>reset</code> cleans up the display system for closing or restarting.
166+ *
167+ */
168+ public abstract void reset();
169+
170+ /**
171+ * @param fontName - name of the font to loaded
172+ * @return an instance of the requested font, null of
173+ * the isn't loaded.
174+ */
175+ public abstract WidgetFont getFont(String fontName);
176+
165177 }
--- a/src/com/jme/system/LWJGLDisplaySystem.java
+++ b/src/com/jme/system/LWJGLDisplaySystem.java
@@ -49,178 +49,175 @@ import com.jme.widget.impl.lwjgl.WidgetLWJGLFont;
4949 * that gives a way of displaying data to the created window.
5050 *
5151 * @author Mark Powell
52- * @version $Id: LWJGLDisplaySystem.java,v 1.7 2004-01-20 12:52:04 greggpatton Exp $
52+ * @version $Id: LWJGLDisplaySystem.java,v 1.8 2004-01-25 02:14:38 mojomonkey Exp $
5353 */
5454 public class LWJGLDisplaySystem extends DisplaySystem {
5555
56- private int bpp;
57- private int frq;
58- private String title = "";
59- private boolean fs;
60- private boolean created;
61- private LWJGLRenderer renderer;
62-
63- /**
64- * Constructor instantiates a new <code>LWJGLDisplaySystem</code> object.
65- * During instantiation confirmation is made to determine if the
66- * LWJGL API is installed properly. If not, a JmeException is thrown.
67- *
68- */
69- public LWJGLDisplaySystem() {
70- try {
71- System.loadLibrary("lwjgl");
72- } catch (UnsatisfiedLinkError e) {
73- throw new JmeException("LWJGL library not set.");
74- }
75-
76- }
77-
78- /**
79- * <code>setTitle</code> sets the window title of the created window.
80- * @param title the title.
81- */
82- public void setTitle(String title) {
83- Window.setTitle(title);
84- }
85-
86- /**
87- * <code>createWindow</code> will create a LWJGL display context. This
88- * window will be a purely native context as defined by the LWJGL API.
89- *
90- * @see com.jme.system.DisplaySystem#createWindow(int, int, int, int, boolean)
91- */
92- public void createWindow(int w, int h, int bpp, int frq, boolean fs) {
93- //confirm that the parameters are valid.
94- if (w <= 0 || h <= 0) {
95- throw new JmeException("Invalid resolution values: " + w + " " + h);
96- } else if ((bpp != 32) && (bpp != 16) && (bpp != 24)) {
97- throw new JmeException("Invalid pixel depth: " + bpp);
98- }
99-
100- //set the window attributes
101- this.width = w;
102- this.height = h;
103- this.bpp = bpp;
104- this.frq = frq;
105- this.fs = fs;
106-
107- initDisplay();
108- renderer = new LWJGLRenderer(width,height);
109-
110- created = true;
111- }
112-
113- /**
114- * <code>getRenderer</code> returns the created rendering class for
115- * LWJGL (<code>LWJGLRenderer</code>). This will give the needed access to
116- * display data to the window.
117- * @see com.jme.system.DisplaySystem#getRenderer()
118- */
119- public Renderer getRenderer() {
120- return renderer;
121- }
122-
123- /**
124- * <code>isCreated</code> returns true if the current display is created,
125- * false otherwise.
126- * @see com.jme.system.DisplaySystem#isCreated()
127- * @return true if display is created.
128- */
129- public boolean isCreated() {
130- return created;
131- }
132-
133- /**
134- * <code>isClosing</code> returns any close requests. True if any exist,
135- * false otherwise.
136- * @see com.jme.system.DisplaySystem#isClosing()
137- * @return true if a close request is active.
138- */
139- public boolean isClosing() {
140- return Window.isCloseRequested();
141- }
142-
143- /**
144- * <code>reset</code> prepares the window for closing or restarting.
145- * @see com.jme.system.DisplaySystem#reset()
146- */
147- public void reset() {
148- Display.resetDisplayMode();
149- }
150-
151- /**
152- * <code>getValidDisplayMode</code> returns a <code>DisplayMode</code> object
153- * that has the requested width, height and color depth. If there is no
154- * mode that supports a requested resolution, null is returned.
155- *
156- * @param width the width of the desired mode.
157- * @param height the height of the desired mode.
158- * @param bpp the color depth of the desired mode.
159- * @param freq the frequency of the monitor.
160- * @return <code>DisplayMode</code> object that supports the requested
161- * resolutions. Null is returned if no valid modes are found.
162- */
163- private DisplayMode getValidDisplayMode(
164- int width,
165- int height,
166- int bpp,
167- int freq) {
168- //get all the modes, and find one that matches our width, height, bpp.
169- DisplayMode[] modes = Display.getAvailableDisplayModes();
170- //Make sure that we find the mode that uses our current monitor freq.
171-
172- for (int i = 0; i < modes.length; i++) {
173- if (modes[i].width == width
174- && modes[i].height == height
175- && modes[i].bpp == bpp
176- && modes[i].freq == freq) {
177-
178- return modes[i];
179- }
180- }
181-
182- //none found
183- return null;
184- }
185-
186- /**
187- * <code>initDisplay</code> creates the LWJGL window with the desired
188- * specifications.
189- *
190- */
191- private void initDisplay() {
192- try {
193- //create the Display.
194- DisplayMode mode = getValidDisplayMode(width, height, bpp, frq);
195- if (null == mode) {
196- throw new JmeException("Bad display mode");
197- }
198-
199- if (fs) {
200- Display.setDisplayMode(mode);
201- Window.create(title, bpp, 0, 8, 0);
202- } else {
203- int x, y;
204- x =
205- (Toolkit.getDefaultToolkit().getScreenSize().width - width)
206- / 2;
207- y =
208- (Toolkit.getDefaultToolkit().getScreenSize().height
209- - height)
210- / 2;
211- Window.create(title, x, y, width, height, bpp, 0, 8, 0);
212- }
213-
214- } catch (Exception e) {
215- System.exit(1);
216- }
217- }
218-
219- /* (non-Javadoc)
220- * @see com.jme.system.DisplaySystem#getFont(java.lang.String)
221- */
222- public WidgetFont getFont(String fontName) {
223- WidgetFont f = new WidgetLWJGLFont("Default");
224- return f;
225- }
56+ private int bpp;
57+ private int frq;
58+ private String title = "";
59+ private boolean fs;
60+ private boolean created;
61+ private LWJGLRenderer renderer;
62+
63+ /**
64+ * Constructor instantiates a new <code>LWJGLDisplaySystem</code> object.
65+ * During instantiation confirmation is made to determine if the
66+ * LWJGL API is installed properly. If not, a JmeException is thrown.
67+ *
68+ */
69+ public LWJGLDisplaySystem() {
70+ try {
71+ System.loadLibrary("lwjgl");
72+ } catch (UnsatisfiedLinkError e) {
73+ throw new JmeException("LWJGL library not set.");
74+ }
75+
76+ }
77+
78+ /**
79+ * <code>isValidDisplayMode</code>
80+ * @see com.jme.system.DisplaySystem#isValidDisplayMode(int, int, int, int)
81+ */
82+ public boolean isValidDisplayMode(int width, int height, int bpp, int freq) {
83+ return getValidDisplayMode(width, height, bpp, freq) != null;
84+ }
85+
86+ /**
87+ * <code>setTitle</code> sets the window title of the created window.
88+ * @param title the title.
89+ */
90+ public void setTitle(String title) {
91+ Window.setTitle(title);
92+ }
93+
94+ /**
95+ * <code>createWindow</code> will create a LWJGL display context. This
96+ * window will be a purely native context as defined by the LWJGL API.
97+ *
98+ * @see com.jme.system.DisplaySystem#createWindow(int, int, int, int, boolean)
99+ */
100+ public void createWindow(int w, int h, int bpp, int frq, boolean fs) {
101+ //confirm that the parameters are valid.
102+ if (w <= 0 || h <= 0) {
103+ throw new JmeException("Invalid resolution values: " + w + " " + h);
104+ } else if ((bpp != 32) && (bpp != 16) && (bpp != 24)) {
105+ throw new JmeException("Invalid pixel depth: " + bpp);
106+ }
107+
108+ //set the window attributes
109+ this.width = w;
110+ this.height = h;
111+ this.bpp = bpp;
112+ this.frq = frq;
113+ this.fs = fs;
114+
115+ initDisplay();
116+ renderer = new LWJGLRenderer(width, height);
117+
118+ created = true;
119+ }
120+
121+ /**
122+ * <code>getRenderer</code> returns the created rendering class for
123+ * LWJGL (<code>LWJGLRenderer</code>). This will give the needed access to
124+ * display data to the window.
125+ * @see com.jme.system.DisplaySystem#getRenderer()
126+ */
127+ public Renderer getRenderer() {
128+ return renderer;
129+ }
130+
131+ /**
132+ * <code>isCreated</code> returns true if the current display is created,
133+ * false otherwise.
134+ * @see com.jme.system.DisplaySystem#isCreated()
135+ * @return true if display is created.
136+ */
137+ public boolean isCreated() {
138+ return created;
139+ }
140+
141+ /**
142+ * <code>isClosing</code> returns any close requests. True if any exist,
143+ * false otherwise.
144+ * @see com.jme.system.DisplaySystem#isClosing()
145+ * @return true if a close request is active.
146+ */
147+ public boolean isClosing() {
148+ return Window.isCloseRequested();
149+ }
150+
151+ /**
152+ * <code>reset</code> prepares the window for closing or restarting.
153+ * @see com.jme.system.DisplaySystem#reset()
154+ */
155+ public void reset() {
156+ Display.resetDisplayMode();
157+ }
158+
159+ /**
160+ * <code>getValidDisplayMode</code> returns a <code>DisplayMode</code> object
161+ * that has the requested width, height and color depth. If there is no
162+ * mode that supports a requested resolution, null is returned.
163+ *
164+ * @param width the width of the desired mode.
165+ * @param height the height of the desired mode.
166+ * @param bpp the color depth of the desired mode.
167+ * @param freq the frequency of the monitor.
168+ * @return <code>DisplayMode</code> object that supports the requested
169+ * resolutions. Null is returned if no valid modes are found.
170+ */
171+ private DisplayMode getValidDisplayMode(int width, int height, int bpp, int freq) {
172+ //get all the modes, and find one that matches our width, height, bpp.
173+ DisplayMode[] modes = Display.getAvailableDisplayModes();
174+ //Make sure that we find the mode that uses our current monitor freq.
175+
176+ for (int i = 0; i < modes.length; i++) {
177+ if (modes[i].width == width && modes[i].height == height && modes[i].bpp == bpp && modes[i].freq == freq) {
178+
179+ return modes[i];
180+ }
181+ }
182+
183+ //none found
184+ return null;
185+ }
186+
187+ /**
188+ * <code>initDisplay</code> creates the LWJGL window with the desired
189+ * specifications.
190+ *
191+ */
192+ private void initDisplay() {
193+ //create the Display.
194+ DisplayMode mode = getValidDisplayMode(width, height, bpp, frq);
195+ if (null == mode) {
196+ throw new JmeException("Bad display mode");
197+ }
198+
199+ try {
200+ if (fs) {
201+ Display.setDisplayMode(mode);
202+ Window.create(title, bpp, 0, 8, 0);
203+ } else {
204+ int x, y;
205+ x = (Toolkit.getDefaultToolkit().getScreenSize().width - width) / 2;
206+ y = (Toolkit.getDefaultToolkit().getScreenSize().height - height) / 2;
207+ Window.create(title, x, y, width, height, bpp, 0, 8, 0);
208+ }
209+
210+ } catch (Exception e) {
211+ //System.exit(1);
212+ throw new Error("Cannot create window");
213+ }
214+ }
215+
216+ /* (non-Javadoc)
217+ * @see com.jme.system.DisplaySystem#getFont(java.lang.String)
218+ */
219+ public WidgetFont getFont(String fontName) {
220+ WidgetFont f = new WidgetLWJGLFont("Default");
221+ return f;
222+ }
226223 }
--- a/src/com/jme/system/PropertiesDialog.java
+++ b/src/com/jme/system/PropertiesDialog.java
@@ -46,6 +46,7 @@ import javax.swing.JCheckBox;
4646 import javax.swing.JComboBox;
4747 import javax.swing.JDialog;
4848 import javax.swing.JLabel;
49+import javax.swing.JOptionPane;
4950 import javax.swing.JPanel;
5051 import javax.swing.UIManager;
5152
@@ -59,228 +60,246 @@ import com.jme.util.LoggingSystem;
5960 *
6061 * @see com.jme.system.PropertiesIO
6162 * @author Mark Powell
62- * @version $Id: PropertiesDialog.java,v 1.4 2003-12-01 13:18:58 mojomonkey Exp $
63+ * @version $Id: PropertiesDialog.java,v 1.5 2004-01-25 02:14:38 mojomonkey Exp $
6364 */
6465 public class PropertiesDialog extends JDialog {
6566
66- //connection to properties file.
67- private PropertiesIO source = null;
68-
69- //Title Image
70- String imageFile = null;
71-
72- //UI components
73- private JCheckBox fullscreenBox = null;
74- private JComboBox displayResCombo = null;
75- private JComboBox displayFreqCombo = null;
76- private JComboBox rendererCombo = null;
77-
78- //flag to denote if the dialog has finished being used.
79- private boolean done = false;
80-
81- /**
82- * Constructor builds the interface for the <code>PropertiesDialog</code>.
83- *
84- * @param source the <code>PropertiesIO</code> object to use for working
85- * with the properties file.
86- * @param imageFile the file to use as the title of the dialog. Null will
87- * result in now picture being used.
88- *
89- * @throws MonkeyRuntimeException if the source is null.
90- */
91- public PropertiesDialog(PropertiesIO source, String imageFile) {
92- try {
93- UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
94- } catch (Exception e) {
95- LoggingSystem.getLogger().log(Level.WARNING, "Could not set" + " native look and feel.");
96- }
97-
98- if (null == source) {
99- throw new JmeException("PropertyIO source cannot be null");
100- }
101-
102- this.source = source;
103- this.imageFile = imageFile;
104-
105- this.addWindowListener(new WindowAdapter() {
106- public void windowClosing(WindowEvent e) {
107- dispose();
108- System.exit(0);
109- }
110- });
111-
112- init();
113- }
114-
115- /**
116- * <code>isDone</code> returns the status of the dialog. If true, the
117- * application has either been used to change/set the properties file, or
118- * has been closed.
119- *
120- * @return true if the dialog is closed, false if it is still up.
121- */
122- public boolean isDone() {
123- return done;
124- }
125-
126- /**
127- *
128- * <code>setImage</code> sets the background image of the dialog.
129- * @param image the image file.
130- */
131- public void setImage(String image) {
132- imageFile = image;
133- }
134-
135- /**
136- * <code>init</code> creates the components to use the dialog.
137- *
138- */
139- private void init() {
140- this.setTitle("Select Display Settings");
141-
142- //The panels...
143- JPanel mainPanel = new JPanel();
144- JPanel centerPanel = new JPanel();
145- JPanel optionsPanel = new JPanel();
146- JPanel buttonPanel = new JPanel();
147-
148- //The buttons...
149- JButton ok = new JButton("Ok");
150- JButton cancel = new JButton("Cancel");
151-
152- mainPanel.setLayout(new BorderLayout());
153- centerPanel.setLayout(new BorderLayout());
154-
155- centerPanel.add(
156- new JLabel(new ImageIcon(imageFile)),
157- BorderLayout.NORTH);
158-
159- displayResCombo = setUpResolutionChooser();
160- displayFreqCombo = setUpFreqChooser();
161- optionsPanel.add(displayResCombo);
162- optionsPanel.add(displayFreqCombo);
163-
164- fullscreenBox = new JCheckBox("Fullscreen?");
165- fullscreenBox.setSelected(source.getFullscreen());
166- rendererCombo = setUpRendererChooser();
167- optionsPanel.add(fullscreenBox);
168- optionsPanel.add(rendererCombo);
169-
170- centerPanel.add(optionsPanel, BorderLayout.SOUTH);
171-
172- //Set the button action listeners. Cancel disposes without saving,
173- //ok saves.
174- ok.addActionListener(new ActionListener() {
175- public void actionPerformed(ActionEvent e) {
176- saveCurrentSelection();
177- dispose();
178- done = true;
179- }
180- });
181-
182- cancel.addActionListener(new ActionListener() {
183- public void actionPerformed(ActionEvent e) {
184- dispose();
185- System.exit(0);
186- }
187- });
188-
189- buttonPanel.add(ok);
190- buttonPanel.add(cancel);
191-
192- mainPanel.add(centerPanel, BorderLayout.CENTER);
193- mainPanel.add(buttonPanel, BorderLayout.SOUTH);
194-
195- this.getContentPane().add(mainPanel);
196-
197- pack();
198-
199- int x, y;
200- x =
201- (Toolkit.getDefaultToolkit().getScreenSize().width
202- - this.getWidth())
203- / 2;
204- y =
205- (Toolkit.getDefaultToolkit().getScreenSize().height
206- - this.getHeight())
207- / 2;
208- this.setLocation(x, y);
209-
210- show();
211- toFront();
212- }
213-
214- /**
215- * <code>saveCurrentSelection</code> saves the current selection as a
216- * properties.cfg file.
217- *
218- */
219- private void saveCurrentSelection() {
220- String display = (String) displayResCombo.getSelectedItem();
221- int width =
222- Integer.parseInt(display.substring(0, display.indexOf("x")));
223- display = display.substring(display.indexOf("x") + 1);
224- int height =
225- Integer.parseInt(display.substring(0, display.indexOf("x")));
226- display = display.substring(display.indexOf("x") + 1);
227- int depth =
228- Integer.parseInt(display.substring(0));
229- String freqString = (String) displayFreqCombo.getSelectedItem();
230- int freq =
231- Integer.parseInt(freqString.substring(0, freqString.indexOf(" ")));
232- boolean fullscreen = fullscreenBox.isSelected();
233- String renderer = (String)rendererCombo.getSelectedItem();
234-
235- //use the propertiesio class to save it.
236- source.save(width, height, depth, freq, fullscreen, renderer);
237- }
238-
239- /**
240- * <code>setUpChooser</code> retrieves all available display modes and
241- * places them in a <code>JComboBox</code>.
242- *
243- * @return the combo box of display modes.
244- */
245- private JComboBox setUpResolutionChooser() {
246- String[] modes =
247- { "640x480x16", "800x600x16", "1024x768x16", "1280x1024x16", "1600x1200x16",
248- "640x480x32", "800x600x32", "1024x768x32", "1280x1024x32", "1600x1200x32" };
249- JComboBox resolutionBox = new JComboBox(modes);
250-
251- resolutionBox.setSelectedItem(
252- source.getWidth()
253- + "x"
254- + source.getHeight()
255- + "x"
256- + source.getDepth());
257-
258- return resolutionBox;
259- }
260-
261- /**
262- *
263- * <code>setUpFreqChooser</code> sets available display frequencys.
264- * @return the combo box that contains the display frequencys.
265- */
266- private JComboBox setUpFreqChooser() {
267- String modes[] = {"0 Hz (Linux)", "60 Hz", "70 Hz", "75 Hz", "80 Hz" };
268- JComboBox freqBox = new JComboBox(modes);
269- freqBox.setSelectedItem(source.getFreq() + " Hz");
270- return freqBox;
271- }
272-
273- /**
274- *
275- * <code>setUpRendererChooser</code> sets the list of available
276- * renderers. This is obtained from the <code>DisplaySystem</code>
277- * class.
278- * @return the list of renderers.
279- */
280- private JComboBox setUpRendererChooser() {
281- String modes[] = DisplaySystem.rendererNames;
282- JComboBox nameBox = new JComboBox(modes);
283- nameBox.setSelectedItem(source.getRenderer());
284- return nameBox;
285- }
67+ //connection to properties file.
68+ private PropertiesIO source = null;
69+
70+ //Title Image
71+ String imageFile = null;
72+
73+ //UI components
74+ private JCheckBox fullscreenBox = null;
75+ private JComboBox displayResCombo = null;
76+ private JComboBox colorDepthCombo = null;
77+ private JComboBox displayFreqCombo = null;
78+ private JComboBox rendererCombo = null;
79+
80+ //flag to denote if the dialog has finished being used.
81+ private boolean done = false;
82+
83+ /**
84+ * Constructor builds the interface for the <code>PropertiesDialog</code>.
85+ *
86+ * @param source the <code>PropertiesIO</code> object to use for working
87+ * with the properties file.
88+ * @param imageFile the file to use as the title of the dialog. Null will
89+ * result in now picture being used.
90+ *
91+ * @throws MonkeyRuntimeException if the source is null.
92+ */
93+ public PropertiesDialog(PropertiesIO source, String imageFile) {
94+ try {
95+ UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
96+ } catch (Exception e) {
97+ LoggingSystem.getLogger().log(Level.WARNING, "Could not set" + " native look and feel.");
98+ }
99+
100+ if (null == source) {
101+ throw new JmeException("PropertyIO source cannot be null");
102+ }
103+
104+ this.source = source;
105+ this.imageFile = imageFile;
106+
107+ this.addWindowListener(new WindowAdapter() {
108+ public void windowClosing(WindowEvent e) {
109+ dispose();
110+ System.exit(0);
111+ }
112+ });
113+
114+ init();
115+ }
116+
117+ /**
118+ * <code>isDone</code> returns the status of the dialog. If true, the
119+ * application has either been used to change/set the properties file, or
120+ * has been closed.
121+ *
122+ * @return true if the dialog is closed, false if it is still up.
123+ */
124+ public boolean isDone() {
125+ return done;
126+ }
127+
128+ /**
129+ *
130+ * <code>setImage</code> sets the background image of the dialog.
131+ * @param image the image file.
132+ */
133+ public void setImage(String image) {
134+ imageFile = image;
135+ }
136+
137+ /**
138+ * <code>init</code> creates the components to use the dialog.
139+ *
140+ */
141+ private void init() {
142+ this.setTitle("Select Display Settings");
143+
144+ //The panels...
145+ JPanel mainPanel = new JPanel();
146+ JPanel centerPanel = new JPanel();
147+ JPanel optionsPanel = new JPanel();
148+ JPanel buttonPanel = new JPanel();
149+
150+ //The buttons...
151+ JButton ok = new JButton("Ok");
152+ JButton cancel = new JButton("Cancel");
153+
154+ mainPanel.setLayout(new BorderLayout());
155+ centerPanel.setLayout(new BorderLayout());
156+
157+ centerPanel.add(new JLabel(new ImageIcon(imageFile)), BorderLayout.NORTH);
158+
159+ displayResCombo = setUpResolutionChooser();
160+ colorDepthCombo = setUpColorDepthChooser();
161+ displayFreqCombo = setUpFreqChooser();
162+ optionsPanel.add(displayResCombo);
163+ optionsPanel.add(colorDepthCombo);
164+ optionsPanel.add(displayFreqCombo);
165+
166+ fullscreenBox = new JCheckBox("Fullscreen?");
167+ fullscreenBox.setSelected(source.getFullscreen());
168+ rendererCombo = setUpRendererChooser();
169+ optionsPanel.add(fullscreenBox);
170+ optionsPanel.add(rendererCombo);
171+
172+ centerPanel.add(optionsPanel, BorderLayout.SOUTH);
173+
174+ //Set the button action listeners. Cancel disposes without saving,
175+ //ok saves.
176+ ok.addActionListener(new ActionListener() {
177+ public void actionPerformed(ActionEvent e) {
178+ if (verifyAndSaveCurrentSelection()) {
179+ dispose();
180+ done = true;
181+ }
182+ }
183+ });
184+
185+ cancel.addActionListener(new ActionListener() {
186+ public void actionPerformed(ActionEvent e) {
187+ dispose();
188+ System.exit(0);
189+ }
190+ });
191+
192+ buttonPanel.add(ok);
193+ buttonPanel.add(cancel);
194+
195+ mainPanel.add(centerPanel, BorderLayout.CENTER);
196+ mainPanel.add(buttonPanel, BorderLayout.SOUTH);
197+
198+ this.getContentPane().add(mainPanel);
199+
200+ pack();
201+
202+ int x, y;
203+ x = (Toolkit.getDefaultToolkit().getScreenSize().width - this.getWidth()) / 2;
204+ y = (Toolkit.getDefaultToolkit().getScreenSize().height - this.getHeight()) / 2;
205+ this.setLocation(x, y);
206+
207+ show();
208+ toFront();
209+ }
210+
211+ /**
212+ * <code>verifyAndSaveCurrentSelection</code> first verifies that
213+ * the display mode is valid for this system, and then saves the
214+ * current selection as a properties.cfg file.
215+ * @return if the selection is valid
216+ */
217+ private boolean verifyAndSaveCurrentSelection() {
218+ String display = (String)displayResCombo.getSelectedItem();
219+
220+ int width = Integer.parseInt(display.substring(0, display.indexOf("x")));
221+ display = display.substring(display.indexOf("x") + 1);
222+
223+ int height = Integer.parseInt(display);
224+
225+ String depthString = (String)colorDepthCombo.getSelectedItem();
226+ int depth = Integer.parseInt(depthString.substring(0, depthString.indexOf(" ")));
227+
228+ String freqString = (String)displayFreqCombo.getSelectedItem();
229+ int freq = Integer.parseInt(freqString.substring(0, freqString.indexOf(" ")));
230+
231+ boolean fullscreen = fullscreenBox.isSelected();
232+ String renderer = (String)rendererCombo.getSelectedItem();
233+
234+ //test valid display mode
235+ DisplaySystem disp = DisplaySystem.getDisplaySystem(renderer);
236+ boolean valid = (disp != null) ? disp.isValidDisplayMode(width, height, depth, freq) : false;
237+
238+ if (valid) {
239+ //use the propertiesio class to save it.
240+ source.save(width, height, depth, freq, fullscreen, renderer);
241+
242+ } else {
243+ JOptionPane.showMessageDialog(
244+ this,
245+ "The selected display mode is not valid!",
246+ "Invalid Mode",
247+ JOptionPane.ERROR_MESSAGE);
248+ }
249+
250+ return valid;
251+ }
252+
253+ /**
254+ * <code>setUpChooser</code> retrieves all available display modes and
255+ * places them in a <code>JComboBox</code>.
256+ *
257+ * @return the combo box of display modes.
258+ */
259+ private JComboBox setUpResolutionChooser() {
260+ String[] modes = { "640x480", "800x600", "1024x768", "1280x1024", "1600x1200" };
261+ JComboBox resolutionBox = new JComboBox(modes);
262+
263+ resolutionBox.setSelectedItem(source.getWidth() + "x" + source.getHeight());
264+
265+ return resolutionBox;
266+ }
267+
268+ /**
269+ * @return a combo box of possible bit depths
270+ */
271+ private JComboBox setUpColorDepthChooser() {
272+ String[] depths = { "16 bpp", "24 bpp", "32 bpp" };
273+ JComboBox depthBox = new JComboBox(depths);
274+
275+ depthBox.setSelectedItem(String.valueOf(source.getDepth()) + " bpp");
276+
277+ return depthBox;
278+ }
279+
280+ /**
281+ *
282+ * <code>setUpFreqChooser</code> sets available display frequencys.
283+ * @return the combo box that contains the display frequencys.
284+ */
285+ private JComboBox setUpFreqChooser() {
286+ String modes[] = { "0 Hz (Linux)", "60 Hz", "70 Hz", "75 Hz", "80 Hz", "85 Hz" };
287+ JComboBox freqBox = new JComboBox(modes);
288+ freqBox.setSelectedItem(source.getFreq() + " Hz");
289+ return freqBox;
290+ }
291+
292+ /**
293+ *
294+ * <code>setUpRendererChooser</code> sets the list of available
295+ * renderers. This is obtained from the <code>DisplaySystem</code>
296+ * class.
297+ * @return the list of renderers.
298+ */
299+ private JComboBox setUpRendererChooser() {
300+ String modes[] = DisplaySystem.rendererNames;
301+ JComboBox nameBox = new JComboBox(modes);
302+ nameBox.setSelectedItem(source.getRenderer());
303+ return nameBox;
304+ }
286305 }