Sketcher2 source code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
1.9 KiB

package com.jotuntech.sketcher.client;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.util.Arrays;
import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
public class JUserEntry extends JPanel {
private JLabel nameLabel;
private JPanel infoPanel;
private JProgressBar volumeBar;
private double slowVolume;
private int[] delayLine;
public JUserEntry(String name) {
setLayout(new BorderLayout());
setOpaque(false);
nameLabel = new JLabel(name);
add(nameLabel, BorderLayout.CENTER);
infoPanel = new JPanel();
infoPanel.setOpaque(false);
infoPanel.setLayout(new BoxLayout(infoPanel, BoxLayout.X_AXIS));
add(infoPanel, BorderLayout.EAST);
volumeBar = new JProgressBar(0, 32768);
volumeBar.setPreferredSize(new Dimension(64, 16));
volumeBar.setOpaque(false);
volumeBar.setValue(32768);
volumeBar.setEnabled(false);
volumeBar.setToolTipText(name + " is not on voice.");
infoPanel.add(volumeBar);
}
public void setVolume(int volume) {
setVolume(volume, 0);
}
public void setVolume(int volume, int delay) {
if(volume <= 0) {
volume = 1;
}
if(delayLine == null || delayLine.length <= delay) {
delayLine = new int[delay + 1];
Arrays.fill(delayLine, 1);
}
delayLine[delay] = volume;
double newVolume = Math.log(delayLine[0]) * 32768d / Math.log(32768);
for(int i = 0; i < delayLine.length - 1; i++) {
delayLine[i] = delayLine[i + 1];
}
delayLine[delayLine.length - 1] = 1;
slowVolume += (newVolume - slowVolume) * 0.333d;
volumeBar.setValue((int) Math.round(slowVolume));
if(!volumeBar.isEnabled()) {
volumeBar.setEnabled(true);
volumeBar.setToolTipText(nameLabel.getText() + " is on voice.");
}
}
public void clearVoice() {
volumeBar.setValue(32768);
volumeBar.setEnabled(false);
volumeBar.setToolTipText(nameLabel.getText() + " is not on voice.");
}
}