Java Code Examples for javax.swing.event.TableModelEvent

The following examples show how to use javax.swing.event.TableModelEvent. 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
Source Project: niftyeditor   Source File: ProprietiesListener.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void tableChanged(TableModelEvent e) {
    
    if (e.getType() == TableModelEvent.UPDATE) {
        EditAttributeCommand command = CommandProcessor.getInstance().getCommand(EditAttributeCommand.class);
        RemoveAttributeCommand removecommand = CommandProcessor.getInstance().getCommand(RemoveAttributeCommand.class);
        TableModel mod = (TableModel) e.getSource();
        String proName = (String) mod.getValueAt(e.getLastRow(), 0);
        String proVal = (String) mod.getValueAt(e.getLastRow(), 1);
        if (proName != null && !proName.isEmpty()) {
            try{
            if (proVal == null || proVal.isEmpty()) {
                removecommand.setAttributeKey(proName);
                CommandProcessor.getInstance().excuteCommand(removecommand);
            } else {
               command.setAttribute(proName);
               command.setValue(proVal);
               CommandProcessor.getInstance().excuteCommand(command);
            }
            }catch(Exception ex){
                ex.printStackTrace();
                JOptionPane.showMessageDialog(null,"Can't set the attribute. " + ex.getMessage());
            }
        }
    }
}
 
Example 2
Source Project: consulo   Source File: ArrangementMatchingRulesControl.java    License: 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 3
public void setImage(com.codename1.ui.Image img) {
    com.codename1.impl.javase.SVG s = (com.codename1.impl.javase.SVG)img.getSVGDocument();
    if(s.getDpis() != null) {
        for(int iter = 0 ; iter < dpiTable.getRowCount() ; iter++) {
            dpiTable.setValueAt(Boolean.FALSE, iter, 1);
        }
        for(int iter = 0 ; iter < s.getDpis().length ; iter++) {
            int row = getDPIRow(s.getDpis()[iter]);
            dpiTable.setValueAt(Boolean.TRUE, row, 1);
            dpiTable.setValueAt(s.getWidthForDPI()[iter], row, 2);
            dpiTable.setValueAt(s.getHeightForDPI()[iter], row, 3);
        }
    }
    renderer = new CodenameOneImageRenderer(img);
    preview.removeAll();
    preview.add(BorderLayout.CENTER, renderer);
    preview.revalidate();
    dpiTable.getModel().addTableModelListener(new TableModelListener() {
        public void tableChanged(TableModelEvent e) {
            updateSVGImage();
        }
    });
}
 
Example 4
Source Project: netbeans   Source File: PropertiesTableModel.java    License: Apache License 2.0 6 votes vote down vote up
/** Fires a TableModelEvent - change of one column */
public void fireTableColumnChanged(int index) {
    int columnModelIndex = index;
    
    // reset the header value as well
    Object list[] = listenerList.getListenerList();
    for (int i = 0; i < list.length; i++) {
        if (list[i] instanceof JTable) {
            JTable jt = (JTable)list[i];
            try {
                TableColumn column = jt.getColumnModel().getColumn(index);
                columnModelIndex = column.getModelIndex();
                column.setHeaderValue(jt.getModel().getColumnName(columnModelIndex));
            } catch (ArrayIndexOutOfBoundsException abe) {
                // only catch exception
            }
            jt.getTableHeader().repaint();
        }
    }
    fireTableChanged(new TableModelEvent(this, 0, getRowCount() - 1, columnModelIndex));
}
 
Example 5
/**
    * Update the Correlation model Parameters Table.
    */
private void updateCorrelationModelParametersTable() {
	// Populate the correlation model parameters table.
	FunctionParameterTableModel parameterTableModel = new FunctionParameterTableModel(this.currentAutoCorrelationFunctionContext);

	this.parentController.getMainPanel().getAutoCorrelationParameterAndGraphPanel().getParametersTable()
	        .setModel(parameterTableModel);

	//setup cell editor.
   	TableColumn columnValue = parentController.getMainPanel().getAutoCorrelationParameterAndGraphPanel()
   	    .getParametersTable().getColumnModel().getColumn(FunctionParameterTableModel.COLUMN_VALUE);
   	columnValue.setCellEditor(new TextCellEditor());

	parameterTableModel.addTableModelListener(new TableModelListener() {
		public void tableChanged(TableModelEvent e) {
			updateCorrelationModelGraph();
		}
	});
}
 
Example 6
Source Project: netbeans   Source File: Model.java    License: Apache License 2.0 6 votes vote down vote up
private void showSubTabs( int row, int col ) {
    this.selCol = col;
    this.selRow = row;
    int newRowCount = rowCount;
    selectedTopItem = null;
    if( selCol >= 0 ) {
        selectedTopItem = selCol == documentCol ? documents[selRow] : views[selRow];
        if( selectedTopItem.hasSubItems() ) {
            newRowCount = Math.max( rowCount, selectedTopItem.getActivatableSubItems().length+selRow);
        } else {
            selCol = -1;
            selRow = -1;
            selectedTopItem = null;
        }
    }
    if( documentCol >= 0 )
        fireTableChanged( new TableModelEvent( this, 0, getRowCount(), documentCol+1 ) );
    if( viewCol >= 0 )
        fireTableChanged( new TableModelEvent( this, 0, getRowCount(), viewCol+1 ) );
    int rowDelta = newRowCount - getRowCount();
    extraRows = newRowCount-rowCount;
    if( rowDelta < 0 )
        fireTableRowsDeleted( rowCount, rowCount-rowDelta );
    else if( rowDelta > 0 )
        fireTableRowsInserted( rowCount, rowCount+rowDelta );
}
 
Example 7
Source Project: java-swing-tips   Source File: HeaderCheckBoxHandler.java    License: MIT License 5 votes vote down vote up
@Override public void tableChanged(TableModelEvent e) {
  if (e.getType() == TableModelEvent.UPDATE && e.getColumn() == targetColumnIndex) {
    int vci = table.convertColumnIndexToView(targetColumnIndex);
    TableColumn column = table.getColumnModel().getColumn(vci);
    Object status = column.getHeaderValue();
    TableModel m = table.getModel();
    if (m instanceof DefaultTableModel && fireUpdateEvent((DefaultTableModel) m, column, status)) {
      JTableHeader h = table.getTableHeader();
      h.repaint(h.getHeaderRect(vci));
    }
  }
}
 
Example 8
Source Project: hottub   Source File: XMBeanAttributes.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void tableChanged(final TableModelEvent e) {
    // only post changes to the draggable column
    if (isColumnEditable(e.getColumn())) {
        final TableModel model = (TableModel)e.getSource();
        Object tableValue = model.getValueAt(e.getFirstRow(),
                                         e.getColumn());

        if (LOGGER.isLoggable(Level.FINER)) {
            LOGGER.finer("tableChanged: firstRow="+e.getFirstRow()+
                ", lastRow="+e.getLastRow()+", column="+e.getColumn()+
                ", value="+tableValue);
        }
        // if it's a String, try construct new value
        // using the defined type.
        if (tableValue instanceof String) {
            try {
                tableValue =
                    Utils.createObjectFromString(getClassName(e.getFirstRow()), // type
                    (String)tableValue);// value
            } catch (Throwable ex) {
                popupAndLog(ex,"tableChanged",
                            Messages.PROBLEM_SETTING_ATTRIBUTE);
            }
        }
        final String attributeName = getValueName(e.getFirstRow());
        final Attribute attribute =
              new Attribute(attributeName,tableValue);
        setAttribute(attribute, "tableChanged");
    }
}
 
Example 9
Source Project: lucene-solr   Source File: FieldValuesPaneProvider.java    License: Apache License 2.0 5 votes vote down vote up
void tableDataChenged(TableModelEvent e) {
  int row = e.getFirstRow();
  int col = e.getColumn();
  if (col == FieldsTableModel.Column.LOAD.getIndex()) {
    boolean isLoad = (boolean) fieldsTable.getModel().getValueAt(row, col);
    if (!isLoad) {
      loadAllCB.setSelected(false);
    }
  }
}
 
Example 10
Source Project: openjdk-8   Source File: TableSorter.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public void newDataAvailable(TableModelEvent e) {
    super.newDataAvailable(e);
    invertedIndex = new int[getRowCount()];
    for (int i = 0; i < invertedIndex.length; i++) {
        invertedIndex[i] = i;
    }
    sort(this.sortColumn, this.ascending);
}
 
Example 11
Source Project: dragonwell8_jdk   Source File: TableSorter.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public void tableChanged(TableModelEvent e) {
    System.out.println("Sorter: tableChanged");
    reallocateIndexes();

    super.tableChanged(e);
}
 
Example 12
public void tableChanged(final TableModelEvent e) {
    // only post changes to the draggable column
    if (isColumnEditable(e.getColumn())) {
        final TableModel model = (TableModel)e.getSource();
        Object tableValue = model.getValueAt(e.getFirstRow(),
                                         e.getColumn());

        if (LOGGER.isLoggable(Level.FINER)) {
            LOGGER.finer("tableChanged: firstRow="+e.getFirstRow()+
                ", lastRow="+e.getLastRow()+", column="+e.getColumn()+
                ", value="+tableValue);
        }
        // if it's a String, try construct new value
        // using the defined type.
        if (tableValue instanceof String) {
            try {
                tableValue =
                    Utils.createObjectFromString(getClassName(e.getFirstRow()), // type
                    (String)tableValue);// value
            } catch (Throwable ex) {
                popupAndLog(ex,"tableChanged",
                            Messages.PROBLEM_SETTING_ATTRIBUTE);
            }
        }
        final String attributeName = getValueName(e.getFirstRow());
        final Attribute attribute =
              new Attribute(attributeName,tableValue);
        setAttribute(attribute, "tableChanged");
    }
}
 
