package edu.princeton.toy.choosers; import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; import edu.princeton.swing.*; import edu.princeton.toy.lang.*; /** * TCheckingChooserPane manages the options related to syntax checking. * * @author btsang * @version 7.1 */ public class TCheckingChooserPane extends JPanel { private static final String CLASS_STRING = TCheckingChooserPane.class.toString(); /** * The command doesn't do anything at present. */ public static final String UPDATE_COMMAND = CLASS_STRING + "#updateCommand"; private ButtonModel ignoreWarningsModel, autoCheckModel; /** * Creates a new TCheckingChooserPane. */ public TCheckingChooserPane() { super(new GridBagLayout()); JCheckBox checkBox = new JCheckBox("Do not generate compiler warnings"); ignoreWarningsModel = checkBox.getModel(); add( checkBox, new GridBagConstraints( 0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.SOUTHWEST, GridBagConstraints.NONE, new Insets(2, 2, 10, 2), 0, 0 ) ); checkBox = new JCheckBox("Check syntax continuously as program is edited"); autoCheckModel = checkBox.getModel(); add( checkBox, new GridBagConstraints( 0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(10, 2, 2, 2), 0, 0 ) ); } /** * Returns wheter or not regular warnings should be ignored when the syntax of a program * is being checked. * * @return True iff regular warnings should be ignored when the syntax of a program * is being checked. */ public boolean getIgnoreWarnings() { return ignoreWarningsModel.isSelected(); } /** * Sets wheter or not regular warnings should be ignored when the syntax of a program * is being checked. * * @param ignoreWarnings True iff regular warnings should be ignored when the syntax of a * program is being checked. */ public void setIgnoreWarnings(boolean ignoreWarnings) { ignoreWarningsModel.setSelected(ignoreWarnings); } /** * Returns wheter or not the syntax should be checked automatically as the user types. * * @return True iff the syntax should be checked automatically as the user types. */ public boolean getAutoCheck() { return autoCheckModel.isSelected(); } /** * Sets wheter or not the syntax should be checked automatically as the user types. * * @param autoCheck True iff the syntax should be checked automatically as the user types. */ public void setAutoCheck(boolean autoCheck) { autoCheckModel.setSelected(autoCheck); } /** * Performs a command based on the argument. * * @param command A string representing the command. Note that pointer equality (not string * equality) is tested here, so it is important to use the string constants defined in this * class. An IllegalArgumentException will be thrown if the argument is invalid. * @return True iff the command was executed sucessfully. */ public synchronized boolean doCommand(String command, Object extraInfo) { //////////////////////////////////////////////////////////////////////////////////////////// if (command == UPDATE_COMMAND) { return true; } throw new IllegalArgumentException(); } }