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  
22  /**
23   * Model of the list of Settypes.
24   * 
25   * Created on January 28, 2007
26   * 
27   * @author Christina Bohk
28   * @author Roland Ewald
29   * 
30   */
31  public class SetTypesListModel extends AbstractListModel {
32  
33  	/** Serialization ID. */
34  	private static final long serialVersionUID = 8369935030761632549L;
35  
36  	/** Reference to edited projection. */
37  	private ProjectionModel projection;
38  
39  	/**
40  	 * Default constructor.
41  	 * 
42  	 * @param currentProjection
43  	 *          the projection to be edited
44  	 */
45  	public SetTypesListModel(ProjectionModel currentProjection) {
46  		this.projection = currentProjection;
47  	}
48  
49  	@Override
50  	public Object getElementAt(int index) {
51  		return this.projection.getSetType(index);
52  	}
53  
54  	@Override
55  	public int getSize() {
56  		return this.projection.getNumOfSetTypes();
57  	}
58  
59  	/**
60  	 * Remove a Settype.
61  	 * 
62  	 * @param index
63  	 *          index of the Settype
64  	 */
65  	public void removeSetType(int index) {
66  		this.projection.removeSetType(index);
67  		this.fireContentsChanged(this, index, getSize() + 1);
68  	}
69  
70  	/**
71  	 * Add a Settype.
72  	 * 
73  	 * @param name
74  	 *          name of the Settype
75  	 * @param desc
76  	 *          description of the Settype
77  	 */
78  	public void addSetType(String name, String desc) {
79  		int index = this.projection.getNumOfSetTypes();
80  		this.projection.createSetType(name, desc);
81  		this.fireContentsChanged(this, index, index + 1);
82  	}
83  
84  	/**
85  	 * Propagates event of a changing Settype.
86  	 * 
87  	 * @param stIndex
88  	 *          index of Settype that was changed
89  	 */
90  	public void setTypeChanged(int stIndex) {
91  		this.fireContentsChanged(this, stIndex, stIndex);
92  	}
93  
94  	public ProjectionModel getProjection() {
95  		return projection;
96  	}
97  
98  	public void setProjection(ProjectionModel scenario) {
99  		this.projection = scenario;
100 	}
101 
102 }