mirror of https://github.com/sipwise/jitsi.git
Introduces the possibility to call any number one has typed in the search field (Issue # 816 Calling certain numbers/contacts that are not in the user list is possible only if the full address/name is typed).
parent
f06e3d7de6
commit
463184bc56
|
After Width: | Height: | Size: 635 B |
|
After Width: | Height: | Size: 625 B |
@ -0,0 +1,297 @@
|
||||
package net.java.sip.communicator.impl.gui.main.contactlist;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.text.*;
|
||||
|
||||
import net.java.sip.communicator.impl.gui.*;
|
||||
import net.java.sip.communicator.impl.gui.main.call.*;
|
||||
import net.java.sip.communicator.service.protocol.*;
|
||||
import net.java.sip.communicator.util.*;
|
||||
import net.java.sip.communicator.util.swing.*;
|
||||
import net.java.sip.communicator.util.swing.plaf.*;
|
||||
|
||||
/**
|
||||
* The <tt>SearchTextFieldUI</tt> is the one responsible for the search field
|
||||
* look & feel. It draws a search icon inside the field and adjusts the bounds
|
||||
* of the editor rectangle according to it.
|
||||
*
|
||||
* @author Yana Stamcheva
|
||||
*/
|
||||
public class SearchFieldUI
|
||||
extends SIPCommTextFieldUI
|
||||
{
|
||||
/**
|
||||
* The icon indicating that this is a search field.
|
||||
*/
|
||||
private ImageIcon searchIcon;
|
||||
|
||||
/**
|
||||
* The default icon of the call button.
|
||||
*/
|
||||
private Image callIcon;
|
||||
|
||||
/**
|
||||
* The rollover icon of the call button.
|
||||
*/
|
||||
private Image callRolloverIcon;
|
||||
|
||||
/**
|
||||
* The call button in the search field.
|
||||
*/
|
||||
private SIPCommButton callButton;
|
||||
|
||||
/**
|
||||
* Indicates if the mouse is currently over the call button.
|
||||
*/
|
||||
private boolean isCallMouseOver = false;
|
||||
|
||||
/**
|
||||
* Creates a <tt>SIPCommTextFieldUI</tt>.
|
||||
*/
|
||||
public SearchFieldUI()
|
||||
{
|
||||
searchIcon = UtilActivator.getResources()
|
||||
.getImage("service.gui.icons.SEARCH_ICON");
|
||||
|
||||
callIcon = UtilActivator.getResources()
|
||||
.getImage("service.gui.buttons.SEARCH_CALL_ICON").getImage();
|
||||
|
||||
callRolloverIcon = UtilActivator.getResources()
|
||||
.getImage("service.gui.buttons.SEARCH_CALL_ROLLOVER_ICON")
|
||||
.getImage();
|
||||
|
||||
callButton = new SIPCommButton(callIcon, callRolloverIcon);
|
||||
|
||||
callButton.setToolTipText(GuiActivator.getResources()
|
||||
.getI18NString("service.gui.CALL_ANY_NUMBER"));
|
||||
callButton.setSize (callRolloverIcon.getWidth(null),
|
||||
callRolloverIcon.getHeight(null));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the custom mouse listeners defined in this class to the installed
|
||||
* listeners.
|
||||
*/
|
||||
protected void installListeners()
|
||||
{
|
||||
super.installListeners();
|
||||
|
||||
getComponent().addMouseListener(
|
||||
new TextFieldMouseListener());
|
||||
|
||||
getComponent().addMouseMotionListener(
|
||||
new TextFieldMouseMotionListener());
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements parent paintSafely method and enables antialiasing.
|
||||
* @param g the <tt>Graphics</tt> object that notified us
|
||||
*/
|
||||
protected void paintSafely(Graphics g)
|
||||
{
|
||||
customPaintBackground(g);
|
||||
super.paintSafely(g);
|
||||
}
|
||||
|
||||
/**
|
||||
* Paints the background of the associated component.
|
||||
* @param g the <tt>Graphics</tt> object used for painting
|
||||
*/
|
||||
protected void customPaintBackground(Graphics g)
|
||||
{
|
||||
Graphics2D g2 = (Graphics2D) g.create();
|
||||
|
||||
try
|
||||
{
|
||||
AntialiasingManager.activateAntialiasing(g2);
|
||||
super.customPaintBackground(g2);
|
||||
|
||||
JTextComponent c = this.getComponent();
|
||||
|
||||
int dy = (c.getY() + c.getHeight()) / 2
|
||||
- searchIcon.getIconHeight()/2;
|
||||
|
||||
g2.drawImage(searchIcon.getImage(), c.getX(), dy + 1, null);
|
||||
|
||||
// Paint call button.
|
||||
Rectangle callRect = getCallButtonRect();
|
||||
int dx = callRect.x;
|
||||
dy = callRect.y;
|
||||
|
||||
if (c.getText() != null
|
||||
&& c.getText().length() > 0)
|
||||
{
|
||||
if (isCallMouseOver)
|
||||
g2.drawImage(callRolloverIcon, dx, dy, null);
|
||||
else
|
||||
g2.drawImage(callIcon, dx, dy, null);
|
||||
}
|
||||
|
||||
}
|
||||
finally
|
||||
{
|
||||
g2.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If we are in the case of disabled delete button, we simply call the
|
||||
* parent implementation of this method, otherwise we recalculate the editor
|
||||
* rectangle in order to leave place for the delete button.
|
||||
* @return the visible editor rectangle
|
||||
*/
|
||||
protected Rectangle getVisibleEditorRect()
|
||||
{
|
||||
Rectangle rect = super.getVisibleEditorRect();
|
||||
|
||||
if ((rect.width > 0) && (rect.height > 0))
|
||||
{
|
||||
rect.x += searchIcon.getIconWidth() + 8;
|
||||
rect.width -= searchIcon.getIconWidth() + callButton.getWidth() + 15;
|
||||
return rect;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The <tt>MouseListener</tt> that listens for mouse events in order to
|
||||
* update the delete icon.
|
||||
*/
|
||||
protected class TextFieldMouseListener implements MouseListener
|
||||
{
|
||||
/**
|
||||
* Updates the call button when the mouse was clicked.
|
||||
* @param e the <tt>MouseEvent</tt> that notified us of the click
|
||||
*/
|
||||
public void mouseClicked(MouseEvent e)
|
||||
{
|
||||
updateCallIcon(e);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the call button when the mouse is enters the component area.
|
||||
* @param e the <tt>MouseEvent</tt> that notified us
|
||||
*/
|
||||
public void mouseEntered(MouseEvent e)
|
||||
{
|
||||
updateCallIcon(e);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the call button when the mouse exits the component area.
|
||||
* @param e the <tt>MouseEvent</tt> that notified us
|
||||
*/
|
||||
public void mouseExited(MouseEvent e)
|
||||
{
|
||||
updateCallIcon(e);
|
||||
}
|
||||
|
||||
public void mousePressed(MouseEvent e) {}
|
||||
|
||||
public void mouseReleased(MouseEvent e) {}
|
||||
}
|
||||
|
||||
/**
|
||||
* The <tt>MouseMotionListener</tt> that listens for mouse events in order
|
||||
* to update the delete icon.
|
||||
*/
|
||||
protected class TextFieldMouseMotionListener implements MouseMotionListener
|
||||
{
|
||||
/**
|
||||
* Updates the delete icon when the mouse is dragged over.
|
||||
* @param e the <tt>MouseEvent</tt> that notified us
|
||||
*/
|
||||
public void mouseDragged(MouseEvent e)
|
||||
{
|
||||
updateCallIcon(e);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the delete icon when the mouse is moved over.
|
||||
* @param e the <tt>MouseEvent</tt> that notified us
|
||||
*/
|
||||
public void mouseMoved(MouseEvent e)
|
||||
{
|
||||
updateCallIcon(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the delete icon, changes the cursor and deletes the content of
|
||||
* the associated text component when the mouse is pressed over the delete
|
||||
* icon.
|
||||
*
|
||||
* @param evt the mouse event that has prompted us to update the delete
|
||||
* icon.
|
||||
*/
|
||||
private void updateCallIcon(MouseEvent evt)
|
||||
{
|
||||
int x = evt.getX();
|
||||
int y = evt.getY();
|
||||
|
||||
Rectangle callButtonRect = getCallButtonRect();
|
||||
|
||||
if (callButtonRect.contains(x, y))
|
||||
{
|
||||
isCallMouseOver = true;
|
||||
getComponent().setCursor(Cursor.getDefaultCursor());
|
||||
|
||||
if (evt.getID() == MouseEvent.MOUSE_CLICKED)
|
||||
{
|
||||
JTextComponent c = getComponent();
|
||||
String searchText = c.getText();
|
||||
|
||||
if (searchText == null)
|
||||
return;
|
||||
|
||||
List<ProtocolProviderService> telephonyProviders
|
||||
= CallManager.getTelephonyProviders();
|
||||
|
||||
if (telephonyProviders.size() == 1)
|
||||
{
|
||||
CallManager.createCall(
|
||||
telephonyProviders.get(0), searchText);
|
||||
}
|
||||
else if (telephonyProviders.size() > 1)
|
||||
{
|
||||
ChooseCallAccountPopupMenu chooseAccountDialog
|
||||
= new ChooseCallAccountPopupMenu(
|
||||
c,
|
||||
searchText,
|
||||
telephonyProviders);
|
||||
|
||||
chooseAccountDialog
|
||||
.setLocation(getCallButtonRect().getLocation());
|
||||
chooseAccountDialog.showPopupMenu();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
isCallMouseOver = false;
|
||||
|
||||
getComponent().repaint();
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the call button rectangle.
|
||||
*
|
||||
* @return the call button rectangle
|
||||
*/
|
||||
protected Rectangle getCallButtonRect()
|
||||
{
|
||||
Component c = getComponent();
|
||||
Rectangle rect = c.getBounds();
|
||||
|
||||
int dx = getDeleteButtonRect().x - callButton.getWidth() - 2;
|
||||
int dy = (rect.y + rect.height) / 2 - callButton.getHeight()/2;
|
||||
|
||||
return new Rectangle( dx,
|
||||
dy,
|
||||
callButton.getWidth(),
|
||||
callButton.getHeight());
|
||||
}
|
||||
}
|
||||
@ -1,86 +0,0 @@
|
||||
package net.java.sip.communicator.util.swing.plaf;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.text.*;
|
||||
|
||||
import net.java.sip.communicator.util.*;
|
||||
import net.java.sip.communicator.util.swing.*;
|
||||
|
||||
/**
|
||||
* The <tt>SearchTextFieldUI</tt> is the one responsible for the search field
|
||||
* look & feel. It draws a search icon inside the field and adjusts the bounds
|
||||
* of the editor rectangle according to it.
|
||||
*
|
||||
* @author Yana Stamcheva
|
||||
*/
|
||||
public class SearchTextFieldUI
|
||||
extends SIPCommTextFieldUI
|
||||
{
|
||||
private ImageIcon searchImg;
|
||||
|
||||
/**
|
||||
* Creates a <tt>SIPCommTextFieldUI</tt>.
|
||||
*/
|
||||
public SearchTextFieldUI()
|
||||
{
|
||||
searchImg = UtilActivator.getResources()
|
||||
.getImage("service.gui.icons.SEARCH_ICON");
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements parent paintSafely method and enables antialiasing.
|
||||
* @param g the <tt>Graphics</tt> object that notified us
|
||||
*/
|
||||
protected void paintSafely(Graphics g)
|
||||
{
|
||||
customPaintBackground(g);
|
||||
super.paintSafely(g);
|
||||
}
|
||||
|
||||
/**
|
||||
* Paints the background of the associated component.
|
||||
* @param g the <tt>Graphics</tt> object used for painting
|
||||
*/
|
||||
protected void customPaintBackground(Graphics g)
|
||||
{
|
||||
Graphics2D g2 = (Graphics2D) g.create();
|
||||
|
||||
try
|
||||
{
|
||||
AntialiasingManager.activateAntialiasing(g2);
|
||||
super.customPaintBackground(g2);
|
||||
|
||||
JTextComponent c = this.getComponent();
|
||||
|
||||
int dy = (c.getY() + c.getHeight()) / 2
|
||||
- searchImg.getIconHeight()/2;
|
||||
|
||||
g2.drawImage(searchImg.getImage(), c.getX(), dy + 1, null);
|
||||
}
|
||||
finally
|
||||
{
|
||||
g2.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If we are in the case of disabled delete button, we simply call the
|
||||
* parent implementation of this method, otherwise we recalculate the editor
|
||||
* rectangle in order to leave place for the delete button.
|
||||
* @return the visible editor rectangle
|
||||
*/
|
||||
protected Rectangle getVisibleEditorRect()
|
||||
{
|
||||
Rectangle rect = super.getVisibleEditorRect();
|
||||
|
||||
if ((rect.width > 0) && (rect.height > 0))
|
||||
{
|
||||
rect.x += searchImg.getIconWidth() + 8;
|
||||
rect.width -= searchImg.getIconWidth() + 15;
|
||||
return rect;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue