Java Code Examples for javax.swing.table.TableCellEditor

The following are top voted examples for showing how to use javax.swing.table.TableCellEditor. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: incubator-netbeans   File: TableUISupport.java   View source code 6 votes vote down vote up
@Override
public TableCellEditor getCellEditor(int row, int column) {
    if (column == 2){
        if (getModel() instanceof TableClassNamesModel) {
            TableClassNamesModel model = (TableClassNamesModel)getModel();
            Table table = model.getTableAt(row);
            DisabledReason dr = table.getDisabledReason();
            boolean existing = dr instanceof Table.ExistingDisabledReason;
            if (existing){
                return new DefaultCellEditor(new JComboBox(new UpdateType[]{UpdateType.UPDATE, UpdateType.RECREATE}));
            } else {
                return new DefaultCellEditor(new JComboBox(new UpdateType[]{UpdateType.NEW}));
            }
        }
    } 
    return super.getCellEditor(row, column);
}
 
Example 2
Project: incubator-netbeans   File: CodeSetupPanel.java   View source code 6 votes vote down vote up
@Override
public TableCellEditor getCellEditor(int row, int column) {
    if(showParamTypes) {
        String paramName = (String) tableModel.getValueAt(row, 0);
        Class type = (column == 2) ? (Class) tableModel.getValueAt(row, 1) : Boolean.class;

        if (Enum.class.isAssignableFrom(type)) {
            JComboBox combo = new JComboBox(type.getEnumConstants());
            return new DefaultCellEditor(combo);
        } else if (type == Boolean.class || type == Boolean.TYPE) {
            JCheckBox cb = new JCheckBox();
            cb.setHorizontalAlignment(JLabel.CENTER);
            cb.setBorderPainted(true);
            return new DefaultCellEditor(cb);
        } else if (paramName.toLowerCase().contains(Constants.PASSWORD)) {
            return new DefaultCellEditor(new JPasswordField());
        }
    }

    return super.getCellEditor(row, column);
}
 
Example 3
Project: QN-ACTR-Release   File: AllBlockingRegionsPanel.java   View source code 6 votes vote down vote up
/**
 * Returns an appropriate editor for the cell specified by
 * <code>row</code> and <code>column</code>. If the
 * <code>TableColumn</code> for this column has a non-null editor,
 * returns that.  If not, finds the class of the data in this
 * column (using <code>getColumnClass</code>)
 * and returns the default editor for this type of data.
 *
 * @param row    the row of the cell to edit, where 0 is the first row
 * @param column the column of the cell to edit,
 *               where 0 is the first column
 * @return the editor for this cell;
 *         if <code>null</code> return the default editor for
 *         this type of cell
 */
@Override
public TableCellEditor getCellEditor(int row, int column) {
	switch (column) {
		case 0:
			return new BlockingTableEditor();
		case 1:
			return super.getDefaultEditor(String.class);
		case 2:
			return super.getDefaultEditor(Boolean.class);
		case 3:
			return new ButtonCellEditor(delete);
		default:
			return null;
	}
}
 
Example 4
Project: QN-ACTR-Release   File: ImagedComboBoxCellEditorFactory.java   View source code 6 votes vote down vote up
/**
 * Returns an instance of editor, given search key for elements to be shown
 * @param data vector with search's key for elements to be shown
 */
public TableCellEditor getEditor(List data) {
	if (editor == null) {
		editor = new ImagedComboEditor();
	}
	LabelRenderer[] rend;
	if (allowsNull) {
		rend = new LabelRenderer[data.size() + 1];
		rend[0] = getDrawComponent(null);
		for (int i = 1; i < rend.length; i++) {
			rend[i] = getDrawComponent(data.get(i - 1));
		}
	} else {
		rend = new LabelRenderer[data.size()];
		for (int i = 0; i < data.size(); i++) {
			rend[i] = getDrawComponent(data.get(i));
		}
	}
	editor.setData(rend);
	return editor;
}
 
Example 5
Project: openjdk-jdk10   File: OldJTable.java   View source code 6 votes vote down vote up
public TableColumn addColumn(Object columnIdentifier, int width,
                             TableCellRenderer renderer,
                             TableCellEditor editor, List columnData) {
    checkDefaultTableModel();

    // Set up the model side first
    DefaultTableModel m = (DefaultTableModel)getModel();
    m.addColumn(columnIdentifier, columnData.toArray());

    // The column will have been added to the end, so the index of the
    // column in the model is the last element.
    TableColumn newColumn = new TableColumn(
            m.getColumnCount()-1, width, renderer, editor);
    super.addColumn(newColumn);
    return newColumn;
}
 
Example 6
Project: AgentWorkbench   File: ComponentTypeDialog.java   View source code 6 votes vote down vote up
/**
 * Rename domain in components.
 *
 * @param oldDomainName the old domain name
 * @param newDomainName the new domain name
 */
public void renameDomainInComponents(String oldDomainName, String newDomainName) {
	
	DefaultTableModel dtmComponents = this.getTableModel4ComponentTypes();
	int column = getColumnHeaderIndexComponents(COL_Domain);
	
	// --- Get the component type definitions from table ----
	JTable jtComponents = this.getJTable4ComponentTypes();
	// --- Confirm, apply changes in table ------------------						
	TableCellEditor tceComponents = jtComponents.getCellEditor();
	if (tceComponents!=null) {
		tceComponents.stopCellEditing();
	}
	for(int row=0; row<dtmComponents.getRowCount(); row++){
		String currValue = (String) dtmComponents.getValueAt(row, column);
		if (currValue.equals(oldDomainName)) {
			dtmComponents.setValueAt(newDomainName, row, column);	
		}
	}
	this.setTableCellEditor4DomainsInComponents(null);
}
 
Example 7
Project: jmt   File: ImagedComboBoxCellEditorFactory.java   View source code 6 votes vote down vote up
/**
 * Returns an instance of editor, given search key for elements to be shown
 * @param data array with search's key for elements to be shown
 */
public TableCellEditor getEditor(Object[] data) {
	if (editor == null) {
		editor = new ImagedComboEditor();
	}
	LabelRenderer[] rend;
	if (allowsNull) {
		rend = new LabelRenderer[data.length + 1];
		rend[0] = getDrawComponent(null);
		for (int i = 1; i < rend.length; i++) {
			rend[i] = getDrawComponent(data[i - 1]);
		}
	} else {
		rend = new LabelRenderer[data.length];
		for (int i = 0; i < data.length; i++) {
			rend[i] = getDrawComponent(data[i]);
		}
	}
	editor.setData(rend);
	return editor;
}
 
Example 8
Project: jdk8u-jdk   File: XMBeanAttributes.java   View source code 6 votes vote down vote up
@Override
public final boolean editCellAt(final int row, final int column, EventObject e) {
    if (LOGGER.isLoggable(Level.FINER)) {
        LOGGER.finer("editCellAt(row="+row+", col="+column+
                ", e="+e+")");
    }
    if (JConsole.isDebug()) {
        System.err.println("edit: "+getValueName(row)+"="+getValue(row));
    }
    boolean retVal = super.editCellAt(row, column, e);
    if (retVal) {
        final TableCellEditor tableCellEditor =
                getColumnModel().getColumn(column).getCellEditor();
        if (tableCellEditor == valueCellEditor) {
            ((JComponent) tableCellEditor).requestFocus();
        }
    }
    return retVal;
}
 
Example 9
Project: rapidminer   File: EditableTableHeader.java   View source code 6 votes vote down vote up
public void removeEditor() {
	TableCellEditor editor = getCellEditor();
	if (editor != null) {
		editor.removeCellEditorListener(this);

		requestFocus();
		remove(editorComp);

		int index = getEditingColumn();
		Rectangle cellRect = getHeaderRect(index);

		setCellEditor(null);
		setEditingColumn(-1);
		editorComp = null;

		repaint(cellRect);
	}
}
 
Example 10
Project: Pogamut3   File: VariableTable.java   View source code 6 votes vote down vote up
public void editingStopped(ChangeEvent e) {
    synchronized(mutex) {
        if (recursion) return;
        recursion = true;
    }
    try {
        // Take in the new value
        TableCellEditor editor = getCellEditor();
        if (editor != null) {
            editor.stopCellEditing();
            Object value = editor.getCellEditorValue();
            setValueAt(value, editingRow, editingColumn);
            removeEditor();
        }
    } finally {
        recursion = false;
    }
}
 
Example 11
Project: jmt   File: GraphPanel.java   View source code 6 votes vote down vote up
/**
 * Returns an appropriate editor for the cell specified by
 * <code>row</code> and <code>column</code>. If the
 * <code>TableColumn</code> for this column has a non-null editor,
 * returns that.  If not, finds the class of the data in this
 * column (using <code>getColumnClass</code>)
 * and returns the default editor for this type of data.
 * <p/>
 *
 * @param row    the row of the cell to edit, where 0 is the first row
 * @param column the column of the cell to edit,
 *               where 0 is the first column
 * @return the editor for this cell;
 *         if <code>null</code> return the default editor for
 *         this type of cell
 * @see javax.swing.DefaultCellEditor
 */
@Override
public TableCellEditor getCellEditor(int row, int column) {
	LinesTableColumn columnType = getColumnType(column);
	switch (columnType) {
		case CLASS:
			return classEditor;
		case STATION:
			if (currentIndex.equals(ExactConstants.INDICES_TYPES[3])) {
				return uStationsEditor;
			} else {
				return stationsEditor;
			}
		case ALGORITHM:
			return algorithmEditor;
	}
	return null;
}
 
Example 12
Project: JavaGraph   File: PropertiesDialog.java   View source code 6 votes vote down vote up
/**
 * Lazily creates and returns a button labelled OK that signals the editors
 * to stop editing. This makes sure that any partially edited result is not
 * lost.
 */
JButton getOkButton() {
    if (this.okButton == null) {
        this.okButton = new JButton("OK");
        this.okButton.addActionListener(new CloseListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                TableCellEditor editor = getInnerTable().getCellEditor();
                if (editor == null || editor.stopCellEditing()) {
                    super.actionPerformed(e);
                }
            }
        });
    }
    return this.okButton;
}
 
Example 13
Project: Cognizant-Intelligent-Test-Scripter   File: TestsetComponent.java   View source code 6 votes vote down vote up
public TestsetComponent(TestExecution testExecution) {
    this.testExecution = testExecution;
    testSetTable = new XTable() {

        @Override
        public Component prepareEditor(TableCellEditor editor, int row, int column) {
            Component c = super.prepareEditor(editor, row, column);
            if (c instanceof JCheckBox) {
                JCheckBox b = (JCheckBox) c;
                b.setBackground(getSelectionBackground());
                b.setBorderPainted(true);
            }
            return c;
        }

    };
    toolBar = new TestSetToolBar(this);
    validator = new TestSetValidator(testSetTable);
    popupMenu = new TestSetPopupMenu(this);
    quickSettings = new QuickSettings(this);
    executePopupMenu = new ExecutePopupMenu();
    init();
}
 
Example 14
Project: jmt   File: AllBlockingRegionsPanel.java   View source code 6 votes vote down vote up
/**
 * Returns an appropriate editor for the cell specified by
 * <code>row</code> and <code>column</code>. If the
 * <code>TableColumn</code> for this column has a non-null editor,
 * returns that.  If not, finds the class of the data in this
 * column (using <code>getColumnClass</code>)
 * and returns the default editor for this type of data.
 *
 * @param row    the row of the cell to edit, where 0 is the first row
 * @param column the column of the cell to edit,
 *               where 0 is the first column
 * @return the editor for this cell;
 *         if <code>null</code> return the default editor for
 *         this type of cell
 */
@Override
public TableCellEditor getCellEditor(int row, int column) {
	switch (column) {
		case 0:
			return new BlockingTableEditor();
		case 1:
			return super.getDefaultEditor(String.class);
		case 2:
			return super.getDefaultEditor(Boolean.class);
		case 3:
			return super.getDefaultEditor(String.class);
		case 4:
			return super.getDefaultEditor(Boolean.class);
		case 5:
			return super.getDefaultEditor(String.class);
		case 6:
			return super.getDefaultEditor(Boolean.class);
		case 7:
			return new ButtonCellEditor(delete);
		default:
			return null;
	}
}
 
Example 15
Project: jmt   File: ClassesPanel.java   View source code 6 votes vote down vote up
@Override
public TableCellEditor getCellEditor(int row, int column) {
	if (column == 1) {
		return comboEditor.getEditor(classTypes);
	} else if (column == 5) {
		if (getValueAt(row, 4) != null) {
			return new ButtonCellEditor(new JButton(editDistribution));
		} else {
			return getDefaultEditor(String.class);
		}
	} else if (column == 6) {
		return new ButtonCellEditor(new JButton(deleteClass));
	} else {
		return getDefaultEditor(getModel().getColumnClass(column));
	}
}
 
Example 16
Project: ramus   File: TableCellEditorFactory.java   View source code 6 votes vote down vote up
private TableCellEditor createBaseQualifierEditor() {
    List<Qualifier> qualifiers = engine.getQualifiers();
    Collections.sort(qualifiers, new Comparator<Qualifier>() {
        @Override
        public int compare(Qualifier o1, Qualifier o2) {
            return collator.compare(o1.getName(), o2.getName());
        }
    });

    JComboBox box = new JComboBox();

    box.addItem(null);
    for (Qualifier qualifier : qualifiers)
        box.addItem(qualifier);

    return new DefaultCellEditor(box);
}
 
Example 17
Project: jmt   File: InputSectionPanel.java   View source code 5 votes vote down vote up
@Override
public TableCellEditor getCellEditor(int row, int column) {
	if (column == 1) {
		if (data.getStationType(stationKey).equals(STATION_TYPE_SERVER)) {
			if (data.getStationQueueStrategy(stationKey).equals(STATION_QUEUE_STRATEGY_PREEMPTIVE)) {
				return ComboBoxCellEditor.getEditorInstance(serverPreemptiveQueuePolicies);
			} else {
				return ComboBoxCellEditor.getEditorInstance(serverNonPreemptiveQueuePolicies);
			}
		} else {
			return ComboBoxCellEditor.getEditorInstance(otherNonPreemptiveQueuePolicies);
		}
	} else if (column == 2) {
		return ComboBoxCellEditor.getEditorInstance(dropRules);
	} else {
		return super.getCellEditor(row, column);
	}
}
 
Example 18
Project: incubator-netbeans   File: TreeTable.java   View source code 5 votes vote down vote up
@Override
public TableCellEditor getDefaultEditor(Class columnClass) {
    if (!edCreated && (columnClass == TreeTableModelAdapter.class)) {
        //Creating this editor in the constructor can take > 100ms even
        //on a very fast machine, so do it lazily here to improve 
        //performance of creating a TreeTable
        setDefaultEditor(TreeTableModelAdapter.class, new TreeTableCellEditor());
        edCreated = true;
    }

    return super.getDefaultEditor(columnClass);
}
 
Example 19
Project: incubator-netbeans   File: SheetTable.java   View source code 5 votes vote down vote up
/** Returns a reference to the static editor shared among all instances
 * of SheetTable */
@Override
public TableCellEditor getCellEditor(int row, int column) {
    if( 0 == column ) {
        TableCellEditor res = getCustomEditor( row );
        if( null != res )
            return res;
    }

    return getEditor();
}
 
Example 20
Project: incubator-netbeans   File: EditablePropertyDisplayer.java   View source code 5 votes vote down vote up
private void cancelEditor() {
    if (getInplaceEditor() != null) {
        java.awt.Container parent = getParent();
        while (parent != null && !(parent instanceof javax.swing.JTable)) {
            parent = parent.getParent();
        }
        if (parent != null) {
            TableCellEditor tce = ((javax.swing.JTable) parent).getCellEditor();
            if (tce != null) {
                tce.cancelCellEditing();
            }
        }
    }
}
 
Example 21
Project: QN-ACTR-Release   File: MeasurePanel.java   View source code 5 votes vote down vote up
/**
 * called by the Wizard before when switching to another panel
 */
@Override
public void lostFocus() {
	// Aborts editing of table
	TableCellEditor editor = measureTable.getCellEditor();
	if (editor != null) {
		editor.stopCellEditing();
	}
}
 
Example 22
Project: jmt   File: TimingSectionPanel.java   View source code 5 votes vote down vote up
@Override
public TableCellEditor getCellEditor(int row, int column) {
	if (column == 3) {
		return ComboBoxCellEditor.getEditorInstance(timingStrategies);
	} else if (column == 5) {
		return distributionEditor;
	} else if (column == 8) {
		return deleteEditor;
	} else {
		return super.getCellEditor(row, column);
	}
}
 
Example 23
Project: Logisim   File: AttrTable.java   View source code 5 votes vote down vote up
void setAttrTableModel(AttrTableModel value) {
	if (attrModel != value) {
		TableCellEditor editor = table.getCellEditor();
		if (editor != null) {
			editor.cancelCellEditing();
		}
		attrModel.removeAttrTableModelListener(this);
		attrModel = value;
		attrModel.addAttrTableModelListener(this);
		fireTableChanged();
	}
}
 
Example 24
Project: ramus   File: TableCellEditorFactory.java   View source code 5 votes vote down vote up
private TableCellEditor createFontTypeEditor() {
    JComboBox box = new JComboBox();
    box.addItem(null);
    box.addItem(BOLD);
    box.addItem(ITALIC);
    box.addItem(BOLD_ITALIC);

    return new DefaultCellEditor(box);
}
 
Example 25
Project: openjdk-jdk10   File: XMBeanAttributes.java   View source code 5 votes vote down vote up
public void cancelCellEditing() {
    if (LOGGER.isLoggable(Level.TRACE)) {
        LOGGER.log(Level.TRACE, "Cancel Editing Row: "+getEditingRow());
    }
    final TableCellEditor tableCellEditor = getCellEditor();
    if (tableCellEditor != null) {
        tableCellEditor.cancelCellEditing();
    }
}
 
Example 26
Project: incubator-netbeans   File: DelegatingCellEditor.java   View source code 5 votes vote down vote up
@Override
public Object getCellEditorValue() {
    if (currentEditor != null) {
        return currentEditor.getCellEditorValue();
    }
    if (canceledEditorRef != null) {
        TableCellEditor canceledEditor = canceledEditorRef.get();
        if (canceledEditor != null) {
            return canceledEditor.getCellEditorValue();
        }
    }
    Exceptions.printStackTrace(new IllegalStateException("No current editor."));
    return null;
}
 
Example 27
Project: incubator-netbeans   File: DelegatingCellEditor.java   View source code 5 votes vote down vote up
@Override
public boolean isCellEditable(EventObject anEvent) {
    if (!(anEvent.getSource() instanceof Outline)) {
        return false;
    }
    Outline outline = (Outline) anEvent.getSource();
    int row;
    if (anEvent instanceof MouseEvent) {
        MouseEvent event = (MouseEvent) anEvent;
        Point p = event.getPoint();
        // Locate the editor under the event location
        //int column = outline.columnAtPoint(p);
        row = outline.rowAtPoint(p);
    } else {
        row = outline.getSelectedRow();
    }
    Node n = DelegatingCellRenderer.getNodeAt(outline, row);
    if (n instanceof TreeModelNode) {
        TreeModelNode tmn = (TreeModelNode) n;
        TableRendererModel trm = tmn.getModel();
        try {
            boolean canEdit = trm.canEditCell(tmn.getObject(), columnID);
            if (canEdit) {
                TableCellEditor tce = trm.getCellEditor(tmn.getObject(), columnID);
                canEdit = tce.isCellEditable(anEvent);
                return canEdit;
            }
        } catch (UnknownTypeException ex) {
        }
    }
    return defaultEditor.isCellEditable(anEvent);
}
 
Example 28
Project: incubator-netbeans   File: DelegatingCellEditor.java   View source code 5 votes vote down vote up
@Override
public boolean shouldSelectCell(EventObject anEvent) {
    if (!(anEvent.getSource() instanceof Outline)) {
        return false;
    }
    Outline outline = (Outline) anEvent.getSource();
    if (!(anEvent instanceof MouseEvent)) {
        return false;
    }
    MouseEvent event = (MouseEvent) anEvent;
    Point p = event.getPoint();

    // Locate the editor under the event location
    //int column = outline.columnAtPoint(p);
    int row = outline.rowAtPoint(p);
    Node n = DelegatingCellRenderer.getNodeAt(outline, row);
    if (n instanceof TreeModelNode) {
        TreeModelNode tmn = (TreeModelNode) n;
        TableRendererModel trm = tmn.getModel();
        try {
            if (trm.canEditCell(tmn.getObject(), columnID)) {
                TableCellEditor editor = trm.getCellEditor(tmn.getObject(), columnID);
                if (editor != null) {
                    return editor.shouldSelectCell(anEvent);
                }
            }
        } catch (UnknownTypeException ex) {
        }
    }
    return defaultEditor.shouldSelectCell(anEvent);
}
 
Example 29
Project: incubator-netbeans   File: DelegatingCellEditor.java   View source code 5 votes vote down vote up
@Override
public void cancelCellEditing() {
    if (currentEditor != null) {
        currentEditor.cancelCellEditing();
        canceledEditorRef = new WeakReference<TableCellEditor>(currentEditor);
        currentEditor = null;
        return ;
    }
}
 
Example 30
Project: jmt   File: LDStrategyEditor.java   View source code 5 votes vote down vote up
@Override
public TableCellEditor getCellEditor(int row, int column) {
	if (column == 2) {
		return distributionEditor;
	} else if (column == 5) {
		return new ButtonCellEditor(new JButton(deleteRange));
	} else {
		return super.getCellEditor(row, column);
	}
}
 
Example 31
Project: jmt   File: BlockingRegionGroupPanel.java   View source code 5 votes vote down vote up
@Override
public TableCellEditor getCellEditor(int row, int column) {
	if (column == 5) {
		return new ButtonCellEditor(new JButton(editMemberClasses));
	} else if (column == 6) {
		return new ButtonCellEditor(new JButton(deleteGroup));
	} else {
		return super.getCellEditor(row, column);
	}
}
 
Example 32
Project: incubator-netbeans   File: Models.java   View source code 5 votes vote down vote up
@Override
public TableCellEditor getCellEditor(Object node, String columnID) throws UnknownTypeException {
    if (tableRendererModel != null) {
        return tableRendererModel.getCellEditor(node, columnID);
    } else {
        return null;
    }
}
 
Example 33
Project: QN-ACTR-Release   File: InputSectionPanel.java   View source code 5 votes vote down vote up
/**
 * called by the Wizard before when switching to another panel
 */
@Override
public void lostFocus() {
	// Aborts editing of table
	TableCellEditor editor = queueTable.getCellEditor();
	if (editor != null) {
		editor.stopCellEditing();
	}
}
 
Example 34
Project: incubator-netbeans   File: TableRendererTest.java   View source code 5 votes vote down vote up
@Override
public TableCellEditor getCellEditor(Object node, String columnID) throws UnknownTypeException {
    if (!(Integer.parseInt((String) node) % 3 == 0)) {
        throw new IllegalStateException("Trying to get editor even if we can not provide it node = "+node);
    }
    return new CellEditorImpl(node, columnID);
}
 
Example 35
Project: incubator-netbeans   File: ProfilerTable.java   View source code 5 votes vote down vote up
public Component prepareEditor(TableCellEditor editor, int row, int column) {
    Component c = super.prepareEditor(editor, row, column);
    
    c.setForeground(getSelectionForeground());
    c.setBackground(getSelectionBackground());
    
    return c;
}
 
Example 36
Project: Logisim   File: AttrTable.java   View source code 5 votes vote down vote up
@Override
public void attrValueChanged(AttrTableModelEvent e) {
	if (e.getSource() != attrModel) {
		attrModel.removeAttrTableModelListener(this);
		return;
	}
	int row = e.getRowIndex();
	TableCellEditor ed = table.getCellEditor();
	if (row >= 0 && ed instanceof CellEditor && attrModel.getRow(row) == ((CellEditor) ed).currentRow) {
		ed.cancelCellEditing();
	}
	fireTableChanged();
}
 
Example 37
Project: incubator-netbeans   File: FmtImports.java   View source code 5 votes vote down vote up
private void removeStarImportPackageButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeStarImportPackageButtonActionPerformed
    int row = starImportPackagesTable.getSelectedRow();
    if (row >= 0) {
        TableCellEditor cellEditor = starImportPackagesTable.getCellEditor();
        if (cellEditor != null)
            cellEditor.cancelCellEditing();
        ((DefaultTableModel)starImportPackagesTable.getModel()).removeRow(row);
    }
}
 
Example 38
Project: QN-ACTR-Release   File: ClassesPanel.java   View source code 5 votes vote down vote up
@Override
public TableCellEditor getCellEditor(int row, int column) {
	if (column == 1) {
		return comboEditor.getEditor(classTypes);
	} else if (column == 5 && getValueAt(row, column - 1) != null) {
		return new ButtonCellEditor(new JButton(editDistribution));
	} else if (column == 6) {
		return new ButtonCellEditor(new JButton(deleteClass));
	} else {
		return super.getCellEditor(row, column);
	}
}
 
Example 39
Project: jmt   File: InputSectionPanel.java   View source code 5 votes vote down vote up
private void setQueueLength() {
	if (infiniteQueueSelector.isSelected()) {
		queueLengthSpinner.setEnabled(false);
		data.setStationQueueCapacity(stationKey, new Integer(-1));
		TableCellEditor editor = queueTable.getCellEditor();
		if (editor != null) {
			editor.cancelCellEditing();
		}
		queueTable.repaint();
	} else {
		queueLengthSpinner.setEnabled(true);
		data.setStationQueueCapacity(stationKey, (Integer) queueLengthSpinner.getValue());
		queueTable.repaint();
	}
}
 
Example 40
Project: AgentWorkbench   File: ComponentTypeDialog.java   View source code 5 votes vote down vote up
/**
 * Registers the escape key stroke in order to close this dialog.
 */
private void registerEscapeKeyStroke() {
	final ComponentTypeDialog compTypeDialog = this;
	final ActionListener listener = new ActionListener() {
        public final void actionPerformed(final ActionEvent ae) {
        	// --- Stop cell editing, if required ----- 
        	TableCellEditor editor = getJTable4DomainTypes().getCellEditor();
if (editor!=null)  {
	editor.stopCellEditing();
	return;
}
editor = getJTable4ComponentTypes().getCellEditor();
if (editor!=null)  {
	editor.stopCellEditing();
	return;
}
        	
        	// --- Close dialog -----------------------
String title = Language.translate("Schlie├čen") + " ?";
String message = Language.translate("Dialog schlie├čen") + " ?";
if (JOptionPane.showConfirmDialog(compTypeDialog, message, title, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE)==JOptionPane.YES_OPTION) {
	canceled = true;
 			setVisible(false);	
}
        }
    };
    final KeyStroke keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, true);
    this.getRootPane().registerKeyboardAction(listener, keyStroke, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
}