001package jmri.jmrit.vsdecoder; 002 003import java.beans.PropertyChangeEvent; 004import org.jdom2.Element; 005 006/** 007 * Throttle trigger. 008 * 009 * <hr> 010 * This file is part of JMRI. 011 * <p> 012 * JMRI is free software; you can redistribute it and/or modify it under 013 * the terms of version 2 of the GNU General Public License as published 014 * by the Free Software Foundation. See the "COPYING" file for a copy 015 * of this license. 016 * <p> 017 * JMRI is distributed in the hope that it will be useful, but WITHOUT 018 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 019 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 020 * for more details. 021 * 022 * @author Mark Underwood Copyright (C) 2011 023 */ 024class ThrottleTrigger extends Trigger { 025 026 public ThrottleTrigger(String name) { 027 super(name); 028 this.setTriggerType(Trigger.TriggerType.THROTTLE); 029 } 030 031 @Override 032 public void propertyChange(PropertyChangeEvent event) { 033 034 // Validate 035 // If no target, or not a name match, or no trigger, or no action 036 // then just return quickly. 037 // Careful: Takes advantage of "lazy OR" behavior 038 if (target == null) { 039 //log.debug("Quit. No target."); 040 return; 041 } 042 if (!event.getPropertyName().equals(this.getEventName())) { 043 //log.debug("Quit. Event name mismatch event: {}, this: {}", event.getPropertyName(), this.getEventName()); 044 return; 045 } 046 if (this.getTriggerType() == TriggerType.NONE) { 047 //log.debug("Quit. TriggerType = NONE"); 048 return; 049 } 050 if (this.getTargetAction() == TargetAction.NOTHING || this.getTargetAction() == TargetAction.STOP_AT_ZERO) { 051 //log.debug("Quit. TargetAction = NOTHING"); 052 return; 053 } 054 055 log.debug("Throttle Trigger old value: {}, new value: {}", event.getOldValue(), event.getNewValue()); 056 this.callback.takeAction((Float) event.getNewValue()); 057 } 058 059 @Override 060 public Element getXml() { 061 Element me = new Element("Trigger"); 062 me.setAttribute("name", this.getName()); 063 me.setAttribute("type", "THROTTLE"); 064 log.warn("CompareTrigger.getXml() not implemented"); 065 return me; 066 } 067 068 @Override 069 public void setXml(Element e) { 070 //Get common stuff 071 super.setXml(e); 072 } 073 074 private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(ThrottleTrigger.class); 075 076}