|
|
|
|
@ -4,17 +4,15 @@
|
|
|
|
|
* Distributable under LGPL license.
|
|
|
|
|
* See terms of license at gnu.org.
|
|
|
|
|
*/
|
|
|
|
|
package net.java.sip.communicator.impl.gui.main.call.conference;
|
|
|
|
|
package net.java.sip.communicator.util.swing;
|
|
|
|
|
|
|
|
|
|
import java.awt.*;
|
|
|
|
|
import java.awt.event.*;
|
|
|
|
|
|
|
|
|
|
import javax.swing.*;
|
|
|
|
|
|
|
|
|
|
import net.java.sip.communicator.impl.gui.main.call.*;
|
|
|
|
|
import net.java.sip.communicator.impl.gui.utils.*;
|
|
|
|
|
import net.java.sip.communicator.service.resources.*;
|
|
|
|
|
import net.java.sip.communicator.util.*;
|
|
|
|
|
import net.java.sip.communicator.util.skin.*;
|
|
|
|
|
import net.java.sip.communicator.util.swing.*;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Represents the sound level indicator for a particular peer.
|
|
|
|
|
@ -26,28 +24,33 @@
|
|
|
|
|
*/
|
|
|
|
|
public class SoundLevelIndicator
|
|
|
|
|
extends TransparentPanel
|
|
|
|
|
implements ComponentListener,
|
|
|
|
|
Skinnable
|
|
|
|
|
implements Skinnable
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Serial version UID.
|
|
|
|
|
*/
|
|
|
|
|
private static final long serialVersionUID = 0L;
|
|
|
|
|
|
|
|
|
|
private static final String SOUND_LEVEL_ACTIVE
|
|
|
|
|
= "service.gui.soundlevel.SOUND_LEVEL_ACTIVE";
|
|
|
|
|
|
|
|
|
|
private static final String SOUND_LEVEL_INACTIVE
|
|
|
|
|
= "service.gui.soundlevel.SOUND_LEVEL_INACTIVE";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Image when a sound level block is active
|
|
|
|
|
* The maximum possible sound level.
|
|
|
|
|
*/
|
|
|
|
|
private ImageIcon soundLevelActiveImage;
|
|
|
|
|
private final int maxSoundLevel;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Image when a sound level block is not active
|
|
|
|
|
* The minimum possible sound level.
|
|
|
|
|
*/
|
|
|
|
|
private ImageIcon soundLevelInactiveImage;
|
|
|
|
|
private final int minSoundLevel;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Current number of distinct sound levels displayed in the UI.
|
|
|
|
|
* The number of (distinct) sound bars displayed by this instance.
|
|
|
|
|
*/
|
|
|
|
|
private int soundBarNumber = 0;
|
|
|
|
|
private int soundBarCount;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The sound level which is currently depicted by this
|
|
|
|
|
@ -56,88 +59,30 @@ public class SoundLevelIndicator
|
|
|
|
|
private int soundLevel;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Indicates if the component listener is added.
|
|
|
|
|
*/
|
|
|
|
|
private boolean isComponentListenerAdded = false;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The minimum possible sound level.
|
|
|
|
|
*/
|
|
|
|
|
private final int minSoundLevel;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The maximum possible sound level.
|
|
|
|
|
* Image when a sound level block is active
|
|
|
|
|
*/
|
|
|
|
|
private final int maxSoundLevel;
|
|
|
|
|
private ImageIcon soundLevelActiveImage;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The renderer of the corresponding call, for which this sound level
|
|
|
|
|
* indicator is created.
|
|
|
|
|
* Image when a sound level block is not active
|
|
|
|
|
*/
|
|
|
|
|
private final CallRenderer callRenderer;
|
|
|
|
|
private ImageIcon soundLevelInactiveImage;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Constructor
|
|
|
|
|
* @param callRenderer the renderer of the corresponding call, for which
|
|
|
|
|
* this sound level indicator is created
|
|
|
|
|
* Initializes a new <tt>SoundLevelIndicator</tt> instance.
|
|
|
|
|
*
|
|
|
|
|
* @param minSoundLevel the minimum possible sound level
|
|
|
|
|
* @param maxSoundLevel the maximum possible sound level
|
|
|
|
|
*/
|
|
|
|
|
public SoundLevelIndicator( CallRenderer callRenderer,
|
|
|
|
|
int minSoundLevel,
|
|
|
|
|
int maxSoundLevel)
|
|
|
|
|
public SoundLevelIndicator(int minSoundLevel, int maxSoundLevel)
|
|
|
|
|
{
|
|
|
|
|
this.callRenderer = callRenderer;
|
|
|
|
|
|
|
|
|
|
this.minSoundLevel = minSoundLevel;
|
|
|
|
|
this.maxSoundLevel = maxSoundLevel;
|
|
|
|
|
this.soundLevel = minSoundLevel;
|
|
|
|
|
|
|
|
|
|
loadSkin();
|
|
|
|
|
|
|
|
|
|
this.soundBarNumber
|
|
|
|
|
= getSoundBarNumber(callRenderer.getCallContainer().getWidth());
|
|
|
|
|
|
|
|
|
|
if (soundBarNumber <= 0)
|
|
|
|
|
soundBarNumber = 8;
|
|
|
|
|
|
|
|
|
|
this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
|
|
|
|
|
|
|
|
|
|
this.initSoundBars();
|
|
|
|
|
|
|
|
|
|
this.addComponentListener(new ComponentAdapter()
|
|
|
|
|
{
|
|
|
|
|
@Override
|
|
|
|
|
public void componentResized(ComponentEvent e)
|
|
|
|
|
{
|
|
|
|
|
if (!isComponentListenerAdded)
|
|
|
|
|
{
|
|
|
|
|
Window parentWindow
|
|
|
|
|
= SwingUtilities.getWindowAncestor(
|
|
|
|
|
SoundLevelIndicator.this);
|
|
|
|
|
|
|
|
|
|
if (parentWindow != null)
|
|
|
|
|
{
|
|
|
|
|
parentWindow.addComponentListener(
|
|
|
|
|
SoundLevelIndicator.this);
|
|
|
|
|
isComponentListenerAdded = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Initializes sound bars.
|
|
|
|
|
*/
|
|
|
|
|
private void initSoundBars()
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < soundBarNumber; i++)
|
|
|
|
|
{
|
|
|
|
|
JLabel block = new JLabel(soundLevelInactiveImage);
|
|
|
|
|
block.setVerticalAlignment(JLabel.CENTER);
|
|
|
|
|
|
|
|
|
|
this.add(block);
|
|
|
|
|
}
|
|
|
|
|
setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -180,8 +125,8 @@ else if (soundLevel > maxSoundLevel)
|
|
|
|
|
*/
|
|
|
|
|
this.soundLevel = (int) (this.soundLevel * 0.8 + soundLevel * 0.2);
|
|
|
|
|
|
|
|
|
|
int activeBarNumber
|
|
|
|
|
= Math.round(this.soundLevel * soundBarNumber / (float) range);
|
|
|
|
|
int activeSoundBarCount
|
|
|
|
|
= Math.round(this.soundLevel * soundBarCount / (float) range);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* We cannot use getComponentCount() and then call getComponent(int)
|
|
|
|
|
@ -198,32 +143,30 @@ else if (soundLevel > maxSoundLevel)
|
|
|
|
|
if (c instanceof JLabel)
|
|
|
|
|
{
|
|
|
|
|
((JLabel) c).setIcon(
|
|
|
|
|
(i < activeBarNumber)
|
|
|
|
|
(i < activeSoundBarCount)
|
|
|
|
|
? soundLevelActiveImage
|
|
|
|
|
: soundLevelInactiveImage);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
this.repaint();
|
|
|
|
|
repaint();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void componentHidden(ComponentEvent e) {}
|
|
|
|
|
|
|
|
|
|
public void componentMoved(ComponentEvent e) {}
|
|
|
|
|
|
|
|
|
|
public void componentShown(ComponentEvent e) {}
|
|
|
|
|
public void resetSoundLevel()
|
|
|
|
|
{
|
|
|
|
|
soundLevel = minSoundLevel;
|
|
|
|
|
updateSoundLevel(minSoundLevel);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Adds/removes sound level bars to this component when it's resized.
|
|
|
|
|
* @param e the <tt>ComponentEvent</tt> which was triggered
|
|
|
|
|
*/
|
|
|
|
|
public void componentResized(ComponentEvent e)
|
|
|
|
|
@Override
|
|
|
|
|
public void setBounds(int x, int y, int width, int height)
|
|
|
|
|
{
|
|
|
|
|
int windowWidth = callRenderer.getCallContainer().getWidth();
|
|
|
|
|
int newNumber = getSoundBarNumber(windowWidth);
|
|
|
|
|
super.setBounds(x, y, width, height);
|
|
|
|
|
|
|
|
|
|
if (newNumber > 0)
|
|
|
|
|
int newSoundBarCount = getSoundBarCount(getWidth());
|
|
|
|
|
|
|
|
|
|
if (newSoundBarCount > 0)
|
|
|
|
|
{
|
|
|
|
|
while (newNumber < soundBarNumber)
|
|
|
|
|
while (newSoundBarCount < soundBarCount)
|
|
|
|
|
{
|
|
|
|
|
for (int i = getComponentCount() - 1; i >= 0; i--)
|
|
|
|
|
{
|
|
|
|
|
@ -231,23 +174,25 @@ public void componentResized(ComponentEvent e)
|
|
|
|
|
|
|
|
|
|
if (c instanceof JLabel)
|
|
|
|
|
{
|
|
|
|
|
this.remove(c);
|
|
|
|
|
soundBarNumber--;
|
|
|
|
|
remove(c);
|
|
|
|
|
soundBarCount--;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while (soundBarNumber < newNumber)
|
|
|
|
|
while (soundBarCount < newSoundBarCount)
|
|
|
|
|
{
|
|
|
|
|
JLabel block = new JLabel(soundLevelInactiveImage);
|
|
|
|
|
JLabel soundBar = new JLabel(soundLevelInactiveImage);
|
|
|
|
|
|
|
|
|
|
this.add(block);
|
|
|
|
|
soundBarNumber++;
|
|
|
|
|
soundBar.setVerticalAlignment(JLabel.CENTER);
|
|
|
|
|
add(soundBar);
|
|
|
|
|
soundBarCount++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.revalidate();
|
|
|
|
|
this.repaint();
|
|
|
|
|
updateSoundLevel(soundLevel);
|
|
|
|
|
revalidate();
|
|
|
|
|
repaint();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -258,13 +203,11 @@ public void componentResized(ComponentEvent e)
|
|
|
|
|
* @return the number of sound level bars that we could currently show in
|
|
|
|
|
* this panel
|
|
|
|
|
*/
|
|
|
|
|
private int getSoundBarNumber(int windowWidth)
|
|
|
|
|
private int getSoundBarCount(int width)
|
|
|
|
|
{
|
|
|
|
|
int barWidth = soundLevelActiveImage.getIconWidth();
|
|
|
|
|
int soundBarWidth = soundLevelActiveImage.getIconWidth();
|
|
|
|
|
|
|
|
|
|
// We deduct 150px from the given windowWidth because this is not the
|
|
|
|
|
// only component positioned on the horizontal axis.
|
|
|
|
|
return (windowWidth - 130)/barWidth;
|
|
|
|
|
return width / soundBarWidth;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -272,11 +215,43 @@ private int getSoundBarNumber(int windowWidth)
|
|
|
|
|
*/
|
|
|
|
|
public void loadSkin()
|
|
|
|
|
{
|
|
|
|
|
soundLevelActiveImage = new ImageIcon(
|
|
|
|
|
ImageLoader.getImage(ImageLoader.SOUND_LEVEL_ACTIVE));
|
|
|
|
|
soundLevelInactiveImage = new ImageIcon(
|
|
|
|
|
ImageLoader.getImage(ImageLoader.SOUND_LEVEL_INACTIVE));
|
|
|
|
|
ResourceManagementService resources = UtilActivator.getResources();
|
|
|
|
|
|
|
|
|
|
updateSoundLevel(minSoundLevel);
|
|
|
|
|
soundLevelActiveImage = resources.getImage(SOUND_LEVEL_ACTIVE);
|
|
|
|
|
soundLevelInactiveImage = resources.getImage(SOUND_LEVEL_INACTIVE);
|
|
|
|
|
|
|
|
|
|
if (!isPreferredSizeSet())
|
|
|
|
|
{
|
|
|
|
|
int preferredHeight = 0;
|
|
|
|
|
int preferredWidth = 0;
|
|
|
|
|
|
|
|
|
|
if (soundLevelActiveImage != null)
|
|
|
|
|
{
|
|
|
|
|
int height = soundLevelActiveImage.getIconHeight();
|
|
|
|
|
int width = soundLevelActiveImage.getIconWidth();
|
|
|
|
|
|
|
|
|
|
if (preferredHeight < height)
|
|
|
|
|
preferredHeight = height;
|
|
|
|
|
if (preferredWidth < width)
|
|
|
|
|
preferredWidth = width;
|
|
|
|
|
}
|
|
|
|
|
if (soundLevelInactiveImage != null)
|
|
|
|
|
{
|
|
|
|
|
int height = soundLevelInactiveImage.getIconHeight();
|
|
|
|
|
int width = soundLevelInactiveImage.getIconWidth();
|
|
|
|
|
|
|
|
|
|
if (preferredHeight < height)
|
|
|
|
|
preferredHeight = height;
|
|
|
|
|
if (preferredWidth < width)
|
|
|
|
|
preferredWidth = width;
|
|
|
|
|
}
|
|
|
|
|
if ((preferredHeight > 0) && (preferredWidth > 0))
|
|
|
|
|
setPreferredSize(
|
|
|
|
|
new Dimension(
|
|
|
|
|
10 * preferredWidth,
|
|
|
|
|
preferredHeight));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
updateSoundLevel(soundLevel);
|
|
|
|
|
}
|
|
|
|
|
}
|