Java Code Examples for javax.swing.event.TableColumnModelEvent

The following examples show how to use javax.swing.event.TableColumnModelEvent. These examples are extracted from open source projects. 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
@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 Project: mars-sim   Source File: TableColumnManager.java    License: 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 3
@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 4
@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 5
@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 6
Source Project: netbeans   Source File: ETableColumnModel.java    License: 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 7
Source Project: netbeans   Source File: IssueTable.java    License: 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 8
Source Project: gate-core   Source File: XJTable.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Overridden to fix 
 * //http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4330950:
 */ 
@Override
public void columnMoved(TableColumnModelEvent e) {
  if (isEditing()) {
      cellEditor.stopCellEditing();
  }
  super.columnMoved(e);
}
 
Example 9
Source Project: openjdk-jdk9   Source File: JTableOperator.java    License: 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 10
Source Project: openjdk-jdk9   Source File: JTableOperator.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Maps {@code JTable.columnMoved(TableColumnModelEvent)} through queue
 */
public void columnMoved(final TableColumnModelEvent tableColumnModelEvent) {
    runMapping(new MapVoidAction("columnMoved") {
        @Override
        public void map() {
            ((JTable) getSource()).columnMoved(tableColumnModelEvent);
        }
    });
}
 
Example 11
Source Project: openjdk-jdk9   Source File: JTableOperator.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Maps {@code JTable.columnRemoved(TableColumnModelEvent)} through queue
 */
public void columnRemoved(final TableColumnModelEvent tableColumnModelEvent) {
    runMapping(new MapVoidAction("columnRemoved") {
        @Override
        public void map() {
            ((JTable) getSource()).columnRemoved(tableColumnModelEvent);
        }
    });
}
 
Example 12
/**
 * Maps {@code JTableHeader.columnAdded(TableColumnModelEvent)} through queue
 */
public void columnAdded(final TableColumnModelEvent tableColumnModelEvent) {
    runMapping(new MapVoidAction("columnAdded") {
        @Override
        public void map() {
            ((JTableHeader) getSource()).columnAdded(tableColumnModelEvent);
        }
    });
}
 
Example 13
/**
 * 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 14
/**
 * 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 15
@Override
public void columnMoved(TableColumnModelEvent e) {
	if (table == null) {
		return;
	}

	onColsConfigChanged();
}
 
Example 16
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 17
Source Project: spotbugs   Source File: BugTreeModel.java    License: 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 18
@Override
public void columnAdded(TableColumnModelEvent e) {
	super.columnAdded(e);
	// bigger default size
	TableColumn column = getColumnModel().getColumn(getColumnModel().getColumnCount() - 1);
	column.setPreferredWidth(COLUMN_WIDTH);
}
 
Example 19
/** 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 20
Source Project: mars-sim   Source File: TableColumnManager.java    License: 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 21
Source Project: jeveassets   Source File: JAutoColumnTable.java    License: 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;
	}
}
 
Example 22
Source Project: pcgen   Source File: JDynamicTable.java    License: 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 23
Source Project: pcgen   Source File: JDynamicTable.java    License: 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 24
/**
 * 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
/**
 * 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 26
@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 27
@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 28
Source Project: pcgen   Source File: JDynamicTable.java    License: 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 29
Source Project: pcgen   Source File: JDynamicTable.java    License: 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 30
/**
 * 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);
		}
	}
}