From 26b97f09b7788718f771276026fcc15b22dab59b Mon Sep 17 00:00:00 2001 From: Denny Date: Thu, 21 Dec 2017 19:59:11 -0500 Subject: [PATCH] Updates SettingsManager to use jackson xml serialization. Final testing on all changes to xml serialization. --- .../dsheirer/controller/channel/Channel.java | 25 +- .../channel/ChannelProcessingManager.java | 4 +- .../io/github/dsheirer/map/DefaultIcon.java | 64 +-- .../java/io/github/dsheirer/map/MapIcon.java | 11 +- .../dsheirer/properties/SystemProperties.java | 2 +- .../record/config/RecordConfiguration.java | 4 - .../dsheirer/settings/ColorSetting.java | 9 +- .../github/dsheirer/settings/FileSetting.java | 41 +- .../dsheirer/settings/MapViewSetting.java | 24 ++ .../io/github/dsheirer/settings/Setting.java | 47 ++- .../github/dsheirer/settings/SettingType.java | 28 ++ .../io/github/dsheirer/settings/Settings.java | 378 +++++++++--------- .../dsheirer/settings/SettingsManager.java | 151 ++----- .../recording/RecordingConfiguration.java | 4 +- .../airspy/AirspyTunerConfiguration.java | 39 +- .../configuration/TunerConfiguration.java | 55 ++- .../fcd/proV1/FCD1TunerConfiguration.java | 3 +- .../fcd/proplusV2/FCD2TunerConfiguration.java | 3 +- .../hackrf/HackRFTunerConfiguration.java | 3 +- .../tuner/rtl/e4k/E4KTunerConfiguration.java | 4 +- .../rtl/r820t/R820TTunerConfiguration.java | 3 +- 21 files changed, 469 insertions(+), 433 deletions(-) create mode 100644 src/main/java/io/github/dsheirer/settings/SettingType.java diff --git a/src/main/java/io/github/dsheirer/controller/channel/Channel.java b/src/main/java/io/github/dsheirer/controller/channel/Channel.java index 1ce7e070..9c0cee7f 100644 --- a/src/main/java/io/github/dsheirer/controller/channel/Channel.java +++ b/src/main/java/io/github/dsheirer/controller/channel/Channel.java @@ -314,7 +314,10 @@ public class Channel extends Configuration implements Listener - ******************************************************************************/ +/* + * ********************************************************************************************************************* + * 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 + * ********************************************************************************************************************* + */ package io.github.dsheirer.map; -import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import io.github.dsheirer.settings.Setting; +import io.github.dsheirer.settings.SettingType; -@JsonSubTypes.Type(value = DefaultIcon.class, name = "defaultIcon") public class DefaultIcon extends Setting { - public DefaultIcon( String name ) - { - super( name ); - } - - /** - * Don't use this constructor. This is used by JAXB to unmarshall saved - * map icons. - */ - public DefaultIcon() - { - } + public DefaultIcon(String name) + { + super(name); + } + + public DefaultIcon() + { + } + + @JacksonXmlProperty(isAttribute = true, localName = "type", namespace = "http://www.w3.org/2001/XMLSchema-instance") + @Override + public SettingType getType() + { + return SettingType.DEFAULT_ICON; + } } diff --git a/src/main/java/io/github/dsheirer/map/MapIcon.java b/src/main/java/io/github/dsheirer/map/MapIcon.java index 2bc1785e..d1be4647 100644 --- a/src/main/java/io/github/dsheirer/map/MapIcon.java +++ b/src/main/java/io/github/dsheirer/map/MapIcon.java @@ -18,20 +18,26 @@ package io.github.dsheirer.map; import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import io.github.dsheirer.settings.Setting; +import io.github.dsheirer.settings.SettingType; import javax.swing.*; import java.awt.*; -@JsonSubTypes.Type(value = MapIcon.class, name = "mapIcon") public class MapIcon extends Setting implements Comparable { private static final int sMAX_IMAGE_DIMENSION = 48; private String mPath; private ImageIcon mImageIcon; + @JacksonXmlProperty(isAttribute = true, localName = "type", namespace = "http://www.w3.org/2001/XMLSchema-instance") + @Override + public SettingType getType() + { + return SettingType.MAP_ICON; + } + /** * Only map icons created at runtime can be marked as non-editable, and * therefore this property is transient. @@ -91,6 +97,7 @@ public class MapIcon extends Setting implements Comparable mDefaultIcon = isDefault; } + @JsonIgnore public ImageIcon getImageIcon() { if(mImageIcon == null) diff --git a/src/main/java/io/github/dsheirer/properties/SystemProperties.java b/src/main/java/io/github/dsheirer/properties/SystemProperties.java index 61714f57..fd4bc75c 100644 --- a/src/main/java/io/github/dsheirer/properties/SystemProperties.java +++ b/src/main/java/io/github/dsheirer/properties/SystemProperties.java @@ -106,7 +106,7 @@ public class SystemProperties } catch (Exception e) { - mLog.error("Couldn't load jar manifest - probably not running from a jar release"); + mLog.error("Unable to load jar manifest - we're probably not running from a release jar"); } return null; diff --git a/src/main/java/io/github/dsheirer/record/config/RecordConfiguration.java b/src/main/java/io/github/dsheirer/record/config/RecordConfiguration.java index 47bbd107..1cda4aa1 100644 --- a/src/main/java/io/github/dsheirer/record/config/RecordConfiguration.java +++ b/src/main/java/io/github/dsheirer/record/config/RecordConfiguration.java @@ -17,17 +17,13 @@ ******************************************************************************/ package io.github.dsheirer.record.config; -import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; import io.github.dsheirer.controller.config.Configuration; import io.github.dsheirer.record.RecorderType; import java.util.ArrayList; import java.util.List; -@JsonSubTypes.Type(value = RecordConfiguration.class, name = "recordConfiguration") -@JacksonXmlRootElement(localName = "record_configuration") public class RecordConfiguration extends Configuration { private List mRecorders = new ArrayList<>(); diff --git a/src/main/java/io/github/dsheirer/settings/ColorSetting.java b/src/main/java/io/github/dsheirer/settings/ColorSetting.java index cb4f0abf..9f4d2c10 100644 --- a/src/main/java/io/github/dsheirer/settings/ColorSetting.java +++ b/src/main/java/io/github/dsheirer/settings/ColorSetting.java @@ -18,12 +18,10 @@ package io.github.dsheirer.settings; import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import java.awt.*; -@JsonSubTypes.Type(value = ColorSetting.class, name = "colorSetting") public class ColorSetting extends Setting { private static final int NO_TRANSLUCENCY = 255; @@ -45,6 +43,13 @@ public class ColorSetting extends Setting setColorSettingName(name); } + @JacksonXmlProperty(isAttribute = true, localName = "type", namespace = "http://www.w3.org/2001/XMLSchema-instance") + @Override + public SettingType getType() + { + return SettingType.COLOR_SETTING; + } + @JacksonXmlProperty(isAttribute = true, localName = "colorSettingName") public ColorSettingName getColorSettingName() { diff --git a/src/main/java/io/github/dsheirer/settings/FileSetting.java b/src/main/java/io/github/dsheirer/settings/FileSetting.java index 06341d1b..afa5f63e 100644 --- a/src/main/java/io/github/dsheirer/settings/FileSetting.java +++ b/src/main/java/io/github/dsheirer/settings/FileSetting.java @@ -1,28 +1,26 @@ -/******************************************************************************* - * SDR Trunk - * Copyright (C) 2014 Dennis Sheirer +/* + * ********************************************************************************************************************* + * 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 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. + * 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 - ******************************************************************************/ + * You should have received a copy of the GNU General Public License along with this program. + * If not, see + * ********************************************************************************************************************* + */ package io.github.dsheirer.settings; -import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import java.io.File; - -@JsonSubTypes.Type(value = FileSetting.class, name = "fileSetting") public class FileSetting extends Setting { private String mPath; @@ -38,6 +36,14 @@ public class FileSetting extends Setting setPath(path); } + @JacksonXmlProperty(isAttribute = true, localName = "type", namespace = "http://www.w3.org/2001/XMLSchema-instance") + @Override + public SettingType getType() + { + return SettingType.FILE_SETTING; + } + + @JacksonXmlProperty(isAttribute = true, localName = "path") public String getPath() { return mPath; @@ -48,6 +54,7 @@ public class FileSetting extends Setting mPath = value; } + @JsonIgnore public File getFile() { return new File(mPath); diff --git a/src/main/java/io/github/dsheirer/settings/MapViewSetting.java b/src/main/java/io/github/dsheirer/settings/MapViewSetting.java index b54fa077..483bf9c7 100644 --- a/src/main/java/io/github/dsheirer/settings/MapViewSetting.java +++ b/src/main/java/io/github/dsheirer/settings/MapViewSetting.java @@ -1,3 +1,20 @@ +/* + * ********************************************************************************************************************* + * 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 + * ********************************************************************************************************************* + */ + package io.github.dsheirer.settings; import com.fasterxml.jackson.annotation.JsonIgnore; @@ -33,6 +50,13 @@ public class MapViewSetting extends Setting mZoom = zoom; } + @JacksonXmlProperty(isAttribute = true, localName = "type", namespace = "http://www.w3.org/2001/XMLSchema-instance") + @Override + public SettingType getType() + { + return SettingType.MAP_VIEW_SETTING; + } + @JacksonXmlProperty(isAttribute = true, localName = "latitude") public double getLatitude() { diff --git a/src/main/java/io/github/dsheirer/settings/Setting.java b/src/main/java/io/github/dsheirer/settings/Setting.java index ef0122ae..0cb497d1 100644 --- a/src/main/java/io/github/dsheirer/settings/Setting.java +++ b/src/main/java/io/github/dsheirer/settings/Setting.java @@ -1,27 +1,39 @@ -/******************************************************************************* - * SDR Trunk - * Copyright (C) 2014 Dennis Sheirer +/* + * ********************************************************************************************************************* + * 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 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. + * 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 - ******************************************************************************/ + * You should have received a copy of the GNU General Public License along with this program. + * If not, see + * ********************************************************************************************************************* + */ package io.github.dsheirer.settings; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; +import io.github.dsheirer.map.DefaultIcon; +import io.github.dsheirer.map.MapIcon; -@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "xsi:type") -public class Setting +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include= JsonTypeInfo.As.PROPERTY, property="type") +@JsonSubTypes({ + @JsonSubTypes.Type(value=ColorSetting.class, name="colorSetting"), + @JsonSubTypes.Type(value=DefaultIcon.class, name="defaultIcon"), + @JsonSubTypes.Type(value=FileSetting.class, name="fileSetting"), + @JsonSubTypes.Type(value=MapIcon.class, name="mapIcon"), + @JsonSubTypes.Type(value=MapViewSetting.class, name="mapViewSetting"), +}) +@JacksonXmlRootElement( localName = "setting" ) +public abstract class Setting { protected String mName; @@ -44,4 +56,7 @@ public class Setting { mName = name; } + + @JsonIgnore + public abstract SettingType getType(); } diff --git a/src/main/java/io/github/dsheirer/settings/SettingType.java b/src/main/java/io/github/dsheirer/settings/SettingType.java new file mode 100644 index 00000000..3cfa0d08 --- /dev/null +++ b/src/main/java/io/github/dsheirer/settings/SettingType.java @@ -0,0 +1,28 @@ +/* + * ********************************************************************************************************************* + * 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 + * ********************************************************************************************************************* + */ + +package io.github.dsheirer.settings; + +public enum SettingType +{ + COLOR_SETTING, + DEFAULT_ICON, + FILE_SETTING, + MAP_ICON, + MAP_VIEW_SETTING, + UNKNOWN; +} diff --git a/src/main/java/io/github/dsheirer/settings/Settings.java b/src/main/java/io/github/dsheirer/settings/Settings.java index d7160fb8..8da930da 100644 --- a/src/main/java/io/github/dsheirer/settings/Settings.java +++ b/src/main/java/io/github/dsheirer/settings/Settings.java @@ -1,22 +1,22 @@ -/******************************************************************************* - * 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 - ******************************************************************************/ +/* + * ********************************************************************************************************************* + * 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 + * ********************************************************************************************************************* + */ package io.github.dsheirer.settings; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; import io.github.dsheirer.map.DefaultIcon; @@ -28,183 +28,183 @@ import io.github.dsheirer.source.tuner.configuration.TunerConfiguration; import java.util.ArrayList; import java.util.List; -@JacksonXmlRootElement( localName = "SDRTrunk_settings" ) +@JacksonXmlRootElement(localName = "SDRTrunk_settings") public class Settings { - private List mSettings = new ArrayList(); + private List mSettings = new ArrayList(); - private List mTunerConfiguration = - new ArrayList(); - - private List mRecordingConfigurations = - new ArrayList(); + private List mTunerConfiguration = new ArrayList(); - public Settings() - { - } + private List mRecordingConfigurations = new ArrayList(); - @JacksonXmlProperty(isAttribute = false, localName = "recording_configuration") - public List getRecordingConfigurations() - { - return mRecordingConfigurations; - } - - public void setRecordingConfigurations( ArrayList configs ) - { - mRecordingConfigurations = configs; - } - - public void addRecordingConfiguration( RecordingConfiguration config ) - { - mRecordingConfigurations.add( config ); - } - - public void removeRecordingConfiguration( RecordingConfiguration config ) - { - mRecordingConfigurations.remove( config ); - } - - @JacksonXmlProperty(isAttribute = false, localName = "tuner_configuration") - public List getTunerConfigurations() - { - return mTunerConfiguration; - } - - public void setTunerConfigurations( List configs ) - { - mTunerConfiguration = configs; - } - - @JacksonXmlProperty(isAttribute = false, localName = "setting") - public List getSettings() - { - return mSettings; - } - - public void setSettings( ArrayList 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 getColorSettings() - { - ArrayList colors = new ArrayList(); - - 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 getMapIcons() - { - ArrayList icons = new ArrayList(); - - for( Setting setting: mSettings ) - { - if( setting instanceof MapIcon ) - { - icons.add( (MapIcon)setting ); - } - } - - return icons; - } - - public MapViewSetting getMapViewSetting( String name ) + public Settings() { - for( Setting setting: mSettings ) - { - if( setting instanceof MapViewSetting && - setting.getName().contentEquals( name ) ) - { - return (MapViewSetting)setting; - } - } - - return null; + } + + @JacksonXmlProperty(isAttribute = false, localName = "recording_configuration") + public List getRecordingConfigurations() + { + return mRecordingConfigurations; + } + + public void setRecordingConfigurations(ArrayList configs) + { + mRecordingConfigurations = configs; + } + + public void addRecordingConfiguration(RecordingConfiguration config) + { + mRecordingConfigurations.add(config); + } + + public void removeRecordingConfiguration(RecordingConfiguration config) + { + mRecordingConfigurations.remove(config); + } + + @JacksonXmlProperty(isAttribute = false, localName = "tuner_configuration") + public List getTunerConfigurations() + { + return mTunerConfiguration; + } + + public void setTunerConfigurations(List configs) + { + mTunerConfiguration = configs; + } + + @JacksonXmlProperty(isAttribute = false, localName = "setting") + public List getSettings() + { + return mSettings; + } + + public void setSettings(ArrayList 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); + } + + @JsonIgnore + 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; + } + + @JsonIgnore + public List getColorSettings() + { + ArrayList colors = new ArrayList(); + + 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 getMapIcons() + { + ArrayList icons = new ArrayList(); + + 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; } } diff --git a/src/main/java/io/github/dsheirer/settings/SettingsManager.java b/src/main/java/io/github/dsheirer/settings/SettingsManager.java index 3114e7e3..00ccf70e 100644 --- a/src/main/java/io/github/dsheirer/settings/SettingsManager.java +++ b/src/main/java/io/github/dsheirer/settings/SettingsManager.java @@ -1,22 +1,25 @@ -/******************************************************************************* - * SDR Trunk - * Copyright (C) 2014-2016 Dennis Sheirer +/* + * ********************************************************************************************************************* + * 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 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. + * 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 - ******************************************************************************/ + * You should have received a copy of the GNU General Public License along with this program. + * If not, see + * ********************************************************************************************************************* + */ package io.github.dsheirer.settings; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.dataformat.xml.JacksonXmlModule; +import com.fasterxml.jackson.dataformat.xml.XmlMapper; import io.github.dsheirer.properties.SystemProperties; import io.github.dsheirer.sample.Listener; import io.github.dsheirer.source.recording.RecordingConfiguration; @@ -27,14 +30,7 @@ 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; @@ -256,11 +252,9 @@ public class SettingsManager implements Listener { saveTunerConfigurationModel(); - JAXBContext context = null; - SystemProperties props = SystemProperties.getInstance(); - Path settingsPath = props.getApplicationFolder("settings"); + Path settingsFolder = props.getApplicationFolder("settings"); String settingsDefault = props.get("settings.defaultFilename", "settings.xml"); @@ -268,63 +262,24 @@ public class SettingsManager implements Listener String settingsCurrent = props.get("settings.currentFilename", settingsDefault); - Path filePath = settingsPath.resolve(settingsCurrent); + Path settingsPath = settingsFolder.resolve(settingsCurrent); - File outputFile = new File(filePath.toString()); - - try + try(OutputStream out = Files.newOutputStream(settingsPath)) { - if(!outputFile.exists()) - { - outputFile.createNewFile(); - } + JacksonXmlModule xmlModule = new JacksonXmlModule(); + xmlModule.setDefaultUseWrapper(false); + ObjectMapper objectMapper = new XmlMapper(xmlModule); + objectMapper.enable(SerializationFeature.INDENT_OUTPUT); + objectMapper.writeValue(out, mSettings); + out.flush(); + } + catch(IOException ioe) + { + mLog.error("IO error while writing the settings to a file [" + settingsPath + "]", ioe); } 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(); - } - } + mLog.error("Error while saving settings file [" + settingsPath + "]", e); } } @@ -340,47 +295,17 @@ public class SettingsManager implements Listener { mLog.info("SettingsManager - loading settings file [" + settingsPath.toString() + "]"); - JAXBContext context = null; + JacksonXmlModule xmlModule = new JacksonXmlModule(); + xmlModule.setDefaultUseWrapper(false); + ObjectMapper objectMapper = new XmlMapper(xmlModule); - InputStream in = null; - - try + try(InputStream in = Files.newInputStream(settingsPath)) { - 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); - } + mSettings = objectMapper.readValue(in, Settings.class); } - catch(Exception e) + catch(IOException ioe) { - 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); - } - } + mLog.error("IO error while reading settings file", ioe); } } else diff --git a/src/main/java/io/github/dsheirer/source/recording/RecordingConfiguration.java b/src/main/java/io/github/dsheirer/source/recording/RecordingConfiguration.java index e17e2a21..7dea1236 100644 --- a/src/main/java/io/github/dsheirer/source/recording/RecordingConfiguration.java +++ b/src/main/java/io/github/dsheirer/source/recording/RecordingConfiguration.java @@ -1,12 +1,12 @@ package io.github.dsheirer.source.recording; import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; import java.io.File; -@JsonSubTypes.Type(value = RecordingConfiguration.class, name = "recordingConfiguration") +@JacksonXmlRootElement(localName = "recording_configuration") public class RecordingConfiguration { private File mRecording; diff --git a/src/main/java/io/github/dsheirer/source/tuner/airspy/AirspyTunerConfiguration.java b/src/main/java/io/github/dsheirer/source/tuner/airspy/AirspyTunerConfiguration.java index 69a447ac..4c5ac346 100644 --- a/src/main/java/io/github/dsheirer/source/tuner/airspy/AirspyTunerConfiguration.java +++ b/src/main/java/io/github/dsheirer/source/tuner/airspy/AirspyTunerConfiguration.java @@ -1,29 +1,26 @@ -/******************************************************************************* - * 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 - ******************************************************************************/ +/* + * ********************************************************************************************************************* + * 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 + * ********************************************************************************************************************* + */ package io.github.dsheirer.source.tuner.airspy; -import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import io.github.dsheirer.source.tuner.TunerType; import io.github.dsheirer.source.tuner.airspy.AirspyTunerController.Gain; import io.github.dsheirer.source.tuner.configuration.TunerConfiguration; -@JsonSubTypes.Type(value = AirspyTunerConfiguration.class, name = "airspyTunerConfiguration") public class AirspyTunerConfiguration extends TunerConfiguration { private int mSampleRate = AirspyTunerController.DEFAULT_SAMPLE_RATE.getRate(); @@ -47,8 +44,9 @@ public class AirspyTunerConfiguration extends TunerConfiguration { super( uniqueID, name ); } - + @Override + @JacksonXmlProperty(isAttribute = true, localName = "type", namespace = "http://www.w3.org/2001/XMLSchema-instance") public TunerType getTunerType() { return TunerType.AIRSPY_R820T; @@ -141,5 +139,4 @@ public class AirspyTunerConfiguration extends TunerConfiguration { mFrequencyCorrection = value; } - } diff --git a/src/main/java/io/github/dsheirer/source/tuner/configuration/TunerConfiguration.java b/src/main/java/io/github/dsheirer/source/tuner/configuration/TunerConfiguration.java index d35c5d0c..876773e0 100644 --- a/src/main/java/io/github/dsheirer/source/tuner/configuration/TunerConfiguration.java +++ b/src/main/java/io/github/dsheirer/source/tuner/configuration/TunerConfiguration.java @@ -1,32 +1,47 @@ -/******************************************************************************* - * SDR Trunk - * Copyright (C) 2014 Dennis Sheirer +/* + * ********************************************************************************************************************* + * 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 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. + * 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 - ******************************************************************************/ + * You should have received a copy of the GNU General Public License along with this program. + * If not, see + * ********************************************************************************************************************* + */ package io.github.dsheirer.source.tuner.configuration; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; import io.github.dsheirer.source.tuner.TunerType; +import io.github.dsheirer.source.tuner.airspy.AirspyTunerConfiguration; +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; /** * Abstract class to hold a named configuration for a specific type of tuner */ -@JacksonXmlRootElement(localName = "tuner_configuration") -@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "xsi:type") +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include= JsonTypeInfo.As.PROPERTY, property="type") +@JsonSubTypes({ + @JsonSubTypes.Type(value=AirspyTunerConfiguration.class, name="airspyTunerConfiguration"), + @JsonSubTypes.Type(value=E4KTunerConfiguration.class, name="e4KTunerConfiguration"), + @JsonSubTypes.Type(value=FCD1TunerConfiguration.class, name="fcd1TunerConfiguration"), + @JsonSubTypes.Type(value=FCD2TunerConfiguration.class, name="fcd2TunerConfiguration"), + @JsonSubTypes.Type(value=HackRFTunerConfiguration.class, name="hackRFTunerConfiguration"), + @JsonSubTypes.Type(value=R820TTunerConfiguration.class, name="r820TTunerConfiguration"), +}) +@JacksonXmlRootElement( localName = "tuner_configuration" ) public abstract class TunerConfiguration { protected String mName; @@ -100,6 +115,12 @@ public abstract class TunerConfiguration mFrequency = frequency; } - @JacksonXmlProperty(isAttribute = true, localName = "tuner_type") + @JsonIgnore public abstract TunerType getTunerType(); + + //Below is maintained for compatibility with javax.xml.bind serialization of the settings file. + //This can be removed if/once there is a new version of the settings. + @JacksonXmlProperty(isAttribute = true, localName = "tuner_type") + public String getLegacyAttribute(){ return null; } + public void setLegacyAttribute(String bonkers) { } } diff --git a/src/main/java/io/github/dsheirer/source/tuner/fcd/proV1/FCD1TunerConfiguration.java b/src/main/java/io/github/dsheirer/source/tuner/fcd/proV1/FCD1TunerConfiguration.java index b4f03b81..79e9a1a4 100644 --- a/src/main/java/io/github/dsheirer/source/tuner/fcd/proV1/FCD1TunerConfiguration.java +++ b/src/main/java/io/github/dsheirer/source/tuner/fcd/proV1/FCD1TunerConfiguration.java @@ -17,7 +17,6 @@ ******************************************************************************/ package io.github.dsheirer.source.tuner.fcd.proV1; -import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import io.github.dsheirer.source.tuner.TunerType; import io.github.dsheirer.source.tuner.configuration.TunerConfiguration; @@ -25,7 +24,6 @@ import io.github.dsheirer.source.tuner.fcd.proV1.FCD1TunerController.LNAEnhance; import io.github.dsheirer.source.tuner.fcd.proV1.FCD1TunerController.LNAGain; import io.github.dsheirer.source.tuner.fcd.proV1.FCD1TunerController.MixerGain; -@JsonSubTypes.Type(value = FCD1TunerConfiguration.class, name = "fcd1TunerConfiguration") public class FCD1TunerConfiguration extends TunerConfiguration { private double mFrequencyCorrection = 22.0d; @@ -50,6 +48,7 @@ public class FCD1TunerConfiguration extends TunerConfiguration super(uniqueID, name); } + @JacksonXmlProperty(isAttribute = true, localName = "type", namespace = "http://www.w3.org/2001/XMLSchema-instance") @Override public TunerType getTunerType() { diff --git a/src/main/java/io/github/dsheirer/source/tuner/fcd/proplusV2/FCD2TunerConfiguration.java b/src/main/java/io/github/dsheirer/source/tuner/fcd/proplusV2/FCD2TunerConfiguration.java index 78d6bcb0..6d11d176 100644 --- a/src/main/java/io/github/dsheirer/source/tuner/fcd/proplusV2/FCD2TunerConfiguration.java +++ b/src/main/java/io/github/dsheirer/source/tuner/fcd/proplusV2/FCD2TunerConfiguration.java @@ -17,12 +17,10 @@ ******************************************************************************/ package io.github.dsheirer.source.tuner.fcd.proplusV2; -import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import io.github.dsheirer.source.tuner.TunerType; import io.github.dsheirer.source.tuner.configuration.TunerConfiguration; -@JsonSubTypes.Type(value = FCD2TunerConfiguration.class, name = "fcd2TunerConfiguration") public class FCD2TunerConfiguration extends TunerConfiguration { private boolean mGainLNA = true; @@ -41,6 +39,7 @@ public class FCD2TunerConfiguration extends TunerConfiguration super(uniqueID, name); } + @JacksonXmlProperty(isAttribute = true, localName = "type", namespace = "http://www.w3.org/2001/XMLSchema-instance") @Override public TunerType getTunerType() { diff --git a/src/main/java/io/github/dsheirer/source/tuner/hackrf/HackRFTunerConfiguration.java b/src/main/java/io/github/dsheirer/source/tuner/hackrf/HackRFTunerConfiguration.java index 35456f62..74590f07 100644 --- a/src/main/java/io/github/dsheirer/source/tuner/hackrf/HackRFTunerConfiguration.java +++ b/src/main/java/io/github/dsheirer/source/tuner/hackrf/HackRFTunerConfiguration.java @@ -18,7 +18,6 @@ package io.github.dsheirer.source.tuner.hackrf; -import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import io.github.dsheirer.source.tuner.TunerType; import io.github.dsheirer.source.tuner.configuration.TunerConfiguration; @@ -26,7 +25,6 @@ import io.github.dsheirer.source.tuner.hackrf.HackRFTunerController.HackRFLNAGai import io.github.dsheirer.source.tuner.hackrf.HackRFTunerController.HackRFSampleRate; import io.github.dsheirer.source.tuner.hackrf.HackRFTunerController.HackRFVGAGain; -@JsonSubTypes.Type(value = HackRFTunerConfiguration.class, name = "hackRFTunerConfiguration") public class HackRFTunerConfiguration extends TunerConfiguration { private HackRFSampleRate mSampleRate = HackRFSampleRate.RATE2_016MHZ; @@ -47,6 +45,7 @@ public class HackRFTunerConfiguration extends TunerConfiguration super(uniqueID, name); } + @JacksonXmlProperty(isAttribute = true, localName = "type", namespace = "http://www.w3.org/2001/XMLSchema-instance") @Override public TunerType getTunerType() { diff --git a/src/main/java/io/github/dsheirer/source/tuner/rtl/e4k/E4KTunerConfiguration.java b/src/main/java/io/github/dsheirer/source/tuner/rtl/e4k/E4KTunerConfiguration.java index 3e62c522..85425729 100644 --- a/src/main/java/io/github/dsheirer/source/tuner/rtl/e4k/E4KTunerConfiguration.java +++ b/src/main/java/io/github/dsheirer/source/tuner/rtl/e4k/E4KTunerConfiguration.java @@ -17,10 +17,8 @@ ******************************************************************************/ package io.github.dsheirer.source.tuner.rtl.e4k; -import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import io.github.dsheirer.source.tuner.TunerType; -import io.github.dsheirer.source.tuner.airspy.AirspyTunerConfiguration; import io.github.dsheirer.source.tuner.configuration.TunerConfiguration; import io.github.dsheirer.source.tuner.rtl.RTL2832TunerController; import io.github.dsheirer.source.tuner.rtl.e4k.E4KTunerController.E4KEnhanceGain; @@ -28,7 +26,6 @@ import io.github.dsheirer.source.tuner.rtl.e4k.E4KTunerController.E4KGain; import io.github.dsheirer.source.tuner.rtl.e4k.E4KTunerController.E4KLNAGain; import io.github.dsheirer.source.tuner.rtl.e4k.E4KTunerController.E4KMixerGain; -@JsonSubTypes.Type(value = AirspyTunerConfiguration.class, name = "e4KTunerConfiguration") public class E4KTunerConfiguration extends TunerConfiguration { private E4KGain mMasterGain = E4KGain.MANUAL; @@ -50,6 +47,7 @@ public class E4KTunerConfiguration extends TunerConfiguration super(uniqueID, name); } + @JacksonXmlProperty(isAttribute = true, localName = "type", namespace = "http://www.w3.org/2001/XMLSchema-instance") @Override public TunerType getTunerType() { diff --git a/src/main/java/io/github/dsheirer/source/tuner/rtl/r820t/R820TTunerConfiguration.java b/src/main/java/io/github/dsheirer/source/tuner/rtl/r820t/R820TTunerConfiguration.java index 4ba2f51d..bb88c8ef 100644 --- a/src/main/java/io/github/dsheirer/source/tuner/rtl/r820t/R820TTunerConfiguration.java +++ b/src/main/java/io/github/dsheirer/source/tuner/rtl/r820t/R820TTunerConfiguration.java @@ -17,13 +17,11 @@ ******************************************************************************/ package io.github.dsheirer.source.tuner.rtl.r820t; -import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import io.github.dsheirer.source.tuner.TunerType; import io.github.dsheirer.source.tuner.configuration.TunerConfiguration; import io.github.dsheirer.source.tuner.rtl.RTL2832TunerController; -@JsonSubTypes.Type(value = R820TTunerConfiguration.class, name = "r820TTunerConfiguration") public class R820TTunerConfiguration extends TunerConfiguration { private R820TTunerController.R820TGain mMasterGain = R820TTunerController.R820TGain.GAIN_327; @@ -45,6 +43,7 @@ public class R820TTunerConfiguration extends TunerConfiguration super(uniqueID, name); } + @JacksonXmlProperty(isAttribute = true, localName = "type", namespace = "http://www.w3.org/2001/XMLSchema-instance") @Override public TunerType getTunerType() {