001package kiwi.ui.propeditor; 002 003import java.awt.event.*; 004import javax.swing.*; 005 006import kiwi.text.FormatConstants; 007import kiwi.ui.*; 008import kiwi.util.DoubleHolder; 009 010/** 011 * @author Mark Lindner 012 */ 013 014public class NumericValueEditor extends PropertyValueEditor 015 { 016 private NumericField field; 017 018 /** 019 */ 020 021 public NumericValueEditor() 022 { 023 field = new NumericField(10, FormatConstants.INTEGER_FORMAT); 024 } 025 026 /** 027 */ 028 029 protected void prepareEditor() 030 { 031 NumericPropertyType type = (NumericPropertyType)property.getType(); 032 field.setType(type.getFormat()); 033 field.clearMinValue(); 034 field.clearMaxValue(); 035 036 if(type.hasMaximumValue()) 037 field.setMaxValue(type.getMaximumValue()); 038 039 if(type.hasMinimumValue()) 040 field.setMinValue(type.getMinimumValue()); 041 042 DoubleHolder holder = (DoubleHolder)property.getValue(); 043 044 if(holder != null) 045 field.setValue(holder.getValue()); 046 else 047 field.setText(null); 048 } 049 050 public void commitInput() 051 { 052 DoubleHolder holder = (DoubleHolder)property.getValue(); 053 if(holder == null) 054 { 055 holder = new DoubleHolder(); 056 property.setValue(holder); 057 } 058 059 holder.setValue(field.getValue()); 060 } 061 062 public boolean validateInput() 063 { 064 return(field.validateInput()); 065 } 066 067 /** 068 */ 069 070 public void addActionListener(ActionListener listener) 071 { 072 field.addActionListener(listener); 073 } 074 075 /** 076 */ 077 078 public void removeActionListener(ActionListener listener) 079 { 080 field.removeActionListener(listener); 081 } 082 083 /** 084 */ 085 086 public JComponent getEditorComponent() 087 { 088 return(field); 089 } 090 091 public void startFocus() 092 { 093 field.requestFocus(); 094 } 095 096} 097 098/* end of source file */