@Test public void testGetColumnIndexAtX() { final TableColumn nameColumn = createColumn("name"); final TableColumn ageColumn = createColumn("age"); EventList<TableColumn> columns = GlazedLists.eventListOf(nameColumn, ageColumn); DefaultTableColumnModel defaultModel = watcher.createDefaultModel(columns); EventTableColumnModel eventModel = watcher.createEventModel(columns); assertEquals(0, defaultModel.getColumnIndexAtX(1)); assertEquals(0, eventModel.getColumnIndexAtX(1)); assertEquals(1, defaultModel.getColumnIndexAtX(76)); assertEquals(1, eventModel.getColumnIndexAtX(76)); assertEquals(-1, defaultModel.getColumnIndexAtX(151)); assertEquals(-1, eventModel.getColumnIndexAtX(151)); }
@Override public int getColumnIndexAtX(int x) { if (x < 0) return -1; swingThreadSource.getReadWriteLock().readLock().lock(); try { for (int i = 0, n = swingThreadSource.size(); i < n; i++) { TableColumn column = swingThreadSource.get(i); x = x - column.getWidth(); if (x < 0) return i; } } finally { swingThreadSource.getReadWriteLock().readLock().unlock(); } return -1; }
EventTableColumnModel implements TableColumnModel, PropertyChangeListener, ListSelectionListener, ListEventListener<T> { @Override public int getColumnIndexAtX(int x) { if (x < 0) return -1; swingThreadSource.getReadWriteLock().readLock().lock(); try { for (int i = 0, n = swingThreadSource.size(); i < n; i++) { TableColumn column = swingThreadSource.get(i); x = x - column.getWidth(); if (x < 0) return i; } } finally { swingThreadSource.getReadWriteLock().readLock().unlock(); } return -1; } }
EventTableColumnModel implements TableColumnModel, PropertyChangeListener, ListSelectionListener, ListEventListener<T> { @Override public int getColumnIndexAtX(int x) { if (x < 0) return -1; swingThreadSource.getReadWriteLock().readLock().lock(); try { for (int i = 0, n = swingThreadSource.size(); i < n; i++) { TableColumn column = swingThreadSource.get(i); x = x - column.getWidth(); if (x < 0) return i; } } finally { swingThreadSource.getReadWriteLock().readLock().unlock(); } return -1; } EventTableColumnModel(EventList<T> source); }
EventTableColumnModel implements TableColumnModel, PropertyChangeListener, ListSelectionListener, ListEventListener<T> { @Override public int getColumnIndexAtX(int x) { if (x < 0) return -1; swingThreadSource.getReadWriteLock().readLock().lock(); try { for (int i = 0, n = swingThreadSource.size(); i < n; i++) { TableColumn column = swingThreadSource.get(i); x = x - column.getWidth(); if (x < 0) return i; } } finally { swingThreadSource.getReadWriteLock().readLock().unlock(); } return -1; } EventTableColumnModel(EventList<T> source); @Override void addColumn(TableColumn column); @Override void removeColumn(TableColumn column); @Override void moveColumn(int columnIndex, int newIndex); @Override void setColumnMargin(int newMargin); @Override int getColumnMargin(); @Override int getColumnCount(); @Override Enumeration<TableColumn> getColumns(); @Override int getColumnIndex(Object identifier); @Override TableColumn getColumn(int columnIndex); @Override int getColumnIndexAtX(int x); @Override int getTotalColumnWidth(); @Override void setColumnSelectionAllowed(boolean flag); @Override boolean getColumnSelectionAllowed(); @Override int[] getSelectedColumns(); @Override int getSelectedColumnCount(); @Override void setSelectionModel(ListSelectionModel newModel); @Override ListSelectionModel getSelectionModel(); @Override void addColumnModelListener(TableColumnModelListener listener); @Override void removeColumnModelListener(TableColumnModelListener listener); @Override void propertyChange(PropertyChangeEvent evt); @Override void valueChanged(ListSelectionEvent e); @Override void listChanged(ListEvent<T> listChanges); void dispose(); }
EventTableColumnModel implements TableColumnModel, PropertyChangeListener, ListSelectionListener, ListEventListener<T> { @Override public int getColumnIndexAtX(int x) { if (x < 0) return -1; swingThreadSource.getReadWriteLock().readLock().lock(); try { for (int i = 0, n = swingThreadSource.size(); i < n; i++) { TableColumn column = swingThreadSource.get(i); x = x - column.getWidth(); if (x < 0) return i; } } finally { swingThreadSource.getReadWriteLock().readLock().unlock(); } return -1; } EventTableColumnModel(EventList<T> source); @Override void addColumn(TableColumn column); @Override void removeColumn(TableColumn column); @Override void moveColumn(int columnIndex, int newIndex); @Override void setColumnMargin(int newMargin); @Override int getColumnMargin(); @Override int getColumnCount(); @Override Enumeration<TableColumn> getColumns(); @Override int getColumnIndex(Object identifier); @Override TableColumn getColumn(int columnIndex); @Override int getColumnIndexAtX(int x); @Override int getTotalColumnWidth(); @Override void setColumnSelectionAllowed(boolean flag); @Override boolean getColumnSelectionAllowed(); @Override int[] getSelectedColumns(); @Override int getSelectedColumnCount(); @Override void setSelectionModel(ListSelectionModel newModel); @Override ListSelectionModel getSelectionModel(); @Override void addColumnModelListener(TableColumnModelListener listener); @Override void removeColumnModelListener(TableColumnModelListener listener); @Override void propertyChange(PropertyChangeEvent evt); @Override void valueChanged(ListSelectionEvent e); @Override void listChanged(ListEvent<T> listChanges); void dispose();  }