001: /*
002: * CONFIDENTIAL AND PROPRIETARY SOURCE CODE OF
003: * NETSCAPE COMMUNICATIONS CORPORATION
004: *
005: * Copyright (c) 1996 Netscape Communications Corporation.
006: * All Rights Reserved.
007: * Use of this Source Code is subject to the terms of the applicable
008: * license agreement from Netscape Communications Corporation.
009: */
010:
011: package applications;
012:
013: import java.applet.Applet;
014:
015: import netscape.application.Application;
016: import netscape.application.ExternalWindow;
017: import netscape.application.InternalWindow;
018: import netscape.application.Rect;
019: import netscape.application.Size;
020:
021: import soif.CSID;
022: import util.ReportError;
023:
024: /**
025: Lo, a header file.
026: *
027: */
028: public class Header {
029: /* ----------------------------------------------------------- */
030:
031: /**
032: * Compass version string.
033: * Minor needs to match ALFRED_VERMINOR in batman/compass.mak.
034: * Date is excluded if it is a final build.
035: */
036: public final static String PRODUCT_VERSION = "Sun ONE Compass Server";
037:
038: /**
039: * Version string.
040: */
041: public final static String VERSION = "Application Package";
042:
043: /**
044: * Long version string.
045: */
046: public final static String LONG_VERSION = VERSION;
047:
048: /**
049: * Prints the version string and, if the <b>dbgLvl</b> parameter
050: * includes the value <i>longVer</i>, also prints the long
051: * version of the version string.
052: */
053: public final static void printVersion(Applet a) {
054: String dbgString = a.getParameter("dbgLvl");
055:
056: if (dbgString != null) {
057: if (dbgString.indexOf("longVer") != -1) {
058: System.out.println(LONG_VERSION);
059: return;
060: }
061: }
062:
063: System.out.println(Header.VERSION);
064: }
065:
066: /* ----------------------------------------------------------- */
067:
068: /**
069: * Show the current version.
070: * @param s application name
071: * @param sys flag do System.out.println
072: * @param stat flag do showStatus()
073: */
074: public final static void showVersion(String s, boolean sys,
075: boolean stat) {
076: if (sys) {
077: System.out.println(s + " / " + PRODUCT_VERSION);
078: }
079:
080: if (stat) {
081: graphical.Header.showStatus(s + " / " + PRODUCT_VERSION);
082: }
083: }
084:
085: /**
086: * Get and parse a parameter which is expected to be an integer
087: * and pass back as an integer.
088: * If the parameter doesn't exist or is not an interger,
089: * pass back the proposed default.
090: * @param a application
091: * @param param the name of the parameter
092: * @param dflt default to pass back if necessary
093: */
094: public final static int getIntParam(Application a, String param,
095: int dflt) {
096: String s = a.parameterNamed(param);
097:
098: if (s == null) {
099: return dflt;
100: } else {
101: try {
102: return Integer.parseInt(s);
103: } catch (NumberFormatException e) {
104: return dflt;
105: }
106: }
107: }
108:
109: /**
110: * Build a CSID based on the codebase and expected application
111: * parameters host, port and name.
112: * @param app application
113: */
114: public final static CSID parameterCSIDMacro(Application app) {
115: CSID csid = new CSID(app.codeBase().toString(), app
116: .parameterNamed("host"), app.parameterNamed("port"),
117: app.parameterNamed("name"));
118:
119: if (csid.isValid() == false) {
120: ReportError.reportError(ReportError.ADMIN, "Header",
121: "parameterCSIDMacro", Messages.INVALIDCSID);
122: }
123:
124: return csid;
125: }
126:
127: /**
128: * Build a database CSID based on the codebase and expected application
129: * parameters dbhost, dbport and dbname.
130: * @param app application
131: */
132: public final static CSID parameterDBCSIDMacro(Application app) {
133: CSID csid = new CSID(app.codeBase().toString(), app
134: .parameterNamed("dbhost"),
135: app.parameterNamed("dbport"), app
136: .parameterNamed("dbname"));
137:
138: if (csid.isValid() == false) {
139: ReportError.reportError(ReportError.ADMIN, "Header",
140: "parameterDBCSIDMacro", Messages.INVALIDCSID);
141: }
142:
143: return csid;
144: }
145:
146: /**
147: * Macro for obtaining parameters and returning not found errors.
148: * @param app application
149: * @param param parameter
150: */
151: public final static String parameterMacro(Application app,
152: String param) {
153: String s = app.parameterNamed(param);
154:
155: if (s == null) {
156: ReportError.reportError(ReportError.ADMIN, "Header",
157: "parameterMacro", Messages.MISSINGPARAMETER + ": "
158: + param);
159: }
160:
161: return s;
162: }
163:
164: /**
165: * ExternalWindow standard sizing macro for InternalWindow.
166: */
167: public final static void EWSizer(ExternalWindow externalWindow) {
168: Size size = externalWindow.windowSizeForContentSize(
169: graphical.Header.WINDOWHGAP
170: + graphical.Header.IWINDWIDTH
171: + graphical.Header.WINDOWHGAP, externalWindow
172: .menuView().height()
173: + graphical.Header.WINDOWVGAP
174: + graphical.Header.IWINDHEIGHT
175: + graphical.Header.WINDOWVGAP);
176: externalWindow.sizeTo(size.width, size.height);
177: }
178:
179: /**
180: * ExternalWindow standard sizing macro for InternalWindow.
181: */
182: public final static void EWSizer(ExternalWindow externalWindow,
183: InternalWindow internalWindow) {
184: Size size = externalWindow.windowSizeForContentSize(
185: internalWindow.x() + internalWindow.width()
186: + graphical.Header.WINDOWHGAP, internalWindow
187: .y()
188: + internalWindow.height()
189: + graphical.Header.WINDOWVGAP);
190: externalWindow.sizeTo(size.width, size.height);
191: }
192: }
|