import java.beans.*; import java.awt.*; import utilities.ConvertKit; public class SineEditor extends PropertyEditorSupport implements PropertyChangeListener { // the GUI that this custom property editor uses protected SineParameters sineParams; //------------------------------------------------------------------- // SineEditor constructor //------------------------------------------------------------------- public SineEditor() { sineParams = new SineParameters(50.0, 1.0, 0.0); sineParams.addPropertyChangeListener(this); } //------------------------------------------------------------------- // overridden PropertyEditor interface methods //------------------------------------------------------------------- public void setValue(Object value) { sineParams.setSineParameters((SineParameters)value); } public Object getValue() { return sineParams; } public boolean supportsCustomEditor() { // yes we do ! return true; } public Component getCustomEditor() { return sineParams; } public boolean isPaintable() { return true; } //------------------------------------------------------------------- // paintValue() is called inside the tool's paint() method to repaint // a property sheet window containing property values. //------------------------------------------------------------------- public void paintValue(Graphics g, Rectangle clipRect) { Rectangle rect = clipRect; int zeroLine = rect.height/2; g.translate(rect.x, rect.y); g.drawRect(0,0, rect.width-1, rect.height-1); double frequency = sineParams.getFrequency(); double phase = sineParams.getPhase(); phase = ConvertKit.toRadians(phase); for (int x=2; x < rect.width-1; x+=2) { double phi = ((double)x) / rect.width*2*Math.PI; double sin = Math.sin(frequency*phi + phase); int y = zeroLine + (int)(sin*rect.height/2); g.drawLine(x-2,zeroLine, x,y); } } //------------------------------------------------------------------- // PropertyChangeListener interface. // Here we (the editor) receive notifications from the SineParameters that some // sine function parameter has changed, so we pass this fact on to our own listener. //------------------------------------------------------------------- public void propertyChange(PropertyChangeEvent evt) { firePropertyChange(); } } // End of Class SineEditor