package com.vci.client.logon.base; import java.awt.Dimension; import java.awt.Frame; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseEvent; import javax.swing.BorderFactory; import javax.swing.JButton; import javax.swing.JToolBar; import com.vci.client.LogonApplication; import com.vci.client.framework.delegate.RightManagementClientDelegate; import com.vci.client.framework.util.RightControlUtil; import com.vci.client.logon.client.LogonPanel; import com.vci.client.ui.exception.VCIException; import com.vci.client.ui.swing.KJButton; import com.vci.client.ui.swing.VCIOptionPane; public abstract class BaseToolBar extends JToolBar{ private static final long serialVersionUID = 1L; public KJButton exitButton = new KJButton("" , "exit.gif"); public KJButton changePasswordButton = new KJButton("" , "password.gif"); public KJButton helpButton = new KJButton("" , "help.gif"); private Frame frame = null; public BaseToolBar(Frame frame) { try { // jbInit(); } catch (Exception e) { e.printStackTrace(); } } public void setToolButtonSize(JButton jb){ jb.setMaximumSize(new Dimension(30, 24)); jb.setMinimumSize(new Dimension(30, 24)); jb.setPreferredSize(new Dimension(30, 24)); jb.setBorder(null); } private void jbInit() { this.setFloatable(false); this.setBorder(BorderFactory.createEmptyBorder()); setToolButtonSize(changePasswordButton); changePasswordButton.setToolTipText("更改密码"); setToolButtonSize(helpButton); helpButton.setToolTipText("帮助"); setToolButtonSize(exitButton); exitButton.setToolTipText("退出"); changePasswordButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { changePasswordButton_actionEvent(); } }); setMouseEnteredAndExitedEvent(changePasswordButton); helpButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { helpMenu_actionEvent(e); } }); setMouseEnteredAndExitedEvent(helpButton); exitButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { exitButton_actionEvent(); } }); setMouseEnteredAndExitedEvent(exitButton); } protected void setMouseEnteredAndExitedEvent(final JButton button){ button.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseEntered(MouseEvent e) { resourceTypesButton_mouseEntered(e, button); } public void mouseExited(MouseEvent e) { resourceTypesButton_mouseExited(e, button); } }); } private void exitButton_actionEvent() { int i=VCIOptionPane.showConfirmDialog(frame, "确定要退出系统吗?","退出系统",VCIOptionPane.YES_NO_OPTION); if(i==0){ if (!RightControlUtil.isAdminOrDeveloperOrRoot(LogonApplication.getUserObject().getUserName())){ /** * 保存日志 */ String message = "登出"; LogonApplication.getUserEntityObject().setModules(LogonPanel.class.getName()); try { new RightManagementClientDelegate(LogonApplication.getUserEntityObject()).savelog(message); } catch (VCIException e) { VCIOptionPane.showError(LogonApplication.frame,"RMIPFramework", e); } } System.exit(0); } } private void helpMenu_actionEvent(ActionEvent ae) { } private void changePasswordButton_actionEvent(){ ChangePasswordDialog changePasswordDialog = new ChangePasswordDialog(frame, false,LogonApplication.getUserEntityObject()); Dimension screenSize = Toolkit.getDefaultToolkit ().getScreenSize (); Dimension dialogSize = changePasswordDialog.getPreferredSize (); dialogSize.height = 300; dialogSize.width = 300; changePasswordDialog.setSize (dialogSize); changePasswordDialog.setResizable(false); changePasswordDialog.setLocation ( (screenSize.width - dialogSize.width) / 2, (screenSize.height - dialogSize.height) / 2); changePasswordDialog.setVisible (true); } public void resourceTypesButton_mouseEntered(MouseEvent e,JButton jb) { jb.setBorder(BorderFactory.createRaisedBevelBorder()); } public void resourceTypesButton_mouseExited(MouseEvent e,JButton jb) { jb.setBorder(null); } public void loadToolBarItem(){ // this.add(changePasswordButton); this.initSpecialToolBar(); // this.add(helpButton); // this.add(exitButton); } public abstract void initSpecialToolBar(); }