Source Code Cross Referenced for UserPreferences.java in  » UML » MetaBoss » com » metaboss » applications » designstudio » 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 » UML » MetaBoss » com.metaboss.applications.designstudio 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
002:        // CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
003:        // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
004:        // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
005:        // OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
006:        // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
007:        // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
008:        // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
009:        // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
010:        // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
011:        // EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
012:        // POSSIBILITY OF SUCH DAMAGE.
013:        //
014:        // Copyright 2000-2005 © Softaris Pty.Ltd. All Rights Reserved.
015:        package com.metaboss.applications.designstudio;
016:
017:        import java.io.File;
018:        import java.io.FileInputStream;
019:        import java.io.FileOutputStream;
020:        import java.util.Properties;
021:
022:        /**
023:         * @author Rost Vashevnik
024:         * @version 1.0
025:         */
026:
027:        public class UserPreferences {
028:            // null untill intialised for the particular application
029:            private static String cApplicationName = null;
030:            private static String cUserPreferencesFileName = null;
031:            private static Properties cUserPreferences = null;
032:            private static boolean cModified = false;
033:
034:            /** This method must be called first in order to initialise UserPreferences for a particular application
035:             *  usually done once very early in the main function */
036:            public static synchronized void initialise(String pApplicationName) {
037:                cUserPreferences = new Properties();
038:                cApplicationName = pApplicationName;
039:                cUserPreferencesFileName = System.getProperty("user.home")
040:                        + System.getProperty("file.separator") + "softaris"
041:                        + System.getProperty("file.separator")
042:                        + pApplicationName
043:                        + System.getProperty("file.separator")
044:                        + "userpreferences.prop";
045:                // Try to load initial properties if possible
046:                try {
047:                    File lPropFile = new File(cUserPreferencesFileName);
048:                    if (lPropFile.isFile() && lPropFile.exists()
049:                            && lPropFile.canRead())
050:                        cUserPreferences.load(new FileInputStream(lPropFile));
051:                    else {
052:                        // Check if directory exists and create one if necessary
053:                        File lUserPreferencesDirectory = new File(System
054:                                .getProperty("user.home")
055:                                + System.getProperty("file.separator")
056:                                + "softaris"
057:                                + System.getProperty("file.separator")
058:                                + pApplicationName);
059:                        if (!lUserPreferencesDirectory.exists())
060:                            lUserPreferencesDirectory.mkdirs();
061:                    }
062:                } catch (java.io.FileNotFoundException e) {
063:                    e.printStackTrace();
064:                } catch (java.io.IOException e) {
065:                    e.printStackTrace();
066:                }
067:            }
068:
069:            /** Must be called occasionally after modifications to save properties back into file */
070:            public static synchronized void save() {
071:                if (cUserPreferences == null)
072:                    throw new RuntimeException(
073:                            "UserPreferences singleton is not initialised");
074:                if (cModified) {
075:                    try {
076:                        cUserPreferences.store(new FileOutputStream(
077:                                cUserPreferencesFileName, false),
078:                                "User Prefrences for the " + cApplicationName
079:                                        + " application");
080:                        cModified = false;
081:                    } catch (java.io.FileNotFoundException e) {
082:                        e.printStackTrace();
083:                    } catch (java.io.IOException e) {
084:                        e.printStackTrace();
085:                    }
086:                }
087:            }
088:
089:            /** Retrieves specifeid user property or null if specified property has not been found */
090:            public static synchronized String getProperty(String pKey) {
091:                if (cUserPreferences == null)
092:                    throw new RuntimeException(
093:                            "UserPreferences singleton is not initialised");
094:                return cUserPreferences.getProperty(pKey);
095:            }
096:
097:            /** Retrieves specifeid user property or default value if specified property has not been found */
098:            public static synchronized String getProperty(String pKey,
099:                    String pDefaultValue) {
100:                if (cUserPreferences == null)
101:                    throw new RuntimeException(
102:                            "UserPreferences singleton is not initialised");
103:                return cUserPreferences.getProperty(pKey, pDefaultValue);
104:            }
105:
106:            /** Sets specified property to the specified value.
107:             *  @return previous value associated with the key or null if none given */
108:            public static synchronized String setProperty(String pKey,
109:                    String pValue) {
110:                if (cUserPreferences == null)
111:                    throw new RuntimeException(
112:                            "UserPreferences singleton is not initialised");
113:                String pOldValue = (String) cUserPreferences.setProperty(pKey,
114:                        pValue);
115:                // Maintain modified flag
116:                if ((pOldValue == null) || (!pOldValue.equals(pValue)))
117:                    cModified = true;
118:                return pOldValue;
119:            }
120:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.