View Javadoc

1   /*
2    * Copyright 2006 - 2012 Christina Bohk and Roland Ewald
3    *  
4    * Licensed under the Apache License, Version 2.0 (the "License"); 
5    * you may not use this file except in compliance with the License. 
6    * You may obtain a copy of the License at 
7    *  
8    *  http://www.apache.org/licenses/LICENSE-2.0
9    *  
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
13   * See the License for the specific language governing permissions and 
14   * limitations under the License. 
15   */
16  package p3j.gui.misc;
17  
18  import javax.swing.AbstractListModel;
19  
20  import p3j.pppm.ProjectionModel;
21  import p3j.pppm.sets.SetType;
22  
23  /**
24   * Model of the list of Settypes.
25   * 
26   * Created on January 28, 2007
27   * 
28   * @author Christina Bohk
29   * @author Roland Ewald
30   * 
31   */
32  public class SetTypesListModel extends AbstractListModel<SetType> {
33  
34  	/** Serialization ID. */
35  	private static final long serialVersionUID = 8369935030761632549L;
36  
37  	/** Reference to edited projection. */
38  	private ProjectionModel projection;
39  
40  	/**
41  	 * Default constructor.
42  	 * 
43  	 * @param currentProjection
44  	 *          the projection to be edited
45  	 */
46  	public SetTypesListModel(ProjectionModel currentProjection) {
47  		this.projection = currentProjection;
48  	}
49  
50  	@Override
51  	public SetType getElementAt(int index) {
52  		return this.projection.getSetType(index);
53  	}
54  
55  	@Override
56  	public int getSize() {
57  		return this.projection.getNumOfSetTypes();
58  	}
59  
60  	/**
61  	 * Remove a Settype.
62  	 * 
63  	 * @param index
64  	 *          index of the Settype
65  	 */
66  	public void removeSetType(int index) {
67  		this.projection.removeSetType(index);
68  		this.fireContentsChanged(this, index, getSize() + 1);
69  	}
70  
71  	/**
72  	 * Add a Settype.
73  	 * 
74  	 * @param name
75  	 *          name of the Settype
76  	 * @param desc
77  	 *          description of the Settype
78  	 */
79  	public void addSetType(String name, String desc) {
80  		int index = this.projection.getNumOfSetTypes();
81  		this.projection.createSetType(name, desc);
82  		this.fireContentsChanged(this, index, index + 1);
83  	}
84  
85  	/**
86  	 * Propagates event of a changing Settype.
87  	 * 
88  	 * @param stIndex
89  	 *          index of Settype that was changed
90  	 */
91  	public void setTypeChanged(int stIndex) {
92  		this.fireContentsChanged(this, stIndex, stIndex);
93  	}
94  
95  	public ProjectionModel getProjection() {
96  		return projection;
97  	}
98  
99  	public void setProjection(ProjectionModel scenario) {
100 		this.projection = scenario;
101 	}
102 
103 }