001: /*
002: * JSSpacingOptionPane.java - JavaStyle spacing 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.JTextField;
028:
029: /**
030: *@author Mike Atkinson (<a href="mailto:javastyle@ladyshot.demon.co.uk">
031: * Mike@ladyshot.demon.co.uk</a> )
032: *@author Dirk Moebius (<a href="mailto:dmoebius@gmx.net">dmoebius@gmx.net
033: * </a>)
034: *@created 03 September 2003
035: *@version $Version: $
036: *@since 1.0
037: */
038: public class JSSpacingOptionPane extends JSHelpOptionPane {
039: private JCheckBox spaceParens;
040: private JCheckBox spaceNotInCasts;
041: private JTextField linesAfterPackage;
042: private JTextField linesBeforeClass;
043: private JTextField linesBetween;
044:
045: private SelectedPanel spaceCasts_sp;
046: private SelectedPanel spaceKeywords_sp;
047: private SelectedPanel spaceParens_sp;
048: private SelectedPanel spaceNotInCasts_sp;
049: private SelectedPanel spaceLocals_sp;
050: private SelectedPanel linesAfterPackage_sp;
051: private SelectedPanel linesBeforeClass_sp;
052: private SelectedPanel linesBetween_sp;
053: private SelectedPanel spaceAroundOps_sp;
054:
055: /**
056: * Constructor for the JSSpacingOptionPane object
057: *
058: *@param project Description of the Parameter
059: */
060: public JSSpacingOptionPane(String project) {
061: super ("javastyle.spacing", "pretty", project);
062: }
063:
064: /**
065: * Description of the Method
066: */
067: public void _init() {
068: ActionHandler ah = new ActionHandler();
069:
070: // "Lines after package statement: nnn"
071: String lines_after_package = props
072: .getString("lines.after.package");
073: linesAfterPackage = new JTextField();
074: linesAfterPackage_sp = addComponent("lines.after.package",
075: "linesAfterPackage", linesAfterPackage);
076: int valLinesAfterPackage = 1;
077: try {
078: valLinesAfterPackage = Integer
079: .parseInt(lines_after_package);
080: } catch (NumberFormatException ex) {
081: }
082: linesAfterPackage.setText(String
083: .valueOf(valLinesAfterPackage - 1));
084:
085: // "Lines before class statement: nnn"
086: linesBeforeClass = new JTextField();
087: linesBeforeClass_sp = addComponent("lines.before.class",
088: "linesBeforeClass", linesBeforeClass);
089:
090: // "Min. lines between methods & classes: nnn"
091: linesBetween = new JTextField();
092: linesBetween_sp = addComponent("lines.between", "linesBetween",
093: linesBetween);
094:
095: // Add space around operators
096: spaceAroundOps_sp = addComponent("space.around.ops",
097: "space.around.ops", new JCheckBox());
098:
099: // "Additional space after casts"
100: spaceCasts_sp = addComponent("cast.space", "spaceCasts",
101: new JCheckBox());
102:
103: // "Additional space after keywords (if, while, etc.)"
104: spaceKeywords_sp = addComponent("keyword.space",
105: "spaceKeywords", new JCheckBox());
106:
107: // "Additional space in parenthesized expressions"
108: spaceParens = new JCheckBox();
109: spaceParens.addActionListener(ah);
110: spaceParens_sp = addComponent("expr.space", "spaceParens",
111: spaceParens);
112:
113: // "...but not in casts"
114: spaceNotInCasts = new JCheckBox();
115: spaceNotInCasts_sp = addComponent("cast.force.nospace",
116: "spaceNotInCasts", spaceNotInCasts);
117: spaceNotInCasts.setEnabled(spaceParens.isSelected());
118:
119: // "Additional blank lines before and after local variable declarations"
120: spaceLocals_sp = addComponent(
121: "insert.space.around.local.variables", "spaceLocals",
122: new JCheckBox());
123:
124: addHelpArea();
125: }
126:
127: /**
128: * Called when the options dialog's `OK' button is pressed. This should
129: * save any properties saved in this option pane.
130: */
131: public void _save() {
132: spaceAroundOps_sp.save();
133: spaceCasts_sp.save();
134: spaceKeywords_sp.save();
135: spaceParens_sp.save();
136: spaceNotInCasts_sp.save();
137: spaceLocals_sp.save();
138: linesAfterPackage_sp.saveInt(1, 1);
139: linesBeforeClass_sp.saveInt(0, 1);
140: linesBetween_sp.saveInt(2, 0);
141:
142: }
143:
144: /**
145: * Description of the Class
146: *
147: *@author Mike
148: *@created 03 September 2003
149: */
150: private class ActionHandler implements ActionListener {
151: /**
152: * Description of the Method
153: *
154: *@param evt Description of the Parameter
155: */
156: public void actionPerformed(ActionEvent evt) {
157: if (evt.getSource() == spaceParens) {
158: spaceNotInCasts.setEnabled(spaceParens.isSelected());
159: }
160: }
161: }
162:
163: }
|