Skip to content
Permalink
Browse files

Store consist file location when roster file location changes

  • Loading branch information...
pabender committed Aug 8, 2019
1 parent 5775c7b commit 75cd1bc25007270bc2073b0a2fb5ad27b2803d13
Showing with 22 additions and 3 deletions.
  1. +22 −3 java/src/jmri/jmrit/consisttool/ConsistFile.java
@@ -1,5 +1,7 @@
package jmri.jmrit.consisttool;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
@@ -14,6 +16,7 @@
import jmri.InstanceManager;
import jmri.jmrit.XmlFile;
import jmri.jmrit.roster.Roster;
import jmri.jmrit.roster.RosterConfigManager;
import jmri.util.FileUtil;
import org.jdom2.Attribute;
import org.jdom2.Document;
@@ -30,15 +33,14 @@
*
* @author Paul Bender Copyright (C) 2008
*/
public class ConsistFile extends XmlFile {
public class ConsistFile extends XmlFile implements PropertyChangeListener {

protected ConsistManager consistMan = null;

public ConsistFile() {
super();
consistMan = InstanceManager.getDefault(jmri.ConsistManager.class);
// set the location to a subdirectory of the defined roster
// directory
Roster.getDefault().addPropertyChangeListener(this);
}

/**
@@ -332,6 +334,23 @@ static public void setFileLocation(String loc) {
public static String defaultConsistFilename() {
return getFileLocation() + "consist.xml";
}

/**
* {@inheritDoc}
*/
@Override
public void propertyChange(PropertyChangeEvent evt) {
if (evt.getSource() instanceof Roster) {
if (evt.getPropertyName().equals(RosterConfigManager.DIRECTORY)) {
try {
this.writeFile(consistMan.getConsistList());
} catch(IOException ioe){
log.error("Unable to write consist information to new consist folder");
}
}
}
}

// initialize logging
private final static Logger log = LoggerFactory.getLogger(ConsistFile.class);
}

0 comments on commit 75cd1bc

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