Search in sources :

Example 1 with IconTableCellRenderer

use of de.embl.rieslab.emu.configuration.ui.utils.IconTableCellRenderer 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);
        }
    });
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) IconTableCellRenderer(de.embl.rieslab.emu.configuration.ui.utils.IconTableCellRenderer) JTextField(javax.swing.JTextField) IconTableCellRenderer(de.embl.rieslab.emu.configuration.ui.utils.IconTableCellRenderer) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) DefaultCellEditor(javax.swing.DefaultCellEditor) JTable(javax.swing.JTable) ComboUIParameter(de.embl.rieslab.emu.ui.uiparameters.ComboUIParameter) TableCellEditor(javax.swing.table.TableCellEditor)

Aggregations

IconTableCellRenderer (de.embl.rieslab.emu.configuration.ui.utils.IconTableCellRenderer)1 ComboUIParameter (de.embl.rieslab.emu.ui.uiparameters.ComboUIParameter)1 DefaultCellEditor (javax.swing.DefaultCellEditor)1 JTable (javax.swing.JTable)1 JTextField (javax.swing.JTextField)1 DefaultTableCellRenderer (javax.swing.table.DefaultTableCellRenderer)1 TableCellEditor (javax.swing.table.TableCellEditor)1 TableCellRenderer (javax.swing.table.TableCellRenderer)1