annotate java/src/uk/ac/qmul/eecs/ccmi/gui/PropertyTableModel.java @ 1:e3935c01cde2 tip

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