From 0ec8481c10cd8277d84c7c1a785483a0a739e5a0 Mon Sep 17 00:00:00 2001 From: abranson Date: Thu, 4 Aug 2011 00:42:34 +0200 Subject: More code cleanup: Refactored Entity Proxy Subscription to handle generics better Rewrote RemoteMap to use TreeMap instead of the internal array for order. It now sorts its keys by number if they parse, else as strings. Removed a no-longer-in-progress outcome form class --- .../c2kernel/graph/view/PropertyTableModel.java | 46 +++++++++++++--------- 1 file changed, 28 insertions(+), 18 deletions(-) (limited to 'source/com/c2kernel/graph/view/PropertyTableModel.java') diff --git a/source/com/c2kernel/graph/view/PropertyTableModel.java b/source/com/c2kernel/graph/view/PropertyTableModel.java index 22ba4f3..b1e69b1 100644 --- a/source/com/c2kernel/graph/view/PropertyTableModel.java +++ b/source/com/c2kernel/graph/view/PropertyTableModel.java @@ -1,6 +1,9 @@ package com.c2kernel.graph.view; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; import javax.swing.JOptionPane; import javax.swing.event.TableModelEvent; @@ -23,26 +26,30 @@ public class PropertyTableModel extends AbstractTableModel { HashMap sourceMap = new HashMap(); ArrayList sortedNameList = new ArrayList(); boolean isEditable = false; - + public PropertyTableModel() { super(); } - public int getColumnCount() + @Override + public int getColumnCount() { return mColumnNames.length; } - public String getColumnName(int col) + @Override + public String getColumnName(int col) { return mColumnNames[col]; } - public int getRowCount() + @Override + public int getRowCount() { synchronized (sourceMap) { return sourceMap.size(); } } - public Object getValueAt(int rowIndex, int colIndex) + @Override + public Object getValueAt(int rowIndex, int colIndex) { synchronized (sourceMap) { String rowName = sortedNameList.get(rowIndex); @@ -52,18 +59,19 @@ public class PropertyTableModel extends AbstractTableModel { return sourceMap.get(rowName); } } - - public void setValueAt(Object value, int rowIndex, int colIndex) + + @Override + public void setValueAt(Object value, int rowIndex, int colIndex) { synchronized (sourceMap) { if (colIndex == 0) return; String rowName = sortedNameList.get(rowIndex); - Class oldElement = sourceMap.get(rowName).getClass(); + Class oldElement = sourceMap.get(rowName).getClass(); if (oldElement == Float.class && value.getClass() == String.class) try { value = Float.valueOf((String)value); } catch (Exception ex) { } - if (value.getClass() != oldElement) + if (value.getClass() != oldElement) JOptionPane.showMessageDialog(null, "This property should contain a "+oldElement.getName()+" not a "+value.getClass().getName(), "Incorrect datatype", JOptionPane.ERROR_MESSAGE); else { sourceMap.put(rowName, value); @@ -71,24 +79,26 @@ public class PropertyTableModel extends AbstractTableModel { } } } - + public void setMap(HashMap props) { synchronized (sourceMap) { sourceMap = props; sortedNameList = new ArrayList(props.size()); - for (Iterator keys = props.keySet().iterator(); keys.hasNext();) - sortedNameList.add(keys.next()); - + for (String string : props.keySet()) + sortedNameList.add(string); + Collections.sort(sortedNameList, new Comparator() { - public int compare(String o1, String o2) { + @Override + public int compare(String o1, String o2) { return (o1.compareToIgnoreCase(o2)); } }); } fireTableChanged(new TableModelEvent(this)); } - - public boolean isCellEditable(int row, int col) + + @Override + public boolean isCellEditable(int row, int col) { return col==1 && isEditable; } @@ -112,7 +122,7 @@ public class PropertyTableModel extends AbstractTableModel { */ public void addProperty(String text, Object object) { sourceMap.put(text,object); - setMap(sourceMap); + setMap(sourceMap); } /** -- cgit v1.2.3