Close/Open a group key combinations

cusax-fix
Yana Stamcheva 20 years ago
parent 3dc703cdfb
commit 333c32839a

@ -7,12 +7,16 @@
package net.java.sip.communicator.impl.gui.main.contactlist;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.AbstractAction;
import javax.swing.text.Position;
import net.java.sip.communicator.impl.gui.utils.Constants;
import net.java.sip.communicator.service.contactlist.MetaContact;
import net.java.sip.communicator.service.contactlist.MetaContactGroup;
/**
* Search the ContactList by typing a letter.
@ -49,51 +53,102 @@ public void keyTyped(KeyEvent e) {
long eventTimestamp = e.getWhen();
String keyChar = String.valueOf(e.getKeyChar());
if ((lastTypedTimestamp - eventTimestamp) > 1000) {
keyBuffer.delete(0, keyBuffer.length() - 1);
if(e.getKeyChar() == ' ') {
closeGroup();
}
this.lastTypedTimestamp = eventTimestamp;
this.keyBuffer.append(keyChar);
else if(e.getKeyChar() == '+') {
openGroup();
}
else if(e.getKeyChar() == '-') {
closeGroup();
}
else {
if ((lastTypedTimestamp - eventTimestamp) > 1000) {
keyBuffer.delete(0, keyBuffer.length() - 1);
}
this.lastTypedTimestamp = eventTimestamp;
this.keyBuffer.append(keyChar);
boolean selectedSameLetterContact = false;
boolean selectedSameLetterContact = false;
int selectedIndex = this.contactList.getSelectedIndex();
int selectedIndex = this.contactList.getSelectedIndex();
// Checks if there's any selected contact node and gets its name.
if (selectedIndex != -1) {
Object selectedObject = this.contactList.getSelectedValue();
// Checks if there's any selected contact node and gets its name.
if (selectedIndex != -1) {
Object selectedObject = this.contactList.getSelectedValue();
if (selectedObject instanceof MetaContact) {
String selectedContactName = ((MetaContact) selectedObject)
.getDisplayName();
if (selectedObject instanceof MetaContact) {
String selectedContactName = ((MetaContact) selectedObject)
.getDisplayName();
if (selectedContactName != null) {
selectedSameLetterContact = selectedContactName.substring(
0, 1).equalsIgnoreCase(keyBuffer.toString());
if (selectedContactName != null) {
selectedSameLetterContact
= selectedContactName.substring(0, 1)
.equalsIgnoreCase(keyBuffer.toString());
}
}
}
}
// The search starts from the beginning if:
// 1) the newly entered character is different from the last one
// or
// 2) the currently selected contact starts with a different letter
int contactIndex = -1;
if (lastTypedKey != keyChar || !selectedSameLetterContact) {
contactIndex = this.contactList.getNextMatch(keyBuffer.toString(),
0, Position.Bias.Forward);
} else {
contactIndex = this.contactList.getNextMatch(keyBuffer.toString(),
selectedIndex + 1, Position.Bias.Forward);
}
// The search starts from the beginning if:
// 1) the newly entered character is different from the last one
// or
// 2) the currently selected contact starts with a different letter
int contactIndex = -1;
if (lastTypedKey != keyChar || !selectedSameLetterContact) {
contactIndex = this.contactList.getNextMatch(
keyBuffer.toString(), 0, Position.Bias.Forward);
} else {
contactIndex = this.contactList.getNextMatch(
keyBuffer.toString(),
selectedIndex + 1, Position.Bias.Forward);
}
int currentlySelectedIndex = this.contactList.getSelectedIndex();
int currentlySelectedIndex = this.contactList.getSelectedIndex();
if (currentlySelectedIndex != contactIndex && contactIndex != -1) {
this.contactList.setSelectedIndex(contactIndex);
}
if (currentlySelectedIndex != contactIndex && contactIndex != -1) {
this.contactList.setSelectedIndex(contactIndex);
}
this.contactList.ensureIndexIsVisible(currentlySelectedIndex);
this.contactList.ensureIndexIsVisible(currentlySelectedIndex);
this.lastTypedKey = keyChar;
this.lastTypedKey = keyChar;
}
}
/**
* Closes a group when it's opened.
*/
public void closeGroup() {
Object selectedValue = this.contactList.getSelectedValue();
if (selectedValue instanceof MetaContactGroup) {
MetaContactGroup group = (MetaContactGroup) selectedValue;
ContactListModel model
= (ContactListModel)contactList.getModel();
if (!model.isGroupClosed(group)) {
model.closeGroup(group);
}
}
}
/**
* Opens a group when it's closed.
*/
public void openGroup() {
Object selectedValue = this.contactList.getSelectedValue();
if (selectedValue instanceof MetaContactGroup) {
MetaContactGroup group = (MetaContactGroup) selectedValue;
ContactListModel model
= (ContactListModel) contactList.getModel();
if (model.isGroupClosed(group)) {
model.openGroup(group);
}
}
}
}

