Mercurial > hg > accesspd
comparison java/src/uk/ac/qmul/eecs/ccmi/gui/PropertyTableModel.java @ 0:78b7fc5391a2
first import, outcome of NIME 2014 hackaton
author | Fiore Martin <f.martin@qmul.ac.uk> |
---|---|
date | Tue, 08 Jul 2014 16:28:59 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:78b7fc5391a2 |
---|---|
1 /* | |
2 CCmI Editor - A Collaborative Cross-Modal Diagram Editing Tool | |
3 | |
4 Copyright (C) 2011 Queen Mary University of London (http://ccmi.eecs.qmul.ac.uk/) | |
5 | |
6 This program is free software: you can redistribute it and/or modify | |
7 it under the terms of the GNU General Public License as published by | |
8 the Free Software Foundation, either version 3 of the License, or | |
9 (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, see <http://www.gnu.org/licenses/>. | |
18 */ | |
19 package uk.ac.qmul.eecs.ccmi.gui; | |
20 | |
21 import java.util.HashSet; | |
22 import java.util.List; | |
23 import java.util.ArrayList; | |
24 import java.util.Set; | |
25 | |
26 import javax.swing.table.AbstractTableModel; | |
27 | |
28 import uk.ac.qmul.eecs.ccmi.diagrammodel.NodeProperties.Modifiers; | |
29 | |
30 | |
31 /** | |
32 * A table model containing the property values currently edited in a table of a {@code PropertyEditorDialog} | |
33 * and the modifiers assigned to them | |
34 * in the form of an array of indexes pointing to the modifiers types | |
35 */ | |
36 @SuppressWarnings("serial") | |
37 public class PropertyTableModel extends AbstractTableModel { | |
38 | |
39 /** | |
40 * Construct a new {@code PropertyTableModel}. | |
41 * | |
42 * @param propertyType the type of the node property related to this table model | |
43 * @param values the list of values for this node property | |
44 * @param modifiers the modifiers for this node property | |
45 */ | |
46 public PropertyTableModel(String propertyType, List<String> values, Modifiers modifiers ){ | |
47 data = new ArrayList<ModifierString>(); | |
48 for(int i = 0; i< values.size();i++){ | |
49 String value = values.get(i); | |
50 data.add(new ModifierString(value, (modifiers == null) ? null : modifiers.getIndexes(i))); | |
51 } | |
52 data.add(new ModifierString(null)); | |
53 columnName = propertyType; | |
54 } | |
55 | |
56 @Override | |
57 public int getColumnCount() { | |
58 return 1; | |
59 } | |
60 | |
61 @Override | |
62 public int getRowCount() { | |
63 return data.size(); | |
64 } | |
65 | |
66 @Override | |
67 public Object getValueAt(int rowIndex, int columnIndex) { | |
68 return data.get(rowIndex); | |
69 } | |
70 | |
71 @Override | |
72 public String getColumnName(int column){ | |
73 return columnName; | |
74 } | |
75 | |
76 @Override | |
77 public void setValueAt(Object value, int rowIndex, int columnIndex){ | |
78 /* we filled up the last row, create another one */ | |
79 if((rowIndex == data.size()-1)&&(!value.toString().equals(""))){ | |
80 data.add(new ModifierString(null)); | |
81 data.get(rowIndex).value = value.toString(); | |
82 fireTableRowsInserted(data.size()-1, data.size()-1); | |
83 fireTableCellUpdated(rowIndex,columnIndex); | |
84 }else if((rowIndex != data.size()-1)&&(value.toString().equals(""))){ | |
85 data.remove(rowIndex); | |
86 fireTableRowsDeleted(rowIndex,rowIndex); | |
87 }else { | |
88 data.get(rowIndex).value = value.toString(); | |
89 fireTableCellUpdated(rowIndex,columnIndex); | |
90 } | |
91 } | |
92 | |
93 @Override | |
94 public boolean isCellEditable(int rowIndex, int columnIndex){ | |
95 return true; | |
96 } | |
97 | |
98 /** | |
99 * Returns the indexes (pointing to the modifiers types) of the property value at the specified row in the table | |
100 * with this model. | |
101 * | |
102 * @param row the row of the property value | |
103 * @return the modifiers type indexes for the specified property value | |
104 */ | |
105 public Set<Integer> getIndexesAt(int row){ | |
106 return data.get(row).modifierIndexes; | |
107 } | |
108 | |
109 /** | |
110 * Set the the indexes (pointing to the modifiers types) of the property value at the specified row in the table | |
111 * with this model. | |
112 * | |
113 * @param row he row of the property value | |
114 * @param indexes the modifiers type indexes for the specified property value | |
115 */ | |
116 public void setIndexesAt(int row, Set<Integer> indexes){ | |
117 data.get(row).modifierIndexes = new HashSet<Integer>(); | |
118 data.get(row).modifierIndexes.addAll(indexes); | |
119 } | |
120 | |
121 /** | |
122 * Set the the indexes (pointing to the modifiers types) of the property value at the specified row in the table | |
123 * with this model. | |
124 * | |
125 * @param row he row of the property value | |
126 * @param indexes the modifiers type indexes for the specified property value | |
127 */ | |
128 public void setIndexesAt(int row, Integer[] indexes){ | |
129 data.get(row).modifierIndexes = new HashSet<Integer>(); | |
130 for(int i=0; i<indexes.length; i++) | |
131 data.get(row).modifierIndexes.add(indexes[i]); | |
132 } | |
133 | |
134 private List<ModifierString> data; | |
135 private String columnName; | |
136 | |
137 private class ModifierString { | |
138 ModifierString(String value, Set<Integer> s){ | |
139 this.value = value; | |
140 modifierIndexes = new HashSet<Integer>(); | |
141 if(s != null){ | |
142 modifierIndexes.addAll(s); | |
143 } | |
144 } | |
145 | |
146 ModifierString(Set<Integer> s){ | |
147 this("",s); | |
148 } | |
149 | |
150 @Override | |
151 public boolean equals(Object o){ | |
152 return value.equals(o); | |
153 } | |
154 | |
155 @Override | |
156 public int hashCode(){ | |
157 return value.hashCode(); | |
158 } | |
159 | |
160 @Override | |
161 public String toString(){ | |
162 return value; | |
163 } | |
164 | |
165 private String value; | |
166 private Set<Integer> modifierIndexes; | |
167 } | |
168 | |
169 } |