]> git.gag.com Git - debian/openrocket/blobdiff - src/net/sf/openrocket/gui/util/GUIUtil.java
introduction tour
[debian/openrocket] / src / net / sf / openrocket / gui / util / GUIUtil.java
index 34258d5874f295a0c88b2207dc13a47023230ebf..4ee74ba4e83edfc75245c9020ecaf00e26d9ba84 100644 (file)
@@ -7,6 +7,7 @@ import java.awt.Font;
 import java.awt.Image;
 import java.awt.KeyboardFocusManager;
 import java.awt.Point;
+import java.awt.Toolkit;
 import java.awt.Window;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
@@ -76,7 +77,6 @@ import net.sf.openrocket.startup.Application;
 import net.sf.openrocket.util.BugException;
 import net.sf.openrocket.util.Invalidatable;
 import net.sf.openrocket.util.MemoryManagement;
-import net.sf.openrocket.util.Prefs;
 
 public class GUIUtil {
        private static final LogHelper log = Application.getLogger();
@@ -108,8 +108,27 @@ public class GUIUtil {
                }
        }
        
+       /**
+        * Return the DPI setting of the monitor.  This is either the setting provided
+        * by the system or a user-specified DPI setting.
+        * 
+        * @return    the DPI setting to use.
+        */
+       public static double getDPI() {
+               int dpi = Application.getPreferences().getInt("DPI", 0); // Tenths of a dpi
+               
+               if (dpi < 10) {
+                       dpi = Toolkit.getDefaultToolkit().getScreenResolution() * 10;
+               }
+               if (dpi < 10)
+                       dpi = 960;
+               
+               return (dpi) / 10.0;
+       }
+       
+       
+       
        
-
        /**
         * Set suitable options for a single-use disposable dialog.  This includes
         * setting ESC to close the dialog, adding the appropriate window icons and
@@ -134,7 +153,7 @@ public class GUIUtil {
        }
        
        
-
+       
        /**
         * Add the correct action to close a JDialog when the ESC key is pressed.
         * The dialog is closed by sending is a WINDOW_CLOSING event.
@@ -173,7 +192,7 @@ public class GUIUtil {
        }
        
        
-
+       
        /**
         * Change the behavior of a component so that TAB and Shift-TAB cycles the focus of
         * the components.  This is necessary for e.g. <code>JTextArea</code>.
@@ -188,7 +207,7 @@ public class GUIUtil {
        }
        
        
-
+       
        /**
         * Set the OpenRocket icons to the window icons.
         * 
@@ -217,7 +236,7 @@ public class GUIUtil {
        }
        
        
-
+       
        /**
         * Set the best available look-and-feel into use.
         */
@@ -275,7 +294,7 @@ public class GUIUtil {
        }
        
        
-
+       
        /**
         * Automatically remember the size of a window.  This stores the window size in the user
         * preferences when resizing/maximizing the window and sets the state on the first call.
@@ -285,22 +304,22 @@ public class GUIUtil {
                        @Override
                        public void componentResized(ComponentEvent e) {
                                log.debug("Storing size of " + window.getClass().getName() + ": " + window.getSize());
-                               Prefs.setWindowSize(window.getClass(), window.getSize());
+                               ((SwingPreferences) Application.getPreferences()).setWindowSize(window.getClass(), window.getSize());
                                if (window instanceof JFrame) {
                                        if ((((JFrame) window).getExtendedState() & JFrame.MAXIMIZED_BOTH) == JFrame.MAXIMIZED_BOTH) {
                                                log.debug("Storing maximized state of " + window.getClass().getName());
-                                               Prefs.setWindowMaximized(window.getClass());
+                                               ((SwingPreferences) Application.getPreferences()).setWindowMaximized(window.getClass());
                                        }
                                }
                        }
                });
                
-               if (Prefs.isWindowMaximized(window.getClass())) {
+               if (((SwingPreferences) Application.getPreferences()).isWindowMaximized(window.getClass())) {
                        if (window instanceof JFrame) {
                                ((JFrame) window).setExtendedState(JFrame.MAXIMIZED_BOTH);
                        }
                } else {
-                       Dimension dim = Prefs.getWindowSize(window.getClass());
+                       Dimension dim = ((SwingPreferences) Application.getPreferences()).getWindowSize(window.getClass());
                        if (dim != null) {
                                window.setSize(dim);
                        }
@@ -316,12 +335,12 @@ public class GUIUtil {
                window.addComponentListener(new ComponentAdapter() {
                        @Override
                        public void componentMoved(ComponentEvent e) {
-                               Prefs.setWindowPosition(window.getClass(), window.getLocation());
+                               ((SwingPreferences) Application.getPreferences()).setWindowPosition(window.getClass(), window.getLocation());
                        }
                });
                
                // Set window position according to preferences, and set prefs when moving
-               Point position = Prefs.getWindowPosition(window.getClass());
+               Point position = ((SwingPreferences) Application.getPreferences()).getWindowPosition(window.getClass());
                if (position != null) {
                        window.setLocationByPlatform(false);
                        window.setLocation(position);
@@ -358,7 +377,7 @@ public class GUIUtil {
        }
        
        
-
+       
        /**
         * Traverses recursively the component tree, and sets all applicable component 
         * models to null, so as to remove the listener connections.  After calling this
@@ -500,7 +519,7 @@ public class GUIUtil {
        }
        
        
-
+       
        /**
         * A mouse listener that toggles the state of a boolean value in a table model
         * when clicked on another column of the table.