DELETE源码实例Demo

javax.swing.event.TableModelEvent#DELETE源码实例Demo

下面列出了javax.swing.event.TableModelEvent#DELETE 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: mars-sim   文件: BarChartTab.java
/**
 * 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();
		 }
	 }
 }
}
 
源代码2 项目: jeveassets   文件: JAutoColumnTable.java
@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();
	}
}
 
源代码3 项目: gdax-java   文件: OrderBookModel.java
public void tableChanged(TableModelEvent e) {
    switch (e.getType()) {
        case TableModelEvent.DELETE: {

            fireAllChanged();
            break;
        }
        case TableModelEvent.INSERT: {

            fireAllChanged();
            break;
        }
        case TableModelEvent.UPDATE: {

            fireAllChanged();
            break;
        }
    }
}
 
源代码4 项目: java-swing-tips   文件: HeaderCheckBoxHandler.java
@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));
  }
}
 
源代码5 项目: consulo   文件: ArrangementMatchingRulesControl.java
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);
  }
}
 
源代码6 项目: netbeans   文件: EventBroadcaster.java
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();
}
 
源代码7 项目: swift-k   文件: Table.java
public void tableChanged(TableModelEvent e) {
	if (e.getType() == TableModelEvent.DELETE || e.getType() == TableModelEvent.INSERT) {
		invalidate();
	}
	else {
		redraw();
	}
}
 
源代码8 项目: USBtinViewer   文件: LogMessageTableModel.java
/**
 * 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);
    }
}
 
源代码9 项目: USBtinViewer   文件: MonitorMessageTableModel.java
/**
 * 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);
    }
}
 
源代码10 项目: pentaho-reporting   文件: JoiningTableModel.java
/**
 * 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();
  }
}
 
源代码11 项目: consulo   文件: JBTable.java
protected void onTableChanged(@Nonnull TableModelEvent e) {
  if (!myRowHeightIsExplicitlySet) {
    myRowHeight = -1;
  }
  if (e.getType() == TableModelEvent.DELETE && isEmpty() || e.getType() == TableModelEvent.INSERT && !isEmpty()) {
    repaintViewport();
  }
}
 
源代码12 项目: WorldPainter   文件: TerrainRangesTableModel.java
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();
}
 
源代码13 项目: WorldPainter   文件: TunnelFloorLayersTableModel.java
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);
    }
}
 
源代码14 项目: WorldPainter   文件: CombinedLayerTableModel.java
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);
    }
}
 
源代码15 项目: netbeans   文件: EventBroadcaster.java
/** 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;
}
 
源代码16 项目: gate-core   文件: XJTable.java
/**
 * 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();
      }
  }
}
 
源代码17 项目: WorldPainter   文件: LayerRangesTableModel.java
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));
}
 
如果文章对您有帮助,请点击页面广告。以鼓励作者做出的努力。