001package jmri.jmrit.operations.rollingstock.cars; 002 003import org.jdom2.Element; 004import org.slf4j.Logger; 005import org.slf4j.LoggerFactory; 006 007import jmri.InstanceManager; 008import jmri.InstanceManagerAutoDefault; 009import jmri.jmrit.operations.rollingstock.RollingStockAttribute; 010 011/** 012 * Represents the colors that cars can have. 013 * 014 * @author Daniel Boudreau Copyright (C) 2008, 2014 015 */ 016public class CarColors extends RollingStockAttribute implements InstanceManagerAutoDefault { 017 018 private static final String COLORS = Bundle.getMessage("carColors"); 019 public static final String CARCOLORS_CHANGED_PROPERTY = "CarColors"; // NOI18N 020 public static final String CARCOLORS_NAME_CHANGED_PROPERTY = "CarColorsName"; // NOI18N 021 022 public CarColors() { 023 } 024 025 @Override 026 protected String getDefaultNames() { 027 return COLORS; 028 } 029 030 @Override 031 public void addName(String color) { 032 super.addName(color); 033 setDirtyAndFirePropertyChange(CARCOLORS_CHANGED_PROPERTY, null, color); 034 } 035 036 @Override 037 public void deleteName(String color) { 038 super.deleteName(color); 039 setDirtyAndFirePropertyChange(CARCOLORS_CHANGED_PROPERTY, color, null); 040 } 041 042 public void replaceName(String oldName, String newName) { 043 super.addName(newName); 044 setDirtyAndFirePropertyChange(CARCOLORS_NAME_CHANGED_PROPERTY, oldName, newName); 045 // need to keep old name so location manager can replace properly 046 super.deleteName(oldName); 047 } 048 049 @edu.umd.cs.findbugs.annotations.SuppressFBWarnings( value="SLF4J_FORMAT_SHOULD_BE_CONST", 050 justification="I18N of Info Message") 051 @Override 052 public int getMaxNameLength() { 053 if (maxNameLength == 0) { 054 super.getMaxNameLength(); 055 log.info(Bundle.getMessage("InfoMaxColor", maxName, maxNameLength)); 056 } 057 return maxNameLength; 058 } 059 060 /** 061 * Create an XML element to represent this Entry. This member has to remain 062 * synchronized with the detailed DTD in operations-cars.dtd. 063 * 064 * @param root The common Element for operations-cars.dtd. 065 */ 066 public void store(Element root) { 067 store(root, Xml.COLORS, Xml.COLOR); 068 } 069 070 public void load(Element root) { 071 load(root, Xml.COLORS, Xml.COLOR, Xml.CAR_COLORS); 072 } 073 074 protected void setDirtyAndFirePropertyChange(String p, Object old, Object n) { 075 // Set dirty 076 InstanceManager.getDefault(CarManagerXml.class).setDirty(true); 077 super.firePropertyChange(p, old, n); 078 } 079 080 private final static Logger log = LoggerFactory.getLogger(CarColors.class); 081 082}