[Mc4j-cvs] mc4j/src/org/mc4j/console/swing/editor ButtonRenderer.java,1.1,1.2 ButtonEditor.java,1.1,
Brought to you by:
ghinkl
From: Greg H. <gh...@us...> - 2006-04-12 19:14:15
|
Update of /cvsroot/mc4j/mc4j/src/org/mc4j/console/swing/editor In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20162/src/org/mc4j/console/swing/editor Added Files: ButtonRenderer.java ButtonEditor.java Log Message: Merging EMS into head for the 2.0 release work --- NEW FILE: ButtonEditor.java --- /* * Copyright 2002-2004 Greg Hinkle * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.mc4j.console.swing.editor; import javax.swing.*; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import java.awt.*; /** * @author Greg Hinkle (gh...@us...), Feb 3, 2005 * @version $Revision: 1.2 $($Author: ghinkl $ / $Date: 2006/04/12 19:14:05 $) */ public class ButtonEditor extends DefaultCellEditor { protected JButton button; private String label; private boolean isPushed; public ButtonEditor(JCheckBox checkBox) { super(checkBox); button = new JButton(); button.setOpaque(true); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { fireEditingStopped(); } }); } 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; } public Object getCellEditorValue() { if (isPushed) { // // JOptionPane.showMessageDialog(button, label + ": Ouch!"); // System.out.println(label + ": Ouch!"); } isPushed = false; return new String(label); } public boolean stopCellEditing() { isPushed = false; return super.stopCellEditing(); } protected void fireEditingStopped() { super.fireEditingStopped(); } } --- NEW FILE: ButtonRenderer.java --- /* * Copyright 2002-2004 Greg Hinkle * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.mc4j.console.swing.editor; import javax.swing.*; import javax.swing.table.TableCellRenderer; import java.awt.*; /** * @author Greg Hinkle (gh...@us...), Feb 3, 2005 * @version $Revision: 1.2 $($Author: ghinkl $ / $Date: 2006/04/12 19:14:05 $) */ public class ButtonRenderer extends JButton implements TableCellRenderer { public ButtonRenderer() { setOpaque(true); } public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { if (isSelected) { setForeground(table.getSelectionForeground()); setBackground(table.getSelectionBackground()); } else { setForeground(table.getForeground()); setBackground(UIManager.getColor("Button.background")); } setText((value == null) ? "" : value.toString()); return this; } } |