KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jimm > datavision > gui > FormulaWin


1 package jimm.datavision.gui;
2 import jimm.datavision.*;
3 import jimm.datavision.gui.cmd.FormulaEditCommand;
4 import jimm.util.I18N;
5 import java.util.Observable JavaDoc;
6 import java.util.Observer JavaDoc;
7
8 /**
9  * This dialog is for editing {@link Formula} code.
10  *
11  * @author Jim Menard, <a HREF="mailto:jimm@io.com">jimm@io.com</a>
12  * @see FormulaWidget
13  * @see jimm.datavision.gui.cmd.FormulaEditCommand
14  */

15 public class FormulaWin extends ScriptEditorWin implements Observer JavaDoc {
16
17 protected Formula formula;
18
19 /**
20  * Constructor.
21  *
22  * @param designer the window to which this dialog belongs
23  * @param report the report
24  * @param formula the formula whose text needs editing
25  */

26 public FormulaWin(Designer designer, Report report, Formula formula) {
27     super(designer, report, formula.getEditableExpression(),
28       I18N.get("FormulaWin.title_prefix") + ' ' + formula.getName(),
29       "FormulaWin.error_unchanged", "FormulaWin.error_title");
30     this.formula = formula;
31     formula.addObserver(this);
32     setLanguage(formula.getLanguage());
33 }
34
35 protected void finalize() throws Throwable JavaDoc {
36     formula.deleteObserver(this);
37     super.finalize();
38 }
39
40 public void update(Observable JavaDoc o, Object JavaDoc arg) {
41     setTitle(I18N.get("FormulaWin.title_prefix") + ' ' + formula.getName());
42     codeField.setText(formula.getEditableExpression());
43 }
44
45 /**
46  * Creates and executes a command that changes the formula's eval string and
47  * language. If there is an error, the command is cancelled (never sent to the
48  * design window).
49  *
50  * @param text the new eval string
51  */

52 public void save(String JavaDoc text) {
53     formula.deleteObserver(this);
54     command = new FormulaEditCommand(formula, text, getLanguage());
55 }
56
57 }
58
Popular Tags