javax.swing.event.TableColumnModelEvent Java Examples

The following examples show how to use javax.swing.event.TableColumnModelEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SorterTableColumnModel.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void moveColumn(int fromIndex, int toIndex) {
    TableColumn from = columnList.get(fromIndex);
    TableColumn to = columnList.get(toIndex);

    columnList.set(fromIndex, to);
    to.setModelIndex(fromIndex);

    columnList.set(toIndex, from);
    from.setModelIndex(toIndex);

    orderUpdate();

    for (TableColumnModelListener w : new ArrayList<>(watchers)) {
        w.columnMoved(new TableColumnModelEvent(this, fromIndex, toIndex));
    }
}
 
Example #2
Source File: PlacemarkManagerTopComponent.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void columnAdded(TableColumnModelEvent e) {
    int minWidth;
    final int index = e.getToIndex();
    switch (index) {
        case 0:
        case 1:
            minWidth = 60;
            break;
        default:
            minWidth = 80;
    }
    TableColumnModel columnModel = (TableColumnModel) e.getSource();
    columnModel.getColumn(index).setPreferredWidth(minWidth);
    columnModel.getColumn(index).setCellRenderer(new RightAlignmentTableCellRenderer());
}
 
Example #3
Source File: LogTableColumnModel.java    From LoggerPlusPlus with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void removeColumn(TableColumn column) {
    int columnIndex = tableColumns.indexOf(column);

    if (columnIndex != -1) {
        // Adjust for the selection
        if (selectionModel != null) {
            selectionModel.removeIndexInterval(columnIndex,columnIndex);
        }

        column.removePropertyChangeListener(this);
        tableColumns.removeElementAt(columnIndex);

        //Update model index for subsequent columns
        for (int index = columnIndex; index < tableColumns.size(); index++) {
            tableColumns.get(index).setModelIndex(index);
        }

        // Post columnAdded event notification.  (JTable and JTableHeader
        // listens so they can adjust size and redraw)
        fireColumnRemoved(new TableColumnModelEvent(this,
                columnIndex, 0));
    }
}
 
Example #4
Source File: LogTableColumnModel.java    From LoggerPlusPlus with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
    public void moveColumn(int viewFrom, int viewTo) {
//		viewToModelMap
        super.moveColumn(viewFrom, viewTo);
        if(viewFrom == viewTo) return;

        int leftIndex = Math.min(viewFrom, viewTo);
        int rightIndex = Math.max(viewFrom, viewTo);

        for (int index = leftIndex; index <= rightIndex; index++) {
            LogTableColumn col = (LogTableColumn) getColumn(index);
            col.setOrder(index);
            col.setModelIndex(index);
        }

        saveLayout();
        this.fireColumnMoved(new TableColumnModelEvent(this, viewFrom, viewTo));
    }
 
Example #5
Source File: TableColumnManager.java    From mars-sim with GNU General Public License v3.0 6 votes vote down vote up
public void columnMoved(TableColumnModelEvent e)
{
	if (e.getFromIndex() == e.getToIndex()) return;

	//  A table column has been moved one position to the left or right
	//  in the view of the table so we need to update the manager to
	//  track the new location

	int index = e.getToIndex();
	TableColumn column = tcm.getColumn( index );
	allColumns.remove( column );

	if (index == 0)
	{
		allColumns.add(0, column);
	}
	else
	{
		index--;
		TableColumn visibleColumn = tcm.getColumn( index );
		int insertionColumn = allColumns.indexOf( visibleColumn );
		allColumns.add(insertionColumn + 1, column);
	}
}
 
Example #6
Source File: DefaultDynamicTableColumnModel.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void removeColumn(TableColumn column)
{
	super.removeColumn(column);
	if (availableColumns.contains(column))
	{
		int index = availableColumns.indexOf(column);
		availableColumns.remove(column);
		fireAvailableColumnRemoved(new TableColumnModelEvent(this, index, -1));
	}
}
 
Example #7
Source File: DefaultDynamicTableColumnModel.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Notifies all listeners that have registered interest for
 * notification on this event type.  The event instance
 * is lazily created using the parameters passed into
 * the fire method.
 * @param  e  the event received
 */
protected void fireAvailableColumnAdded(TableColumnModelEvent e)
{
	// Guaranteed to return a non-null array
	Object[] listeners = listenerList.getListenerList();
	// Process the listeners last to first, notifying
	// those that are interested in this event
	for (int i = listeners.length - 2; i >= 0; i -= 2)
	{
		if (listeners[i] == DynamicTableColumnModelListener.class)
		{
			((DynamicTableColumnModelListener) listeners[i + 1]).availableColumnAdded(e);
		}
	}
}
 
Example #8
Source File: DefaultDynamicTableColumnModel.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Notifies all listeners that have registered interest for
 * notification on this event type.  The event instance
 * is lazily created using the parameters passed into
 * the fire method.
 * @param  e  the event received
 */
