001    /*
002     * OneRuleListener.java 
003     * Part of the Spirograph problem set
004     *
005     * Developed for "Rethinking CS101", a project of Lynn Andrea Stein's AP Group.
006     * For more information, see <a href="http://www.ai.mit.edu/projects/cs101/">the
007     * CS101 homepage</a> or email <las@ai.mit.edu>.
008     *
009     * Copyright (C) 1996 Massachusetts Institute of Technology.
010     * Please do not redistribute without obtaining permission.
011     */
012    
013    package spirograph;
014    
015    import java.awt.event.*;
016    import java.awt.*;
017    
018    /** This implements a listener that is created by {@link CodeBox } and passed
019     * to {@link AdvEnv}. It enables or disables the approprite text areas and
020     * fields so that when only one rule is being used the other rule is
021     * grayed out.
022     *
023     * <p>Copyright © 1998 Massachusetts Institute of Technology<br />
024     * Copyright © 2003 Franklin W. Olin College of Engineering
025     *
026     * @author Luis Sarmenta, lfgs@cag.lcs.mit.edu
027     * @author Henry Wong, henryw@mit.edu
028     * @author Patrick G. Heck, gus.heck@olin.edu
029     * @version $Id: OneRuleListener.java,v 1.4 2004/02/09 20:55:03 gus Exp $
030     * @see CodeMerger
031     * @see CodeBox
032     */
033    public class OneRuleListener implements ItemListener {
034        TextArea onTA, offTA, onFields, offFields;
035        Button onButton, offButton;
036        Checkbox offCheckbox;
037        CodeMerger myMerger;
038        
039        /**
040         * Create an object that monitors the state of the specified components and
041         * enables or disables them as needed.
042         *
043         * @param onTA The code text area that remains on
044         * @param offTA The code text area that is turned off
045         * @param onFields The fields text area that remains on
046         * @param offFields The fields text area that is turned off
047         * @param onButton The button that remains on
048         * @param offButton The button that is turned off
049         * @param offCheckbox The other check box wich gets turned off
050         * @param myMerger The code merger that is to be used for both rules
051         */    
052        public OneRuleListener(TextArea onTA, TextArea offTA, TextArea onFields, TextArea offFields, Button onButton, Button offButton, Checkbox offCheckbox, CodeMerger myMerger) {
053            this.onTA = onTA;
054            this.offTA = offTA;
055            this.onFields = onFields;
056            this.offFields = offFields;
057            this.onButton = onButton;
058            this.offButton = offButton;
059            this.offCheckbox = offCheckbox;
060            this.myMerger = myMerger;
061        }
062    
063        /**
064         * Examine the supplied event and disable components if the item has been selected.
065         *
066         * @param ie An item event from the component we are listening to.
067         */    
068        public void itemStateChanged(ItemEvent ie) {
069            if ( ie.getStateChange() == ItemEvent.SELECTED )
070            {
071                onTA.setEnabled(true);
072                offTA.setEnabled(false);
073                onFields.setEnabled(true);
074                offFields.setEnabled(false);
075                onButton.setEnabled(true);
076                offButton.setEnabled(false);
077                offCheckbox.setState(false);
078                offCheckbox.setEnabled(false);
079                myMerger.setBoth(true);
080            } else {
081                onTA.setEnabled(true);
082                offTA.setEnabled(true);
083                onFields.setEnabled(true);
084                offFields.setEnabled(true);
085                onButton.setEnabled(true);
086                offButton.setEnabled(true);
087                offCheckbox.setEnabled(true);
088                myMerger.setBoth(false);
089            }
090        }
091    }
092    
093    /*
094     * $Log: OneRuleListener.java,v $
095     * Revision 1.4  2004/02/09 20:55:03  gus
096     * javadoc fixes
097     *
098     * Revision 1.3  2003/01/15 17:36:10  gus
099     * adding log keywords to files that don't have them
100     *
101     */