001: /*
002: The contents of this file are subject to the Common Public Attribution License
003: Version 1.0 (the "License"); you may not use this file except in compliance with
004: the License. You may obtain a copy of the License at
005: http://www.projity.com/license . The License is based on the Mozilla Public
006: License Version 1.1 but Sections 14 and 15 have been added to cover use of
007: software over a computer network and provide for limited attribution for the
008: Original Developer. In addition, Exhibit A has been modified to be consistent
009: with Exhibit B.
010:
011: Software distributed under the License is distributed on an "AS IS" basis,
012: WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the
013: specific language governing rights and limitations under the License. The
014: Original Code is OpenProj. The Original Developer is the Initial Developer and
015: is Projity, Inc. All portions of the code written by Projity are Copyright (c)
016: 2006, 2007. All Rights Reserved. Contributors Projity, Inc.
017:
018: Alternatively, the contents of this file may be used under the terms of the
019: Projity End-User License Agreeement (the Projity License), in which case the
020: provisions of the Projity License are applicable instead of those above. If you
021: wish to allow use of your version of this file only under the terms of the
022: Projity License and not to allow others to use your version of this file under
023: the CPAL, indicate your decision by deleting the provisions above and replace
024: them with the notice and other provisions required by the Projity License. If
025: you do not delete the provisions above, a recipient may use your version of this
026: file under either the CPAL or the Projity License.
027:
028: [NOTE: The text of this license may differ slightly from the text of the notices
029: in Exhibits A and B of the license at http://www.projity.com/license. You should
030: use the latest text at http://www.projity.com/license for your modifications.
031: You may not remove this license text from the source files.]
032:
033: Attribution Information: Attribution Copyright Notice: Copyright � 2006, 2007
034: Projity, Inc. Attribution Phrase (not exceeding 10 words): Powered by OpenProj,
035: an open source solution from Projity. Attribution URL: http://www.projity.com
036: Graphic Image as provided in the Covered Code as file: openproj_logo.png with
037: alternatives listed on http://www.projity.com/logo
038:
039: Display of Attribution Information is required in Larger Works which are defined
040: in the CPAL as a work which combines Covered Code or portions thereof with code
041: not governed by the terms of the CPAL. However, in addition to the other notice
042: obligations, all copies of the Covered Code in Executable and Source Code form
043: distributed must, as a form of attribution of the original author, include on
044: each user interface screen the "OpenProj" logo visible to all users. The
045: OpenProj logo should be located horizontally aligned with the menu bar and left
046: justified on the top left of the screen adjacent to the File menu. The logo
047: must be at least 100 x 25 pixels. When users click on the "OpenProj" logo it
048: must direct them back to http://www.projity.com.
049: */
050: package com.projity.util;
051:
052: import java.util.HashMap;
053: import java.util.Locale;
054: import java.util.StringTokenizer;
055:
056: import com.projity.company.ApplicationUser;
057: import com.projity.contrib.ClassLoaderUtils;
058: import com.projity.session.SessionFactory;
059:
060: public class Environment {
061: private static boolean clientSide = false;
062: private static boolean standAlone = false;
063: private static boolean batchMode = false;
064: private static ApplicationUser user = null;
065: private static String partnerId = null;
066: private static String login = null;
067: private static boolean importing = false;
068: private static boolean newLook = false;
069: private static boolean newLaf = false;
070: private static boolean scripting = false;
071: private static boolean visible = true;
072: private static boolean applet = false;
073:
074: public static int LINUX = 1;
075: public static int MAC = 2;
076: private static int os = -1;
077:
078: public static final boolean isBatchMode() {
079: return batchMode;
080: }
081:
082: public static final void setBatchMode(boolean processingUndoRedo) {
083: Environment.batchMode = processingUndoRedo;
084: }
085:
086: public Environment() {
087: super ();
088: // TODO Auto-generated constructor stub
089: }
090:
091: public static String getLogin() {
092: if (login == null)
093: login = SessionFactory.getInstance().getLogin();
094: return login;
095: }
096:
097: public static final boolean isClientSide() {
098: return clientSide;
099: }
100:
101: public static final void setClientSide(boolean clientSide) {
102: Environment.clientSide = clientSide;
103: }
104:
105: public static float getJavaVersionNumber() {
106: String javaVersion = System
107: .getProperty("java.specification.version");
108: return Float.parseFloat(javaVersion);
109: }
110:
111: public static final boolean getStandAlone() {
112: return standAlone;
113: }
114:
115: public static final void setStandAlone(boolean standAlone) {
116: Environment.standAlone = standAlone;
117: }
118:
119: public static final ApplicationUser getUser() {
120: return user;
121: }
122:
123: public static final void setUser(ApplicationUser user) {
124: Environment.user = user;
125: }
126:
127: public static final boolean isAdministrator() {
128: return user.isAdministrator();
129: }
130:
131: public static final String getPartnerId() {
132: return partnerId;
133: }
134:
135: public static final void setPartnerId(String partnerId) {
136: Environment.partnerId = partnerId;
137: }
138:
139: public static final boolean isWindows() {
140: //false for some linux window managers
141: return true;//System.getProperty("os.name").toUpperCase().contains("WINDOWS");
142: }
143:
144: public static boolean isImporting() {
145: return importing;
146: }
147:
148: public static void setImporting(boolean importing) {
149: System.out.println("set importing " + importing);
150: Environment.importing = importing;
151: }
152:
153: public static boolean isNewLook() {
154: return newLook;
155: }
156:
157: public static void setNewLook(boolean newLook) {
158: Environment.newLook = newLook;
159:
160: Environment.newLaf = newLook
161: && Environment.getJavaVersionNumber() >= 1.5f
162: && Environment.getOs() != Environment.LINUX
163: && !Environment.isChinese();
164: }
165:
166: public static boolean isNewLaf() {
167: return newLaf;
168: }
169:
170: public static boolean isScripting() {
171: return scripting;
172: }
173:
174: public static void setScripting(boolean scripting) {
175: Environment.scripting = scripting;
176: }
177:
178: public static boolean isVisible() {
179: return visible;
180: }
181:
182: public static void setVisible(boolean visible) {
183: Environment.visible = visible;
184: }
185:
186: public static boolean isOpenProj() {
187: return getStandAlone();
188: }
189:
190: public static boolean isApplet() {
191: return applet;
192: }
193:
194: public static void setApplet(boolean applet) {
195: Environment.applet = applet;
196: }
197:
198: public static int getOs() {
199: if (os == -1) {
200: String osName = System.getProperty("os.name").toLowerCase();
201: if (osName.startsWith("linux"))
202: os = LINUX;
203: else if (osName.startsWith("mac os x"))
204: os = MAC;
205: else
206: os = 0;
207: }
208: return os;
209: }
210:
211: public static final int DEFAULT_FONT = 0;
212: public static final int GANTT_ANNOTATIONS_FONT = 1;
213: public static final int NETWORK_FONT = 2;
214:
215: private static HashMap<Integer, String> fonts = new HashMap<Integer, String>();
216: static {
217: fonts.put(GANTT_ANNOTATIONS_FONT, "TimesRoman BOLD 11");
218: fonts.put(NETWORK_FONT, "TimesRoman");
219: }
220:
221: public static String getFont(int type) {
222: String font = fonts.get(type);
223: return font == null ? fonts.get(DEFAULT_FONT) : font;
224: }
225:
226: public static void setFont(String font, int type) {
227: fonts.put(type, font);
228: }
229:
230: public static void resetFonts() {
231: fonts.clear();
232: }
233:
234: public static boolean isChinese() {
235: Locale locale = Locale.getDefault();
236: return locale.equals(Locale.SIMPLIFIED_CHINESE)
237: || locale.equals(Locale.TRADITIONAL_CHINESE);
238: }
239:
240: /**
241: * Compares this version with the specified version for order. Returns a
242: * negative integer, zero, or a positive integer as this version is less
243: * than, equal to, or greater than the specified version.
244: */
245: public static int compareJavaVersionTo(String version) {
246: return ClassLoaderUtils.compareJavaVersionTo(version);
247: }
248:
249: public static int compareJavaVersion(String version1,
250: String version2) {
251: return ClassLoaderUtils.compareJavaVersion(version1, version2);
252: }
253:
254: }
|