escape closes the login and message windows

cusax-fix
Yana Stamcheva 20 years ago
parent 1135d2cf76
commit 83efce08fc

@ -16,13 +16,19 @@
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.AbstractAction;
import javax.swing.BorderFactory;
import javax.swing.InputMap;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.KeyStroke;
import net.java.sip.communicator.impl.gui.main.Account;
import net.java.sip.communicator.impl.gui.main.MainFrame;
@ -63,23 +69,15 @@ public class LoginWindow extends JDialog
private AccountManager accountManager;
private LoginManager loginManager;
private MainFrame mainFrame;
private String protocolName;
public LoginWindow( MainFrame mainFrame,
String protocolName,
AccountManager accountManager){
super(mainFrame);
this.mainFrame = mainFrame;
this.accountManager = accountManager;
this.protocolName = protocolName;
this.setModal(true);
this.backgroundPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
@ -97,8 +95,12 @@ public LoginWindow( MainFrame mainFrame,
this.setSize(370, 240);
this.setResizable(false);
this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
this.enableKeyActions();
}
private void init() {
this.uinComboBox = new JComboBox(this.accountManager
@ -211,4 +213,26 @@ protected void paintComponent(Graphics g) {
}
}
/**
* Enables the actions when a key is pressed, for now
* closes the window when esc is pressed.
*/
private void enableKeyActions(){
AbstractAction act = new AbstractAction()
{
public void actionPerformed(ActionEvent e)
{
LoginWindow.this.setVisible(false);
}
};
getRootPane().getActionMap().put("close", act);
InputMap imap =
this.getRootPane()
.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "close");
}
}

@ -8,13 +8,20 @@
package net.java.sip.communicator.impl.gui.main.message;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.util.Vector;
import javax.swing.AbstractAction;
import javax.swing.InputMap;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JSplitPane;
import javax.swing.KeyStroke;
import net.java.sip.communicator.impl.gui.main.MainFrame;
import net.java.sip.communicator.impl.gui.main.login.LoginWindow;
import net.java.sip.communicator.impl.gui.main.utils.ImageLoader;
import net.java.sip.communicator.service.contactlist.MetaContact;
@ -61,6 +68,8 @@ public MessageWindow (MainFrame parentWindow){
sendPanel = new MessageSendPanel(this);
this.init();
this.enableKeyActions();
}
public void init (){
@ -130,5 +139,25 @@ public ChatPanel getChatPanel() {
return chatPanel;
}
/**
* Enables the actions when a key is pressed, for now
* closes the window when esc is pressed.
*/
private void enableKeyActions(){
AbstractAction act = new AbstractAction()
{
public void actionPerformed(ActionEvent e)
{
MessageWindow.this.setVisible(false);
}
};
getRootPane().getActionMap().put("close", act);
InputMap imap =
this.getRootPane()
.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "close");
}
}

Loading…
Cancel
Save