001: /*
002: * SkeletonPropertyTableModel.java
003: *
004: * Created on 14 août 2003, 22:12
005: */
006:
007: package net.charabia.jsmoothgen.skeleton;
008:
009: import java.util.*;
010:
011: /**
012: *
013: * @author Rodrigo
014: */
015: public class SkeletonPropertyTableModel extends
016: javax.swing.table.AbstractTableModel {
017: private Vector m_props = new Vector();
018:
019: /** Creates a new instance of SkeletonPropertyTableModel */
020: public SkeletonPropertyTableModel(SkeletonProperty[] props) {
021: if (props == null)
022: return;
023:
024: for (int i = 0; i < props.length; i++) {
025: m_props.add(props[i]);
026: }
027: }
028:
029: public SkeletonPropertyTableModel() {
030: m_props.add(new SkeletonProperty());
031: }
032:
033: public void add(SkeletonProperty prop) {
034: m_props.addElement(prop);
035: fireTableRowsInserted(m_props.size() - 1, m_props.size());
036: fireTableStructureChanged();
037: }
038:
039: public void add(SkeletonProperty prop, int row) {
040: m_props.insertElementAt(prop, row);
041: fireTableRowsInserted(row, row);
042: fireTableStructureChanged();
043: }
044:
045: public void removeRow(int row) {
046: m_props.removeElementAt(row);
047: fireTableRowsDeleted(row, row);
048: }
049:
050: public String getColumnName(int column) {
051: switch (column) {
052: case 0:
053: return "Id";
054: case 1:
055: return "GUI Label";
056: case 2:
057: return "Description";
058: case 3:
059: return "Type";
060: case 4:
061: return "Default Values";
062: default:
063: return "";
064: }
065: }
066:
067: public int getColumnCount() {
068: return 5;
069: }
070:
071: public int getRowCount() {
072: return m_props.size();
073: }
074:
075: public boolean isCellEditable(int rowIndex, int columnIndex) {
076: return true;
077: }
078:
079: public Object getValueAt(int rowIndex, int columnIndex) {
080: SkeletonProperty sp = (SkeletonProperty) m_props.get(rowIndex);
081: switch (columnIndex) {
082: case 0:
083: return sp.getIdName();
084: case 1:
085: return sp.getLabel();
086: case 2:
087: return sp.getDescription();
088: case 3:
089: return sp.getType();
090: case 4:
091: return sp.getValue();
092: default:
093: return "";
094: }
095: }
096:
097: public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
098: SkeletonProperty sp = (SkeletonProperty) m_props.get(rowIndex);
099: switch (columnIndex) {
100: case 0:
101: sp.setIdName(aValue.toString());
102: break;
103: case 1:
104: sp.setLabel(aValue.toString());
105: break;
106: case 2:
107: sp.setDescription(aValue.toString());
108: break;
109: case 3:
110: sp.setType(aValue.toString());
111: break;
112: case 4:
113: sp.setValue(aValue.toString());
114: break;
115: }
116: }
117:
118: public SkeletonProperty[] getProperties() {
119: SkeletonProperty[] result = new SkeletonProperty[m_props.size()];
120: for (int i = 0; i < result.length; i++) {
121: result[i] = (SkeletonProperty) m_props.get(i);
122: }
123: return result;
124: }
125:
126: public void swapItems(int offset1, int offset2) {
127: if ((offset1 >= 0) && (offset1 < m_props.size())
128: && (offset2 >= 0) && (offset2 < m_props.size())) {
129: Object o1 = m_props.get(offset1);
130: Object o2 = m_props.get(offset2);
131: m_props.set(offset1, o2);
132: m_props.set(offset2, o1);
133: }
134: fireTableRowsUpdated(Math.min(offset1, offset2), Math.max(
135: offset1, offset2));
136: }
137: }
|