⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cppuserpanel.java

📁 打印管理程序,测试完全通过.windows开发环境.
💻 JAVA
字号:
package jp.co.ntl.swing.ext.cppuser;

import java.awt.CardLayout;
import java.io.IOException;

import javax.swing.JApplet;
import javax.swing.JFrame;

import jp.co.ntl.NetworkException;
import jp.co.ntl.ServerException;
import jp.co.ntl.TimeOutException;
import jp.co.ntl.NoUSBException;
import jp.co.ntl.awt.event.ChangeEvent;
import jp.co.ntl.awt.event.ChangeListener;
import jp.co.ntl.swing.ext.MainBasePanel;
import jp.co.ntl.swing.ext.DialogManager;
import jp.co.ntl.cppuser.CPPUserInfo;
import jp.co.ntl.Util;

public class CPPUserPanel extends MainBasePanel implements ChangeListener {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private CheckSPKeyPanel	checkSPKeyPanel;
	private AdminUserPanel		adminUserPanel;
	private GeneralUserPanel	generalUserPanel;
	private CardLayout			layout;
	
	private USBCheckThread		usbCheck;
	private CPPUserInvoker		invoker;
	
	private CPPUserPanel		alias;
	
	private CPPUserInfo		userInfo;
	
	public CPPUserPanel(JFrame frame) {
		super(frame, CPP);
	}
	
	public CPPUserPanel(JApplet applet) {
		super(applet, CPP);
	}
	
	protected void buildComponents() {
		super.buildComponents();
		
		alias = this;
		
		Resource.load(Util.getCurrentLocale());
		
		invoker = CPPUserInvoker.getInstance(net);
	
		layout = new CardLayout();
		setLayout(layout);
		
		checkSPKeyPanel = new CheckSPKeyPanel(frame, net);
		checkSPKeyPanel.setFont(frame.getFont());
		add("CheckSPKey", checkSPKeyPanel);
		
		adminUserPanel = new AdminUserPanel(frame, net);
		adminUserPanel.setFont(frame.getFont());
		add("AdminUser", adminUserPanel);

		generalUserPanel = new GeneralUserPanel(frame, net);
		generalUserPanel.setFont(frame.getFont());
		add("GeneralUser", generalUserPanel);
		
		generalUserPanel.addChangeListener(this);
		
		goCheckSPKeyPanel();
		
		usbCheck = new USBCheckThread(userInfo, invoker);
		usbCheck.setCheckSkip(true);
		usbCheck.start();
	}
	
	public void finalize() {
		if (usbCheck != null) {
			usbCheck.setEndThreadFlag(true);
			try {
				usbCheck.join();
			} catch (InterruptedException e) {
				;
			}
		}
		
		try {
			super.finalize();
		} catch (Throwable e) {
			;
		}
	}
	
	public void goAdminUserPanel(CPPUserInfo userInfo) {
		if (usbCheck != null) {
			usbCheck.setUserInfo(userInfo);
			usbCheck.setCheckSkip(false);
		}

		adminUserPanel.beginPanel();
		layout.show(this, "AdminUser");
	}
	
	public void goGeneralUserPanel(CPPUserInfo userInfo) {
		if (usbCheck != null) {
			usbCheck.setUserInfo(userInfo);
			usbCheck.setCheckSkip(false);
		}

		generalUserPanel.beginPanel();
		layout.show(this, "GeneralUser");
	}
	
	public void goCheckSPKeyPanel() {
		if (usbCheck != null) {
			usbCheck.setCheckSkip(true);
		}

		layout.show(this, "CheckSPKey");
	}
	
	public void stateChanged(ChangeEvent ce) {
		Object	obj = ce.getSource();
		if (obj == generalUserPanel) {
			if (usbCheck != null) {
				try {
					CPPUserInfo	userInfo = invoker.getUSBUserInfo();
					usbCheck.setUserInfo(userInfo);
				} catch (NetworkException e) {
					DialogManager.showMessage(this, DialogManager.ERROR_NETWORK);
				} catch (ServerException e) {
					DialogManager.showMessage(this, DialogManager.ERROR_SERVER, new String[] { e.getMessage() });
				} catch (TimeOutException e) {
					DialogManager.showMessage(this, DialogManager.ERROR_TIMEOUT);
				} catch (NoUSBException e) {
///					DialogManager.showMessage(this, DialogManager.ERROR_INSERT_REGISTERED_USB_CPP, new String[] { userInfo.getUsername() });
					goCheckSPKeyPanel();
				}
			}
		}
	}
	
	private class USBCheckThread extends Thread {
		private final static int	period = 5000;

		private CPPUserInfo		userInfo;
		private CPPUserInvoker		invoker;
		private boolean			endThread = false;
		private boolean			checkSkip = false;

		public USBCheckThread(CPPUserInfo userInfo, CPPUserInvoker invoker) {
			this.userInfo = userInfo;
			this.invoker = invoker;
		}
		
		public void run() {
			// 	USB Key 偑憓擖偝傟偰偄傞偐廃婜揑偵僠僃僢僋偡傞
			while (endThread == false) {
				Util.debugPrint("USB Key check");

				Util.debugPrint("user name = " + userInfo.getUsername());
///				Util.debugPrint("USB serial = " + userInfo.getUSBSerial());
				Util.debugPrint("password = " + userInfo.getPassword());
				if (!checkSkip) {
					boolean	err = false;
					try {
						if (!invoker.checkRegisteredUSB(userInfo)) {
							err = true;
///							DialogManager.showMessage(alias, DialogManager.ERROR_INSERT_REGISTERED_USB_CPP, new String[] { userInfo.getUsername() });
							goCheckSPKeyPanel();
						}
						
					} catch (IOException e) {
						err = true;
///						DialogManager.showMessage(alias, DialogManager.ERROR_INSERT_REGISTERED_USB_CPP, new String[] { userInfo.getUsername() });
						goCheckSPKeyPanel();
					} catch (NoUSBException e) {
						err = true;
///						DialogManager.showMessage(alias, DialogManager.ERROR_INSERT_REGISTERED_USB_CPP, new String[] { userInfo.getUsername() });
						goCheckSPKeyPanel();
					}
					
					if (!err) {
						try {
							if (!invoker.isRegisteredUser(userInfo)) {
///								DialogManager.showMessage(alias, DialogManager.ERROR_NOT_REGISTERED_USER_CPP_WITH_BACK, new String[] { userInfo.getUsername() });
								goCheckSPKeyPanel();
							}
						} catch (NetworkException e) {
							DialogManager.showMessage(alias, DialogManager.ERROR_NETWORK);
						} catch (ServerException e) {
							DialogManager.showMessage(alias, DialogManager.ERROR_SERVER, new String[] { e.getMessage() });
						} catch (TimeOutException e) {
							DialogManager.showMessage(alias, DialogManager.ERROR_TIMEOUT);
						}
					}
				}
			
				try {
					Thread.sleep(period);
				} catch (InterruptedException e) {
					;
				}
			}
		}
		
		public synchronized void setUserInfo(CPPUserInfo userInfo) {
			this.userInfo = userInfo;
		}
		
		public synchronized void setEndThreadFlag(boolean endThread) {
			this.endThread = endThread;
		}
		
		public synchronized void setCheckSkip(boolean checkSkip) {
			this.checkSkip = checkSkip;
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -