Minor optimizations to .impl.gui.main.call wrt Map iterations, memory consumption because of fields.

cusax-fix
Lyubomir Marinov 17 years ago
parent f277264e9a
commit 201fc434a3

@ -19,7 +19,7 @@
import net.java.sip.communicator.util.*;
/**
* The AccountSelectorBox is located in the main application windwo under the
* The AccountSelectorBox is located in the main application window under the
* field where the telephone number is written. It contains all accounts that
* support telephony operation set and is meant to be used by user to select the
* account, which he/she would like to use when calling. The selected account
@ -36,13 +36,14 @@ public class AccountSelectorBox
private static final Logger logger =
Logger.getLogger(AccountSelectorBox.class);
private Hashtable accountsTable = new Hashtable();
private final Map<ProtocolProviderService, JMenuItem> accountsTable =
new Hashtable<ProtocolProviderService, JMenuItem>();
private SIPCommMenu menu = new SIPCommMenu();
private final SIPCommMenu menu = new SIPCommMenu();
private ProtocolProviderService selectedProvider;
private MainCallPanel parentCallPanel;
private final MainCallPanel parentCallPanel;
/**
* Creates an instance of AccountSelectorBox.
@ -59,7 +60,7 @@ public AccountSelectorBox(MainCallPanel parentPanel)
}
/**
* Adds an account to this accoult selector box. The account is represented
* Adds an account to this account selector box. The account is represented
* by its protocol provider.
*
* @param pps the protocol provider for the added account
@ -110,17 +111,13 @@ public void actionPerformed(ActionEvent e)
{
JMenuItem menuItem = (JMenuItem) e.getSource();
Enumeration i = accountsTable.keys();
while (i.hasMoreElements())
for (Map.Entry<ProtocolProviderService, JMenuItem> entry : accountsTable
.entrySet())
{
ProtocolProviderService pps =
(ProtocolProviderService) i.nextElement();
if (accountsTable.get(pps).equals(menuItem))
if (entry.getValue().equals(menuItem))
{
this.setSelected(pps, (ImageIcon) menuItem.getIcon());
this
.setSelected(entry.getKey(), (ImageIcon) menuItem.getIcon());
return;
}
}
@ -147,23 +144,19 @@ public Image createAccountStatusImage(ProtocolProviderService pps)
if (presence != null)
{
statusImage =
ImageLoader.getBytesInImage(presence.getPresenceStatus()
.getStatusIcon());
}
else if (pps.isRegistered())
else
{
statusImage =
ImageLoader.getBytesInImage(pps.getProtocolIcon().getIcon(
ProtocolIcon.ICON_SIZE_16x16));
}
else
{
statusImage =
LightGrayFilter.createDisabledImage(ImageLoader
.getBytesInImage(pps.getProtocolIcon().getIcon(
ProtocolIcon.ICON_SIZE_16x16)));
if (!pps.isRegistered())
{
statusImage = LightGrayFilter.createDisabledImage(statusImage);
}
}
int index = parentCallPanel.getMainFrame().getProviderIndex(pps);
@ -201,7 +194,7 @@ else if (pps.isRegistered())
*/
public void updateAccountStatus(ProtocolProviderService pps)
{
JMenuItem menuItem = (JMenuItem) accountsTable.get(pps);
JMenuItem menuItem = accountsTable.get(pps);
Icon icon = new ImageIcon(createAccountStatusImage(pps));
@ -241,15 +234,8 @@ public void setSelected(ProtocolProviderService pps, ImageIcon icon)
{
this.selectedProvider = pps;
SelectedObject selectedObject = new SelectedObject(icon, pps);
this.menu.setSelected(selectedObject);
String tooltipText;
tooltipText = pps.getAccountID().getUserID();
this.menu.setToolTipText(tooltipText);
this.menu.setSelected(new SelectedObject(icon, pps));
this.menu.setToolTipText(pps.getAccountID().getUserID());
this.parentCallPanel.setCallProvider(pps);
}
@ -306,15 +292,14 @@ public int getAccountsNumber()
*/
public void removeAccount(ProtocolProviderService pps)
{
JMenuItem accountItem = (JMenuItem) this.accountsTable.get(pps);
JMenuItem accountItem = this.accountsTable.get(pps);
this.menu.remove(accountItem);
this.accountsTable.remove(pps);
if (selectedProvider == pps && accountsTable.size() > 0)
setSelected((ProtocolProviderService) accountsTable.keys()
.nextElement());
setSelected(accountsTable.keySet().iterator().next());
}
/**
@ -324,17 +309,9 @@ public void removeAccount(ProtocolProviderService pps)
*/
private ProtocolProviderService findFirstRegisteredProvider()
{
Enumeration e = this.accountsTable.keys();
while (e.hasMoreElements())
{
ProtocolProviderService pps =
(ProtocolProviderService) e.nextElement();
for (ProtocolProviderService pps : accountsTable.keySet())
if (pps.isRegistered())
return pps;
}
return null;
}
}

