package com.vci.client.portal.UI.v3.comptdesign.compt.al;
|
|
import java.awt.Container;
|
import java.awt.Dimension;
|
import java.awt.Point;
|
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionListener;
|
import java.awt.event.FocusEvent;
|
import java.awt.event.FocusListener;
|
import java.awt.event.KeyAdapter;
|
import java.awt.event.KeyEvent;
|
import java.awt.event.KeyListener;
|
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseListener;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
import java.util.Observable;
|
import java.util.Observer;
|
|
import javax.swing.SwingUtilities;
|
import javax.swing.event.DocumentEvent;
|
import javax.swing.event.DocumentListener;
|
|
import com.vci.client.portal.UI.v3.comptdesign.UIComptDesignDialog;
|
import com.vci.client.portal.UI.v3.comptdesign.compt.BaseComptPanel;
|
import com.vci.client.portal.UI.v3.comptdesign.compt.popupcompt.BasePopupDialog;
|
import com.vci.client.ui.swing.components.VCIJTextField;
|
|
public abstract class BaseActionListener<T extends BasePopupDialog>
|
extends Observable implements ActionListener, Observer {
|
|
private BaseComptPanel ownedComptPanel = null;
|
private UIComptDesignDialog ownedUIComptDesignDialog = null;
|
private VCIJTextField txt = null;
|
private List<VCIJTextField> clearTxtList = null;
|
|
private BasePopupDialog popupDialog = null;
|
|
protected KeyListener escapeKeyListener = new KeyAdapter() {
|
public void keyReleased(KeyEvent e) {
|
if(e.getKeyChar() == KeyEvent.VK_ESCAPE){
|
if(getOwnedUIComptDesignDialog() != null){
|
getOwnedUIComptDesignDialog().setVisible(false);
|
}
|
}
|
}
|
};
|
|
private class HidePopupDialogHandler implements MouseListener, FocusListener, ActionListener{
|
|
@Override
|
public void focusGained(FocusEvent e) {
|
// TODO Auto-generated method stub
|
|
}
|
|
@Override
|
public void focusLost(FocusEvent e) {
|
// TODO Auto-generated method stub
|
hidePopupDialog();
|
}
|
|
@Override
|
public void mouseClicked(MouseEvent e) {
|
// TODO Auto-generated method stub
|
hidePopupDialog();
|
}
|
|
@Override
|
public void mousePressed(MouseEvent e) {
|
// TODO Auto-generated method stub
|
|
}
|
|
@Override
|
public void mouseReleased(MouseEvent e) {
|
// TODO Auto-generated method stub
|
|
}
|
|
@Override
|
public void mouseEntered(MouseEvent e) {
|
// TODO Auto-generated method stub
|
|
}
|
|
@Override
|
public void mouseExited(MouseEvent e) {
|
// TODO Auto-generated method stub
|
|
}
|
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
// TODO Auto-generated method stub
|
hidePopupDialog();
|
}
|
}
|
|
private HidePopupDialogHandler hideHander = null;
|
private HidePopupDialogHandler getHideHandler(){
|
if(hideHander == null){
|
hideHander = new HidePopupDialogHandler();
|
}
|
return hideHander;
|
}
|
public BaseActionListener(
|
BaseComptPanel ownedComptPanel,
|
UIComptDesignDialog ownedUIComptDesignDialog,
|
VCIJTextField txt,
|
List<VCIJTextField> clearTxtList){
|
this.ownedComptPanel = ownedComptPanel;
|
this.ownedUIComptDesignDialog = ownedUIComptDesignDialog;
|
this.txt = txt;
|
this.clearTxtList = clearTxtList;
|
|
if(ownedComptPanel != null){
|
ownedComptPanel.getTxtRefBtnALMap().put(txt.hashCode(), this);
|
Container pc = txt.getParent();
|
while(pc != null){
|
pc.addMouseListener(getHideHandler());
|
pc.addFocusListener(getHideHandler());
|
pc = pc.getParent();
|
}
|
}
|
if(txt != null){
|
txt.getDocument().addDocumentListener(new DocumentListener() {
|
@Override
|
public void removeUpdate(DocumentEvent e) {
|
txt_DocumentListener_response(null);
|
}
|
@Override
|
public void insertUpdate(DocumentEvent e) {
|
txt_DocumentListener_response(null);
|
}
|
@Override
|
public void changedUpdate(DocumentEvent e) {
|
txt_DocumentListener_response(null);
|
}
|
});
|
txt.addKeyListener(escapeKeyListener);
|
}
|
}
|
protected void txt_DocumentListener_response(DocumentEvent e){
|
if(getPopupDialog() != null){
|
if(!getPopupDialog().isVisible()){
|
return;
|
}
|
getPopupDialog().setIgnoreTxtInputValue(false);
|
getPopupDialog().loadData();
|
getTxt().requestFocus();
|
}
|
}
|
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
// TODO Auto-generated method stub
|
// Observable 作为被观察者,表明已更新
|
setChanged();
|
// 本ActionListener执行时,其它观察者做出响应(隐藏那些按钮弹出的PopupDialog)
|
notifyObservers(this);
|
|
// 按钮响应事件
|
btn_actionPerformed(e);
|
}
|
|
|
private Map<Integer, BasePopupDialog> dialogMap = new HashMap<Integer, BasePopupDialog>();
|
|
protected void btn_actionPerformed(ActionEvent e){
|
BasePopupDialog popupDialog = null;
|
if(dialogMap.containsKey(getTxt().hashCode())){
|
popupDialog = getBtnActionShowPopupDialog();
|
} else {
|
popupDialog = getBtnActionShowPopupDialog();
|
dialogMap.put(getTxt().hashCode(), popupDialog);
|
}
|
if(popupDialog == null) return;
|
|
if(!popupDialog.isBuildCompleted()){
|
popupDialog.buildDialog();
|
}
|
|
@SuppressWarnings("unchecked")
|
Runnable dialogCallback = getBtnActionShowPopupDialogCallback((T)popupDialog);
|
if(dialogCallback != null){
|
popupDialog.setDialogCallback(dialogCallback);
|
}
|
|
if(popupDialog.isVisible()){
|
return;
|
}
|
|
showPopupDialog(popupDialog);
|
}
|
|
protected void showPopupDialog(BasePopupDialog popupDialog){
|
getOwnedComptPanel().getTxtRefBtnALMap().get(getTxt().hashCode()).setPopupDialog(popupDialog);
|
setPopupDialog(popupDialog);
|
popupDialog.setIgnoreTxtInputValue(true);
|
Point p = new Point(0, getTxt().getHeight() + 1);
|
SwingUtilities.convertPointToScreen(p, getTxt());
|
popupDialog.setLocation(p);
|
Dimension size = getTxt().getSize();
|
size.height = 250;
|
popupDialog.setSize(size);
|
popupDialog.loadData();
|
popupDialog.requestFocus();
|
popupDialog.setVisible(true);
|
}
|
|
protected abstract BasePopupDialog getBtnActionShowPopupDialog();
|
|
protected abstract Runnable getBtnActionShowPopupDialogCallback(T popupDialog);
|
|
protected void clearTxtText(){
|
clearTxtText(clearTxtList);
|
}
|
|
protected void clearTxtText(List<VCIJTextField> txts){
|
if(txts != null){
|
for (VCIJTextField txt : txts) {
|
txt.setText("");
|
}
|
}
|
}
|
|
@Override
|
public void update(Observable o, Object arg) {
|
hidePopupDialog();
|
}
|
public BaseComptPanel getOwnedComptPanel() {
|
return ownedComptPanel;
|
}
|
public void setOwnedComptPanel(BaseComptPanel ownedComptPanel) {
|
this.ownedComptPanel = ownedComptPanel;
|
}
|
public UIComptDesignDialog getOwnedUIComptDesignDialog() {
|
return ownedUIComptDesignDialog;
|
}
|
|
public void setOwnedUIComptDesignDialog(UIComptDesignDialog ownedUIComptDesignDialog) {
|
this.ownedUIComptDesignDialog = ownedUIComptDesignDialog;
|
}
|
public VCIJTextField getTxt() {
|
return txt;
|
}
|
public void setTxt(VCIJTextField txt) {
|
this.txt = txt;
|
}
|
public BasePopupDialog getPopupDialog() {
|
return popupDialog;
|
}
|
public void setPopupDialog(BasePopupDialog popupDialog) {
|
this.popupDialog = popupDialog;
|
}
|
|
/**
|
* 隐藏PopupDialog
|
*/
|
public void hidePopupDialog(){
|
if(getPopupDialog() != null){
|
getPopupDialog().setVisible(false);
|
}
|
}
|
|
}
|