001: package vicazh.hyperpool.stream;
002:
003: import java.util.*;
004: import javax.swing.table.*;
005: import vicazh.hyperpool.*;
006:
007: /**
008: * The priorities table model
009: *
010: * @author Victor Zhigunov
011: * @version 0.4.0
012: */
013: public class IPrioritiesModel extends AbstractTableModel {
014: private Object name;
015:
016: private Object client;
017:
018: private Object server;
019:
020: private IInt[] priorities;
021:
022: /**
023: * @param name
024: * column name for line name
025: * @param client
026: * column name for client priority name
027: * @param server
028: * column name for server priority name
029: * @param priorities
030: * priorities array
031: */
032: public IPrioritiesModel(Object name, Object client, Object server,
033: IInt[] priorities) {
034: this .name = name;
035: this .client = client;
036: this .server = server;
037: this .priorities = priorities;
038: }
039:
040: private IListSelector selector;
041:
042: public void setSelector(IListSelector selector) {
043: this .selector = selector;
044: }
045:
046: public void setValueAt(Object aValue, int row, int column) {
047: List<List<Object>> list = selector.getList();
048: Priority p = (Priority) list.get(row);
049: switch (column) {
050: case 1:
051: p.setClient(((IInt) aValue).value);
052: break;
053: case 2:
054: p.setServer(((IInt) aValue).value);
055: break;
056: }
057: selector.setList(list);
058: }
059:
060: public Object getValueAt(int row, int column) {
061: Priority p = (Priority) selector.getList().get(row);
062: switch (column) {
063: case 0:
064: return ((LineMBean) selector.getGroup().getObjects().get(
065: row)).getName();
066: case 1:
067: return priorities[Arrays.binarySearch(priorities,
068: new Integer(p.getClient()))];
069: case 2:
070: return priorities[Arrays.binarySearch(priorities,
071: new Integer(p.getServer()))];
072: }
073: return null;
074: }
075:
076: public int getRowCount() {
077: return selector == null ? 0 : selector.getGroup().getObjects()
078: .size();
079: }
080:
081: public int getColumnCount() {
082: return 3;
083: }
084:
085: public String getColumnName(int columnIndex) {
086: switch (columnIndex) {
087: case 0:
088: return name.toString();
089: case 1:
090: return client.toString();
091: case 2:
092: return server.toString();
093: }
094: return null;
095: }
096:
097: public boolean isCellEditable(int row, int column) {
098: return column > 0;
099: }
100:
101: public void insert(int index) {
102: fireTableRowsInserted(index, index);
103: }
104:
105: public void remove(int index) {
106: fireTableRowsDeleted(index, index);
107: }
108: }
|