001: /*
002: * JSIndentOptionPane.java - JavaStyle indenting options panel
003: * Copyright (C) 2001 Dirk Moebius
004: *
005: * jEdit buffer options:
006: * :tabSize=4:indentSize=4:noTabs=false:maxLineLen=0:
007: *
008: * This program is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU General Public License
010: * as published by the Free Software Foundation; either version 2
011: * of the License, or any later version.
012: *
013: * This program is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016: * GNU General Public License for more details.
017: *
018: * You should have received a copy of the GNU General Public License
019: * along with this program; if not, write to the Free Software
020: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
021: */
022: package org.acm.seguin.ide.common.options;
023:
024: import java.awt.event.ActionEvent;
025: import java.awt.event.ActionListener;
026: import javax.swing.JCheckBox;
027: import javax.swing.JLabel;
028: import javax.swing.JTextField;
029: import javax.swing.JRadioButton;
030: import javax.swing.ButtonGroup;
031:
032: /**
033: *@author Mike Atkinson (<a href="mailto:javastyle@ladyshot.demon.co.uk">
034: * Mike@ladyshot.demon.co.uk</a> )
035: *@author Dirk Moebius (<a href="mailto:dmoebius@gmx.net">dmoebius@gmx.net
036: * </a>)
037: *@created 03 September 2003
038: *@version $Version: $
039: *@since 1.0
040: */
041: public class JSIndentOptionPane extends JSHelpOptionPane {
042:
043: private final static String[] bracketModes = { "C", "PASCAL",
044: "EMACS" };
045:
046: private JRadioButton forceBlocks;
047: private JRadioButton removeBlocks;
048: private JTextField caseIndent;
049:
050: private SelectedPanel elseStartLine_sp;
051: private SelectedPanel catchStartLine_sp;
052: private SelectedPanel throwsStartLine_sp;
053: private SelectedPanel forceBlocks_sp;
054: private SelectedPanel removeBlocks_sp;
055: private SelectedPanel emptyBlocks_sp;
056: private SelectedPanel indentCont_sp;
057: private SelectedPanel cbrackets_sp;
058: private SelectedPanel mbrackets_sp;
059: private SelectedPanel brackets_sp;
060: private SelectedPanel caseIndent_sp;
061:
062: /**
063: * Constructor for the JSIndentOptionPane object
064: *
065: *@param project Description of the Parameter
066: */
067: public JSIndentOptionPane(String project) {
068: super ("javastyle.indenting", "pretty", project);
069: }
070:
071: /**
072: * Description of the Method
073: */
074: public void _init() {
075: ActionHandler ah = new ActionHandler();
076:
077: // "'else' starts on a new line"
078: elseStartLine_sp = addComponent("else.start.line",
079: "elseStartLine", new JCheckBox());
080:
081: // "'catch' starts on a new line"
082: catchStartLine_sp = addComponent("catch.start.line",
083: "catchStartLine", new JCheckBox());
084:
085: // "'throws' starts on a new line"
086: throwsStartLine_sp = addComponent("throws.newline",
087: "throwsStartLine", new JCheckBox());
088:
089: // "Indent continued lines"
090: String[] indentContModes = { "single", "double", "param" };
091: //indentCont = new JMouseComboBox(indentContModes);
092: indentCont_sp = addComponent("surprise.return",
093: "indentContinuedLines", new JMouseComboBox(
094: indentContModes));
095:
096: // "Brackets { } :"
097: addComponent(new JLabel(getIdeJavaStyleOption("brackets")));
098:
099: // "Class brackets are on lines by themselves"
100: cbrackets_sp = addComponent("class.block.style",
101: "brackets.classes", new JMouseComboBox(bracketModes));
102:
103: /*
104: // // REVISIT: enum blocks currently use the class brackets style.
105: // // "Enum brackets are on lines by themselves"
106: //ebrackets = new JMouseComboBox(bracketModes);
107: //ebrackets.setEditable(false);
108: //ebrackets.setSelectedItem(props.getString("enum.block.style"));
109: //addHelpFor(ebrackets, "brackets.enums");
110: //addComponent(getIdeJavaStyleOption("brackets.enums"), ebrackets);
111: */
112: // "Method brackets are on lines by themselves"
113: mbrackets_sp = addComponent("method.block.style",
114: "brackets.methods", new JMouseComboBox(bracketModes));
115:
116: // "Other brackets (if,while,for etc.) are on lines by themselves"
117: brackets_sp = addComponent("block.style", "brackets.other",
118: new JMouseComboBox(bracketModes));
119:
120: // "Create brackets around single-line blocks"
121: forceBlocks = new JRadioButton();
122: forceBlocks_sp = addComponent("force.block", "forceBlocks",
123: forceBlocks);
124:
125: // "Remove brackets around single-line blocks"
126: removeBlocks = new JRadioButton();
127: removeBlocks.addActionListener(ah);
128: removeBlocks_sp = addComponent("remove.excess.blocks",
129: "removeBlocks", removeBlocks);
130:
131: ButtonGroup group = new ButtonGroup();
132: group.add(forceBlocks);
133: group.add(removeBlocks);
134:
135: // "Put empty methods and constructors on a single line"
136: emptyBlocks_sp = addComponent("empty.block.single.line",
137: "emptyBlocks", new JCheckBox());
138:
139: // "Indent case statements: nnn"
140: caseIndent = new JTextField();
141: caseIndent_sp = addComponent("case.indent", "caseIndent",
142: caseIndent);
143:
144: addHelpArea();
145: }
146:
147: /**
148: * Called when the options dialog's `OK' button is pressed. This should
149: * save any properties saved in this option pane.
150: */
151: public void _save() {
152: elseStartLine_sp.save();
153: catchStartLine_sp.save();
154: throwsStartLine_sp.save();
155: forceBlocks_sp.save();
156: removeBlocks_sp.save();
157: emptyBlocks_sp.save();
158: indentCont_sp.save();
159: cbrackets_sp.save();
160: mbrackets_sp.save();
161: brackets_sp.save();
162: caseIndent_sp.saveInt(4, 0);
163:
164: }
165:
166: /**
167: * Description of the Class
168: *
169: *@author Mike
170: *@created 03 September 2003
171: */
172: private class ActionHandler implements ActionListener {
173: /**
174: * Description of the Method
175: *
176: *@param evt Description of the Parameter
177: */
178: public void actionPerformed(ActionEvent evt) {
179: if (evt.getSource() == forceBlocks) {
180: if (forceBlocks.isSelected()) {
181: removeBlocks.setSelected(false);
182: }
183: } else if (evt.getSource() == removeBlocks) {
184: if (removeBlocks.isSelected()) {
185: forceBlocks.setSelected(false);
186: }
187: }
188: }
189: }
190:
191: }
|