Package jmri.jmrit.beantable
Class RowComboBoxPanel
java.lang.Object
javax.swing.AbstractCellEditor
javax.swing.DefaultCellEditor
jmri.jmrit.beantable.RowComboBoxPanel
- All Implemented Interfaces:
Serializable,CellEditor,TableCellEditor,TableCellRenderer,TreeCellEditor
- Direct Known Subclasses:
OBlockTableModel.CurveComboBoxPanel,OBlockTableModel.SpeedComboBoxPanel,PathTurnoutTableModel.StateComboBoxPanel,SignalHeadTableModel.AppearanceComboBoxPanel,SignallingPanel.SignalMastModel.AspectComboBoxPanel,SignallingPanel.TableModel.StateComboBoxPanel,SignalMastTableDataModel.AspectComboBoxPanel
Table cell editor abstract class with a custom ComboBox per row as the editing component.
Used as TableCellRenderer in SignalMast JTable, declared in ConfigValueColumn() Based on: http://alvinalexander.com/java/jwarehouse/netbeans-src/monitor/src/org/netbeans/modules/web/monitor/client/ComboBoxTableCellEditor.java.shtml
- Since:
- 4.7.1
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.DefaultCellEditor
DefaultCellEditor.EditorDelegate -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected RunnableTo request the focus for the combobox (with SwingUtilities.invokeLater())protected booleanReact on action events on the combobox?protected intThe current row.protected JPanelThe surrounding panel for the combobox.protected ObjectThe previously selected value in the editor.protected JPanelThe surrounding panel for the combobox.protected EventObjectThe event that causes the editing to start.protected JTableThe table.protected booleanListeners for the table added?Fields inherited from class javax.swing.DefaultCellEditor
clickCountToStart, delegate, editorComponentFields inherited from class javax.swing.AbstractCellEditor
changeEvent, listenerList -
Constructor Summary
ConstructorsConstructorDescriptionRowComboBoxPanel(Object[] values) RowComboBoxPanel(Object[] values, ListCellRenderer<?> customRenderer) Create a new CellEditor and CellRenderer.RowComboBoxPanel(ListCellRenderer<?> customRenderer) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidOpen combobox (Editor) when clicked.protected voidMethod for our own VALUECOL row specific JComboBox.protected voidStop editing if a new row is selected.Get current contents (value) in cell.protected intgetEditorBox(int row) protected ComponentgetEditorComponent(JTable table, Object value, boolean isSelected, int row, int col) (Re)build combobox with all allowed state values, select current and add action listener.protected ComponentgetRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col) (Re)build combobox with only the active state value.final ComponentgetTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int col) Create the editor component for the cell and add a listener for changes in the table.final ComponentgetTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col) Create the renderer component for the cell and add a listener for changes in the table.booleanIs the cell editable?final voidPut contents into the combobox.protected voidupdateData(int row, boolean isSelected, JTable table) Refresh contents of editor.Methods inherited from class javax.swing.DefaultCellEditor
cancelCellEditing, getClickCountToStart, getComponent, getTreeCellEditorComponent, setClickCountToStart, shouldSelectCell, stopCellEditingMethods inherited from class javax.swing.AbstractCellEditor
addCellEditorListener, fireEditingCanceled, fireEditingStopped, getCellEditorListeners, removeCellEditorListenerMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface javax.swing.CellEditor
addCellEditorListener, removeCellEditorListener
-
Field Details
-
editor
The surrounding panel for the combobox. -
renderer
The surrounding panel for the combobox. -
tableListenerAdded
Listeners for the table added? -
table
The table. -
comboBoxFocusRequester
To request the focus for the combobox (with SwingUtilities.invokeLater()) -
currentRow
The current row. -
prevItem
The previously selected value in the editor. -
consumeComboBoxActionEvent
React on action events on the combobox? -
startEditingEvent
The event that causes the editing to start. We need it to know if we should open the popup automatically.
-
-
Constructor Details
-
RowComboBoxPanel
Create a new CellEditor and CellRenderer.- Parameters:
values- array (list) of options to displaycustomRenderer- renderer to display things
-
RowComboBoxPanel
-
RowComboBoxPanel
public RowComboBoxPanel() -
RowComboBoxPanel
-
-
Method Details
-
getTableCellEditorComponent
public final Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int col) Create the editor component for the cell and add a listener for changes in the table.- Specified by:
getTableCellEditorComponentin interfaceTableCellEditor- Overrides:
getTableCellEditorComponentin classDefaultCellEditor- Parameters:
table- parent JTable of NamedBeanvalue- current value for cell to be rendered.isSelected- tells if this row is selected in the table.row- the row in table.col- the column in table, in this case Value (Aspect or Appearance).- Returns:
- A JPanel containing a JComboBox with valid options as the CellEditor for the Value.
-
getEditorComponent
protected Component getEditorComponent(JTable table, Object value, boolean isSelected, int row, int col) (Re)build combobox with all allowed state values, select current and add action listener.- Parameters:
table- parent JTable of NamedBeanvalue- current value for cell to be rendered.isSelected- tells if this row is selected in the table.row- the row in table.col- the column in table, in this case Value (Aspect or Appearance).- Returns:
- a JPanel containing a JComboBox
- See Also:
-
getTableCellRendererComponent
public final Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col) Create the renderer component for the cell and add a listener for changes in the table.- Specified by:
getTableCellRendererComponentin interfaceTableCellRenderer- Parameters:
table- the parent Table.value- current value for cell to be rendered.isSelected- tells if this row is selected in the table.hasFocus- true if the row has focus.row- the row in table.col- the column in table, in this case Value (Aspect/Appearance).- Returns:
- A JPanel containing a JComboBox with only the current Value as the CellRenderer.
-
getRendererComponent
protected Component getRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col) (Re)build combobox with only the active state value.- Parameters:
table- the parent Table.value- current value for cell to be rendered.isSelected- tells if this row is selected in the table.hasFocus- true if the row has focus.row- the row in table.col- the column in table, in this case Value (Aspect/Appearance).- Returns:
- a JPanel containing a JComboBox
- See Also:
-
updateData
Refresh contents of editor.- Parameters:
row- the row in table.isSelected- tells if this row is selected in the table.table- the parent Table.- See Also:
-
isCellEditable
Is the cell editable? If the mouse was pressed at a margin we don't want the cell to be editable.- Specified by:
isCellEditablein interfaceCellEditor- Overrides:
isCellEditablein classDefaultCellEditor- Parameters:
evt- The event-object- Returns:
- true when user clicked inside cell, not on cell border
-
getCellEditorValue
Get current contents (value) in cell.- Specified by:
getCellEditorValuein interfaceCellEditor- Overrides:
getCellEditorValuein classDefaultCellEditor- Returns:
- value (String in 4.6 applications)
-
setItems
Put contents into the combobox.- Parameters:
items- array (strings) of options to display
-
eventEditorMousePressed
Open combobox (Editor) when clicked. -
eventTableSelectionChanged
Stop editing if a new row is selected. -
eventRowComboBoxActionPerformed
Method for our own VALUECOL row specific JComboBox.- Parameters:
choice- the selected item (Aspect/Appearance) in the combobox list
-
getCurrentRow
-
getEditorBox
-