mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-12 16:47:31 -05:00
Updates pull request from Roman Tsypuk to convert the build system from
ant to gradle. Removes linux and windows application launch scripts and produces an executable jar with all resources included.
This commit is contained in:
190
src/main/java/io/github/dsheirer/settings/ColorSetting.java
Normal file
190
src/main/java/io/github/dsheirer/settings/ColorSetting.java
Normal file
@@ -0,0 +1,190 @@
|
||||
/*******************************************************************************
|
||||
* SDR Trunk
|
||||
* Copyright (C) 2014 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 io.github.dsheirer.settings;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlTransient;
|
||||
import java.awt.*;
|
||||
|
||||
public class ColorSetting extends Setting
|
||||
{
|
||||
@SuppressWarnings( "unused" )
|
||||
private static final int NO_TRANSLUCENCY = 255;
|
||||
private static final int SPECTRUM_TRANSLUCENCY = 128;
|
||||
private static final int CONFIG_TRANSLUCENCY = 60;
|
||||
|
||||
private String mRGB;
|
||||
private int mAlpha;
|
||||
private ColorSettingName mColorSettingName = ColorSettingName.UNKNOWN;
|
||||
|
||||
public ColorSetting()
|
||||
{
|
||||
setColor( mColorSettingName.getDefaultColor() );
|
||||
}
|
||||
|
||||
public ColorSetting( ColorSettingName name )
|
||||
{
|
||||
setColor( name.getDefaultColor() );
|
||||
setColorSettingName( name );
|
||||
}
|
||||
|
||||
@XmlAttribute
|
||||
public ColorSettingName getColorSettingName()
|
||||
{
|
||||
return mColorSettingName;
|
||||
}
|
||||
|
||||
public void setColorSettingName( ColorSettingName name )
|
||||
{
|
||||
mColorSettingName = name;
|
||||
}
|
||||
|
||||
@XmlAttribute
|
||||
public String getRgb()
|
||||
{
|
||||
return mRGB;
|
||||
}
|
||||
|
||||
public void setRgb( String value )
|
||||
{
|
||||
mRGB = value;
|
||||
}
|
||||
|
||||
@XmlAttribute
|
||||
public int getAlpha()
|
||||
{
|
||||
return mAlpha;
|
||||
}
|
||||
|
||||
public void setAlpha( int value )
|
||||
{
|
||||
mAlpha = value;
|
||||
}
|
||||
|
||||
@XmlTransient
|
||||
public Color getColor()
|
||||
{
|
||||
Color temp = Color.decode( mRGB );
|
||||
|
||||
return new Color( temp.getRed(),
|
||||
temp.getGreen(),
|
||||
temp.getBlue(),
|
||||
mAlpha );
|
||||
}
|
||||
|
||||
public void setColor( Color color )
|
||||
{
|
||||
mRGB = Integer.toHexString( color.getRGB() );
|
||||
mRGB = "#" + mRGB.substring( 2, mRGB.length() );
|
||||
mAlpha = color.getAlpha();
|
||||
}
|
||||
|
||||
public static Color getTranslucent( Color color, int translucency )
|
||||
{
|
||||
return new Color( color.getRed(),
|
||||
color.getGreen(),
|
||||
color.getBlue(),
|
||||
translucency );
|
||||
}
|
||||
|
||||
public enum ColorSettingName
|
||||
{
|
||||
CHANNEL_CONFIG( getTranslucent( Color.LIGHT_GRAY, CONFIG_TRANSLUCENCY ),
|
||||
"Channel", "Channel Color" ),
|
||||
CHANNEL_CONFIG_PROCESSING( getTranslucent( Color.GREEN, CONFIG_TRANSLUCENCY ),
|
||||
"Channel Processing", "Processing Channel Color" ),
|
||||
CHANNEL_CONFIG_SELECTED( getTranslucent( Color.BLUE, CONFIG_TRANSLUCENCY ),
|
||||
"Channel Selected", "Selected Channel Color" ),
|
||||
|
||||
CHANNEL_STATE_BACKGROUND( Color.BLACK, "Background",
|
||||
"Channel State Background" ),
|
||||
CHANNEL_STATE_GRADIENT_TOP_CALL( Color.BLACK,
|
||||
"Call Gradient Top", "Channel Call State Gradient Top" ),
|
||||
CHANNEL_STATE_GRADIENT_MIDDLE_CALL( Color.BLUE,
|
||||
"Call Gradient Middle", "Channel Call State Gradient Middle" ),
|
||||
CHANNEL_STATE_GRADIENT_TOP_CONTROL( Color.BLACK,
|
||||
"Control Gradient Top", "Channel Control State Gradient Top" ),
|
||||
CHANNEL_STATE_GRADIENT_MIDDLE_CONTROL( new Color( 0xC64F00 ),
|
||||
"Control Gradient Middle", "Channel Control State Gradient Middle" ),
|
||||
CHANNEL_STATE_GRADIENT_TOP_DATA( Color.BLACK,
|
||||
"Data Gradient Top", "Channel Data State Gradient Top" ),
|
||||
CHANNEL_STATE_GRADIENT_MIDDLE_DATA( new Color( 0xCC00CC ),
|
||||
"Data Gradient Middle", "Channel Data State Gradient Middle" ),
|
||||
CHANNEL_STATE_GRADIENT_TOP_FADE( Color.BLACK,
|
||||
"Fade Gradient Top", "Channel Fade State Gradient Top" ),
|
||||
CHANNEL_STATE_GRADIENT_MIDDLE_FADE( Color.DARK_GRAY,
|
||||
"Fade Gradient Middle", "Channel Fade State Gradient Middle" ),
|
||||
CHANNEL_STATE_GRADIENT_TOP_IDLE( Color.BLACK,
|
||||
"Idle Gradient Top", "Channel Idle State Gradient Top" ),
|
||||
CHANNEL_STATE_GRADIENT_MIDDLE_IDLE( Color.DARK_GRAY,
|
||||
"Idle Gradient Middle", "Channel Idle State Gradient Middle" ),
|
||||
CHANNEL_STATE_GRADIENT_TOP_NO_TUNER( Color.RED,
|
||||
"No Tuner Gradient Top", "Channel No Tuner State Gradient Top" ),
|
||||
CHANNEL_STATE_GRADIENT_MIDDLE_NO_TUNER( new Color( 0x990000 ),
|
||||
"No Tuner Gradient Middle", "Channel No Tuner State Gradient Middle" ),
|
||||
CHANNEL_STATE_LABEL_DETAILS( Color.LIGHT_GRAY,
|
||||
"Details", "Details Label Color" ),
|
||||
CHANNEL_STATE_LABEL_DECODER( Color.GREEN,
|
||||
"Decoder", "Decoder Label Color" ),
|
||||
CHANNEL_STATE_LABEL_AUX_DECODER( Color.YELLOW,
|
||||
"Aux Decoder", "Aux Decoder Label Color" ),
|
||||
CHANNEL_STATE_SELECTED_CHANNEL( Color.YELLOW,
|
||||
"Selected Channel Indicator", "Selected Channel Indicator Color" ),
|
||||
|
||||
SPECTRUM_BACKGROUND( Color.BLACK,
|
||||
"Background", "Spectrum Background Color" ),
|
||||
SPECTRUM_CURSOR( Color.ORANGE,
|
||||
"Cursor", "Spectrum Cursor Color" ),
|
||||
SPECTRUM_GRADIENT_BOTTOM( getTranslucent( Color.GREEN, SPECTRUM_TRANSLUCENCY ),
|
||||
"Gradient Bottom", "Spectrum Gradient Bottom Color" ),
|
||||
SPECTRUM_GRADIENT_TOP( getTranslucent( Color.WHITE, SPECTRUM_TRANSLUCENCY ),
|
||||
"Gradient Top", "Spectrum Gradient Top Color" ),
|
||||
SPECTRUM_LINE( getTranslucent( Color.LIGHT_GRAY, SPECTRUM_TRANSLUCENCY ),
|
||||
"Line", "Spectrum Lines and Text Color" ),
|
||||
|
||||
UNKNOWN( Color.RED, "Unknown", "Unknown Setting Color" );
|
||||
|
||||
private Color mDefaultColor;
|
||||
private String mLabel;
|
||||
private String mDialogTitle;
|
||||
|
||||
private ColorSettingName( Color defaultColor,
|
||||
String label,
|
||||
String dialogTitle )
|
||||
{
|
||||
mDefaultColor = defaultColor;
|
||||
mLabel = label;
|
||||
mDialogTitle = dialogTitle;
|
||||
}
|
||||
|
||||
public Color getDefaultColor()
|
||||
{
|
||||
return mDefaultColor;
|
||||
}
|
||||
|
||||
public String getLabel()
|
||||
{
|
||||
return mLabel;
|
||||
}
|
||||
|
||||
public String getDialogTitle()
|
||||
{
|
||||
return mDialogTitle;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/*******************************************************************************
|
||||
* SDR Trunk
|
||||
* Copyright (C) 2014 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 io.github.dsheirer.settings;
|
||||
|
||||
import io.github.dsheirer.settings.ColorSetting.ColorSettingName;
|
||||
import io.github.dsheirer.util.ColorIcon;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
/**
|
||||
* JMenuItem for selecting a color and automatically setting (saving) the
|
||||
* color selection in the settings manager
|
||||
*/
|
||||
public class ColorSettingMenuItem extends JMenuItem
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private ColorSettingName mColorSettingName;
|
||||
private SettingsManager mSettingsManager;
|
||||
private Color mCurrentColor;
|
||||
|
||||
public ColorSettingMenuItem( SettingsManager settingsManager,
|
||||
ColorSettingName colorSettingName )
|
||||
{
|
||||
super( colorSettingName.getLabel() );
|
||||
|
||||
mSettingsManager = settingsManager;
|
||||
mColorSettingName = colorSettingName;
|
||||
|
||||
mCurrentColor = mSettingsManager
|
||||
.getColorSetting( mColorSettingName ).getColor();
|
||||
|
||||
this.setIcon( new ColorIcon( mCurrentColor ) );
|
||||
|
||||
addActionListener( new ActionListener()
|
||||
{
|
||||
@Override
|
||||
public void actionPerformed( ActionEvent e )
|
||||
{
|
||||
Color newColor = JColorChooser.showDialog( ColorSettingMenuItem.this,
|
||||
mColorSettingName.getDialogTitle(),
|
||||
mCurrentColor );
|
||||
|
||||
if( newColor != null )
|
||||
{
|
||||
mSettingsManager.setColorSetting( mColorSettingName, newColor );
|
||||
}
|
||||
}
|
||||
} );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*******************************************************************************
|
||||
* SDR Trunk
|
||||
* Copyright (C) 2014 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 io.github.dsheirer.settings;
|
||||
|
||||
import io.github.dsheirer.settings.ColorSetting.ColorSettingName;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
/**
|
||||
* JMenuItem for selecting a color and automatically setting (saving) the
|
||||
* color selection in the settings manager
|
||||
*/
|
||||
public class ColorSettingResetAllMenuItem extends JMenuItem
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private SettingsManager mSettingsManager;
|
||||
|
||||
public ColorSettingResetAllMenuItem( SettingsManager settingsManager,
|
||||
ColorSettingName colorSettingName )
|
||||
{
|
||||
super( "Reset - " + colorSettingName.getLabel() );
|
||||
|
||||
mSettingsManager = settingsManager;
|
||||
|
||||
addActionListener( new ActionListener()
|
||||
{
|
||||
@Override
|
||||
public void actionPerformed( ActionEvent e )
|
||||
{
|
||||
mSettingsManager.resetAllColorSettings();
|
||||
}
|
||||
} );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*******************************************************************************
|
||||
* SDR Trunk
|
||||
* Copyright (C) 2014 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 io.github.dsheirer.settings;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
/**
|
||||
* JMenuItem for selecting a color and automatically setting (saving) the
|
||||
* color selection in the settings manager
|
||||
*/
|
||||
public class ColorSettingResetMenuItem extends JMenuItem
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private ColorSetting.ColorSettingName mColorSettingName;
|
||||
private SettingsManager mSettingsManager;
|
||||
|
||||
public ColorSettingResetMenuItem( SettingsManager settingsManager,
|
||||
ColorSetting.ColorSettingName colorSettingName )
|
||||
{
|
||||
super( "Reset - " + colorSettingName.getLabel() );
|
||||
|
||||
mSettingsManager = settingsManager;
|
||||
mColorSettingName = colorSettingName;
|
||||
|
||||
addActionListener( new ActionListener()
|
||||
{
|
||||
@Override
|
||||
public void actionPerformed( ActionEvent e )
|
||||
{
|
||||
mSettingsManager.resetColorSetting( mColorSettingName );
|
||||
}
|
||||
} );
|
||||
}
|
||||
}
|
||||
52
src/main/java/io/github/dsheirer/settings/FileSetting.java
Normal file
52
src/main/java/io/github/dsheirer/settings/FileSetting.java
Normal file
@@ -0,0 +1,52 @@
|
||||
/*******************************************************************************
|
||||
* SDR Trunk
|
||||
* Copyright (C) 2014 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 io.github.dsheirer.settings;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
|
||||
public class FileSetting extends Setting
|
||||
{
|
||||
private String mPath;
|
||||
|
||||
public FileSetting()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public FileSetting( String name, String path )
|
||||
{
|
||||
super( name );
|
||||
setPath( path );
|
||||
}
|
||||
|
||||
public String getPath()
|
||||
{
|
||||
return mPath;
|
||||
}
|
||||
|
||||
public void setPath( String value )
|
||||
{
|
||||
mPath = value;
|
||||
}
|
||||
|
||||
public File getFile()
|
||||
{
|
||||
return new File( mPath );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package io.github.dsheirer.settings;
|
||||
|
||||
import org.jdesktop.swingx.mapviewer.GeoPosition;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlTransient;
|
||||
|
||||
public class MapViewSetting extends Setting
|
||||
{
|
||||
private double mLatitude;
|
||||
private double mLongitude;
|
||||
private int mZoom;
|
||||
|
||||
public MapViewSetting()
|
||||
{
|
||||
/* Empty constructor for JAXB */
|
||||
}
|
||||
|
||||
public MapViewSetting( String name, double latitude, double longitude, int zoom )
|
||||
{
|
||||
super( name );
|
||||
mLatitude = latitude;
|
||||
mLongitude = longitude;
|
||||
mZoom = zoom;
|
||||
}
|
||||
|
||||
public MapViewSetting( String name, GeoPosition position, int zoom )
|
||||
{
|
||||
super( name );
|
||||
mLatitude = position.getLatitude();
|
||||
mLongitude = position.getLongitude();
|
||||
mZoom = zoom;
|
||||
}
|
||||
|
||||
@XmlAttribute
|
||||
public double getLatitude()
|
||||
{
|
||||
return mLatitude;
|
||||
}
|
||||
|
||||
public void setLatitude( double latitude )
|
||||
{
|
||||
mLatitude = latitude;
|
||||
}
|
||||
|
||||
@XmlAttribute
|
||||
public double getLongitude()
|
||||
{
|
||||
return mLongitude;
|
||||
}
|
||||
|
||||
public void setLongitude( double longitude )
|
||||
{
|
||||
mLongitude = longitude;
|
||||
}
|
||||
|
||||
@XmlAttribute
|
||||
public int getZoom()
|
||||
{
|
||||
return mZoom;
|
||||
}
|
||||
|
||||
public void setZoom( int zoom )
|
||||
{
|
||||
mZoom = zoom;
|
||||
}
|
||||
|
||||
@XmlTransient
|
||||
public GeoPosition getGeoPosition()
|
||||
{
|
||||
return new GeoPosition( mLatitude, mLongitude );
|
||||
}
|
||||
|
||||
public void setGeoPosition( GeoPosition position )
|
||||
{
|
||||
mLatitude = position.getLatitude();
|
||||
mLongitude = position.getLongitude();
|
||||
}
|
||||
}
|
||||
45
src/main/java/io/github/dsheirer/settings/Setting.java
Normal file
45
src/main/java/io/github/dsheirer/settings/Setting.java
Normal file
@@ -0,0 +1,45 @@
|
||||
/*******************************************************************************
|
||||
* SDR Trunk
|
||||
* Copyright (C) 2014 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 io.github.dsheirer.settings;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
|
||||
public class Setting
|
||||
{
|
||||
protected String mName;
|
||||
|
||||
public Setting()
|
||||
{
|
||||
}
|
||||
|
||||
public Setting( String name )
|
||||
{
|
||||
mName = name;
|
||||
}
|
||||
|
||||
@XmlAttribute
|
||||
public String getName()
|
||||
{
|
||||
return mName;
|
||||
}
|
||||
|
||||
public void setName( String name )
|
||||
{
|
||||
mName = name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/*******************************************************************************
|
||||
* SDR Trunk
|
||||
* Copyright (C) 2014 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 io.github.dsheirer.settings;
|
||||
|
||||
public interface SettingChangeListener
|
||||
{
|
||||
public void settingChanged( Setting setting );
|
||||
public void settingDeleted( Setting setting );
|
||||
}
|
||||
235
src/main/java/io/github/dsheirer/settings/Settings.java
Normal file
235
src/main/java/io/github/dsheirer/settings/Settings.java
Normal file
@@ -0,0 +1,235 @@
|
||||
/*******************************************************************************
|
||||
* SDR Trunk
|
||||
* Copyright (C) 2014-2016 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 io.github.dsheirer.settings;
|
||||
|
||||
import io.github.dsheirer.map.DefaultIcon;
|
||||
import io.github.dsheirer.map.MapIcon;
|
||||
import io.github.dsheirer.settings.ColorSetting.ColorSettingName;
|
||||
import io.github.dsheirer.source.recording.RecordingConfiguration;
|
||||
import io.github.dsheirer.source.tuner.airspy.AirspyTunerConfiguration;
|
||||
import io.github.dsheirer.source.tuner.configuration.TunerConfiguration;
|
||||
import io.github.dsheirer.source.tuner.fcd.proV1.FCD1TunerConfiguration;
|
||||
import io.github.dsheirer.source.tuner.fcd.proplusV2.FCD2TunerConfiguration;
|
||||
import io.github.dsheirer.source.tuner.hackrf.HackRFTunerConfiguration;
|
||||
import io.github.dsheirer.source.tuner.rtl.e4k.E4KTunerConfiguration;
|
||||
import io.github.dsheirer.source.tuner.rtl.r820t.R820TTunerConfiguration;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.XmlSeeAlso;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Support for persisting via JAXB all configured SDRTrunk settings
|
||||
*/
|
||||
@XmlSeeAlso( { AirspyTunerConfiguration.class,
|
||||
ColorSetting.class,
|
||||
DefaultIcon.class,
|
||||
E4KTunerConfiguration.class,
|
||||
FCD1TunerConfiguration.class,
|
||||
FCD2TunerConfiguration.class,
|
||||
FileSetting.class,
|
||||
HackRFTunerConfiguration.class,
|
||||
MapViewSetting.class,
|
||||
MapIcon.class,
|
||||
R820TTunerConfiguration.class,
|
||||
RecordingConfiguration.class,
|
||||
Setting.class,
|
||||
TunerConfiguration.class } )
|
||||
|
||||
@XmlRootElement( name = "SDRTrunk_settings" )
|
||||
public class Settings
|
||||
{
|
||||
private List<Setting> mSettings = new ArrayList<Setting>();
|
||||
|
||||
private List<TunerConfiguration> mTunerConfiguration =
|
||||
new ArrayList<TunerConfiguration>();
|
||||
|
||||
private List<RecordingConfiguration> mRecordingConfigurations =
|
||||
new ArrayList<RecordingConfiguration>();
|
||||
|
||||
public Settings()
|
||||
{
|
||||
}
|
||||
|
||||
@XmlElement( name="recording_configuration" )
|
||||
public List<RecordingConfiguration> getRecordingConfigurations()
|
||||
{
|
||||
return mRecordingConfigurations;
|
||||
}
|
||||
|
||||
public void setRecordingConfigurations( ArrayList<RecordingConfiguration> configs )
|
||||
{
|
||||
mRecordingConfigurations = configs;
|
||||
}
|
||||
|
||||
public void addRecordingConfiguration( RecordingConfiguration config )
|
||||
{
|
||||
mRecordingConfigurations.add( config );
|
||||
}
|
||||
|
||||
public void removeRecordingConfiguration( RecordingConfiguration config )
|
||||
{
|
||||
mRecordingConfigurations.remove( config );
|
||||
}
|
||||
|
||||
@XmlElement( name="tuner_configuration" )
|
||||
public List<TunerConfiguration> getTunerConfigurations()
|
||||
{
|
||||
return mTunerConfiguration;
|
||||
}
|
||||
|
||||
public void setTunerConfigurations( List<TunerConfiguration> configs )
|
||||
{
|
||||
mTunerConfiguration = configs;
|
||||
}
|
||||
|
||||
@XmlElement( name="setting" )
|
||||
public List<Setting> getSettings()
|
||||
{
|
||||
return mSettings;
|
||||
}
|
||||
|
||||
public void setSettings( ArrayList<Setting> settings )
|
||||
{
|
||||
mSettings = settings;
|
||||
}
|
||||
|
||||
public Setting getSetting( String name )
|
||||
{
|
||||
for( Setting setting: mSettings )
|
||||
{
|
||||
if( setting.getName().contentEquals( name ) )
|
||||
{
|
||||
return setting;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void addSetting( Setting setting )
|
||||
{
|
||||
mSettings.add( setting );
|
||||
}
|
||||
|
||||
public void removeSetting( Setting setting )
|
||||
{
|
||||
mSettings.remove( setting );
|
||||
}
|
||||
|
||||
public DefaultIcon getDefaultIcon()
|
||||
{
|
||||
for( Setting setting: mSettings )
|
||||
{
|
||||
if( setting instanceof DefaultIcon )
|
||||
{
|
||||
return (DefaultIcon)setting;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public ColorSetting getColorSetting( ColorSettingName name )
|
||||
{
|
||||
for( Setting setting: mSettings )
|
||||
{
|
||||
if( setting instanceof ColorSetting &&
|
||||
((ColorSetting)setting).getColorSettingName() == name )
|
||||
{
|
||||
return (ColorSetting)setting;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<ColorSetting> getColorSettings()
|
||||
{
|
||||
ArrayList<ColorSetting> colors = new ArrayList<ColorSetting>();
|
||||
|
||||
for( Setting setting: mSettings )
|
||||
{
|
||||
if( setting instanceof ColorSetting )
|
||||
{
|
||||
colors.add( (ColorSetting)setting );
|
||||
}
|
||||
}
|
||||
|
||||
return colors;
|
||||
}
|
||||
|
||||
public FileSetting getFileSetting( String name )
|
||||
{
|
||||
for( Setting setting: mSettings )
|
||||
{
|
||||
if( setting instanceof FileSetting &&
|
||||
setting.getName().contentEquals( name ) )
|
||||
{
|
||||
return (FileSetting)setting;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public MapIcon getMapIcon( String name )
|
||||
{
|
||||
for( Setting setting: mSettings )
|
||||
{
|
||||
if( setting instanceof MapIcon &&
|
||||
setting.getName().contentEquals( name ) )
|
||||
{
|
||||
return (MapIcon)setting;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public ArrayList<MapIcon> getMapIcons()
|
||||
{
|
||||
ArrayList<MapIcon> icons = new ArrayList<MapIcon>();
|
||||
|
||||
for( Setting setting: mSettings )
|
||||
{
|
||||
if( setting instanceof MapIcon )
|
||||
{
|
||||
icons.add( (MapIcon)setting );
|
||||
}
|
||||
}
|
||||
|
||||
return icons;
|
||||
}
|
||||
|
||||
public MapViewSetting getMapViewSetting( String name )
|
||||
{
|
||||
for( Setting setting: mSettings )
|
||||
{
|
||||
if( setting instanceof MapViewSetting &&
|
||||
setting.getName().contentEquals( name ) )
|
||||
{
|
||||
return (MapViewSetting)setting;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
499
src/main/java/io/github/dsheirer/settings/SettingsManager.java
Normal file
499
src/main/java/io/github/dsheirer/settings/SettingsManager.java
Normal file
@@ -0,0 +1,499 @@
|
||||
/*******************************************************************************
|
||||
* SDR Trunk
|
||||
* Copyright (C) 2014-2016 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 io.github.dsheirer.settings;
|
||||
|
||||
import io.github.dsheirer.properties.SystemProperties;
|
||||
import io.github.dsheirer.sample.Listener;
|
||||
import io.github.dsheirer.source.recording.RecordingConfiguration;
|
||||
import io.github.dsheirer.source.tuner.configuration.TunerConfigurationEvent;
|
||||
import io.github.dsheirer.source.tuner.configuration.TunerConfigurationModel;
|
||||
import io.github.dsheirer.util.ThreadPool;
|
||||
import org.jdesktop.swingx.mapviewer.GeoPosition;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Marshaller;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
import java.awt.*;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
public class SettingsManager implements Listener<TunerConfigurationEvent>
|
||||
{
|
||||
private final static Logger mLog = LoggerFactory.getLogger(SettingsManager.class);
|
||||
|
||||
private Settings mSettings = new Settings();
|
||||
private List<SettingChangeListener> mListeners = new ArrayList<>();
|
||||
private TunerConfigurationModel mTunerConfigurationModel;
|
||||
private boolean mLoadingSettings = false;
|
||||
private AtomicBoolean mSettingsSavePending = new AtomicBoolean();
|
||||
|
||||
public SettingsManager(TunerConfigurationModel tunerConfigurationModel)
|
||||
{
|
||||
//TODO: move settings into a SettingsModel
|
||||
//and update this class to only provide loading, saving, and model
|
||||
//change detection producing a save.
|
||||
|
||||
mTunerConfigurationModel = tunerConfigurationModel;
|
||||
|
||||
//Register for tuner config events so that we can save the settings
|
||||
mTunerConfigurationModel.addListener(this);
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads settings from the current settings file, or the default settings file,
|
||||
* as specified in the current SDRTrunk system settings
|
||||
*/
|
||||
private void init()
|
||||
{
|
||||
SystemProperties props = SystemProperties.getInstance();
|
||||
|
||||
Path settingsFolder = props.getApplicationFolder("settings");
|
||||
|
||||
String defaultSettingsFile =
|
||||
props.get("settings.defaultFilename", "settings.xml");
|
||||
|
||||
String settingsFile =
|
||||
props.get("settings.currentFilename", defaultSettingsFile);
|
||||
|
||||
load(settingsFolder.resolve(settingsFile));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receive(TunerConfigurationEvent t)
|
||||
{
|
||||
if(!mLoadingSettings)
|
||||
{
|
||||
scheduleSettingsSave();
|
||||
}
|
||||
}
|
||||
|
||||
public Settings getSettings()
|
||||
{
|
||||
return mSettings;
|
||||
}
|
||||
|
||||
public void setSettings(Settings settings)
|
||||
{
|
||||
mSettings = settings;
|
||||
}
|
||||
|
||||
public Setting getSetting(String name)
|
||||
{
|
||||
return mSettings.getSetting(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current setting, or if the setting doesn't exist
|
||||
* returns a newly created setting with the specified parameters
|
||||
*/
|
||||
public ColorSetting getColorSetting(ColorSetting.ColorSettingName name)
|
||||
{
|
||||
ColorSetting setting = mSettings.getColorSetting(name);
|
||||
|
||||
if(setting == null)
|
||||
{
|
||||
setting = new ColorSetting(name);
|
||||
|
||||
addSetting(setting);
|
||||
}
|
||||
|
||||
return setting;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fetches the current setting and applies the parameter(s) to it. Creates
|
||||
* the setting if it does not exist
|
||||
*/
|
||||
public void setColorSetting(ColorSetting.ColorSettingName name, Color color)
|
||||
{
|
||||
ColorSetting setting = getColorSetting(name);
|
||||
|
||||
setting.setColor(color);
|
||||
|
||||
broadcastSettingChange(setting);
|
||||
|
||||
scheduleSettingsSave();
|
||||
}
|
||||
|
||||
public void resetColorSetting(ColorSetting.ColorSettingName name)
|
||||
{
|
||||
setColorSetting(name, name.getDefaultColor());
|
||||
}
|
||||
|
||||
public void resetAllColorSettings()
|
||||
{
|
||||
for(ColorSetting color : mSettings.getColorSettings())
|
||||
{
|
||||
resetColorSetting(color.getColorSettingName());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current setting, or if the setting doesn't exist
|
||||
* returns a newly created setting with the specified parameters
|
||||
*/
|
||||
public FileSetting getFileSetting(String name, String defaultPath)
|
||||
{
|
||||
FileSetting setting = mSettings.getFileSetting(name);
|
||||
|
||||
if(setting == null)
|
||||
{
|
||||
setting = new FileSetting(name, defaultPath);
|
||||
|
||||
addSetting(setting);
|
||||
}
|
||||
|
||||
return setting;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the current setting and applies the parameter(s) to it. Creates
|
||||
* the setting if it does not exist
|
||||
*/
|
||||
public void setFileSetting(String name, String path)
|
||||
{
|
||||
FileSetting setting = getFileSetting(name, path);
|
||||
|
||||
setting.setPath(path);
|
||||
|
||||
broadcastSettingChange(setting);
|
||||
|
||||
scheduleSettingsSave();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the setting and stores the set of settings
|
||||
*
|
||||
* @param setting
|
||||
*/
|
||||
private void addSetting(Setting setting)
|
||||
{
|
||||
mSettings.addSetting(setting);
|
||||
|
||||
scheduleSettingsSave();
|
||||
|
||||
broadcastSettingChange(setting);
|
||||
}
|
||||
|
||||
public List<RecordingConfiguration> getRecordingConfigurations()
|
||||
{
|
||||
return mSettings.getRecordingConfigurations();
|
||||
}
|
||||
|
||||
public void addRecordingConfiguration(RecordingConfiguration config)
|
||||
{
|
||||
mSettings.addRecordingConfiguration(config);
|
||||
scheduleSettingsSave();
|
||||
}
|
||||
|
||||
public void removeRecordingConfiguration(RecordingConfiguration config)
|
||||
{
|
||||
mSettings.removeRecordingConfiguration(config);
|
||||
scheduleSettingsSave();
|
||||
}
|
||||
|
||||
public MapViewSetting getMapViewSetting(String name, GeoPosition position, int zoom)
|
||||
{
|
||||
MapViewSetting loc = mSettings.getMapViewSetting(name);
|
||||
|
||||
if(loc != null)
|
||||
{
|
||||
return loc;
|
||||
}
|
||||
else
|
||||
{
|
||||
MapViewSetting newLoc = new MapViewSetting(name, position, zoom);
|
||||
|
||||
addSetting(newLoc);
|
||||
|
||||
return newLoc;
|
||||
}
|
||||
}
|
||||
|
||||
public void setMapViewSetting(String name, GeoPosition position, int zoom)
|
||||
{
|
||||
MapViewSetting loc = getMapViewSetting(name, position, zoom);
|
||||
|
||||
loc.setGeoPosition(position);
|
||||
loc.setZoom(zoom);
|
||||
|
||||
scheduleSettingsSave();
|
||||
}
|
||||
|
||||
private void save()
|
||||
{
|
||||
saveTunerConfigurationModel();
|
||||
|
||||
JAXBContext context = null;
|
||||
|
||||
SystemProperties props = SystemProperties.getInstance();
|
||||
|
||||
Path settingsPath = props.getApplicationFolder("settings");
|
||||
|
||||
String settingsDefault = props.get("settings.defaultFilename",
|
||||
"settings.xml");
|
||||
|
||||
String settingsCurrent = props.get("settings.currentFilename",
|
||||
settingsDefault);
|
||||
|
||||
Path filePath = settingsPath.resolve(settingsCurrent);
|
||||
|
||||
File outputFile = new File(filePath.toString());
|
||||
|
||||
try
|
||||
{
|
||||
if(!outputFile.exists())
|
||||
{
|
||||
outputFile.createNewFile();
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
mLog.error("SettingsManager - couldn't create file to save "
|
||||
+ "settings [" + filePath.toString() + "]", e);
|
||||
}
|
||||
|
||||
OutputStream out = null;
|
||||
|
||||
try
|
||||
{
|
||||
out = new FileOutputStream(outputFile);
|
||||
|
||||
try
|
||||
{
|
||||
context = JAXBContext.newInstance(Settings.class);
|
||||
|
||||
Marshaller m = context.createMarshaller();
|
||||
|
||||
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
|
||||
|
||||
m.marshal(mSettings, out);
|
||||
}
|
||||
catch(JAXBException e)
|
||||
{
|
||||
mLog.error("SettingsManager - jaxb exception while saving " +
|
||||
"settings", e);
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
mLog.error("SettingsManager - couldn't open output stream to " +
|
||||
"save settings [" + filePath.toString() + "]");
|
||||
}
|
||||
finally
|
||||
{
|
||||
if(out != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
out.close();
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Erases current settings and loads settings from the settingsPath filename,
|
||||
* if it exists.
|
||||
*/
|
||||
public void load(Path settingsPath)
|
||||
{
|
||||
mLoadingSettings = true;
|
||||
|
||||
if(Files.exists(settingsPath))
|
||||
{
|
||||
mLog.info("SettingsManager - loading settings file [" + settingsPath.toString() + "]");
|
||||
|
||||
JAXBContext context = null;
|
||||
|
||||
InputStream in = null;
|
||||
|
||||
try
|
||||
{
|
||||
in = new FileInputStream(settingsPath.toString());
|
||||
|
||||
try
|
||||
{
|
||||
context = JAXBContext.newInstance(Settings.class);
|
||||
|
||||
Unmarshaller m = context.createUnmarshaller();
|
||||
|
||||
mSettings = (Settings) m.unmarshal(in);
|
||||
}
|
||||
catch(JAXBException e)
|
||||
{
|
||||
mLog.error("SettingsManager - jaxb exception while loading " +
|
||||
"settings", e);
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
mLog.error("SettingsManager - coulcn't open inputstream to " +
|
||||
"load settings [" + settingsPath.toString() + "]", e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if(in != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
in.close();
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
mLog.error("SettingsManager - exception while closing " +
|
||||
"the settings file inputstream reader", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
mLog.info("SettingsManager - settings does not exist [" +
|
||||
settingsPath.toString() + "]");
|
||||
}
|
||||
|
||||
if(mSettings == null)
|
||||
{
|
||||
mSettings = new Settings();
|
||||
}
|
||||
|
||||
loadTunerConfigurationModel();
|
||||
|
||||
mLoadingSettings = false;
|
||||
}
|
||||
|
||||
private void loadTunerConfigurationModel()
|
||||
{
|
||||
if(mSettings != null)
|
||||
{
|
||||
mTunerConfigurationModel.clear();
|
||||
|
||||
mTunerConfigurationModel.addTunerConfigurations(
|
||||
mSettings.getTunerConfigurations());
|
||||
}
|
||||
}
|
||||
|
||||
private void saveTunerConfigurationModel()
|
||||
{
|
||||
if(mSettings != null)
|
||||
{
|
||||
mSettings.setTunerConfigurations(
|
||||
mTunerConfigurationModel.getTunerConfigurations());
|
||||
}
|
||||
}
|
||||
|
||||
public void broadcastSettingChange(Setting setting)
|
||||
{
|
||||
Iterator<SettingChangeListener> it = mListeners.iterator();
|
||||
|
||||
while(it.hasNext())
|
||||
{
|
||||
SettingChangeListener listener = it.next();
|
||||
|
||||
if(listener == null)
|
||||
{
|
||||
it.remove();
|
||||
}
|
||||
else
|
||||
{
|
||||
listener.settingChanged(setting);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void broadcastSettingDeleted(Setting setting)
|
||||
{
|
||||
Iterator<SettingChangeListener> it = mListeners.iterator();
|
||||
|
||||
while(it.hasNext())
|
||||
{
|
||||
SettingChangeListener listener = it.next();
|
||||
|
||||
if(listener == null)
|
||||
{
|
||||
it.remove();
|
||||
}
|
||||
else
|
||||
{
|
||||
listener.settingDeleted(setting);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void addListener(SettingChangeListener listener)
|
||||
{
|
||||
mListeners.add(listener);
|
||||
}
|
||||
|
||||
public void removeListener(SettingChangeListener listener)
|
||||
{
|
||||
mListeners.remove(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedules a settings save task. Subsequent calls to this method will be ignored until the
|
||||
* save event occurs, thus limiting repetitive saving to a minimum.
|
||||
*/
|
||||
private void scheduleSettingsSave()
|
||||
{
|
||||
if(!mLoadingSettings)
|
||||
{
|
||||
if(mSettingsSavePending.compareAndSet(false, true))
|
||||
{
|
||||
ThreadPool.SCHEDULED.schedule(new SettingsSaveTask(), 2, TimeUnit.SECONDS);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the settings save pending flag to false and proceeds to save the
|
||||
* settings.
|
||||
*/
|
||||
public class SettingsSaveTask implements Runnable
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
mSettingsSavePending.set(false);
|
||||
|
||||
save();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user