gvsig-3d / org.gvsig.animation3d / trunk / org.gvsig.animation3d / org.gvsig.animation3d.swing / org.gvsig.animation3d.swing.impl / src / main / java / org / gvsig / animation3d / swing / impl / DefaultAnimation3DTableModel.java @ 672
History | View | Annotate | Download (2.76 KB)
1 |
package org.gvsig.animation3d.swing.impl; |
---|---|
2 |
|
3 |
import java.util.List; |
4 |
|
5 |
import javax.swing.table.AbstractTableModel; |
6 |
|
7 |
import org.gvsig.animation3d.swing.api.Animation3D; |
8 |
import org.gvsig.tools.ToolsLocator; |
9 |
import org.gvsig.tools.dataTypes.CoercionException; |
10 |
import org.gvsig.tools.dataTypes.DataTypes; |
11 |
import org.gvsig.tools.i18n.I18nManager; |
12 |
import org.slf4j.Logger; |
13 |
import org.slf4j.LoggerFactory; |
14 |
|
15 |
/**
|
16 |
* @author <a href="mailto:lmarques@disid.com">Lluis Marques</a>
|
17 |
*
|
18 |
*/
|
19 |
public class DefaultAnimation3DTableModel extends AbstractTableModel { |
20 |
|
21 |
private static final long serialVersionUID = 482904298368611455L; |
22 |
|
23 |
private static final Logger LOG = LoggerFactory.getLogger(DefaultAnimation3DTableModel.class); |
24 |
|
25 |
private List<Animation3D> animations; |
26 |
|
27 |
private String[] columns = new String[] { "animation" }; |
28 |
|
29 |
/**
|
30 |
*
|
31 |
* @param animations
|
32 |
*/
|
33 |
public DefaultAnimation3DTableModel(List<Animation3D> animations) { |
34 |
this.animations = animations;
|
35 |
} |
36 |
|
37 |
@Override
|
38 |
public String getColumnName(int column) { |
39 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
40 |
return i18nManager.getTranslation(columns[column]);
|
41 |
} |
42 |
|
43 |
@Override
|
44 |
public int getColumnCount() { |
45 |
return columns.length;
|
46 |
} |
47 |
|
48 |
@Override
|
49 |
public int getRowCount() { |
50 |
return animations.size();
|
51 |
} |
52 |
|
53 |
@Override
|
54 |
public Object getValueAt(int row, int column) { |
55 |
return animations.get(row).getName();
|
56 |
} |
57 |
|
58 |
@Override
|
59 |
public void setValueAt(Object aValue, int rowIndex, int columnIndex) { |
60 |
String name;
|
61 |
try {
|
62 |
name = (String) ToolsLocator.getDataTypesManager().coerce(DataTypes.STRING, aValue);
|
63 |
} catch (CoercionException e) {
|
64 |
LOG.warn(String.format("Can not coerce %1s to String", aValue), e); |
65 |
return;
|
66 |
} |
67 |
this.getAnimation(rowIndex).setName(name);
|
68 |
fireTableCellUpdated(rowIndex, columnIndex); |
69 |
} |
70 |
|
71 |
@Override
|
72 |
public boolean isCellEditable(int rowIndex, int columnIndex) { |
73 |
return columnIndex == 0; |
74 |
} |
75 |
|
76 |
public void addAnimation(Animation3D animation){ |
77 |
this.animations.add(animation);
|
78 |
fireTableRowsInserted(animations.size() , animations.size()); |
79 |
} |
80 |
|
81 |
public Animation3D getAnimation(int index){ |
82 |
return animations.get(index);
|
83 |
} |
84 |
|
85 |
public void removeAnimation(Animation3D animation){ |
86 |
int index = this.animations.indexOf(animation); |
87 |
if(index != -1){ |
88 |
this.animations.remove(animation);
|
89 |
fireTableRowsDeleted(index, index); |
90 |
} |
91 |
} |
92 |
|
93 |
public void removeAnimation(int index){ |
94 |
if( index > -1 && index < animations.size()){ |
95 |
this.animations.remove(index);
|
96 |
fireTableRowsDeleted(index, index); |
97 |
} |
98 |
} |
99 |
} |