Example 13
Source Project: dragonwell8_jdk   Source File: TableSorter.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public void newDataAvailable(TableModelEvent e) {
    super.newDataAvailable(e);
    invertedIndex = new int[getRowCount()];
    for (int i = 0; i < invertedIndex.length; i++) {
        invertedIndex[i] = i;
    }
    sort(this.sortColumn, this.ascending);
}
 
Example 14
Source Project: Spark   Source File: OTRPrefPanel.java    License: Apache License 2.0 5 votes vote down vote up
private void loadRemoteKeys() {

        for (RosterEntry entry : Roster.getInstanceFor( SparkManager.getConnection() ).getEntries()) {
            SessionID curSession = new SessionID(SparkManager.getConnection().getUser(), entry.getUser(), "Scytale");
            String remoteKey = _keyManager.getRemoteFingerprint(curSession);
            if (remoteKey != null) {
                boolean isVerified = _keyManager.isVerified(curSession);
                _keytable.addEntry(entry.getUser(), remoteKey, isVerified);
            }
        }

        _keytable.addTableChangeListener(new TableModelListener() {

            @Override
            public void tableChanged(TableModelEvent e) {
                int col = e.getColumn();
                int row = e.getFirstRow();

                if (col == 2) {
                    boolean selection = (Boolean) _keytable.getValueAt(row, col);
                    String JID = (String) _keytable.getValueAt(row, 0);
                    SessionID curSelectedSession = new SessionID(SparkManager.getConnection().getUser(), JID, "Scytale");
                    if (!selection) {
                        _keyManager.verify(curSelectedSession);
                    } else {
                        _keyManager.unverify(curSelectedSession);
                    }
                }
            }
        });

    }
 
Example 15
Source Project: ghidra   Source File: ThreadedTableModel.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @see javax.swing.table.AbstractTableModel#fireTableChanged(javax.swing.event.TableModelEvent)
 */
@Override
public void fireTableChanged(TableModelEvent e) {
	if (SwingUtilities.isEventDispatchThread()) {
		super.fireTableChanged(e);
		return;
	}
	final TableModelEvent e1 = e;
	SwingUtilities.invokeLater(() -> ThreadedTableModel.super.fireTableChanged(e1));
}
 
Example 16
Source Project: ghidra   Source File: ThreadedTableTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testAddSendsEvent() {
	waitForTableModel(model);
	AtomicReference<TableModelEvent> ref = new AtomicReference<>();
	runSwing(() -> model.addTableModelListener(e -> ref.set(e)));

	int newValue = model.getRowCount() + 1;
	addItemToModel(newValue);

	assertEvent_AllDataChanged(ref.get());
}
 
Example 17
@Override
public void tableChanged(TableModelEvent e) {
    final TableModel tableModel = (TableModel) e.getSource();
    final MosaicOp.Variable[] variables = new MosaicOp.Variable[tableModel.getRowCount()];
    for (int i = 0; i < variables.length; i++) {
        variables[i] = new MosaicOp.Variable((String) tableModel.getValueAt(i, 0),
                                             (String) tableModel.getValueAt(i, 1));
    }
    getBinding().setPropertyValue(variables);
}
 
Example 18
Source Project: jdk8u_jdk   Source File: TableSorter.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void sortByColumn(int column, boolean ascending) {
    this.ascending = ascending;
    sortingColumns.clear();
    sortingColumns.add(column);
    sort(this);
    super.tableChanged(new TableModelEvent(this));
}
 
Example 19
public void sortByColumn(int column, boolean ascending) {
    this.ascending = ascending;
    sortingColumns.clear();
    sortingColumns.add(new Integer(column));
    sort(this);
    super.tableChanged(new TableModelEvent(this));
}
 
Example 20
Source Project: ghidra   Source File: VTFunctionAssociationProvider.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void tableChanged(TableModelEvent e) {

	StringBuffer buffy = new StringBuffer();
	String sessionName = controller.getVersionTrackingSessionName();
	buffy.append("[Session: ").append(sessionName).append("] - ");
	getTableFilterString("Source Functions", sourceFunctionsModel, buffy);
	buffy.append(" / ");
	getTableFilterString("Destination Functions", destinationFunctionsModel, buffy);
	setSubTitle(buffy.toString());
}
 
