#82 WIP - converted all classes to get icons from IconManager and removed icon management from the SettingsManager

This commit is contained in:
Denny
2017-01-08 21:06:02 -05:00
parent 488dc9da4c
commit b6498d048a
43 changed files with 4809 additions and 5084 deletions

View File

@@ -1,160 +1,162 @@
/*******************************************************************************
* SDR Trunk
* Copyright (C) 2015 Dennis Sheirer
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
* sdrtrunk
* Copyright (C) 2014-2017 Dennis Sheirer
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
******************************************************************************/
package module.decode.state;
import java.awt.Color;
import java.awt.Font;
import javax.swing.JLabel;
import javax.swing.JPanel;
import alias.Alias;
import icon.IconManager;
import sample.Listener;
import settings.ColorSetting;
import settings.ColorSetting.ColorSettingName;
import settings.Setting;
import settings.SettingChangeListener;
import settings.SettingsManager;
import alias.Alias;
public abstract class DecoderPanel extends JPanel
implements Listener<ChangedAttribute>, SettingChangeListener
import javax.swing.*;
import java.awt.*;
public abstract class DecoderPanel extends JPanel
implements Listener<ChangedAttribute>, SettingChangeListener
{
private static final long serialVersionUID = 1L;
private static final long serialVersionUID = 1L;
protected Font mFontDetails = new Font( Font.MONOSPACED, Font.PLAIN, 12 );
protected Font mFontDecoder = new Font( Font.MONOSPACED, Font.PLAIN, 12 );
protected Font mFontAuxDecoder = new Font( Font.MONOSPACED, Font.PLAIN, 10 );
protected Font mFontDetails = new Font(Font.MONOSPACED, Font.PLAIN, 12);
protected Font mFontDecoder = new Font(Font.MONOSPACED, Font.PLAIN, 12);
protected Font mFontAuxDecoder = new Font(Font.MONOSPACED, Font.PLAIN, 10);
public static final int ICON_SIZE = 12;
protected Color mColorLabelDetails;
protected Color mColorLabelDecoder;
protected Color mColorLabelAuxDecoder;
protected SettingsManager mSettingsManager;
protected IconManager mIconManager;
protected SettingsManager mSettingsManager;
protected DecoderState mDecoderState;
public DecoderPanel( SettingsManager settingsManager, DecoderState decoderState )
{
mSettingsManager = settingsManager;
mSettingsManager.addListener( this );
mDecoderState = decoderState;
mDecoderState.setChangedAttributeListener( this );
}
public void dispose()
{
mSettingsManager.removeListener( this );
mSettingsManager = null;
mDecoderState.removeChangedAttributeListener();
mDecoderState = null;
}
public DecoderState getDecoderState()
{
return mDecoderState;
}
protected void init()
{
getColors();
setOpaque( false ); //Use the parent panel's background color
}
public DecoderPanel(IconManager iconManager, SettingsManager settingsManager, DecoderState decoderState)
{
mIconManager = iconManager;
mSettingsManager = settingsManager;
mSettingsManager.addListener(this);
mDecoderState = decoderState;
mDecoderState.setChangedAttributeListener(this);
}
public void dispose()
{
mSettingsManager.removeListener(this);
mSettingsManager = null;
mDecoderState.removeChangedAttributeListener();
mDecoderState = null;
}
public DecoderState getDecoderState()
{
return mDecoderState;
}
protected void init()
{
getColors();
setOpaque(false); //Use the parent panel's background color
}
private void getColors()
{
mColorLabelDetails = mSettingsManager.getColorSetting(
ColorSettingName.CHANNEL_STATE_LABEL_DETAILS ).getColor();
mColorLabelDecoder = mSettingsManager.getColorSetting(
ColorSettingName.CHANNEL_STATE_LABEL_DECODER ).getColor();
mColorLabelAuxDecoder = mSettingsManager.getColorSetting(
ColorSettingName.CHANNEL_STATE_LABEL_AUX_DECODER ).getColor();
mColorLabelDetails = mSettingsManager.getColorSetting(
ColorSettingName.CHANNEL_STATE_LABEL_DETAILS).getColor();
mColorLabelDecoder = mSettingsManager.getColorSetting(
ColorSettingName.CHANNEL_STATE_LABEL_DECODER).getColor();
mColorLabelAuxDecoder = mSettingsManager.getColorSetting(
ColorSettingName.CHANNEL_STATE_LABEL_AUX_DECODER).getColor();
}
@Override
public void settingChanged( Setting setting )
@Override
public void settingChanged(Setting setting)
{
if( setting instanceof ColorSetting )
{
ColorSetting colorSetting = (ColorSetting)setting;
if(setting instanceof ColorSetting)
{
ColorSetting colorSetting = (ColorSetting) setting;
switch( colorSetting.getColorSettingName() )
{
case CHANNEL_STATE_LABEL_AUX_DECODER:
mColorLabelAuxDecoder = colorSetting.getColor();
repaint();
break;
case CHANNEL_STATE_LABEL_DECODER:
mColorLabelDecoder = colorSetting.getColor();
repaint();
break;
case CHANNEL_STATE_LABEL_DETAILS:
mColorLabelDetails = colorSetting.getColor();
repaint();
break;
default:
break;
}
}
switch(colorSetting.getColorSettingName())
{
case CHANNEL_STATE_LABEL_AUX_DECODER:
mColorLabelAuxDecoder = colorSetting.getColor();
repaint();
break;
case CHANNEL_STATE_LABEL_DECODER:
mColorLabelDecoder = colorSetting.getColor();
repaint();
break;
case CHANNEL_STATE_LABEL_DETAILS:
mColorLabelDetails = colorSetting.getColor();
repaint();
break;
default:
break;
}
}
}
@Override
public void settingDeleted( Setting setting ) {}
protected void setAliasLabel( final JLabel label, final Alias alias )
{
setAliasLabel( label, alias, true );
}
protected void setAliasLabel( final JLabel label, final Alias alias, boolean includeIcon )
{
if( alias != null )
{
label.setText( alias.getName() );
@Override
public void settingDeleted(Setting setting)
{
}
protected void setAliasLabel(final JLabel label, final Alias alias)
{
setAliasLabel(label, alias, true);
}
protected void setAliasLabel(final JLabel label, final Alias alias, boolean includeIcon)
{
if(alias != null)
{
label.setText(alias.getName());
if(includeIcon)
{
String iconName = alias.getIconName();
if(iconName != null)
{
label.setIcon(mIconManager.getIcon(iconName, IconManager.DEFAULT_ICON_SIZE));
}
else
{
label.setIcon(null);
}
}
else
{
label.setIcon(null);
}
}
else
{
label.setText("");
label.setIcon(null);
}
}
if( includeIcon )
{
String iconName = alias.getIconName();
if( iconName != null )
{
label.setIcon( mSettingsManager
.getImageIcon( iconName, SettingsManager.DEFAULT_ICON_SIZE ) );
}
else
{
label.setIcon( null );
}
}
else
{
label.setIcon( null );
}
}
else
{
label.setText( "" );
label.setIcon( null );
}
}
}