AbstractMultiModelKnob.java

  1. // @formatter:off
  2.  /*******************************************************************************
  3.  *
  4.  * This file is part of JMad.
  5.  *
  6.  * Copyright (c) 2008-2011, CERN. All rights reserved.
  7.  *
  8.  * Licensed under the Apache License, Version 2.0 (the "License");
  9.  * you may not use this file except in compliance with the License.
  10.  * You may obtain a copy of the License at
  11.  *
  12.  *     http://www.apache.org/licenses/LICENSE-2.0
  13.  *
  14.  * Unless required by applicable law or agreed to in writing, software
  15.  * distributed under the License is distributed on an "AS IS" BASIS,
  16.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17.  * See the License for the specific language governing permissions and
  18.  * limitations under the License.
  19.  *
  20.  ******************************************************************************/
  21. // @formatter:on

  22. /*
  23.  * $Id $
  24.  *
  25.  * $Date$ $Revision$ $Author$
  26.  *
  27.  * Copyright CERN ${year}, All Rights Reserved.
  28.  */
  29. package cern.accsoft.steering.jmad.model.knob;

  30. import java.util.ArrayList;
  31. import java.util.List;

  32. import cern.accsoft.steering.jmad.domain.knob.AbstractKnob;
  33. import cern.accsoft.steering.jmad.model.JMadModel;

  34. /**
  35.  * Implementation of a Knob which allows to act on multiple Models. Changes to the Knob value have to be propagated to
  36.  * all connected Models.
  37.  *
  38.  * @author muellerg
  39.  */
  40. public abstract class AbstractMultiModelKnob extends AbstractKnob implements MultiModelKnob {

  41.     /** the list of models that are connected to knob */
  42.     private List<JMadModel> connectedModels;

  43.     @Override
  44.     public synchronized void addModel(JMadModel model) {
  45.         this.connectedModels.add(model);
  46.     }

  47.     public AbstractMultiModelKnob() {
  48.         /* new empty model list, models are added later on */
  49.         this.connectedModels = new ArrayList<JMadModel>();
  50.     }

  51.     /**
  52.      * @return the {@link JMadModel}s connected to this Knob.
  53.      */
  54.     public synchronized List<JMadModel> getConnectedModels() {
  55.         return this.connectedModels;
  56.     }
  57. }