19 package org.sleuthkit.autopsy.casemodule;
28 import java.awt.event.*;
30 import javax.swing.border.*;
31 import javax.swing.table.*;
46 class ButtonColumn
extends AbstractCellEditor
47 implements TableCellRenderer, TableCellEditor, ActionListener, MouseListener {
50 private Action action;
52 private Border originalBorder;
53 private Border focusBorder;
55 private JButton renderButton;
56 private JButton editButton;
58 private boolean isButtonColumnEditor;
72 ButtonColumn(JTable table, Action action,
int column, String buttonName) {
75 this.buttonName = buttonName;
77 renderButton =
new JButton();
78 editButton =
new JButton();
79 editButton.setFocusPainted(
false);
80 editButton.addActionListener(
this);
81 originalBorder = editButton.getBorder();
82 setFocusBorder(
new LineBorder(Color.BLUE));
84 TableColumnModel columnModel = table.getColumnModel();
85 columnModel.getColumn(column).setCellRenderer(
this);
86 columnModel.getColumn(column).setCellEditor(
this);
87 table.addMouseListener(
this);
95 public Border getFocusBorder() {
104 public void setFocusBorder(Border focusBorder) {
105 this.focusBorder = focusBorder;
106 editButton.setBorder(focusBorder);
109 public int getMnemonic() {
118 public void setMnemonic(
int mnemonic) {
119 this.mnemonic = mnemonic;
120 renderButton.setMnemonic(mnemonic);
121 editButton.setMnemonic(mnemonic);
125 public Component getTableCellEditorComponent(
126 JTable table, Object value,
boolean isSelected,
int row,
int column) {
127 text = (value == null) ?
"" : value.toString();
128 editButton.setText(text);
133 public Object getCellEditorValue() {
141 public Component getTableCellRendererComponent(
142 JTable table, Object value,
boolean isSelected,
boolean hasFocus,
int row,
int column) {
144 renderButton.setForeground(table.getSelectionForeground());
145 renderButton.setBackground(table.getSelectionBackground());
147 renderButton.setForeground(table.getForeground());
148 renderButton.setBackground(UIManager.getColor(
"Button.background"));
152 renderButton.setBorder(focusBorder);
154 renderButton.setBorder(originalBorder);
158 renderButton.setText(buttonName);
169 public void actionPerformed(ActionEvent e) {
170 int row = table.convertRowIndexToModel(table.getEditingRow());
171 fireEditingStopped();
174 ActionEvent
event =
new ActionEvent(
176 ActionEvent.ACTION_PERFORMED,
178 action.actionPerformed(event);
190 public void mousePressed(MouseEvent e) {
191 if (table.isEditing()
192 && table.getCellEditor() ==
this) {
193 isButtonColumnEditor =
true;
198 public void mouseReleased(MouseEvent e) {
199 if (isButtonColumnEditor
200 && table.isEditing()) {
201 table.getCellEditor().stopCellEditing();
204 isButtonColumnEditor =
false;
208 public void mouseClicked(MouseEvent e) {
212 public void mouseEntered(MouseEvent e) {
216 public void mouseExited(MouseEvent e) {