PageRenderTime 82ms CodeModel.GetById 40ms app.highlight 5ms RepoModel.GetById 35ms app.codeStats 1ms

/src/mpv5/utils/renderer/ButtonEditor.java

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/
Java | 66 lines | 53 code | 9 blank | 4 comment | 4 complexity | 227372d55bd84b13a5ef7c7b44c162bb MD5 | raw file
 1package mpv5.utils.renderer;
 2
 3import java.awt.*;
 4import java.awt.event.*;
 5import javax.swing.*;
 6import javax.swing.table.*;
 7
 8/**
 9 * Nobuo Tamemasa (http://www2.gol.com/users/tame/swing/examples/JTableExamples1.html)
10 * @version 1.0 11/09/98
11 */
12public class ButtonEditor extends DefaultCellEditor {
13
14    protected JButton button;
15    private String label;
16    private boolean isPushed;
17
18    public ButtonEditor(JButton button) {
19        super(new JCheckBox());
20        setClickCountToStart(1);
21        this.button = button;
22        button.setOpaque(true);
23        button.setMargin(new Insets(0, 0, 0, 0));
24        button.addActionListener(new ActionListener() {
25            public void actionPerformed(ActionEvent e) {
26                fireEditingStopped();
27            }
28        });
29    }
30
31    @Override
32    public Component getTableCellEditorComponent(JTable table, Object value,
33            boolean isSelected, int row, int column) {
34        if (isSelected) {
35            button.setForeground(table.getSelectionForeground());
36            button.setBackground(table.getSelectionBackground());
37        } else {
38            button.setForeground(table.getForeground());
39            button.setBackground(table.getBackground());
40        }
41        label = (value == null) ? "" : value.toString();
42        button.setText(label);
43        isPushed = true;
44        
45        return button;
46    }
47
48    @Override
49    public Object getCellEditorValue() {
50        if (isPushed) {
51        }
52        isPushed = false;
53        return new String(label);
54    }
55
56    @Override
57    public boolean stopCellEditing() {
58        isPushed = false;
59        return super.stopCellEditing();
60    }
61
62    @Override
63    protected void fireEditingStopped() {
64        super.fireEditingStopped();
65    }
66}