Source Code Cross Referenced for Settings.java in  » J2EE » jag » com » finalist » jaggenerator » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » jag » com.finalist.jaggenerator 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*   Copyright (C) 2003 Finalist IT Group
002:         *
003:         *   This file is part of JAG - the Java J2EE Application Generator
004:         *
005:         *   JAG is free software; you can redistribute it and/or modify
006:         *   it under the terms of the GNU General Public License as published by
007:         *   the Free Software Foundation; either version 2 of the License, or
008:         *   (at your option) any later version.
009:         *   JAG is distributed in the hope that it will be useful,
010:         *   but WITHOUT ANY WARRANTY; without even the implied warranty of
011:         *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012:         *   GNU General Public License for more details.
013:         *   You should have received a copy of the GNU General Public License
014:         *   along with JAG; if not, write to the Free Software
015:         *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
016:         */
017:        package com.finalist.jaggenerator;
018:
019:        import javax.swing.*;
020:        import java.util.prefs.Preferences;
021:        import java.awt.*;
022:
023:        /**
024:         * The Settings class handles the loading and saving of user-settings like the current Window-size,
025:         * divider-locations, etc.
026:         *
027:         * @author Onno Scheffers
028:         */
029:        public class Settings {
030:            // Retrieve current user's JAG-preferences
031:            private static final Preferences PREFS = Preferences
032:                    .userNodeForPackage(JagGenerator.class);
033:
034:            private static final String KEY_LAST_SELECTED_OUTPUT_DIR = "last_outputdir";
035:
036:            // Store Divider positions
037:            private static final String KEY_VERTICAL_DIVIDER_POSITION = "vdiv";
038:            private static final int DEFAULT_VERTICAL_DIVIDER_POSITION = 400;
039:            private static final String KEY_HORIZONTAL_DIVIDER_POSITION = "hdiv";
040:            private static final int DEFAULT_HORIZONTAL_DIVIDER_POSITION = 444;
041:            // Store Window-position and size
042:            private static final String KEY_WINDOW_X = "winx";
043:            private static final int DEFAULT_WINDOW_X = Integer.MIN_VALUE;
044:            private static final String KEY_WINDOW_Y = "winy";
045:            private static final int DEFAULT_WINDOW_Y = Integer.MIN_VALUE;
046:            private static final String KEY_WINDOW_WIDTH = "winwidth";
047:            private static final int DEFAULT_WINDOW_WIDTH = 1000;
048:            private static final String KEY_WINDOW_HEIGHT = "winheight";
049:            private static final int DEFAULT_WINDOW_HEIGHT = 760;
050:            // Store window-maximized state
051:            private static final String KEY_MAXIMIZED = "winmaximized";
052:            private static final boolean DEFAULT_MAXIMIZED = false;
053:            // static properties holding the values to read and/or store
054:            private static int verticalDividerPosition;
055:            private static int horizontalDividerPosition;
056:            private static int windowX;
057:            private static int windowY;
058:            private static int windowWidth;
059:            private static int windowHeight;
060:            private static boolean isMaximized;
061:
062:            public static String getLastSelectedOutputDir() {
063:                return lastSelectedOutputDir;
064:            }
065:
066:            public static void setLastSelectedOutputDir(
067:                    String lastSelectedOutputDir) {
068:                Settings.lastSelectedOutputDir = lastSelectedOutputDir;
069:            }
070:
071:            private static String lastSelectedOutputDir;
072:
073:            /**
074:             * Static method for reading the user-settings
075:             */
076:            public static void read() {
077:                Settings.verticalDividerPosition = PREFS.getInt(
078:                        KEY_VERTICAL_DIVIDER_POSITION,
079:                        DEFAULT_VERTICAL_DIVIDER_POSITION);
080:                Settings.horizontalDividerPosition = PREFS.getInt(
081:                        KEY_HORIZONTAL_DIVIDER_POSITION,
082:                        DEFAULT_HORIZONTAL_DIVIDER_POSITION);
083:                Settings.windowX = PREFS.getInt(KEY_WINDOW_X, DEFAULT_WINDOW_X);
084:                Settings.windowY = PREFS.getInt(KEY_WINDOW_Y, DEFAULT_WINDOW_Y);
085:                Settings.windowWidth = PREFS.getInt(KEY_WINDOW_WIDTH,
086:                        DEFAULT_WINDOW_WIDTH);
087:                Settings.windowHeight = PREFS.getInt(KEY_WINDOW_HEIGHT,
088:                        DEFAULT_WINDOW_HEIGHT);
089:                Settings.isMaximized = PREFS.getBoolean(KEY_MAXIMIZED,
090:                        DEFAULT_MAXIMIZED);
091:                Settings.lastSelectedOutputDir = PREFS.get(
092:                        KEY_LAST_SELECTED_OUTPUT_DIR, ".");
093:            }
094:
095:            /**
096:             * Static method for writing the user-settings.
097:             */
098:            public static void write() {
099:                PREFS.putInt(KEY_VERTICAL_DIVIDER_POSITION,
100:                        verticalDividerPosition);
101:                PREFS.putInt(KEY_HORIZONTAL_DIVIDER_POSITION,
102:                        horizontalDividerPosition);
103:                PREFS.putInt(KEY_WINDOW_X, windowX);
104:                PREFS.putInt(KEY_WINDOW_Y, windowY);
105:                PREFS.putInt(KEY_WINDOW_WIDTH, windowWidth);
106:                PREFS.putInt(KEY_WINDOW_HEIGHT, windowHeight);
107:                PREFS.putBoolean(KEY_MAXIMIZED, isMaximized);
108:                PREFS.put(KEY_LAST_SELECTED_OUTPUT_DIR, lastSelectedOutputDir);
109:            }
110:
111:            /**
112:             * Returns the last-known vertical divider position.
113:             *
114:             * @return the last-known vertical divider position.
115:             */
116:            public static int getVerticalDividerPosition() {
117:                return verticalDividerPosition;
118:            }
119:
120:            /**
121:             * Sets a new value for the vertical divider position that will be stored
122:             * the next time you call <code>write()</code>.
123:             *
124:             * @param verticalDividerPosition The value to store for the vertical divider position.
125:             */
126:            public static void setVerticalDividerPosition(
127:                    int verticalDividerPosition) {
128:                Settings.verticalDividerPosition = verticalDividerPosition;
129:            }
130:
131:            /**
132:             * Returns the last-known horizontal divider position.
133:             *
134:             * @return the last-known horizontal divider position.
135:             */
136:            public static int getHorizontalDividerPosition() {
137:                return horizontalDividerPosition;
138:            }
139:
140:            /**
141:             * Sets a new value for the horizontal divider position that will be stored
142:             * the next time you call <code>write()</code>.
143:             *
144:             * @param horizontalDividerPosition The value to store for the horizontal divider position.
145:             */
146:            public static void setHorizontalDividerPosition(
147:                    int horizontalDividerPosition) {
148:                Settings.horizontalDividerPosition = horizontalDividerPosition;
149:            }
150:
151:            /**
152:             * Returns the last-known maximized state.
153:             *
154:             * @return the last-known maximized state.
155:             */
156:            public static boolean isMaximized() {
157:                return isMaximized;
158:            }
159:
160:            /**
161:             * Sets a new value for the maximized state that will be stored
162:             * the next time you call <code>write()</code>.
163:             *
164:             * @param maximized The value to store for the maximized state.
165:             */
166:            public static void setMaximized(boolean maximized) {
167:                isMaximized = maximized;
168:            }
169:
170:            /**
171:             * Returns the last-known window bounds.
172:             *
173:             * @return the last-known window bounds.
174:             */
175:            public static Rectangle getUserWindowBounds(JFrame frame) {
176:                if (windowX == Integer.MIN_VALUE
177:                        || windowY == Integer.MIN_VALUE) {
178:                    // Center the current window
179:                    Dimension screenSize = frame.getToolkit().getScreenSize();
180:                    windowX = (int) (screenSize.getWidth() / 2 - windowWidth / 2);
181:                    windowY = (int) (screenSize.getHeight() / 2 - windowHeight / 2);
182:                }
183:                return new Rectangle(windowX, windowY, windowWidth,
184:                        windowHeight);
185:            }
186:
187:            /**
188:             * Sets a new value for the window bounds that will be stored
189:             * the next time you call <code>write()</code>.
190:             *
191:             * @param bounds The value to store for the window bounds.
192:             */
193:            public static void setUserWindowBounds(Rectangle bounds) {
194:                windowX = (int) bounds.getX();
195:                windowY = (int) bounds.getY();
196:                windowWidth = (int) bounds.getWidth();
197:                windowHeight = (int) bounds.getHeight();
198:            }
199:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.