1 22 23 package salsa.util; 24 25 import java.awt.*; 26 import java.util.prefs.*; 27 import houston.*; 28 29 public class FrameUtils 30 { 31 static Logger T = Logger.getLogger( FrameUtils.class ); 32 33 public static void restoreBounds( Frame f, int defaultX, int defaultY, int defaultWidth, int defaultHeight, int defaultState ) 34 { 35 Preferences prefs = Preferences.userNodeForPackage( f.getClass() ); 36 37 int x = prefs.getInt( "x", defaultX ); 38 int y = prefs.getInt( "y", defaultY ); 39 int width = prefs.getInt( "width", defaultWidth ); 40 int height = prefs.getInt( "height", defaultHeight ); 41 int state = prefs.getInt( "state", defaultState ); 42 43 f.setLocation( x, y ); 44 f.setSize( width, height ); 45 f.setExtendedState( state ); 46 } 47 48 52 public static void restoreBounds( Frame f ) 53 { 54 Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); 55 56 int defaultWidth = ( int ) ( screen.width * 0.66 ); 58 int defaultHeight = ( int ) ( screen.height * 0.66 ); 59 60 int defaultX = ( screen.width - defaultWidth ) / 2; 62 int defaultY = ( screen.height - defaultHeight ) / 2; 63 64 restoreBounds( f, defaultX, defaultY, defaultWidth, defaultHeight, Frame.NORMAL ); 65 } 66 67 public static void saveBounds( Frame f ) 68 { 69 74 T.debug( "frame=" + f.getClass().getName() ); 75 76 int state = f.getExtendedState(); 77 if( ( state & Frame.ICONIFIED ) == Frame.ICONIFIED ) 78 { 79 T.debug( "frame is iconified" ); 80 } 81 else if( ( state & Frame.MAXIMIZED_BOTH ) == Frame.MAXIMIZED_BOTH ) 82 { 83 T.debug( "frame is maximized" ); 84 } 85 else 86 { 87 89 T.debug( "frame is normal" ); 90 } 91 92 Rectangle rect = f.getBounds(); 93 T.debug( "x,y,width,height=" + rect.x + "," + rect.y + "," + rect.width + "," + rect.height ); 94 95 Preferences prefs = Preferences.userNodeForPackage( f.getClass() ); 96 97 prefs.putInt( "x", rect.x ); 100 prefs.putInt( "y", rect.y ); 101 prefs.putInt( "width", rect.width ); 102 prefs.putInt( "height", rect.height ); 103 prefs.putInt( "state", state ); 104 } 105 } 106 | Popular Tags |