protected void fireAvailableColumnRemoved(TableColumnModelEvent e)
{
	// Guaranteed to return a non-null array
	Object[] listeners = listenerList.getListenerList();
	// Process the listeners last to first, notifying
	// those that are interested in this event
	for (int i = listeners.length - 2; i >= 0; i -= 2)
	{
		if (listeners[i] == DynamicTableColumnModelListener.class)
		{
			((DynamicTableColumnModelListener) listeners[i + 1]).availableColumnRemove(e);
		}
	}
}
 
Example #9
Source File: TableColumnsGeometryPersisterImpl.java    From pgptool with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void columnMoved(TableColumnModelEvent e) {
	if (table == null) {
		return;
	}

	onColsConfigChanged();
}
 
Example #10
Source File: LogTableColumnModel.java    From LoggerPlusPlus with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void addColumn(TableColumn column) {
    //We should add the column at the correct position based on its order value.
    if (column == null) {
        throw new IllegalArgumentException("Object is null");
    } else {
        //Find the first element with a greater order than the one to be added and add it before it.
        int newPosition = -1;
        for (int i = 0; i < this.tableColumns.size(); i++) {
            int currentOrderAtIndex = ((LogTableColumn) this.tableColumns.get(i)).getOrder();
            if (currentOrderAtIndex > ((LogTableColumn) column).getOrder()){
                newPosition = i;
                break;
            }
        }
        if(newPosition == -1){ //No elements with a greater order value. Add it to the end.
            newPosition = this.tableColumns.size();
        }

        this.tableColumns.add(newPosition, column);
        //Adjust model index for new and subsequent columns
        for (int i = newPosition; i < tableColumns.size(); i++) {
            tableColumns.get(i).setModelIndex(i);
        }

        column.addPropertyChangeListener(this);
        this.fireColumnAdded(new TableColumnModelEvent(this, 0, this.getColumnCount() - 1));
    }
}
 
Example #11
Source File: DefaultDynamicTableColumnModel.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void removeColumn(TableColumn column)
{
	super.removeColumn(column);
	if (availableColumns.contains(column))
	{
		int index = availableColumns.indexOf(column);
		availableColumns.remove(column);
		fireAvailableColumnRemoved(new TableColumnModelEvent(this, index, -1));
	}
}
 
Example #12
Source File: DefaultDynamicTableColumnModel.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void addColumn(TableColumn column)
{
	if (getColumnCount() < offset)
	{
		super.addColumn(column);
	}
	else
	{
		int index = availableColumns.size();
		availableColumns.add(column);
		fireAvailableColumnAdded(new TableColumnModelEvent(this, -1, index));
	}
}
 
Example #13
Source File: ETableColumnModel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Copy of addColumn(TableColumn) with an index specifying where to add the new column */
   private void addColumn(TableColumn aColumn, int index) {
if (aColumn == null) {
    throw new IllegalArgumentException("Object is null");
}

tableColumns.insertElementAt(aColumn, index);
aColumn.addPropertyChangeListener(this);
//invalidateWidthCache();
       totalColumnWidth = -1;

// Post columnAdded event notification
fireColumnAdded(new TableColumnModelEvent(this, 0, index));
   }
 
Example #14
Source File: JDynamicTable.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void availableColumnRemove(TableColumnModelEvent event)
{

	menu.getItems().remove(event.getFromIndex());
	if (menu.getItems().isEmpty())
	{
		cornerButton.setVisible(false);
	}
}
 
Example #15
Source File: DefaultDynamicTableColumnModel.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void addColumn(TableColumn column)
{
	if (getColumnCount() < offset)
	{
		super.addColumn(column);
	}
	else
	{
		int index = availableColumns.size();
		availableColumns.add(column);
		fireAvailableColumnAdded(new TableColumnModelEvent(this, -1, index));
	}
}
 
Example #16
Source File: IssueTable.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void columnMoved(TableColumnModelEvent e) {
    int from = e.getFromIndex();
    int to = e.getToIndex();
    if(from == to) {
        return;
    }
    table.getTableHeader().getColumnModel().getColumn(from).setModelIndex(from);
    table.getTableHeader().getColumnModel().getColumn(to).setModelIndex(to);
    tableModel.moveColumn(from, to);
}
 
Example #17
Source File: JTableOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Maps {@code JTable.columnAdded(TableColumnModelEvent)} through queue
 */
public void columnAdded(final TableColumnModelEvent tableColumnModelEvent) {
    runMapping(new MapVoidAction("columnAdded") {
        @Override
        public void map() {
            ((JTable) getSource()).columnAdded(tableColumnModelEvent);
        }
    });
}
 
Example #18
Source File: JTableHeaderOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Maps {@code JTableHeader.columnRemoved(TableColumnModelEvent)}
 * through queue
 */
public void columnRemoved(final TableColumnModelEvent tableColumnModelEvent) {
    runMapping(new MapVoidAction("columnRemoved") {
        @Override
        public void map() {
            ((JTableHeader) getSource()).columnRemoved(tableColumnModelEvent);
        }
    });
}
 
