001: package jimm.datavision.gui;
002:
003: import jimm.datavision.*;
004: import jimm.datavision.gui.cmd.SuppressionProcEditCommand;
005: import jimm.util.I18N;
006: import java.awt.BorderLayout;
007: import java.awt.Color;
008: import java.awt.event.ActionEvent;
009: import javax.swing.*;
010:
011: /**
012: * An edit dialog for suppression procs.
013: *
014: * @author Jim Menard, <a href="mailto:jimm@io.com">jimm@io.com</a>
015: * @see jimm.datavision.SuppressionProc
016: * @see jimm.datavision.Formula
017: * @see jimm.datavision.gui.cmd.SuppressionProcEditCommand
018: */
019: public class SuppressionProcWin extends ScriptEditorWin {
020:
021: protected static final int CHECK_BOX_INDENT_WIDTH = 32;
022:
023: protected SectionWidget sectionWidget;
024: protected JCheckBox hideCheckBox;
025:
026: /**
027: * Constructor.
028: *
029: * @param designer the window to which this dialog belongs
030: * @param sectionWidget the section widget
031: */
032: public SuppressionProcWin(Designer designer,
033: SectionWidget sectionWidget) {
034: super (designer, sectionWidget.getSection().getReport(),
035: sectionWidget.getSection().getSuppressionProc()
036: .getFormula().getEditableExpression(), I18N
037: .get("SuppressionProcWin.title"),
038: "SuppressionProcWin.error_unchanged",
039: "SuppressionProcWin.error_title");
040:
041: // Finish GUI setup
042: hideCheckBox.setSelected(sectionWidget.getSection()
043: .getSuppressionProc().isHidden());
044: enableEditBox();
045:
046: this .sectionWidget = sectionWidget;
047: setLanguage(sectionWidget.getSection().getSuppressionProc()
048: .getFormula().getLanguage());
049: }
050:
051: protected JComponent northPanel(Report report) {
052: hideCheckBox = new JCheckBox(I18N
053: .get("SuppressionProcWin.always_hide"));
054: hideCheckBox.addActionListener(this );
055:
056: Box box = Box.createHorizontalBox();
057: box.add(Box.createHorizontalStrut(CHECK_BOX_INDENT_WIDTH));
058: box.add(hideCheckBox);
059:
060: JPanel northPanel = new JPanel();
061: northPanel.add(box, BorderLayout.WEST);
062: northPanel.add(super .northPanel(report), BorderLayout.EAST);
063:
064: return northPanel;
065: }
066:
067: /**
068: * Creates and executes a command that changes the formula's eval string.
069: * If there is an error, the command is cancelled (never sent to the
070: * design window).
071: *
072: * @param text the new eval string
073: */
074: public void save(String text) {
075: command = new SuppressionProcEditCommand(sectionWidget,
076: hideCheckBox.isSelected(), text, getLanguage());
077: }
078:
079: /**
080: * Listens for "Always Hide" actions; passes all others on to
081: * our superclass.
082: */
083: public void actionPerformed(ActionEvent e) {
084: String cmd = e.getActionCommand();
085: if (I18N.get("SuppressionProcWin.always_hide").equals(cmd))
086: enableEditBox();
087: else
088: super .actionPerformed(e);
089: }
090:
091: /**
092: * Enables or disables code editor box based on state of "Always
093: * Hide" checkbox.
094: */
095: protected void enableEditBox() {
096: boolean hide = hideCheckBox.isSelected();
097: codeField.setEditable(!hide);
098: codeField.setBackground(hide ? Color.lightGray : Color.white);
099: }
100:
101: }
|