Java Code Examples for javax.swing.event.TableModelEvent#DELETE
The following examples show how to use
javax.swing.event.TableModelEvent#DELETE .
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: BarChartTab.java From mars-sim with GNU General Public License v3.0 | 6 votes |
/** * The underlying model has changed. */ public void tableChanged(TableModelEvent e) { if ((e.getType() == TableModelEvent.INSERT) || (e.getType() == TableModelEvent.DELETE)) { loadCategories(); fireDatasetChanged(); } else if (e.getColumn() == TableModelEvent.ALL_COLUMNS) fireDatasetChanged(); else { boolean dataChanged = false; for (int column : columns) { if (column == e.getColumn()) dataChanged = true; } if (dataChanged) { long time = System.nanoTime() / 1000000L; if ((time - lastUpdateTime) > MIN_TIME_BETWEEN_UPDATES) { lastUpdateTime = time; fireDatasetChanged(); } } } }
Example 2
Source File: JAutoColumnTable.java From jeveassets with GNU General Public License v2.0 | 6 votes |
@Override public void tableChanged(final TableModelEvent e) { //XXX - Workaround for Java 7 if (getTable().isEditing()) { getTable().getCellEditor().cancelCellEditing(); } if (e.getType() == TableModelEvent.DELETE) { rowsCount = rowsCount - (Math.abs(e.getFirstRow() - e.getLastRow()) + 1); } if (e.getType() == TableModelEvent.INSERT) { rowsCount = rowsCount + (Math.abs(e.getFirstRow() - e.getLastRow()) + 1); } if (Math.abs(rowsLastTime + rowsCount) == getRowCount() //Last Table Update && (e.getType() != TableModelEvent.UPDATE || (e.getType() == TableModelEvent.UPDATE && e.getFirstRow() >= 0))) { rowsLastTime = getRowCount(); rowsCount = 0; autoResizeColumns(); } }
Example 3
Source File: OrderBookModel.java From gdax-java with MIT License | 6 votes |
public void tableChanged(TableModelEvent e) { switch (e.getType()) { case TableModelEvent.DELETE: { fireAllChanged(); break; } case TableModelEvent.INSERT: { fireAllChanged(); break; } case TableModelEvent.UPDATE: { fireAllChanged(); break; } } }
Example 4
Source File: ArrangementMatchingRulesControl.java From consulo with Apache License 2.0 | 6 votes |
private void onTableChange(@Nonnull TableModelEvent e) { final int signum; switch (e.getType()) { case TableModelEvent.INSERT: signum = 1; break; case TableModelEvent.DELETE: signum = -1; for (int i = e.getLastRow(); i >= e.getFirstRow(); i--) { myComponents.remove(i); } break; default: return; } int shift = Math.abs(e.getFirstRow() - e.getLastRow() + 1) * signum; myComponents.shiftKeys(e.getFirstRow(), shift); if (myRowUnderMouse >= e.getFirstRow()) { myRowUnderMouse = -1; } if (getModel().getSize() > 0) { repaintRows(0, getModel().getSize() - 1, false); } }
Example 5
Source File: HeaderCheckBoxHandler.java From java-swing-tips with MIT License | 6 votes |
@Override public void tableChanged(TableModelEvent e) { int vci = table.convertColumnIndexToView(targetColumnIndex); TableColumn column = table.getColumnModel().getColumn(vci); Object status = column.getHeaderValue(); TableModel m = table.getModel(); boolean repaint = false; if (e.getType() == TableModelEvent.DELETE) { // System.out.println("DELETE"); // System.out.println(status + ": " + Status.INDETERMINATE.equals(status)); repaint = fireDeleteEvent(m, column, status); } else if (e.getType() == TableModelEvent.INSERT && status != Status.INDETERMINATE) { // System.out.println("INSERT"); repaint = fireInsertEvent(m, column, status, e); } else if (e.getType() == TableModelEvent.UPDATE && e.getColumn() == targetColumnIndex) { // System.out.println("UPDATE"); repaint = fireUpdateEvent(m, column, status); } if (repaint) { JTableHeader h = table.getTableHeader(); h.repaint(h.getHeaderRect(vci)); } }
Example 6
Source File: MonitorMessageTableModel.java From USBtinViewer with GNU General Public License v3.0 | 5 votes |
/** * Clear the message list */ public void clear() { if (messages.size() == 0) return; int lastRow = messages.size() - 1; messages.clear(); TableModelEvent e = new TableModelEvent(this, 0, lastRow, TableModelEvent.ALL_COLUMNS, TableModelEvent.DELETE); for (int i = 0, n = listeners.size(); i < n; i++) { listeners.get(i).tableChanged(e); } }
Example 7
Source File: CombinedLayerTableModel.java From WorldPainter with GNU General Public License v3.0 | 5 votes |
void deleteRow(int rowIndex) { rows.remove(rowIndex); TableModelEvent event = new TableModelEvent(this, rowIndex, rowIndex, TableModelEvent.ALL_COLUMNS, TableModelEvent.DELETE); for (TableModelListener listener: listeners) { listener.tableChanged(event); } }
Example 8
Source File: TunnelFloorLayersTableModel.java From WorldPainter with GNU General Public License v3.0 | 5 votes |
public void removeLayer(int row) { Layer layer = layers.remove(row); settings.remove(layer); TableModelEvent event = new TableModelEvent(this, row, row, TableModelEvent.ALL_COLUMNS, TableModelEvent.DELETE); for (TableModelListener listener: listeners) { listener.tableChanged(event); } }
Example 9
Source File: TerrainRangesTableModel.java From WorldPainter with GNU General Public License v3.0 | 5 votes |
public void deleteRow(int row) { System.arraycopy(levels, row + 1, levels, row, rows - 1 - row); System.arraycopy(terrains, row + 1, terrains, row, rows - 1 - row); rows--; TableModelEvent event = new TableModelEvent(this, row, row, TableModelEvent.ALL_COLUMNS, TableModelEvent.DELETE); for (TableModelListener listener: listeners) { listener.tableChanged(event); } notifyChangeListener(); }
Example 10
Source File: JBTable.java From consulo with Apache License 2.0 | 5 votes |
protected void onTableChanged(@Nonnull TableModelEvent e) { if (!myRowHeightIsExplicitlySet) { myRowHeight = -1; } if (e.getType() == TableModelEvent.DELETE && isEmpty() || e.getType() == TableModelEvent.INSERT && !isEmpty()) { repaintViewport(); } }
Example 11
Source File: JoiningTableModel.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
/** * This fine grain notification tells listeners the exact range of cells, rows, or columns that changed. */ public void tableChanged( final TableModelEvent e ) { if ( e.getType() == TableModelEvent.UPDATE && e.getFirstRow() == TableModelEvent.HEADER_ROW ) { updateStructure(); } else if ( e.getType() == TableModelEvent.INSERT || e.getType() == TableModelEvent.DELETE ) { updateRowCount(); } else { updateData(); } }
Example 12
Source File: LogMessageTableModel.java From USBtinViewer with GNU General Public License v3.0 | 5 votes |
/** * Clear the message list */ public void clear() { if (messages.size() == 0) return; int lastRow = messages.size() - 1; messages.clear(); TableModelEvent e = new TableModelEvent(this, 0, lastRow, TableModelEvent.ALL_COLUMNS, TableModelEvent.DELETE); for (int i = 0, n = listeners.size(); i < n; i++) { listeners.get(i).tableChanged(e); } }
Example 13
Source File: Table.java From swift-k with Apache License 2.0 | 5 votes |
public void tableChanged(TableModelEvent e) { if (e.getType() == TableModelEvent.DELETE || e.getType() == TableModelEvent.INSERT) { invalidate(); } else { redraw(); } }
Example 14
Source File: EventBroadcaster.java From netbeans with Apache License 2.0 | 5 votes |
private static String tableModelEventToString (TableModelEvent e) { StringBuilder sb = new StringBuilder(); sb.append ("TableModelEvent "); switch (e.getType()) { case TableModelEvent.INSERT : sb.append ("insert "); break; case TableModelEvent.DELETE : sb.append ("delete "); break; case TableModelEvent.UPDATE : sb.append ("update "); break; default : sb.append("Unknown type ").append(e.getType()); } sb.append ("from "); switch (e.getFirstRow()) { case TableModelEvent.HEADER_ROW : sb.append ("header row "); break; default : sb.append (e.getFirstRow()); sb.append (' '); } sb.append ("to "); sb.append (e.getLastRow()); sb.append (" column "); switch (e.getColumn()) { case TableModelEvent.ALL_COLUMNS : sb.append ("ALL_COLUMNS"); break; default : sb.append (e.getColumn()); } return sb.toString(); }
Example 15
Source File: EventBroadcaster.java From netbeans with Apache License 2.0 | 4 votes |
/** Translates tree expansion event into an appropriate TableModelEvent * indicating the number of rows added/removed at the appropriate index */ private TableModelEvent translateEvent (TreeExpansionEvent e, boolean expand) { //PENDING: This code should be profiled - the descendent paths search //is not cheap, and it might be less expensive (at least if the table //does not have expensive painting logic) to simply fire a generic //"something changed" table model event and be done with it. TreePath path = e.getPath(); //Add one because it is a child of the row. int firstRow = getLayout().getRowForPath(path) + 1; if (firstRow == -1) { //This does not mean nothing happened, it may just be that we are //a large model tree, and the FixedHeightLayoutCache says the //change happened in a row that is not showing. //TODO: Just to make the table scrollbar adjust itself appropriately, //we may want to look up the number of children in the model and //fire an event that says that that many rows were added. Waiting //to see if anybody actually will use this (i.e. fires changes in //offscreen nodes as a normal part of usage return null; } //Get all the expanded descendants of the path that was expanded/collapsed TreePath[] paths = getTreePathSupport().getExpandedDescendants(path); //Start with the number of children of whatever was expanded/collapsed int count = getTreeModel().getChildCount(path.getLastPathComponent()); if (count == 0) { return null; } //Iterate any of the expanded children, adding in their child counts for (int i=0; i < paths.length; i++) { count += getTreeModel().getChildCount(paths[i].getLastPathComponent()); } //Now we can calculate the last row affected for real int lastRow = firstRow + count -1; //Construct a table model event reflecting this data TableModelEvent result = new TableModelEvent (getModel(), firstRow, lastRow, TableModelEvent.ALL_COLUMNS, expand ? TableModelEvent.INSERT : TableModelEvent.DELETE); return result; }
Example 16
Source File: LayerRangesTableModel.java From WorldPainter with GNU General Public License v3.0 | 4 votes |
public void deleteRow(int row) { layers.remove(row); filters.remove(row); TableModelEvent event = new TableModelEvent(this, row, row, TableModelEvent.ALL_COLUMNS, TableModelEvent.DELETE); listeners.forEach(listener -> listener.tableChanged(event)); }
Example 17
Source File: XJTable.java From gate-core with GNU Lesser General Public License v3.0 | 4 votes |
/** * This gets events from the source model and forwards them to the UI */ @Override public void tableChanged(TableModelEvent e){ int type = e.getType(); int firstRow = e.getFirstRow(); int lastRow = e.getLastRow(); int column = e.getColumn(); //deal with the changes in the data //we have no way to "repair" the sorting on data updates so we will need //to rebuild the order every time switch(type){ case TableModelEvent.UPDATE: if(firstRow == TableModelEvent.HEADER_ROW){ //complete structure change -> reallocate the data init(sourceModel); newColumns(); fireTableStructureChanged(); if(isSortable()) sort(); }else if(lastRow == Integer.MAX_VALUE){ //all data changed (including the number of rows) init(sourceModel); if(isSortable()){ sort(); } else { //this will re-create all rows (which deletes the rowModel in JTable) componentSizedProperly = false; fireTableDataChanged(); } }else{ //the rows should have normal values //if the sortedColumn is not affected we don't care if(isSortable() && (column == sortedColumn || column == TableModelEvent.ALL_COLUMNS)){ //re-sorting will also fire the event upwards sort(); }else{ componentSizedProperly = false; fireTableChanged(new TableModelEvent(this, sourceToTarget(firstRow), sourceToTarget(lastRow), column, type)); } } break; case TableModelEvent.INSERT: //rows were inserted -> we need to rebuild init(sourceModel); if(firstRow != TableModelEvent.HEADER_ROW && firstRow == lastRow){ //single row insertion if(isSortable()) sort(); else{ componentSizedProperly = false; fireTableChanged(new TableModelEvent(this, sourceToTarget(firstRow), sourceToTarget(lastRow), column, type)); } }else{ //the real rows are not in sequence if(isSortable()) sort(); else { //this will re-create all rows (which deletes the rowModel in JTable) componentSizedProperly = false; fireTableDataChanged(); } } break; case TableModelEvent.DELETE: //rows were deleted -> we need to rebuild init(sourceModel); if(isSortable()) sort(); else { //this will re-create all rows (which deletes the rowModel in JTable) componentSizedProperly = false; fireTableDataChanged(); } } }