1 package org.catacomb.druid.gui.edit; 2 3 import org.catacomb.druid.event.LabelActor; 4 import org.catacomb.druid.swing.DFloat; 5 import org.catacomb.interlish.content.DoubleValue; 6 import org.catacomb.interlish.structure.*; 7 import org.catacomb.report.E; 8 9 10 import java.awt.Color; 11 12 public class DruFloat extends DruGCPanel 13 implements LabelActor, Ablable, DoubleValueEditor, ValueWatcher { 14 static final long serialVersionUID = 1001; 15 16 DFloat dFloat; 17 18 public LabelActor labelActor; 19 20 21 DoubleValue doubleValue; 22 23 24 25 public DruFloat(double val, double min, double max, String scale) { 26 super(); 27 28 dFloat = new DFloat(val, min, max, scale); 29 30 addSingleDComponent(dFloat); 31 dFloat.setLabelActor(this); 32 } 33 34 35 public void setProperties(double val, double min, double max, String scale) { 36 dFloat.setProperties(val, min, max, scale); 37 } 38 39 40 41 42 public void valueChangedBy(Value pv, Object src) { 43 if (src == this) { 44 valueChange(doubleValue.getDouble()); 45 46 } else { 47 if (doubleValue == pv) { 48 if (doubleValue == null) { 49 dFloat.setValue(0.0); 50 dFloat.setEnabled(false); 51 } else { 52 dFloat.setValue(doubleValue.getDouble()); 53 } 54 } else { 55 E.error("value changed by called with mismatched value"); 56 } 57 } 58 } 59 60 61 public void setDoubleValue(DoubleValue dv) { 62 if (doubleValue != null) { 63 doubleValue.removeValueWatcher(this); 64 } 65 doubleValue = dv; 66 if (doubleValue == null) { 67 dFloat.setEnabled(false); 68 } else { 69 dFloat.setValue(doubleValue.getDouble()); 70 doubleValue.addValueWatcher(this); 71 } 72 } 73 74 75 76 public void setLabel(String s) { 77 dFloat.setLabel(s); 78 } 79 80 public void setEditable(boolean b) { 81 dFloat.setEditable(b); 82 dFloat.setEnabled(b); 83 } 84 85 86 public void postApply() { 87 dFloat.setMouseActor(this); 88 } 89 90 91 public void setBg(Color c) { 92 dFloat.setBg(c); 93 super.setBg(c); 94 } 95 96 97 public void able(boolean b) { 98 dFloat.setEnabled(b); 99 } 100 101 102 103 104 public void labelAction(String s, boolean b) { 105 double d = dFloat.getValue(); 106 if (doubleValue != null) { 107 doubleValue.reportableSetDouble(d, this); 108 } else { 109 E.warning("no holder - dropping value change " + d); 110 } 111 112 } 113 114 115 116 }