1 package prefuse.data; 2 3 import java.util.ArrayList ; 4 import java.util.Date ; 5 import java.util.HashMap ; 6 import java.util.Iterator ; 7 8 import javax.swing.event.TableModelEvent ; 9 10 import prefuse.data.column.Column; 11 import prefuse.data.column.ColumnFactory; 12 import prefuse.data.column.ColumnMetadata; 13 import prefuse.data.event.ColumnListener; 14 import prefuse.data.event.EventConstants; 15 import prefuse.data.event.TableListener; 16 import prefuse.data.expression.Expression; 17 import prefuse.data.expression.Predicate; 18 import prefuse.data.expression.parser.ExpressionParser; 19 import prefuse.data.tuple.AbstractTupleSet; 20 import prefuse.data.tuple.TableTuple; 21 import prefuse.data.tuple.TupleManager; 22 import prefuse.data.util.FilterIteratorFactory; 23 import prefuse.data.util.Index; 24 import prefuse.data.util.RowManager; 25 import prefuse.data.util.Sort; 26 import prefuse.data.util.TableIterator; 27 import prefuse.data.util.TreeIndex; 28 import prefuse.util.TypeLib; 29 import prefuse.util.collections.CopyOnWriteArrayList; 30 import prefuse.util.collections.IncompatibleComparatorException; 31 import prefuse.util.collections.IntIterator; 32 33 34 88 public class Table extends AbstractTupleSet implements ColumnListener { 89 90 91 protected CopyOnWriteArrayList m_listeners; 92 93 94 protected ArrayList m_columns; 95 96 protected ArrayList m_names; 97 98 100 protected HashMap m_entries; 101 102 103 protected RowManager m_rows; 104 105 106 protected TupleManager m_tuples; 107 108 109 protected int m_modCount = 0; 110 111 113 protected int m_lastCol = -1; 114 115 116 protected Schema m_schema; 117 118 121 125 public Table() { 126 this(0, 0); 127 } 128 129 135 public Table(int nrows, int ncols) { 136 this(nrows, ncols, TableTuple.class); 137 } 138 139 145 protected Table(int nrows, int ncols, Class tupleType) { 146 m_listeners = new CopyOnWriteArrayList(); 147 m_columns = new ArrayList (ncols); 148 m_names = new ArrayList (ncols); 149 m_rows = new RowManager(this); 150 m_entries = new HashMap (ncols+5); 151 m_tuples = new TupleManager(this, null, tupleType); 152 153 if ( nrows > 0 ) 154 addRows(nrows); 155 } 156 157 160 164 public int getColumnCount() { 165 return m_columns.size(); 166 } 167 168 173 public Class getColumnType(int col) { 174 return getColumn(col).getColumnType(); 175 } 176 177 182 public Class getColumnType(String field) { 183 Column c = getColumn(field); 184 return (c==null ? null : c.getColumnType()); 185 } 186 187 191 public int getRowCount() { 192 return m_rows.getRowCount(); 193 } 194 195 199 public int getMinimumRow() { 200 return m_rows.getMinimumRow(); 201 } 202 203 207 public int getMaximumRow() { 208 return m_rows.getMaximumRow(); 209 } 210 211 217 public boolean isCellEditable(int row, int col) { 218 if ( !m_rows.isValidRow(row) ) { 219 return false; 220 } else { 221 return getColumn(col).isCellEditable(row); 222 } 223 } 224 225 231 public int getModificationCount() { 232 return m_modCount; 233 } 234 235 241 public void setTupleManager(TupleManager tm) { 242 m_tuples.invalidateAll(); 243 m_tuples = tm; 244 } 245 246 260 public Schema getSchema() { 261 if ( m_schema == null ) { 262 Schema s = new Schema(); 263 for ( int i=0; i<getColumnCount(); ++i ) { 264 s.addColumn(getColumnName(i), getColumnType(i), 265 getColumn(i).getDefaultValue()); 266 } 267 s.lockSchema(); 268 m_schema = s; 269 } 270 return m_schema; 271 } 272 273 277 protected void invalidateSchema() { 278 m_schema = null; 279 } 280 281 284 298 public int getColumnRow(int row, int col) { 299 return m_rows.getColumnRow(row, col); 300 } 301 302 317 public int getTableRow(int colrow, int col) { 318 return m_rows.getTableRow(colrow, col); 319 } 320 321 326 public int addRow() { 327 int r = m_rows.addRow(); 328 updateRowCount(); 329 330 fireTableEvent(r, r, TableModelEvent.ALL_COLUMNS, 331 TableModelEvent.INSERT); 332 return r; 333 } 334 335 341 public void addRows(int nrows) { 342 for ( int i=0; i<nrows; ++i ) { 343 addRow(); 344 } 345 } 346 347 350 protected void updateRowCount() { 351 int maxrow = m_rows.getMaximumRow() + 1; 352 353 Iterator cols = getColumns(); 355 while ( cols.hasNext() ) { 356 Column c = (Column)cols.next(); 357 c.setMaximumRow(maxrow); 358 } 359 } 360 361 367 public boolean removeRow(int row) { 368 if ( m_rows.isValidRow(row) ) { 369 fireTableEvent(row, row, TableModelEvent.ALL_COLUMNS, 374 TableModelEvent.DELETE); 375 m_tuples.invalidate(row); 377 m_rows.releaseRow(row); 381 for ( Iterator cols = getColumns(); cols.hasNext(); ) { 383 Column c = (Column)cols.next(); 384 c.revertToDefault(row); 385 } 386 return true; 387 } 388 return false; 389 } 390 391 395 public void clear() { 396 IntIterator rows = rows(true); 397 while ( rows.hasNext() ) { 398 removeRow(rows.nextInt()); 399 } 400 } 401 402 407 public boolean isValidRow(int row) { 408 return m_rows.isValidRow(row); 409 } 410 411 414 418 protected boolean hasColumn(String name) { 419 return getColumnNumber(name) != -1; 420 } 421 422 427 public String getColumnName(int col) { 428 return (String )m_names.get(col); 429 } 430 431 436 public int getColumnNumber(String field) { 437 ColumnEntry e = (ColumnEntry)m_entries.get(field); 438 return ( e==null ? -1 : e.colnum ); 439 } 440 441 446 public int getColumnNumber(Column col) { 447 return m_columns.indexOf(col); 448 } 449 450 455 public Column getColumn(int col) { 456 m_lastCol = col; 457 return (Column)m_columns.get(col); 458 } 459 460 465 public Column getColumn(String field) { 466 ColumnEntry e = (ColumnEntry)m_entries.get(field); 467 return ( e != null ? e.column : null ); 468 } 469 470 476 public void addColumn(String name, Class type) { 477 addColumn(name, type, null); 478 } 479 480 487 public void addColumn(String name, Class type, Object defaultValue) { 488 Column col = ColumnFactory.getColumn(type, 489 m_rows.getMaximumRow()+1, defaultValue); 490 addColumn(name, col); 491 } 492 493 504 public void addColumn(String name, String expr) { 505 Expression ex = ExpressionParser.parse(expr); 506 Throwable t = ExpressionParser.getError(); 507 if ( t != null ) { 508 throw new RuntimeException (t); 509 } else { 510 addColumn(name, ex); 511 } 512 } 513 514 521 public void addColumn(String name, Expression expr) { 522 addColumn(name, ColumnFactory.getColumn(this, expr)); 523 } 524 525 532 public void addConstantColumn(String name, Class type, Object dflt) { 533 addColumn(name, ColumnFactory.getConstantColumn(type, dflt)); 534 } 535 536 541 protected void addColumn(String name, Column col) { 542 int idx = getColumnNumber(name); 543 if ( idx >= 0 && idx < m_columns.size() ) { 544 throw new IllegalArgumentException ( 545 "Table already has column with name \""+name+"\""); 546 } 547 548 m_columns.add(col); 550 m_names.add(name); 551 m_lastCol = m_columns.size()-1; 552 ColumnEntry entry = new ColumnEntry(m_lastCol, col, 553 new ColumnMetadata(this, name)); 554 555 ColumnEntry oldEntry = (ColumnEntry)m_entries.put(name, entry); 557 if ( oldEntry != null ) oldEntry.dispose(); 558 559 invalidateSchema(); 560 561 col.addColumnListener(this); 563 564 fireTableEvent(m_rows.getMinimumRow(), m_rows.getMaximumRow(), 566 m_lastCol, TableModelEvent.INSERT); 567 } 568 569 574 protected Column removeColumn(int idx) { 575 if ( idx < 0 || idx >= m_columns.size() ) { 577 throw new IllegalArgumentException ("Column index is not legal."); 578 } 579 580 String name = (String )m_names.get(idx); 581 ((ColumnEntry)m_entries.get(name)).dispose(); 582 Column col = (Column)m_columns.remove(idx); 583 m_entries.remove(name); 584 m_names.remove(idx); 585 renumberColumns(); 586 587 m_lastCol = -1; 588 invalidateSchema(); 589 590 col.removeColumnListener(this); 592 593 fireTableEvent(m_rows.getMinimumRow(), m_rows.getMaximumRow(), 595 idx, TableModelEvent.DELETE); 596 597 return col; 598 } 599 600 605 public Column removeColumn(String field) { 606 int idx = m_names.indexOf(field); 607 if ( idx < 0 ) { 608 throw new IllegalArgumentException ("No such column."); 609 } 610 return removeColumn(idx); 611 } 612 613 617 public void removeColumn(Column c) { 618 int idx = m_columns.indexOf(c); 619 if ( idx < 0 ) { 620 throw new IllegalArgumentException ("No such column."); 621 } 622 removeColumn(idx); 623 } 624 625 628 protected void renumberColumns() { 629 Iterator iter = m_names.iterator(); 630 for ( int idx=0; iter.hasNext(); ++idx ) { 631 String name = (String )iter.next(); 632 ColumnEntry e = (ColumnEntry)m_entries.get(name); 633 e.colnum = idx; 634 } 635 } 636 637 641 protected Iterator getColumns() { 642 return m_columns.iterator(); 643 } 644 645 649 protected Iterator getColumnNames() { 650 return m_names.iterator(); 651 } 652 653 656 661 public ColumnMetadata getMetadata(String field) { 662 ColumnEntry e = (ColumnEntry)m_entries.get(field); 663 if ( e == null ) { 664 throw new IllegalArgumentException ("Unknown column name: "+field); 665 } 666 return e.metadata; 667 } 668 669 672 681 public Index index(String field) { 682 ColumnEntry e = (ColumnEntry)m_entries.get(field); 683 if ( e == null ) { 684 throw new IllegalArgumentException ("Unknown column name: "+field); 685 } else if ( e.index != null ) { 686 return e.index; } 688 689 Column col = e.column; 690 try { 691 e.index = new TreeIndex(this, m_rows, col, null); 692 } catch ( IncompatibleComparatorException ice ) { } 693 694 return e.index; 695 } 696 697 703 public Index getIndex(String field) { 704 ColumnEntry e = (ColumnEntry)m_entries.get(field); 705 if ( e == null ) { 706 throw new IllegalArgumentException ("Unknown column name: "+field); 707 } 708 return e.index; 709 } 710 711 719 protected Index getIndex(String field, Class expType, boolean create) { 720 if ( !expType.equals(getColumnType(field)) ) { 721 throw new IllegalArgumentException ("Column type does not match."); 723 } 724 if ( getIndex(field)==null && create) { 725 index(field); 726 } 727 return getIndex(field); 728 } 729 730 736 public boolean removeIndex(String field) { 737 ColumnEntry e = (ColumnEntry)m_entries.get(field); 738 if ( e == null ) { 739 throw new IllegalArgumentException ("Unknown column name: "+field); 740 } 741 if ( e.index == null ) { 742 return false; 743 } else { 744 e.index.dispose(); 745 e.index = null; 746 return true; 747 } 748 } 749 750 753 759 public Tuple getTuple(int row) { 760 return m_tuples.getTuple(row); 761 } 762 763 776 public Tuple addTuple(Tuple t) { 777 if ( t.getTable() == this ) { 778 return null; 779 } else { 780 Schema s = t.getSchema(); 781 if ( getSchema().isAssignableFrom(s) ) { 782 int r = addRow(); 783 for ( int i=0; i<s.getColumnCount(); ++i ) { 784 String field = s.getColumnName(i); 785 this.set(r, field, t.get(i)); 786 } 787 return getTuple(r); 788 } else { 789 return null; 790 } 791 } 792 } 793 794 802 public Tuple setTuple(Tuple t) { 803 clear(); 804 return addTuple(t); 805 } 806 807 815 public boolean removeTuple(Tuple t) { 816 if ( containsTuple(t) ) { 817 removeRow(t.getRow()); 818 return true; 819 } else { 820 return false; 821 } 822 } 823 824 831 public boolean containsTuple(Tuple t) { 832 return (t.getTable()==this && isValidRow(t.getRow())); 833 } 834 835 841 public int getTupleCount() { 842 return getRowCount(); 843 } 844 845 849 public boolean isAddColumnSupported() { 850 return true; 851 } 852 853 856 867 public boolean canGet(String field, Class type) { 868 Column c = getColumn(field); 869 return ( c==null ? false : c.canGet(type) ); 870 } 871 872 884 public boolean canSet(String field, Class type) { 885 Column c = getColumn(field); 886 return ( c==null ? false : c.canSet(type) ); 887 } 888 889 898 public Object get(int row, String field) { 899 int col = getColumnNumber(field); 900 row = getColumnRow(row, col); 901 return getColumn(col).get(row); 902 } 903 904 915 public void set(int row, String field, Object val) { 916 int col = getColumnNumber(field); 917 row = getColumnRow(row, col); 918 getColumn(col).set(val, row); 919 920 } 923 924 933 public Object get(int row, int col) { 934 row = getColumnRow(row, col); 935 return getColumn(col).get(row); 936 } 937 938 949 public void set(int row, int col, Object val) { 950 row = getColumnRow(row, col); 951 getColumn(col).set(val, row); 952 953 } 956 957 963 public Object getDefault(String field) { 964 int col = getColumnNumber(field); 965 return getColumn(col).getDefaultValue(); 966 } 967 968 974 public void revertToDefault(int row, String field) { 975 int col = getColumnNumber(field); 976 row = getColumnRow(row, col); 977 getColumn(col).revertToDefault(row); 978 } 979 980 983 991 public final boolean canGetInt(String field) { 992 Column col = getColumn(field); 993 return ( col==null ? false : col.canGetInt() ); 994 } 995 996 1003 public final boolean canSetInt(String field) { 1004 Column col = getColumn(field); 1005 return ( col==null ? false : col.canSetInt() ); 1006 } 1007 1008 1015 public final int getInt(int row, String field) { 1016 int col = getColumnNumber(field); 1017 row = getColumnRow(row, col); 1018 return getColumn(col).getInt(row); 1019 } 1020 1021 1029 public final void setInt(int row, String field, int val) { 1030 int col = getColumnNumber(field); 1031 row = getColumnRow(row, col); 1032 getColumn(col).setInt(val, row); 1033 } 1034 1035 1042 public final int getInt(int row, int col) { 1043 row = getColumnRow(row, col); 1044 return getColumn(col).getInt(row); 1045 } 1046 1047 1055 public final void setInt(int row, int col, int val) { 1056 row = getColumnRow(row, col); 1057 getColumn(col).setInt(val, row); 1058 } 1059 1060 1062 1070 public final boolean canGetLong(String field) { 1071 Column col = getColumn(field); 1072 return ( col==null ? false : col.canGetLong() ); 1073 } 1074 1075 1082 public final boolean canSetLong(String field) { 1083 Column col = getColumn(field); 1084 return ( col==null ? false : col.canSetLong() ); 1085 } 1086 1087 1094 public final long getLong(int row, String field) { 1095 int col = getColumnNumber(field); 1096 row = getColumnRow(row, col); 1097 return getColumn(col).getLong(row); 1098 } 1099 1100 1108 public final void setLong(int row, String field, long val) { 1109 int col = getColumnNumber(field); 1110 row = getColumnRow(row, col); 1111 getColumn(col).setLong(val, row); 1112 } 1113 1114 1121 public final long getLong(int row, int col) { 1122 row = getColumnRow(row, col); 1123 return getColumn(col).getLong(row); 1124 } 1125 1126 1134 public final void setLong(int row, int col, long val) { 1135 row = getColumnRow(row, col); 1136 getColumn(col).setLong(val, row); 1137 } 1138 1139 1141 1149 public final boolean canGetFloat(String field) { 1150 Column col = getColumn(field); 1151 return ( col==null ? false : col.canGetFloat() ); 1152 } 1153 1154 1161 public final boolean canSetFloat(String field) { 1162 Column col = getColumn(field); 1163 return ( col==null ? false : col.canSetFloat() ); 1164 } 1165 1166 1173 public final float getFloat(int row, String field) { 1174 int col = getColumnNumber(field); 1175 row = getColumnRow(row, col); 1176 return getColumn(col).getFloat(row); 1177 } 1178 1179 1187 public final void setFloat(int row, String field, float val) { 1188 int col = getColumnNumber(field); 1189 row = getColumnRow(row, col); 1190 getColumn(col).setFloat(val, row); 1191 } 1192 1193 1200 public final float getFloat(int row, int col) { 1201 row = getColumnRow(row, col); 1202 return getColumn(col).getFloat(row); 1203 } 1204 1205 1213 public final void setFloat(int row, int col, float val) { 1214 row = getColumnRow(row, col); 1215 getColumn(col).setFloat(val, row); 1216 } 1217 1218 1220 1228 public final boolean canGetDouble(String field) { 1229 Column col = getColumn(field); 1230 return ( col==null ? false : col.canGetDouble() ); 1231 } 1232 1233 1240 public final boolean canSetDouble(String field) { 1241 Column col = getColumn(field); 1242 return ( col==null ? false : col.canSetDouble() ); 1243 } 1244 1245 1252 public final double getDouble(int row, String field) { 1253 int col = getColumnNumber(field); 1254 row = getColumnRow(row, col); 1255 return getColumn(col).getDouble(row); 1256 } 1257 1258 1266 public final void setDouble(int row, String field, double val) { 1267 int col = getColumnNumber(field); 1268 row = getColumnRow(row, col); 1269 getColumn(col).setDouble(val, row); 1270 } 1271 1272 1279 public final double getDouble(int row, int col) { 1280 row = getColumnRow(row, col); 1281 return getColumn(col).getDouble(row); 1282 } 1283 1284 1292 public final void setDouble(int row, int col, double val) { 1293 row = getColumnRow(row, col); 1294 getColumn(col).setDouble(val, row); 1295 } 1296 1297 1299 1307 public final boolean canGetBoolean(String field) { 1308 Column col = getColumn(field); 1309 return ( col==null ? false : col.canGetBoolean() ); 1310 } 1311 1312 1319 public final boolean canSetBoolean(String field) { 1320 Column col = getColumn(field); 1321 return ( col==null ? false : col.canSetBoolean() ); 1322 } 1323 1324 1331 public final boolean getBoolean(int row, String field) { 1332 int col = getColumnNumber(field); 1333 row = getColumnRow(row, col); 1334 return getColumn(col).getBoolean(row); 1335 } 1336 1337 1345 public final void setBoolean(int row, String field, boolean val) { 1346 int col = getColumnNumber(field); 1347 row = getColumnRow(row, col); 1348 getColumn(col).setBoolean(val, row); 1349 } 1350 1351 1358 public final boolean getBoolean(int row, int col) { 1359 row = getColumnRow(row, col); 1360 return getColumn(col).getBoolean(row); 1361 } 1362 1363 1371 public final void setBoolean(int row, int col, boolean val) { 1372 row = getColumnRow(row, col); 1373 getColumn(col).setBoolean(val, row); 1374 } 1375 1376 1378 1386 public final boolean canGetString(String field) { 1387 Column col = getColumn(field); 1388 return ( col==null ? false : col.canGetString() ); 1389 } 1390 1391 1398 public final boolean canSetString(String field) { 1399 Column col = getColumn(field); 1400 return ( col==null ? false : col.canSetString() ); 1401 } 1402 1403 1410 public final String getString(int row, String field) { 1411 int col = getColumnNumber(field); 1412 row = getColumnRow(row, col); 1413 return getColumn(col).getString(row); 1414 } 1415 1416 1424 public final void setString(int row, String field, String val) { 1425 int col = getColumnNumber(field); 1426 row = getColumnRow(row, col); 1427 getColumn(col).setString(val, row); 1428 } 1429 1430 1437 public final String getString(int row, int col) { 1438 row = getColumnRow(row, col); 1439 return getColumn(col).getString(row); 1440 } 1441 1442 1450 public final void setString(int row, int col, String val) { 1451 row = getColumnRow(row, col); 1452 getColumn(col).setString(val, row); 1453 } 1454 1455 1457 1465 public final boolean canGetDate(String field) { 1466 Column col = getColumn(field); 1467 return ( col==null ? false : col.canGetDate() ); 1468 } 1469 1470 1477 public final boolean canSetDate(String field) { 1478 Column col = getColumn(field); 1479 return ( col==null ? false : col.canSetDate() ); 1480 } 1481 1482 1489 public final Date getDate(int row, String field) { 1490 int col = getColumnNumber(field); 1491 row = getColumnRow(row, col); 1492 return getColumn(col).getDate(row); 1493 } 1494 1495 1503 public final void setDate(int row, String field, Date val) { 1504 int col = getColumnNumber(field); 1505 row = getColumnRow(row, col); 1506 getColumn(col).setDate(val, row); 1507 } 1508 1509 1516 public final Date getDate(int row, int col) { 1517 row = getColumnRow(row, col); 1518 return getColumn(col).getDate(row); 1519 } 1520 1521 1529 public final void setDate(int row, int col, Date val) { 1530 row = getColumnRow(row, col); 1531 getColumn(col).setDate(val, row); 1532 } 1533 1534 1537 1549 public Table select(Predicate filter, Sort sort) { 1550 Table t = getSchema().instantiate(); 1551 Iterator tuples = tuples(filter, sort); 1552 while ( tuples.hasNext() ) { 1553 t.addTuple((Tuple)tuples.next()); 1554 } 1555 return t; 1556 } 1557 1558 1563 public void remove(Predicate filter) { 1564 for ( IntIterator ii = rows(filter); ii.hasNext(); ) 1565 removeRow(ii.nextInt()); 1566 } 1567 1568 1571 1575 public TableIterator iterator() { 1576 return iterator(rows()); 1577 } 1578 1579 1584 public TableIterator iterator(IntIterator rows) { 1585 return new TableIterator(this, rows); 1586 } 1587 1588 1593 public Iterator tuples() { 1594 return m_tuples.iterator(rows()); 1595 } 1596 1597 1601 public Iterator tuplesReversed() { 1602 return m_tuples.iterator(rows(true)); 1603 } 1604 1605 1610 public Iterator tuples(IntIterator rows) { 1611 return m_tuples.iterator(rows); 1612 } 1613 1614 1618 public IntIterator rows() { 1619 return m_rows.rows(); 1620 } 1621 1622 1628 public IntIterator rows(Predicate filter) { 1629 return FilterIteratorFactory.rows(this, filter); 1630 } 1631 1632 1637 public IntIterator rows(boolean reverse) { 1638 return m_rows.rows(reverse); 1639 } 1640 1641 1650 public IntIterator rowsSortedBy(String field, boolean ascend) { 1651 Class type = getColumnType(field); 1652 Index index = getIndex(field, type, true); 1653 int t = ascend ? Index.TYPE_ASCENDING : Index.TYPE_DESCENDING; 1654 return index.allRows(t); 1655 } 1656 1657 1670 public IntIterator rangeSortedBy(String field, int lo, int hi, int indexType) { 1671 Index index = getIndex(field, int.class, true); 1672 return index.rows(lo, hi, indexType); 1673 } 1674 1675 1688 public IntIterator rangeSortedBy(String field, long lo, long hi, int indexType) { 1689 Index index = getIndex(field, long.class, true); 1690 return index.rows(lo, hi, indexType); 1691 } 1692 1693 1706 public IntIterator rangeSortedBy(String field, float lo, float hi, int indexType) { 1707 Index index = getIndex(field, float.class, true); 1708 return index.rows(lo, hi, indexType); 1709 } 1710 1711 1724 public IntIterator rangeSortedBy(String field, double lo, double hi, int indexType) { 1725 Index index = getIndex(field, double.class, true); 1726 return index.rows(lo, hi, indexType); 1727 } 1728 1729 1742 public IntIterator rangeSortedBy(String field, Object lo, Object hi, int indexType) { 1743 Class type = TypeLib.getSharedType(lo, hi); 1744 if ( type == null ) 1746 throw new IllegalArgumentException ("Incompatible arguments"); 1747 Index index = getIndex(field, type, true); 1748 return index.rows(lo, hi, indexType); 1749 } 1750 1751 1754 1756 1759 public void columnChanged(Column src, int idx, boolean prev) { 1760 handleColumnChanged(src, idx, idx); 1761 } 1762 1763 1766 public void columnChanged(Column src, int idx, double prev) { 1767 handleColumnChanged(src, idx, idx); 1768 } 1769 1770 1773 public void columnChanged(Column src, int idx, float prev) { 1774 handleColumnChanged(src, idx, idx); 1775 } 1776 1777 1780 public void columnChanged(Column src, int idx, int prev) { 1781 handleColumnChanged(src, idx, idx); 1782 } 1783 1784 1787 public void columnChanged(Column src, int idx, long prev) { 1788 handleColumnChanged(src, idx, idx); 1789 } 1790 1791 1794 public void columnChanged(Column src, int idx, Object prev) { 1795 handleColumnChanged(src, idx, idx); 1796 } 1797 1798 1801 public void columnChanged(Column src, int type, int start, int end) { 1802 handleColumnChanged(src, start, end); 1803 } 1804 1805 1811 protected void handleColumnChanged(Column c, int start, int end) { 1812 for ( ; !isValidRow(start) && start <= end; ++start ); 1813 if ( start > end ) return; 1815 int idx; 1817 if ( m_lastCol != -1 && c == getColumn(m_lastCol) ) { 1818 idx = m_lastCol; 1820 } else { 1821 idx = getColumnNumber(c); 1823 } 1824 1825 if ( idx >= 0 ) { 1827 fireTableEvent(start, end, idx, TableModelEvent.UPDATE); 1828 } 1829 } 1830 1831 1833 1837 public void addTableListener(TableListener listnr) { 1838 if ( !m_listeners.contains(listnr) ) 1839 m_listeners.add(listnr); 1840 } 1841 1842 1846 public void removeTableListener(TableListener listnr) { 1847 m_listeners.remove(listnr); 1848 } 1849 1850 1862 protected void fireTableEvent(int row0, int row1, int col, int type) { 1863 ++m_modCount; 1865 1866 if ( type != EventConstants.UPDATE && 1867 col == EventConstants.ALL_COLUMNS ) 1868 { 1869 fireTupleEvent(this, row0, row1, type); 1871 } 1872 1873 if ( !m_listeners.isEmpty() ) { 1874 Object [] lstnrs = m_listeners.getArray(); 1876 for ( int i=0; i<lstnrs.length; ++i ) { 1877 ((TableListener)lstnrs[i]).tableChanged( 1878 this, row0, row1, col, type); 1879 } 1880 } 1881 } 1882 1883 1886 1889 public String toString() { 1890 StringBuffer sbuf = new StringBuffer (); 1891 sbuf.append("Table["); 1892 sbuf.append("rows=").append(getRowCount()); 1893 sbuf.append(", cols=").append(getColumnCount()); 1894 sbuf.append(", maxrow=").append(m_rows.getMaximumRow()); 1895 sbuf.append("]"); 1896 return sbuf.toString(); 1897 } 1898 1899 1902 1908 protected static class ColumnEntry { 1909 1910 1911 public int colnum; 1912 1913 public Column column; 1914 1915 public ColumnMetadata metadata; 1916 1917 public Index index; 1918 1919 1925 public ColumnEntry(int col, Column column, ColumnMetadata metadata) { 1926 this.colnum = col; 1927 this.column = column; 1928 this.metadata = metadata; 1929 this.index = null; 1930 } 1931 1932 1936 public void dispose() { 1937 if ( metadata != null ) 1938 metadata.dispose(); 1939 if ( index != null ) 1940 index.dispose(); 1941 } 1942 1943 } 1945} | Popular Tags |