001: /*
002: * JSAlignmentOptionPane.java - JavaStyle alignment 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: import org.acm.seguin.ide.common.IDEPlugin;
029: import org.acm.seguin.ide.common.IDEInterface;
030:
031: /**
032: *@author Mike Atkinson (<a href="mailto:javastyle@ladyshot.demon.co.uk">
033: * Mike@ladyshot.demon.co.uk </a> )
034: *@author Dirk Moebius (<a href="mailto:dmoebius@gmx.net">dmoebius@gmx.net
035: * </a> )
036: *@created 03 September 2003
037: *@version $Version: $
038: *@since 1.0
039: */
040: public class JSAlignmentOptionPane extends JSHelpOptionPane {
041: private JCheckBox alignPrefixed;
042: private JTextField dynamicSpacing;
043: private JTextField fieldNameIndent;
044: private JMouseComboBox lineUpFields;
045:
046: private SelectedPanel alignParameters_sp;
047: private SelectedPanel lineUpFields_sp;
048: private SelectedPanel alignWithBlock_sp;
049: private SelectedPanel alignPrefixed_sp;
050: private SelectedPanel dynamicSpacing_sp;
051: private SelectedPanel fieldNameIndent_sp;
052: private SelectedPanel lineUpTags_sp;
053:
054: private final static String[] lineUpFieldsOptions = {
055: getIdeJavaStyleOption("lineUpFields.not"),
056: getIdeJavaStyleOption("lineUpFields.tabular"),
057: getIdeJavaStyleOption("lineUpFields.atEquals"),
058: getIdeJavaStyleOption("lineUpFields.atFixedColumn") };
059:
060: /**
061: * Constructor for the JSAlignmentOptionPane object
062: *
063: *@param project Description of the Parameter
064: */
065: public JSAlignmentOptionPane(String project) {
066: super ("javastyle.alignment", "pretty", project);
067: }
068:
069: /**
070: * Description of the Method
071: */
072: public void _init() {
073: ActionHandler ah = new ActionHandler();
074:
075: String variable_spacing = props.getString("variable.spacing",
076: "single");
077:
078: // "Align parameters if they start on a new line
079: alignParameters_sp = addComponent("params.lineup",
080: "params.lineup", new JCheckBox());
081:
082: // "Line up field definitions"
083: lineUpFields = new JMouseComboBox(lineUpFieldsOptions);
084: lineUpFields.addActionListener(ah);
085: lineUpFields_sp = addComponent("variable.spacing",
086: "lineUpFields", lineUpFields);
087:
088: // "Align with the block opener '{'"
089: alignWithBlock_sp = addComponent("variable.align.with.block",
090: "lineUpFields.alignWithBlock", new JCheckBox());
091:
092: // "Align even if prefixed by JavaDoc"
093: alignPrefixed = new JCheckBox();
094: alignPrefixed_sp = addComponent("variable.spacing",
095: "lineUpFields.alignPrefixed", alignPrefixed);
096: alignPrefixed.setSelected(variable_spacing.equals("dynamic"));
097:
098: // "Spacing between columns: nnn"
099: dynamicSpacing = new JTextField();
100: dynamicSpacing_sp = addComponent("dynamic.variable.spacing",
101: "1", "lineUpFields.dynamicSpacing", dynamicSpacing);
102:
103: // "Indent field names to column: nnn"
104: fieldNameIndent = new JTextField();
105: fieldNameIndent_sp = addComponent("field.name.indent",
106: "lineUpFields.fieldNameIndent", fieldNameIndent);
107: int fni = props.getInteger("field.name.indent", -1);
108: fieldNameIndent.setText(Integer.toString(fni));
109:
110: // "Line up names and descriptions in JavaDoc tags"
111: lineUpTags_sp = addComponent("javadoc.id.lineup", "lineUpTags",
112: new JCheckBox());
113:
114: if (fni >= 0) {
115: lineUpFields.setSelectedIndex(3);
116: } else if (variable_spacing.equals("dynamic")
117: || variable_spacing.equals("javadoc.dynamic")) {
118: lineUpFields.setSelectedIndex(1);
119: } else if (variable_spacing.equals("align.equals")) {
120: lineUpFields.setSelectedIndex(2);
121: } else {
122: lineUpFields.setSelectedIndex(0);
123: }
124:
125: addHelpArea();
126: }
127:
128: /**
129: * Called when the options dialog's `OK' button is pressed. This should
130: * save any properties saved in this option pane.
131: */
132: public void _save() {
133: int sel = lineUpFields.getSelectedIndex();
134: int fni = -1;
135: int dvs = 1;
136: String variable_spacing = "single";
137:
138: if (sel == 1) {
139: if (alignPrefixed.isSelected()) {
140: variable_spacing = "dynamic";
141: } else {
142: variable_spacing = "javadoc.dynamic";
143: }
144: try {
145: dvs = Integer.parseInt(dynamicSpacing.getText());
146: } catch (NumberFormatException nfex) {
147: IDEPlugin.log(IDEInterface.ERROR, this ,
148: "invalid number for dynamic.variable.spacing: "
149: + dynamicSpacing.getText());
150: }
151: } else if (sel == 2) {
152: variable_spacing = "align.equals";
153: } else if (sel == 3) {
154: try {
155: fni = Integer.parseInt(fieldNameIndent.getText());
156: } catch (NumberFormatException nfex) {
157: IDEPlugin.log(IDEInterface.ERROR, this ,
158: "invalid number for field.name.indent: "
159: + fieldNameIndent.getText());
160: }
161: }
162:
163: alignParameters_sp.save();
164: alignWithBlock_sp.save();
165: alignPrefixed_sp.save(variable_spacing);
166: dynamicSpacing_sp.save(Integer.toString(dvs));
167: fieldNameIndent_sp.save(Integer.toString(fni));
168: lineUpTags_sp.save();
169: }
170:
171: /**
172: * Description of the Class
173: *
174: *@author Mike Atkinson (Mike)
175: *@created 03 September 2003
176: *@version $Version: $
177: *@since 1.0
178: */
179: private class ActionHandler implements ActionListener {
180: /**
181: * Description of the Method
182: *
183: *@param evt Description of Parameter
184: */
185: public void actionPerformed(ActionEvent evt) {
186: if (evt.getSource() == lineUpFields) {
187: int sel = lineUpFields.getSelectedIndex();
188:
189: alignPrefixed.setEnabled(sel == 1);
190: dynamicSpacing.setEnabled(sel == 1);
191: fieldNameIndent.setEnabled(sel == 3);
192: }
193: }
194: }
195:
196: }
|