01: package jimm.datavision.gui;
02:
03: import jimm.datavision.*;
04: import jimm.datavision.gui.cmd.FormulaEditCommand;
05: import jimm.util.I18N;
06: import java.util.Observable;
07: import java.util.Observer;
08:
09: /**
10: * This dialog is for editing {@link Formula} code.
11: *
12: * @author Jim Menard, <a href="mailto:jimm@io.com">jimm@io.com</a>
13: * @see FormulaWidget
14: * @see jimm.datavision.gui.cmd.FormulaEditCommand
15: */
16: public class FormulaWin extends ScriptEditorWin implements Observer {
17:
18: protected Formula formula;
19:
20: /**
21: * Constructor.
22: *
23: * @param designer the window to which this dialog belongs
24: * @param report the report
25: * @param formula the formula whose text needs editing
26: */
27: public FormulaWin(Designer designer, Report report, Formula formula) {
28: super (designer, report, formula.getEditableExpression(), I18N
29: .get("FormulaWin.title_prefix")
30: + ' ' + formula.getName(),
31: "FormulaWin.error_unchanged", "FormulaWin.error_title");
32: this .formula = formula;
33: formula.addObserver(this );
34: setLanguage(formula.getLanguage());
35: }
36:
37: protected void finalize() throws Throwable {
38: formula.deleteObserver(this );
39: super .finalize();
40: }
41:
42: public void update(Observable o, Object arg) {
43: setTitle(I18N.get("FormulaWin.title_prefix") + ' '
44: + formula.getName());
45: codeField.setText(formula.getEditableExpression());
46: }
47:
48: /**
49: * Creates and executes a command that changes the formula's eval string and
50: * language. If there is an error, the command is cancelled (never sent to the
51: * design window).
52: *
53: * @param text the new eval string
54: */
55: public void save(String text) {
56: formula.deleteObserver(this );
57: command = new FormulaEditCommand(formula, text, getLanguage());
58: }
59:
60: }
|