Package jmri.jmrit.beantable
Class RowComboBoxPanel
- java.lang.Object
-
- javax.swing.AbstractCellEditor
-
- javax.swing.DefaultCellEditor
-
- jmri.jmrit.beantable.RowComboBoxPanel
-
- All Implemented Interfaces:
java.io.Serializable
,javax.swing.CellEditor
,javax.swing.table.TableCellEditor
,javax.swing.table.TableCellRenderer
,javax.swing.tree.TreeCellEditor
- Direct Known Subclasses:
OBlockTableModel.CurveComboBoxPanel
,OBlockTableModel.SpeedComboBoxPanel
,PathTurnoutTableModel.StateComboBoxPanel
,SignalHeadTableModel.AppearanceComboBoxPanel
,SignallingPanel.SignalMastModel.AspectComboBoxPanel
,SignallingPanel.TableModel.StateComboBoxPanel
,SignalMastTableDataModel.AspectComboBoxPanel
public abstract class RowComboBoxPanel extends javax.swing.DefaultCellEditor implements javax.swing.table.TableCellRenderer
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:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.Runnable
comboBoxFocusRequester
To request the focus for the combobox (with SwingUtilities.invokeLater())protected boolean
consumeComboBoxActionEvent
React on action events on the combobox?protected int
currentRow
The current row.protected javax.swing.JPanel
editor
The surrounding panel for the combobox.protected java.lang.Object
prevItem
The previously selected value in the editor.protected javax.swing.JPanel
renderer
The surrounding panel for the combobox.protected java.util.EventObject
startEditingEvent
The event that causes the editing to start.protected javax.swing.JTable
table
The table.protected boolean
tableListenerAdded
Listeners for the table added?
-
Constructor Summary
Constructors Constructor Description RowComboBoxPanel()
RowComboBoxPanel(java.lang.Object[] values)
RowComboBoxPanel(java.lang.Object[] values, javax.swing.ListCellRenderer<?> customRenderer)
Create a new CellEditor and CellRenderer.RowComboBoxPanel(javax.swing.ListCellRenderer<?> customRenderer)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
eventEditorMousePressed()
Open combobox (Editor) when clicked.protected void
eventRowComboBoxActionPerformed(java.lang.Object choice)
Method for our own VALUECOL row specific JComboBox.protected void
eventTableSelectionChanged()
Stop editing if a new row is selected.java.lang.Object
getCellEditorValue()
Get current contents (value) in cell.protected int
getCurrentRow()
protected javax.swing.JComboBox<java.lang.String>
getEditorBox(int row)
protected java.awt.Component
getEditorComponent(javax.swing.JTable table, java.lang.Object value, boolean isSelected, int row, int col)
(Re)build combobox with all allowed state values, select current and add action listener.protected java.awt.Component
getRendererComponent(javax.swing.JTable table, java.lang.Object value, boolean isSelected, boolean hasFocus, int row, int col)
(Re)build combobox with only the active state value.java.awt.Component
getTableCellEditorComponent(javax.swing.JTable table, java.lang.Object value, boolean isSelected, int row, int col)
Create the editor component for the cell and add a listener for changes in the table.java.awt.Component
getTableCellRendererComponent(javax.swing.JTable table, java.lang.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.boolean
isCellEditable(java.util.EventObject evt)
Is the cell editable?void
setItems(java.lang.Object[] items)
Put contents into the combobox.protected void
updateData(int row, boolean isSelected, javax.swing.JTable table)
Refresh contents of editor.-
Methods inherited from class javax.swing.DefaultCellEditor
cancelCellEditing, getClickCountToStart, getComponent, getTreeCellEditorComponent, setClickCountToStart, shouldSelectCell, stopCellEditing
-
Methods inherited from class javax.swing.AbstractCellEditor
addCellEditorListener, fireEditingCanceled, fireEditingStopped, getCellEditorListeners, removeCellEditorListener
-
-
-
-
Field Detail
-
editor
protected javax.swing.JPanel editor
The surrounding panel for the combobox.
-
renderer
protected javax.swing.JPanel renderer
The surrounding panel for the combobox.
-
tableListenerAdded
protected boolean tableListenerAdded
Listeners for the table added?
-
table
protected javax.swing.JTable table
The table.
-
comboBoxFocusRequester
protected java.lang.Runnable comboBoxFocusRequester
To request the focus for the combobox (with SwingUtilities.invokeLater())
-
currentRow
protected int currentRow
The current row.
-
prevItem
protected java.lang.Object prevItem
The previously selected value in the editor.
-
consumeComboBoxActionEvent
protected boolean consumeComboBoxActionEvent
React on action events on the combobox?
-
startEditingEvent
protected java.util.EventObject startEditingEvent
The event that causes the editing to start. We need it to know if we should open the popup automatically.
-
-
Constructor Detail
-
RowComboBoxPanel
public RowComboBoxPanel(java.lang.Object[] values, javax.swing.ListCellRenderer<?> customRenderer)
Create a new CellEditor and CellRenderer.- Parameters:
values
- array (list) of options to displaycustomRenderer
- renderer to display things
-
RowComboBoxPanel
public RowComboBoxPanel(java.lang.Object[] values)
-
RowComboBoxPanel
public RowComboBoxPanel()
-
RowComboBoxPanel
public RowComboBoxPanel(javax.swing.ListCellRenderer<?> customRenderer)
-
-
Method Detail
-
getTableCellEditorComponent
public final java.awt.Component getTableCellEditorComponent(javax.swing.JTable table, java.lang.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:
getTableCellEditorComponent
in interfacejavax.swing.table.TableCellEditor
- Overrides:
getTableCellEditorComponent
in classjavax.swing.DefaultCellEditor
- 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 java.awt.Component getEditorComponent(javax.swing.JTable table, java.lang.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:
getTableCellEditorComponent(JTable, Object, boolean, int, int)
,getEditorBox(int)
-
getTableCellRendererComponent
public final java.awt.Component getTableCellRendererComponent(javax.swing.JTable table, java.lang.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:
getTableCellRendererComponent
in interfacejavax.swing.table.TableCellRenderer
- 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 java.awt.Component getRendererComponent(javax.swing.JTable table, java.lang.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:
getTableCellRendererComponent(JTable, Object, boolean, boolean, int, int)
-
updateData
protected void updateData(int row, boolean isSelected, javax.swing.JTable table)
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:
getTableCellEditorComponent(JTable, Object, boolean, int, int)
-
isCellEditable
public boolean isCellEditable(java.util.EventObject evt)
Is the cell editable? If the mouse was pressed at a margin we don't want the cell to be editable.- Specified by:
isCellEditable
in interfacejavax.swing.CellEditor
- Overrides:
isCellEditable
in classjavax.swing.DefaultCellEditor
- Parameters:
evt
- The event-object- Returns:
- true when user clicked inside cell, not on cell border
-
getCellEditorValue
public java.lang.Object getCellEditorValue()
Get current contents (value) in cell.- Specified by:
getCellEditorValue
in interfacejavax.swing.CellEditor
- Overrides:
getCellEditorValue
in classjavax.swing.DefaultCellEditor
- Returns:
- value (String in 4.6 applications)
-
setItems
public final void setItems(@Nonnull java.lang.Object[] items)
Put contents into the combobox.- Parameters:
items
- array (strings) of options to display
-
eventEditorMousePressed
protected void eventEditorMousePressed()
Open combobox (Editor) when clicked.
-
eventTableSelectionChanged
protected void eventTableSelectionChanged()
Stop editing if a new row is selected.
-
eventRowComboBoxActionPerformed
protected void eventRowComboBoxActionPerformed(@Nonnull java.lang.Object choice)
Method for our own VALUECOL row specific JComboBox.- Parameters:
choice
- the selected item (Aspect/Appearance) in the combobox list
-
getCurrentRow
protected int getCurrentRow()
-
getEditorBox
protected javax.swing.JComboBox<java.lang.String> getEditorBox(int row)
-
-