Java Code Examples for javax.swing.event.TableModelEvent#INSERT

The following examples show how to use javax.swing.event.TableModelEvent#INSERT . 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: ArrangementMatchingRulesControl.java    From consulo with Apache License 2.0 6 votes vote down vote up
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 2
Source File: BarChartTab.java    From mars-sim with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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 3
Source File: JAutoColumnTable.java    From jeveassets with GNU General Public License v2.0 6 votes vote down vote up
@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 4
Source File: OrderBookModel.java    From gdax-java with MIT License 6 votes vote down vote up
public void tableChanged(TableModelEvent e) {
    switch (e.getType()) {
        case TableModelEvent.DELETE: {

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

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

            fireAllChanged();
            break;
        }
    }
}
 
Example 5
Source File: TailingModeMarkersPanel.java    From otroslogviewer with Apache License 2.0 6 votes vote down vote up
@Override
public void tableChanged(final TableModelEvent e) {
  final HashSet<AutomaticMarker> selected = defaultTableModel.getSelected();

  if (e.getType() == TableModelEvent.INSERT) {
    SwingUtilities.invokeLater(() -> {
      int firstRow = e.getFirstRow();
      int lastRow = e.getLastRow();
      for (int i = firstRow; i <= lastRow; i++) {
        LogData logData = dataTableModel.getLogData(i);
        for (AutomaticMarker m : selected) {
          if (m.toMark(logData)) {
            dataTableModel.markRows(m.getColors(), i);
          }
        }
      }
    });
  }
}
 
Example 6
Source File: TunnelFloorLayersTableModel.java    From WorldPainter with GNU General Public License v3.0 5 votes vote down vote up
public void addLayer(Layer layer) {
    if (! layers.contains(layer)) {
        layers.add(layer);
        settings.put(layer, new TunnelLayer.LayerSettings());
        int row = layers.size() - 1;
        TableModelEvent event = new TableModelEvent(this, row, row, TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT);
        for (TableModelListener listener: listeners) {
            listener.tableChanged(event);
        }
    }
}
 
Example 7
Source File: PumpCalibration.java    From NanoJ-Fluidics with MIT License 5 votes vote down vote up
@Override
public void tableChanged(TableModelEvent e) {
    if (e.getType() == TableModelEvent.UPDATE || e.getType() == TableModelEvent.INSERT ) {
        if (!editing) {
            double diameter;
            double maxFlowRate;
            double minFlowRate;

            diameter = Double.parseDouble((String) tableModel.getValueAt(e.getFirstRow(),DIAMETER));
            maxFlowRate = Double.parseDouble((String) tableModel.getValueAt(e.getFirstRow(),MAX_FLOW_RATE));
            minFlowRate = Double.parseDouble((String) tableModel.getValueAt(e.getFirstRow(),MIN_FLOW_RATE));

            String name = (String) tableModel.getValueAt(e.getFirstRow(),NAME);
            String subPump = (String) tableModel.getValueAt(e.getFirstRow(),SUB_PUMP);
            String port = (String) tableModel.getValueAt(e.getFirstRow(),PORT);

            pumpManager.updateReferenceRate(e.getFirstRow(),new double[] {diameter,maxFlowRate,minFlowRate});

            prefs.putDouble(CAL+DIAMETER+name+subPump+port,diameter);
            prefs.putDouble(CAL+MAX_FLOW_RATE+name+subPump+port,maxFlowRate);
            prefs.putDouble(CAL+MIN_FLOW_RATE+name+subPump+port,minFlowRate);

            gui.log.message("Updated calibration of " + name + ", " + subPump + " on port " + port + " to: " +
                    diameter + ", " + maxFlowRate + ", " + minFlowRate);
        }
    }
}
 
Example 8
Source File: LayerRangesTableModel.java    From WorldPainter with GNU General Public License v3.0 5 votes vote down vote up
public void addRow(Filter filter, Layer layer) {
    filters.add(filter);
    layers.add(layer);
    int index = filters.size() - 1;
    TableModelEvent event = new TableModelEvent(this, index, index, TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT);
    listeners.forEach(listener -> listener.tableChanged(event));
}
 
Example 9
Source File: JBTable.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected void onTableChanged(@Nonnull TableModelEvent e) {
  if (!myRowHeightIsExplicitlySet) {
    myRowHeight = -1;
  }
  if (e.getType() == TableModelEvent.DELETE && isEmpty() || e.getType() == TableModelEvent.INSERT && !isEmpty()) {
    repaintViewport();
  }
}
 
Example 10
Source File: JoiningTableModel.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * 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 11
Source File: CombinedLayerTableModel.java    From WorldPainter with GNU General Public License v3.0 5 votes vote down vote up
void addRow(Row row) {
    rows.add(row);
    TableModelEvent event = new TableModelEvent(this, rows.size() - 1, rows.size() - 1, TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT);
    for (TableModelListener listener: listeners) {
        listener.tableChanged(event);
    }
}
 
Example 12
Source File: LogMessageTableModel.java    From USBtinViewer with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Add given message to message list
 * 
 * @param msg Message list to add
 */
public void addMessage(LogMessage msg) {
    int index = messages.size();
    messages.add(msg);

    TableModelEvent e = new TableModelEvent(this, index, index, TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT);
    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 vote down vote up
public void tableChanged(TableModelEvent e) {
	if (e.getType() == TableModelEvent.DELETE || e.getType() == TableModelEvent.INSERT) {
		invalidate();
	}
	else {
		redraw();
	}
}
 
Example 14
Source File: ComplexTypePanel.java    From binnavi with Apache License 2.0 5 votes vote down vote up
@Override
public void tableChanged(final TableModelEvent event) {
  if (event.getType() == TableModelEvent.INSERT || event.getType() == TableModelEvent.UPDATE) {
    final MemberTableModel model = members.getModel();
    for (int i = 0; i < model.getRowCount(); i++) {
      final int modelIndex = members.convertRowIndexToModel(i);
      boolean validate = validateTableRow(i);
      model.markRow(modelIndex, validate);
    }
  }
}
 
Example 15
Source File: EventBroadcaster.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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 16
Source File: DetailsTable.java    From visualvm with GNU General Public License v2.0 4 votes vote down vote up
public void tableChanged(TableModelEvent e) {
    super.tableChanged(e);
    if (e.getType() == TableModelEvent.INSERT) updateColumns(false);
}
 
Example 17
Source File: DetailsTable.java    From visualvm with GNU General Public License v2.0 4 votes vote down vote up
public void tableChanged(TableModelEvent e) {
    super.tableChanged(e);
    if (e.getType() == TableModelEvent.INSERT) updateColumns(false);
}
 
Example 18
Source File: XJTable.java    From gate-core with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * 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();
      }
  }
}
 
Example 19
Source File: DetailsTable.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void tableChanged(TableModelEvent e) {
    super.tableChanged(e);
    if (e.getType() == TableModelEvent.INSERT) updateColumns(false);
}
 
Example 20
Source File: EventBroadcaster.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/** 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;
}