1 23 package info.monitorenter.gui.chart.events; 24 25 import info.monitorenter.gui.chart.Chart2D; 26 import info.monitorenter.gui.chart.layout.LayoutFactory.PropertyChangeCheckBoxMenuItem; 27 28 import java.awt.Color ; 29 import java.awt.event.ActionEvent ; 30 import java.beans.PropertyChangeEvent ; 31 32 import javax.swing.JColorChooser ; 33 import javax.swing.JComponent ; 34 35 45 public final class JComponentActionSetCustomBackground extends AJComponentAction { 46 47 50 private static final long serialVersionUID = 3904680491952451890L; 51 52 56 private Color m_lastChosenColor; 57 58 72 public JComponentActionSetCustomBackground(final JComponent component, final String description) { 73 super(component, description); 74 component.addPropertyChangeListener(Chart2D.PROPERTY_BACKGROUND_COLOR, this); 75 } 76 77 80 public void actionPerformed(final ActionEvent e) { 81 Color chosen = JColorChooser.showDialog(this.m_component, "choose background color for " 82 + this.m_component.getName(), this.m_component.getBackground()); 83 this.m_lastChosenColor = chosen; 84 this.m_component.setBackground(chosen); 85 } 86 87 90 public void propertyChange(final PropertyChangeEvent evt) { 91 String property = evt.getPropertyName(); 92 if (property.equals(Chart2D.PROPERTY_BACKGROUND_COLOR)) { 93 Color newColor = (Color ) evt.getNewValue(); 94 if (newColor.equals(this.m_lastChosenColor)) { 95 this.firePropertyChange(PropertyChangeCheckBoxMenuItem.PROPERTY_SELECTED, 96 new Boolean (false), new Boolean (true)); 97 98 } else { 99 this.firePropertyChange(PropertyChangeCheckBoxMenuItem.PROPERTY_SELECTED, 100 new Boolean (true), new Boolean (false)); 101 } 102 } 103 } 104 } 105 | Popular Tags |