Example #19
Source File: CsvTableEditorChangeListenerTest.java    From intellij-csv-validator with Apache License 2.0 5 votes vote down vote up
public void testFunctionsNotFaulty() {
    TableColumnModelEvent event = new TableColumnModelEvent(fileEditor.getTable().getColumnModel(), 0, 1);
    fileEditor.tableEditorListener.columnAdded(event);
    fileEditor.tableEditorListener.columnRemoved(event);
    fileEditor.tableEditorListener.columnMoved(event);

    fileEditor.tableEditorListener.columnMarginChanged(new ChangeEvent(fileEditor.getTable().getColumnModel()));
    fileEditor.tableEditorListener.columnSelectionChanged(new ListSelectionEvent(fileEditor.getTable().getColumnModel(), 0, 1, true));
    fileEditor.tableEditorListener.tableChanged(new TableModelEvent(fileEditor.getTableModel()));
    assertTrue(true);
}
 
Example #20
Source File: JTableHeaderOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Maps {@code JTableHeader.columnMoved(TableColumnModelEvent)} through queue
 */
public void columnMoved(final TableColumnModelEvent tableColumnModelEvent) {
    runMapping(new MapVoidAction("columnMoved") {
        @Override
        public void map() {
            ((JTableHeader) getSource()).columnMoved(tableColumnModelEvent);
        }
    });
}
 
Example #21
Source File: JDynamicTable.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void availableColumnAdded(TableColumnModelEvent event)
{
	int index = event.getToIndex();
	TableColumn column = dynamicColumnModel.getAvailableColumns().get(index);
	menu.getItems().add(index, createMenuItem(column));
	cornerButton.setVisible(true);
}
 
Example #22
Source File: BugTreeModel.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void columnMoved(final TableColumnModelEvent evt) {
    if (evt.getFromIndex() == evt.getToIndex()) {
        return;
    }
    sortOrderChanged = true;
    // rebuild();
}
 
Example #23
Source File: DefaultDynamicTableColumnModel.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Notifies all listeners that have registered interest for
 * notification on this event type.  The event instance
 * is lazily created using the parameters passed into
 * the fire method.
 * @param  e  the event received
 */
protected void fireAvailableColumnRemoved(TableColumnModelEvent e)
{
	// Guaranteed to return a non-null array
	Object[] listeners = listenerList.getListenerList();
	// Process the listeners last to first, notifying
	// those that are interested in this event
	for (int i = listeners.length - 2; i >= 0; i -= 2)
	{
		if (listeners[i] == DynamicTableColumnModelListener.class)
		{
			((DynamicTableColumnModelListener) listeners[i + 1]).availableColumnRemove(e);
		}
	}
}
 
Example #24
Source File: DefaultDynamicTableColumnModel.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Notifies all listeners that have registered interest for
 * notification on this event type.  The event instance
 * is lazily created using the parameters passed into
 * the fire method.
 * @param  e  the event received
 */
protected void fireAvailableColumnAdded(TableColumnModelEvent e)
{
	// Guaranteed to return a non-null array
	Object[] listeners = listenerList.getListenerList();
	// Process the listeners last to first, notifying
	// those that are interested in this event
	for (int i = listeners.length - 2; i >= 0; i -= 2)
	{
		if (listeners[i] == DynamicTableColumnModelListener.class)
		{
			((DynamicTableColumnModelListener) listeners[i + 1]).availableColumnAdded(e);
		}
	}
}
 
Example #25
Source File: JDynamicTable.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void availableColumnRemove(TableColumnModelEvent event)
{

	menu.getItems().remove(event.getFromIndex());
	if (menu.getItems().isEmpty())
	{
		cornerButton.setVisible(false);
	}
}
 
Example #26
Source File: AttributeEditor.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void columnAdded(TableColumnModelEvent e) {
	super.columnAdded(e);
	// bigger default size
	TableColumn column = getColumnModel().getColumn(getColumnModel().getColumnCount() - 1);
	column.setPreferredWidth(COLUMN_WIDTH);
}
 
Example #27
Source File: ExtendedJTable.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
/** Necessary to properly stopping the editing when a column is moved (dragged). */
@Override
public void columnMoved(final TableColumnModelEvent e) {
	if (isEditing()) {
		cellEditor.stopCellEditing();
	}
	super.columnMoved(e);
}
 
Example #28
Source File: TableColumnManager.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
public void columnAdded(TableColumnModelEvent e)
  {
  	//  A table column was added to the TableColumnModel so we need
  	//  to update the manager to track this column

  	TableColumn column = tcm.getColumn( e.getToIndex() );

if (allColumns.contains( column ))
	return;
else
	allColumns.add( column );
  }
 
Example #29
Source File: JDynamicTable.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void availableColumnAdded(TableColumnModelEvent event)
{
	int index = event.getToIndex();
	TableColumn column = dynamicColumnModel.getAvailableColumns().get(index);
	menu.getItems().add(index, createMenuItem(column));
	cornerButton.setVisible(true);
}
 
Example #30
Source File: JAutoColumnTable.java    From jeveassets with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void columnMoved(final TableColumnModelEvent e) {
	if (e.getFromIndex() != e.getToIndex()) {
		if (!columnMoved) {
			from = e.getFromIndex();
		}
		to = e.getToIndex();
		columnMoved = true;
	}
}