1 24 package info.monitorenter.gui.chart.events; 25 26 import info.monitorenter.gui.chart.Chart2D; 27 import info.monitorenter.gui.chart.layout.LayoutFactory.PropertyChangeCheckBoxMenuItem; 28 29 import java.awt.Color ; 30 import java.awt.event.ActionEvent ; 31 import java.beans.PropertyChangeEvent ; 32 import java.util.HashMap ; 33 import java.util.Map ; 34 35 import javax.swing.JColorChooser ; 36 37 51 public final class Chart2DActionSetCustomGridColorSingleton extends AChart2DAction { 52 55 private static final long serialVersionUID = 3691034370412916788L; 56 59 private static Map instances = new HashMap (); 60 61 62 private static String key(final Chart2D chart) { 63 return chart.getClass().getName() + chart.hashCode(); 64 } 65 66 85 public static Chart2DActionSetCustomGridColorSingleton getInstance( 86 final Chart2D chart, final String colorName) { 87 Chart2DActionSetCustomGridColorSingleton result = 88 (Chart2DActionSetCustomGridColorSingleton) Chart2DActionSetCustomGridColorSingleton.instances 89 .get(key(chart)); 90 if (result == null) { 91 result = new Chart2DActionSetCustomGridColorSingleton(chart, colorName); 92 Chart2DActionSetCustomGridColorSingleton.instances.put(key(chart), result); 93 } 94 return result; 95 } 96 97 101 private Color m_lastChosenColor; 102 103 116 private Chart2DActionSetCustomGridColorSingleton(final Chart2D chart, final String colorName) { 117 super(chart, colorName); 118 chart.addPropertyChangeListener(Chart2D.PROPERTY_GRID_COLOR, this); 119 } 120 121 124 public void actionPerformed(final ActionEvent e) { 125 Color chosen = JColorChooser.showDialog(this.m_chart, "choose color for " 126 + this.m_chart.getName(), this.m_chart.getGridColor()); 127 this.m_lastChosenColor = chosen; 128 this.m_chart.setGridColor(chosen); 129 } 130 131 134 public void propertyChange(final PropertyChangeEvent evt) { 135 String property = evt.getPropertyName(); 136 if (property.equals(Chart2D.PROPERTY_GRID_COLOR)) { 137 Color newColor = (Color ) evt.getNewValue(); 138 if (newColor.equals(this.m_lastChosenColor)) { 139 this.firePropertyChange(PropertyChangeCheckBoxMenuItem.PROPERTY_SELECTED, 140 new Boolean (false), new Boolean (true)); 141 142 } else { 143 this.firePropertyChange(PropertyChangeCheckBoxMenuItem.PROPERTY_SELECTED, 144 new Boolean (true), new Boolean (false)); 145 } 146 } 147 } 148 } 149 | Popular Tags |