mirror of https://github.com/sipwise/jitsi.git
parent
4850ca6995
commit
e992e1a7e7
@ -0,0 +1,276 @@
|
||||
/*
|
||||
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license.
|
||||
* See terms of license at gnu.org.
|
||||
*/
|
||||
package net.java.sip.communicator.impl.gui.main.call;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.beans.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.AbstractListModel;
|
||||
import javax.swing.ComboBoxEditor;
|
||||
import javax.swing.MutableComboBoxModel;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.event.DocumentEvent;
|
||||
import javax.swing.event.DocumentListener;
|
||||
|
||||
import net.java.sip.communicator.impl.gui.main.contactlist.*;
|
||||
import net.java.sip.communicator.service.contactlist.*;
|
||||
|
||||
/**
|
||||
* The <tt>CallComboBox</tt> is a history editable combo box that is positioned
|
||||
* above call and hangup buttons and is used when writing a number or a contact
|
||||
* name in order to be called.
|
||||
*
|
||||
* @author Yana Stamcheva
|
||||
*/
|
||||
public class CallComboBox
|
||||
extends JComboBox
|
||||
implements ActionListener,
|
||||
FocusListener
|
||||
{
|
||||
|
||||
private ArrayList historyList = new ArrayList();
|
||||
|
||||
private CallManager callManager;
|
||||
|
||||
public CallComboBox(CallManager callManager) {
|
||||
|
||||
this.callManager = callManager;
|
||||
|
||||
historyList.add("gigi@ekyga.net");
|
||||
historyList.add("sc3@voipgw.u-strasbg.fr");
|
||||
|
||||
setModel(new FilterableComboBoxModel(historyList));
|
||||
setEditor(new CallComboEditor());
|
||||
setEditable(true);
|
||||
setFocusable(true);
|
||||
|
||||
this.addActionListener(this);
|
||||
this.getEditor().getEditorComponent().addFocusListener(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this combo box editor field is empty. This will be the case if
|
||||
* the user hasn't selected an item from the combobox and hasn't written
|
||||
* anything the field.
|
||||
*
|
||||
* @return TRUE if the combobox editor field is empty, otherwise FALSE
|
||||
*/
|
||||
public boolean isComboFieldEmpty()
|
||||
{
|
||||
String item = ((CallComboEditor)this.getEditor()).getItem().toString();
|
||||
|
||||
if(item.length() > 0)
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles events triggered by user selection. Enables the call button
|
||||
* when user selects something the combo box.
|
||||
*/
|
||||
public void actionPerformed(ActionEvent e)
|
||||
{
|
||||
if(!isComboFieldEmpty()) {
|
||||
|
||||
callManager.setCallMetaContact(false);
|
||||
callManager.getCallButton().setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void focusGained(FocusEvent e)
|
||||
{
|
||||
this.callManager.setCallMetaContact(false);
|
||||
|
||||
ContactList clist = this.callManager.getMainFrame()
|
||||
.getContactListPanel().getContactList();
|
||||
clist.removeSelectionInterval(
|
||||
clist.getSelectedIndex(), clist.getSelectedIndex());
|
||||
}
|
||||
|
||||
public void focusLost(FocusEvent e)
|
||||
{}
|
||||
|
||||
public class FilterableComboBoxModel extends AbstractListModel
|
||||
implements MutableComboBoxModel {
|
||||
|
||||
private List items;
|
||||
private Filter filter;
|
||||
private List filteredItems;
|
||||
private Object selectedItem;
|
||||
|
||||
public FilterableComboBoxModel(List items) {
|
||||
|
||||
this.items = new ArrayList(items);
|
||||
filteredItems = new ArrayList(items.size());
|
||||
updateFilteredItems();
|
||||
}
|
||||
|
||||
public void addElement( Object obj ) {
|
||||
|
||||
items.add(obj);
|
||||
updateFilteredItems();
|
||||
}
|
||||
|
||||
public void removeElement( Object obj ) {
|
||||
|
||||
items.remove(obj);
|
||||
updateFilteredItems();
|
||||
}
|
||||
|
||||
public void removeElementAt(int index) {
|
||||
|
||||
items.remove(index);
|
||||
updateFilteredItems();
|
||||
}
|
||||
|
||||
public void insertElementAt( Object obj, int index ) {}
|
||||
|
||||
public void setFilter(Filter filter) {
|
||||
|
||||
this.filter = filter;
|
||||
updateFilteredItems();
|
||||
}
|
||||
|
||||
protected void updateFilteredItems() {
|
||||
|
||||
fireIntervalRemoved(this, 0, filteredItems.size());
|
||||
filteredItems.clear();
|
||||
|
||||
if (filter == null)
|
||||
filteredItems.addAll(items);
|
||||
else {
|
||||
for (Iterator iterator = items.iterator(); iterator.hasNext();) {
|
||||
|
||||
Object item = iterator.next();
|
||||
|
||||
if (filter.accept(item))
|
||||
filteredItems.add(item);
|
||||
}
|
||||
}
|
||||
fireIntervalAdded(this, 0, filteredItems.size());
|
||||
}
|
||||
|
||||
public int getSize() {
|
||||
return filteredItems.size();
|
||||
}
|
||||
|
||||
public Object getElementAt(int index) {
|
||||
return filteredItems.get(index);
|
||||
}
|
||||
|
||||
public Object getSelectedItem() {
|
||||
return selectedItem;
|
||||
}
|
||||
|
||||
public void setSelectedItem(Object val) {
|
||||
|
||||
if ((selectedItem == null) && (val == null))
|
||||
return;
|
||||
|
||||
if ((selectedItem != null) && selectedItem.equals(val))
|
||||
return;
|
||||
|
||||
if ((val != null) && val.equals(selectedItem))
|
||||
return;
|
||||
|
||||
selectedItem = val;
|
||||
fireContentsChanged(this, -1, -1);
|
||||
}
|
||||
}
|
||||
|
||||
public static interface Filter {
|
||||
public boolean accept(Object obj);
|
||||
}
|
||||
|
||||
class StartsWithFilter implements Filter {
|
||||
|
||||
private String prefix;
|
||||
public StartsWithFilter(String prefix) { this.prefix = prefix; }
|
||||
public boolean accept(Object o) { return o.toString().startsWith(prefix); }
|
||||
}
|
||||
|
||||
public class CallComboEditor
|
||||
implements ComboBoxEditor, DocumentListener
|
||||
{
|
||||
private JTextField text;
|
||||
private volatile boolean filtering = false;
|
||||
private volatile boolean setting = false;
|
||||
|
||||
public CallComboEditor() {
|
||||
|
||||
text = new JTextField(15);
|
||||
text.getDocument().addDocumentListener(this);
|
||||
}
|
||||
|
||||
public Component getEditorComponent() { return text; }
|
||||
|
||||
public void setItem(Object item) {
|
||||
|
||||
if(filtering)
|
||||
return;
|
||||
|
||||
setting = true;
|
||||
String newText = (item == null) ? "" : item.toString();
|
||||
text.setText(newText);
|
||||
setting = false;
|
||||
}
|
||||
|
||||
public Object getItem() {
|
||||
return text.getText();
|
||||
}
|
||||
|
||||
public void selectAll() { text.selectAll(); }
|
||||
|
||||
public void addActionListener(ActionListener l) {
|
||||
text.addActionListener(l);
|
||||
}
|
||||
|
||||
public void removeActionListener(ActionListener l) {
|
||||
text.removeActionListener(l);
|
||||
}
|
||||
|
||||
public void insertUpdate(DocumentEvent e) { handleChange(); }
|
||||
public void removeUpdate(DocumentEvent e) { handleChange(); }
|
||||
public void changedUpdate(DocumentEvent e) { }
|
||||
|
||||
protected void handleChange() {
|
||||
if (setting)
|
||||
return;
|
||||
|
||||
filtering = true;
|
||||
|
||||
Filter filter = null;
|
||||
if (text.getText().length() > 0) {
|
||||
filter = new StartsWithFilter(text.getText());
|
||||
|
||||
callManager.setCallMetaContact(false);
|
||||
|
||||
callManager.getCallButton().setEnabled(true);
|
||||
}
|
||||
else {
|
||||
Object o = callManager.getMainFrame().getContactListPanel()
|
||||
.getContactList().getSelectedValue();
|
||||
|
||||
if(o == null || !(o instanceof MetaContact))
|
||||
callManager.getCallButton().setEnabled(false);
|
||||
}
|
||||
|
||||
((FilterableComboBoxModel) getModel()).setFilter(filter);
|
||||
// A bit nasty but it seems to get the popup validated properly
|
||||
setPopupVisible(false);
|
||||
setPopupVisible(true);
|
||||
filtering = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,137 @@
|
||||
/*
|
||||
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license.
|
||||
* See terms of license at gnu.org.
|
||||
*/
|
||||
package net.java.sip.communicator.impl.gui.main.call;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
import net.java.sip.communicator.impl.gui.utils.*;
|
||||
import net.java.sip.communicator.service.protocol.*;
|
||||
|
||||
/**
|
||||
* The <tt>CallParticipantPanel</tt> is the panel containing data for a call
|
||||
* participant in a given call. It contains information like call participant
|
||||
* name, photo, call duration, etc.
|
||||
*
|
||||
* @author Yana Stamcheva
|
||||
*/
|
||||
public class CallParticipantPanel extends JPanel
|
||||
{
|
||||
JPanel contactPanel = new JPanel(new BorderLayout());
|
||||
|
||||
JPanel namePanel = new JPanel(new GridLayout(0, 1));
|
||||
|
||||
JLabel nameLabel = new JLabel("", JLabel.CENTER);
|
||||
|
||||
JLabel timeLabel = new JLabel("00:00:00", JLabel.CENTER);
|
||||
|
||||
JLabel photoLabel = new JLabel(new ImageIcon(
|
||||
ImageLoader.getImage(ImageLoader.DEFAULT_USER_PHOTO)));
|
||||
|
||||
Timer timer = new Timer(1000, new CallTimerListener());
|
||||
|
||||
JLabel stateLabel;
|
||||
|
||||
/**
|
||||
* Creates a <tt>CallParticipantPanel</tt> for the given call participant.
|
||||
*
|
||||
* @param participant the call participant
|
||||
*/
|
||||
public CallParticipantPanel(CallParticipant participant)
|
||||
{
|
||||
super(new BorderLayout());
|
||||
|
||||
stateLabel = new JLabel(participant.getState().getStateString(),
|
||||
JLabel.CENTER);
|
||||
|
||||
timer.setRepeats(true);
|
||||
|
||||
if(participant.getDisplayName() != null)
|
||||
nameLabel.setText(participant.getDisplayName());
|
||||
else
|
||||
nameLabel.setText(participant.getAddress());
|
||||
|
||||
namePanel.add(nameLabel);
|
||||
namePanel.add(stateLabel);
|
||||
namePanel.add(timeLabel);
|
||||
|
||||
contactPanel.add(photoLabel, BorderLayout.CENTER);
|
||||
contactPanel.add(namePanel, BorderLayout.SOUTH);
|
||||
|
||||
this.add(contactPanel, BorderLayout.NORTH);
|
||||
this.setPreferredSize(new Dimension(100, 200));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the state of the contained call participant.
|
||||
* @param state the state of the contained call participant
|
||||
*/
|
||||
public void setState(String state)
|
||||
{
|
||||
this.stateLabel.setText(state);
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the timer that counts call duration.
|
||||
*/
|
||||
public void startCallTimer()
|
||||
{
|
||||
timer.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops the timer that counts call duration.
|
||||
*/
|
||||
public void stopCallTimer()
|
||||
{
|
||||
timer.stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* Each second refreshes the time label to show to the user the exact
|
||||
* duration of the call.
|
||||
*/
|
||||
private class CallTimerListener implements ActionListener
|
||||
{
|
||||
private int timer = 0;
|
||||
|
||||
public void actionPerformed(ActionEvent e)
|
||||
{
|
||||
timer ++;
|
||||
int s = timer%60;
|
||||
int m = (timer - s)/60;
|
||||
int h = m/60;
|
||||
|
||||
timeLabel.setText(processTime(h)
|
||||
+ ":" + processTime(m)
|
||||
+ ":" + processTime(s));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a 0 in the beginning of one digit numbers.
|
||||
*
|
||||
* @param time The time parameter could be hours, minutes or seconds.
|
||||
* @return The formatted minutes string.
|
||||
*/
|
||||
private String processTime(int time)
|
||||
{
|
||||
String timeString = new Integer(time).toString();
|
||||
|
||||
String resultString = "";
|
||||
if (timeString.length() < 2)
|
||||
resultString = resultString.concat("0").concat(timeString);
|
||||
else
|
||||
resultString = timeString;
|
||||
|
||||
return resultString;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -1,93 +0,0 @@
|
||||
/*
|
||||
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license.
|
||||
* See terms of license at gnu.org.
|
||||
*/
|
||||
|
||||
package net.java.sip.communicator.impl.gui.main.call;
|
||||
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
|
||||
import net.java.sip.communicator.impl.gui.customcontrols.*;
|
||||
import net.java.sip.communicator.impl.gui.main.*;
|
||||
import net.java.sip.communicator.impl.gui.utils.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Yana Stamcheva
|
||||
*/
|
||||
public class CallReceivePanel extends JDialog {
|
||||
|
||||
private Image callButtonBG = ImageLoader
|
||||
.getImage(ImageLoader.CALL_BUTTON_BG);
|
||||
|
||||
private Image callButtonRolloverBG = ImageLoader
|
||||
.getImage(ImageLoader.CALL_ROLLOVER_BUTTON_BG);
|
||||
|
||||
private Image hangupButtonBG = ImageLoader
|
||||
.getImage(ImageLoader.HANGUP_BUTTON_BG);
|
||||
|
||||
private Image hangupButtonRolloverBG = ImageLoader
|
||||
.getImage(ImageLoader.HANGUP_ROLLOVER_BUTTON_BG);
|
||||
|
||||
private JLabel personPhoto = new JLabel(new ImageIcon(ImageLoader
|
||||
.getImage(ImageLoader.DEFAULT_USER_PHOTO)));
|
||||
|
||||
private JLabel personName = new JLabel("John Smith");
|
||||
|
||||
private JLabel birthDate = new JLabel("11/11/1900");
|
||||
|
||||
private JLabel emptyLabel = new JLabel(" ");
|
||||
|
||||
private JLabel personInfo = new JLabel("additional info");
|
||||
|
||||
private SIPCommButton callButton;
|
||||
|
||||
private SIPCommButton hangupButton;
|
||||
|
||||
private JPanel userInfoPanel = new JPanel();
|
||||
|
||||
private JPanel buttonsPanel = new JPanel(new FlowLayout(FlowLayout.CENTER,
|
||||
15, 5));
|
||||
|
||||
public CallReceivePanel(MainFrame parent) {
|
||||
|
||||
super(parent);
|
||||
|
||||
this.setSize(300, 200);
|
||||
|
||||
this.getContentPane().setLayout(new BorderLayout());
|
||||
|
||||
callButton = new SIPCommButton(callButtonBG, callButtonRolloverBG);
|
||||
|
||||
hangupButton = new SIPCommButton(
|
||||
hangupButtonBG, hangupButtonRolloverBG);
|
||||
|
||||
this.init();
|
||||
}
|
||||
|
||||
public void init() {
|
||||
this.personName.setFont(new Font("Sans Serif", Font.BOLD, 12));
|
||||
|
||||
// this.buttonsPanel.setBorder(BorderFactory.createMatteBorder(1, 0, 0,
|
||||
// 0, Color.GRAY));
|
||||
this.buttonsPanel.add(callButton);
|
||||
this.buttonsPanel.add(hangupButton);
|
||||
|
||||
this.userInfoPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 0,
|
||||
0));
|
||||
this.userInfoPanel.setLayout(new BoxLayout(userInfoPanel,
|
||||
BoxLayout.Y_AXIS));
|
||||
|
||||
this.userInfoPanel.add(personName);
|
||||
this.userInfoPanel.add(birthDate);
|
||||
this.userInfoPanel.add(emptyLabel);
|
||||
this.userInfoPanel.add(personInfo);
|
||||
|
||||
this.getContentPane().add(personPhoto, BorderLayout.WEST);
|
||||
this.getContentPane().add(userInfoPanel, BorderLayout.CENTER);
|
||||
this.getContentPane().add(buttonsPanel, BorderLayout.SOUTH);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue