Skip to content
Permalink
Browse files

handle VSD Deprecation and Spotbugs Warnings

  • Loading branch information...
klk32003 committed Sep 18, 2018
1 parent 6d80277 commit d2ece5235f38c2e4fb214b1b95b48d6f4333c0f5
@@ -1,6 +1,14 @@
package jmri.jmrit.vsdecoder;

/*
import java.awt.event.ActionEvent;
import java.io.File;
import javax.swing.AbstractAction;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* <hr>
* This file is part of JMRI.
* <P>
@@ -15,16 +23,8 @@
* for more details.
* <P>
*
* @author Mark Underwood Copyright (C) 2011
*
* @author Mark Underwood Copyright (C) 2011
*/
import java.awt.event.ActionEvent;
import java.io.File;
import javax.swing.AbstractAction;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Load VSDecoder Profiles from XML
@@ -51,7 +51,7 @@ public LoadVSDFileAction() {
}

JFileChooser fileChooser;
static private String last_path = null;
private String last_path = null;

/**
* The action is performed. Let the user choose the file to load from. Read
@@ -69,7 +69,7 @@ public void actionPerformed(ActionEvent e) {
start_dir = last_path;
}

log.debug("Using path: " + start_dir);
log.debug("Using path: {}", start_dir);

fileChooser = new JFileChooser(start_dir);
jmri.util.FileChooserFilter filt = new jmri.util.FileChooserFilter(Bundle.getMessage("LoadVSDFileChooserFilterLabel"));
@@ -101,7 +101,7 @@ public static boolean loadVSDFile(java.io.File f) {
// Create a VSD (zip) file.
try {
vsdfile = new VSDFile(f);
log.debug("VSD File name = " + vsdfile.getName());
log.debug("VSD File name = {}", vsdfile.getName());
if (vsdfile.isInitialized()) {
VSDecoderManager.instance().loadProfiles(vsdfile);
}
@@ -113,14 +113,14 @@ public static boolean loadVSDFile(java.io.File f) {
Bundle.getMessage("VSDFileError"), JOptionPane.ERROR_MESSAGE);
}

return (vsdfile.isInitialized());
return vsdfile.isInitialized();

} catch (java.util.zip.ZipException ze) {
log.error("ZipException opening file " + f.toString(), ze);
return (false);
return false;
} catch (java.io.IOException ze) {
log.error("IOException opening file " + f.toString(), ze);
return (false);
return false;
}
}

@@ -130,33 +130,32 @@ public static boolean loadVSDFile(String fp) {
try {
// Create a VSD (zip) file.
vsdfile = new VSDFile(fp);
log.debug("VSD File name = " + vsdfile.getName());
log.debug("VSD File name: {}", vsdfile.getName());
if (vsdfile.isInitialized()) {
VSDecoderManager.instance().loadProfiles(vsdfile);
}
// Cleanup and close files.
vsdfile.close();

return (vsdfile.isInitialized());
return vsdfile.isInitialized();
} catch (java.util.zip.ZipException ze) {
log.error("ZipException opening file " + fp, ze);
return (false);
return false;
} catch (java.io.IOException ze) {
log.error("IOException opening file " + fp, ze);
return (false);
return false;
}

/*
File f = null;
try {
f = new File(fp);
return(loadVSDFile(f));
return loadVSDFile(f);
} catch (java.io.IOException ioe) {
log.warn("IO Error auto-loading VSD File: " + (f==null?"(null)":f.getAbsolutePath()) + " ", ioe);
return(false);
return false;
} catch (NullPointerException npe) {
log.warn("NP Error auto-loading VSD File: FP = " + fp, npe);
return(false);
return false;
}
*/
}
@@ -24,7 +24,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/*
/**
* <hr>
* This file is part of JMRI.
* <P>
@@ -39,9 +39,8 @@
* for more details.
* <P>
*
* @author Mark Underwood Copyright (C) 2011
* @author Mark Underwood Copyright (C) 2011
*/
@SuppressWarnings("deprecation")
public class VSDConfigPanel extends JmriPanel {

// Local References
@@ -348,17 +347,15 @@ public void setRosterEntry(RosterEntry entry) {
if ((vsd_path != null) && (vsd_profile != null)) {
// Load the indicated VSDecoder Profile and update the Profile combo box
dec = VSDecoderManager.instance().getVSDecoder(vsd_profile, vsd_path);
if (dec != null) {
log.debug("VSDecoder loaded from file: " + dec.getProfileName());
dec.setAddress(rosterEntry.getDccLocoAddress());
dec.enable();
main_pane.setDecoder(dec);
ArrayList<String> sl = VSDecoderManager.instance().getVSDProfileNames();
updateProfileList(sl);
profileComboBox.setSelectedItem(dec.getProfileName());
profileComboBox.setEnabled(true);
profile_selected = true;
}
log.debug("VSDecoder loaded from file: " + dec.getProfileName());
dec.setAddress(rosterEntry.getDccLocoAddress());
dec.enable();
main_pane.setDecoder(dec);
ArrayList<String> sl = VSDecoderManager.instance().getVSDProfileNames();
updateProfileList(sl);
profileComboBox.setSelectedItem(dec.getProfileName());
profileComboBox.setEnabled(true);
profile_selected = true;
}

// Set the Address box from the Roster entry
@@ -390,24 +387,17 @@ private void rosterSaveButtonAction(ActionEvent e) {
log.debug("rosterSaveButton pressed");
if (rosterSelector.getSelectedRosterEntries().length != 0) {
RosterEntry r = rosterSelector.getSelectedRosterEntries()[0];
String path = main_pane.getDecoder().getVSDFilePath();
String profile = profileComboBox.getSelectedItem().toString();
if ((path == null) || (profile == null)) {
log.debug("Path and/or Profile not selected. Ignore Save button press.");
return;
} else {
r.setOpen(true);
r.putAttribute("VSDecoder_Path", main_pane.getDecoder().getVSDFilePath());
r.putAttribute("VSDecoder_Profile", profileComboBox.getSelectedItem().toString());
int value = JOptionPane.showConfirmDialog(null,
MessageFormat.format(Bundle.getMessage("UpdateRoster"),
new Object[]{r.titleString()}),
Bundle.getMessage("SaveRoster?"), JOptionPane.YES_NO_OPTION);
if (value == JOptionPane.YES_OPTION) {
storeFile(r);
}
r.setOpen(false);
r.setOpen(true);
r.putAttribute("VSDecoder_Path", main_pane.getDecoder().getVSDFilePath());
r.putAttribute("VSDecoder_Profile", profileComboBox.getSelectedItem().toString());
int value = JOptionPane.showConfirmDialog(null,
MessageFormat.format(Bundle.getMessage("UpdateRoster"),
new Object[]{r.titleString()}),
Bundle.getMessage("SaveRoster?"), JOptionPane.YES_NO_OPTION);
if (value == JOptionPane.YES_OPTION) {
storeFile(r);
}
r.setOpen(false);

// Need to write RosterEntry to file.
}
@@ -89,7 +89,7 @@
protected javax.swing.event.EventListenerList listenerList = new javax.swing.event.EventListenerList();

//private static VSDecoderManager instance = null; // sole instance of this class
private static VSDecoderManagerThread thread = null; // thread for running the manager
private volatile static VSDecoderManagerThread thread = null; // thread for running the manager

private VSDecoderPreferences vsdecoderPrefs; // local pointer to the preferences object

@@ -1,6 +1,6 @@
package jmri.jmrit.vsdecoder;

/*
/**
* <hr>
* This file is part of JMRI.
* <P>
@@ -15,12 +15,11 @@
* for more details.
* <P>
*
* @author Mark Underwood Copyright (C) 2011
*
* @author Mark Underwood Copyright (C) 2011
*/
class VSDecoderManagerThread extends Thread {

private static VSDecoderManagerThread instance = null;
private volatile static VSDecoderManagerThread instance = null;
private static VSDecoderManager manager = null;
boolean is_running;

@@ -31,8 +30,7 @@ private VSDecoderManagerThread() {

public static VSDecoderManagerThread instance(Boolean create) {
manager = new VSDecoderManager();

return (instance());
return instance();
}

public static VSDecoderManagerThread instance() {
@@ -41,13 +39,12 @@ public static VSDecoderManagerThread instance() {
temp.setName("VSDecoderManagerThread");
temp.start();
instance = temp; // don't allow escape of VSDecoderManagerThread object until running

}
return (instance);
return instance;
}

public static VSDecoderManager manager() {
return (VSDecoderManagerThread.manager);
return VSDecoderManagerThread.manager;
}

@Override
@@ -4,97 +4,83 @@
import javax.vecmath.Vector3f;
import jmri.AudioException;
import jmri.AudioManager;
import jmri.jmrit.audio.AudioFactory;
import jmri.jmrit.audio.AudioListener;
import jmri.util.PhysicalLocation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* <hr>
* This file is part of JMRI.
* <P>
* JMRI is free software; you can redistribute it and/or modify it under
* the terms of version 2 of the GNU General Public License as published
* by the Free Software Foundation. See the "COPYING" file for a copy
* of this license.
* <P>
* JMRI 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.
* <P>
*
* @author Mark Underwood Copyright (C) 2012
* @author Klaus Killinger Copyright (C) 2018
*/
public class VSDListener {

//public final static String ListenerSysNamePrefix = "IAL$VSD:";
// Only one Audio Listener can exist, and it is already present in the Audio Table
public final static String ListenerSysName = "IAL$";

private AudioListener _listener;
private String _sysname;
private String _username;
private ListeningSpot _location;

//public VSDListener(String sname) {
// this(sname, sname);
//}

//public VSDListener(String sname, String uname) {
// _sysname = ListenerSysNamePrefix + sname;
// _username = uname;

// AudioManager am = jmri.InstanceManager.getDefault(jmri.AudioManager.class);
// try {
// _listener = (AudioListener) am.provideAudio(ListenerSysNamePrefix + _sysname);
// log.debug("Listener Created: " + _listener);
// } catch (AudioException | IllegalArgumentException ae) {
// log.warn("Exception creating Listener: " + ae);
// // Do nothing?
// }
//}

public VSDListener(AudioListener l) {
_listener = l;
_sysname = l.getSystemName();
_username = l.getUserName();
}
private AudioFactory af;
private AudioListener listener;
private String sysname;
private String username;
private ListeningSpot location;

public VSDListener() {
// Initialize the AudioManager (if it isn't already) and get the Listener.
AudioManager am = jmri.InstanceManager.getDefault(jmri.AudioManager.class);
am.init();
_listener = am.getActiveAudioFactory().getActiveAudioListener();

List<String> names = am.getSystemNameList('L');
if (names.size() == 0) {
log.debug("No Listener yet. Creating one.");
af = am.getActiveAudioFactory();
if (af != null) {
listener = af.getActiveAudioListener();
log.debug("Default listener: {}, system name: {}", listener, listener.getSystemName());
setSystemName(listener.getSystemName());
setUserName(listener.getUserName());
} else {
log.debug("Found name: " + names.get(0));
log.warn("AudioFactory not available");
}
_sysname = _listener.getSystemName();
_username = _listener.getUserName();
}

public String getSystemName() {
return (_sysname);
return sysname;
}

public String getUserName() {
return (_username);
return username;
}

public ListeningSpot getLocation() {
return (_location);
return location;
}

public void setSystemName(String s) {
_sysname = s;
void setSystemName(String s) {
sysname = s;
}

public void setUserName(String u) {
_username = u;
void setUserName(String u) {
username = u;
}

public void setLocation(ListeningSpot l) {
_location = l;
_listener.setPosition(new Vector3f(l.getLocation()));
_listener.setOrientation(new Vector3f(l.getLookAtVector()), new Vector3f(l.getUpVector()));
location = l;
listener.setPosition(new Vector3f(l.getLocation()));
listener.setOrientation(new Vector3f(l.getLookAtVector()), new Vector3f(l.getUpVector()));
// Set position here
}

public void setPosition(PhysicalLocation p) {
if (_location == null) {
_location = new ListeningSpot();
}
_location.setLocation(p);
_listener.setPosition(p);
}

private final static Logger log = LoggerFactory.getLogger(VSDListener.class);

}

0 comments on commit d2ece52

Please sign in to comment.
You can’t perform that action at this time.