1 32 33 package it.businesslogic.ireport.gui.sheet; 34 35 import it.businesslogic.ireport.gui.JNumberComboBox; 36 import it.businesslogic.ireport.gui.event.SheetPropertyValueChangedEvent; 37 import it.businesslogic.ireport.gui.event.ValueChangedEvent; 38 import it.businesslogic.ireport.gui.event.ValueChangedListener; 39 import java.util.*; 40 import javax.swing.*; 41 import it.businesslogic.ireport.util.*; 42 43 public class NumberComboBoxSheetProperty extends SheetProperty 44 { 45 46 JNumberComboBox jNumberComboBox=null; 47 48 public NumberComboBoxSheetProperty(String key, String name) { 49 super( key, name, SheetProperty.COMBOBOX); 50 } 51 52 public Object getEditorValue(JComponent component) 53 { 54 return ""+(int)jNumberComboBox.getValue(); 55 } 56 57 public void setValue(Object value) 58 { 59 61 this.value = value; 62 this.setEditorValue(getEditor(), (value == null) ? getDefaultValue() : value); 63 updateLabel(); 64 } 65 66 public void setEditorValue(JComponent component, Object str) 67 { 68 if (str == null || str.equals("")) 69 { 70 str = getDefaultValue(); 71 } 72 if (str == null) str = ""; 73 74 boolean setting = isSetting(); 75 this.setSetting(true); 76 try { 77 ((JComboBox)component).setSelectedItem(str); 78 } catch (Exception ex) { 79 ex.printStackTrace(); 80 } 81 this.setSetting(setting); 82 } 83 84 public void addEntry(String name, int value) 85 { 86 ((JNumberComboBox)getEditor()).addEntry(name, (double)value); 87 } 88 89 public JComponent getEditor() 90 { 91 if (jNumberComboBox != null) return jNumberComboBox; 92 93 jNumberComboBox = new JNumberComboBox(); 94 jNumberComboBox.setEditable(true); 95 96 103 104 jNumberComboBox.setBorder(null); 105 106 122 jNumberComboBox.addItemListener(new java.awt.event.ItemListener () { 123 public void itemStateChanged(java.awt.event.ItemEvent evt) { 124 125 if (evt.getStateChange() == evt.SELECTED) 126 { 127 actionPerformed(null); 128 } 129 } 130 }); 131 jNumberComboBox.addActionListener(this); 132 133 return jNumberComboBox; 134 } 135 136 public void actionPerformed(java.awt.event.ActionEvent event) 137 { 138 if (isSetting()) return; 139 140 142 143 Object new_value = getEditorValue( this.getEditor() ); 144 if (new_value != null && new_value.equals(value)) return; 145 if (new_value != null) 146 { 147 try { 148 Double.parseDouble(new_value+""); 149 } catch (Exception ex) 150 { 151 return; 152 } 153 } 154 155 Object oldValue = value; 156 value = new_value; 157 if(oldValue == null || value == null) 159 { 160 updateLabel(); 161 } 162 163 fireSheetPropertyValueChangedListenerSheetPropertyValueChanged( 164 new SheetPropertyValueChangedEvent(getKeyName(),oldValue,value, this)); 165 } 166 167 public void updateValues(Vector values, boolean addNullEntry){ 168 169 170 Misc.updateComboBox( (JComboBox)getEditor(), values, addNullEntry); 171 172 } 173 174 } 175 | Popular Tags |