📄 ini.java
字号:
public static void setProperty (String key, String value)
{
// log.finer(key + "=" + value);
if (s_prop == null)
s_prop = new Properties();
if (key.equals(P_WARNING) || key.equals(P_WARNING_de))
s_prop.setProperty(key, value);
else if (!isClient())
s_prop.setProperty(key, SecureInterface.CLEARVALUE_START + value + SecureInterface.CLEARVALUE_END);
else
{
if (value == null)
s_prop.setProperty(key, "");
else
{
String eValue = SecureEngine.encrypt(value);
if (eValue == null)
s_prop.setProperty(key, "");
else
s_prop.setProperty(key, eValue);
}
}
} // setProperty
/**
* Set Property
* @param key Key
* @param value Value
*/
public static void setProperty (String key, boolean value)
{
setProperty (key, value ? "Y" : "N");
} // setProperty
/**
* Set Property
* @param key Key
* @param value Value
*/
public static void setProperty (String key, int value)
{
setProperty (key, String.valueOf(value));
} // setProperty
/**
* Get Propery
* @param key Key
* @return Value
*/
public static String getProperty (String key)
{
if (key == null)
return "";
String retStr = s_prop.getProperty(key, "");
if (retStr == null || retStr.length() == 0)
return "";
//
String value = SecureEngine.decrypt(retStr);
// log.finer(key + "=" + value);
if (value == null)
return "";
return value;
} // getProperty
/**
* Get Propery as Boolean
* @param key Key
* @return Value
*/
public static boolean isPropertyBool (String key)
{
return getProperty (key).equals("Y");
} // getProperty
/**
* Cache Windows
* @return true if windows are cached
*/
public static boolean isCacheWindow()
{
return getProperty (P_CACHE_WINDOW).equals("Y");
} // isCacheWindow
/**************************************************************************
* Get Properties
*
* @return Ini properties
*/
public static Properties getProperties()
{
return s_prop;
} // getProperties
/**
* toString
* @return String representation
*/
public static String getAsString()
{
StringBuffer buf = new StringBuffer ("Ini[");
Enumeration e = s_prop.keys();
while (e.hasMoreElements())
{
String key = (String)e.nextElement();
buf.append(key).append("=");
buf.append(getProperty(key)).append("; ");
}
buf.append("]");
return buf.toString();
} // toString
/*************************************************************************/
/** System environment prefix */
public static final String ENV_PREFIX = "env.";
/** System Property Value of COMPIERE_HOME */
public static final String COMPIERE_HOME = "COMPIERE_HOME";
/** IsClient Internal marker */
private static boolean s_client = true;
/** IsClient Internal marker */
private static boolean s_loaded = false;
/**
* Are we in Client Mode ?
* @return true if client
*/
public static boolean isClient()
{
return s_client;
} // isClient
/**
* Set Client Mode
* @param client client
*/
public static void setClient (boolean client)
{
s_client = client;
} // setClient
/**
* Are the properties loaded?
* @return true if properties loaded.
*/
public static boolean isLoaded()
{
return s_loaded;
} // isLoaded
/**
* Get Compiere Home from Environment
* @return CompiereHome or null
*/
public static String getCompiereHome()
{
String env = System.getProperty (ENV_PREFIX + COMPIERE_HOME);
if (env == null)
env = System.getProperty (COMPIERE_HOME);
return env;
} // getCompiereHome
/**
* Set Compiere Home
* @param CompiereHome COMPIERE_HOME
*/
public static void setCompiereHome (String CompiereHome)
{
if (CompiereHome != null && CompiereHome.length() > 0)
System.setProperty (COMPIERE_HOME, CompiereHome);
} // setCompiereHome
/**
* Find Compiere Home
* @return compiere home or null
*/
public static String findCompiereHome()
{
String ch = getCompiereHome();
if (ch != null)
return ch;
File[] roots = File.listRoots();
for (int i = 0; i < roots.length; i++)
{
if (roots[i].getAbsolutePath().startsWith("A:"))
continue;
File[] subs = roots[i].listFiles();
if (subs == null)
continue;
for (int j = 0; j < subs.length; j++)
{
if (!subs[j].isDirectory())
continue;
String fileName = subs[j].getAbsolutePath();
if (fileName.indexOf("Compiere2") != 1)
{
String libDir = fileName + File.separator + "lib";
File lib = new File(libDir);
if (lib.exists() && lib.isDirectory())
return fileName;
}
}
}
return ch;
} // findCompiereHome
/**************************************************************************
* Get Window Dimension
* @param AD_Window_ID window no
* @return dimension or null
*/
public static Dimension getWindowDimension(int AD_Window_ID)
{
String key = "WindowDim" + AD_Window_ID;
String value = (String)s_prop.get(key);
if (value == null || value.length() == 0)
return null;
int index = value.indexOf("|");
if (index == -1)
return null;
try
{
String w = value.substring(0, index);
String h = value.substring(index+1);
return new Dimension(Integer.parseInt(w),Integer.parseInt(h));
}
catch (Exception e)
{
}
return null;
} // getWindowDimension
/**
* Set Window Dimension
* @param AD_Window_ID window
* @param windowDimension dimension - null to remove
*/
public static void setWindowDimension(int AD_Window_ID, Dimension windowDimension)
{
String key = "WindowDim" + AD_Window_ID;
if (windowDimension != null)
{
String value = windowDimension.width + "|" + windowDimension.height;
s_prop.put(key, value);
}
else
s_prop.remove(key);
} // setWindowDimension
/**
* Get Window Location
* @param AD_Window_ID window id
* @return location or null
*/
public static Point getWindowLocation(int AD_Window_ID)
{
String key = "WindowLoc" + AD_Window_ID;
String value = (String)s_prop.get(key);
if (value == null || value.length() == 0)
return null;
int index = value.indexOf("|");
if (index == -1)
return null;
try
{
String x = value.substring(0, index);
String y = value.substring(index+1);
return new Point(Integer.parseInt(x),Integer.parseInt(y));
}
catch (Exception e)
{
}
return null;
} // getWindowLocation
/**
* Set Window Location
* @param AD_Window_ID window
* @param windowLocation location - null to remove
*/
public static void setWindowLocation(int AD_Window_ID, Point windowLocation)
{
String key = "WindowLoc" + AD_Window_ID;
if (windowLocation != null)
{
String value = windowLocation.x + "|" + windowLocation.y;
s_prop.put(key, value);
}
else
s_prop.remove(key);
} // setWindowLocation
/**
* Get Divider Location
* @return location
*/
public static int getDividerLocation()
{
String key = "Divider";
String value = (String)s_prop.get(key);
if (value == null || value.length() == 0)
return 0;
try
{
return Integer.parseInt(value);
}
catch (Exception e)
{
}
return 0;
} // getDividerLocation
/**
* Set Divider Location
* @param dividerLocation location
*/
public static void setDividerLocation(int dividerLocation)
{
String key = "Divider";
String value = String.valueOf(dividerLocation);
s_prop.put(key, value);
} // setDividerLocation
} // Ini
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -