📄 env.java
字号:
{
if (ctx == null)
throw new IllegalArgumentException ("Require Context");
Iterator keyIterator = ctx.keySet().iterator();
String[] sList = new String[ctx.size()];
int i = 0;
while (keyIterator.hasNext())
{
Object key = keyIterator.next();
sList[i++] = key.toString() + " == " + ctx.get(key).toString();
}
return sList;
} // getEntireContext
/**
* Get Header info (connection, org, user)
* @param ctx context
* @param WindowNo window
* @return Header String
*/
public static String getHeader(Properties ctx, int WindowNo)
{
StringBuffer sb = new StringBuffer();
if (WindowNo > 0)
sb.append(getContext(ctx, WindowNo, "WindowName", false)).append(" ");
sb.append(getContext(ctx, "#AD_User_Name")).append("@")
.append(getContext(ctx, "#AD_Client_Name")).append(".")
.append(getContext(ctx, "#AD_Org_Name"))
.append(" [").append(CConnection.get().toString()).append("]");
return sb.toString();
} // getHeader
/**
* Clean up context for Window (i.e. delete it)
* @param ctx context
* @param WindowNo window
*/
public static void clearWinContext(Properties ctx, int WindowNo)
{
if (ctx == null)
throw new IllegalArgumentException ("Require Context");
//
Object[] keys = ctx.keySet().toArray();
for (int i = 0; i < keys.length; i++)
{
String tag = keys[i].toString();
if (tag.startsWith(WindowNo+"|"))
ctx.remove(keys[i]);
}
// Clear Lookup Cache
MLookupCache.cacheReset(WindowNo);
// MLocator.cacheReset(WindowNo);
//
removeWindow(WindowNo);
} // clearWinContext
/**
* Clean up all context (i.e. delete it)
* @param ctx context
*/
public static void clearContext(Properties ctx)
{
if (ctx == null)
throw new IllegalArgumentException ("Require Context");
ctx.clear();
} // clearContext
/**
* Parse Context replaces global or Window context @tag@ with actual value.
*
* @tag@ are ignored otherwise "" is returned
* @param ctx context
* @param WindowNo Number of Window
* @param value Message to be parsed
* @param onlyWindow if true, no defaults are used
* @param ignoreUnparsable if true, unsuccessful @return parsed String or "" if not successful and ignoreUnparsable
*/
public static String parseContext (Properties ctx, int WindowNo, String value,
boolean onlyWindow, boolean ignoreUnparsable)
{
if (value == null || value.length() == 0)
return "";
String token;
String inStr = new String(value);
StringBuffer outStr = new StringBuffer();
int i = inStr.indexOf('@');
while (i != -1)
{
outStr.append(inStr.substring(0, i)); // up to @
inStr = inStr.substring(i+1, inStr.length()); // from first @
int j = inStr.indexOf('@'); // next @
if (j < 0)
{
s_log.log(Level.SEVERE, "No second tag: " + inStr);
return ""; // no second tag
}
token = inStr.substring(0, j);
String ctxInfo = getContext(ctx, WindowNo, token, onlyWindow); // get context
if (ctxInfo.length() == 0 && (token.startsWith("#") || token.startsWith("$")) )
ctxInfo = getContext(ctx, token); // get global context
if (ctxInfo.length() == 0)
{
s_log.config("No context Win=" + WindowNo + " for: " + token);
if (!ignoreUnparsable)
return ""; // token not found
}
else
outStr.append(ctxInfo); // replace context with Context
inStr = inStr.substring(j+1, inStr.length()); // from second @
i = inStr.indexOf('@');
}
outStr.append(inStr); // add the rest of the string
return outStr.toString();
} // parseContext
/**
* Parse Context replaces global or Window context @tag@ with actual value.
*
* @param ctx context
* @param WindowNo Number of Window
* @param value Message to be parsed
* @param onlyWindow if true, no defaults are used
* @return parsed String or "" if not successful
*/
public static String parseContext (Properties ctx, int WindowNo, String value,
boolean onlyWindow)
{
return parseContext(ctx, WindowNo, value, onlyWindow, false);
} // parseContext
/*************************************************************************/
// Array of active Windows
private static ArrayList<Container> s_windows = new ArrayList<Container>(20);
/**
* Add Container and return WindowNo.
* The container is a APanel, AWindow or JFrame/JDialog
* @param win window
* @return WindowNo used for context
*/
public static int createWindowNo(Container win)
{
int retValue = s_windows.size();
s_windows.add(win);
return retValue;
} // createWindowNo
/**
* Search Window by comparing the Frames
* @param container container
* @return WindowNo of container or 0
*/
public static int getWindowNo (Container container)
{
if (container == null)
return 0;
JFrame winFrame = getFrame(container);
if (winFrame == null)
return 0;
// loop through windows
for (int i = 0; i < s_windows.size(); i++)
{
Container cmp = (Container)s_windows.get(i);
if (cmp != null)
{
JFrame cmpFrame = getFrame(cmp);
if (winFrame.equals(cmpFrame))
return i;
}
}
return 0;
} // getWindowNo
/**
* Return the JFrame pointer of WindowNo - or null
* @param WindowNo window
* @return JFrame of WindowNo
*/
public static JFrame getWindow (int WindowNo)
{
JFrame retValue = null;
try
{
retValue = getFrame ((Container)s_windows.get(WindowNo));
}
catch (Exception e)
{
s_log.log(Level.SEVERE, e.toString());
}
return retValue;
} // getWindow
/**
* Remove window from active list
* @param WindowNo window
*/
private static void removeWindow (int WindowNo)
{
if (WindowNo < s_windows.size())
s_windows.set(WindowNo, null);
} // removeWindow
/**
* Clean up context for Window (i.e. delete it)
* @param WindowNo window
*/
public static void clearWinContext(int WindowNo)
{
clearWinContext (s_ctx, WindowNo);
} // clearWinContext
/**
* Clean up all context (i.e. delete it)
*/
public static void clearContext()
{
s_ctx.clear();
} // clearContext
/**************************************************************************
* Get Frame of Window
* @param container Container
* @return JFrame of container or null
*/
public static JFrame getFrame (Container container)
{
Container element = container;
while (element != null)
{
if (element instanceof JFrame)
return (JFrame)element;
element = element.getParent();
}
return null;
} // getFrame
/**
* Get Graphics of container or its parent.
* The element may not have a Graphic if not displayed yet,
* but the parent might have.
* @param container Container
* @return Graphics of container or null
*/
public static Graphics getGraphics (Container container)
{
Container element = container;
while (element != null)
{
Graphics g = element.getGraphics();
if (g != null)
return g;
element = element.getParent();
}
return null;
} // getFrame
/**
* Return JDialog or JFrame Parent
* @param container Container
* @return JDialog or JFrame of container
*/
public static Window getParent (Container container)
{
Container element = container;
while (element != null)
{
if (element instanceof JDialog || element instanceof JFrame)
return (Window)element;
if (element instanceof Window)
return (Window)element;
element = element.getParent();
}
return null;
} // getParent
/**************************************************************************
* Get Image with File name
*
* @param fileNameInImageDir full file name in imgaes folder (e.g. Bean16.gif)
* @return image
*/
public static Image getImage (String fileNameInImageDir)
{
URL url = Compiere.class.getResource("images/" + fileNameInImageDir);
if (url == null)
{
s_log.log(Level.SEVERE, "Not found: " + fileNameInImageDir);
return null;
}
Toolkit tk = Toolkit.getDefaultToolkit();
return tk.getImage(url);
} // getImage
/**
* Get ImageIcon.
*
* @param fileNameInImageDir full file name in imgaes folder (e.g. Bean16.gif)
* @return image
*/
public static ImageIcon getImageIcon (String fileNameInImageDir)
{
URL url = Compiere.class.getResource("images/" + fileNameInImageDir);
if (url == null)
{
s_log.log(Level.SEVERE, "Not found: " + fileNameInImageDir);
return null;
}
return new ImageIcon(url);
} // getImageIcon
/***************************************************************************
* Start Browser
* @param url url
*/
public static void startBrowser (String url)
{
s_log.info(url);
// OS command
String cmd = "explorer ";
if (!isWindows())
cmd = "netscape ";
//
String execute = cmd + url;
try
{
Runtime.getRuntime().exec(execute);
}
catch (Exception e)
{
try{
Runtime.getRuntime().exec("firefox " + url);
}catch(Exception ex){
System.err.println("Env.startBrowser - " + "firefox " + url + " - " + ex);
}
s_log.severe(execute + " - " + e);
}
} // startBrowser
/**
* Do we run on Apple
* @return true if Mac
*/
public static boolean isMac()
{
String osName = System.getProperty ("os.name");
osName = osName.toLowerCase();
return osName.indexOf ("mac") != -1;
} // isMac
/**
* Do we run on Windows
* @return true if windows
*/
public static boolean isWindows()
{
String osName = System.getProperty ("os.name");
osName = osName.toLowerCase();
return osName.indexOf ("windows") != -1;
} // isWindows
/** Array of hidden Windows */
private static ArrayList<CFrame> s_hiddenWindows = new ArrayList<CFrame>();
/** Closing Window Indicator */
private static boolean s_closingWindows = false;
/**
* Hide Window
* @param window window
* @return true if window is hidden, otherwise close it
*/
static public boolean hideWindow(CFrame window)
{
if (!Ini.isCacheWindow() || s_closingWindows)
return false;
for (int i = 0; i < s_hiddenWindows.size(); i++)
{
CFrame hidden = s_hiddenWindows.get(i);
s_log.info(i + ": " + hidden);
if (hidden.getAD_Window_ID() == window.getAD_Window_ID())
return false; // already there
}
if (window.getAD_Window_ID() != 0) // workbench
{
if (s_hiddenWindows.add(window))
{
window.setVisible(false);
s_log.info(window.toString());
// window.dispatchEvent(new WindowEvent(window, WindowEvent.WINDOW_ICONIFIED));
if (s_hiddenWindows.size() > 10)
s_hiddenWindows.remove(0); // sort of lru
return true;
}
}
return false;
} // hideWindow
/**
* Show Window
* @param AD_Window_ID window
* @return true if window re-displayed
*/
static public boolean showWindow (int AD_Window_ID)
{
for (int i = 0; i < s_hiddenWindows.size(); i++)
{
CFrame hidden = s_hiddenWindows.get(i);
if (hidden.getAD_Window_ID() == AD_Window_ID)
{
hidden.setVisible(true);
s_hiddenWindows.remove(i);
s_log.info(hidden.toString());
hidden.toFront();
return true;
}
}
return false;
} // showWindow
/**
* Clode Windows
*/
static void closeWindows ()
{
s_closingWindows = true;
for (int i = 0; i < s_hiddenWindows.size(); i++)
{
CFrame hidden = s_hiddenWindows.get(i);
hidden.dispose();
}
s_closingWindows = false;
} // closeWindows
/**************************************************************************
* Static Variables
*/
/** Big Decimal 0 */
static final public BigDecimal ZERO = new BigDecimal(0.0);
/** Big Decimal 1 */
static final public BigDecimal ONE = new BigDecimal(1.0);
/** Big Decimal 100 */
static final public BigDecimal ONEHUNDRED = new BigDecimal(100.0);
/** New Line */
public static final String NL = System.getProperty("line.separator");
/**
* Static initializer
*/
static
{
// Set English as default Language
s_ctx.put(LANGUAGE, Language.getBaseAD_Language());
} // static
} // Env
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -