use of javax.swing.DefaultCellEditor in project micro-manager by micro-manager.
the class ParametersTable method createTable.
private void createTable(DefaultTableModel model) {
table = new JTable(model) {
private static final long serialVersionUID = 1L;
@Override
public TableCellRenderer getCellRenderer(int row, int column) {
switch(column) {
case 0:
return new BoldTableCellRenderer();
case 1:
String s = (String) table.getValueAt(row, 0);
if (uiparameterSet_.get(s).getType().equals(UIParameter.UIParameterType.COLOR)) {
// if Color parameter
return new IconTableCellRenderer();
} else if (uiparameterSet_.get(s).getType().equals(UIParameter.UIParameterType.BOOL)) {
// if checkbox
return super.getDefaultRenderer(Boolean.class);
} else {
return new DefaultTableCellRenderer();
}
default:
return super.getCellRenderer(row, column);
}
}
@Override
public TableCellEditor getCellEditor(int row, int column) {
switch(column) {
case 0:
return super.getCellEditor(row, column);
case 1:
String s = (String) table.getValueAt(row, 0);
if (uiparameterSet_.get(s).getType().equals(UIParameter.UIParameterType.COLOR)) {
return new DefaultCellEditor(color);
} else if (uiparameterSet_.get(s) instanceof ComboUIParameter) {
return new DefaultCellEditor(new JComboBox<String>(((ComboUIParameter) uiparameterSet_.get(s)).getComboValues()));
} else if (uiparameterSet_.get(s).getType().equals(UIParameter.UIParameterType.BOOL)) {
return super.getDefaultEditor(Boolean.class);
} else if (uiparameterSet_.get(s).getType().equals(UIParameter.UIParameterType.UIPROPERTY)) {
return new DefaultCellEditor(new JComboBox<String>(getAvailableProperties((UIPropertyParameter) uiparameterSet_.get(s))));
} else {
return new DefaultCellEditor(new JTextField());
}
default:
return super.getCellEditor(row, column);
}
}
@Override
public boolean isCellEditable(int row, int col) {
// only second column is editable
if (col < 1) {
return false;
} else {
return true;
}
}
};
table.setAutoCreateRowSorter(false);
table.setRowHeight(23);
table.addMouseListener(new java.awt.event.MouseAdapter() {
@Override
public void mouseClicked(java.awt.event.MouseEvent evt) {
int row = table.rowAtPoint(evt.getPoint());
updateHelper(row);
}
});
}
use of javax.swing.DefaultCellEditor in project KaroToolsCollection by ultimate.
the class SummaryScreen method initTable.
private void initTable(final JTable table) {
table.setRowHeight(20);
TableColumn col;
for (int i = 0; i < table.getColumnCount(); i++) {
col = table.getColumnModel().getColumn(i);
col.setPreferredWidth(this.model.getColumnWidth(i));
if (table.getColumnClass(i).equals(Integer.class)) {
col.setCellEditor(new SpinnerCellEditor(new SpinnerNumberModel(2, 0, Integer.MAX_VALUE, 1)));
} else if (table.getColumnClass(i).equals(EnumGameTC.class)) {
col.setCellEditor(new DefaultCellEditor(new JComboBox<Label<EnumGameTC>>(new GenericEnumModel<EnumGameTC>(EnumGameTC.class, EnumGameTC.free, false))));
} else if (table.getColumnClass(i).equals(EnumGameDirection.class)) {
col.setCellEditor(new DefaultCellEditor(new JComboBox<Label<EnumGameDirection>>(new GenericEnumModel<EnumGameDirection>(EnumGameDirection.class, EnumGameDirection.free, false))));
} else if (table.getColumnClass(i).equals(Map.class)) {
Map[] maps = karoAPICache.getMaps().toArray(new Map[0]);
col.setCellEditor(new DefaultCellEditor(new JComboBox<Map>(new DefaultComboBoxModel<Map>(maps))));
} else if (table.getColumnClass(i).equals(User.class)) {
UserCellEditor editor = new UserCellEditor(this.gui, this.model, karoAPICache);
col.setCellEditor(editor);
col.setCellRenderer(editor);
}
}
// Batch-Update-Support
table.getTableHeader().addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
int col = table.columnAtPoint(e.getPoint());
if (// Title
col == 0)
batchUpdateString(col, Language.getString("screen.summary.table.name"), Language.getString("screen.summary.batchUpdate.note.name"));
else if (// Map
col == 1)
batchUpdateSelection(col, Language.getString("screen.summary.table.map"), new DefaultComboBoxModel<Map>(karoAPICache.getMaps().toArray(new Map[0])));
else if (// Players
col == 2)
batchUpdatePlayers(col, Language.getString("screen.summary.table.players"));
else if (// ZZZ
col == 3)
batchUpdateInt(col, Language.getString("screen.summary.table.zzz"), new SpinnerNumberModel(2, 0, Integer.MAX_VALUE, 1));
else if (// TC
col == 4)
batchUpdateSelection(col, Language.getString("screen.summary.table.crashs"), new GenericEnumModel<EnumGameTC>(EnumGameTC.class, EnumGameTC.free, false));
else if (// CPs
col == 5)
batchUpdateBoolean(col, Language.getString("screen.summary.table.cps"));
else if (// Direction
col == 6)
batchUpdateSelection(col, Language.getString("screen.summary.table.direction"), new GenericEnumModel<EnumGameDirection>(EnumGameDirection.class, EnumGameDirection.free, false));
else if (// Create
col == 7)
batchUpdateBoolean(col, Language.getString("screen.summary.table.createstatus"));
else if (// Leave
col == 8)
batchUpdateBoolean(col, Language.getString("screen.summary.table.leavestatus"));
}
});
for (PlannedGame game : this.gameSeries.getGames()) {
this.model.addRow(game);
}
}
use of javax.swing.DefaultCellEditor in project openhospital-gui by informatici.
the class MovStockMultipleDischarging method getJTable.
private JTable getJTable() {
if (jTableMovements == null) {
model = new JTableModel();
jTableMovements = new JTable(model);
jTableMovements.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
jTableMovements.setRowHeight(24);
jTableMovements.addKeyListener(new KeyListener() {
@Override
public void keyTyped(KeyEvent e) {
}
@Override
public void keyReleased(KeyEvent e) {
}
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_DELETE) {
int row = jTableMovements.getSelectedRow();
model.removeItem(row);
}
}
});
for (int i = 0; i < columnNames.length; i++) {
jTableMovements.getColumnModel().getColumn(i).setCellRenderer(new EnabledTableCellRenderer());
jTableMovements.getColumnModel().getColumn(i).setMinWidth(columnWidth[i]);
if (!columnResizable[i]) {
jTableMovements.getColumnModel().getColumn(i).setResizable(columnResizable[i]);
jTableMovements.getColumnModel().getColumn(i).setMaxWidth(columnWidth[i]);
}
if (!columnVisible[i]) {
jTableMovements.getColumnModel().getColumn(i).setMinWidth(0);
jTableMovements.getColumnModel().getColumn(i).setMaxWidth(0);
jTableMovements.getColumnModel().getColumn(i).setWidth(0);
}
}
TableColumn qtyOptionColumn = jTableMovements.getColumnModel().getColumn(4);
qtyOptionColumn.setCellEditor(new DefaultCellEditor(comboBoxUnits));
comboBoxUnits.setSelectedIndex(optionSelected);
}
return jTableMovements;
}
use of javax.swing.DefaultCellEditor in project opentcs by openTCS.
the class DriverGUI method initCommAdaptersComboBox.
private void initCommAdaptersComboBox(LocalVehicleEntry vehicleEntry, int rowIndex, SingleCellEditor adapterCellEditor) {
final CommAdapterComboBox comboBox = new CommAdapterComboBox();
AttachmentInformation ai;
try {
ai = callWrapper.call(() -> servicePortal.getVehicleService().fetchAttachmentInformation(vehicleEntry.getAttachmentInformation().getVehicleReference()));
} catch (Exception ex) {
LOG.warn("Error fetching attachment information for {}", vehicleEntry.getVehicleName(), ex);
return;
}
ai.getAvailableCommAdapters().forEach(factory -> comboBox.addItem(factory));
// Set the selection to the attached comm adapter, (The vehicle is already attached to a comm
// adapter due to auto attachment on startup.)
comboBox.setSelectedItem(vehicleEntry.getAttachmentInformation().getAttachedCommAdapter());
comboBox.setRenderer(new AdapterFactoryCellRenderer());
comboBox.addPopupMenuListener(new BoundsPopupMenuListener());
comboBox.addItemListener((ItemEvent evt) -> {
if (evt.getStateChange() == ItemEvent.DESELECTED) {
return;
}
// If we selected a comm adapter that's already attached, do nothing.
if (Objects.equals(evt.getItem(), vehicleEntry.getAttachedCommAdapterDescription())) {
LOG.debug("{} is already attached to: {}", vehicleEntry.getVehicleName(), evt.getItem());
return;
}
int reply = JOptionPane.showConfirmDialog(null, bundle.getString("driverGui.optionPane_driverChangeConfirmation.message"), bundle.getString("driverGui.optionPane_driverChangeConfirmation.title"), JOptionPane.YES_NO_OPTION);
if (reply == JOptionPane.NO_OPTION) {
return;
}
VehicleCommAdapterDescription factory = comboBox.getSelectedItem();
try {
callWrapper.call(() -> servicePortal.getVehicleService().attachCommAdapter(vehicleEntry.getAttachmentInformation().getVehicleReference(), factory));
} catch (Exception ex) {
LOG.warn("Error attaching adapter {} to vehicle {}", factory, vehicleEntry.getVehicleName(), ex);
return;
}
LOG.info("Attaching comm adapter {} to {}", factory, vehicleEntry.getVehicleName());
});
adapterCellEditor.setEditorAt(rowIndex, new DefaultCellEditor(comboBox));
vehicleEntry.addPropertyChangeListener(comboBox);
}
use of javax.swing.DefaultCellEditor in project DSpace by DSpace.
the class PropertiesDialog method createControls.
/**
* Create the controls that are to be displayed in the system.
*
* @return A panel that contains the controls.
*/
protected final JPanel createControls() {
JPanel panel = new JPanel(new BorderLayout());
propertiesTable = new JTable(new PropertiesModel());
((DefaultCellEditor) propertiesTable.getDefaultEditor(String.class)).setClickCountToStart(1);
JScrollPane scrollpane = new JScrollPane(propertiesTable, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
panel.add(scrollpane, BorderLayout.CENTER);
return panel;
}
Aggregations