001: /*
002: *JSJavadocOptionPane.java - JavaStyle javadoc options panel
003: *Copyright (C) 2000,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:
030: /**
031: * Description of the Class
032: *
033: * @author Mike Atkinson (<a
034: * href="mailto:javastyle@ladyshot.demon.co.uk">
035: * Mike@ladyshot.demon.co.uk</a> )
036: * @author Dirk Moebius (<a href="mailto:dmoebius@gmx.net">
037: * dmoebius@gmx.net </a> )
038: * @created 03 September 2003
039: * @version $Version: $
040: * @since 1.0
041: */
042: public class JSJavadocOptionPane extends JSHelpOptionPane {
043: private JTextField jdocIndent;
044: private JMouseComboBox jdocOnClasses;
045: private JMouseComboBox jdocOnEnums;
046: private JMouseComboBox jdocOnFields;
047: private JMouseComboBox jdocOnMethods;
048: private JCheckBox jdocReformat;
049: private JTextField jdocWordwrap;
050: private JTextField jdocWordwrapIgnore;
051:
052: private SelectedPanel jdocIndent_sp;
053: private SelectedPanel jdocInnerClasses_sp;
054: private SelectedPanel jdocKeepAll_sp;
055: private SelectedPanel jdocOnClasses_sp;
056: private SelectedPanel jdocOnEnums_sp;
057: private SelectedPanel jdocOnFields_sp;
058: private SelectedPanel jdocOnMethods_sp;
059: private SelectedPanel jdocReformat_sp;
060: private SelectedPanel jdocSingleLine_sp;
061: private SelectedPanel jdocFirstLine_sp;
062: private SelectedPanel jdocWordwrap_sp;
063: private SelectedPanel jdocWordwrapIgnore_sp;
064:
065: private final static String[] prots = {
066: getIdeJavaStyleOption("prot.none"),
067: getIdeJavaStyleOption("prot.public"),
068: getIdeJavaStyleOption("prot.protected"),
069: getIdeJavaStyleOption("prot.package"),
070: getIdeJavaStyleOption("prot.all") };
071:
072: /**
073: * Constructor for the JSJavadocOptionPane object
074: *
075: * @param project Description of the Parameter
076: */
077: public JSJavadocOptionPane(String project) {
078: super ("javastyle.javadoc", "pretty", project);
079: }
080:
081: /** Description of the Method */
082: public void _init() {
083: ActionHandler ah = new ActionHandler();
084:
085: //PropertiesFile props = JavaStylePlugin.getProperties();
086:
087: // "Keep all JavaDoc comments"
088: jdocKeepAll_sp = addComponent("keep.all.javadoc",
089: "jdocKeepAll", new JCheckBox());
090:
091: // "Create JavaDoc comments for inner classes"
092: jdocInnerClasses_sp = addComponent("document.nested.classes",
093: "jdocInnerClasses", new JCheckBox());
094:
095: // "Allow single line JavaDoc comments"
096: jdocSingleLine_sp = addComponent("allow.singleline.javadoc",
097: "jdocSingleLine", new JCheckBox());
098:
099: // First line of JavaDoc is append the /** line
100: jdocFirstLine_sp = addComponent("first.singleline.javadoc",
101: "jdocFirstLine", new JCheckBox());
102:
103: // "Create JavaDoc, if missing, on..."
104: addComponent(new JLabel(getIdeJavaStyleOption("jdocCreate")));
105:
106: // "...Fields:"
107: jdocOnFields = new JMouseComboBox(prots);
108: jdocOnFields_sp = addComponent("field.minimum", "jdocOnFields",
109: jdocOnFields);
110: jdocOnFields.setSelectedIndex(protnameToIndex(props
111: .getString("field.minimum")));
112:
113: // "...Methods:"
114: jdocOnMethods = new JMouseComboBox(prots);
115: jdocOnMethods_sp = addComponent("method.minimum",
116: "jdocOnMethods", jdocOnMethods);
117: jdocOnMethods.setSelectedIndex(protnameToIndex(props
118: .getString("method.minimum")));
119:
120: // "...Classes:"
121: jdocOnClasses = new JMouseComboBox(prots);
122: jdocOnClasses_sp = addComponent("class.minimum",
123: "jdocOnClasses", jdocOnClasses);
124: jdocOnClasses.setSelectedIndex(protnameToIndex(props
125: .getString("class.minimum")));
126:
127: // "...Enums:"
128: jdocOnEnums = new JMouseComboBox(prots);
129: jdocOnEnums_sp = addComponent("enum.minimum", "jdocOnEnums",
130: jdocOnEnums);
131: jdocOnEnums.setSelectedIndex(protnameToIndex(props
132: .getString("enum.minimum")));
133:
134: // "Wordwrap JavaDoc comments"
135: boolean reformat_comments = props
136: .getBoolean("reformat.comments");
137:
138: jdocReformat = new JCheckBox();
139: jdocReformat.addActionListener(ah);
140: jdocReformat_sp = addComponent("reformat.comments",
141: "jdocReformat", jdocReformat);
142: jdocReformat.setSelected(reformat_comments);
143:
144: // "At column: nnn"
145: jdocWordwrap = new JTextField();
146: jdocWordwrap_sp = addComponent("javadoc.wordwrap.max",
147: "jdocWordwrap", jdocWordwrap);
148: jdocWordwrap.setEnabled(reformat_comments);
149:
150: // "Only lines longer than: nnn"
151: jdocWordwrapIgnore = new JTextField();
152: jdocWordwrapIgnore_sp = addComponent("javadoc.wordwrap.min",
153: "jdocWordwrapIgnore", jdocWordwrapIgnore);
154: jdocWordwrapIgnore.setEnabled(reformat_comments);
155:
156: // "Spaces between JavaDoc star and text: nnn"
157: jdocIndent_sp = addComponent("javadoc.indent", "jdocIndent",
158: new JTextField());
159:
160: addHelpArea();
161: }
162:
163: /**
164: * Called when the options dialog's `OK' button is pressed.
165: * This should save any properties saved in this option pane.
166: */
167: public void _save() {
168: jdocIndent_sp.saveInt(1, 0);
169: jdocInnerClasses_sp.save();
170: jdocKeepAll_sp.save();
171: jdocOnClasses_sp.save(indexToProtname(jdocOnClasses
172: .getSelectedIndex()));
173: jdocOnEnums_sp.save(indexToProtname(jdocOnEnums
174: .getSelectedIndex()));
175: jdocOnFields_sp.save(indexToProtname(jdocOnFields
176: .getSelectedIndex()));
177: jdocOnMethods_sp.save(indexToProtname(jdocOnMethods
178: .getSelectedIndex()));
179: jdocReformat_sp.save();
180: jdocSingleLine_sp.save();
181: jdocFirstLine_sp.save();
182: jdocWordwrap_sp.saveInt(78, 0);
183: jdocWordwrapIgnore_sp.saveInt(40, 0);
184: }
185:
186: /**
187: * Description of the Method
188: *
189: * @param index Description of Parameter
190: * @return Description of the Returned Value
191: */
192: private static String indexToProtname(int index) {
193: switch (index) {
194: case 1:
195: return "public";
196: case 2:
197: return "protected";
198: case 3:
199: return "package";
200: case 4:
201: return "all";
202: default:
203: return "none";
204: }
205: }
206:
207: /**
208: * Description of the Method
209: *
210: * @param propname Description of Parameter
211: * @return Description of the Returned Value
212: */
213: private static int protnameToIndex(String propname) {
214: if (propname == null) {
215: return 0;
216: } else if (propname.equalsIgnoreCase("public")) {
217: return 1;
218: } else if (propname.equalsIgnoreCase("protected")) {
219: return 2;
220: } else if (propname.equalsIgnoreCase("package")
221: || propname.equalsIgnoreCase("default")) {
222: return 3;
223: } else if (propname.equalsIgnoreCase("private")
224: || propname.equalsIgnoreCase("all")) {
225: return 4;
226: } else {
227: return 0;
228: }
229: }
230:
231: /**
232: * Description of the Class
233: *
234: * @author Mike Atkinson (Mike)
235: * @created 14 July 2003
236: */
237: private class ActionHandler implements ActionListener {
238: /**
239: * Description of the Method
240: *
241: * @param evt Description of Parameter
242: */
243: public void actionPerformed(ActionEvent evt) {
244: if (evt.getSource() == jdocReformat) {
245: boolean sel = jdocReformat.isSelected();
246:
247: jdocWordwrap.setEnabled(sel);
248: jdocWordwrapIgnore.setEnabled(sel);
249: }
250: }
251: }
252:
253: }
|