@ -15,6 +15,7 @@
import java.awt.event.ActionListener;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.WindowAdapter;
@ -97,7 +98,6 @@ public ContactListPanel(MainFrame mainFrame) {
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
this.getVerticalScrollBar().setUnitIncrement(30);
}
/**
@ -118,20 +118,11 @@ public void initTree(MetaContactListService contactListService) {
this.getRootPane().getActionMap().put("runChat",
new RunMessageWindowAction());
this.getRootPane().getActionMap().put("closeGroup",
new CloseGroupAction());
this.getRootPane().getActionMap().put("openGroup",
new OpenGroupAction());
InputMap imap = this.getRootPane().getInputMap(
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "runChat");
imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0), "closeGroup");
imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, 0), "openGroup");
imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_MINUS, 0), "closeGroup");
imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0), "closeGroup");
imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0), "openGroup");
}
public ContactList getContactList() {
@ -686,46 +677,6 @@ else if (selectedValue instanceof MetaContactGroup) {
}
}
};
/**
* Closes a group when it's opened.
*/
private class CloseGroupAction extends AbstractAction {
public void actionPerformed(ActionEvent e) {
Object selectedValue = getContactList().getSelectedValue();
if (selectedValue instanceof MetaContactGroup) {
MetaContactGroup group = (MetaContactGroup) selectedValue;
ContactListModel model
= (ContactListModel)contactList.getModel();
if (!model.isGroupClosed(group)) {
model.closeGroup(group);
}
}
}
};
/**
* Opens a group when it's closed.
*/
private class OpenGroupAction extends AbstractAction {
public void actionPerformed(ActionEvent e) {
Object selectedValue = getContactList().getSelectedValue();
if (selectedValue instanceof MetaContactGroup) {
MetaContactGroup group = (MetaContactGroup) selectedValue;
ContactListModel model
= (ContactListModel)contactList.getModel();
if (model.isGroupClosed(group)) {
model.openGroup(group);
}
}
}
};
/**
* The TypingTimer is started after a PAUSED typing notification
@ -752,5 +703,5 @@ public void actionPerformed(ActionEvent e) {
private void setMetaContact(MetaContact metaContact) {
this.metaContact = metaContact;
}
}
}
}

@ -12,12 +12,14 @@
import java.awt.Color;
import java.awt.Font;
import java.awt.Image;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Map;
@ -199,6 +201,33 @@ public class Constants {
public static final boolean TABBED_CHAT_WINDOW = true;
/*
* ======================================================================
* ------------------------ SPECIAL CHARS LIST --------------------------
* ======================================================================
*/
private static final ArrayList specialCharsList = new ArrayList();
static{
specialCharsList.add(new Integer(KeyEvent.VK_PLUS));
specialCharsList.add(new Integer(KeyEvent.VK_MINUS));
specialCharsList.add(new Integer(KeyEvent.VK_SPACE));
specialCharsList.add(new Integer(KeyEvent.VK_ENTER));
specialCharsList.add(new Integer(KeyEvent.VK_LEFT));
specialCharsList.add(new Integer(KeyEvent.VK_RIGHT));
};
/**
* Checks if the given char is in the list of application special chars.
*
* @param charCode The char code.
*/
public static boolean isSpecialChar(int charCode) {
if(specialCharsList.contains(new Integer(charCode)))
return true;
else
return false;
}
/**
* Gets protocol logo icon.
*/

Loading…
Cancel
Save