001package jmri.jmrit.operations.rollingstock.cars; 002 003import org.jdom2.Element; 004 005import jmri.InstanceManager; 006import jmri.InstanceManagerAutoDefault; 007import jmri.jmrit.operations.rollingstock.RollingStockAttribute; 008 009/** 010 * Represents the owner names that cars can have. 011 * 012 * @author Daniel Boudreau Copyright (C) 2008, 2014 013 */ 014public class CarOwners extends RollingStockAttribute implements InstanceManagerAutoDefault { 015 016 public static final String CAROWNERS_NAME_CHANGED_PROPERTY = "CarOwners Name"; // NOI18N 017 public static final String CAROWNERS_CHANGED_PROPERTY = "CarOwners Length"; // NOI18N 018 019 public CarOwners() { 020 } 021 022 @Override 023 protected String getDefaultNames() { 024 return ""; // there aren't any 025 } 026 027 @Override 028 public void addName(String owner) { 029 super.addName(owner); 030 setDirtyAndFirePropertyChange(CAROWNERS_CHANGED_PROPERTY, null, owner); 031 } 032 033 @Override 034 public void deleteName(String owner) { 035 super.deleteName(owner); 036 setDirtyAndFirePropertyChange(CAROWNERS_CHANGED_PROPERTY, owner, null); 037 } 038 039 public void replaceName(String oldName, String newName) { 040 super.addName(newName); 041 setDirtyAndFirePropertyChange(CAROWNERS_NAME_CHANGED_PROPERTY, oldName, newName); 042 super.deleteName(oldName); 043 } 044 045 /** 046 * Create an XML element to represent this Entry. This member has to remain 047 * synchronized with the detailed DTD in operations-cars.dtd. 048 * 049 * @param root The common Element for operations-cars.dtd. 050 * 051 */ 052 public void store(Element root) { 053 store(root, Xml.OWNERS, Xml.OWNER); 054 } 055 056 public void load(Element root) { 057 load(root, Xml.OWNERS, Xml.OWNER, Xml.CAR_OWNERS); 058 } 059 060 protected void setDirtyAndFirePropertyChange(String p, Object old, Object n) { 061 // Set dirty 062 InstanceManager.getDefault(CarManagerXml.class).setDirty(true); 063 super.firePropertyChange(p, old, n); 064 } 065 066// private final static Logger log = LoggerFactory.getLogger(CarOwners.class); 067 068}