Example 21
Source Project: netbeans   Source File: PanelSupportedFrameworksVisual.java    License: Apache License 2.0 5 votes vote down vote up
public void tableChanged(TableModelEvent e) {
    FrameworksTableModel model = (FrameworksTableModel) jTableFrameworks.getModel();
    if (jTableFrameworks.getSelectedRow() == -1) {
        return;
    }
    FrameworkModelItem item = model.getItem(jTableFrameworks.getSelectedRow());
    WebFrameworkProvider framework = item.getFramework();
    setConfigPanel(framework, item);
}
 
Example 22
@Override
protected JComponent getSwingComponent() {
    // Create columns names
    String columnNames[] = {"Column 1", "Column 2", "Column 3"};

    // Create some data
    String dataValues[][] = {
        {"12", "234", "67"},
        {"-123", "43", "853"},
        {"93", "89.2", "109"},
        {"279", "9033", "3092"},
        {"12", "234", "67"},
        {"-123", "43", "853"},
        {"93", "89.2", "109"},
        {"279", "9033", "3092"},
        {"12", "234", "67"},
        {"-123", "43", "853"},
        {"93", "89.2", "109"},
        {"279", "9033", "3092"},
        {"12", "234", "67"},
        {"-123", "43", "853"},
        {"93", "89.2", "109"},
        {"279", "9033", "3092"}
    };

    // Create a new table instance
    JTable jt = new JTable(dataValues, columnNames);
    jt.getModel().addTableModelListener(new TableModelListener() {

        public void tableChanged(TableModelEvent e) {
            System.err.println("table changed");
        }
    });
    return jt;
}
 
Example 23
Source Project: TencentKona-8   Source File: TableSorter.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public void newDataAvailable(TableModelEvent e) {
    super.newDataAvailable(e);
    invertedIndex = new int[getRowCount()];
    for (int i = 0; i < invertedIndex.length; i++) {
        invertedIndex[i] = i;
    }
    sort(this.sortColumn, this.ascending);
}
 
Example 24
Source Project: WorldPainter   Source File: InfoPanel.java    License: GNU General Public License v3.0 5 votes vote down vote up
boolean clear() {
    if (! rows.isEmpty()) {
        rows.clear();
        layerIndices.clear();
        TableModelEvent event = new TableModelEvent(this);
        for (TableModelListener listener: listeners) {
            listener.tableChanged(event);
        }
        return true;
    } else {
        return false;
    }
}
 
Example 25
public void updateRowHeights(TableModelEvent e) {
    final int first;
    final int last;
    if (e == null || e.getFirstRow() == TableModelEvent.HEADER_ROW) {
        first = 0;
        last = this.getTable().getRowCount();
    } else {
        first = e.getFirstRow();
        last = e.getLastRow() + 1;
    }

    SwingUtilities.invokeLater(() -> {
        updateRowHeights(first, last);
    });
}
 
Example 26
Source Project: jdk8u60   Source File: TableSorter.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public void tableChanged(TableModelEvent e) {
    System.out.println("Sorter: tableChanged");
    reallocateIndexes();

    super.tableChanged(e);
}
 
Example 27
Source Project: jdk8u_jdk   Source File: TableSorter.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public void newDataAvailable(TableModelEvent e) {
    super.newDataAvailable(e);
    invertedIndex = new int[getRowCount()];
    for (int i = 0; i < invertedIndex.length; i++) {
        invertedIndex[i] = i;
    }
    sort(this.sortColumn, this.ascending);
}
 
Example 28
Source Project: weblaf   Source File: TableHeaderPainter.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Installs language listeners.
 */
protected void installLanguageListeners ()
{
    languageSensitive = new LanguageListener ()
    {
        @Override
        public void languageChanged ( @NotNull final Language oldLanguage, @NotNull final Language newLanguage )
        {
            if ( isLanguageSensitive () )
            {
                final JTable table = component.getTable ();
                if ( table != null && table.getModel () instanceof AbstractTableModel )
                {
                    // Calling public model methods when possible
                    final AbstractTableModel tableModel = ( AbstractTableModel ) table.getModel ();
                    tableModel.fireTableRowsUpdated ( TableModelEvent.HEADER_ROW, TableModelEvent.HEADER_ROW );
                }
                else
                {
                    // Simply repainting table header
                    component.repaint ();
                }
            }
        }
    };
    UILanguageManager.addLanguageListener ( component, languageSensitive );
}
 
Example 29
protected void fireTableModelEvent( final TableModelEvent event ) {
  final TableModelListener[] listeners = eventListenerList.getListeners( TableModelListener.class );
  for ( int i = 0; i < listeners.length; i++ ) {
    final TableModelListener listener = listeners[ i ];
    listener.tableChanged( event );
  }
}
 
Example 30
Source Project: netbeans   Source File: InsertRecordDialog.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void tableChanged(TableModelEvent e) {
    if (SwingUtilities.isEventDispatchThread()) {
        refreshSQL();
    } else {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                refreshSQL();
            }
        });
    }
}