KickJava   Java API By Example, From Geeks To Geeks.

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


1 package jimm.datavision.gui;
2 import jimm.datavision.Report;
3 import jimm.datavision.gui.cmd.SummaryCommand;
4 import jimm.util.I18N;
5 import java.awt.BorderLayout JavaDoc;
6 import javax.swing.*;
7
8 /**
9  * A report description (name, title, author, etc.) editing dialog box.
10  *
11  * @author Jim Menard, <a HREF="mailto:jimm@io.com">jimm@io.com</a>
12  */

13 public class DescripWin extends EditWin {
14
15 protected static final int TEXT_FIELD_COLS = 32;
16 protected static final int TEXT_AREA_ROWS = 6;
17 protected static final int TEXT_AREA_COLS = 32;
18
19 protected Report report;
20 protected JTextField nameField;
21 protected JTextField titleField;
22 protected JTextField authorField;
23 protected JTextArea descriptionField;
24
25 /**
26  * Constructor.
27  *
28  * @param designer the window to which this dialog belongs
29  * @param report report (I love useful, thoughtful comments)
30  */

31 public DescripWin(Designer designer, Report report) {
32     super(designer, I18N.get("DescripWin.title"), "SummaryCommand.name");
33
34     this.report = report;
35
36     buildWindow();
37     pack();
38     setVisible(true);
39 }
40
41 /**
42  * Builds the window contents.
43  */

44 protected void buildWindow() {
45     // All edit fields
46
JPanel editorPanel = buildEditor();
47
48     // OK, Apply, Revert, and Cancel Buttons
49
JPanel buttonPanel = closeButtonPanel();
50
51     // Add values and buttons to window
52
getContentPane().add(editorPanel, BorderLayout.CENTER);
53     getContentPane().add(buttonPanel, BorderLayout.SOUTH);
54 }
55
56 protected JPanel buildEditor() {
57     EditFieldLayout efl = new EditFieldLayout();
58
59     nameField = efl.addTextField(I18N.get("DescripWin.report_name"),
60                  report.getName(), TEXT_FIELD_COLS);
61     titleField = efl.addTextField(I18N.get("DescripWin.report_title"),
62                   report.getTitle(), TEXT_FIELD_COLS);
63     authorField = efl.addTextField(I18N.get("DescripWin.author_name"),
64                    report.getAuthor(), TEXT_FIELD_COLS);
65     descriptionField = efl.addTextArea(I18N.get("DescripWin.description"),
66                        report.getDescription(),
67                        TEXT_AREA_ROWS, TEXT_AREA_COLS);
68
69     return efl.getPanel();
70 }
71
72 protected void fillEditFields() {
73     nameField.setText(report.getName());
74     titleField.setText(report.getTitle());
75     authorField.setText(report.getAuthor());
76     descriptionField.setText(report.getDescription());
77 }
78
79 protected void doSave() {
80     SummaryCommand cmd =
81     new SummaryCommand(report, nameField.getText(), titleField.getText(),
82                authorField.getText(), descriptionField.getText());
83     cmd.perform();
84     commands.add(cmd);
85 }
86
87 protected void doRevert() {
88     fillEditFields();
89 }
90
91 }
92
Popular Tags