Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / gui / wizards / LayerListModel.java @ 40558

History | View | Annotate | Download (2.99 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.app.gui.wizards;
25

    
26
import java.util.ArrayList;
27
import java.util.Collection;
28

    
29
import javax.swing.AbstractListModel;
30

    
31

    
32
/**
33
 * DOCUMENT ME!
34
 *
35
 * @author Fernando Gonz?lez Cort?s
36
 */
37
public class LayerListModel extends AbstractListModel {
38
    private ArrayList nodos = new ArrayList();
39

    
40
    /**
41
     * DOCUMENT ME!
42
     *
43
     * @param elemento DOCUMENT ME!
44
     *
45
     * @return DOCUMENT ME!
46
     */
47
    public boolean addElement(LayerInfo elemento) {
48
        if (elemento == null) {
49
            return false;
50
        }
51

    
52
        for (int i = 0; i < nodos.size(); i++) {
53
            if (((LayerInfo) nodos.get(i)).equals(elemento)) {
54
                return false;
55
            }
56
        }
57

    
58
        nodos.add(elemento);
59

    
60
        fireContentsChanged(this, nodos.size() - 1, nodos.size() - 1);
61

    
62
        return true;
63
    }
64

    
65
        public void clear(){
66
                nodos.clear();
67
                fireContentsChanged(this, 0, 0);
68
        }
69

    
70
    /**
71
     * DOCUMENT ME!
72
     *
73
     * @param index DOCUMENT ME!
74
     *
75
     * @return DOCUMENT ME!
76
     */
77
    public LayerInfo delElement(int index) {
78
        LayerInfo ret = (LayerInfo) nodos.remove(index);
79
        this.fireContentsChanged(this, index, index);
80

    
81
        return ret;
82
    }
83

    
84
    /**
85
     * DOCUMENT ME!
86
     *
87
     * @param c DOCUMENT ME!
88
     */
89
    public void delElements(Collection c) {
90
        nodos.removeAll(c);
91
        this.fireContentsChanged(this, 0, nodos.size());
92
    }
93

    
94
    /**
95
     * @see javax.swing.ListModel#getSize()
96
     */
97
    public int getSize() {
98
        return nodos.size();
99
    }
100

    
101
    /**
102
     * @see javax.swing.ListModel#getElementAt(int)
103
     */
104
    public Object getElementAt(int index) {
105
        return ((LayerInfo) nodos.get(index)).text;
106
    }
107

    
108
    /**
109
     * DOCUMENT ME!
110
     *
111
     * @return DOCUMENT ME!
112
     */
113
    public LayerInfo[] getElements() {
114
        return (LayerInfo[]) nodos.toArray(new LayerInfo[0]);
115
    }
116

    
117
    /**
118
     * DOCUMENT ME!
119
     *
120
     * @param index DOCUMENT ME!
121
     *
122
     * @return DOCUMENT ME!
123
     */
124
    public LayerInfo getLayerInfo(int index) {
125
        return (LayerInfo) nodos.get(index);
126
    }
127
}