mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-19 20:17:25 -05:00
Co-authored-by: Denny <denny@denny-desktop>
This commit is contained in:
@@ -52,6 +52,8 @@ import java.awt.EventQueue;
|
|||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.locks.Lock;
|
||||||
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
|
|
||||||
public class AudioChannelPanel extends JPanel implements Listener<AudioEvent>, SettingChangeListener
|
public class AudioChannelPanel extends JPanel implements Listener<AudioEvent>, SettingChangeListener
|
||||||
{
|
{
|
||||||
@@ -84,6 +86,7 @@ public class AudioChannelPanel extends JPanel implements Listener<AudioEvent>, S
|
|||||||
private Identifier mIdentifier;
|
private Identifier mIdentifier;
|
||||||
private List<Alias> mAliases = Collections.EMPTY_LIST;
|
private List<Alias> mAliases = Collections.EMPTY_LIST;
|
||||||
private AliasModel mAliasModel;
|
private AliasModel mAliasModel;
|
||||||
|
private Lock mLock = new ReentrantLock();
|
||||||
|
|
||||||
public AudioChannelPanel(IconManager iconManager, UserPreferences userPreferences, SettingsManager settingsManager,
|
public AudioChannelPanel(IconManager iconManager, UserPreferences userPreferences, SettingsManager settingsManager,
|
||||||
AudioOutput audioOutput, AliasModel aliasModel)
|
AudioOutput audioOutput, AliasModel aliasModel)
|
||||||
@@ -198,16 +201,27 @@ public class AudioChannelPanel extends JPanel implements Listener<AudioEvent>, S
|
|||||||
* Resets the from and to labels.
|
* Resets the from and to labels.
|
||||||
*/
|
*/
|
||||||
private void resetLabels()
|
private void resetLabels()
|
||||||
|
{
|
||||||
|
//Protect access to mIdentifier and mAliases
|
||||||
|
mLock.lock();
|
||||||
|
|
||||||
|
try
|
||||||
{
|
{
|
||||||
boolean updated = mIdentifier != null;
|
boolean updated = mIdentifier != null;
|
||||||
mIdentifier = null;
|
mIdentifier = null;
|
||||||
mAliases = Collections.EMPTY_LIST;
|
mAliases = Collections.EMPTY_LIST;
|
||||||
|
|
||||||
|
//Hold the lock through the label update
|
||||||
if(updated)
|
if(updated)
|
||||||
{
|
{
|
||||||
updateLabels();
|
updateLabels();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
mLock.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void updateIdentifiers(IdentifierCollection identifierCollection)
|
private void updateIdentifiers(IdentifierCollection identifierCollection)
|
||||||
{
|
{
|
||||||
@@ -227,6 +241,11 @@ public class AudioChannelPanel extends JPanel implements Listener<AudioEvent>, S
|
|||||||
|
|
||||||
boolean updated = false;
|
boolean updated = false;
|
||||||
|
|
||||||
|
//Protect access to mIdentifier and mAliases
|
||||||
|
mLock.lock();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
if(toIds.size() == 1)
|
if(toIds.size() == 1)
|
||||||
{
|
{
|
||||||
Identifier currentIdentifier = mIdentifier;
|
Identifier currentIdentifier = mIdentifier;
|
||||||
@@ -255,22 +274,31 @@ public class AudioChannelPanel extends JPanel implements Listener<AudioEvent>, S
|
|||||||
updated = true;
|
updated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Hold the lock through the label update
|
||||||
if(updated)
|
if(updated)
|
||||||
{
|
{
|
||||||
updateLabels();
|
updateLabels();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
mLock.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the alias label with text and icon from the alias. Note: this
|
* Updates the alias label with text and icon from the alias.
|
||||||
* does not occur on the Swing event thread -- wrap any calls to this
|
|
||||||
* method with an event thread call.
|
|
||||||
*/
|
*/
|
||||||
private void updateLabels()
|
private void updateLabels()
|
||||||
{
|
{
|
||||||
String identifier = null;
|
String identifier = null;
|
||||||
String iconName = null;
|
String iconName = null;
|
||||||
|
|
||||||
|
//Protect access to mIdentifier and mAliases
|
||||||
|
mLock.lock();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
if(mAliases.size() == 1)
|
if(mAliases.size() == 1)
|
||||||
{
|
{
|
||||||
identifier = mAliases.get(0).getName();
|
identifier = mAliases.get(0).getName();
|
||||||
@@ -292,19 +320,17 @@ public class AudioChannelPanel extends JPanel implements Listener<AudioEvent>, S
|
|||||||
}
|
}
|
||||||
|
|
||||||
final ImageIcon icon = iconName != null ? mIconManager.getIcon(iconName, 18) : null;
|
final ImageIcon icon = iconName != null ? mIconManager.getIcon(iconName, 18) : null;
|
||||||
|
|
||||||
final String identifierText = identifier;
|
final String identifierText = identifier;
|
||||||
|
|
||||||
EventQueue.invokeLater(new Runnable()
|
EventQueue.invokeLater(() -> {
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
mIdentifierLabel.setText(identifierText);
|
mIdentifierLabel.setText(identifierText);
|
||||||
mIconLabel.setIcon(icon);
|
mIconLabel.setIcon(icon);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
mLock.unlock();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -329,6 +355,7 @@ public class AudioChannelPanel extends JPanel implements Listener<AudioEvent>, S
|
|||||||
switch(colorSetting.getColorSettingName())
|
switch(colorSetting.getColorSettingName())
|
||||||
{
|
{
|
||||||
case CHANNEL_STATE_LABEL_DECODER:
|
case CHANNEL_STATE_LABEL_DECODER:
|
||||||
|
EventQueue.invokeLater(() -> {
|
||||||
if(mIdentifierLabel != null)
|
if(mIdentifierLabel != null)
|
||||||
{
|
{
|
||||||
mIdentifierLabel.setForeground(mLabelColor);
|
mIdentifierLabel.setForeground(mLabelColor);
|
||||||
@@ -337,6 +364,7 @@ public class AudioChannelPanel extends JPanel implements Listener<AudioEvent>, S
|
|||||||
{
|
{
|
||||||
mIconLabel.setForeground(mLabelColor);
|
mIconLabel.setForeground(mLabelColor);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user