@ -30,7 +30,7 @@ public class CallComboBox
{
public final static int MAX_COMBO_SIZE = 10;
private MainCallPanel parentCallPanel;
private final MainCallPanel parentCallPanel;
/**
* Creates a <tt>CallComboBox</tt> by specifying the parent panel, where
@ -68,10 +68,7 @@ public boolean isComboFieldEmpty()
{
String item = ((CallComboEditor) this.getEditor()).getItem().toString();
if (item.length() > 0)
return false;
else
return true;
return (item.length() <= 0);
}
/**
@ -113,9 +110,9 @@ protected void handleChange()
ContactList clist =
parentCallPanel.getMainFrame().getContactListPanel()
.getContactList();
int selectedIndex = clist.getSelectedIndex();
clist.removeSelectionInterval(clist.getSelectedIndex(), clist
.getSelectedIndex());
clist.removeSelectionInterval(selectedIndex, selectedIndex);
parentCallPanel.setCallButtonEnabled(true);
}
@ -125,12 +122,8 @@ protected void handleChange()
parentCallPanel.getMainFrame().getContactListPanel()
.getContactList().getSelectedValue();
boolean enabled = true;
if (o == null || !(o instanceof MetaContact))
{
// no contact can be called. call button not active
enabled = false;
}
// no contact can be called. call button not active
boolean enabled = (o instanceof MetaContact);
parentCallPanel.setCallButtonEnabled(enabled);

@ -32,9 +32,9 @@ public class CallDialog
private static final String HANGUP_BUTTON = "HangupButton";
DialpadDialog dialpadDialog;
private DialpadDialog dialpadDialog;
private CallPanel callPanel;
private final CallPanel callPanel;
/**
* Creates a <tt>CallDialog</tt> by specifying the underlying call panel.
@ -64,8 +64,9 @@ public CallDialog(CallPanel callPanel)
dialButton.addActionListener(this);
this.getContentPane().add(callPanel, BorderLayout.CENTER);
this.getContentPane().add(buttonsPanel, BorderLayout.SOUTH);
Container contentPane = getContentPane();
contentPane.add(callPanel, BorderLayout.CENTER);
contentPane.add(buttonsPanel, BorderLayout.SOUTH);
hangupButton.setName(HANGUP_BUTTON);

@ -356,13 +356,9 @@ public Iterator<CallParticipantPanel> getParticipantsPanels()
*/
public CallParticipantPanel getParticipantPanel(CallParticipant participant)
{
Iterator<Map.Entry<CallParticipant, CallParticipantPanel>> participants =
participantsPanels.entrySet().iterator();
while (participants.hasNext())
for (Map.Entry<CallParticipant, CallParticipantPanel> participantEntry : participantsPanels
.entrySet())
{
Map.Entry<CallParticipant, CallParticipantPanel> participantEntry =
participants.next();
CallParticipant entryParticipant = participantEntry.getKey();
if ((entryParticipant != null)

@ -19,6 +19,7 @@
import net.java.sip.communicator.impl.gui.utils.*;
import net.java.sip.communicator.service.audionotifier.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.resources.*;
import net.java.sip.communicator.util.*;
/**
@ -33,48 +34,6 @@ public class DialPanel
{
private Logger logger = Logger.getLogger(DialPanel.class);
private DialButton oneButton = new DialButton(
ImageLoader.getImage(ImageLoader.ONE_DIAL_BUTTON));
private DialButton twoButton = new DialButton(
ImageLoader.getImage(ImageLoader.TWO_DIAL_BUTTON));
private DialButton threeButton = new DialButton(
ImageLoader.getImage(ImageLoader.THREE_DIAL_BUTTON));
private DialButton fourButton = new DialButton(
ImageLoader.getImage(ImageLoader.FOUR_DIAL_BUTTON));
private DialButton fiveButton = new DialButton(
ImageLoader.getImage(ImageLoader.FIVE_DIAL_BUTTON));
private DialButton sixButton = new DialButton(
ImageLoader.getImage(ImageLoader.SIX_DIAL_BUTTON));
private DialButton sevenButton = new DialButton(
ImageLoader.getImage(ImageLoader.SEVEN_DIAL_BUTTON));
private DialButton eightButton = new DialButton(
ImageLoader.getImage(ImageLoader.EIGHT_DIAL_BUTTON));
private DialButton nineButton = new DialButton(
ImageLoader.getImage(ImageLoader.NINE_DIAL_BUTTON));
private DialButton starButton = new DialButton(
ImageLoader.getImage(ImageLoader.STAR_DIAL_BUTTON));
private DialButton zeroButton = new DialButton(
ImageLoader.getImage(ImageLoader.ZERO_DIAL_BUTTON));
private DialButton diezButton = new DialButton(
ImageLoader.getImage(ImageLoader.DIEZ_DIAL_BUTTON));
private int hgap = GuiActivator.getResources().
getSettingsInt("dialPadHorizontalGap");
private int vgap = GuiActivator.getResources().
getSettingsInt("dialPadVerticalGap");
/**
* Handles press and hold zero button action.
*/
@ -83,10 +42,13 @@ public class DialPanel
private boolean isTypedPlus = false;
private JPanel dialPadPanel = new JPanel(new GridLayout(4, 3, hgap, vgap));
private final JPanel dialPadPanel =
new JPanel(new GridLayout(4, 3, GuiActivator.getResources()
.getSettingsInt("dialPadHorizontalGap"), GuiActivator
.getResources().getSettingsInt("dialPadVerticalGap")));
private LinkedList<CallParticipant> callParticipantsList
= new LinkedList<CallParticipant>();
private final java.util.List<CallParticipant> callParticipantsList =
new LinkedList<CallParticipant>();
private MainCallPanel parentCallPanel;
@ -139,74 +101,43 @@ public void init()
this.plusZeroTimer.setRepeats(false);
oneButton.setAlignmentY(JButton.LEFT_ALIGNMENT);
twoButton.setAlignmentY(JButton.LEFT_ALIGNMENT);
threeButton.setAlignmentY(JButton.LEFT_ALIGNMENT);
fourButton.setAlignmentY(JButton.LEFT_ALIGNMENT);
fiveButton.setAlignmentY(JButton.LEFT_ALIGNMENT);
sixButton.setAlignmentY(JButton.LEFT_ALIGNMENT);
sevenButton.setAlignmentY(JButton.LEFT_ALIGNMENT);
eightButton.setAlignmentY(JButton.LEFT_ALIGNMENT);
nineButton.setAlignmentY(JButton.LEFT_ALIGNMENT);
zeroButton.setAlignmentY(JButton.LEFT_ALIGNMENT);
diezButton.setAlignmentY(JButton.LEFT_ALIGNMENT);
starButton.setAlignmentY(JButton.LEFT_ALIGNMENT);
oneButton.setName("one");
twoButton.setName("two");
threeButton.setName("three");
fourButton.setName("four");
fiveButton.setName("five");
sixButton.setName("six");
sevenButton.setName("seven");
eightButton.setName("eight");
nineButton.setName("nine");
zeroButton.setName("zero");
diezButton.setName("diez");
starButton.setName("star");
oneButton.addMouseListener(this);
twoButton.addMouseListener(this);
threeButton.addMouseListener(this);
fourButton.addMouseListener(this);
fiveButton.addMouseListener(this);
sixButton.addMouseListener(this);
sevenButton.addMouseListener(this);
eightButton.addMouseListener(this);
nineButton.addMouseListener(this);
zeroButton.addMouseListener(this);
diezButton.addMouseListener(this);
starButton.addMouseListener(this);
oneButton.setOpaque(false);
twoButton.setOpaque(false);
threeButton.setOpaque(false);
fourButton.setOpaque(false);
fiveButton.setOpaque(false);
sixButton.setOpaque(false);
sevenButton.setOpaque(false);
eightButton.setOpaque(false);
nineButton.setOpaque(false);
zeroButton.setOpaque(false);
diezButton.setOpaque(false);
starButton.setOpaque(false);
dialPadPanel.add(oneButton);
dialPadPanel.add(twoButton);
dialPadPanel.add(threeButton);
dialPadPanel.add(fourButton);
dialPadPanel.add(fiveButton);
dialPadPanel.add(sixButton);
dialPadPanel.add(sevenButton);
dialPadPanel.add(eightButton);
dialPadPanel.add(nineButton);
dialPadPanel.add(starButton);
dialPadPanel.add(zeroButton);
dialPadPanel.add(diezButton);
ImageID[] images =
new ImageID[]
{ ImageLoader.ONE_DIAL_BUTTON, ImageLoader.TWO_DIAL_BUTTON,
ImageLoader.THREE_DIAL_BUTTON, ImageLoader.FOUR_DIAL_BUTTON,
ImageLoader.FIVE_DIAL_BUTTON, ImageLoader.SIX_DIAL_BUTTON,
ImageLoader.SEVEN_DIAL_BUTTON, ImageLoader.EIGHT_DIAL_BUTTON,
ImageLoader.NINE_DIAL_BUTTON, ImageLoader.STAR_DIAL_BUTTON,
ImageLoader.ZERO_DIAL_BUTTON, ImageLoader.DIEZ_DIAL_BUTTON };
String[] names =
new String[]
{ "one", "two", "three", "four", "five", "six", "seven", "eight",
"nine", "star", "zero", "diez" };
final int buttonCount = images.length;
if (buttonCount != names.length)
throw new IllegalStateException("names");
Image bgImage = ImageLoader.getImage(ImageLoader.DIAL_BUTTON_BG);
for (int buttonIndex = 0; buttonIndex < buttonCount; buttonIndex++)
dialPadPanel.add(createDialButton(bgImage, images[buttonIndex],
names[buttonIndex]));
this.add(dialPadPanel, BorderLayout.CENTER);
}
private JButton createDialButton(Image bgImage, ImageID iconImage,
String name)
{
JButton button =
new SIPCommButton(bgImage, ImageLoader.getImage(iconImage));
button.setAlignmentY(JButton.LEFT_ALIGNMENT);
button.setName(name);
button.setOpaque(false);
button.addMouseListener(this);
return button;
}
public void mouseClicked(MouseEvent e)
{
}
@ -393,19 +324,6 @@ else if (buttonName.equals("star"))
if(dtmfTone != null)
this.sendDtmfTone(dtmfTone);
}
private class DialButton extends SIPCommButton
{
/**
* Creates an instance of <tt>MsgToolbarButton</tt>.
* @param iconImage The icon to display on this button.
*/
public DialButton(Image iconImage)
{
super( ImageLoader.getImage(ImageLoader.DIAL_BUTTON_BG),
iconImage);
}
}
/**
* Paints the main background image to the background of this dial panel.

@ -4,7 +4,6 @@
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.gui.main.call;
import java.awt.*;
@ -73,9 +72,9 @@ private void init()
this.bgPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
this.getContentPane().setLayout(new BorderLayout());
this.getContentPane().add(bgPanel, BorderLayout.CENTER);
Container contentPane = getContentPane();
contentPane.setLayout(new BorderLayout());
contentPane.add(bgPanel, BorderLayout.CENTER);
this.bgPanel.add(dialPanel, BorderLayout.CENTER);

@ -35,18 +35,8 @@ public class ReceivedCallDialog
private static final String HANGUP_BUTTON = "HangupButton";
private Logger logger = Logger.getLogger(ReceivedCallDialog.class);
private Call incomingCall;
/**
* Creates a <tt>ReceivedCallDialog</tt>
*/
public ReceivedCallDialog()
{
super();
}
/**
* Creates a <tt>ReceivedCallDialog</tt> by specifying the associated call.
*
@ -54,7 +44,7 @@ public ReceivedCallDialog()
*/
public ReceivedCallDialog(Call call)
{
this();
super();
this.incomingCall = call;

@ -13,13 +13,11 @@
import net.java.sip.communicator.impl.gui.utils.*;
import net.java.sip.communicator.impl.gui.i18n.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.media.*;
/**
* The UI button used to toggle on or off call securing
*
* @author Emanuel Onica
*
*/
public class SecureButton
extends JButton

Loading…
Cancel
Save