use of org.jivesoftware.spark.plugin.ContextMenuListener in project Spark by igniterealtime.
the class PhonePlugin method setupPhoneSystem.
private void setupPhoneSystem() {
// Add Dial Menu
final JMenu viewMenu = SparkManager.getMainWindow().getMenuByName(Res.getString("menuitem.actions"));
JMenuItem dialNumberMenu = new JMenuItem(SparkRes.getImageIcon(SparkRes.ON_PHONE_IMAGE));
ResourceUtils.resButton(dialNumberMenu, Res.getString("button.dial.number"));
// Add Listener
dialNumberMenu.addActionListener(e -> {
dialPanel = new DialPanel();
dialPanel.getDialButton().addActionListener(e1 -> {
String number = dialPanel.getNumberToDial();
if (ModelUtil.hasLength(number)) {
dialPanel.setText(Res.getString("message.calling", number));
dialPanel.changeToRinging();
callExtension(number);
}
});
dialDialog = PhoneDialog.invoke(dialPanel, Res.getString("title.dial.phone"), Res.getString("message.number.to.call"), null);
dialPanel.getDialField().requestFocusInWindow();
dialPanel.getDialField().addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
if (e.getKeyChar() == KeyEvent.VK_ENTER) {
try {
String number = dialPanel.getNumberToDial();
if (ModelUtil.hasLength(number)) {
dialPanel.setText(Res.getString("message.calling", number));
dialPanel.changeToRinging();
callExtension(number);
}
e.consume();
} catch (Exception ex) {
Log.error(ex);
}
}
}
});
});
viewMenu.add(dialNumberMenu);
// Add ChatRoomListener to call users based on JID
SparkManager.getChatManager().addChatRoomListener(new ChatRoomListenerAdapter() {
public void chatRoomOpened(final ChatRoom room) {
if (room instanceof ChatRoomImpl) {
final ChatRoomButton callButton = new ChatRoomButton("", SparkRes.getImageIcon(SparkRes.TELEPHONE_24x24));
callButton.setToolTipText(Res.getString("tooltip.place.a.call"));
final ChatRoomImpl chatRoom = (ChatRoomImpl) room;
boolean phoneEnabled = false;
try {
phoneEnabled = phoneClient.isPhoneEnabled(XmppStringUtils.parseBareJid(chatRoom.getParticipantJID()));
} catch (Exception e) {
Log.error(e);
}
if (phoneEnabled) {
room.addChatRoomButton(callButton);
callButton.addActionListener(e -> callJID(chatRoom.getParticipantJID()));
}
}
}
});
ContactList contactList = SparkManager.getWorkspace().getContactList();
contactList.addContextMenuListener(new ContextMenuListener() {
public void poppingUp(Object object, final JPopupMenu popup) {
if (object instanceof ContactItem) {
final ContactItem item = (ContactItem) object;
boolean phoneEnabled = false;
try {
phoneEnabled = phoneClient.isPhoneEnabled(item.getJID());
} catch (Exception e) {
Log.error("There was an error retrieving phone information.", e);
}
if (phoneEnabled) {
Action callAction = new AbstractAction() {
private static final long serialVersionUID = 7221741748743018431L;
public void actionPerformed(ActionEvent e) {
callJID(item.getJID());
}
};
callAction.putValue(Action.NAME, "Call");
callAction.putValue(Action.SMALL_ICON, SparkRes.getImageIcon(SparkRes.ON_PHONE_IMAGE));
popup.add(callAction);
}
}
}
public void poppingDown(JPopupMenu popup) {
}
public boolean handleDefaultAction(MouseEvent e) {
return false;
}
});
}
Aggregations