package com.vci.client;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Insets;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.net.UnknownHostException;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;
import com.vci.client.ClientSession;
import com.vci.client.common.ConfigUtils;
import com.vci.client.common.interfaces.IAppEventManager;
import com.vci.client.common.objects.ClientInfo;
import com.vci.client.common.objects.UserEntityObject;
import com.vci.client.common.objects.UserObject;
import com.vci.client.framework.delegate.RightManagementClientDelegate;
import com.vci.client.framework.delegate.SystemCfgClientDelegate;
import com.vci.client.framework.rightdistribution.object.RoleRightObject;
import com.vci.client.logon.client.BaseStyle;
import com.vci.client.logon.client.LogonFrame;
import com.vci.client.logon.client.VciFrame;
import com.vci.client.logon.client.ViewCodeFrame;
import com.vci.client.ui.exception.VCIException;
import com.vci.client.ui.locale.LocaleDisplay;
import com.vci.client.ui.swing.VCIOptionPane;
import com.vci.client.ui.swing.VCISwingUtil;
import com.vci.client.ui.swing.components.VCIJOptionPane;
import com.vci.common.resource.CommonProperties;
import com.vci.corba.framework.data.UserInfo;
import com.vci.mw.ClientContextVariable;
import com.vci.mw.LaunchModeEnum;
public class LogonApplication extends BaseStyle implements IAppEventManager {
public static Frame frame = null;
boolean packFrame = false;
public static UserObject userObject = null;
public static String urlBasePath = ".";
public static RoleRightObject[] currentUserRoleRights = null;
private Date loginTime = null;
private int loginovertime = Integer.parseInt(CommonProperties.getStringProperty("logon.loginovertime"));
public void setUserObject(UserObject userObj) {
userObject = userObj;
}
@Override
public boolean checkExpired() {
boolean expired = isExpired();
if(expired){
VCIOptionPane.showMessageDialog(LogonApplication.frame, "会话过期,请重新登录!!!!");
}
return expired;
}
@Override
public void relogin() {
if (frame != null){
frame.dispose();
}
show(new String[]{});
}
/**
* 检查Client会话是否过期
* @return
*/
private boolean isExpired(){
boolean res = false;
// add by xchao 2013.08.16 begin 根据选项配置,确定是否需要检查客户端UI是否超时
if(!ClientSession.isCheckClientUITimeout())
return false;
// add by xchao 2013.08.16 end
long betweenTime = 0;
if (loginTime != null){
// 当前时间 - 登录时间 -》 转换为分钟
betweenTime = (System.currentTimeMillis() - loginTime.getTime()) / (60 * 1000);
}
// 与会话超时阀值进行比较
if (betweenTime > loginovertime){
betweenTime = 0;
loginTime = null;
res = true;
}else{
setLoginTime();
res = false;
}
ClientSession.setTimeOutFlag(res);
return res;
}
/**
* 设置登录时间
*/
private void setLoginTime(){
loginTime = new Date();
}
public static UserObject getUserObject() {
return userObject;
}
public static UserEntityObject userEntityObject;
public static UserEntityObject getUserEntityObject() {
return userEntityObject;
}
public void setUserEntityObject(UserEntityObject userEntityObject) {
this.userEntityObject = userEntityObject;
}
private void setUserData(UserObject userObj) {
this.userObject = userObj;
String ip = this.getLocalIP();
String userName = userObj.getUserName();
UserEntityObject entityObj = new UserEntityObject(userName, ip);
this.setUserEntityObject(entityObj);
}
private static String getLocalIP() {
String ip = "127.0.0.1";
try {
ip = java.net.InetAddress.getLocalHost().getHostAddress();
} catch (UnknownHostException e) {
e.printStackTrace();
}
return ip;
}
public LogonApplication(final UserObject userObj) {
ClientSession.setAppEventManager(this);
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
ClientSession.setTimeOutFlag(false);
setUserData(userObj);
VciFrame vciFrame = new VciFrame(userObj);
try {
vciFrame.init();
} catch (Exception e) {
e.printStackTrace();
VCIOptionPane.showError(vciFrame, LocaleDisplay.getI18nString("100001", "RMIPFramework", Locale.getDefault()));
}
if (packFrame) {
vciFrame.pack();
} else {
vciFrame.validate();
}
showMainFrame(vciFrame);
}
});
}
@Deprecated
public static void loadJar() {
// nothing
}
/**
* 单点登录使用方法
* @param userObj
* @param message 业务系统传递的信息
*/
public LogonApplication(final UserObject userObj,final String[] taskMessage) {
ClientSession.setAppEventManager(this);
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
ClientSession.setTimeOutFlag(false);
setUserData(userObj);
VciFrame vciFrame = new VciFrame(userObj);
vciFrame.setTaskMessage(taskMessage);
try {
vciFrame.init();
} catch (Exception e) {
VCIOptionPane.showError(vciFrame, LocaleDisplay.getI18nString("100001", "RMIPFramework", Locale.getDefault()));
}
if (packFrame) {
vciFrame.pack();
} else {
vciFrame.validate();
}
showMainFrame(vciFrame);
}
});
}
private void showMainFrame(VciFrame vciFrame){
vciFrame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
VCISwingUtil.setClientMainFrame(vciFrame);
vciFrame.setFocusableWindowState(true);
setSizeAndLocation(vciFrame);
vciFrame.setVisible(true);
frame = vciFrame;
// 集成(单点)登录或是B/S登录界面登录时,Client启动时,重新ClientContextVariable
LogonApplication.frame = vciFrame;
ClientContextVariable.setFrame(vciFrame);
try {
vciFrame.loadTab1(0);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private Dimension getCurrentSizeAndSetLocation(VciFrame frame){
Dimension d = new Dimension();
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(frame.getGraphicsConfiguration());
int top = insets.top;
int left = insets.left;
int right = insets.right;
int bottom = insets.bottom;
int width = dim.width - left - right;
int height = dim.height - top - bottom;
int x = insets.left;
int y = insets.top;
frame.setLocation(x, y);
d = new Dimension(width, height);
return d;
}
private boolean manualSetSize = false;
private void setSizeAndLocation(final VciFrame frame){
Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(frame.getGraphicsConfiguration());
Dimension size = getCurrentSizeAndSetLocation(frame);
frame.setPreferredSize(size);
frame.setSize(size);
Point location = new Point(insets.left, insets.top);
frame.setLocation(location);
frame.setLocationByPlatform(true);
frame.setLocationRelativeTo(null);
frame.addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
if(e.getSource() instanceof VciFrame){
if(manualSetSize){
manualSetSize = false;
return;
}
VciFrame vf = (VciFrame)e.getSource();
int extendedState = vf.getExtendedState();
if((extendedState & JFrame.MAXIMIZED_BOTH) == JFrame.MAXIMIZED_BOTH){
manualSetSize = true;
Dimension size = getCurrentSizeAndSetLocation(frame);
frame.setPreferredSize(size);
frame.setSize(size);
return;
}
//
// //paramString -> COMPONENT_RESIZED (0,0 1600x856)
// String[] widthXHeights = e.paramString()
// .replaceAll("COMPONENT_RESIZED", "").trim()
// .replaceAll("\\(", "")
// .replaceAll("\\)", "")
// .split(" ")[1].split("x");
// int widthNew = Integer.valueOf(widthXHeights[0]);
// int heightNew = Integer.valueOf(widthXHeights[1]);
// Dimension maxSize = vf.getMaximumSize();
// if(heightNew > maxSize.height){
// heightNew = maxSize.height;
// manualSetSize = true;
// vf.setSize(widthNew, heightNew);
// }
}
}
});
}
public static void main(String[] args) {
System.out.println("");
System.out.println("\t***************************************************************");
System.out.println("\t* VCI-Platform Client V2024 www.vci-tech.com *");
System.out.println("\t* (C)Beijing Hongbo Yuanda Sciense and Technology Co. , Ltd. *");
System.out.println("\t***************************************************************");
System.out.println("");
for(String a : args){
System.out.println("args = "+ a);
}
// args = new String[]{"intUser_xc","taskType_EDIT","taskId_840033", "ViewCode_false"};
// add by xchao 2013.08.16 begin 设置客户端UI需要检查是否超时
ClientSession.setCheckClientUITimeout(true);
// add by xchao 2013.08.16 end
// launchMode_1 -> 此时代表常规模式,如:通过命令行或调试模式 normal
// launchMode_2 -> jnlpwebstart 此时代表通过 使用 jnlp 方式启动
// webBasePath_http://ip:port/xxx -> http://ip:port/xxx 是 jnlp 方式启动的 .jnlp 主地址
for(String arg : args){
if(arg.contains("_")){
String[] kvs = arg.split("_");
if(kvs.length >= 2){
if("launchMode".equalsIgnoreCase(kvs[0])){
LaunchModeEnum launchMode = LaunchModeEnum.getByIntVal(Integer.valueOf(kvs[1]));
ClientContextVariable.setClientLanuchMode(launchMode);
} else if("webBasePath".equalsIgnoreCase(kvs[0])){
String webBasePath = arg.substring(arg.indexOf("_")+1);
if(!"".equals(webBasePath)){
ClientContextVariable.setWebBasePath(webBasePath);
}
}
}
}
}
// System.out.println("launchMode:" + ClientContextVariable.getClientLanuchMode().getLabel());
// System.out.println("webBasePath:" + ClientContextVariable.getWebBasePath());
// if(ClientContextVariable.getClientLanuchMode() == LaunchModeEnum.Normal){
// new ClassLoaderUtil().loadNeedLoadJars();
// }
show(args);
}
public static void show(final String[] argsInput){
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
try {
String sLookFeel = ConfigUtils.getConfigValue("LookAndFeel");
if (!sLookFeel.isEmpty() && !sLookFeel.equals("LookAndFeel"))
VCISwingUtil.setLookAndFeel(sLookFeel);
else
VCISwingUtil.setLookAndFeel();
JFrame.setDefaultLookAndFeelDecorated(true);
JDialog.setDefaultLookAndFeelDecorated(true);
//设置主题
//SubstanceLookAndFeel.setCurrentTheme(new SubstanceEbonyTheme());
//设置按钮外观
//SubstanceLookAndFeel.setCurrentButtonShaper(new ClassicButtonShaper());
//VCISwingUtil.setLookAndFeel(VCISwingUtil.LOOK_AND_FEEL_PlasticLookAndFeel);
//VCISwingUtil.setLookAndFeel(VCISwingUtil.LOOK_AND_FEEL_WindowsLookAndFeel);
//VCISwingUtil.setLookAndFeel(VCISwingUtil.LOOK_AND_FEEL_AlloyLookAndFeel);
//VCISwingUtil.setLookAndFeel(VCISwingUtil.LOOK_AND_FEEL_NimbusLookAndFeel);
//VCISwingUtil.setLookAndFeel(VCISwingUtil.LOOK_AND_FEEL_MetalLookAndFeel);
//VCISwingUtil.setLookAndFeel("org.pushingpixels.substance.api.SubstanceBusinessBlackSteelLookAndFeel");
//VCISwingUtil.setLookAndFeel();
String intUserName = "";
String taskType = "";
String taskId = "";
String codes = "";
if(argsInput.length >0){
// 从传入的参数中,解析出集成用户,参数信息 intUser_XXX
String[] innerName = argsInput[0].split("_");
if(innerName!=null && innerName.length==2){
for(int i = 0; i < innerName.length; i++){
String arg = innerName[i];
if(arg.trim().equals("intUser")){
if((i+1)