/src/mpv5/utils/renderer/ButtonEditor.java
Java | 66 lines | 53 code | 9 blank | 4 comment | 4 complexity | 227372d55bd84b13a5ef7c7b44c162bb MD5 | raw file
Possible License(s): LGPL-3.0, Apache-2.0, GPL-3.0, GPL-2.0, AGPL-3.0, JSON, BSD-3-Clause
- package mpv5.utils.renderer;
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- import javax.swing.table.*;
- /**
- * Nobuo Tamemasa (http://www2.gol.com/users/tame/swing/examples/JTableExamples1.html)
- * @version 1.0 11/09/98
- */
- public class ButtonEditor extends DefaultCellEditor {
- protected JButton button;
- private String label;
- private boolean isPushed;
- public ButtonEditor(JButton button) {
- super(new JCheckBox());
- setClickCountToStart(1);
- this.button = button;
- button.setOpaque(true);
- button.setMargin(new Insets(0, 0, 0, 0));
- button.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- fireEditingStopped();
- }
- });
- }
- @Override
- public Component getTableCellEditorComponent(JTable table, Object value,
- boolean isSelected, int row, int column) {
- if (isSelected) {
- button.setForeground(table.getSelectionForeground());
- button.setBackground(table.getSelectionBackground());
- } else {
- button.setForeground(table.getForeground());
- button.setBackground(table.getBackground());
- }
- label = (value == null) ? "" : value.toString();
- button.setText(label);
- isPushed = true;
-
- return button;
- }
- @Override
- public Object getCellEditorValue() {
- if (isPushed) {
- }
- isPushed = false;
- return new String(label);
- }
- @Override
- public boolean stopCellEditing() {
- isPushed = false;
- return super.stopCellEditing();
- }
- @Override
- protected void fireEditingStopped() {
- super.fireEditingStopped();
- }
- }