Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.utils / src / main / java / org / gvsig / utils / listManager / DefaultListModel.java @ 40561

History | View | Annotate | Download (2.63 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.utils.listManager;
25

    
26
import java.util.Vector;
27

    
28
import javax.swing.AbstractListModel;
29
/**
30
 * Implementaci?n por defecto de ListModel
31
 *
32
 * @author Fernando Gonz?lez Cort?s
33
 */
34
public class DefaultListModel extends AbstractListModel implements ListModel {
35
    private Vector v;
36
    private boolean down=true;
37
    /**
38
     * Crea un nuevo DefaultListModel con un par?metro que indica si la lista
39
     * se crea en el orden que se van introcuciendo(true) o al contrario.
40
     */
41
    public DefaultListModel(boolean down) {
42
        v = new Vector();
43
        this.down=down;
44
    }
45

    
46
    /**
47
     * @see org.gvsig.utils.listManager.ListModel#remove(int)
48
     */
49
    public Object remove(int i) throws ArrayIndexOutOfBoundsException {
50
        Object o = v.remove(i);
51
        super.fireIntervalRemoved(this, i, i);
52

    
53
        return o;
54
    }
55

    
56
    /**
57
     * @see org.gvsig.utils.listManager.ListModel#insertAt(int,
58
     *      java.lang.Object)
59
     */
60
    public void insertAt(int i, Object o) {
61
        v.add(i, o);
62
        super.fireIntervalAdded(this, i, i);
63
    }
64

    
65
    /**
66
     * @see javax.swing.ListModel#getSize()
67
     */
68
    public int getSize() {
69
        return v.size();
70
    }
71

    
72
    /**
73
     * @see javax.swing.ListModel#getElementAt(int)
74
     */
75
    public Object getElementAt(int arg0) {
76
        return v.get(arg0);
77
    }
78

    
79
    /**
80
     * @see org.gvsig.utils.listManager.ListModel#add(java.lang.Object)
81
     */
82
    public void add(Object o) {
83
      if (down) {
84
        v.add(o);
85
        super.fireIntervalAdded(this, v.size() - 1, v.size() - 1);
86
      } else {
87
        insertAt(0, o);
88
      }
89
    }
90

    
91
        /**
92
         * @see org.gvsig.utils.listManager.ListModel#getObjects()
93
         */
94
        public Vector getObjects() {
95
                return v;
96
        }
97
}