From ff839d3d665de634ce53b11b76fadc9913afa7ec Mon Sep 17 00:00:00 2001 From: Yana Stamcheva Date: Mon, 22 May 2006 16:26:21 +0000 Subject: [PATCH] "Clsing a window shortly after a new msg should trigger a warning" --- .../impl/gui/main/i18n/messages.properties | 2 +- .../impl/gui/main/message/ChatWindow.java | 68 ++++++++++++------- 2 files changed, 43 insertions(+), 27 deletions(-) diff --git a/src/net/java/sip/communicator/impl/gui/main/i18n/messages.properties b/src/net/java/sip/communicator/impl/gui/main/i18n/messages.properties index c9731a7d7..a63a39a55 100644 --- a/src/net/java/sip/communicator/impl/gui/main/i18n/messages.properties +++ b/src/net/java/sip/communicator/impl/gui/main/i18n/messages.properties @@ -11,7 +11,7 @@ call=Call callList=Call list cancel=Cancel close=Close -closeChatAfterNewMsg=You have received a message in last 5 seconds. Are you sure you want to close this chat? +closeChatAfterNewMsg=You have received new message in last 2 seconds. Are you sure you want to close this chat? configure=Configure connectionFailed=Connection failed connectionFailedMessage=The connection could not be established due to a network \n connection problem. Please check your network configuration. diff --git a/src/net/java/sip/communicator/impl/gui/main/message/ChatWindow.java b/src/net/java/sip/communicator/impl/gui/main/message/ChatWindow.java index 780ab6155..ecde71893 100755 --- a/src/net/java/sip/communicator/impl/gui/main/message/ChatWindow.java +++ b/src/net/java/sip/communicator/impl/gui/main/message/ChatWindow.java @@ -11,6 +11,9 @@ import java.awt.event.ActionEvent; import java.awt.event.KeyEvent; import java.awt.event.MouseEvent; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.awt.event.WindowListener; import java.util.Date; import java.util.Enumeration; import java.util.Hashtable; @@ -81,6 +84,11 @@ public ChatWindow (MainFrame mainFrame){ this.init(); this.enableKeyActions(); + this.addWindowListener(new WindowAdapter(){ + public void windowClosing(WindowEvent e){ + close(); + } + }); } /** @@ -138,32 +146,7 @@ private void enableKeyActions(){ { public void actionPerformed(ActionEvent e) { - if(!getCurrentChatWritePanel().isEmpty()){ - int answer = JOptionPane.showConfirmDialog(ChatWindow.this, - Messages.getString("nonEmptyChatWindowClose"), - Messages.getString("warning"), - JOptionPane.OK_CANCEL_OPTION, - JOptionPane.WARNING_MESSAGE); - - if(answer == JOptionPane.YES_OPTION){ - closeChat(); - } - } - else if(System.currentTimeMillis() - getCurrentConversationPanel() - .getLastIncomingMsgTimestamp().getTime() < 3*1000){ - int answer = JOptionPane.showConfirmDialog(ChatWindow.this, - Messages.getString("closeChatAfterNewMsg"), - Messages.getString("warning"), - JOptionPane.OK_CANCEL_OPTION, - JOptionPane.WARNING_MESSAGE); - - if(answer == JOptionPane.YES_OPTION){ - closeChat(); - } - } - else{ - closeChat(); - } + close(); } }; @@ -212,6 +195,39 @@ public void actionPerformed(ActionEvent e) (KeyEvent.VK_LEFT, KeyEvent.ALT_DOWN_MASK), "changeTabBackword"); } + /** + * Closes the current chat, triggering warnings to the user + * when there are non-sent messages or a message is received + * in last 2 seconds. + */ + private void close(){ + if(!getCurrentChatWritePanel().isEmpty()){ + int answer = JOptionPane.showConfirmDialog(ChatWindow.this, + Messages.getString("nonEmptyChatWindowClose"), + Messages.getString("warning"), + JOptionPane.OK_CANCEL_OPTION, + JOptionPane.WARNING_MESSAGE); + + if(answer == JOptionPane.YES_OPTION){ + closeChat(); + } + } + else if(System.currentTimeMillis() - getCurrentConversationPanel() + .getLastIncomingMsgTimestamp().getTime() < 2*1000){ + int answer = JOptionPane.showConfirmDialog(ChatWindow.this, + Messages.getString("closeChatAfterNewMsg"), + Messages.getString("warning"), + JOptionPane.OK_CANCEL_OPTION, + JOptionPane.WARNING_MESSAGE); + + if(answer == JOptionPane.YES_OPTION){ + closeChat(); + } + } + else{ + closeChat(); + } + } /** * Closes the selected chat tab or the window if there * are no tabs.