Search in sources :

Example 66 with DefaultCellEditor

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);
        }
    });
}
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)

Example 67 with DefaultCellEditor

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);
    }
}
Also used : GenericEnumModel(ultimate.karomuskel.ui.components.GenericEnumModel) MouseEvent(java.awt.event.MouseEvent) JComboBox(javax.swing.JComboBox) Label(ultimate.karomuskel.ui.Language.Label) JLabel(javax.swing.JLabel) MouseAdapter(java.awt.event.MouseAdapter) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) TableColumn(javax.swing.table.TableColumn) UserCellEditor(ultimate.karomuskel.ui.components.UserCellEditor) DefaultCellEditor(javax.swing.DefaultCellEditor) SpinnerNumberModel(javax.swing.SpinnerNumberModel) EnumGameDirection(ultimate.karoapi4j.enums.EnumGameDirection) EnumGameTC(ultimate.karoapi4j.enums.EnumGameTC) PlannedGame(ultimate.karoapi4j.model.official.PlannedGame) SpinnerCellEditor(ultimate.karomuskel.ui.components.SpinnerCellEditor) Map(ultimate.karoapi4j.model.official.Map)

Example 68 with DefaultCellEditor

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;
}
Also used : KeyEvent(java.awt.event.KeyEvent) JTable(javax.swing.JTable) KeyListener(java.awt.event.KeyListener) TableColumn(javax.swing.table.TableColumn) DefaultCellEditor(javax.swing.DefaultCellEditor)

Example 69 with DefaultCellEditor

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);
}
Also used : ItemEvent(java.awt.event.ItemEvent) VehicleCommAdapterDescription(org.opentcs.drivers.vehicle.VehicleCommAdapterDescription) AttachmentInformation(org.opentcs.drivers.vehicle.management.AttachmentInformation) BoundsPopupMenuListener(org.opentcs.util.gui.BoundsPopupMenuListener) Point(org.opentcs.data.model.Point) DefaultCellEditor(javax.swing.DefaultCellEditor)

Example 70 with DefaultCellEditor

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;
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) BorderLayout(java.awt.BorderLayout) JTable(javax.swing.JTable) DefaultCellEditor(javax.swing.DefaultCellEditor)

Aggregations

DefaultCellEditor (javax.swing.DefaultCellEditor)192 JComboBox (javax.swing.JComboBox)120 JTable (javax.swing.JTable)61 TableColumn (javax.swing.table.TableColumn)61 ArrayList (java.util.ArrayList)47 TableCellEditor (javax.swing.table.TableCellEditor)35 JScrollPane (javax.swing.JScrollPane)33 JPanel (javax.swing.JPanel)26 ActionEvent (java.awt.event.ActionEvent)25 JTextField (javax.swing.JTextField)23 DefaultTableCellRenderer (javax.swing.table.DefaultTableCellRenderer)23 ProxyColumn (us.mn.state.dot.tms.client.proxy.ProxyColumn)23 JLabel (javax.swing.JLabel)22 Component (java.awt.Component)21 DefaultTableModel (javax.swing.table.DefaultTableModel)21 Dimension (java.awt.Dimension)17 ActionListener (java.awt.event.ActionListener)16 JButton (javax.swing.JButton)16 JCheckBox (javax.swing.JCheckBox)16 TableCellRenderer (javax.swing.table.TableCellRenderer)15